]> git.hungrycats.org Git - linux/commitdiff
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)
committerZygo Blaxell <zblaxell@serenity.furryterror.org>
Wed, 3 Dec 2014 15:16:59 +0000 (10:16 -0500)
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>
(cherry picked from commit c3929c3624e1764855e5a452728aec201b18b42a)

fs/btrfs/volumes.c

index 1cf830009fb1c98ce2ee6fdc95c89ae496d8a48d..9e900f3108bdaa2a941c3163abf03d004ba7fba6 100644 (file)
@@ -1652,8 +1652,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;
        }
 
@@ -1798,8 +1798,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;
 }