From: Nikolay Borisov <nborisov@suse.com>
To: Anand Jain <anand.jain@oracle.com>, linux-btrfs@vger.kernel.org
Cc: wqu@suse.com, dsterba@suse.com
Subject: Re: [PATCH 1/2] btrfs: drop never met condition of disk_total_bytes == 0
Date: Fri, 25 Sep 2020 09:19:02 +0300 [thread overview]
Message-ID: <b7c8399b-e410-8748-d1f3-f8603a8980ae@suse.com> (raw)
In-Reply-To: <bed38208-67ff-ac66-187e-7e8ad91e1968@oracle.com>
On 25.09.20 г. 7:17 ч., Anand Jain wrote:
>
>
> On 24/9/20 7:48 pm, Nikolay Borisov wrote:
>>
>>
>> On 24.09.20 г. 13:11 ч., Anand Jain wrote:
>>> btrfs_device::disk_total_bytes is set even for a seed device (the
>>> comment is wrong).
>>>
>>> The function fill_device_from_item() does the job of reading it from the
>>> item and updating btrfs_device::disk_total_bytes. So both the missing
>>> device and the seed devices do have their disk_total_bytes updated.
>>>
>>> So this patch removes the check dev->disk_total_bytes == 0 in the
>>> function verify_one_dev_extent()
>>>
>>> Signed-off-by: Anand Jain <anand.jain@oracle.com>
>>> ---
>>> fs/btrfs/volumes.c | 15 ---------------
>>> 1 file changed, 15 deletions(-)
>>>
>>> diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
>>> index 7f43ed88fffc..9be40eece8ed 100644
>>> --- a/fs/btrfs/volumes.c
>>> +++ b/fs/btrfs/volumes.c
>>> @@ -7578,21 +7578,6 @@ static int verify_one_dev_extent(struct
>>> btrfs_fs_info *fs_info,
>>> goto out;
>>> }
>>> - /* It's possible this device is a dummy for seed device */
>>> - if (dev->disk_total_bytes == 0) {
>>> - struct btrfs_fs_devices *devs;
>>> -
>>> - devs = list_first_entry(&fs_info->fs_devices->seed_list,
>>> - struct btrfs_fs_devices, seed_list);
>>> - dev = btrfs_find_device(devs, devid, NULL, NULL, false);
>>> - if (!dev) {
>>> - btrfs_err(fs_info, "failed to find seed devid %llu",
>>> - devid);
>>> - ret = -EUCLEAN;
>>> - goto out;
>>> - }
>>> - }
>>
>> The commit which introduced this check states that the device with a
>> disk_total_bytes = 0 occurs from clone_fs_devices called from open_seed.
>> It seems the check is legit and your changelog doesn't account for that
>> if it's safe you should provide description why is that.
>
> yes the commit 1b3922a8bc74 (btrfs: Use real device structure to verify
> dev extent) introduced it. In Qu's analysis, it is unclear why the
> total_disk_bytes was 0.
>
> Theoretically, all devices (including missing and seed) marked with the
> BTRFS_DEV_STATE_IN_FS_METADATA flag gets the total_disk_bytes updated at
> fill_device_from_item().
>
> open_ctree()
> btrfs_read_chunk_tree()
> read_one_dev()
> open_seed_device()
This function returns the cloned fs_devices whose devices are not
initialized. Later, in read_one_dev the 'device' is acquired from
fs_info->fs_devices, not from the returned fs_devices :
device = btrfs_find_device(fs_info->fs_devices, devid, dev_uuid,
fs_uuid, true);
And finally fill_device_from_item(leaf, dev_item, device); is called for
the device which was found from fs_info->fs_devices and not from the
returned 'fs_devices' from :
fs_devices = open_seed_devices(fs_info, fs_uuid);
What this means is that struct btrfs_device of devices in
fs_info->seed_list is never fully initialized.
> fill_device_from_item()
>
> Even if verify_one_dev_extent() reports total_disk_bytes == 0, then IMO
> its a bug to be fixed somewhere else and not in verify_one_dev_extent()
> as it's just a messenger. It is never expected that a total_disk_bytes
> shall be zero.
I agree, however this would involve fixing clone_fs_devices to properly
initialize struct btrfs_device. I'm in favor of removing special casing.
Looking closer into verify_one_dev_extent I see that the device is
referenced from fs_info->fs_devices :
dev = btrfs_find_device(fs_info->fs_devices, devid, NULL, NULL, true);
And indeed, it seems that all devices of fs_info->fs_devices are
initialized as per your above explanation. So yeah, your patch is
codewise correct but the changelog is wrong:
disk_total_bytes is never set for seed devices (seed devices are after
all housed in fs_info->seed_list which as I explained above doesn't
fully initialize btrfs_devices)
A better changelog would document following invariants:
1. Seed devices don't have their disktotal bytes initialized
2. In spite of (1), verify_dev_one_extent is never called for such
devices so it's fine because devices anchored at fs_info->fs_devices are
always properly initialized.
<snip>
next prev parent reply other threads:[~2020-09-25 6:19 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-09-24 10:11 [PATCH 0/2] fix verify_one_dev_extent and btrfs_find_device Anand Jain
2020-09-24 10:11 ` [PATCH 1/2] btrfs: drop never met condition of disk_total_bytes == 0 Anand Jain
2020-09-24 11:48 ` Nikolay Borisov
2020-09-24 11:58 ` Qu Wenruo
2020-09-24 12:19 ` Qu Wenruo
2020-09-25 4:17 ` Anand Jain
2020-09-25 6:19 ` Nikolay Borisov [this message]
2020-09-25 7:33 ` Anand Jain
2020-09-25 7:56 ` Nikolay Borisov
2020-09-25 8:12 ` Anand Jain
2020-10-05 13:22 ` Josef Bacik
2020-10-06 12:53 ` Anand Jain
2020-10-06 12:54 ` [PATCH v2 " Anand Jain
2020-10-21 4:16 ` [PATCH RESEND " Anand Jain
2020-10-21 14:35 ` Josef Bacik
2020-10-22 9:40 ` Anand Jain
2020-10-29 21:30 ` Anand Jain
2020-09-24 10:11 ` [PATCH 2/2] btrfs: fix btrfs_find_device unused arg seed Anand Jain
2020-09-24 10:21 ` Nikolay Borisov
2020-09-25 8:22 ` Nikolay Borisov
2020-09-25 8:42 ` Anand Jain
2020-10-05 13:23 ` Josef Bacik
2020-10-21 4:16 ` [PATCH RESEND " Anand Jain
2020-10-29 21:30 ` [PATCH RESEND v2 " Anand Jain
2020-10-02 3:14 ` [PATCH 0/2] fix verify_one_dev_extent and btrfs_find_device Anand Jain
2020-10-21 4:16 ` [PATCH RESEND " Anand Jain
2020-10-29 21:02 ` David Sterba
2020-10-29 21:14 ` Anand Jain
2020-11-11 15:49 ` David Sterba
2020-10-29 21:30 ` Anand Jain
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=b7c8399b-e410-8748-d1f3-f8603a8980ae@suse.com \
--to=nborisov@suse.com \
--cc=anand.jain@oracle.com \
--cc=dsterba@suse.com \
--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).