From 760ecb0a6ffb87d7cdfe3deea134e5bb95f40b3a Mon Sep 17 00:00:00 2001 From: Jim Harris Date: Thu, 29 Aug 2019 08:21:13 -0700 Subject: [PATCH] nvme/hello_world: don't print message for inactive namespaces Some SSDs have inactive namespaces under normal circumstances, especially those that support namespace management. Printing error messages for these can be confusing to users. So just remove that log message. This removes the only usage of cdata in register_ns(). But that cdata assignment was prefaced with a useful comment for readers of this example code. So move that comment to attach_cb() and restructure the code there a little bit. Signed-off-by: Jim Harris Change-Id: I844e860ea0856d73ca535b6fcbd14279b96da4f1 Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/466797 Tested-by: SPDK CI Jenkins Reviewed-by: Changpeng Liu Reviewed-by: Shuhei Matsumoto Reviewed-by: Tom Nabarro --- examples/nvme/hello_world/hello_world.c | 26 +++++++++++-------------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/examples/nvme/hello_world/hello_world.c b/examples/nvme/hello_world/hello_world.c index 87c23bb1c..bf0318fd1 100644 --- a/examples/nvme/hello_world/hello_world.c +++ b/examples/nvme/hello_world/hello_world.c @@ -59,22 +59,8 @@ static void register_ns(struct spdk_nvme_ctrlr *ctrlr, struct spdk_nvme_ns *ns) { struct ns_entry *entry; - const struct spdk_nvme_ctrlr_data *cdata; - - /* - * spdk_nvme_ctrlr is the logical abstraction in SPDK for an NVMe - * controller. During initialization, the IDENTIFY data for the - * controller is read using an NVMe admin command, and that data - * can be retrieved using spdk_nvme_ctrlr_get_data() to get - * detailed information on the controller. Refer to the NVMe - * specification for more details on IDENTIFY for NVMe controllers. - */ - cdata = spdk_nvme_ctrlr_get_data(ctrlr); if (!spdk_nvme_ns_is_active(ns)) { - printf("Controller %-20.20s (%-20.20s): Skipping inactive NS %u\n", - cdata->mn, cdata->sn, - spdk_nvme_ns_get_id(ns)); return; } @@ -292,7 +278,7 @@ attach_cb(void *cb_ctx, const struct spdk_nvme_transport_id *trid, int nsid, num_ns; struct ctrlr_entry *entry; struct spdk_nvme_ns *ns; - const struct spdk_nvme_ctrlr_data *cdata = spdk_nvme_ctrlr_get_data(ctrlr); + const struct spdk_nvme_ctrlr_data *cdata; entry = malloc(sizeof(struct ctrlr_entry)); if (entry == NULL) { @@ -302,6 +288,16 @@ attach_cb(void *cb_ctx, const struct spdk_nvme_transport_id *trid, printf("Attached to %s\n", trid->traddr); + /* + * spdk_nvme_ctrlr is the logical abstraction in SPDK for an NVMe + * controller. During initialization, the IDENTIFY data for the + * controller is read using an NVMe admin command, and that data + * can be retrieved using spdk_nvme_ctrlr_get_data() to get + * detailed information on the controller. Refer to the NVMe + * specification for more details on IDENTIFY for NVMe controllers. + */ + cdata = spdk_nvme_ctrlr_get_data(ctrlr); + snprintf(entry->name, sizeof(entry->name), "%-20.20s (%-20.20s)", cdata->mn, cdata->sn); entry->ctrlr = ctrlr;