From: Anand Jain <anand.jain@oracle.com>
To: linux-btrfs@vger.kernel.org
Subject: [PATCH v4 1/7] btrfs: drop uuid_mutex in btrfs_free_extra_devids()
Date: Mon, 16 Jul 2018 22:58:06 +0800 [thread overview]
Message-ID: <20180716145812.20836-2-anand.jain@oracle.com> (raw)
In-Reply-To: <20180716145812.20836-1-anand.jain@oracle.com>
btrfs_free_extra_devids() is called only in the mount context which
traverses through the fs_devices::devices and frees the orphan devices
devices in the given %fs_devices if any. As the search for the orphan
device is limited to fs_devices::devices so we don't need the global
uuid_mutex.
There can't be any mount-point based ioctl threads in this context as
the mount thread is not yet returned. But there can be the btrfs-control
based scan ioctls thread which calls device_list_add().
Here in the mount thread the fs_devices::opened is incremented way before
btrfs_free_extra_devids() is called and in the scan context the fs_devices
which are already opened neither be freed or alloc-able at
device_list_add().
But lets say you change the device-path and call the scan again, then scan
would update the new device path and this operation could race against the
btrfs_free_extra_devids() thread, which might be in the process of
free-ing the same device. So synchronize it by using the
device_list_mutex.
This scenario is a very corner case, and practically the scan and mount
are anyway serialized by the usage so unless the race is instrumented its
very difficult to achieve.
Signed-off-by: Anand Jain <anand.jain@oracle.com>
Reviewed-by: David Sterba <dsterba@suse.com>
---
v3->v4: As we traverse through the seed device, fs_device gets updated with
the child seed fs_devices, so make sure we use the same fs_devices
pointer for the mutex_unlock as used for the mutex_lock.
v2->v3: Update change log.
(Currently device_list_add() is very lean on its device_list_mutex usage,
a cleanup and fix is wip. Given the practicality of the above race
condition this patch is good to merge).
v1->v2: replace uuid_mutex with device_list_mutex instead of delete.
change log updated.
fs/btrfs/volumes.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
index 88d37bfa99c8..870c9f69a6a4 100644
--- a/fs/btrfs/volumes.c
+++ b/fs/btrfs/volumes.c
@@ -934,8 +934,9 @@ void btrfs_free_extra_devids(struct btrfs_fs_devices *fs_devices, int step)
{
struct btrfs_device *device, *next;
struct btrfs_device *latest_dev = NULL;
+ struct btrfs_fs_devices *parent_fs_devices = fs_devices;
- mutex_lock(&uuid_mutex);
+ mutex_lock(&parent_fs_devices->device_list_mutex);
again:
/* This is the initialized path, it is safe to release the devices. */
list_for_each_entry_safe(device, next, &fs_devices->devices, dev_list) {
@@ -989,8 +990,7 @@ void btrfs_free_extra_devids(struct btrfs_fs_devices *fs_devices, int step)
}
fs_devices->latest_bdev = latest_dev->bdev;
-
- mutex_unlock(&uuid_mutex);
+ mutex_unlock(&parent_fs_devices->device_list_mutex);
}
static void free_device_rcu(struct rcu_head *head)
--
2.7.0
next prev parent reply other threads:[~2018-07-16 15:22 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-07-16 14:58 [PATCH 0/7] Misc volume patch set part2 Anand Jain
2018-07-16 14:58 ` Anand Jain [this message]
2018-07-16 14:58 ` [PATCH v2 2/7] btrfs: fix race between free_stale_devices and close_fs_devices Anand Jain
2018-07-16 14:58 ` [PATCH 3/7] btrfs: do device clone using the btrfs_scan_one_device Anand Jain
2018-07-19 12:31 ` David Sterba
2018-07-20 6:35 ` Anand Jain
2018-07-20 7:13 ` Anand Jain
2018-07-16 14:58 ` [PATCH 4/7] btrfs: use the assigned fs_devices instead of the dereference Anand Jain
2018-07-19 12:01 ` David Sterba
2018-07-16 14:58 ` [PATCH 5/7] btrfs: warn for num_devices below 0 Anand Jain
2018-07-23 14:01 ` David Sterba
2018-07-23 14:15 ` Anand Jain
2018-07-16 14:58 ` [PATCH 6/7] btrfs: add helper btrfs_num_devices() to deduce num_devices Anand Jain
2018-07-19 11:53 ` David Sterba
2018-07-20 1:41 ` Anand Jain
2018-07-20 11:18 ` Anand Jain
2018-07-23 13:57 ` David Sterba
2018-07-23 14:21 ` Anand Jain
2018-07-16 14:58 ` [PATCH 7/7] btrfs: add helper function check device delete able Anand Jain
2018-07-19 11:45 ` David Sterba
2018-07-20 1:34 ` Anand Jain
2018-07-20 11:22 ` Anand Jain
2018-07-16 15:27 ` [PATCH 0/7] Misc volume patch set part2 Anand Jain
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=20180716145812.20836-2-anand.jain@oracle.com \
--to=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).