bdev/nvme: Simplify the code flow to handle multipath in bdev_nvme_attach_controller

This clean up makes the following patches a little easier.

Signed-off-by: Shuhei Matsumoto <smatsumoto@nvidia.com>
Change-Id: I0415de9b99567b4de1ad7b35298ea51a664d4a32
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/12049
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: Aleksey Marchuk <alexeymar@mellanox.com>
Reviewed-by: Jim Harris <james.r.harris@intel.com>
This commit is contained in:
Shuhei Matsumoto 2022-03-27 17:24:54 +09:00 committed by Tomasz Zawadzki
parent 36e81f15ff
commit edb03a183f

View File

@ -444,9 +444,6 @@ rpc_bdev_nvme_attach_controller(struct spdk_jsonrpc_request *request,
} }
} }
drv_opts = spdk_nvme_ctrlr_get_opts(ctrlr->ctrlr);
ctrlr_trid = spdk_nvme_ctrlr_get_transport_id(ctrlr->ctrlr);
/* This controller already exists. Check what the user wants to do. */ /* This controller already exists. Check what the user wants to do. */
if (strcasecmp(ctx->req.multipath, "disable") == 0) { if (strcasecmp(ctx->req.multipath, "disable") == 0) {
/* The user does not want to do any form of multipathing. */ /* The user does not want to do any form of multipathing. */
@ -454,21 +451,9 @@ rpc_bdev_nvme_attach_controller(struct spdk_jsonrpc_request *request,
"A controller named %s already exists and multipath is disabled\n", "A controller named %s already exists and multipath is disabled\n",
ctx->req.name); ctx->req.name);
goto cleanup; goto cleanup;
} else if (strcasecmp(ctx->req.multipath, "failover") == 0 ||
strcasecmp(ctx->req.multipath, "multipath") == 0) {
/* The user wants to add this as a failover path or add this to create multipath. */
if (strncmp(trid.traddr, ctrlr_trid->traddr, sizeof(trid.traddr)) == 0 && } else if (strcasecmp(ctx->req.multipath, "failover") != 0 &&
strncmp(trid.trsvcid, ctrlr_trid->trsvcid, sizeof(trid.trsvcid)) == 0 && strcasecmp(ctx->req.multipath, "multipath") != 0) {
strncmp(ctx->req.drv_opts.src_addr, drv_opts->src_addr, sizeof(drv_opts->src_addr)) == 0 &&
strncmp(ctx->req.drv_opts.src_svcid, drv_opts->src_svcid, sizeof(drv_opts->src_svcid)) == 0) {
/* Exactly same network path can't be added a second time */
spdk_jsonrpc_send_error_response_fmt(request, -EALREADY,
"A controller named %s already exists with the specified network path\n",
ctx->req.name);
goto cleanup;
}
} else {
/* Invalid multipath option */ /* Invalid multipath option */
spdk_jsonrpc_send_error_response_fmt(request, -EINVAL, spdk_jsonrpc_send_error_response_fmt(request, -EINVAL,
"Invalid multipath parameter: %s\n", "Invalid multipath parameter: %s\n",
@ -476,6 +461,21 @@ rpc_bdev_nvme_attach_controller(struct spdk_jsonrpc_request *request,
goto cleanup; goto cleanup;
} }
/* The user wants to add this as a failover path or add this to create multipath. */
drv_opts = spdk_nvme_ctrlr_get_opts(ctrlr->ctrlr);
ctrlr_trid = spdk_nvme_ctrlr_get_transport_id(ctrlr->ctrlr);
if (strncmp(trid.traddr, ctrlr_trid->traddr, sizeof(trid.traddr)) == 0 &&
strncmp(trid.trsvcid, ctrlr_trid->trsvcid, sizeof(trid.trsvcid)) == 0 &&
strncmp(ctx->req.drv_opts.src_addr, drv_opts->src_addr, sizeof(drv_opts->src_addr)) == 0 &&
strncmp(ctx->req.drv_opts.src_svcid, drv_opts->src_svcid, sizeof(drv_opts->src_svcid)) == 0) {
/* Exactly same network path can't be added a second time */
spdk_jsonrpc_send_error_response_fmt(request, -EALREADY,
"A controller named %s already exists with the specified network path\n",
ctx->req.name);
goto cleanup;
}
if (strncmp(trid.subnqn, if (strncmp(trid.subnqn,
ctrlr_trid->subnqn, ctrlr_trid->subnqn,
SPDK_NVMF_NQN_MAX_LEN) != 0) { SPDK_NVMF_NQN_MAX_LEN) != 0) {
@ -486,8 +486,6 @@ rpc_bdev_nvme_attach_controller(struct spdk_jsonrpc_request *request,
goto cleanup; goto cleanup;
} }
if (strncmp(ctx->req.drv_opts.hostnqn, drv_opts->hostnqn, SPDK_NVMF_NQN_MAX_LEN) != 0) { if (strncmp(ctx->req.drv_opts.hostnqn, drv_opts->hostnqn, SPDK_NVMF_NQN_MAX_LEN) != 0) {
/* Different HOSTNQN is not allowed when specifying the same controller name. */ /* Different HOSTNQN is not allowed when specifying the same controller name. */
spdk_jsonrpc_send_error_response_fmt(request, -EINVAL, spdk_jsonrpc_send_error_response_fmt(request, -EINVAL,