nbd: fix possible sysfs duplicate warning
Subsystems (2)
PATCH 1/1 nbd: fix possible sysfs duplicate warning
From: Xiubo Li <[email protected]>
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.
--- drivers/block/nbd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/block/nbd.c +1 -1
@@ -248,8 +248,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); } }
Signature · 1 line
2.21.0
Quoted 11 lines · On Thu, Sep 19, 2019 at 11:44:27AM +0530, [email protected] wrote:
From: Xiubo Li <[email protected]>
1.
nbd_puttakes the mutex and dropsnbd->refto 0. It then doesidr_removeand drops the mutex.2.
nbd_genl_connecttakes the mutex. idr_find/idr_for_each fails to find an existing device, so it doesnbd_dev_add.3. just before the
nbd_putcould callnbd_dev_removeor not finished totally, but ifnbd_dev_addtry toadd_disk, we can hit:
Quoted 7 lines
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_mutexlock.Signed-off-by Xiubo Li <[email protected]>Reported-by Mike Christie <[email protected]>
Sorry, don't know how I missed this.
Thanks,
Josef
Quoted 12 lines · Josef Bacik
Quoted 11 lines · On Thu, Sep 19, 2019 at 11:44:27AM +0530, [email protected] wrote:
From: Xiubo Li <[email protected]>
1.
nbd_puttakes the mutex and dropsnbd->refto 0. It then doesidr_removeand drops the mutex.2.
nbd_genl_connecttakes the mutex. idr_find/idr_for_each fails to find an existing device, so it doesnbd_dev_add.3. just before the
nbd_putcould callnbd_dev_removeor not finished totally, but ifnbd_dev_addtry toadd_disk, we can hit:
Quoted 8 lines
Quoted 7 lines
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_mutexlock.Signed-off-by Xiubo Li <[email protected]>Reported-by Mike Christie <[email protected]>Sorry, don't know how I missed this.
Many thanks.
Xiubo
Quoted 5 lines
Reviewed-by Josef Bacik <[email protected]>Thanks,
Josef
Quoted 8 lines · On 9/19/19 12:14 AM, [email protected] wrote:
From: Xiubo Li <[email protected]>
1.
nbd_puttakes the mutex and dropsnbd->refto 0. It then doesidr_removeand drops the mutex.2.
nbd_genl_connecttakes the mutex. idr_find/idr_for_each fails to find an existing device, so it doesnbd_dev_add.
Quoted 7 lines
3. just before the
nbd_putcould callnbd_dev_removeor not finished totally, but ifnbd_dev_addtry toadd_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_mutexlock.
Applied, thanks.
Signature · 1 line
Jens Axboe