From 9a99ff90f9244e67025ab33af90d99273b1409df Mon Sep 17 00:00:00 2001 From: Shuhei Matsumoto Date: Tue, 22 Jun 2021 14:20:37 +0900 Subject: [PATCH] example/nvme_hotplug: Use spdk_nvme_detach_async() We can add one or more ctrlrs to the existing detach context even after polling started as long as spdk_nvme_detach_poll_async() returns -EBUSY. By relying on this update, add a global variable g_detach_ctx and use it to aggregate multiple detachments. Signed-off-by: Shuhei Matsumoto Change-Id: I28dcfa41daf1fe2bbe76fac80e1bc2abc24751f7 Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/8471 Tested-by: SPDK CI Jenkins Community-CI: Mellanox Build Bot Reviewed-by: Jim Harris Reviewed-by: Aleksey Marchuk --- examples/nvme/hotplug/hotplug.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/examples/nvme/hotplug/hotplug.c b/examples/nvme/hotplug/hotplug.c index ff821c7ed..14eb820f8 100644 --- a/examples/nvme/hotplug/hotplug.c +++ b/examples/nvme/hotplug/hotplug.c @@ -73,6 +73,7 @@ static int g_insert_times; static int g_removal_times; static int g_shm_id = -1; static uint64_t g_timeout_in_us = SPDK_SEC_TO_USEC; +static struct spdk_nvme_detach_ctx *g_detach_ctx; static void task_complete(struct perf_task *task); @@ -142,7 +143,7 @@ unregister_dev(struct dev_ctx *dev) fprintf(stderr, "unregister_dev: %s\n", dev->name); spdk_nvme_ctrlr_free_io_qpair(dev->qpair); - spdk_nvme_detach(dev->ctrlr); + spdk_nvme_detach_async(dev->ctrlr, &g_detach_ctx); TAILQ_REMOVE(&g_devs, dev, tailq); free(dev); @@ -319,7 +320,7 @@ remove_cb(void *cb_ctx, struct spdk_nvme_ctrlr *ctrlr) * in g_devs (for example, because we skipped it during register_dev), * so immediately detach it. */ - spdk_nvme_detach(ctrlr); + spdk_nvme_detach_async(ctrlr, &g_detach_ctx); } static void @@ -338,6 +339,7 @@ io_loop(void) struct dev_ctx *dev, *dev_tmp; uint64_t tsc_end; uint64_t next_stats_tsc; + int rc; tsc_end = spdk_get_ticks() + g_time_in_sec * g_tsc_rate; next_stats_tsc = spdk_get_ticks(); @@ -382,6 +384,13 @@ io_loop(void) } } + if (g_detach_ctx) { + rc = spdk_nvme_detach_poll_async(g_detach_ctx); + if (rc == 0) { + g_detach_ctx = NULL; + } + } + now = spdk_get_ticks(); if (now > tsc_end) { break; @@ -400,6 +409,10 @@ io_loop(void) drain_io(dev); unregister_dev(dev); } + + if (g_detach_ctx) { + spdk_nvme_detach_poll(g_detach_ctx); + } } static void usage(char *program_name)