Commit f5194e34 authored by David Sterba's avatar David Sterba

btrfs: lift uuid_mutex to callers of btrfs_open_devices

Prepartory work to fix race between mount and device scan.

The callers will have to manage the critical section, eg. mount wants to
scan and then call btrfs_open_devices without the ioctl scan walking in
and modifying the fs devices in the meantime.
Reviewed-by: default avatarAnand Jain <anand.jain@oracle.com>
Signed-off-by: default avatarDavid Sterba <dsterba@suse.com>
parent 899f9307
...@@ -1567,7 +1567,9 @@ static struct dentry *btrfs_mount_root(struct file_system_type *fs_type, ...@@ -1567,7 +1567,9 @@ static struct dentry *btrfs_mount_root(struct file_system_type *fs_type,
goto error_fs_info; goto error_fs_info;
} }
mutex_lock(&uuid_mutex);
error = btrfs_open_devices(fs_devices, mode, fs_type); error = btrfs_open_devices(fs_devices, mode, fs_type);
mutex_unlock(&uuid_mutex);
if (error) if (error)
goto error_fs_info; goto error_fs_info;
......
...@@ -1142,7 +1142,8 @@ int btrfs_open_devices(struct btrfs_fs_devices *fs_devices, ...@@ -1142,7 +1142,8 @@ int btrfs_open_devices(struct btrfs_fs_devices *fs_devices,
{ {
int ret; int ret;
mutex_lock(&uuid_mutex); lockdep_assert_held(&uuid_mutex);
mutex_lock(&fs_devices->device_list_mutex); mutex_lock(&fs_devices->device_list_mutex);
if (fs_devices->opened) { if (fs_devices->opened) {
fs_devices->opened++; fs_devices->opened++;
...@@ -1152,7 +1153,6 @@ int btrfs_open_devices(struct btrfs_fs_devices *fs_devices, ...@@ -1152,7 +1153,6 @@ int btrfs_open_devices(struct btrfs_fs_devices *fs_devices,
ret = open_fs_devices(fs_devices, flags, holder); ret = open_fs_devices(fs_devices, flags, holder);
} }
mutex_unlock(&fs_devices->device_list_mutex); mutex_unlock(&fs_devices->device_list_mutex);
mutex_unlock(&uuid_mutex);
return ret; return ret;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment