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 <smatsumoto@nvidia.com>
Change-Id: Ic71b29ad920f8393da7d7db0dab45e10e3268aec
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/13654
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: Changpeng Liu <changpeng.liu@intel.com>
Reviewed-by: Dong Yi <dongx.yi@intel.com>
Reviewed-by: Aleksey Marchuk <alexeymar@nvidia.com>
This commit is contained in:
Shuhei Matsumoto 2022-07-13 14:09:27 +09:00 committed by Tomasz Zawadzki
parent 81e92f6bca
commit 2b78ecf34c

View File

@ -378,6 +378,7 @@ get_log_pages(struct spdk_nvme_ctrlr *ctrlr)
const struct spdk_nvme_ctrlr_data *cdata; const struct spdk_nvme_ctrlr_data *cdata;
outstanding_commands = 0; outstanding_commands = 0;
bool is_discovery = spdk_nvme_ctrlr_is_discovery(ctrlr); bool is_discovery = spdk_nvme_ctrlr_is_discovery(ctrlr);
uint32_t nsid, active_ns_count = 0;
cdata = spdk_nvme_ctrlr_get_data(ctrlr); 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)) { 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 /* 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 * descriptor is returned only if that ANA group contains namespaces
* that are attached to the controller processing the command, and * 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. * Hence the following size should be enough.
*/ */
g_ana_log_page_size = sizeof(struct spdk_nvme_ana_page) + cdata->nanagrpid * 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); sizeof(uint32_t);
g_ana_log_page = calloc(1, g_ana_log_page_size); g_ana_log_page = calloc(1, g_ana_log_page_size);
if (g_ana_log_page == NULL) { if (g_ana_log_page == NULL) {