summaryrefslogtreecommitdiff
path: root/fs
diff options
context:
space:
mode:
authorAnand Jain <anand.jain@oracle.com>2018-05-29 17:23:20 +0800
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2018-09-15 09:46:56 +0200
commit40ce21951aab62b8cdd6d2b852154d6fe9f11163 (patch)
treefbb678ed7099fec22fe1ad5141d0ccdc711220f1 /fs
parentb57a7b0d4122033fba58c60f0560cdf9004fbf88 (diff)
btrfs: use device_list_mutex when removing stale devices
[ Upstream commit 7bcb8164ad9435068d9bc3b83b8a002c64d63ff6 ] btrfs_free_stale_devices() finds a stale (not opened) device matching path in the fs_uuid list. We are already under uuid_mutex so when we check for each fs_devices, hold the device_list_mutex too. Signed-off-by: Anand Jain <anand.jain@oracle.com> Reviewed-by: David Sterba <dsterba@suse.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>
Diffstat (limited to 'fs')
-rw-r--r--fs/btrfs/volumes.c25
1 files changed, 15 insertions, 10 deletions
diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
index 34ac2c7c8b97..6e6b4f2c85ad 100644
--- a/fs/btrfs/volumes.c
+++ b/fs/btrfs/volumes.c
@@ -640,8 +640,11 @@ static void btrfs_free_stale_devices(const char *path,
struct btrfs_device *device, *tmp_device;
list_for_each_entry_safe(fs_devices, tmp_fs_devices, &fs_uuids, fs_list) {
- if (fs_devices->opened)
+ mutex_lock(&fs_devices->device_list_mutex);
+ if (fs_devices->opened) {
+ mutex_unlock(&fs_devices->device_list_mutex);
continue;
+ }
list_for_each_entry_safe(device, tmp_device,
&fs_devices->devices, dev_list) {
@@ -661,16 +664,18 @@ static void btrfs_free_stale_devices(const char *path,
continue;
/* delete the stale device */
- if (fs_devices->num_devices == 1) {
- btrfs_sysfs_remove_fsid(fs_devices);
- list_del(&fs_devices->fs_list);
- free_fs_devices(fs_devices);
+ fs_devices->num_devices--;
+ list_del(&device->dev_list);
+ btrfs_free_device(device);
+
+ if (fs_devices->num_devices == 0)
break;
- } else {
- fs_devices->num_devices--;
- list_del(&device->dev_list);
- btrfs_free_device(device);
- }
+ }
+ mutex_unlock(&fs_devices->device_list_mutex);
+ if (fs_devices->num_devices == 0) {
+ btrfs_sysfs_remove_fsid(fs_devices);
+ list_del(&fs_devices->fs_list);
+ free_fs_devices(fs_devices);
}
}
}