nvmf/vfio-user: optimize lookup_io_q() function

The function is used to check the IO SQ or CQ exists or not,
so return bool type is better and also rename it.

Change-Id: I1af2a25255b012dcf1e1952b828617ededf9b897
Signed-off-by: Changpeng Liu <changpeng.liu@intel.com>
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/9680
Community-CI: Broadcom CI <spdk-ci.pdl@broadcom.com>
Community-CI: Mellanox Build Bot
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: Ben Walker <benjamin.walker@intel.com>
Reviewed-by: Aleksey Marchuk <alexeymar@mellanox.com>
Reviewed-by: Jim Harris <james.r.harris@intel.com>
Reviewed-by: Andreas Economides <andreas.economides@nutanix.com>
This commit is contained in:
Changpeng Liu 2021-09-29 23:08:56 +08:00
parent aa9e0ac633
commit 318a3f0a43

View File

@ -899,34 +899,27 @@ post_completion(struct nvmf_vfio_user_ctrlr *ctrlr, struct nvme_q *cq,
return 0;
}
static struct nvme_q *
lookup_io_q(struct nvmf_vfio_user_ctrlr *ctrlr, const uint16_t qid, const bool is_cq)
static bool
io_q_exists(struct nvmf_vfio_user_ctrlr *vu_ctrlr, const uint16_t qid, const bool is_cq)
{
struct nvme_q *q;
assert(ctrlr != NULL);
assert(vu_ctrlr != NULL);
if (qid == 0 || qid >= NVMF_VFIO_USER_DEFAULT_MAX_QPAIRS_PER_CTRLR) {
return NULL;
return false;
}
if (ctrlr->qp[qid] == NULL) {
return NULL;
if (vu_ctrlr->qp[qid] == NULL) {
return false;
}
if (is_cq) {
/* CQ is always exist if the queue pair wasn't null */
q = &ctrlr->qp[qid]->cq;
return q;
} else {
if (ctrlr->qp[qid]->state == VFIO_USER_QPAIR_SQ_DELETED ||
ctrlr->qp[qid]->state == VFIO_USER_QPAIR_UNINITIALIZED) {
return NULL;
if (!is_cq) {
if (vu_ctrlr->qp[qid]->state == VFIO_USER_QPAIR_SQ_DELETED ||
vu_ctrlr->qp[qid]->state == VFIO_USER_QPAIR_UNINITIALIZED) {
return false;
}
q = &ctrlr->qp[qid]->sq;
}
return q;
return true;
}
static void
@ -1120,7 +1113,7 @@ handle_create_io_q(struct nvmf_vfio_user_ctrlr *ctrlr,
goto out;
}
if (lookup_io_q(ctrlr, qid, is_cq)) {
if (io_q_exists(ctrlr, qid, is_cq)) {
SPDK_ERRLOG("%s: %cQ%d already exists\n", ctrlr_id(ctrlr),
is_cq ? 'C' : 'S', qid);
sct = SPDK_NVME_SCT_COMMAND_SPECIFIC;
@ -1166,7 +1159,7 @@ handle_create_io_q(struct nvmf_vfio_user_ctrlr *ctrlr,
}
/* CQ must be created before SQ */
if (!lookup_io_q(ctrlr, cmd->cdw11_bits.create_io_sq.cqid, true)) {
if (!io_q_exists(ctrlr, cmd->cdw11_bits.create_io_sq.cqid, true)) {
SPDK_ERRLOG("%s: CQ%d does not exist\n", ctrlr_id(ctrlr),
cmd->cdw11_bits.create_io_sq.cqid);
sct = SPDK_NVME_SCT_COMMAND_SPECIFIC;
@ -1270,7 +1263,7 @@ handle_del_io_q(struct nvmf_vfio_user_ctrlr *ctrlr,
ctrlr_id(ctrlr), is_cq ? 'C' : 'S',
cmd->cdw10_bits.delete_io_q.qid);
if (lookup_io_q(ctrlr, cmd->cdw10_bits.delete_io_q.qid, is_cq) == NULL) {
if (!io_q_exists(ctrlr, cmd->cdw10_bits.delete_io_q.qid, is_cq)) {
SPDK_ERRLOG("%s: I/O %cQ%d does not exist\n", ctrlr_id(ctrlr),
is_cq ? 'C' : 'S', cmd->cdw10_bits.delete_io_q.qid);
sct = SPDK_NVME_SCT_COMMAND_SPECIFIC;