Skip to content

Commit 4d48a54

Browse files
clemep-siostorvalds
authored andcommitted
nbd: fix I/O hang on disconnected nbds
Fix a problem that causes I/O to a disconnected (or partially initialized) nbd device to hang indefinitely. To reproduce: # ioctl NBD_SET_SIZE_BLOCKS /dev/nbd23 514048 # dd if=/dev/nbd23 of=/dev/null bs=4096 count=1 ...hangs... This can also occur when an nbd device loses its nbd-client/server connection. Although we clear the queue of any outstanding I/Os after the client/server connection fails, any additional I/Os that get queued later will hang. This bug may also be the problem reported in this bug report: http://bugzilla.kernel.org/show_bug.cgi?id=12277 Testing would need to be performed to determine if the two issues are the same. This problem was introduced by the new request handling thread code ("NBD: allow nbd to be used locally", 3/2008), which entered into mainline around 2.6.25. The fix, which is fairly simple, is to restore the check for lo->sock being NULL in do_nbd_request. This causes I/O to an uninitialized nbd to immediately fail with an I/O error, as it did prior to the introduction of this bug. Signed-off-by: Paul Clements <[email protected]> Reported-by: Jon Nelson <[email protected]> Acked-by: Pavel Machek <[email protected]> Cc: <[email protected]> [2.6.26.x, 2.6.27.x, 2.6.28.x] Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent 9480c53 commit 4d48a54

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

drivers/block/nbd.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -549,6 +549,15 @@ static void do_nbd_request(struct request_queue * q)
549549

550550
BUG_ON(lo->magic != LO_MAGIC);
551551

552+
if (unlikely(!lo->sock)) {
553+
printk(KERN_ERR "%s: Attempted send on closed socket\n",
554+
lo->disk->disk_name);
555+
req->errors++;
556+
nbd_end_request(req);
557+
spin_lock_irq(q->queue_lock);
558+
continue;
559+
}
560+
552561
spin_lock_irq(&lo->queue_lock);
553562
list_add_tail(&req->queuelist, &lo->waiting_queue);
554563
spin_unlock_irq(&lo->queue_lock);

0 commit comments

Comments
 (0)