Re: [PATCH 03/17] btrfs: do not hold device_list_mutex when closing devices

David Sterba
2020-08-14T14:12:47Z

On Mon, Aug 10, 2020 at 11:42:28AM -0400, Josef Bacik wrote:
> not have the device_list_mutex here. We're already holding the
> uuid_mutex which keeps us safe from any external modification of the
> fs_devices.
>
> Signed-off-by: Josef Bacik <josef@toxicpanda.com>
> ---
> fs/btrfs/volumes.c | 5 +----
> 1 file changed, 1 insertion(+), 4 deletions(-)
>
> diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
> index 3ac44dad58bb..97ec9c0a91aa 100644
> --- a/fs/btrfs/volumes.c
> +++ b/fs/btrfs/volumes.c
> @@ -1155,11 +1155,8 @@ static int close_fs_devices(struct btrfs_fs_devices *fs_devices)
> if (--fs_devices->opened > 0)
> return 0;
>
> - mutex_lock(&fs_devices->device_list_mutex);
> - list_for_each_entry_safe(device, tmp, &fs_devices->devices, dev_list) {
> + list_for_each_entry_safe(device, tmp, &fs_devices->devices, dev_list)
> btrfs_close_one_device(device);
> - }
> - mutex_unlock(&fs_devices->device_list_mutex);

As Filipe pointed out, uuid mutex is not held in the dev replace
function, I suggest to add

lockdep_assert_held(&uuid_mutex);

when locks are removed and we rely on callers to make sure the right
locks are taken.