From 2b78ecf34cb2dced25a3fa94469353777efce6cd Mon Sep 17 00:00:00 2001 From: Shuhei Matsumoto Date: Wed, 13 Jul 2022 14:09:27 +0900 Subject: [PATCH] example/nvme_identify: Calculate and use active ns count to allocate ANA log page get_log_page() had used cdata->nn as active ns count to allocate a ANA log page. However, cdata->nn might be larger than the real active ns count. Fix this potential issue. Signed-off-by: Shuhei Matsumoto Change-Id: Ic71b29ad920f8393da7d7db0dab45e10e3268aec Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/13654 Community-CI: Broadcom CI Community-CI: Mellanox Build Bot Tested-by: SPDK CI Jenkins Reviewed-by: Changpeng Liu Reviewed-by: Dong Yi Reviewed-by: Aleksey Marchuk --- examples/nvme/identify/identify.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/examples/nvme/identify/identify.c b/examples/nvme/identify/identify.c index 736630a0d..ed3ccf6b0 100644 --- a/examples/nvme/identify/identify.c +++ b/examples/nvme/identify/identify.c @@ -378,6 +378,7 @@ get_log_pages(struct spdk_nvme_ctrlr *ctrlr) const struct spdk_nvme_ctrlr_data *cdata; outstanding_commands = 0; bool is_discovery = spdk_nvme_ctrlr_is_discovery(ctrlr); + uint32_t nsid, active_ns_count = 0; cdata = spdk_nvme_ctrlr_get_data(ctrlr); @@ -408,6 +409,11 @@ get_log_pages(struct spdk_nvme_ctrlr *ctrlr) } if (spdk_nvme_ctrlr_is_log_page_supported(ctrlr, SPDK_NVME_LOG_ASYMMETRIC_NAMESPACE_ACCESS)) { + for (nsid = spdk_nvme_ctrlr_get_first_active_ns(ctrlr); + nsid != 0; nsid = spdk_nvme_ctrlr_get_next_active_ns(ctrlr, nsid)) { + active_ns_count++; + } + /* We always set RGO (Return Groups Only) to 0 in this tool, an ANA group * descriptor is returned only if that ANA group contains namespaces * that are attached to the controller processing the command, and @@ -415,7 +421,7 @@ get_log_pages(struct spdk_nvme_ctrlr *ctrlr) * Hence the following size should be enough. */ g_ana_log_page_size = sizeof(struct spdk_nvme_ana_page) + cdata->nanagrpid * - sizeof(struct spdk_nvme_ana_group_descriptor) + cdata->nn * + sizeof(struct spdk_nvme_ana_group_descriptor) + active_ns_count * sizeof(uint32_t); g_ana_log_page = calloc(1, g_ana_log_page_size); if (g_ana_log_page == NULL) {