linux-nvme.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: Yi Zhang <yi.zhang@redhat.com>
To: linux-nvme@lists.infradead.org
Cc: kbusch@kernel.org, Justin Tee <justin.tee@broadcom.com>
Subject: [PATCH nvme-cli] nvme-print: nvme list -o json fix
Date: Fri,  1 May 2020 15:42:10 +0800	[thread overview]
Message-ID: <20200501074210.6381-1-yi.zhang@redhat.com> (raw)

Bellow error log will be triggered on non pcie transport, so only print the
ProductName for pcie transport, also add print "\n" and json_free_object fix

Failed to open /sys/class/nvme/nvme1/device/subsystem_vendor with errno No such file or directory
Failed to open /sys/class/nvme/nvme1/device/subsystem_device with errno No such file or directory
Failed to open /sys/class/nvme/nvme1/device/vendor with errno No such file or directory
Failed to open /sys/class/nvme/nvme1/device/device with errno No such file or directory
Failed to open /sys/class/nvme/nvme1/device/class with errno No such file or directory
{
  "Devices" : [
    {
      "NameSpace" : 1,
      "DevicePath" : "/dev/nvme1n1",
      "Firmware" : "4.18.0-1",
      "Index" : 1,
      "ModelNumber" : "Linux",
      "ProductName" : "NULL",
      "SerialNumber" : "eb4695bf0da275a3",
      "UsedBytes" : 268435456000,
      "MaximumLBA" : 524288000,
      "PhysicalSize" : 268435456000,
      "SectorSize" : 512
    }
  ]
}

Reported-by: Justin Tee  <justin.tee@broadcom.com>
Signed-off-by: Yi Zhang <yi.zhang@redhat.com>
---
 nvme-print.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/nvme-print.c b/nvme-print.c
index 42e27a3..7414280 100644
--- a/nvme-print.c
+++ b/nvme-print.c
@@ -4629,7 +4629,7 @@ static void json_simple_ns(struct nvme_namespace *n, struct json_array *devices)
 
 	json_object_add_value_string(device_attrs, "ModelNumber", formatter);
 
-	if (index >= 0) {
+	if (index >= 0 && !strcmp(n->ctrl->transport, "pcie")) {
 		char *product = nvme_product_name(index);
 
 		json_object_add_value_string(device_attrs, "ProductName", product);
@@ -4682,6 +4682,8 @@ static void json_simple_list(struct nvme_topology *t)
 	}
 	json_object_add_value_array(root, "Devices", devices);
 	json_print_object(root, NULL);
+	printf("\n");
+	json_free_object(root);
 }
 
 static void json_print_list_items(struct nvme_topology *t,
-- 
2.21.0


_______________________________________________
linux-nvme mailing list
linux-nvme@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-nvme

             reply	other threads:[~2020-05-01  7:45 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-05-01  7:42 Yi Zhang [this message]
2020-05-01 17:03 ` [PATCH nvme-cli] nvme-print: nvme list -o json fix Keith Busch

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200501074210.6381-1-yi.zhang@redhat.com \
    --to=yi.zhang@redhat.com \
    --cc=justin.tee@broadcom.com \
    --cc=kbusch@kernel.org \
    --cc=linux-nvme@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).