From: Martin Steigerwald <martin@lichtvoll.de>
To: linux-btrfs@vger.kernel.org, Qu Wenruo <wqu@suse.com>
Subject: Re: [PATCH] btrfs: fix false alert caused by legacy btrfs root item
Date: Mon, 05 Oct 2020 17:29:51 +0200 [thread overview]
Message-ID: <1786699.e55IGcOCre@merkaba> (raw)
In-Reply-To: <20200922023701.32654-1-wqu@suse.com>
Hi Qu!
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.
Is this going into 5.9? Asking cause it is not in 5.9-rc8.
Of course I can keep the patch and as the external disk has been fixed, I
would not even need it anymore.
Best,
Martin
> 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-10-05 15:30 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
[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 [this message]
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=1786699.e55IGcOCre@merkaba \
--to=martin@lichtvoll.de \
--cc=linux-btrfs@vger.kernel.org \
--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).