bh = nilfs_grab_buffer(inode, btnc, blocknr, BIT(BH_NILFS_Node)); if (unlikely(!bh)) return ERR_PTR(-ENOMEM);
if (unlikely(buffer_mapped(bh) || buffer_uptodate(bh) ||
buffer_dirty(bh))) { /* * The block buffer at the specified new address was already * in use. This can happen if it is a virtual block number * and has been reallocated due to corruption of the bitmap * used to manage its allocation state (if not, the buffer * clearing of an abandoned b-tree node is missing somewhere).
*/
nilfs_error(inode->i_sb, "state inconsistency probably due to duplicate use of b-tree node block address %llu (ino=%lu)",
(unsignedlonglong)blocknr, inode->i_ino); goto failed;
}
memset(bh->b_data, 0, i_blocksize(inode));
bh->b_blocknr = blocknr;
set_buffer_mapped(bh);
set_buffer_uptodate(bh);
/** * nilfs_btnode_delete - delete B-tree node buffer * @bh: buffer to be deleted * * nilfs_btnode_delete() invalidates the specified buffer and delete the page * including the buffer if the page gets unbusy.
*/ void nilfs_btnode_delete(struct buffer_head *bh)
{ struct address_space *mapping; struct folio *folio = bh->b_folio;
pgoff_t index = folio->index; int still_dirty;
if (!still_dirty && mapping)
invalidate_inode_pages2_range(mapping, index, index);
}
/** * nilfs_btnode_prepare_change_key - prepare to change the search key of a * b-tree node block * @btnc: page cache in which the b-tree node block is buffered * @ctxt: structure for exchanging context information for key change * * nilfs_btnode_prepare_change_key() prepares to move the contents of the * b-tree node block of the old key given in the "oldkey" member of @ctxt to * the position of the new key given in the "newkey" member of @ctxt in the * page cache @btnc. Here, the key of the block is an index in units of * blocks, and if the page and block sizes match, it matches the page index * in the page cache. * * If the page size and block size match, this function attempts to move the * entire folio, and in preparation for this, inserts the original folio into * the new index of the cache. If this insertion fails or if the page size * and block size are different, it falls back to a copy preparation using * nilfs_btnode_create_block(), inserts a new block at the position * corresponding to "newkey", and stores the buffer head pointer in the * "newbh" member of @ctxt. * * Note that the current implementation does not support folio sizes larger * than the page size. * * Return: 0 on success, or one of the following negative error codes on * failure: * * %-EIO - I/O error (metadata corruption). * * %-ENOMEM - Insufficient memory available.
*/ int nilfs_btnode_prepare_change_key(struct address_space *btnc, struct nilfs_btnode_chkey_ctxt *ctxt)
{ struct buffer_head *obh, *nbh; struct inode *inode = btnc->host;
__u64 oldkey = ctxt->oldkey, newkey = ctxt->newkey; int err;
xa_lock_irq(&btnc->i_pages);
err = __xa_insert(&btnc->i_pages, newkey, ofolio, GFP_NOFS);
xa_unlock_irq(&btnc->i_pages); /* * Note: folio->index will not change to newkey until * nilfs_btnode_commit_change_key() will be called. * To protect the folio in intermediate state, the folio lock * is held.
*/ if (!err) return 0; elseif (err != -EBUSY) goto failed_unlock;
err = invalidate_inode_pages2_range(btnc, newkey, newkey); if (!err) goto retry; /* fallback to copy mode */
folio_unlock(ofolio);
}
nbh = nilfs_btnode_create_block(btnc, newkey); if (IS_ERR(nbh)) return PTR_ERR(nbh);
/** * nilfs_btnode_commit_change_key - commit the change of the search key of * a b-tree node block * @btnc: page cache in which the b-tree node block is buffered * @ctxt: structure for exchanging context information for key change * * nilfs_btnode_commit_change_key() executes the key change based on the * context @ctxt prepared by nilfs_btnode_prepare_change_key(). If no valid * block buffer is prepared in "newbh" of @ctxt (i.e., a full folio move), * this function removes the folio from the old index and completes the move. * Otherwise, it copies the block data and inherited flag states of "oldbh" * to "newbh" and clears the "oldbh" from the cache. In either case, the * relocated buffer is marked as dirty. * * As with nilfs_btnode_prepare_change_key(), the current implementation does * not support folio sizes larger than the page size.
*/ void nilfs_btnode_commit_change_key(struct address_space *btnc, struct nilfs_btnode_chkey_ctxt *ctxt)
{ struct buffer_head *obh = ctxt->bh, *nbh = ctxt->newbh;
__u64 oldkey = ctxt->oldkey, newkey = ctxt->newkey; struct folio *ofolio;
/** * nilfs_btnode_abort_change_key - abort the change of the search key of a * b-tree node block * @btnc: page cache in which the b-tree node block is buffered * @ctxt: structure for exchanging context information for key change * * nilfs_btnode_abort_change_key() cancels the key change associated with the * context @ctxt prepared via nilfs_btnode_prepare_change_key() and performs * any necessary cleanup. If no valid block buffer is prepared in "newbh" of * @ctxt, this function removes the folio from the destination index and aborts * the move. Otherwise, it clears "newbh" from the cache. * * As with nilfs_btnode_prepare_change_key(), the current implementation does * not support folio sizes larger than the page size.
*/ void nilfs_btnode_abort_change_key(struct address_space *btnc, struct nilfs_btnode_chkey_ctxt *ctxt)
{ struct buffer_head *nbh = ctxt->newbh;
__u64 oldkey = ctxt->oldkey, newkey = ctxt->newkey;
if (oldkey == newkey) return;
if (nbh == NULL) { /* blocksize == pagesize */
xa_erase_irq(&btnc->i_pages, newkey);
folio_unlock(ctxt->bh->b_folio);
} else { /* * When canceling a buffer that a prepare operation has * allocated to copy a node block to another location, use * nilfs_btnode_delete() to initialize and release the buffer * so that the buffer flags will not be in an inconsistent * state when it is reallocated.
*/
nilfs_btnode_delete(nbh);
}
}
Messung V0.5
¤ Dauer der Verarbeitung: 0.12 Sekunden
(vorverarbeitet)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.