--- x/fs/btrfs/volumes.c +++ y/fs/btrfs/volumes.c @@ -1277,7 +1277,6 @@ int btrfs_open_devices(struct btrfs_fs_d * We also don't need the lock here as this is called during mount and * exclusion is provided by uuid_mutex */ - mutex_lock(&uuid_mutex); if (fs_devices->opened) { fs_devices->opened++; ret = 0; @@ -1285,8 +1284,6 @@ int btrfs_open_devices(struct btrfs_fs_d list_sort(NULL, &fs_devices->devices, devid_cmp); ret = open_fs_devices(fs_devices, flags, holder); } - mutex_unlock(&uuid_mutex); - return ret; } --- x/fs/btrfs/super.c +++ y/fs/btrfs/super.c @@ -1472,22 +1472,6 @@ static struct dentry *btrfs_mount_root(s goto error_fs_info; } - mutex_lock(&uuid_mutex); - error = btrfs_parse_device_options(data); - if (error) { - mutex_unlock(&uuid_mutex); - goto error_fs_info; - } - - device = btrfs_scan_one_device(device_name); - if (IS_ERR(device)) { - mutex_unlock(&uuid_mutex); - error = PTR_ERR(device); - goto error_fs_info; - } - fs_info->fs_devices = device->fs_devices; - mutex_unlock(&uuid_mutex); - s = sget(fs_type, btrfs_test_super, btrfs_set_super, flags | SB_NOSEC, fs_info); if (IS_ERR(s)) { @@ -1500,15 +1484,31 @@ static struct dentry *btrfs_mount_root(s if ((flags ^ s->s_flags) & SB_RDONLY) error = -EBUSY; } else { - struct btrfs_fs_devices *fs_devices = fs_info->fs_devices; + struct btrfs_fs_devices *fs_devices; + + mutex_lock(&uuid_mutex); + error = btrfs_parse_device_options(data); + if (error) { + mutex_unlock(&uuid_mutex); + goto error_fs_info; + } + device = btrfs_scan_one_device(device_name); + if (IS_ERR(device)) { + mutex_unlock(&uuid_mutex); + error = PTR_ERR(device); + goto error_fs_info; + } + fs_info->fs_devices = fs_devices = device->fs_devices; error = btrfs_open_devices(fs_devices, sb_open_mode(flags), s); + mutex_unlock(&uuid_mutex); + if (error) goto out_deactivate; if (!(flags & SB_RDONLY) && fs_devices->rw_devices == 0) { error = -EACCES; - btrfs_close_devices(fs_info->fs_devices); + btrfs_close_devices(fs_devices); goto out_deactivate; }