]> Git Repo - linux.git/commitdiff
Btrfs: init device stats for new devices
authorStefan Behrens <[email protected]>
Fri, 11 Oct 2013 13:20:42 +0000 (15:20 +0200)
committerChris Mason <[email protected]>
Tue, 12 Nov 2013 03:01:09 +0000 (22:01 -0500)
Device stats are only initialized (read from tree items) on mount.
Trying to read device stats after adding or replacing new devices will
return errors.

btrfs_init_new_device() and btrfs_init_dev_replace_tgtdev() are the two
functions that allocate and initialize new btrfs_device structures after
a filesystem is mounted. They set the device stats to zero by using
kzalloc() which is correct for new devices. The only missing thing was
to declare these stats as being valid (device->dev_stats_valid = 1) and
this patch adds this missing code.

This is the reproducer:

TEST_DEV1=/dev/sdzzzzz1
TEST_DEV2=/dev/sdzzzzz2
TEST_DEV3=/dev/sdzzzzz3
TEST_MNT=/mnt
mkfs.btrfs $TEST_DEV1
mount $TEST_DEV1 $TEST_MNT
btrfs device add $TEST_DEV2 $TEST_MNT
btrfs device stat $TEST_MNT
btrfs replace start -B $TEST_DEV2 $TEST_DEV3 $TEST_MNT
btrfs device stat $TEST_MNT
umount $TEST_MNT

Reported-by: Ondrej Kunc <[email protected]>
Signed-off-by: Stefan Behrens <[email protected]>
Signed-off-by: Josef Bacik <[email protected]>
Signed-off-by: Chris Mason <[email protected]>
fs/btrfs/volumes.c

index 5d7ea267d8ff69df2f3faf12850f752962651c56..f492f7eabf29e9df47ba88f7d8c0e230066d515c 100644 (file)
@@ -2042,6 +2042,7 @@ int btrfs_init_new_device(struct btrfs_root *root, char *device_path)
        device->in_fs_metadata = 1;
        device->is_tgtdev_for_dev_replace = 0;
        device->mode = FMODE_EXCL;
+       device->dev_stats_valid = 1;
        set_blocksize(device->bdev, 4096);
 
        if (seeding_dev) {
@@ -2209,6 +2210,7 @@ int btrfs_init_dev_replace_tgtdev(struct btrfs_root *root, char *device_path,
        device->in_fs_metadata = 1;
        device->is_tgtdev_for_dev_replace = 1;
        device->mode = FMODE_EXCL;
+       device->dev_stats_valid = 1;
        set_blocksize(device->bdev, 4096);
        device->fs_devices = fs_info->fs_devices;
        list_add(&device->dev_list, &fs_info->fs_devices->devices);
This page took 0.068187 seconds and 4 git commands to generate.