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 <shuhei.matsumoto.xt@hitachi.com>
Change-Id: I28dcfa41daf1fe2bbe76fac80e1bc2abc24751f7
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/8471
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
Community-CI: Mellanox Build Bot
Reviewed-by: Jim Harris <james.r.harris@intel.com>
Reviewed-by: Aleksey Marchuk <alexeymar@mellanox.com>
This commit is contained in:
Shuhei Matsumoto 2021-06-22 14:20:37 +09:00 committed by Jim Harris
parent 3959e397d4
commit 9a99ff90f9

View File

@ -73,6 +73,7 @@ static int g_insert_times;
static int g_removal_times; static int g_removal_times;
static int g_shm_id = -1; static int g_shm_id = -1;
static uint64_t g_timeout_in_us = SPDK_SEC_TO_USEC; static uint64_t g_timeout_in_us = SPDK_SEC_TO_USEC;
static struct spdk_nvme_detach_ctx *g_detach_ctx;
static void static void
task_complete(struct perf_task *task); task_complete(struct perf_task *task);
@ -142,7 +143,7 @@ unregister_dev(struct dev_ctx *dev)
fprintf(stderr, "unregister_dev: %s\n", dev->name); fprintf(stderr, "unregister_dev: %s\n", dev->name);
spdk_nvme_ctrlr_free_io_qpair(dev->qpair); 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); TAILQ_REMOVE(&g_devs, dev, tailq);
free(dev); 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), * in g_devs (for example, because we skipped it during register_dev),
* so immediately detach it. * so immediately detach it.
*/ */
spdk_nvme_detach(ctrlr); spdk_nvme_detach_async(ctrlr, &g_detach_ctx);
} }
static void static void
@ -338,6 +339,7 @@ io_loop(void)
struct dev_ctx *dev, *dev_tmp; struct dev_ctx *dev, *dev_tmp;
uint64_t tsc_end; uint64_t tsc_end;
uint64_t next_stats_tsc; uint64_t next_stats_tsc;
int rc;
tsc_end = spdk_get_ticks() + g_time_in_sec * g_tsc_rate; tsc_end = spdk_get_ticks() + g_time_in_sec * g_tsc_rate;
next_stats_tsc = spdk_get_ticks(); 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(); now = spdk_get_ticks();
if (now > tsc_end) { if (now > tsc_end) {
break; break;
@ -400,6 +409,10 @@ io_loop(void)
drain_io(dev); drain_io(dev);
unregister_dev(dev); unregister_dev(dev);
} }
if (g_detach_ctx) {
spdk_nvme_detach_poll(g_detach_ctx);
}
} }
static void usage(char *program_name) static void usage(char *program_name)