From 8afa746b4d4dd44195380dd8b5e3265c514c1ca5 Mon Sep 17 00:00:00 2001 From: Shuhei Matsumoto Date: Thu, 4 Nov 2021 01:47:34 +0900 Subject: [PATCH] bdev/nvme: Use new APIs in a reset ctrlr sequence Replace the spdk_nvme_ctrlr_reset_async() and spdk_nvme_reset_poll_async() calls by the spdk_nvme_ctrlr_disconnect(), spdk_nvme_ctrlr_reconnect_async(), and spdk_nvme_ctrlr_reconnect_poll_async() calls in a reset ctrlr sequence. spdk_nvme_ctrlr_disconnect() can fail if ctrlr is already resetting or removed. But both cases are not possible. reset is controlled and the callback to the hot remove is called when the ctrlr is hot removed. So we assume spdk_nvme_ctrlr_disconnect() always succeed. Signed-off-by: Shuhei Matsumoto Change-Id: I1299e198597b2a2110f80b9a868e2dae015682ee Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/10092 Community-CI: Broadcom CI Tested-by: SPDK CI Jenkins Reviewed-by: Aleksey Marchuk Reviewed-by: Ben Walker Reviewed-by: Jim Harris --- module/bdev/nvme/bdev_nvme.c | 20 +++++++------ module/bdev/nvme/bdev_nvme.h | 1 - .../lib/bdev/nvme/bdev_nvme.c/bdev_nvme_ut.c | 28 +++++-------------- 3 files changed, 18 insertions(+), 31 deletions(-) diff --git a/module/bdev/nvme/bdev_nvme.c b/module/bdev/nvme/bdev_nvme.c index 6f5daf1e04..e9940ddf5c 100644 --- a/module/bdev/nvme/bdev_nvme.c +++ b/module/bdev/nvme/bdev_nvme.c @@ -1289,7 +1289,7 @@ bdev_nvme_ctrlr_reset_poll(void *arg) struct nvme_ctrlr *nvme_ctrlr = arg; int rc; - rc = spdk_nvme_ctrlr_reset_poll_async(nvme_ctrlr->reset_ctx); + rc = spdk_nvme_ctrlr_reconnect_poll_async(nvme_ctrlr->ctrlr); if (rc == -EAGAIN) { return SPDK_POLLER_BUSY; } @@ -1311,20 +1311,22 @@ static void bdev_nvme_reset_ctrlr(struct spdk_io_channel_iter *i, int status) { struct nvme_ctrlr *nvme_ctrlr = spdk_io_channel_iter_get_io_device(i); - int rc; + int rc __attribute__((unused)); assert(status == 0); - rc = spdk_nvme_ctrlr_reset_async(nvme_ctrlr->ctrlr, &nvme_ctrlr->reset_ctx); - if (rc != 0) { - SPDK_ERRLOG("Create controller reset context failed\n"); - bdev_nvme_reset_complete(nvme_ctrlr, false); - return; - } + /* Disconnect fails if ctrlr is already resetting or removed. Both cases are + * not possible. Reset is controlled and the callback to hot remove is called + * when ctrlr is hot removed. + */ + rc = spdk_nvme_ctrlr_disconnect(nvme_ctrlr->ctrlr); + assert(rc == 0); + + spdk_nvme_ctrlr_reconnect_async(nvme_ctrlr->ctrlr); + assert(nvme_ctrlr->reset_detach_poller == NULL); nvme_ctrlr->reset_detach_poller = SPDK_POLLER_REGISTER(bdev_nvme_ctrlr_reset_poll, nvme_ctrlr, 0); - } static void diff --git a/module/bdev/nvme/bdev_nvme.h b/module/bdev/nvme/bdev_nvme.h index 6800d3db91..61bf174308 100644 --- a/module/bdev/nvme/bdev_nvme.h +++ b/module/bdev/nvme/bdev_nvme.h @@ -122,7 +122,6 @@ struct nvme_ctrlr { bdev_nvme_reset_cb reset_cb_fn; void *reset_cb_arg; - struct spdk_nvme_ctrlr_reset_ctx *reset_ctx; /* Poller used to check for reset/detach completion */ struct spdk_poller *reset_detach_poller; struct spdk_nvme_detach_ctx *detach_ctx; diff --git a/test/unit/lib/bdev/nvme/bdev_nvme.c/bdev_nvme_ut.c b/test/unit/lib/bdev/nvme/bdev_nvme.c/bdev_nvme_ut.c index 385739a4e4..318dc16889 100644 --- a/test/unit/lib/bdev/nvme/bdev_nvme.c/bdev_nvme_ut.c +++ b/test/unit/lib/bdev/nvme/bdev_nvme.c/bdev_nvme_ut.c @@ -264,10 +264,6 @@ struct spdk_nvme_probe_ctx { struct spdk_nvme_ctrlr *init_ctrlr; }; -struct spdk_nvme_ctrlr_reset_ctx { - struct spdk_nvme_ctrlr *ctrlr; -}; - uint32_t spdk_nvme_ctrlr_get_first_active_ns(struct spdk_nvme_ctrlr *ctrlr) { @@ -729,12 +725,8 @@ spdk_nvme_ctrlr_free_io_qpair(struct spdk_nvme_qpair *qpair) } int -spdk_nvme_ctrlr_reset_poll_async(struct spdk_nvme_ctrlr_reset_ctx *ctrlr_reset_ctx) +spdk_nvme_ctrlr_reconnect_poll_async(struct spdk_nvme_ctrlr *ctrlr) { - struct spdk_nvme_ctrlr *ctrlr = ctrlr_reset_ctx->ctrlr; - - free(ctrlr_reset_ctx); - if (ctrlr->fail_reset) { ctrlr->is_failed = true; return -EIO; @@ -743,22 +735,16 @@ spdk_nvme_ctrlr_reset_poll_async(struct spdk_nvme_ctrlr_reset_ctx *ctrlr_reset_c return 0; } -int -spdk_nvme_ctrlr_reset_async(struct spdk_nvme_ctrlr *ctrlr, - struct spdk_nvme_ctrlr_reset_ctx **reset_ctx) +void +spdk_nvme_ctrlr_reconnect_async(struct spdk_nvme_ctrlr *ctrlr) { - struct spdk_nvme_ctrlr_reset_ctx *ctrlr_reset_ctx; - - ctrlr_reset_ctx = calloc(1, sizeof(*ctrlr_reset_ctx)); - if (!ctrlr_reset_ctx) { - return -ENOMEM; - } +} +int +spdk_nvme_ctrlr_disconnect(struct spdk_nvme_ctrlr *ctrlr) +{ ctrlr->is_failed = false; - ctrlr_reset_ctx->ctrlr = ctrlr; - *reset_ctx = ctrlr_reset_ctx; - return 0; }