btrfs: init device stats for seed devices
authorJosef Bacik <josef@toxicpanda.com>
Fri, 18 Sep 2020 20:44:32 +0000 (16:44 -0400)
committerDavid Sterba <dsterba@suse.com>
Wed, 7 Oct 2020 10:17:58 +0000 (12:17 +0200)
commit124604eb50f88e6c1ff6587bdd2fc09bea810b32
treefc3b578808253f04b802fcf801469cab06829454
parent905eb88bceb253aa0f475eb04eec149d6059126e
btrfs: init device stats for seed devices

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.

Reviewed-by: Anand Jain <anand.jain@oracle.com>
Signed-off-by: Josef Bacik <josef@toxicpanda.com>
Reviewed-by: David Sterba <dsterba@suse.com>
[ rename to btrfs_device_init_dev_stats ]
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/volumes.c