Blob Blame History Raw
commit 01e6062e7be71b7dec29ecd8de09eb411ddd78f1
Author: Yi Zhang <yi.zhang@redhat.com>
Date:   Fri May 1 15:42:10 2020 +0800

    nvme-print: nvme list -o json fix
    
    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>
    Signed-off-by: Keith Busch <kbusch@kernel.org>

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,