Thread (11 messages) 11 messages, 2 authors, 2021-10-05

Re: [PATCH v3 3/6] btrfs: do not call close_fs_devices in btrfs_rm_device

From: Anand Jain <hidden>
Date: 2021-10-05 03:18:28

On 05/10/2021 01:19, Josef Bacik wrote:
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 simply decrement the  ->opened counter 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.
David,

  You might want to add this patch before commit e197aab25da2 (btrfs: do 
not take the uuid_mutex in btrfs_rm_device) in the misc-next. As this 
patch is preparatory of it.
Signed-off-by: Josef Bacik <josef@toxicpanda.com>
  Reviewed-by: Anand Jain [off-list ref]

Thx, Anand
quoted hunk ↗ jump to hunk
---
  fs/btrfs/volumes.c | 9 ++++++++-
  1 file changed, 8 insertions(+), 1 deletion(-)
diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
index 0941f61d8071..5f19d0863094 100644
--- a/fs/btrfs/volumes.c
+++ b/fs/btrfs/volumes.c
@@ -2211,9 +2211,16 @@ int btrfs_rm_device(struct btrfs_fs_info *fs_info, const char *device_path,
  	synchronize_rcu();
  	btrfs_free_device(device);
  
+	/*
+	 * This can happen if cur_devices is the private seed devices list.  We
+	 * cannot call close_fs_devices() here because it expects the uuid_mutex
+	 * to be held, but in fact we don't need that for the private
+	 * seed_devices, we can simply decrement cur_devices->opened and then
+	 * remove it from our list and free the fs_devices.
+	 */
  	if (cur_devices->num_devices == 0) {
  		list_del_init(&cur_devices->seed_list);
-		close_fs_devices(cur_devices);
+		cur_devices->opened--;
  		free_fs_devices(cur_devices);
  	}
  
  
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help