nvme/nvme_rdma: Reduced the code lines.
Here destruct contrllers are in one function, and we can remove the duplicated codes using goto. It can save several lines of codes. Signed-off-by: yidong0635 <dongx.yi@intel.com> Change-Id: Ibf3cb9fe2ea4bfc65d42603a7b13aaf575854580 Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/1638 Tested-by: SPDK CI Jenkins <sys_sgci@intel.com> Reviewed-by: Aleksey Marchuk <alexeymar@mellanox.com> Reviewed-by: Ben Walker <benjamin.walker@intel.com>
This commit is contained in:
parent
96250f5b3d
commit
20564d423b
@ -1802,8 +1802,7 @@ static struct spdk_nvme_ctrlr *nvme_rdma_ctrlr_construct(const struct spdk_nvme_
|
|||||||
rctrlr->cm_events = calloc(NVME_RDMA_NUM_CM_EVENTS, sizeof(*rctrlr->cm_events));
|
rctrlr->cm_events = calloc(NVME_RDMA_NUM_CM_EVENTS, sizeof(*rctrlr->cm_events));
|
||||||
if (rctrlr->cm_events == NULL) {
|
if (rctrlr->cm_events == NULL) {
|
||||||
SPDK_ERRLOG("unable to allocat buffers to hold CM events.\n");
|
SPDK_ERRLOG("unable to allocat buffers to hold CM events.\n");
|
||||||
nvme_rdma_ctrlr_destruct(&rctrlr->ctrlr);
|
goto destruct_ctrlr;
|
||||||
return NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; i < NVME_RDMA_NUM_CM_EVENTS; i++) {
|
for (i = 0; i < NVME_RDMA_NUM_CM_EVENTS; i++) {
|
||||||
@ -1813,15 +1812,13 @@ static struct spdk_nvme_ctrlr *nvme_rdma_ctrlr_construct(const struct spdk_nvme_
|
|||||||
rctrlr->cm_channel = rdma_create_event_channel();
|
rctrlr->cm_channel = rdma_create_event_channel();
|
||||||
if (rctrlr->cm_channel == NULL) {
|
if (rctrlr->cm_channel == NULL) {
|
||||||
SPDK_ERRLOG("rdma_create_event_channel() failed\n");
|
SPDK_ERRLOG("rdma_create_event_channel() failed\n");
|
||||||
nvme_rdma_ctrlr_destruct(&rctrlr->ctrlr);
|
goto destruct_ctrlr;
|
||||||
return NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
flag = fcntl(rctrlr->cm_channel->fd, F_GETFL);
|
flag = fcntl(rctrlr->cm_channel->fd, F_GETFL);
|
||||||
if (fcntl(rctrlr->cm_channel->fd, F_SETFL, flag | O_NONBLOCK) < 0) {
|
if (fcntl(rctrlr->cm_channel->fd, F_SETFL, flag | O_NONBLOCK) < 0) {
|
||||||
SPDK_ERRLOG("Cannot set event channel to non blocking\n");
|
SPDK_ERRLOG("Cannot set event channel to non blocking\n");
|
||||||
nvme_rdma_ctrlr_destruct(&rctrlr->ctrlr);
|
goto destruct_ctrlr;
|
||||||
return NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
rctrlr->ctrlr.adminq = nvme_rdma_ctrlr_create_qpair(&rctrlr->ctrlr, 0,
|
rctrlr->ctrlr.adminq = nvme_rdma_ctrlr_create_qpair(&rctrlr->ctrlr, 0,
|
||||||
@ -1829,39 +1826,38 @@ static struct spdk_nvme_ctrlr *nvme_rdma_ctrlr_construct(const struct spdk_nvme_
|
|||||||
rctrlr->ctrlr.opts.admin_queue_size, false);
|
rctrlr->ctrlr.opts.admin_queue_size, false);
|
||||||
if (!rctrlr->ctrlr.adminq) {
|
if (!rctrlr->ctrlr.adminq) {
|
||||||
SPDK_ERRLOG("failed to create admin qpair\n");
|
SPDK_ERRLOG("failed to create admin qpair\n");
|
||||||
nvme_rdma_ctrlr_destruct(&rctrlr->ctrlr);
|
goto destruct_ctrlr;
|
||||||
return NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
rc = nvme_transport_ctrlr_connect_qpair(&rctrlr->ctrlr, rctrlr->ctrlr.adminq);
|
rc = nvme_transport_ctrlr_connect_qpair(&rctrlr->ctrlr, rctrlr->ctrlr.adminq);
|
||||||
if (rc < 0) {
|
if (rc < 0) {
|
||||||
SPDK_ERRLOG("failed to connect admin qpair\n");
|
SPDK_ERRLOG("failed to connect admin qpair\n");
|
||||||
nvme_rdma_ctrlr_destruct(&rctrlr->ctrlr);
|
goto destruct_ctrlr;
|
||||||
return NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (nvme_ctrlr_get_cap(&rctrlr->ctrlr, &cap)) {
|
if (nvme_ctrlr_get_cap(&rctrlr->ctrlr, &cap)) {
|
||||||
SPDK_ERRLOG("get_cap() failed\n");
|
SPDK_ERRLOG("get_cap() failed\n");
|
||||||
nvme_ctrlr_destruct(&rctrlr->ctrlr);
|
goto destruct_ctrlr;
|
||||||
return NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (nvme_ctrlr_get_vs(&rctrlr->ctrlr, &vs)) {
|
if (nvme_ctrlr_get_vs(&rctrlr->ctrlr, &vs)) {
|
||||||
SPDK_ERRLOG("get_vs() failed\n");
|
SPDK_ERRLOG("get_vs() failed\n");
|
||||||
nvme_ctrlr_destruct(&rctrlr->ctrlr);
|
goto destruct_ctrlr;
|
||||||
return NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (nvme_ctrlr_add_process(&rctrlr->ctrlr, 0) != 0) {
|
if (nvme_ctrlr_add_process(&rctrlr->ctrlr, 0) != 0) {
|
||||||
SPDK_ERRLOG("nvme_ctrlr_add_process() failed\n");
|
SPDK_ERRLOG("nvme_ctrlr_add_process() failed\n");
|
||||||
nvme_ctrlr_destruct(&rctrlr->ctrlr);
|
goto destruct_ctrlr;
|
||||||
return NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
nvme_ctrlr_init_cap(&rctrlr->ctrlr, &cap, &vs);
|
nvme_ctrlr_init_cap(&rctrlr->ctrlr, &cap, &vs);
|
||||||
|
|
||||||
SPDK_DEBUGLOG(SPDK_LOG_NVME, "successfully initialized the nvmf ctrlr\n");
|
SPDK_DEBUGLOG(SPDK_LOG_NVME, "successfully initialized the nvmf ctrlr\n");
|
||||||
return &rctrlr->ctrlr;
|
return &rctrlr->ctrlr;
|
||||||
|
|
||||||
|
destruct_ctrlr:
|
||||||
|
nvme_ctrlr_destruct(&rctrlr->ctrlr);
|
||||||
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
|
Loading…
Reference in New Issue
Block a user