From: Chandan Babu R <chandanrlinux@gmail.com>
To: "Darrick J. Wong" <darrick.wong@oracle.com>
Cc: linux-xfs@vger.kernel.org, david@fromorbit.com
Subject: Re: [PATCH 2/4] xfs: fix the minrecs logic when dealing with inode root child blocks
Date: Fri, 13 Nov 2020 12:05:32 +0530 [thread overview]
Message-ID: <1911194.Ks6Zr3F47T@garuda> (raw)
In-Reply-To: <160494586556.772802.12631379595730474933.stgit@magnolia>
On Monday 9 November 2020 11:47:45 PM IST Darrick J. Wong wrote:
> From: Darrick J. Wong <darrick.wong@oracle.com>
>
> The comment and logic in xchk_btree_check_minrecs for dealing with
> inode-rooted btrees isn't quite correct. While the direct children of
> the inode root are allowed to have fewer records than what would
> normally be allowed for a regular ondisk btree block, this is only true
> if there is only one child block and the number of records don't fit in
> the inode root.
>
The code changes are consistent with rules provided in the comments.
Reviewed-by: Chandan Babu R <chandanrlinux@gmail.com>
> Fixes: 08a3a692ef58 ("xfs: btree scrub should check minrecs")
> Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
> ---
> fs/xfs/scrub/btree.c | 45 +++++++++++++++++++++++++++------------------
> 1 file changed, 27 insertions(+), 18 deletions(-)
>
>
> diff --git a/fs/xfs/scrub/btree.c b/fs/xfs/scrub/btree.c
> index f52a7b8256f9..debf392e0515 100644
> --- a/fs/xfs/scrub/btree.c
> +++ b/fs/xfs/scrub/btree.c
> @@ -452,32 +452,41 @@ xchk_btree_check_minrecs(
> int level,
> struct xfs_btree_block *block)
> {
> - unsigned int numrecs;
> - int ok_level;
> -
> - numrecs = be16_to_cpu(block->bb_numrecs);
> + struct xfs_btree_cur *cur = bs->cur;
> + unsigned int root_level = cur->bc_nlevels - 1;
> + unsigned int numrecs = be16_to_cpu(block->bb_numrecs);
>
> /* More records than minrecs means the block is ok. */
> - if (numrecs >= bs->cur->bc_ops->get_minrecs(bs->cur, level))
> + if (numrecs >= cur->bc_ops->get_minrecs(cur, level))
> return;
>
> /*
> - * Certain btree blocks /can/ have fewer than minrecs records. Any
> - * level greater than or equal to the level of the highest dedicated
> - * btree block are allowed to violate this constraint.
> - *
> - * For a btree rooted in a block, the btree root can have fewer than
> - * minrecs records. If the btree is rooted in an inode and does not
> - * store records in the root, the direct children of the root and the
> - * root itself can have fewer than minrecs records.
> + * For btrees rooted in the inode, it's possible that the root block
> + * contents spilled into a regular ondisk block because there wasn't
> + * enough space in the inode root. The number of records in that
> + * child block might be less than the standard minrecs, but that's ok
> + * provided that there's only one direct child of the root.
> */
> - ok_level = bs->cur->bc_nlevels - 1;
> - if (bs->cur->bc_flags & XFS_BTREE_ROOT_IN_INODE)
> - ok_level--;
> - if (level >= ok_level)
> + if ((cur->bc_flags & XFS_BTREE_ROOT_IN_INODE) &&
> + level == cur->bc_nlevels - 2) {
> + struct xfs_btree_block *root_block;
> + struct xfs_buf *root_bp;
> + int root_maxrecs;
> +
> + root_block = xfs_btree_get_block(cur, root_level, &root_bp);
> + root_maxrecs = cur->bc_ops->get_dmaxrecs(cur, root_level);
> + if (be16_to_cpu(root_block->bb_numrecs) != 1 ||
> + numrecs <= root_maxrecs)
> + xchk_btree_set_corrupt(bs->sc, cur, level);
> return;
> + }
>
> - xchk_btree_set_corrupt(bs->sc, bs->cur, level);
> + /*
> + * Otherwise, only the root level is allowed to have fewer than minrecs
> + * records or keyptrs.
> + */
> + if (level < root_level)
> + xchk_btree_set_corrupt(bs->sc, cur, level);
> }
>
> /*
>
>
--
chandan
next prev parent reply other threads:[~2020-11-13 6:35 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-11-09 18:17 [PATCH 0/4] xfs: fix various scrub problems Darrick J. Wong
2020-11-09 18:17 ` [PATCH 1/4] xfs: fix brainos in the refcount scrubber's rmap fragment processor Darrick J. Wong
2020-11-10 18:35 ` Christoph Hellwig
2020-11-12 12:51 ` Chandan Babu R
2020-11-12 16:05 ` Darrick J. Wong
2020-11-13 5:11 ` Chandan Babu R
2020-11-09 18:17 ` [PATCH 2/4] xfs: fix the minrecs logic when dealing with inode root child blocks Darrick J. Wong
2020-11-13 6:35 ` Chandan Babu R [this message]
2020-11-14 10:39 ` Christoph Hellwig
2020-11-09 18:17 ` [PATCH 3/4] xfs: strengthen rmap record flags checking Darrick J. Wong
2020-11-13 7:02 ` Chandan Babu R
2020-11-14 10:40 ` Christoph Hellwig
2020-11-09 18:17 ` [PATCH 4/4] xfs: directory scrub should check the null bestfree entries too Darrick J. Wong
2020-11-13 9:08 ` Chandan Babu R
2020-11-14 10:40 ` Christoph Hellwig
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=1911194.Ks6Zr3F47T@garuda \
--to=chandanrlinux@gmail.com \
--cc=darrick.wong@oracle.com \
--cc=david@fromorbit.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