From add76a3515f30afe21c7c8a12b71e9bb8e4d6fea Mon Sep 17 00:00:00 2001 From: Changpeng Liu Date: Tue, 5 Mar 2019 02:32:34 -0500 Subject: [PATCH] bdev/nvme: change hotplug poller with asynchronous probe API Change-Id: Id198e8ec79c84743ef5025e1552c4ce45ca30445 Signed-off-by: Changpeng Liu Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/445078 Tested-by: SPDK CI Jenkins Reviewed-by: Darek Stojaczyk Reviewed-by: wuzhouhui Reviewed-by: Jim Harris Reviewed-by: Shuhei Matsumoto --- lib/bdev/nvme/bdev_nvme.c | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/lib/bdev/nvme/bdev_nvme.c b/lib/bdev/nvme/bdev_nvme.c index bece36fe7..ecbc318f7 100644 --- a/lib/bdev/nvme/bdev_nvme.c +++ b/lib/bdev/nvme/bdev_nvme.c @@ -117,6 +117,7 @@ static uint64_t g_nvme_hotplug_poll_period_us = NVME_HOTPLUG_POLL_PERIOD_DEFAULT static bool g_nvme_hotplug_enabled = false; static struct spdk_thread *g_bdev_nvme_init_thread; static struct spdk_poller *g_hotplug_poller; +static struct spdk_nvme_probe_ctx *g_hotplug_probe_ctx; static char *g_nvme_hostnqn = NULL; static void nvme_ctrlr_create_bdevs(struct nvme_bdev_ctrlr *nvme_bdev_ctrlr); @@ -1059,8 +1060,25 @@ remove_cb(void *cb_ctx, struct spdk_nvme_ctrlr *ctrlr) static int bdev_nvme_hotplug(void *arg) { - if (spdk_nvme_probe(NULL, NULL, hotplug_probe_cb, attach_cb, remove_cb) != 0) { - SPDK_ERRLOG("spdk_nvme_probe() failed\n"); + struct spdk_nvme_transport_id trid_pcie; + int done; + + if (!g_hotplug_probe_ctx) { + memset(&trid_pcie, 0, sizeof(trid_pcie)); + trid_pcie.trtype = SPDK_NVME_TRANSPORT_PCIE; + + g_hotplug_probe_ctx = spdk_nvme_probe_async(&trid_pcie, NULL, + hotplug_probe_cb, + attach_cb, remove_cb); + if (!g_hotplug_probe_ctx) { + return -1; + } + } + + done = spdk_nvme_probe_poll_async(g_hotplug_probe_ctx); + if (done != -EAGAIN) { + g_hotplug_probe_ctx = NULL; + return 1; } return -1; @@ -1553,6 +1571,7 @@ bdev_nvme_library_fini(void) struct nvme_probe_skip_entry *entry, *entry_tmp; spdk_poller_unregister(&g_hotplug_poller); + free(g_hotplug_probe_ctx); TAILQ_FOREACH_SAFE(entry, &g_skipped_nvme_ctrlrs, tailq, entry_tmp) { TAILQ_REMOVE(&g_skipped_nvme_ctrlrs, entry, tailq);