Commit c2a77f51 authored by Krzysztof Karas's avatar Krzysztof Karas Committed by Tomasz Zawadzki
Browse files

module/bdev/nvme: add detach-monitor poller



In cases where hotplug option is not enabled (via bdev_nvme_set_hotplug)
we should still be able to detect unexpected hot-removes of underlying
devices (otherwise we'll wait for a detach that never happens, see issue
3226 and prints at lib/env_dpdk/pci.c:235).

Unless hotplug option is enabled, we do not want to attach to all
available devices, so we should only watch for remove events.
To achieve that, add a new polling function and assign it to
'g_hotplug_poller' upon first bdev_nvme_attach controller and
unregister the poller after all controllers are removed. In essence,
we'll always have a poller as long as at least one controller is
present, regardless of hotplug being enabled.

Fixes #3226

Change-Id: Iac281604e2fc3e108e16e415de4b19c50f0d3148
Signed-off-by: default avatarKrzysztof Karas <krzysztof.karas@intel.com>
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/23575


Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: default avatarJim Harris <jim.harris@samsung.com>
Community-CI: Mellanox Build Bot
Reviewed-by: default avatarShuhei Matsumoto <smatsumoto@nvidia.com>
parent e14876e1
Loading
Loading
Loading
Loading
+28 −0
Original line number Diff line number Diff line
@@ -5265,6 +5265,26 @@ populate_namespaces_cb(struct nvme_async_probe_ctx *ctx, int rc)
	}
}

static int
bdev_nvme_remove_poller(void *ctx)
{
	struct spdk_nvme_transport_id trid_pcie;

	if (TAILQ_EMPTY(&g_nvme_bdev_ctrlrs)) {
		spdk_poller_unregister(&g_hotplug_poller);
		return SPDK_POLLER_IDLE;
	}

	memset(&trid_pcie, 0, sizeof(trid_pcie));
	spdk_nvme_trid_populate_transport(&trid_pcie, SPDK_NVME_TRANSPORT_PCIE);

	if (spdk_nvme_scan_attached(&trid_pcie)) {
		SPDK_ERRLOG_RATELIMIT("spdk_nvme_scan_attached() failed\n");
	}

	return SPDK_POLLER_BUSY;
}

static void
nvme_ctrlr_create_done(struct nvme_ctrlr *nvme_ctrlr,
		       struct nvme_async_probe_ctx *ctx)
@@ -5276,6 +5296,11 @@ nvme_ctrlr_create_done(struct nvme_ctrlr *nvme_ctrlr,
				nvme_ctrlr->nbdev_ctrlr->name);

	nvme_ctrlr_populate_namespaces(nvme_ctrlr, ctx);

	if (g_hotplug_poller == NULL) {
		g_hotplug_poller = SPDK_POLLER_REGISTER(bdev_nvme_remove_poller, NULL,
							NVME_HOTPLUG_POLL_PERIOD_DEFAULT);
	}
}

static void
@@ -5784,6 +5809,9 @@ set_nvme_hotplug_period_cb(void *_ctx)
	spdk_poller_unregister(&g_hotplug_poller);
	if (ctx->enabled) {
		g_hotplug_poller = SPDK_POLLER_REGISTER(bdev_nvme_hotplug, NULL, ctx->period_us);
	} else {
		g_hotplug_poller = SPDK_POLLER_REGISTER(bdev_nvme_remove_poller, NULL,
							NVME_HOTPLUG_POLL_PERIOD_DEFAULT);
	}

	g_nvme_hotplug_poll_period_us = ctx->period_us;
+1 −0
Original line number Diff line number Diff line
@@ -75,6 +75,7 @@ DEFINE_STUB_V(spdk_nvme_qpair_set_abort_dnr, (struct spdk_nvme_qpair *qpair, boo
DEFINE_STUB(spdk_keyring_get_key, struct spdk_key *, (const char *name), NULL);
DEFINE_STUB_V(spdk_keyring_put_key, (struct spdk_key *k));
DEFINE_STUB(spdk_key_get_name, const char *, (struct spdk_key *k), NULL);
DEFINE_STUB(spdk_nvme_scan_attached, int, (const struct spdk_nvme_transport_id *trid), 0);

int
spdk_nvme_ctrlr_get_memory_domains(const struct spdk_nvme_ctrlr *ctrlr,