Skip to content

Commit 5860beb

Browse files
josefbacikkdave
authored andcommitted
btrfs: do not call close_fs_devices in btrfs_rm_device
There's a subtle case where if we're removing the seed device from a file system we need to free its private copy of the fs_devices. However we do not need to call close_fs_devices(), because at this point there are no devices left to close as we've closed the last one. The only thing that close_fs_devices() does is decrement ->opened, which should be 1. We want to avoid calling close_fs_devices() here because it has a lockdep_assert_held(&uuid_mutex), and we are going to stop holding the uuid_mutex in this path. So add an assert for the ->opened counter and simply decrement it like we should, and then clean up like normal. Also add a comment explaining what we're doing here as I initially removed this code erroneously. Signed-off-by: Josef Bacik <josef@toxicpanda.com> Signed-off-by: David Sterba <dsterba@suse.com>
1 parent 1923e05 commit 5860beb

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

fs/btrfs/volumes.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2185,9 +2185,17 @@ int btrfs_rm_device(struct btrfs_fs_info *fs_info, const char *device_path,
21852185
synchronize_rcu();
21862186
btrfs_free_device(device);
21872187

2188+
/*
2189+
* This can happen if cur_devices is the private seed devices list. We
2190+
* cannot call close_fs_devices() here because it expects the uuid_mutex
2191+
* to be held, but in fact we don't need that for the private
2192+
* seed_devices, we can simply decrement cur_devices->opened and then
2193+
* remove it from our list and free the fs_devices.
2194+
*/
21882195
if (cur_devices->open_devices == 0) {
2196+
ASSERT(cur_devices->opened == 1);
21892197
list_del_init(&cur_devices->seed_list);
2190-
close_fs_devices(cur_devices);
2198+
cur_devices->opened--;
21912199
free_fs_devices(cur_devices);
21922200
}
21932201

0 commit comments

Comments
 (0)