nbd: set io timeout

After setting io timeout, host can avoid nbd io
stuck or kernel hang occasionally caused by nbd
stop or underlying bdev removal.

Change-Id: I4ba2a0af7ff7bed369cdaf86121f082136dc1a0b
Signed-off-by: Liu Xiaodong <xiaodong.liu@intel.com>
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/6191
Community-CI: Broadcom CI
Community-CI: Mellanox Build Bot
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: <dongx.yi@intel.com>
Reviewed-by: Ben Walker <benjamin.walker@intel.com>
Reviewed-by: Changpeng Liu <changpeng.liu@intel.com>
Reviewed-by: Ziye Yang <ziye.yang@intel.com>
This commit is contained in:
Liu Xiaodong 2021-02-01 08:19:14 -05:00 committed by Tomasz Zawadzki
parent eea826a276
commit b7c33b5e61

View File

@ -50,6 +50,7 @@
#define GET_IO_LOOP_COUNT 16
#define NBD_BUSY_WAITING_MS 1000
#define NBD_BUSY_POLLING_INTERVAL_US 20000
#define NBD_IO_TIMEOUT_S 60
enum nbd_io_state_t {
/* Receiving or ready to receive nbd request header */
@ -922,6 +923,17 @@ nbd_start_complete(struct spdk_nbd_start_ctx *ctx)
goto err;
}
#ifdef NBD_SET_TIMEOUT
rc = ioctl(ctx->nbd->dev_fd, NBD_SET_TIMEOUT, NBD_IO_TIMEOUT_S);
if (rc == -1) {
SPDK_ERRLOG("ioctl(NBD_SET_TIMEOUT) failed: %s\n", spdk_strerror(errno));
rc = -errno;
goto err;
}
#else
SPDK_NOTICELOG("ioctl(NBD_SET_TIMEOUT) is not supported.\n");
#endif
#ifdef NBD_FLAG_SEND_TRIM
rc = ioctl(ctx->nbd->dev_fd, NBD_SET_FLAGS, NBD_FLAG_SEND_TRIM);
if (rc == -1) {