Commit 82b2c192 authored by Thanos Makatos's avatar Thanos Makatos Committed by Tomasz Zawadzki
Browse files

nvmf/vfio-user: refactor duplicate code



Change-Id: If501002e9ed110f77a4ece9f026ecfc4e53dee27
Signed-off-by: default avatarThanos Makatos <thanos.makatos@nutanix.com>
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/15388


Reviewed-by: default avatarJohn Levon <levon@movementarian.org>
Reviewed-by: default avatarJim Harris <james.r.harris@intel.com>
Reviewed-by: default avatarChangpeng Liu <changpeng.liu@intel.com>
Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
parent a7885283
Loading
Loading
Loading
Loading
+17 −9
Original line number Diff line number Diff line
@@ -1731,6 +1731,16 @@ free_sq_reqs(struct nvmf_vfio_user_sq *sq)
	}
}

static void
delete_cq_done(struct nvmf_vfio_user_ctrlr *ctrlr, struct nvmf_vfio_user_cq *cq)
{
	assert(cq->cq_ref == 0);
	unmap_q(ctrlr, &cq->mapping);
	cq->size = 0;
	cq->cq_state = VFIO_USER_CQ_DELETED;
	cq->group = NULL;
}

/* Deletes a SQ, if this SQ is the last user of the associated CQ
 * and the controller is being shut down/reset or vfio-user client disconnects,
 * then the CQ is also deleted.
@@ -1766,10 +1776,7 @@ delete_sq_done(struct nvmf_vfio_user_ctrlr *vu_ctrlr, struct nvmf_vfio_user_sq *

		assert(cq->cq_ref > 0);
		if (--cq->cq_ref == 0) {
			unmap_q(vu_ctrlr, &cq->mapping);
			cq->size = 0;
			cq->cq_state = VFIO_USER_CQ_DELETED;
			cq->group = NULL;
			delete_cq_done(vu_ctrlr, cq);
		}
	}
}
@@ -2212,12 +2219,13 @@ handle_del_io_q(struct nvmf_vfio_user_ctrlr *ctrlr,
			sc = SPDK_NVME_SC_INVALID_QUEUE_DELETION;
			goto out;
		}

		unmap_q(ctrlr, &cq->mapping);
		cq->size = 0;
		cq->cq_state = VFIO_USER_CQ_DELETED;
		cq->group = NULL;
		delete_cq_done(ctrlr, cq);
	} else {
		/*
		 * Deletion of the CQ is only deferred to delete_sq_done() on
		 * VM reboot or CC.EN change, so we have to delete it in all
		 * other cases.
		 */
		ctx = calloc(1, sizeof(*ctx));
		if (!ctx) {
			sct = SPDK_NVME_SCT_GENERIC;