Commit f7866a56 authored by Changpeng Liu's avatar Changpeng Liu Committed by Tomasz Zawadzki
Browse files

nvmf: consolidate AER notification into one function



Change-Id: If43e92fad60eff3e3f12cac1a8b413f5c16232fb
Signed-off-by: default avatarChangpeng Liu <changpeng.liu@intel.com>
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/9633


Community-CI: Mellanox Build Bot
Community-CI: Broadcom CI <spdk-ci.pdl@broadcom.com>
Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: default avatarAleksey Marchuk <alexeymar@mellanox.com>
Reviewed-by: default avatarJim Harris <james.r.harris@intel.com>
parent 86ad145b
Loading
Loading
Loading
Loading
+23 −61
Original line number Diff line number Diff line
@@ -3172,6 +3172,21 @@ nvmf_ctrlr_process_fabrics_cmd(struct spdk_nvmf_request *req)
	}
}

static inline void
nvmf_ctrlr_queue_pending_async_event(struct spdk_nvmf_ctrlr *ctrlr,
				     union spdk_nvme_async_event_completion *event)
{
	struct spdk_nvmf_async_event_completion *nvmf_event;

	nvmf_event = calloc(1, sizeof(*nvmf_event));
	if (!nvmf_event) {
		SPDK_ERRLOG("Alloc nvmf event failed, ignore the event\n");
		return;
	}
	nvmf_event->event.raw = event->raw;
	STAILQ_INSERT_TAIL(&ctrlr->async_events, nvmf_event, link);
}

static inline int
nvmf_ctrlr_async_event_notification(struct spdk_nvmf_ctrlr *ctrlr,
				    union spdk_nvme_async_event_completion *event)
@@ -3179,7 +3194,14 @@ nvmf_ctrlr_async_event_notification(struct spdk_nvmf_ctrlr *ctrlr,
	struct spdk_nvmf_request *req;
	struct spdk_nvme_cpl *rsp;

	assert(ctrlr->nr_aer_reqs > 0);
	/* If there is no outstanding AER request, queue the event.  Then
	 * if an AER is later submitted, this event can be sent as a
	 * response.
	 */
	if (ctrlr->nr_aer_reqs == 0) {
		nvmf_ctrlr_queue_pending_async_event(ctrlr, event);
		return 0;
	}

	req = ctrlr->aer_req[--ctrlr->nr_aer_reqs];
	rsp = &req->rsp->nvme_cpl;
@@ -3192,21 +3214,6 @@ nvmf_ctrlr_async_event_notification(struct spdk_nvmf_ctrlr *ctrlr,
	return 0;
}

static inline void
nvmf_ctrlr_queue_pending_async_event(struct spdk_nvmf_ctrlr *ctrlr,
				     union spdk_nvme_async_event_completion *event)
{
	struct spdk_nvmf_async_event_completion *nvmf_event;

	nvmf_event = calloc(1, sizeof(*nvmf_event));
	if (!nvmf_event) {
		SPDK_ERRLOG("Alloc nvmf event failed, ignore the event\n");
		return;
	}
	nvmf_event->event.raw = event->raw;
	STAILQ_INSERT_TAIL(&ctrlr->async_events, nvmf_event, link);
}

int
nvmf_ctrlr_async_event_ns_notice(struct spdk_nvmf_ctrlr *ctrlr)
{
@@ -3225,15 +3232,6 @@ nvmf_ctrlr_async_event_ns_notice(struct spdk_nvmf_ctrlr *ctrlr)
	event.bits.async_event_info = SPDK_NVME_ASYNC_EVENT_NS_ATTR_CHANGED;
	event.bits.log_page_identifier = SPDK_NVME_LOG_CHANGED_NS_LIST;

	/* If there is no outstanding AER request, queue the event.  Then
	 * if an AER is later submitted, this event can be sent as a
	 * response.
	 */
	if (ctrlr->nr_aer_reqs == 0) {
		nvmf_ctrlr_queue_pending_async_event(ctrlr, &event);
		return 0;
	}

	return nvmf_ctrlr_async_event_notification(ctrlr, &event);
}

@@ -3255,15 +3253,6 @@ nvmf_ctrlr_async_event_ana_change_notice(struct spdk_nvmf_ctrlr *ctrlr)
	event.bits.async_event_info = SPDK_NVME_ASYNC_EVENT_ANA_CHANGE;
	event.bits.log_page_identifier = SPDK_NVME_LOG_ASYMMETRIC_NAMESPACE_ACCESS;

	/* If there is no outstanding AER request, queue the event.  Then
	 * if an AER is later submitted, this event can be sent as a
	 * response.
	 */
	if (ctrlr->nr_aer_reqs == 0) {
		nvmf_ctrlr_queue_pending_async_event(ctrlr, &event);
		return 0;
	}

	return nvmf_ctrlr_async_event_notification(ctrlr, &event);
}

@@ -3284,15 +3273,6 @@ nvmf_ctrlr_async_event_reservation_notification(struct spdk_nvmf_ctrlr *ctrlr)
	event.bits.async_event_info = SPDK_NVME_ASYNC_EVENT_RESERVATION_LOG_AVAIL;
	event.bits.log_page_identifier = SPDK_NVME_LOG_RESERVATION_NOTIFICATION;

	/* If there is no outstanding AER request, queue the event.  Then
	 * if an AER is later submitted, this event can be sent as a
	 * response.
	 */
	if (ctrlr->nr_aer_reqs == 0) {
		nvmf_ctrlr_queue_pending_async_event(ctrlr, &event);
		return;
	}

	nvmf_ctrlr_async_event_notification(ctrlr, &event);
}

@@ -3317,15 +3297,6 @@ nvmf_ctrlr_async_event_discovery_log_change_notice(struct spdk_nvmf_ctrlr *ctrlr
	event.bits.async_event_info = SPDK_NVME_ASYNC_EVENT_DISCOVERY_LOG_CHANGE;
	event.bits.log_page_identifier = SPDK_NVME_LOG_DISCOVERY;

	/* If there is no outstanding AER request, queue the event.  Then
	 * if an AER is later submitted, this event can be sent as a
	 * response.
	 */
	if (ctrlr->nr_aer_reqs == 0) {
		nvmf_ctrlr_queue_pending_async_event(ctrlr, &event);
		return 0;
	}

	return nvmf_ctrlr_async_event_notification(ctrlr, &event);
}

@@ -3342,15 +3313,6 @@ nvmf_ctrlr_async_event_error_event(struct spdk_nvmf_ctrlr *ctrlr,
		return 0;
	}

	/* If there is no outstanding AER request, queue the event.  Then
	 * if an AER is later submitted, this event can be sent as a
	 * response.
	 */
	if (ctrlr->nr_aer_reqs == 0) {
		nvmf_ctrlr_queue_pending_async_event(ctrlr, &event);
		return 0;
	}

	return nvmf_ctrlr_async_event_notification(ctrlr, &event);
}