Commit 9a99ff90 authored by Shuhei Matsumoto's avatar Shuhei Matsumoto Committed by Jim Harris
Browse files

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: default avatarShuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
Change-Id: I28dcfa41daf1fe2bbe76fac80e1bc2abc24751f7
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/8471


Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
Community-CI: Mellanox Build Bot
Reviewed-by: default avatarJim Harris <james.r.harris@intel.com>
Reviewed-by: default avatarAleksey Marchuk <alexeymar@mellanox.com>
parent 3959e397
Loading
Loading
Loading
Loading
+15 −2
Original line number Diff line number Diff line
@@ -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)