From 8db29979b1f430cd8c639a7c5874cd568fb717d3 Mon Sep 17 00:00:00 2001 From: Changpeng Liu Date: Thu, 6 Sep 2018 23:48:16 -0400 Subject: [PATCH] nvme: broke up nvme_ctrlr_set_keep_alive_timeout() completion into a function Change-Id: I9b92caa2d151b5a4835c0ecb7023d61cdf2a2898 Signed-off-by: Changpeng Liu Reviewed-on: https://review.gerrithub.io/424778 Tested-by: SPDK CI Jenkins Chandler-Test-Pool: SPDK Automated Test System Reviewed-by: Shuhei Matsumoto Reviewed-by: Ben Walker Reviewed-by: Jim Harris --- lib/nvme/nvme_ctrlr.c | 45 +++++++++++++++++++++++++------------------ 1 file changed, 26 insertions(+), 19 deletions(-) diff --git a/lib/nvme/nvme_ctrlr.c b/lib/nvme/nvme_ctrlr.c index 77faf71cd5..1f1b74c277 100644 --- a/lib/nvme/nvme_ctrlr.c +++ b/lib/nvme/nvme_ctrlr.c @@ -1001,11 +1001,35 @@ nvme_ctrlr_set_num_qpairs(struct spdk_nvme_ctrlr *ctrlr) return 0; } +static void +nvme_ctrlr_set_keep_alive_timeout_done(void *arg, const struct spdk_nvme_cpl *cpl) +{ + uint32_t keep_alive_interval_ms; + struct spdk_nvme_ctrlr *ctrlr = (struct spdk_nvme_ctrlr *)arg; + + if (ctrlr->opts.keep_alive_timeout_ms != cpl->cdw0) { + SPDK_DEBUGLOG(SPDK_LOG_NVME, "Controller adjusted keep alive timeout to %u ms\n", + cpl->cdw0); + } + + ctrlr->opts.keep_alive_timeout_ms = cpl->cdw0; + + keep_alive_interval_ms = ctrlr->opts.keep_alive_timeout_ms / 2; + if (keep_alive_interval_ms == 0) { + keep_alive_interval_ms = 1; + } + SPDK_DEBUGLOG(SPDK_LOG_NVME, "Sending keep alive every %u ms\n", keep_alive_interval_ms); + + ctrlr->keep_alive_interval_ticks = (keep_alive_interval_ms * spdk_get_ticks_hz()) / UINT64_C(1000); + + /* Schedule the first Keep Alive to be sent as soon as possible. */ + ctrlr->next_keep_alive_tick = spdk_get_ticks(); +} + static int nvme_ctrlr_set_keep_alive_timeout(struct spdk_nvme_ctrlr *ctrlr) { struct nvme_completion_poll_status status; - uint32_t keep_alive_interval_ms; int rc; if (ctrlr->opts.keep_alive_timeout_ms == 0) { @@ -1033,24 +1057,7 @@ nvme_ctrlr_set_keep_alive_timeout(struct spdk_nvme_ctrlr *ctrlr) ctrlr->opts.keep_alive_timeout_ms = 0; return -ENXIO; } - - if (ctrlr->opts.keep_alive_timeout_ms != status.cpl.cdw0) { - SPDK_DEBUGLOG(SPDK_LOG_NVME, "Controller adjusted keep alive timeout to %u ms\n", - status.cpl.cdw0); - } - - ctrlr->opts.keep_alive_timeout_ms = status.cpl.cdw0; - - keep_alive_interval_ms = ctrlr->opts.keep_alive_timeout_ms / 2; - if (keep_alive_interval_ms == 0) { - keep_alive_interval_ms = 1; - } - SPDK_DEBUGLOG(SPDK_LOG_NVME, "Sending keep alive every %u ms\n", keep_alive_interval_ms); - - ctrlr->keep_alive_interval_ticks = (keep_alive_interval_ms * spdk_get_ticks_hz()) / UINT64_C(1000); - - /* Schedule the first Keep Alive to be sent as soon as possible. */ - ctrlr->next_keep_alive_tick = spdk_get_ticks(); + nvme_ctrlr_set_keep_alive_timeout_done(ctrlr, &status.cpl); return 0; }