From: Brian Foster <bfoster@redhat.com>
To: "Darrick J. Wong" <darrick.wong@oracle.com>
Cc: linux-xfs@vger.kernel.org
Subject: Re: [PATCH 1/7] xfs: introduce fake roots for ag-rooted btrees
Date: Fri, 13 Mar 2020 10:47:12 -0400 [thread overview]
Message-ID: <20200313144712.GA11929@bfoster> (raw)
In-Reply-To: <158398473702.1308059.5932849079464881055.stgit@magnolia>
On Wed, Mar 11, 2020 at 08:45:37PM -0700, Darrick J. Wong wrote:
> From: Darrick J. Wong <darrick.wong@oracle.com>
>
> 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@oracle.com>
> ---
> fs/xfs/libxfs/xfs_btree.c | 168 +++++++++++++++++++++++++++++++++++++++++++++
> fs/xfs/libxfs/xfs_btree.h | 30 ++++++++
> fs/xfs/xfs_trace.h | 28 ++++++++
> 3 files changed, 225 insertions(+), 1 deletion(-)
>
>
> diff --git a/fs/xfs/libxfs/xfs_btree.c b/fs/xfs/libxfs/xfs_btree.c
> index 4ef9f0b42c7f..085bc070e804 100644
> --- a/fs/xfs/libxfs/xfs_btree.c
> +++ b/fs/xfs/libxfs/xfs_btree.c
...
> @@ -4908,3 +4910,169 @@ xfs_btree_has_more_records(
> else
> return block->bb_u.s.bb_rightsib != cpu_to_be32(NULLAGBLOCK);
> }
> +
...
> +/*
> + * Initialize a AG-rooted btree cursor with the given AG btree fake root. The
> + * btree cursor's bc_ops will be overridden as needed to make the staging
> + * functionality work. If new_ops is not NULL, these new ops will be passed
> + * out to the caller for further overriding.
> + */
> +void
> +xfs_btree_stage_afakeroot(
> + struct xfs_btree_cur *cur,
> + struct xbtree_afakeroot *afake,
> + struct xfs_btree_ops **new_ops)
> +{
> + struct xfs_btree_ops *nops;
> +
> + ASSERT(!(cur->bc_flags & XFS_BTREE_STAGING));
> + ASSERT(!(cur->bc_flags & XFS_BTREE_ROOT_IN_INODE));
> + ASSERT(cur->bc_tp == NULL);
> +
> + nops = kmem_alloc(sizeof(struct xfs_btree_ops), KM_NOFS);
> + memcpy(nops, cur->bc_ops, sizeof(struct xfs_btree_ops));
> + nops->alloc_block = xfs_btree_fakeroot_alloc_block;
> + nops->free_block = xfs_btree_fakeroot_free_block;
> + nops->init_ptr_from_cur = xfs_btree_fakeroot_init_ptr_from_cur;
> + nops->set_root = xfs_btree_afakeroot_set_root;
> + nops->dup_cursor = xfs_btree_fakeroot_dup_cursor;
> +
> + cur->bc_ag.afake = afake;
> + cur->bc_nlevels = afake->af_levels;
> + cur->bc_ops = nops;
> + cur->bc_flags |= XFS_BTREE_STAGING;
> +
> + if (new_ops)
> + *new_ops = nops;
Curious why we have new_ops if the caller unconditionally assigns
->bc_ops to the same value..? That aside:
Reviewed-by: Brian Foster <bfoster@redhat.com>
> +}
> +
> +/*
> + * Transform an AG-rooted staging btree cursor back into a regular cursor by
> + * substituting a real btree root for the fake one and restoring normal btree
> + * cursor ops. The caller must log the btree root change prior to calling
> + * this.
> + */
> +void
> +xfs_btree_commit_afakeroot(
> + struct xfs_btree_cur *cur,
> + struct xfs_trans *tp,
> + struct xfs_buf *agbp,
> + const struct xfs_btree_ops *ops)
> +{
> + ASSERT(cur->bc_flags & XFS_BTREE_STAGING);
> + ASSERT(cur->bc_tp == NULL);
> +
> + trace_xfs_btree_commit_afakeroot(cur);
> +
> + kmem_free((void *)cur->bc_ops);
> + cur->bc_ag.agbp = agbp;
> + cur->bc_ops = ops;
> + cur->bc_flags &= ~XFS_BTREE_STAGING;
> + cur->bc_tp = tp;
> +}
> diff --git a/fs/xfs/libxfs/xfs_btree.h b/fs/xfs/libxfs/xfs_btree.h
> index 0d10bbd5223a..aa4a7bd40023 100644
> --- a/fs/xfs/libxfs/xfs_btree.h
> +++ b/fs/xfs/libxfs/xfs_btree.h
> @@ -179,7 +179,10 @@ union xfs_btree_irec {
>
> /* Per-AG btree information. */
> struct xfs_btree_cur_ag {
> - struct xfs_buf *agbp;
> + union {
> + struct xfs_buf *agbp;
> + struct xbtree_afakeroot *afake; /* fake ag header root */
> + };
> xfs_agnumber_t agno;
> union {
> struct {
> @@ -235,6 +238,12 @@ typedef struct xfs_btree_cur
> #define XFS_BTREE_LASTREC_UPDATE (1<<2) /* track last rec externally */
> #define XFS_BTREE_CRC_BLOCKS (1<<3) /* uses extended btree blocks */
> #define XFS_BTREE_OVERLAPPING (1<<4) /* overlapping intervals */
> +/*
> + * The root of this btree is a fakeroot structure so that we can stage a btree
> + * rebuild without leaving it accessible via primary metadata. The ops struct
> + * is dynamically allocated and must be freed when the cursor is deleted.
> + */
> +#define XFS_BTREE_STAGING (1<<5)
>
>
> #define XFS_BTREE_NOERROR 0
> @@ -515,4 +524,23 @@ xfs_btree_islastblock(
> return block->bb_u.s.bb_rightsib == cpu_to_be32(NULLAGBLOCK);
> }
>
> +/* Fake root for an AG-rooted btree. */
> +struct xbtree_afakeroot {
> + /* AG block number of the new btree root. */
> + xfs_agblock_t af_root;
> +
> + /* Height of the new btree. */
> + unsigned int af_levels;
> +
> + /* Number of blocks used by the btree. */
> + unsigned int af_blocks;
> +};
> +
> +/* Cursor interactions with with fake roots for AG-rooted btrees. */
> +void xfs_btree_stage_afakeroot(struct xfs_btree_cur *cur,
> + struct xbtree_afakeroot *afake,
> + struct xfs_btree_ops **new_ops);
> +void xfs_btree_commit_afakeroot(struct xfs_btree_cur *cur, struct xfs_trans *tp,
> + struct xfs_buf *agbp, const struct xfs_btree_ops *ops);
> +
> #endif /* __XFS_BTREE_H__ */
> diff --git a/fs/xfs/xfs_trace.h b/fs/xfs/xfs_trace.h
> index 059c3098a4a0..d8c229492973 100644
> --- a/fs/xfs/xfs_trace.h
> +++ b/fs/xfs/xfs_trace.h
> @@ -3605,6 +3605,34 @@ TRACE_EVENT(xfs_check_new_dalign,
> __entry->calc_rootino)
> )
>
> +TRACE_EVENT(xfs_btree_commit_afakeroot,
> + TP_PROTO(struct xfs_btree_cur *cur),
> + TP_ARGS(cur),
> + TP_STRUCT__entry(
> + __field(dev_t, dev)
> + __field(xfs_btnum_t, btnum)
> + __field(xfs_agnumber_t, agno)
> + __field(xfs_agblock_t, agbno)
> + __field(unsigned int, levels)
> + __field(unsigned int, blocks)
> + ),
> + TP_fast_assign(
> + __entry->dev = cur->bc_mp->m_super->s_dev;
> + __entry->btnum = cur->bc_btnum;
> + __entry->agno = cur->bc_ag.agno;
> + __entry->agbno = cur->bc_ag.afake->af_root;
> + __entry->levels = cur->bc_ag.afake->af_levels;
> + __entry->blocks = cur->bc_ag.afake->af_blocks;
> + ),
> + TP_printk("dev %d:%d btree %s ag %u levels %u blocks %u root %u",
> + MAJOR(__entry->dev), MINOR(__entry->dev),
> + __print_symbolic(__entry->btnum, XFS_BTNUM_STRINGS),
> + __entry->agno,
> + __entry->levels,
> + __entry->blocks,
> + __entry->agbno)
> +)
> +
> #endif /* _TRACE_XFS_H */
>
> #undef TRACE_INCLUDE_PATH
>
next prev parent reply other threads:[~2020-03-13 14:47 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-03-12 3:45 [PATCH v4 0/7] xfs: btree bulk loading Darrick J. Wong
2020-03-12 3:45 ` [PATCH 1/7] xfs: introduce fake roots for ag-rooted btrees Darrick J. Wong
2020-03-13 14:47 ` Brian Foster [this message]
2020-03-13 16:30 ` Darrick J. Wong
2020-03-12 3:45 ` [PATCH 2/7] xfs: introduce fake roots for inode-rooted btrees Darrick J. Wong
2020-03-13 14:47 ` Brian Foster
2020-03-13 16:32 ` Darrick J. Wong
2020-03-12 3:45 ` [PATCH 3/7] xfs: support bulk loading of staged btrees Darrick J. Wong
2020-03-13 14:49 ` Brian Foster
2020-03-13 16:28 ` Darrick J. Wong
2020-03-12 3:45 ` [PATCH 4/7] xfs: add support for free space btree staging cursors Darrick J. Wong
2020-03-12 3:46 ` [PATCH 5/7] xfs: add support for inode " Darrick J. Wong
2020-03-12 3:46 ` [PATCH 6/7] xfs: add support for refcount " Darrick J. Wong
2020-03-12 3:46 ` [PATCH 7/7] xfs: add support for rmap " Darrick J. Wong
-- strict thread matches above, loose matches on Subject: below --
2020-03-15 23:50 [PATCH v5 0/7] xfs: btree bulk loading Darrick J. Wong
2020-03-15 23:50 ` [PATCH 1/7] xfs: introduce fake roots for ag-rooted btrees Darrick J. Wong
2020-03-16 10:41 ` Christoph Hellwig
2020-03-16 15:03 ` Darrick J. Wong
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200313144712.GA11929@bfoster \
--to=bfoster@redhat.com \
--cc=darrick.wong@oracle.com \
--cc=linux-xfs@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox