Btrfs: modify rw_devices counter under chunk_mutex context
authorMiao Xie <miaox@cn.fujitsu.com>
Wed, 3 Sep 2014 13:35:47 +0000 (21:35 +0800)
committerChris Mason <clm@fb.com>
Wed, 17 Sep 2014 20:38:49 +0000 (13:38 -0700)
rw_devices counter is often used to tune the profile when doing chunk allocation,
so we should modify it under the chunk_mutex context to avoid getting wrong
chunk profile.

Signed-off-by: Miao Xie <miaox@cn.fujitsu.com>
Signed-off-by: Chris Mason <clm@fb.com>
fs/btrfs/volumes.c

index 57a7f33..77d7fbc 100644 (file)
@@ -1649,8 +1649,8 @@ int btrfs_rm_device(struct btrfs_root *root, char *device_path)
        if (device->writeable) {
                lock_chunks(root);
                list_del_init(&device->dev_alloc_list);
+               device->fs_devices->rw_devices--;
                unlock_chunks(root);
-               root->fs_info->fs_devices->rw_devices--;
                clear_super = true;
        }
 
@@ -1795,8 +1795,8 @@ error_undo:
                lock_chunks(root);
                list_add(&device->dev_alloc_list,
                         &root->fs_info->fs_devices->alloc_list);
+               device->fs_devices->rw_devices++;
                unlock_chunks(root);
-               root->fs_info->fs_devices->rw_devices++;
        }
        goto error_brelse;
 }