btrfs: use existing cur_devices, cleanup btrfs_rm_device
authorAnand Jain <anand.jain@oracle.com>
Thu, 12 Apr 2018 02:29:31 +0000 (10:29 +0800)
committerDavid Sterba <dsterba@suse.com>
Mon, 28 May 2018 16:23:13 +0000 (18:23 +0200)
Instead of de-referencing the device->fs_devices use cur_devices
which points to the same fs_devices and does not change.

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

index c1d09da40d73f06ca8f920b8bb5577e30629fc8f..a382d53c560af673acb3424de1620dd92ac6ab27 100644 (file)
@@ -2015,20 +2015,25 @@ int btrfs_rm_device(struct btrfs_fs_info *fs_info, const char *device_path,
         * (super_copy) should hold the device list mutex.
         */
 
         * (super_copy) should hold the device list mutex.
         */
 
+       /*
+        * In normal cases the cur_devices == fs_devices. But in case
+        * of deleting a seed device, the cur_devices should point to
+        * its own fs_devices listed under the fs_devices->seed.
+        */
        cur_devices = device->fs_devices;
        mutex_lock(&fs_devices->device_list_mutex);
        list_del_rcu(&device->dev_list);
 
        cur_devices = device->fs_devices;
        mutex_lock(&fs_devices->device_list_mutex);
        list_del_rcu(&device->dev_list);
 
-       device->fs_devices->num_devices--;
-       device->fs_devices->total_devices--;
+       cur_devices->num_devices--;
+       cur_devices->total_devices--;
 
        if (test_bit(BTRFS_DEV_STATE_MISSING, &device->dev_state))
 
        if (test_bit(BTRFS_DEV_STATE_MISSING, &device->dev_state))
-               device->fs_devices->missing_devices--;
+               cur_devices->missing_devices--;
 
        btrfs_assign_next_active_device(fs_info, device, NULL);
 
        if (device->bdev) {
 
        btrfs_assign_next_active_device(fs_info, device, NULL);
 
        if (device->bdev) {
-               device->fs_devices->open_devices--;
+               cur_devices->open_devices--;
                /* remove sysfs entry */
                btrfs_sysfs_rm_device_link(fs_devices, device);
        }
                /* remove sysfs entry */
                btrfs_sysfs_rm_device_link(fs_devices, device);
        }