Skip to contentSkip to conversation

NBD: fix I/O hang on disconnected nbds

PATCH In review Paul Clements 2 participants 3 messages Feb 9, 2009 – Feb 10, 2009

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 NBD: fix I/O hang on disconnected nbds

This patch fixes 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.

--
Paul

This patch fixes 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.

---

 nbd.c |    9 +++++++++
 1 files changed, 9 insertions(+)
drivers/block/nbd.c renamed from drivers/block/nbd.c.PRISTINE +9 -0
@@ -547,6 +547,15 @@ static void do_nbd_request(struct reques
 
 		BUG_ON(lo->magic != LO_MAGIC);
 
+		if (unlikely(!lo->sock)) {
+			printk(KERN_ERR "%s: Attempted send on closed socket\n",
+				lo->disk->disk_name);
+			req->errors++;
+			nbd_end_request(req);
+			spin_lock_irq(q->queue_lock);
+			continue;
+		}
+
 		spin_lock_irq(&lo->queue_lock);
 		list_add_tail(&req->queuelist, &lo->waiting_queue);
 		spin_unlock_irq(&lo->queue_lock);
#1 lore raw
Quoted 16 lines · On Mon, 09 Feb 2009 13:21:51 -0500 Paul Clements <[email protected]>…

This patch fixes 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

Quoted 6 lines

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.

Seems that the patch applies to 2.6.26, but not to 2.6.25.

Quoted 5 lines

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.

I marked this as needing backporting into 2.6.26.x, 2.6.27.x and 2.6.28.x. OK?

#2 lore raw
Quoted 7 lines · Andrew Morton
Quoted 2 lines · On Mon, 09 Feb 2009 13:21:51 -0500 Paul Clements <[email protected]>…

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.

Seems that the patch applies to 2.6.26, but not to 2.6.25.

OK, couldn't remember the exact timeframe.

Quoted 6 lines
Quoted 3 lines

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.

I marked this as needing backporting into 2.6.26.x, 2.6.27.x and 2.6.28.x. OK?

Yes, that would be a good idea.

Thanks,
Paul