From ee82713678e067dcf9738b6bcf77c9203cb7a0e3 Mon Sep 17 00:00:00 2001 From: Daniel Verkamp Date: Wed, 14 Dec 2016 18:29:22 -0700 Subject: [PATCH] nvme/rdma: clean up nvme_rdma_req_init() Make the caller pre-allocate an rdma_req and change req_init() so it only does initialization, not allocation. This is necessary to distinguish between rdma_req allocation failure and other types of failures, which will become important in future patches when requests will be queued if rdma_req allocation fails. Change-Id: Ie6edebc1b5f05001b42fc959a29ce0ea6875e41e Signed-off-by: Daniel Verkamp --- lib/nvme/nvme_rdma.c | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/lib/nvme/nvme_rdma.c b/lib/nvme/nvme_rdma.c index b939706aa5..4c8cd3ceae 100644 --- a/lib/nvme/nvme_rdma.c +++ b/lib/nvme/nvme_rdma.c @@ -745,20 +745,14 @@ nvme_rdma_qpair_connect(struct nvme_rdma_qpair *rqpair) return 0; } -static struct spdk_nvme_rdma_req * -nvme_rdma_req_init(struct nvme_rdma_qpair *rqpair, struct nvme_request *req) +static int +nvme_rdma_req_init(struct nvme_rdma_qpair *rqpair, struct nvme_request *req, + struct spdk_nvme_rdma_req *rdma_req) { - struct spdk_nvme_rdma_req *rdma_req; struct spdk_nvme_sgl_descriptor *nvme_sgl; - if (!rqpair || !req) { - return NULL; - } - - rdma_req = nvme_rdma_req_get(rqpair); - if (!rdma_req) { - return NULL; - } + assert(rqpair != NULL); + assert(req != NULL); rdma_req->req = req; req->cmd.cid = rdma_req->id; @@ -769,9 +763,8 @@ nvme_rdma_req_init(struct nvme_rdma_qpair *rqpair, struct nvme_request *req) nvme_sgl->address = (uint64_t)req->payload.u.contig + req->payload_offset; nvme_sgl->keyed.length = req->payload_size; } else { - nvme_rdma_req_put(rqpair, rdma_req); /* Need to handle other case later */ - return NULL; + return -1; } rdma_req->req->cmd.psdt = SPDK_NVME_PSDT_SGL_MPTR_SGL; @@ -786,7 +779,7 @@ nvme_rdma_req_init(struct nvme_rdma_qpair *rqpair, struct nvme_request *req) } memcpy(&rqpair->cmds[rdma_req->id], &req->cmd, sizeof(req->cmd)); - return rdma_req; + return 0; } static int @@ -1331,9 +1324,16 @@ nvme_rdma_qpair_submit_request(struct spdk_nvme_qpair *qpair, int rc; rqpair = nvme_rdma_qpair(qpair); - rdma_req = nvme_rdma_req_init(rqpair, req); + + rdma_req = nvme_rdma_req_get(rqpair); if (!rdma_req) { - SPDK_ERRLOG("spdk_nvme_rdma_req memory allocation failed duing read\n"); + SPDK_ERRLOG("nvme_rdma_req_get() failed\n"); + return -1; + } + + if (nvme_rdma_req_init(rqpair, req, rdma_req)) { + SPDK_ERRLOG("nvme_rdma_req_init() failed\n"); + nvme_rdma_req_put(rqpair, rdma_req); return -1; }