Re: [PATCH 1/2] btrfs: init device stats for seed devices

David Sterba
2020-09-22T17:13:58Z

On Fri, Sep 18, 2020 at 04:44:32PM -0400, Josef Bacik wrote:
> We recently started recording device stats across the fleet, and noticed
> a large increase in messages such as this
>
> BTRFS warning (device dm-0): get dev_stats failed, not yet valid
>
> on our tiers that use seed devices for their root devices. This is
> because we do not initialize the device stats for any seed devices if we
> have a sprout device and mount using that sprout device. The basic
> steps for reproducing are
>
> mkfs seed device
> mount seed device
> fill seed device
> umount seed device
> btrfstune -S 1 seed device
> mount seed device
> btrfs device add -f sprout device /mnt/wherever
> umount /mnt/wherever
> mount sprout device /mnt/wherever
> btrfs device stats /mnt/wherever
>
> This will fail with the above message in dmesg.
>
> Fix this by iterating over the fs_devices->seed if they exist in
> btrfs_init_dev_stats. This fixed the problem and properly reports the
> stats for both devices.
>
> Signed-off-by: Josef Bacik <josef@toxicpanda.com>
> ---
> fs/btrfs/volumes.c | 88 +++++++++++++++++++++++++---------------------
> 1 file changed, 48 insertions(+), 40 deletions(-)
>
> diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
> index 6c7c8819cb31..c0cea9f5fdbc 100644
> --- a/fs/btrfs/volumes.c
> +++ b/fs/btrfs/volumes.c
> @@ -7223,61 +7223,69 @@ static void btrfs_set_dev_stats_value(struct extent_buffer *eb,
> sizeof(val));
> }
>
> -int btrfs_init_dev_stats(struct btrfs_fs_info *fs_info)
> +static void __btrfs_init_dev_stats(struct btrfs_fs_info *fs_info,
> + struct btrfs_device *device,
> + struct btrfs_path *path)

__ is not necessary and can be avoided by naming the function properly,
as it initializes the stats on a device

> {
> - struct btrfs_key key;
> struct btrfs_root *dev_root = fs_info->dev_root;

The fs_info parameter is used only once, just to read the dev_root, that
is also used just once. Both can be obtained from the @device.

The path is passed for convenience as it's reused and allocated out of
mutex, so that's fine for a helper.