All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v3 0/2] nbd: improve timeout handling and a fix
@ 2020-09-30  3:23 Hou Pu
  2020-09-30  3:23 ` [PATCH v3 1/2] nbd: return -ETIMEDOUT when NBD_DO_IT ioctl returns Hou Pu
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Hou Pu @ 2020-09-30  3:23 UTC (permalink / raw)
  To: josef, axboe; +Cc: linux-block, nbd, Hou Pu

Patch #1 is a fix. Patch #2 is trying to improve io timeout
handling.

Thanks,
Hou

v3 changes:
* Add 'Reviewed-by: Josef Bacik <josef@toxicpanda.com>' in patch #2.

v2 changes:
* Add 'Reviewed-by: Josef Bacik <josef@toxicpanda.com>' in patch #1.
* Original patch #2 is dropped.
* Keep the behavior same as before when we don't set a .timeout
and num_connections > 1.
* Coding style fixes.

Hou Pu (2):
  nbd: return -ETIMEDOUT when NBD_DO_IT ioctl returns
  nbd: introduce a client flag to do zero timeout handling

 drivers/block/nbd.c      | 33 ++++++++++++++++++++++++++++-----
 include/uapi/linux/nbd.h |  4 ++++
 2 files changed, 32 insertions(+), 5 deletions(-)

-- 
2.11.0


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH v3 1/2] nbd: return -ETIMEDOUT when NBD_DO_IT ioctl returns
  2020-09-30  3:23 [PATCH v3 0/2] nbd: improve timeout handling and a fix Hou Pu
@ 2020-09-30  3:23 ` Hou Pu
  2020-09-30  3:23 ` [PATCH v3 2/2] nbd: introduce a client flag to do zero timeout handling Hou Pu
  2020-11-08  8:46 ` [PATCH v3 0/2] nbd: improve timeout handling and a fix Hou Pu
  2 siblings, 0 replies; 4+ messages in thread
From: Hou Pu @ 2020-09-30  3:23 UTC (permalink / raw)
  To: josef, axboe; +Cc: linux-block, nbd, Hou Pu

