From 2a67deefc00041f9e7e2aa25ae7aa423e798be1f Mon Sep 17 00:00:00 2001 From: Shuhei Matsumoto Date: Fri, 6 Aug 2021 07:13:04 +0900 Subject: [PATCH] nvmf: Add ana_reporting parameter into JSON config dump We could not restore the setting of ana_reporting because it was not included in the JSON config dump. Add the parameter ana_reporting into JSON config dump by adding and using a new helper function nvmf_subsystem_get_ana_reporting(). Besides, previously the JSON RPC nvmf_subsystem_get_listeners had ana_state regardless of the value of ana_reporting. We make it conditional in this patch. The JSON RPC nvmf_subsystem_get_listeners had not been used in the test code in the repository. Hence this change will be acceptable. Signed-off-by: Shuhei Matsumoto Change-Id: Ia4e04600c969c254e0a816d3eb34983ee951091e Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/9111 Community-CI: Broadcom CI Community-CI: Mellanox Build Bot Reviewed-by: Changpeng Liu Reviewed-by: Jim Harris Reviewed-by: Aleksey Marchuk Reviewed-by: Monica Kenguva Tested-by: SPDK CI Jenkins --- lib/nvmf/nvmf.c | 1 + lib/nvmf/nvmf_internal.h | 1 + lib/nvmf/nvmf_rpc.c | 6 ++++-- lib/nvmf/subsystem.c | 6 ++++++ test/unit/lib/nvmf/nvmf.c/nvmf_ut.c | 1 + 5 files changed, 13 insertions(+), 2 deletions(-) diff --git a/lib/nvmf/nvmf.c b/lib/nvmf/nvmf.c index 9fd519c4f7..d3a63c81af 100644 --- a/lib/nvmf/nvmf.c +++ b/lib/nvmf/nvmf.c @@ -467,6 +467,7 @@ nvmf_write_subsystem_config_json(struct spdk_json_write_ctx *w, spdk_json_write_named_uint32(w, "min_cntlid", spdk_nvmf_subsystem_get_min_cntlid(subsystem)); spdk_json_write_named_uint32(w, "max_cntlid", spdk_nvmf_subsystem_get_max_cntlid(subsystem)); + spdk_json_write_named_bool(w, "ana_reporting", nvmf_subsystem_get_ana_reporting(subsystem)); /* } "params" */ spdk_json_write_object_end(w); diff --git a/lib/nvmf/nvmf_internal.h b/lib/nvmf/nvmf_internal.h index 0d4c72da25..7cb99b160e 100644 --- a/lib/nvmf/nvmf_internal.h +++ b/lib/nvmf/nvmf_internal.h @@ -387,6 +387,7 @@ void nvmf_subsystem_set_ana_state(struct spdk_nvmf_subsystem *subsystem, const struct spdk_nvme_transport_id *trid, enum spdk_nvme_ana_state ana_state, spdk_nvmf_tgt_subsystem_listen_done_fn cb_fn, void *cb_arg); +bool nvmf_subsystem_get_ana_reporting(struct spdk_nvmf_subsystem *subsystem); /** * Sets the controller ID range for a subsystem. diff --git a/lib/nvmf/nvmf_rpc.c b/lib/nvmf/nvmf_rpc.c index 8ba9974f04..d5ed637a52 100644 --- a/lib/nvmf/nvmf_rpc.c +++ b/lib/nvmf/nvmf_rpc.c @@ -2221,8 +2221,10 @@ dump_nvmf_subsystem_listener(struct spdk_json_write_ctx *w, spdk_json_write_named_string(w, "trsvcid", trid->trsvcid); spdk_json_write_object_end(w); - spdk_json_write_named_string(w, "ana_state", - nvme_ana_state_str(listener->ana_state)); + if (nvmf_subsystem_get_ana_reporting(listener->subsystem)) { + spdk_json_write_named_string(w, "ana_state", + nvme_ana_state_str(listener->ana_state)); + } spdk_json_write_object_end(w); } diff --git a/lib/nvmf/subsystem.c b/lib/nvmf/subsystem.c index 4a6fbe4e69..7ac6f13fde 100644 --- a/lib/nvmf/subsystem.c +++ b/lib/nvmf/subsystem.c @@ -2871,6 +2871,12 @@ spdk_nvmf_subsystem_set_ana_reporting(struct spdk_nvmf_subsystem *subsystem, return 0; } +bool +nvmf_subsystem_get_ana_reporting(struct spdk_nvmf_subsystem *subsystem) +{ + return subsystem->flags.ana_reporting; +} + struct subsystem_listener_update_ctx { struct spdk_nvmf_subsystem_listener *listener; diff --git a/test/unit/lib/nvmf/nvmf.c/nvmf_ut.c b/test/unit/lib/nvmf/nvmf.c/nvmf_ut.c index 0c725e3dae..84bd0b3d1f 100644 --- a/test/unit/lib/nvmf/nvmf.c/nvmf_ut.c +++ b/test/unit/lib/nvmf/nvmf.c/nvmf_ut.c @@ -91,6 +91,7 @@ DEFINE_STUB(spdk_nvmf_subsystem_get_next_host, struct spdk_nvmf_host *, (struct spdk_nvmf_subsystem *subsystem, struct spdk_nvmf_host *prev_host), NULL); DEFINE_STUB(spdk_nvmf_subsystem_get_first_ns, struct spdk_nvmf_ns *, (struct spdk_nvmf_subsystem *subsystem), NULL); +DEFINE_STUB(nvmf_subsystem_get_ana_reporting, bool, (struct spdk_nvmf_subsystem *subsystem), false); DEFINE_STUB_V(spdk_nvmf_ns_get_opts, (const struct spdk_nvmf_ns *ns, struct spdk_nvmf_ns_opts *opts, size_t opts_size)); DEFINE_STUB(spdk_nvmf_ns_get_id, uint32_t, (const struct spdk_nvmf_ns *ns), 0);