nvme/pcie: don't allow constructing a controller from secondary process

With various possibilities to leak the rte_pci_device in the
primary process, we could technically construct the controller
in secondary. The nvme stack is not prepared for this and
will fail to initialize the device, but will still leak the
device object memory.

This patch adds an extra check to prevent any controller from
being constructed in secondary process.

Change-Id: I772f42b541c5db53310362b6595cebf9a30e8491
Signed-off-by: Darek Stojaczyk <dariusz.stojaczyk@intel.com>
Reviewed-on: https://review.gerrithub.io/434407 (master)
Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/448365
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: Jim Harris <james.r.harris@intel.com>
Reviewed-by: Ben Walker <benjamin.walker@intel.com>
This commit is contained in:
Darek Stojaczyk 2018-11-22 17:19:47 +01:00
parent ebb89b20ca
commit 9bdd0195fe

View File

@ -703,15 +703,14 @@ pcie_nvme_enum_cb(void *ctx, struct spdk_pci_device *pci_dev)
trid.trtype = SPDK_NVME_TRANSPORT_PCIE;
spdk_pci_addr_fmt(trid.traddr, sizeof(trid.traddr), &pci_addr);
/* Verify that this controller is not already attached */
ctrlr = spdk_nvme_get_ctrlr_by_trid_unsafe(&trid);
if (ctrlr) {
if (spdk_process_is_primary()) {
/* Already attached */
return 0;
} else {
return nvme_ctrlr_add_process(ctrlr, pci_dev);
if (!spdk_process_is_primary()) {
if (!ctrlr) {
SPDK_ERRLOG("Controller must be constructed in the primary process first.\n");
return -1;
}
return nvme_ctrlr_add_process(ctrlr, pci_dev);
}
/* check whether user passes the pci_addr */