Skip to content

Commit 2516ab1

Browse files
josefbacikaxboe
authored andcommitted
nbd: only clear the queue on device teardown
When running a disconnect torture test I noticed that sometimes we would crash with a negative ref count on our queue. This was because we were ending the same request twice. Turns out we were racing with NBD_CLEAR_SOCK clearing the requests as well as the teardown of the device clearing the requests. So instead make the ioctl only shutdown the sockets and make it so that we only ever run nbd_clear_que from the device teardown. Signed-off-by: Josef Bacik <[email protected]> Signed-off-by: Jens Axboe <[email protected]>
1 parent 799f9a3 commit 2516ab1

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

drivers/block/nbd.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -616,7 +616,9 @@ static void nbd_clear_req(struct request *req, void *data, bool reserved)
616616

617617
static void nbd_clear_que(struct nbd_device *nbd)
618618
{
619+
blk_mq_stop_hw_queues(nbd->disk->queue);
619620
blk_mq_tagset_busy_iter(&nbd->tag_set, nbd_clear_req, NULL);
621+
blk_mq_start_hw_queues(nbd->disk->queue);
620622
dev_dbg(disk_to_dev(nbd->disk), "queue cleared\n");
621623
}
622624

@@ -1041,7 +1043,7 @@ static int nbd_start_device_ioctl(struct nbd_device *nbd, struct block_device *b
10411043
static void nbd_clear_sock_ioctl(struct nbd_device *nbd,
10421044
struct block_device *bdev)
10431045
{
1044-
nbd_clear_sock(nbd);
1046+
sock_shutdown(nbd);
10451047
kill_bdev(bdev);
10461048
nbd_bdev_reset(bdev);
10471049
if (test_and_clear_bit(NBD_HAS_CONFIG_REF,

0 commit comments

Comments
 (0)