linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: David Sterba <dsterba@suse.com>
To: linux-btrfs@vger.kernel.org
Cc: anand.jain@oracle.com, David Sterba <dsterba@suse.com>
Subject: [PATCH 6/7] btrfs: reorder initialization before the mount locks uuid_mutex
Date: Wed, 20 Jun 2018 19:51:40 +0200	[thread overview]
Message-ID: <c501e3ab67e55bbd71f07de9c0981eec19d49d3c.1529516228.git.dsterba@suse.com> (raw)
In-Reply-To: <cover.1529516226.git.dsterba@suse.com>

In preparation to take a big lock, move resource initialization before
the critical section. It's not obvious from the diff, the desired order
is:

- initialize mount security options
- allocate temporary fs_info
- allocate superblock buffers

Signed-off-by: David Sterba <dsterba@suse.com>
---
 fs/btrfs/super.c | 30 ++++++++++++++----------------
 1 file changed, 14 insertions(+), 16 deletions(-)

diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c
index e3324ddf2777..1780eb41f203 100644
--- a/fs/btrfs/super.c
+++ b/fs/btrfs/super.c
@@ -1528,14 +1528,6 @@ static struct dentry *btrfs_mount_root(struct file_system_type *fs_type,
 	if (!(flags & SB_RDONLY))
 		mode |= FMODE_WRITE;
 
-	mutex_lock(&uuid_mutex);
-	error = btrfs_parse_early_options(data, mode, fs_type,
-					  &fs_devices);
-	mutex_unlock(&uuid_mutex);
-	if (error) {
-		return ERR_PTR(error);
-	}
-
 	security_init_mnt_opts(&new_sec_opts);
 	if (data) {
 		error = parse_security_options(data, &new_sec_opts);
@@ -1543,12 +1535,6 @@ static struct dentry *btrfs_mount_root(struct file_system_type *fs_type,
 			return ERR_PTR(error);
 	}
 
-	mutex_lock(&uuid_mutex);
-	error = btrfs_scan_one_device(device_name, mode, fs_type, &fs_devices);
-	mutex_unlock(&uuid_mutex);
-	if (error)
-		goto error_sec_opts;
-
 	/*
 	 * Setup a dummy root and fs_info for test/set super.  This is because
 	 * we don't actually fill this stuff out until open_ctree, but we need
@@ -1561,8 +1547,6 @@ static struct dentry *btrfs_mount_root(struct file_system_type *fs_type,
 		goto error_sec_opts;
 	}
 
-	fs_info->fs_devices = fs_devices;
-
 	fs_info->super_copy = kzalloc(BTRFS_SUPER_INFO_SIZE, GFP_KERNEL);
 	fs_info->super_for_commit = kzalloc(BTRFS_SUPER_INFO_SIZE, GFP_KERNEL);
 	security_init_mnt_opts(&fs_info->security_opts);
@@ -1571,6 +1555,20 @@ static struct dentry *btrfs_mount_root(struct file_system_type *fs_type,
 		goto error_fs_info;
 	}
 
+	mutex_lock(&uuid_mutex);
+	error = btrfs_parse_early_options(data, mode, fs_type, &fs_devices);
+	mutex_unlock(&uuid_mutex);
+	if (error)
+		goto error_fs_info;
+
+	mutex_lock(&uuid_mutex);
+	error = btrfs_scan_one_device(device_name, mode, fs_type, &fs_devices);
+	mutex_unlock(&uuid_mutex);
+	if (error)
+		goto error_fs_info;
+
+	fs_info->fs_devices = fs_devices;
+
 	mutex_lock(&uuid_mutex);
 	error = btrfs_open_devices(fs_devices, mode, fs_type);
 	mutex_unlock(&uuid_mutex);
-- 
2.17.0


  parent reply	other threads:[~2018-06-20 17:54 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-06-20 17:51 [PATCH 0/7] Fix locking when scanning devices David Sterba
2018-06-20 17:51 ` [PATCH 1/7] btrfs: restore uuid_mutex in btrfs_open_devices David Sterba
2018-07-04  8:09   ` Anand Jain
2018-07-13 12:49     ` David Sterba
2018-06-20 17:51 ` [PATCH 2/7] btrfs: extend critical section when scanning a new device David Sterba
2018-06-26  7:34   ` Anand Jain
2018-07-04  8:18   ` Anand Jain
2018-07-13 12:55     ` David Sterba
2018-06-20 17:51 ` [PATCH 3/7] btrfs: lift uuid_mutex to callers of btrfs_scan_one_device David Sterba
2018-07-04  8:19   ` Anand Jain
2018-06-20 17:51 ` [PATCH 4/7] btrfs: lift uuid_mutex to callers of btrfs_open_devices David Sterba
2018-07-04  8:19   ` Anand Jain
2018-06-20 17:51 ` [PATCH 5/7] btrfs: lift uuid_mutex to callers of btrfs_parse_early_options David Sterba
2018-07-04  8:20   ` Anand Jain
2018-06-20 17:51 ` David Sterba [this message]
2018-07-04  8:21   ` [PATCH 6/7] btrfs: reorder initialization before the mount locks uuid_mutex Anand Jain
2018-06-20 17:51 ` [PATCH 7/7] btrfs: fix mount and ioctl device scan ioctl race David Sterba
2018-06-26  9:33   ` Anand Jain
2018-07-04  8:22   ` Anand Jain
2018-06-21  7:48 ` [PATCH 0/7] Fix locking when scanning devices Nikolay Borisov
2018-06-22 11:39   ` David Sterba

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=c501e3ab67e55bbd71f07de9c0981eec19d49d3c.1529516228.git.dsterba@suse.com \
    --to=dsterba@suse.com \
    --cc=anand.jain@oracle.com \
    --cc=linux-btrfs@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).