From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-co1nam03on0118.outbound.protection.outlook.com ([104.47.40.118]:6016 "EHLO NAM03-CO1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727773AbeH3WMT (ORCPT ); Thu, 30 Aug 2018 18:12:19 -0400 From: Sasha Levin To: "stable@vger.kernel.org" CC: David Sterba , Sasha Levin Subject: [PATCH AUTOSEL 4.18 111/113] btrfs: lift uuid_mutex to callers of btrfs_open_devices Date: Thu, 30 Aug 2018 18:08:40 +0000 Message-ID: <20180830180714.36167-45-alexander.levin@microsoft.com> References: <20180830180714.36167-1-alexander.levin@microsoft.com> In-Reply-To: <20180830180714.36167-1-alexander.levin@microsoft.com> Content-Language: en-US Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Sender: stable-owner@vger.kernel.org List-ID: From: David Sterba [ 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 Signed-off-by: David Sterba Signed-off-by: Sasha Levin --- fs/btrfs/super.c | 2 ++ fs/btrfs/volumes.c | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c index 81107ad49f3a..f369b480956a 100644 --- a/fs/btrfs/super.c +++ b/fs/btrfs/super.c @@ -1565,7 +1565,9 @@ static struct dentry *btrfs_mount_root(struct file_sy= stem_type *fs_type, goto error_fs_info; } =20 + mutex_lock(&uuid_mutex); error =3D btrfs_open_devices(fs_devices, mode, fs_type); + mutex_unlock(&uuid_mutex); if (error) goto error_fs_info; =20 diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c index fca57c1f077c..0bd8c544d2de 100644 --- a/fs/btrfs/volumes.c +++ b/fs/btrfs/volumes.c @@ -1146,7 +1146,8 @@ int btrfs_open_devices(struct btrfs_fs_devices *fs_de= vices, { int ret; =20 - 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_de= vices, ret =3D open_fs_devices(fs_devices, flags, holder); } mutex_unlock(&fs_devices->device_list_mutex); - mutex_unlock(&uuid_mutex); =20 return ret; } --=20 2.17.1