nvme_manage: Fix a bug of uninitialized namespace

Uninitialized namespace struct will be all zeros.
Some drive might have multiple namespaces but not initialized.
nvme_manage will get to segment fault when this happens. This
patch is to fix this.

Change-Id: I8ea5bf3d7c29cf876fbea3d1bee22b95748d3b8a
Signed-off-by: Chunyang Hui <chunyang.hui@intel.com>
Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/447414
Reviewed-by: Changpeng Liu <changpeng.liu@intel.com>
Reviewed-by: Jim Harris <james.r.harris@intel.com>
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
This commit is contained in:
Chunyang Hui 2019-03-08 22:50:57 +08:00 committed by Jim Harris
parent e39b4d6cdb
commit aa09ce098d

View File

@ -220,10 +220,9 @@ display_namespace(struct spdk_nvme_ns *ns)
static void
display_controller(struct dev *dev, int model)
{
struct spdk_nvme_ns *ns;
const struct spdk_nvme_ctrlr_data *cdata;
uint8_t str[128];
uint32_t i;
uint32_t nsid;
cdata = spdk_nvme_ctrlr_get_data(dev->ctrlr);
@ -264,12 +263,9 @@ display_controller(struct dev *dev, int model)
printf("\n");
printf("Namespace Attributes\n");
printf("============================\n");
for (i = 1; i <= spdk_nvme_ctrlr_get_num_ns(dev->ctrlr); i++) {
ns = spdk_nvme_ctrlr_get_ns(dev->ctrlr, i);
if (ns == NULL) {
continue;
}
display_namespace(ns);
for (nsid = spdk_nvme_ctrlr_get_first_active_ns(dev->ctrlr);
nsid != 0; nsid = spdk_nvme_ctrlr_get_next_active_ns(dev->ctrlr, nsid)) {
display_namespace(spdk_nvme_ctrlr_get_ns(dev->ctrlr, nsid));
}
}