nvmf/vfio-user: refactor duplicate code
Change-Id: If501002e9ed110f77a4ece9f026ecfc4e53dee27 Signed-off-by: Thanos Makatos <thanos.makatos@nutanix.com> Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/15388 Reviewed-by: John Levon <levon@movementarian.org> Reviewed-by: Jim Harris <james.r.harris@intel.com> Reviewed-by: Changpeng Liu <changpeng.liu@intel.com> Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
This commit is contained in:
parent
a7885283b3
commit
82b2c1923f
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user