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

nvme_pci: ctrlr_scan_attached callback



Currently, enabling hotplug results in launching a poller, which probes
devices and responds to hot-inserts/-removes. Without it, a device might
be stuck attached to SPDK in cases of unexpected hot-remove
(spdk_pci_device_detach will never be called). To work around that,
users would be required to enable hotplug (via bdev_nvme_set_hotplug
--enable) each time they want to attach a device to SPDK application.

We could perform a NVMe PCIe transport scan without attaching new
devices instead. This new scan could handle only a hot-remove of
underlying device to prevent SPDK from hogging it.

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


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 ff659498
Loading
Loading
Loading
Loading
+15 −7
Original line number Diff line number Diff line
@@ -852,6 +852,16 @@ pcie_nvme_enum_cb(void *ctx, struct spdk_pci_device *pci_dev)
	return nvme_ctrlr_probe(&trid, enum_ctx->probe_ctx, pci_dev);
}

static int
nvme_pci_ctrlr_scan_attached(struct spdk_nvme_probe_ctx *probe_ctx)
{
	/* Only the primary process can monitor hotplug. */
	if (spdk_process_is_primary()) {
		return _nvme_pcie_hotplug_monitor(probe_ctx);
	}
	return 0;
}

static int
nvme_pcie_ctrlr_scan(struct spdk_nvme_probe_ctx *probe_ctx,
		     bool direct_connect)
@@ -868,14 +878,11 @@ nvme_pcie_ctrlr_scan(struct spdk_nvme_probe_ctx *probe_ctx,
	}

	/* Only the primary process can monitor hotplug. */
	if (spdk_process_is_primary()) {
		if (_nvme_pcie_hotplug_monitor(probe_ctx) > 0) {
	if (nvme_pci_ctrlr_scan_attached(probe_ctx) > 0) {
		/* Some removal events were received. Return immediately, avoiding
			 * an spdk_pci_enumerate() which could trigger issue #3205.
			 */
		 * an spdk_pci_enumerate() which could trigger issue #3205. */
		return 0;
	}
	}

	if (enum_ctx.has_pci_addr == false) {
		return spdk_pci_enumerate(spdk_pci_nvme_get_driver(),
@@ -1077,6 +1084,7 @@ const struct spdk_nvme_transport_ops pcie_ops = {
	.type = SPDK_NVME_TRANSPORT_PCIE,
	.ctrlr_construct = nvme_pcie_ctrlr_construct,
	.ctrlr_scan = nvme_pcie_ctrlr_scan,
	.ctrlr_scan_attached = nvme_pci_ctrlr_scan_attached,
	.ctrlr_destruct = nvme_pcie_ctrlr_destruct,
	.ctrlr_enable = nvme_pcie_ctrlr_enable,