Btrfs: protect devices list with its mutex
authorLiu Bo <bo.li.liu@oracle.com>
Wed, 14 Nov 2012 14:35:30 +0000 (14:35 +0000)
committerJosef Bacik <jbacik@fusionio.com>
Wed, 12 Dec 2012 22:15:28 +0000 (17:15 -0500)
Since we've kill the bigger one volume_mutex, we need to add devices
list mutex back.

Signed-off-by: Liu Bo <bo.li.liu@oracle.com>
Signed-off-by: Chris Mason <chris.mason@fusionio.com>
fs/btrfs/volumes.c

index db79fb7e7e917bae6aa8db8c876f64825bf0b345..92e586bc80046aa4341d1a0badafb87cd6da93e0 100644 (file)
@@ -1681,16 +1681,17 @@ int btrfs_init_new_device(struct btrfs_root *root, char *device_path)
        filemap_write_and_wait(bdev->bd_inode->i_mapping);
 
        devices = &root->fs_info->fs_devices->devices;
-       /*
-        * we have the volume lock, so we don't need the extra
-        * device list mutex while reading the list here.
-        */
+
+       mutex_lock(&root->fs_info->fs_devices->device_list_mutex);
        list_for_each_entry(device, devices, dev_list) {
                if (device->bdev == bdev) {
                        ret = -EEXIST;
+                       mutex_unlock(
+                               &root->fs_info->fs_devices->device_list_mutex);
                        goto error;
                }
        }
+       mutex_unlock(&root->fs_info->fs_devices->device_list_mutex);
 
        device = kzalloc(sizeof(*device), GFP_NOFS);
        if (!device) {