nvme: check whether the process is already added at the probe phase

Change-Id: I556c0fd993998a291bff227365102b9985e6d7ec
Signed-off-by: GangCao <gang.cao@intel.com>
This commit is contained in:
GangCao 2016-11-16 21:25:27 -05:00 committed by Jim Harris
parent a1948352a3
commit 9ec380ba90

View File

@ -804,14 +804,23 @@ nvme_ctrlr_configure_aer(struct spdk_nvme_ctrlr *ctrlr)
} }
/** /**
* This function will be called when a new process is using the controller. * This function will be called when a process is using the controller.
* 1. For the primary process, it is called when constructing the controller. * 1. For the primary process, it is called when constructing the controller.
* 2. For the secondary process, it is called at probing the controller. * 2. For the secondary process, it is called at probing the controller.
* Note: will check whether the process is already added for the same process.
*/ */
int int
nvme_ctrlr_add_process(struct spdk_nvme_ctrlr *ctrlr, void *devhandle) nvme_ctrlr_add_process(struct spdk_nvme_ctrlr *ctrlr, void *devhandle)
{ {
struct spdk_nvme_ctrlr_process *ctrlr_proc; struct spdk_nvme_ctrlr_process *ctrlr_proc, *active_proc;
pid_t pid = getpid();
/* Check whether the process is already added or not */
TAILQ_FOREACH(active_proc, &ctrlr->active_procs, tailq) {
if (active_proc->pid == pid) {
return 0;
}
}
/* Initialize the per process properties for this ctrlr */ /* Initialize the per process properties for this ctrlr */
ctrlr_proc = spdk_zmalloc(sizeof(struct spdk_nvme_ctrlr_process), 64, NULL); ctrlr_proc = spdk_zmalloc(sizeof(struct spdk_nvme_ctrlr_process), 64, NULL);
@ -822,7 +831,7 @@ nvme_ctrlr_add_process(struct spdk_nvme_ctrlr *ctrlr, void *devhandle)
} }
ctrlr_proc->is_primary = spdk_process_is_primary(); ctrlr_proc->is_primary = spdk_process_is_primary();
ctrlr_proc->pid = getpid(); ctrlr_proc->pid = pid;
STAILQ_INIT(&ctrlr_proc->active_reqs); STAILQ_INIT(&ctrlr_proc->active_reqs);
ctrlr_proc->devhandle = devhandle; ctrlr_proc->devhandle = devhandle;
ctrlr_proc->ref = 0; ctrlr_proc->ref = 0;