From 9a3939bfb7d5089938c05b0ec8fbcdab6e579b2f Mon Sep 17 00:00:00 2001 From: Shuhei Matsumoto Date: Thu, 26 Aug 2021 18:20:54 +0900 Subject: [PATCH] bdev/nvme: Include hostnqn into ctrlr_opts when calling bdev_nvme_create() bdev_nvme_create() is called only by a single caller and hostnqn is just copied to ctrlr_opts even if it is passed separately. Hence include hostnqn into ctrlr_opts rather than passing it as a parameter for bdev_nvme_create(). Signed-off-by: Shuhei Matsumoto Change-Id: I75b640bcecefa94950b0c19936fab0571c428125 Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/9332 Community-CI: Mellanox Build Bot Community-CI: Broadcom CI Tested-by: SPDK CI Jenkins Reviewed-by: Konrad Sztyber Reviewed-by: Ben Walker Reviewed-by: Jim Harris --- module/bdev/nvme/bdev_nvme.c | 5 ---- module/bdev/nvme/bdev_nvme.h | 1 - module/bdev/nvme/bdev_nvme_rpc.c | 7 ++++- .../lib/bdev/nvme/bdev_nvme.c/bdev_nvme_ut.c | 30 +++++++++---------- 4 files changed, 21 insertions(+), 22 deletions(-) diff --git a/module/bdev/nvme/bdev_nvme.c b/module/bdev/nvme/bdev_nvme.c index dc3f13a03..667dc873f 100644 --- a/module/bdev/nvme/bdev_nvme.c +++ b/module/bdev/nvme/bdev_nvme.c @@ -2669,7 +2669,6 @@ bdev_nvme_create(struct spdk_nvme_transport_id *trid, const char *base_name, const char **names, uint32_t count, - const char *hostnqn, uint32_t prchk_flags, spdk_bdev_create_nvme_fn cb_fn, void *cb_ctx, @@ -2719,10 +2718,6 @@ bdev_nvme_create(struct spdk_nvme_transport_id *trid, ctx->opts.keep_alive_timeout_ms = g_opts.keep_alive_timeout_ms; ctx->opts.disable_read_ana_log_page = true; - if (hostnqn) { - snprintf(ctx->opts.hostnqn, sizeof(ctx->opts.hostnqn), "%s", hostnqn); - } - if (hostid->hostaddr[0] != '\0') { snprintf(ctx->opts.src_addr, sizeof(ctx->opts.src_addr), "%s", hostid->hostaddr); } diff --git a/module/bdev/nvme/bdev_nvme.h b/module/bdev/nvme/bdev_nvme.h index dc76684b8..8f0fdad4e 100644 --- a/module/bdev/nvme/bdev_nvme.h +++ b/module/bdev/nvme/bdev_nvme.h @@ -75,7 +75,6 @@ int bdev_nvme_create(struct spdk_nvme_transport_id *trid, const char *base_name, const char **names, uint32_t count, - const char *hostnqn, uint32_t prchk_flags, spdk_bdev_create_nvme_fn cb_fn, void *cb_ctx, diff --git a/module/bdev/nvme/bdev_nvme_rpc.c b/module/bdev/nvme/bdev_nvme_rpc.c index f58e7c209..f033cda1e 100644 --- a/module/bdev/nvme/bdev_nvme_rpc.c +++ b/module/bdev/nvme/bdev_nvme_rpc.c @@ -365,6 +365,11 @@ rpc_bdev_nvme_attach_controller(struct spdk_jsonrpc_request *request, goto conflicting_arguments; } + if (ctx->req.hostnqn) { + snprintf(ctx->req.opts.hostnqn, sizeof(ctx->req.opts.hostnqn), "%s", + ctx->req.hostnqn); + } + if (ctx->req.hostaddr) { maxlen = sizeof(hostid.hostaddr); len = strnlen(ctx->req.hostaddr, maxlen); @@ -397,7 +402,7 @@ rpc_bdev_nvme_attach_controller(struct spdk_jsonrpc_request *request, ctx->request = request; ctx->count = NVME_MAX_BDEVS_PER_RPC; - rc = bdev_nvme_create(&trid, &hostid, ctx->req.name, ctx->names, ctx->count, ctx->req.hostnqn, + rc = bdev_nvme_create(&trid, &hostid, ctx->req.name, ctx->names, ctx->count, prchk_flags, rpc_bdev_nvme_attach_controller_done, ctx, &ctx->req.opts); if (rc) { spdk_jsonrpc_send_error_response(request, rc, spdk_strerror(-rc)); diff --git a/test/unit/lib/bdev/nvme/bdev_nvme.c/bdev_nvme_ut.c b/test/unit/lib/bdev/nvme/bdev_nvme.c/bdev_nvme_ut.c index 493108e7c..c04f95c68 100644 --- a/test/unit/lib/bdev/nvme/bdev_nvme.c/bdev_nvme_ut.c +++ b/test/unit/lib/bdev/nvme/bdev_nvme.c/bdev_nvme_ut.c @@ -1519,7 +1519,7 @@ test_pending_reset(void) g_ut_attach_ctrlr_status = 0; g_ut_attach_bdev_count = 1; - rc = bdev_nvme_create(&trid, &hostid, "nvme0", attached_names, STRING_SIZE, NULL, 0, + rc = bdev_nvme_create(&trid, &hostid, "nvme0", attached_names, STRING_SIZE, 0, attach_ctrlr_done, NULL, NULL); CU_ASSERT(rc == 0); @@ -1645,7 +1645,7 @@ test_attach_ctrlr(void) g_ut_attach_ctrlr_status = -EIO; g_ut_attach_bdev_count = 0; - rc = bdev_nvme_create(&trid, &hostid, "nvme0", attached_names, STRING_SIZE, NULL, 0, + rc = bdev_nvme_create(&trid, &hostid, "nvme0", attached_names, STRING_SIZE, 0, attach_ctrlr_done, NULL, NULL); CU_ASSERT(rc == 0); @@ -1660,7 +1660,7 @@ test_attach_ctrlr(void) g_ut_attach_ctrlr_status = 0; - rc = bdev_nvme_create(&trid, &hostid, "nvme0", attached_names, STRING_SIZE, NULL, 0, + rc = bdev_nvme_create(&trid, &hostid, "nvme0", attached_names, STRING_SIZE, 0, attach_ctrlr_done, NULL, NULL); CU_ASSERT(rc == 0); @@ -1687,7 +1687,7 @@ test_attach_ctrlr(void) g_ut_attach_bdev_count = 1; - rc = bdev_nvme_create(&trid, &hostid, "nvme0", attached_names, STRING_SIZE, NULL, 0, + rc = bdev_nvme_create(&trid, &hostid, "nvme0", attached_names, STRING_SIZE, 0, attach_ctrlr_done, NULL, NULL); CU_ASSERT(rc == 0); @@ -1722,7 +1722,7 @@ test_attach_ctrlr(void) g_ut_register_bdev_status = -EINVAL; g_ut_attach_bdev_count = 0; - rc = bdev_nvme_create(&trid, &hostid, "nvme0", attached_names, STRING_SIZE, NULL, 0, + rc = bdev_nvme_create(&trid, &hostid, "nvme0", attached_names, STRING_SIZE, 0, attach_ctrlr_done, NULL, NULL); CU_ASSERT(rc == 0); @@ -1833,7 +1833,7 @@ test_aer_cb(void) g_ut_attach_ctrlr_status = 0; g_ut_attach_bdev_count = 3; - rc = bdev_nvme_create(&trid, &hostid, "nvme0", attached_names, STRING_SIZE, NULL, 0, + rc = bdev_nvme_create(&trid, &hostid, "nvme0", attached_names, STRING_SIZE, 0, attach_ctrlr_done, NULL, NULL); CU_ASSERT(rc == 0); @@ -2030,7 +2030,7 @@ test_submit_nvme_cmd(void) g_ut_attach_ctrlr_status = 0; g_ut_attach_bdev_count = 1; - rc = bdev_nvme_create(&trid, &hostid, "nvme0", attached_names, STRING_SIZE, NULL, 0, + rc = bdev_nvme_create(&trid, &hostid, "nvme0", attached_names, STRING_SIZE, 0, attach_ctrlr_done, NULL, NULL); CU_ASSERT(rc == 0); @@ -2121,7 +2121,7 @@ test_add_remove_trid(void) ctrlr1 = ut_attach_ctrlr(&trid1, 0, false); SPDK_CU_ASSERT_FATAL(ctrlr1 != NULL); - rc = bdev_nvme_create(&trid1, &hostid, "nvme0", attached_names, STRING_SIZE, NULL, 0, + rc = bdev_nvme_create(&trid1, &hostid, "nvme0", attached_names, STRING_SIZE, 0, attach_ctrlr_done, NULL, NULL); CU_ASSERT(rc == 0); @@ -2136,7 +2136,7 @@ test_add_remove_trid(void) ctrlr2 = ut_attach_ctrlr(&trid2, 0, false); SPDK_CU_ASSERT_FATAL(ctrlr2 != NULL); - rc = bdev_nvme_create(&trid2, &hostid, "nvme0", attached_names, STRING_SIZE, NULL, 0, + rc = bdev_nvme_create(&trid2, &hostid, "nvme0", attached_names, STRING_SIZE, 0, attach_ctrlr_done, NULL, NULL); CU_ASSERT(rc == 0); @@ -2166,7 +2166,7 @@ test_add_remove_trid(void) ctrlr3 = ut_attach_ctrlr(&trid3, 0, false); SPDK_CU_ASSERT_FATAL(ctrlr3 != NULL); - rc = bdev_nvme_create(&trid3, &hostid, "nvme0", attached_names, STRING_SIZE, NULL, 0, + rc = bdev_nvme_create(&trid3, &hostid, "nvme0", attached_names, STRING_SIZE, 0, attach_ctrlr_done, NULL, NULL); CU_ASSERT(rc == 0); @@ -2211,7 +2211,7 @@ test_add_remove_trid(void) ctrlr1 = ut_attach_ctrlr(&trid1, 0, false); SPDK_CU_ASSERT_FATAL(ctrlr1 != NULL); - rc = bdev_nvme_create(&trid1, &hostid, "nvme0", attached_names, STRING_SIZE, NULL, 0, + rc = bdev_nvme_create(&trid1, &hostid, "nvme0", attached_names, STRING_SIZE, 0, attach_ctrlr_done, NULL, NULL); CU_ASSERT(rc == 0); @@ -2226,7 +2226,7 @@ test_add_remove_trid(void) ctrlr2 = ut_attach_ctrlr(&trid2, 0, false); SPDK_CU_ASSERT_FATAL(ctrlr2 != NULL); - rc = bdev_nvme_create(&trid2, &hostid, "nvme0", attached_names, STRING_SIZE, NULL, 0, + rc = bdev_nvme_create(&trid2, &hostid, "nvme0", attached_names, STRING_SIZE, 0, attach_ctrlr_done, NULL, NULL); CU_ASSERT(rc == 0); @@ -2282,7 +2282,7 @@ test_abort(void) set_thread(1); - rc = bdev_nvme_create(&trid, &hostid, "nvme0", attached_names, STRING_SIZE, NULL, 0, + rc = bdev_nvme_create(&trid, &hostid, "nvme0", attached_names, STRING_SIZE, 0, attach_ctrlr_done, NULL, NULL); CU_ASSERT(rc == 0); @@ -2495,7 +2495,7 @@ test_bdev_unregister(void) g_ut_attach_ctrlr_status = 0; g_ut_attach_bdev_count = 2; - rc = bdev_nvme_create(&trid, &hostid, "nvme0", attached_names, STRING_SIZE, NULL, 0, + rc = bdev_nvme_create(&trid, &hostid, "nvme0", attached_names, STRING_SIZE, 0, attach_ctrlr_done, NULL, NULL); CU_ASSERT(rc == 0); @@ -2610,7 +2610,7 @@ test_init_ana_log_page(void) g_ut_attach_ctrlr_status = 0; g_ut_attach_bdev_count = 5; - rc = bdev_nvme_create(&trid, &hostid, "nvme0", attached_names, STRING_SIZE, NULL, 0, + rc = bdev_nvme_create(&trid, &hostid, "nvme0", attached_names, STRING_SIZE, 0, attach_ctrlr_done, NULL, NULL); CU_ASSERT(rc == 0);