diff --git a/lib/nvme/nvme_ctrlr.c b/lib/nvme/nvme_ctrlr.c index aaab88be9..107156f0f 100644 --- a/lib/nvme/nvme_ctrlr.c +++ b/lib/nvme/nvme_ctrlr.c @@ -1136,6 +1136,7 @@ nvme_ctrlr_async_event_cb(void *arg, const struct spdk_nvme_cpl *cpl) { struct nvme_async_event_request *aer = arg; struct spdk_nvme_ctrlr *ctrlr = aer->ctrlr; + struct spdk_nvme_ctrlr_process *active_proc; if (cpl->status.sc == SPDK_NVME_SC_ABORTED_SQ_DELETION) { /* @@ -1147,8 +1148,9 @@ nvme_ctrlr_async_event_cb(void *arg, const struct spdk_nvme_cpl *cpl) return; } - if (ctrlr->aer_cb_fn != NULL) { - ctrlr->aer_cb_fn(ctrlr->aer_cb_arg, cpl); + active_proc = spdk_nvme_ctrlr_get_current_process(ctrlr); + if (active_proc && active_proc->aer_cb_fn) { + active_proc->aer_cb_fn(active_proc->aer_cb_arg, cpl); } /* @@ -1976,8 +1978,17 @@ spdk_nvme_ctrlr_register_aer_callback(struct spdk_nvme_ctrlr *ctrlr, spdk_nvme_aer_cb aer_cb_fn, void *aer_cb_arg) { - ctrlr->aer_cb_fn = aer_cb_fn; - ctrlr->aer_cb_arg = aer_cb_arg; + struct spdk_nvme_ctrlr_process *active_proc; + + nvme_robust_mutex_lock(&ctrlr->ctrlr_lock); + + active_proc = spdk_nvme_ctrlr_get_current_process(ctrlr); + if (active_proc) { + active_proc->aer_cb_fn = aer_cb_fn; + active_proc->aer_cb_arg = aer_cb_arg; + } + + nvme_robust_mutex_unlock(&ctrlr->ctrlr_lock); } void diff --git a/lib/nvme/nvme_internal.h b/lib/nvme/nvme_internal.h index 3c5083fa1..821eb32bb 100644 --- a/lib/nvme/nvme_internal.h +++ b/lib/nvme/nvme_internal.h @@ -375,6 +375,9 @@ struct spdk_nvme_ctrlr_process { /** Allocated IO qpairs */ TAILQ_HEAD(, spdk_nvme_qpair) allocated_io_qpairs; + spdk_nvme_aer_cb aer_cb_fn; + void *aer_cb_arg; + /** * A function pointer to timeout callback function */ @@ -437,8 +440,6 @@ struct spdk_nvme_ctrlr { uint32_t num_aers; struct nvme_async_event_request aer[NVME_MAX_ASYNC_EVENTS]; - spdk_nvme_aer_cb aer_cb_fn; - void *aer_cb_arg; /** guards access to the controller itself, including admin queues */ pthread_mutex_t ctrlr_lock;