From bb555ef1b0fb164f1faadb4991cf6123b1977e32 Mon Sep 17 00:00:00 2001 From: Ben Walker Date: Mon, 30 Aug 2021 13:41:16 -0700 Subject: [PATCH] bdev/nvme: Reverse order of checks in bdev_nvme_attach_controllers Do simple validity checks first, then check for duplicate controllers. Signed-off-by: Ben Walker Change-Id: Ic21d64574b37a3d9148e5cd6d5a7599449ea8fe1 Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/9341 Community-CI: Broadcom CI Community-CI: Mellanox Build Bot Tested-by: SPDK CI Jenkins Reviewed-by: Changpeng Liu Reviewed-by: Paul Luse Reviewed-by: Jim Harris Reviewed-by: Jacek Kalwas --- module/bdev/nvme/bdev_nvme_rpc.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/module/bdev/nvme/bdev_nvme_rpc.c b/module/bdev/nvme/bdev_nvme_rpc.c index e2f00fff3..507156a5e 100644 --- a/module/bdev/nvme/bdev_nvme_rpc.c +++ b/module/bdev/nvme/bdev_nvme_rpc.c @@ -308,8 +308,6 @@ rpc_bdev_nvme_attach_controller(struct spdk_jsonrpc_request *request, rc = spdk_nvme_transport_id_parse_trtype(&trid.trtype, ctx->req.trtype); assert(rc == 0); - ctrlr = nvme_ctrlr_get_by_name(ctx->req.name); - /* Parse traddr */ maxlen = sizeof(trid.traddr); len = strnlen(ctx->req.traddr, maxlen); @@ -360,11 +358,6 @@ rpc_bdev_nvme_attach_controller(struct spdk_jsonrpc_request *request, memcpy(trid.subnqn, ctx->req.subnqn, len + 1); } - if (ctrlr && (ctx->req.hostaddr || ctx->req.hostnqn || ctx->req.hostsvcid || ctx->req.prchk_guard || - ctx->req.prchk_reftag)) { - goto conflicting_arguments; - } - if (ctx->req.hostnqn) { snprintf(ctx->req.opts.hostnqn, sizeof(ctx->req.opts.hostnqn), "%s", ctx->req.hostnqn); @@ -392,6 +385,13 @@ rpc_bdev_nvme_attach_controller(struct spdk_jsonrpc_request *request, memcpy(hostid.hostsvcid, ctx->req.hostsvcid, len + 1); } + ctrlr = nvme_ctrlr_get_by_name(ctx->req.name); + + if (ctrlr && (ctx->req.hostaddr || ctx->req.hostnqn || ctx->req.hostsvcid || ctx->req.prchk_guard || + ctx->req.prchk_reftag)) { + goto conflicting_arguments; + } + if (ctx->req.prchk_reftag) { prchk_flags |= SPDK_NVME_IO_FLAGS_PRCHK_REFTAG; }