btrfs: fix in-memory value of total_devices after seed device deletion
authorAnand Jain <anand.jain@oracle.com>
Tue, 3 Jul 2018 09:07:23 +0000 (17:07 +0800)
committerDavid Sterba <dsterba@suse.com>
Mon, 6 Aug 2018 11:12:45 +0000 (13:12 +0200)
In case of deleting the seed device the %cur_devices (seed) and the
%fs_devices (parent) are different. Now, as the parent
fs_devices::total_devices also maintains the total number of devices
including the seed device, so decrement its in-memory value for the
successful seed delete. We are already updating its corresponding
on-disk btrfs_super_block::number_devices value.

Signed-off-by: Anand Jain <anand.jain@oracle.com>
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/volumes.c

index 211fb21614874681d9e5711e61793b797f7e6884..f532e855b50726fec6ae09e57a426e12cedaa970 100644 (file)
@@ -2026,6 +2026,9 @@ int btrfs_rm_device(struct btrfs_fs_info *fs_info, const char *device_path,
 
        cur_devices->num_devices--;
        cur_devices->total_devices--;
 
        cur_devices->num_devices--;
        cur_devices->total_devices--;
+       /* Update total_devices of the parent fs_devices if it's seed */
+       if (cur_devices != fs_devices)
+               fs_devices->total_devices--;
 
        if (test_bit(BTRFS_DEV_STATE_MISSING, &device->dev_state))
                cur_devices->missing_devices--;
 
        if (test_bit(BTRFS_DEV_STATE_MISSING, &device->dev_state))
                cur_devices->missing_devices--;