On Wed, Mar 04, 2020 at 03:34:59PM -0800, Darrick J. Wong wrote: > On Wed, Mar 04, 2020 at 01:21:03PM -0500, Brian Foster wrote: > > On Tue, Mar 03, 2020 at 07:28:28PM -0800, Darrick J. Wong wrote: > > > From: Darrick J. Wong <darrick.wong@xxxxxxxxxx> > > > > > > Create an in-core fake root for AG-rooted btree types so that callers > > > can generate a whole new btree using the upcoming btree bulk load > > > function without making the new tree accessible from the rest of the > > > filesystem. It is up to the individual btree type to provide a function > > > to create a staged cursor (presumably with the appropriate callouts to > > > update the fakeroot) and then commit the staged root back into the > > > filesystem. > > > > > > Signed-off-by: Darrick J. Wong <darrick.wong@xxxxxxxxxx> > > > --- > > > > The code all seems reasonable, mostly infrastructure. Just a few high > > level comments.. > > > > It would be helpful if the commit log (or code comments) explained more > > about the callouts that are replaced for a staging tree (and why). > > Ok. I have two block comments to add. > > > > fs/xfs/libxfs/xfs_btree.c | 117 +++++++++++++++++++++++++++++++++++++++++++++ > > > fs/xfs/libxfs/xfs_btree.h | 42 ++++++++++++++-- > > > fs/xfs/xfs_trace.h | 28 +++++++++++ > > > 3 files changed, 182 insertions(+), 5 deletions(-) > > > > > > > > > diff --git a/fs/xfs/libxfs/xfs_btree.c b/fs/xfs/libxfs/xfs_btree.c > > > index e6f898bf3174..9a7c1a4d0423 100644 > > > --- a/fs/xfs/libxfs/xfs_btree.c > > > +++ b/fs/xfs/libxfs/xfs_btree.c > > > @@ -382,6 +382,8 @@ xfs_btree_del_cursor( > > > /* > > > * Free the cursor. > > > */ > > > + if (unlikely(cur->bc_flags & XFS_BTREE_STAGING)) > > > + kmem_free((void *)cur->bc_ops); > > > kmem_cache_free(xfs_btree_cur_zone, cur); > > > } > > > > > > @@ -4908,3 +4910,118 @@ xfs_btree_has_more_records( > > > else > > > return block->bb_u.s.bb_rightsib != cpu_to_be32(NULLAGBLOCK); > > > } > > Add here a new comment: > > /* > * Staging Cursors and Fake Roots for Btrees > * ========================================= > * > * A staging btree cursor is a special type of btree cursor that callers > * must use to construct a new btree index using the btree bulk loader > * code. The bulk loading code uses the staging btree cursor to > * abstract the details of initializing new btree blocks and filling > * them with records or key/ptr pairs. Regular btree operations (e.g. > * queries and modifications) are not supported with staging cursors, > * and callers must not invoke them. > * > * Fake root structures contain all the information about a btree that > * is under construction by the bulk loading code. Staging btree > * cursors point to fake root structures instead of the usual AG header > * or inode structure. > * > * Callers are expected to initialize a fake root structure and pass it > * into the _stage_cursor function for a specific btree type. When bulk > * loading is complete, callers should call the _commit_staged_btree > * function for that specific btree type to commit the new btree into > * the filesystem. > */ > > > > > + > > > +/* We don't allow staging cursors to be duplicated. */ > > /* > * Don't allow staging cursors to be duplicated because they're supposed > * to be kept private to a single thread. > */ private to a single -thread- or a single -btree modification context-? Cheers, Dave. -- Dave Chinner david@xxxxxxxxxxxxx