]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
btrfs: lift uuid_mutex to callers of btrfs_open_devices
authorDavid Sterba <dsterba@suse.com>
Tue, 19 Jun 2018 15:09:47 +0000 (17:09 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sat, 15 Sep 2018 07:46:55 +0000 (09:46 +0200)
[ Upstream commit f5194e34cabaddd348a90f950e0a8188dd26cdc0 ]

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: Anand Jain <anand.jain@oracle.com>
Signed-off-by: David Sterba <dsterba@suse.com>
Signed-off-by: Sasha Levin <alexander.levin@microsoft.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
fs/btrfs/super.c
fs/btrfs/volumes.c

index bddfc28b27c05f43b046d48ff59ad919a6b258d3..6eb789a529a322e27360106f8c81271a0d2ca8ca 100644 (file)
@@ -1565,7 +1565,9 @@ static struct dentry *btrfs_mount_root(struct file_system_type *fs_type,
                goto error_fs_info;
        }
 
+       mutex_lock(&uuid_mutex);
        error = btrfs_open_devices(fs_devices, mode, fs_type);
+       mutex_unlock(&uuid_mutex);
        if (error)
                goto error_fs_info;
 
index fca57c1f077cc70b6dbefdbf47affa15dc153553..0bd8c544d2de50034d6beaff1e29fdd228cb0cf9 100644 (file)
@@ -1146,7 +1146,8 @@ int btrfs_open_devices(struct btrfs_fs_devices *fs_devices,
 {
        int ret;
 
-       mutex_lock(&uuid_mutex);
+       lockdep_assert_held(&uuid_mutex);
+
        mutex_lock(&fs_devices->device_list_mutex);
        if (fs_devices->opened) {
                fs_devices->opened++;
@@ -1156,7 +1157,6 @@ int btrfs_open_devices(struct btrfs_fs_devices *fs_devices,
                ret = open_fs_devices(fs_devices, flags, holder);
        }
        mutex_unlock(&fs_devices->device_list_mutex);
-       mutex_unlock(&uuid_mutex);
 
        return ret;
 }