Lines Matching +full:cache +full:- +full:block +full:- +full:size

1 // SPDX-License-Identifier: GPL-2.0+
3 * NILFS B-tree node cache
5 * Copyright (C) 2005-2008 Nippon Telegraph and Telephone Corporation.
15 #include <linux/backing-dev.h>
25 * nilfs_init_btnc_inode - initialize B-tree node cache inode
28 * nilfs_init_btnc_inode() sets up an inode for B-tree node cache.
34 btnc_inode->i_mode = S_IFREG; in nilfs_init_btnc_inode()
35 ii->i_flags = 0; in nilfs_init_btnc_inode()
36 memset(&ii->i_bmap_data, 0, sizeof(struct nilfs_bmap)); in nilfs_init_btnc_inode()
37 mapping_set_gfp_mask(btnc_inode->i_mapping, GFP_NOFS); in nilfs_init_btnc_inode()
38 btnc_inode->i_mapping->a_ops = &nilfs_buffer_cache_aops; in nilfs_init_btnc_inode()
43 invalidate_mapping_pages(btnc, 0, -1); in nilfs_btnode_cache_clear()
50 struct inode *inode = btnc->host; in nilfs_btnode_create_block()
55 return ERR_PTR(-ENOMEM); in nilfs_btnode_create_block()
60 * The block buffer at the specified new address was already in nilfs_btnode_create_block()
61 * in use. This can happen if it is a virtual block number in nilfs_btnode_create_block()
64 * clearing of an abandoned b-tree node is missing somewhere). in nilfs_btnode_create_block()
66 nilfs_error(inode->i_sb, in nilfs_btnode_create_block()
67 … "state inconsistency probably due to duplicate use of b-tree node block address %llu (ino=%lu)", in nilfs_btnode_create_block()
68 (unsigned long long)blocknr, inode->i_ino); in nilfs_btnode_create_block()
71 memset(bh->b_data, 0, i_blocksize(inode)); in nilfs_btnode_create_block()
72 bh->b_blocknr = blocknr; in nilfs_btnode_create_block()
76 folio_unlock(bh->b_folio); in nilfs_btnode_create_block()
77 folio_put(bh->b_folio); in nilfs_btnode_create_block()
81 folio_unlock(bh->b_folio); in nilfs_btnode_create_block()
82 folio_put(bh->b_folio); in nilfs_btnode_create_block()
84 return ERR_PTR(-EIO); in nilfs_btnode_create_block()
92 struct inode *inode = btnc->host; in nilfs_btnode_submit_block()
98 return -ENOMEM; in nilfs_btnode_submit_block()
100 err = -EEXIST; /* internal code */ in nilfs_btnode_submit_block()
101 folio = bh->b_folio; in nilfs_btnode_submit_block()
108 if (inode->i_ino != NILFS_DAT_INO) { in nilfs_btnode_submit_block()
109 struct the_nilfs *nilfs = inode->i_sb->s_fs_info; in nilfs_btnode_submit_block()
111 /* blocknr is a virtual block number */ in nilfs_btnode_submit_block()
112 err = nilfs_dat_translate(nilfs->ns_dat, blocknr, in nilfs_btnode_submit_block()
123 err = -EBUSY; /* internal code */ in nilfs_btnode_submit_block()
132 err = -EEXIST; /* internal code */ in nilfs_btnode_submit_block()
136 bh->b_blocknr = pblocknr; /* set block address for read */ in nilfs_btnode_submit_block()
137 bh->b_end_io = end_buffer_read_sync; in nilfs_btnode_submit_block()
140 bh->b_blocknr = blocknr; /* set back to the given block address */ in nilfs_btnode_submit_block()
153 * nilfs_btnode_delete - delete B-tree node buffer
162 struct folio *folio = bh->b_folio; in nilfs_btnode_delete()
163 pgoff_t index = folio->index; in nilfs_btnode_delete()
172 mapping = folio->mapping; in nilfs_btnode_delete()
181 * nilfs_btnode_prepare_change_key - prepare to change the search key of a
182 * b-tree node block
183 * @btnc: page cache in which the b-tree node block is buffered
187 * b-tree node block of the old key given in the "oldkey" member of @ctxt to
189 * page cache @btnc. Here, the key of the block is an index in units of
190 * blocks, and if the page and block sizes match, it matches the page index
191 * in the page cache.
193 * If the page size and block size match, this function attempts to move the
195 * the new index of the cache. If this insertion fails or if the page size
196 * and block size are different, it falls back to a copy preparation using
197 * nilfs_btnode_create_block(), inserts a new block at the position
202 * than the page size.
206 * * %-EIO - I/O error (metadata corruption).
207 * * %-ENOMEM - Insufficient memory available.
213 struct inode *inode = btnc->host; in nilfs_btnode_prepare_change_key()
214 __u64 oldkey = ctxt->oldkey, newkey = ctxt->newkey; in nilfs_btnode_prepare_change_key()
220 obh = ctxt->bh; in nilfs_btnode_prepare_change_key()
221 ctxt->newbh = NULL; in nilfs_btnode_prepare_change_key()
223 if (inode->i_blkbits == PAGE_SHIFT) { in nilfs_btnode_prepare_change_key()
224 struct folio *ofolio = obh->b_folio; in nilfs_btnode_prepare_change_key()
227 /* BUG_ON(oldkey != obh->b_folio->index); */ in nilfs_btnode_prepare_change_key()
228 if (unlikely(oldkey != ofolio->index)) in nilfs_btnode_prepare_change_key()
234 xa_lock_irq(&btnc->i_pages); in nilfs_btnode_prepare_change_key()
235 err = __xa_insert(&btnc->i_pages, newkey, ofolio, GFP_NOFS); in nilfs_btnode_prepare_change_key()
236 xa_unlock_irq(&btnc->i_pages); in nilfs_btnode_prepare_change_key()
238 * Note: folio->index will not change to newkey until in nilfs_btnode_prepare_change_key()
245 else if (err != -EBUSY) in nilfs_btnode_prepare_change_key()
260 ctxt->newbh = nbh; in nilfs_btnode_prepare_change_key()
264 folio_unlock(obh->b_folio); in nilfs_btnode_prepare_change_key()
269 * nilfs_btnode_commit_change_key - commit the change of the search key of
270 * a b-tree node block
271 * @btnc: page cache in which the b-tree node block is buffered
276 * block buffer is prepared in "newbh" of @ctxt (i.e., a full folio move),
278 * Otherwise, it copies the block data and inherited flag states of "oldbh"
279 * to "newbh" and clears the "oldbh" from the cache. In either case, the
283 * not support folio sizes larger than the page size.
288 struct buffer_head *obh = ctxt->bh, *nbh = ctxt->newbh; in nilfs_btnode_commit_change_key()
289 __u64 oldkey = ctxt->oldkey, newkey = ctxt->newkey; in nilfs_btnode_commit_change_key()
296 ofolio = obh->b_folio; in nilfs_btnode_commit_change_key()
297 if (unlikely(oldkey != ofolio->index)) in nilfs_btnode_commit_change_key()
304 xa_lock_irq(&btnc->i_pages); in nilfs_btnode_commit_change_key()
305 __xa_erase(&btnc->i_pages, oldkey); in nilfs_btnode_commit_change_key()
306 __xa_set_mark(&btnc->i_pages, newkey, PAGECACHE_TAG_DIRTY); in nilfs_btnode_commit_change_key()
307 xa_unlock_irq(&btnc->i_pages); in nilfs_btnode_commit_change_key()
309 ofolio->index = obh->b_blocknr = newkey; in nilfs_btnode_commit_change_key()
315 nbh->b_blocknr = newkey; in nilfs_btnode_commit_change_key()
316 ctxt->bh = nbh; in nilfs_btnode_commit_change_key()
317 nilfs_btnode_delete(obh); /* will decrement bh->b_count */ in nilfs_btnode_commit_change_key()
322 * nilfs_btnode_abort_change_key - abort the change of the search key of a
323 * b-tree node block
324 * @btnc: page cache in which the b-tree node block is buffered
329 * any necessary cleanup. If no valid block buffer is prepared in "newbh" of
331 * the move. Otherwise, it clears "newbh" from the cache.
334 * not support folio sizes larger than the page size.
339 struct buffer_head *nbh = ctxt->newbh; in nilfs_btnode_abort_change_key()
340 __u64 oldkey = ctxt->oldkey, newkey = ctxt->newkey; in nilfs_btnode_abort_change_key()
346 xa_erase_irq(&btnc->i_pages, newkey); in nilfs_btnode_abort_change_key()
347 folio_unlock(ctxt->bh->b_folio); in nilfs_btnode_abort_change_key()
351 * allocated to copy a node block to another location, use in nilfs_btnode_abort_change_key()