From: Martin Steigerwald <martin@lichtvoll.de>
To: linux-btrfs@vger.kernel.org, Qu Wenruo <wqu@suse.com>,
Qu Wenruo <quwenruo.btrfs@gmx.com>
Subject: Re: [PATCH] btrfs: fix false alert caused by legacy btrfs root item
Date: Tue, 22 Sep 2020 19:17:19 +0200 [thread overview]
Message-ID: <10820501.WrPryYWVak@merkaba> (raw)
In-Reply-To: <6db35b15-1f16-dfd8-368c-b03e428eba08@gmx.com>
Qu Wenruo - 22.09.20, 12:34:18 CEST:
> On 2020/9/22 下午6:20, Martin Steigerwald wrote:
> > Instead of the tool, can I also patch my kernel with the patch below
> > to have it automatically fix it?
>
> Sure, this one is a little safer than the tool.
>
> > If so, which approach would you prefer for testing?
> >
> > I can apply the patch as I compile kernels myself.
>
> That's great.
>
> That should solve the problem.
>
> And if you don't like the legacy root item, just do a balance (no
> matter data or metadata), and that legacy root item will be converted
> to current one, and even affected kernel won't report any error any
> more.
Tested with patch. No error message :)
Tested-By: Martin Steigerwald <martin@lichtvoll.de>
Will do balance once I know whether a minimal one is enough. Can test
with old unpatched kernel then as well. Both 5.9-rc5, as 5.9-rc6 didn't
compile for some reason.
Thanks,
Martin
> > Qu Wenruo - 22.09.20, 04:37:01 CEST:
> >> Commit 259ee7754b67 ("btrfs: tree-checker: Add ROOT_ITEM check")
> >> introduced btrfs root item size check, however btrfs root item has
> >> two format, the legacy one which just ends before generation_v2
> >> member, is smaller than current btrfs root item size.
> >>
> >> This caused btrfs kernel to reject valid but old tree root leaves.
> >>
> >> Fix this problem by also allowing legacy root item, since kernel
> >> can
> >> already handle them pretty well and upgrade to newer root item
> >> format
> >> when needed.
> >>
> >> Reported-by: Martin Steigerwald <martin@lichtvoll.de>
> >> Fixes: 259ee7754b67 ("btrfs: tree-checker: Add ROOT_ITEM check")
> >> Signed-off-by: Qu Wenruo <wqu@suse.com>
> >> ---
> >>
> >> fs/btrfs/tree-checker.c | 17 ++++++++++++-----
> >> include/uapi/linux/btrfs_tree.h | 9 +++++++++
> >> 2 files changed, 21 insertions(+), 5 deletions(-)
> >>
> >> diff --git a/fs/btrfs/tree-checker.c b/fs/btrfs/tree-checker.c
> >> index 7b1fee630f97..6f794aca48d3 100644
> >> --- a/fs/btrfs/tree-checker.c
> >> +++ b/fs/btrfs/tree-checker.c
> >> @@ -1035,7 +1035,7 @@ static int check_root_item(struct
> >> extent_buffer
> >> *leaf, struct btrfs_key *key, int slot)
> >>
> >> {
> >>
> >> struct btrfs_fs_info *fs_info = leaf->fs_info;
> >>
> >> - struct btrfs_root_item ri;
> >> + struct btrfs_root_item ri = { 0 };
> >>
> >> const u64 valid_root_flags = BTRFS_ROOT_SUBVOL_RDONLY |
> >>
> >> BTRFS_ROOT_SUBVOL_DEAD;
> >>
> >> int ret;
> >>
> >> @@ -1044,14 +1044,21 @@ static int check_root_item(struct
> >> extent_buffer *leaf, struct btrfs_key *key, if (ret < 0)
> >>
> >> return ret;
> >>
> >> - if (btrfs_item_size_nr(leaf, slot) != sizeof(ri)) {
> >> + if (btrfs_item_size_nr(leaf, slot) != sizeof(ri) &&
> >> + btrfs_item_size_nr(leaf, slot) !=
> >
> > btrfs_legacy_root_item_size())
> >
> >> { generic_err(leaf, slot,
> >> - "invalid root item size, have %u expect %zu",
> >> - btrfs_item_size_nr(leaf, slot), sizeof(ri));
> >> + "invalid root item size, have %u expect %zu or
> >
> > %zu",
> >
> >> + btrfs_item_size_nr(leaf, slot), sizeof(ri),
> >> + btrfs_legacy_root_item_size());
> >>
> >> }
> >>
> >> + /*
> >> + * For legacy root item, the members starting at generation_v2
> >
> > will
> >
> >> be + * all filled with 0.
> >> + * And since we allow geneartion_v2 as 0, it will still pass the
> >> check. + */
> >>
> >> read_extent_buffer(leaf, &ri, btrfs_item_ptr_offset(leaf, slot),
> >>
> >> - sizeof(ri));
> >> + btrfs_item_size_nr(leaf, slot));
> >>
> >> /* Generation related */
> >> if (btrfs_root_generation(&ri) >
> >>
> >> diff --git a/include/uapi/linux/btrfs_tree.h
> >> b/include/uapi/linux/btrfs_tree.h index 9ba64ca6b4ac..464095a28b18
> >> 100644
> >> --- a/include/uapi/linux/btrfs_tree.h
> >> +++ b/include/uapi/linux/btrfs_tree.h
> >> @@ -644,6 +644,15 @@ struct btrfs_root_item {
> >>
> >> __le64 reserved[8]; /* for future */
> >>
> >> } __attribute__ ((__packed__));
> >>
> >> +/*
> >> + * Btrfs root item used to be smaller than current size.
> >> + * The old format ends at where member generation_v2 is.
> >> + */
> >> +static inline size_t btrfs_legacy_root_item_size(void)
> >> +{
> >> + return offsetof(struct btrfs_root_item, generation_v2);
> >> +}
> >> +
> >>
> >> /*
> >>
> >> * this is used for both forward and backward root refs
> >> */
--
Martin
next prev parent reply other threads:[~2020-09-22 17:17 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-09-22 2:37 [PATCH] btrfs: fix false alert caused by legacy btrfs root item Qu Wenruo
2020-09-22 10:20 ` Martin Steigerwald
2020-09-22 10:34 ` Qu Wenruo
2020-09-22 15:48 ` Martin Steigerwald
2020-09-22 23:17 ` Qu Wenruo
2020-09-23 19:41 ` Martin Steigerwald
2020-09-24 0:07 ` Qu Wenruo
2020-09-24 6:17 ` Martin Steigerwald
2020-09-22 17:17 ` Martin Steigerwald [this message]
[not found] ` <202009221943.4vKWL4lC%lkp@intel.com>
2020-09-22 11:31 ` Qu Wenruo
2020-09-22 20:51 ` Josef Bacik
2020-09-23 6:23 ` kernel test robot
2020-09-23 9:31 ` David Sterba
2020-09-23 10:28 ` Qu Wenruo
2020-09-23 17:08 ` David Sterba
2020-09-23 9:43 ` David Sterba
2020-10-05 15:29 ` Martin Steigerwald
2020-10-06 0:19 ` Qu Wenruo
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=10820501.WrPryYWVak@merkaba \
--to=martin@lichtvoll.de \
--cc=linux-btrfs@vger.kernel.org \
--cc=quwenruo.btrfs@gmx.com \
--cc=wqu@suse.com \
/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;
as well as URLs for NNTP newsgroup(s).