Lines Matching +full:buffered +full:- +full:negative

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()
42 invalidate_mapping_pages(btnc, 0, -1); in nilfs_btnode_cache_clear()
49 struct inode *inode = btnc->host; in nilfs_btnode_create_block()
54 return ERR_PTR(-ENOMEM); in nilfs_btnode_create_block()
63 * clearing of an abandoned b-tree node is missing somewhere). in nilfs_btnode_create_block()
65 nilfs_error(inode->i_sb, in nilfs_btnode_create_block()
66 … "state inconsistency probably due to duplicate use of b-tree node block address %llu (ino=%lu)", in nilfs_btnode_create_block()
67 (unsigned long long)blocknr, inode->i_ino); in nilfs_btnode_create_block()
70 memset(bh->b_data, 0, i_blocksize(inode)); in nilfs_btnode_create_block()
71 bh->b_blocknr = blocknr; in nilfs_btnode_create_block()
75 folio_unlock(bh->b_folio); in nilfs_btnode_create_block()
76 folio_put(bh->b_folio); in nilfs_btnode_create_block()
80 folio_unlock(bh->b_folio); in nilfs_btnode_create_block()
81 folio_put(bh->b_folio); in nilfs_btnode_create_block()
83 return ERR_PTR(-EIO); in nilfs_btnode_create_block()
91 struct inode *inode = btnc->host; in nilfs_btnode_submit_block()
97 return -ENOMEM; in nilfs_btnode_submit_block()
99 err = -EEXIST; /* internal code */ in nilfs_btnode_submit_block()
100 folio = bh->b_folio; in nilfs_btnode_submit_block()
107 if (inode->i_ino != NILFS_DAT_INO) { in nilfs_btnode_submit_block()
108 struct the_nilfs *nilfs = inode->i_sb->s_fs_info; in nilfs_btnode_submit_block()
111 err = nilfs_dat_translate(nilfs->ns_dat, blocknr, in nilfs_btnode_submit_block()
122 err = -EBUSY; /* internal code */ in nilfs_btnode_submit_block()
131 err = -EEXIST; /* internal code */ in nilfs_btnode_submit_block()
135 bh->b_blocknr = pblocknr; /* set block address for read */ in nilfs_btnode_submit_block()
136 bh->b_end_io = end_buffer_read_sync; in nilfs_btnode_submit_block()
139 bh->b_blocknr = blocknr; /* set back to the given block address */ in nilfs_btnode_submit_block()
152 * nilfs_btnode_delete - delete B-tree node buffer
161 struct folio *folio = bh->b_folio; in nilfs_btnode_delete()
162 pgoff_t index = folio->index; in nilfs_btnode_delete()
171 mapping = folio->mapping; in nilfs_btnode_delete()
180 * nilfs_btnode_prepare_change_key - prepare to change the search key of a
181 * b-tree node block
182 * @btnc: page cache in which the b-tree node block is buffered
186 * b-tree node block of the old key given in the "oldkey" member of @ctxt to
203 * Return: 0 on success, or the following negative error code on failure.
204 * * %-EIO - I/O error (metadata corruption).
205 * * %-ENOMEM - Insufficient memory available.
211 struct inode *inode = btnc->host; in nilfs_btnode_prepare_change_key()
212 __u64 oldkey = ctxt->oldkey, newkey = ctxt->newkey; in nilfs_btnode_prepare_change_key()
218 obh = ctxt->bh; in nilfs_btnode_prepare_change_key()
219 ctxt->newbh = NULL; in nilfs_btnode_prepare_change_key()
221 if (inode->i_blkbits == PAGE_SHIFT) { in nilfs_btnode_prepare_change_key()
222 struct folio *ofolio = obh->b_folio; in nilfs_btnode_prepare_change_key()
225 /* BUG_ON(oldkey != obh->b_folio->index); */ in nilfs_btnode_prepare_change_key()
226 if (unlikely(oldkey != ofolio->index)) in nilfs_btnode_prepare_change_key()
232 xa_lock_irq(&btnc->i_pages); in nilfs_btnode_prepare_change_key()
233 err = __xa_insert(&btnc->i_pages, newkey, ofolio, GFP_NOFS); in nilfs_btnode_prepare_change_key()
234 xa_unlock_irq(&btnc->i_pages); in nilfs_btnode_prepare_change_key()
236 * Note: folio->index will not change to newkey until in nilfs_btnode_prepare_change_key()
243 else if (err != -EBUSY) in nilfs_btnode_prepare_change_key()
258 ctxt->newbh = nbh; in nilfs_btnode_prepare_change_key()
262 folio_unlock(obh->b_folio); in nilfs_btnode_prepare_change_key()
267 * nilfs_btnode_commit_change_key - commit the change of the search key of
268 * a b-tree node block
269 * @btnc: page cache in which the b-tree node block is buffered
286 struct buffer_head *obh = ctxt->bh, *nbh = ctxt->newbh; in nilfs_btnode_commit_change_key()
287 __u64 oldkey = ctxt->oldkey, newkey = ctxt->newkey; in nilfs_btnode_commit_change_key()
294 ofolio = obh->b_folio; in nilfs_btnode_commit_change_key()
295 if (unlikely(oldkey != ofolio->index)) in nilfs_btnode_commit_change_key()
302 xa_lock_irq(&btnc->i_pages); in nilfs_btnode_commit_change_key()
303 __xa_erase(&btnc->i_pages, oldkey); in nilfs_btnode_commit_change_key()
304 __xa_set_mark(&btnc->i_pages, newkey, PAGECACHE_TAG_DIRTY); in nilfs_btnode_commit_change_key()
305 xa_unlock_irq(&btnc->i_pages); in nilfs_btnode_commit_change_key()
307 ofolio->index = obh->b_blocknr = newkey; in nilfs_btnode_commit_change_key()
313 nbh->b_blocknr = newkey; in nilfs_btnode_commit_change_key()
314 ctxt->bh = nbh; in nilfs_btnode_commit_change_key()
315 nilfs_btnode_delete(obh); /* will decrement bh->b_count */ in nilfs_btnode_commit_change_key()
320 * nilfs_btnode_abort_change_key - abort the change of the search key of a
321 * b-tree node block
322 * @btnc: page cache in which the b-tree node block is buffered
337 struct buffer_head *nbh = ctxt->newbh; in nilfs_btnode_abort_change_key()
338 __u64 oldkey = ctxt->oldkey, newkey = ctxt->newkey; in nilfs_btnode_abort_change_key()
344 xa_erase_irq(&btnc->i_pages, newkey); in nilfs_btnode_abort_change_key()
345 folio_unlock(ctxt->bh->b_folio); in nilfs_btnode_abort_change_key()