nvme: detach the pci device with calling process's own devhandle

Change-Id: I2693b4bd29e0500379d5e399723aec7e44bffca3
Signed-off-by: GangCao <gang.cao@intel.com>
This commit is contained in:
GangCao 2017-05-16 03:19:06 -04:00 committed by Daniel Verkamp
parent 644678258f
commit b347d551e8
5 changed files with 41 additions and 3 deletions

View File

@ -1106,6 +1106,30 @@ nvme_ctrlr_get_ref_count(struct spdk_nvme_ctrlr *ctrlr)
return ref;
}
/**
* Get the PCI device handle which is only visible to its associated process.
*/
struct spdk_pci_device *
nvme_ctrlr_proc_get_devhandle(struct spdk_nvme_ctrlr *ctrlr)
{
struct spdk_nvme_ctrlr_process *active_proc;
pid_t pid = getpid();
struct spdk_pci_device *devhandle = NULL;
nvme_robust_mutex_lock(&ctrlr->ctrlr_lock);
TAILQ_FOREACH(active_proc, &ctrlr->active_procs, tailq) {
if (active_proc->pid == pid) {
devhandle = active_proc->devhandle;
break;
}
}
nvme_robust_mutex_unlock(&ctrlr->ctrlr_lock);
return devhandle;
}
/**
* This function will be called repeatedly during initialization until the controller is ready.
*/

View File

@ -524,6 +524,7 @@ void nvme_completion_poll_cb(void *arg, const struct spdk_nvme_cpl *cpl);
int nvme_ctrlr_add_process(struct spdk_nvme_ctrlr *ctrlr, void *devhandle);
void nvme_ctrlr_free_processes(struct spdk_nvme_ctrlr *ctrlr);
struct spdk_pci_device *nvme_ctrlr_proc_get_devhandle(struct spdk_nvme_ctrlr *ctrlr);
int nvme_ctrlr_probe(const struct spdk_nvme_transport_id *trid, void *devhandle,
spdk_nvme_probe_cb probe_cb, void *cb_ctx);

View File

@ -775,6 +775,7 @@ int
nvme_pcie_ctrlr_destruct(struct spdk_nvme_ctrlr *ctrlr)
{
struct nvme_pcie_ctrlr *pctrlr = nvme_pcie_ctrlr(ctrlr);
struct spdk_pci_device *devhandle = nvme_ctrlr_proc_get_devhandle(ctrlr);
if (ctrlr->adminq) {
nvme_pcie_qpair_destroy(ctrlr->adminq);
@ -783,7 +784,11 @@ nvme_pcie_ctrlr_destruct(struct spdk_nvme_ctrlr *ctrlr)
nvme_ctrlr_free_processes(ctrlr);
nvme_pcie_ctrlr_free_bars(pctrlr);
spdk_pci_device_detach(pctrlr->devhandle);
if (devhandle) {
spdk_pci_device_detach(devhandle);
}
spdk_free(pctrlr);
return 0;

View File

@ -19,10 +19,12 @@ if [ $(uname -s) = Linux ]; then
timing_enter mp_fault_test
timing_enter mp_fault_test_1
$rootdir/examples/nvme/arbitration/arbitration -i 0 -s 4096 -t 5 -c 0xf &
pid=$!
sleep 3
$rootdir/examples/nvme/perf/perf -i 0 -q 128 -w read -s 4096 -t 3 -c 0x10
$rootdir/examples/nvme/perf/perf -i 0 -q 128 -w read -s 4096 -t 5 -c 0x10 &
sleep 1
kill -9 $!
kill -9 $pid
wait $!
timing_exit mp_fault_test_1
timing_enter mp_fault_test_2

View File

@ -176,6 +176,12 @@ nvme_ctrlr_free_processes(struct spdk_nvme_ctrlr *ctrlr)
abort();
}
struct spdk_pci_device *
nvme_ctrlr_proc_get_devhandle(struct spdk_nvme_ctrlr *ctrlr)
{
abort();
}
int
nvme_ctrlr_probe(const struct spdk_nvme_transport_id *trid, void *devhandle,
spdk_nvme_probe_cb probe_cb, void *cb_ctx)