summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorXiubo Li <xiubli@redhat.com>2019-09-19 09:14:27 +0300
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2019-11-06 15:08:44 +0300
commit1df6bb8ce8ababaee2d66add746235a73e5df2db (patch)
tree4af63a6a5b874e6adc92b8ae6a2b80a0abe364ee
parent2ef37b2c9c6820db58c6c5c782e032ff3463f319 (diff)
downloadlinux-1df6bb8ce8ababaee2d66add746235a73e5df2db.tar.xz
nbd: fix possible sysfs duplicate warning
[ Upstream commit 862488105b84ca744b3d8ff131e0fcfe10644be1 ] 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 <mchristi@redhat.com> Reviewed-by: Josef Bacik <josef@toxicpanda.com> Signed-off-by: Xiubo Li <xiubli@redhat.com> Signed-off-by: Jens Axboe <axboe@kernel.dk> Signed-off-by: Sasha Levin <sashal@kernel.org>
-rw-r--r--drivers/block/nbd.c2
1 files changed, 1 insertions, 1 deletions
diff --git a/drivers/block/nbd.c b/drivers/block/nbd.c
index 0b727f7432f9..bd164192045b 100644
--- a/drivers/block/nbd.c
+++ b/drivers/block/nbd.c
@@ -230,8 +230,8 @@ static void nbd_put(struct nbd_device *nbd)
if (refcount_dec_and_mutex_lock(&nbd->refs,
&nbd_index_mutex)) {
idr_remove(&nbd_index_idr, nbd->index);
- mutex_unlock(&nbd_index_mutex);
nbd_dev_remove(nbd);
+ mutex_unlock(&nbd_index_mutex);
}
}