We used to return -ETIMEDOUT if io timeout happened. But since
commit d970958b2d24 ("nbd: enable replace socket if only one
connection is configured"), user space would not get -ETIMEDOUT.
This commit fixes this. Only return -ETIMEDOUT if only one socket
is configured by ioctl and the user specified a non-zero timeout
value.

Reviewed-by: Josef Bacik <josef@toxicpanda.com>
Signed-off-by: Hou Pu <houpu@bytedance.com>
---
 drivers/block/nbd.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/drivers/block/nbd.c b/drivers/block/nbd.c
index ce7e9f223b20..538e9dcf5bf2 100644
--- a/drivers/block/nbd.c
+++ b/drivers/block/nbd.c
@@ -395,6 +395,11 @@ static enum blk_eh_timer_return nbd_xmit_timeout(struct request *req,
 	}
 	config = nbd->config;
 
+	if (!test_bit(NBD_RT_BOUND, &config->runtime_flags) &&
+	    config->num_connections == 1 &&
+	    nbd->tag_set.timeout)
+		goto error_out;
+
 	if (config->num_connections > 1 ||
 	    (config->num_connections == 1 && nbd->tag_set.timeout)) {
 		dev_err_ratelimited(nbd_to_dev(nbd),
@@ -455,6 +460,7 @@ static enum blk_eh_timer_return nbd_xmit_timeout(struct request *req,
 		return BLK_EH_RESET_TIMER;
 	}
 
+error_out:
 	dev_err_ratelimited(nbd_to_dev(nbd), "Connection timed out\n");
 	set_bit(NBD_RT_TIMEDOUT, &config->runtime_flags);
 	cmd->status = BLK_STS_IOERR;
-- 
2.11.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH v3 2/2] nbd: introduce a client flag to do zero timeout handling
  2020-09-30  3:23 [PATCH v3 0/2] nbd: improve timeout handling and a fix Hou Pu
  2020-09-30  3:23 ` [PATCH v3 1/2] nbd: return -ETIMEDOUT when NBD_DO_IT ioctl returns Hou Pu
@ 2020-09-30  3:23 ` Hou Pu
  2020-11-08  8:46 ` [PATCH v3 0/2] nbd: improve timeout handling and a fix Hou Pu
  2 siblings, 0 replies; 4+ messages in thread
From: Hou Pu @ 2020-09-30  3:23 UTC (permalink / raw)
  To: josef, axboe; +Cc: linux-block, nbd, Hou Pu

Introduce a dedicated client flag NBD_RT_WAIT_ON_TIMEOUT to reset
timer in nbd_xmit_timer instead of depending on tag_set.timeout == 0.
So that the timeout value could be configured by the user to
whatever they like instead of the default 30s. A smaller timeout
value allow us to detect if a new socket is reconfigured in a
shorter time. Thus the io could be requeued more quickly.

In multiple sockets configuration, the user could also disable
dropping the socket in timeout by setting this flag.

The tag_set.timeout == 0 setting still works like before.

Reviewed-by: Josef Bacik <josef@toxicpanda.com>
Signed-off-by: Hou Pu <houpu@bytedance.com>
---
 drivers/block/nbd.c      | 27 ++++++++++++++++++++++-----
 include/uapi/linux/nbd.h |  4 ++++
 2 files changed, 26 insertions(+), 5 deletions(-)

diff --git a/drivers/block/nbd.c b/drivers/block/nbd.c
index 538e9dcf5bf2..2d32e31b7b96 100644
--- a/drivers/block/nbd.c
+++ b/drivers/block/nbd.c
@@ -80,6 +80,7 @@ struct link_dead_args {
 #define NBD_RT_BOUND			5
 #define NBD_RT_DESTROY_ON_DISCONNECT	6
 #define NBD_RT_DISCONNECT_ON_CLOSE	7
+#define NBD_RT_WAIT_ON_TIMEOUT		8
 
 #define NBD_DESTROY_ON_DISCONNECT	0
 #define NBD_DISCONNECT_REQUESTED	1
@@ -378,6 +379,16 @@ static u32 req_to_nbd_cmd_type(struct request *req)
 	}
 }
 
+static inline bool wait_on_timeout(struct nbd_device *nbd,
+				   struct nbd_config *config)
+{
+	if (test_bit(NBD_RT_WAIT_ON_TIMEOUT, &config->runtime_flags) ||
+	    (config->num_connections == 1 && nbd->tag_set.timeout == 0))
+		return true;
+	else
+		return false;
+}
+
 static enum blk_eh_timer_return nbd_xmit_timeout(struct request *req,
 						 bool reserved)
 {
@@ -400,8 +411,7 @@ static enum blk_eh_timer_return nbd_xmit_timeout(struct request *req,
 	    nbd->tag_set.timeout)
 		goto error_out;
 
-	if (config->num_connections > 1 ||
-	    (config->num_connections == 1 && nbd->tag_set.timeout)) {
+	if (!wait_on_timeout(nbd, config)) {
 		dev_err_ratelimited(nbd_to_dev(nbd),
 				    "Connection timed out, retrying (%d/%d alive)\n",
 				    atomic_read(&config->live_connections),
@@ -432,9 +442,7 @@ static enum blk_eh_timer_return nbd_xmit_timeout(struct request *req,
 			nbd_config_put(nbd);
 			return BLK_EH_DONE;
 		}
-	}
-
-	if (!nbd->tag_set.timeout) {
+	} else {
 		/*
 		 * Userspace sets timeout=0 to disable socket disconnection,
 		 * so just warn and reset the timer.
@@ -1956,6 +1964,9 @@ static int nbd_genl_connect(struct sk_buff *skb, struct genl_info *info)
 			set_bit(NBD_RT_DISCONNECT_ON_CLOSE,
 				&config->runtime_flags);
 		}
+		if (flags & NBD_CFLAG_WAIT_ON_TIMEOUT)
+			set_bit(NBD_RT_WAIT_ON_TIMEOUT,
+				&config->runtime_flags);
 	}
 
 	if (info->attrs[NBD_ATTR_SOCKETS]) {
@@ -2139,6 +2150,12 @@ static int nbd_genl_reconfigure(struct sk_buff *skb, struct genl_info *info)
 			clear_bit(NBD_RT_DISCONNECT_ON_CLOSE,
 					&config->runtime_flags);
 		}
+		if (flags & NBD_CFLAG_WAIT_ON_TIMEOUT)
+			set_bit(NBD_RT_WAIT_ON_TIMEOUT,
+				&config->runtime_flags);
+		else
+			clear_bit(NBD_RT_WAIT_ON_TIMEOUT,
+				  &config->runtime_flags);
 	}
 
 	if (info->attrs[NBD_ATTR_SOCKETS]) {
diff --git a/include/uapi/linux/nbd.h b/include/uapi/linux/nbd.h
index 20d6cc91435d..cc3abfb92de5 100644
--- a/include/uapi/linux/nbd.h
+++ b/include/uapi/linux/nbd.h
@@ -56,6 +56,10 @@ enum {
 #define NBD_CFLAG_DISCONNECT_ON_CLOSE (1 << 1) /* disconnect the nbd device on
 						*  close by last opener.
 						*/
+#define NBD_CFLAG_WAIT_ON_TIMEOUT (1 << 2) /* do not fallback to other sockets
+					    * in io timeout, instead just reset
+					    * timer and wait.
+					    */
 
 /* userspace doesn't need the nbd_device structure */
 
-- 
2.11.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH v3 0/2] nbd: improve timeout handling and a fix
  2020-09-30  3:23 [PATCH v3 0/2] nbd: improve timeout handling and a fix Hou Pu
  2020-09-30  3:23 ` [PATCH v3 1/2] nbd: return -ETIMEDOUT when NBD_DO_IT ioctl returns Hou Pu
  2020-09-30  3:23 ` [PATCH v3 2/2] nbd: introduce a client flag to do zero timeout handling Hou Pu
@ 2020-11-08  8:46 ` Hou Pu
  2 siblings, 0 replies; 4+ messages in thread
From: Hou Pu @ 2020-11-08  8:46 UTC (permalink / raw)
  To: axboe; +Cc: josef, linux-block, nbd



On 2020/9/30 11:23 AM, Hou Pu wrote:
> Patch #1 is a fix. Patch #2 is trying to improve io timeout
> handling.
> 
> Thanks,
> Hou
> 
> v3 changes:
> * Add 'Reviewed-by: Josef Bacik <josef@toxicpanda.com>' in patch #2.

Hi Jens,
Sorry to bother. Emmm, It would be great to pick up these 2 patches
into the upstream. Could you give a helping hand?

Thanks,
Hou

> 
> v2 changes:
> * Add 'Reviewed-by: Josef Bacik <josef@toxicpanda.com>' in patch #1.
> * Original patch #2 is dropped.
> * Keep the behavior same as before when we don't set a .timeout
> and num_connections > 1.
> * Coding style fixes.
> 
> Hou Pu (2):
>    nbd: return -ETIMEDOUT when NBD_DO_IT ioctl returns
>    nbd: introduce a client flag to do zero timeout handling
> 
>   drivers/block/nbd.c      | 33 ++++++++++++++++++++++++++++-----
>   include/uapi/linux/nbd.h |  4 ++++
>   2 files changed, 32 insertions(+), 5 deletions(-)
> 

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2020-11-08  8:47 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-09-30  3:23 [PATCH v3 0/2] nbd: improve timeout handling and a fix Hou Pu
2020-09-30  3:23 ` [PATCH v3 1/2] nbd: return -ETIMEDOUT when NBD_DO_IT ioctl returns Hou Pu
2020-09-30  3:23 ` [PATCH v3 2/2] nbd: introduce a client flag to do zero timeout handling Hou Pu
2020-11-08  8:46 ` [PATCH v3 0/2] nbd: improve timeout handling and a fix Hou Pu

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.