Skip to content

Commit 8624881

Browse files
lxbszaxboe
authored andcommitted
nbd: fix possible sysfs duplicate warning
1. nbd_put takes the mutex and drops nbd->ref to 0. It then does idr_remove and drops the mutex. 2. nbd_genl_connect takes the mutex. idr_find/idr_for_each fails to find an existing device, so it does nbd_dev_add. 3. just before the nbd_put could call nbd_dev_remove or not finished totally, but if nbd_dev_add try to add_disk, we can hit: debugfs: Directory 'nbd1' with parent 'block' already present! This patch will make sure all the disk add/remove stuff are done by holding the nbd_index_mutex lock. Reported-by: Mike Christie <[email protected]> Reviewed-by: Josef Bacik <[email protected]> Signed-off-by: Xiubo Li <[email protected]> Signed-off-by: Jens Axboe <[email protected]>
1 parent 79a85e2 commit 8624881

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

drivers/block/nbd.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,8 +248,8 @@ static void nbd_put(struct nbd_device *nbd)
248248
if (refcount_dec_and_mutex_lock(&nbd->refs,
249249
&nbd_index_mutex)) {
250250
idr_remove(&nbd_index_idr, nbd->index);
251-
mutex_unlock(&nbd_index_mutex);
252251
nbd_dev_remove(nbd);
252+
mutex_unlock(&nbd_index_mutex);
253253
}
254254
}
255255

0 commit comments

Comments
 (0)