diff mbox series

[2/5,SRU,XENIAL] nbd: Timeouts are not user requested disconnects

Message ID 20181011144123.24543-3-colin.king@canonical.com
State New
Headers show
Series Fix nbd panic on ubuntu_nbd_smoke_test | expand

Commit Message

Colin Ian King Oct. 11, 2018, 2:41 p.m. UTC
From: Markus Pargmann <mpa@pengutronix.de>

BugLink: https://bugs.launchpad.net/bugs/1793464

It may be useful to know in the client that a connection timed out. The
current code returns success for a timeout.

This patch reports the error code -ETIMEDOUT for a timeout.

Signed-off-by: Markus Pargmann <mpa@pengutronix.de>
(backported from commit 1f7b5cf1be4351e60cf8ae7aab976503dd73c5f8)
Signed-off-by: Colin Ian King <colin.king@canonical.com>
---
 drivers/block/nbd.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
diff mbox series

Patch

diff --git a/drivers/block/nbd.c b/drivers/block/nbd.c
index d65a6f5..cc2844f 100644
--- a/drivers/block/nbd.c
+++ b/drivers/block/nbd.c
@@ -57,6 +57,7 @@  struct nbd_device {
 	loff_t blksize;
 	loff_t bytesize;
 	int xmit_timeout;
+	bool timedout;
 	bool disconnect; /* a disconnect has been requested by user */
 
 	struct timer_list timeout_timer;
@@ -195,10 +196,9 @@  static void nbd_xmit_timeout(unsigned long arg)
 	if (list_empty(&nbd->queue_head))
 		return;
 
-	nbd->disconnect = true;
-
 	spin_lock_irqsave(&nbd->sock_lock, flags);
 
+	nbd->timedout = true;
 
 	if (nbd->sock)
 		kernel_sock_shutdown(nbd->sock, SHUT_RDWR);
@@ -791,7 +791,10 @@  static int __nbd_ioctl(struct block_device *bdev, struct nbd_device *nbd,
 		if (max_part > 0)
 			blkdev_reread_part(bdev);
 		if (nbd->disconnect) /* user requested, ignore socket errors */
-			return 0;
+			error = 0;
+		if (nbd->timedout)
+			error = -ETIMEDOUT;
+
 		return error;
 	}