Commit 2b78ecf3 authored by Shuhei Matsumoto's avatar Shuhei Matsumoto Committed by Tomasz Zawadzki
Browse files

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: default avatarShuhei 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: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: default avatarChangpeng Liu <changpeng.liu@intel.com>
Reviewed-by: default avatarDong Yi <dongx.yi@intel.com>
Reviewed-by: default avatarAleksey Marchuk <alexeymar@nvidia.com>
parent 81e92f6b
Loading
Loading
Loading
Loading
+7 −1
Original line number Diff line number Diff line
@@ -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) {