linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Qu Wenruo <wqu@suse.com>
To: Martin Steigerwald <martin@lichtvoll.de>,
	linux-btrfs@vger.kernel.org, Qu Wenruo <quwenruo.btrfs@gmx.com>
Subject: Re: [PATCH] btrfs: fix false alert caused by legacy btrfs root item
Date: Wed, 23 Sep 2020 07:17:01 +0800	[thread overview]
Message-ID: <ec3a5769-a847-6b3d-d502-b96c053b070f@suse.com> (raw)
In-Reply-To: <8998433.IpVEtotQbC@merkaba>



On 2020/9/22 下午11:48, Martin Steigerwald wrote:
> 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.
> 
> Thanks.
> 
>>> 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.
> 
> Can I get away with a minimal balance? Or does it need to be a full one?

Minimal is enough.
You just need to balance one chunk.

You can confirm it with "btrfs ins dump-tree -t root <device>".
If DATA_RELOC_TREE item size is still 249, it's legacy one.
If it's 429, then it's the current one.

Thanks,
Qu
> 
> Best,
> 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
>>>>   */
> 
> 


  reply	other threads:[~2020-09-22 23: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 [this message]
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
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=ec3a5769-a847-6b3d-d502-b96c053b070f@suse.com \
    --to=wqu@suse.com \
    --cc=linux-btrfs@vger.kernel.org \
    --cc=martin@lichtvoll.de \
    --cc=quwenruo.btrfs@gmx.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).