From a22f55658ca26566a5d5c58160ad127eaef17456 Mon Sep 17 00:00:00 2001 From: Seth Howell Date: Tue, 28 Jul 2020 14:35:13 -0700 Subject: [PATCH] lib/nvme: add timeout to fabric connect commands. We can't afford to wait here blocking forever. Add a reasonable timeout (1 second) to this command. Signed-off-by: Seth Howell Change-Id: I7e373c5515d42a46403f03d7d09e72225f8910ff Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/3563 Community-CI: Mellanox Build Bot Tested-by: SPDK CI Jenkins Reviewed-by: Jim Harris Reviewed-by: Aleksey Marchuk --- lib/nvme/nvme_fabric.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/nvme/nvme_fabric.c b/lib/nvme/nvme_fabric.c index 9fff20873d..294a17cbbf 100644 --- a/lib/nvme/nvme_fabric.c +++ b/lib/nvme/nvme_fabric.c @@ -40,6 +40,12 @@ #include "spdk/endian.h" #include "spdk/string.h" +#ifdef DEBUG +#define NVME_FABRIC_CONNECT_COMMAND_TIMEOUT 0 +#else +#define NVME_FABRIC_CONNECT_COMMAND_TIMEOUT 1 +#endif + static int nvme_fabric_prop_set_cmd(struct spdk_nvme_ctrlr *ctrlr, uint32_t offset, uint8_t size, uint64_t value) @@ -454,7 +460,8 @@ nvme_fabric_qpair_connect(struct spdk_nvme_qpair *qpair, uint32_t num_entries) return rc; } - if (nvme_wait_for_completion(qpair, status)) { + /* If we time out, the qpair will abort the request upon destruction. */ + if (nvme_wait_for_completion_timeout(qpair, status, NVME_FABRIC_CONNECT_COMMAND_TIMEOUT)) { SPDK_ERRLOG("Connect command failed\n"); spdk_free(nvmf_data); if (!status->timed_out) {