]> www.infradead.org Git - users/hch/nvme-cli.git/commitdiff
nvme-print: nvme list -o json fix
authorYi Zhang <yi.zhang@redhat.com>
Fri, 1 May 2020 07:42:10 +0000 (15:42 +0800)
committerKeith Busch <kbusch@kernel.org>
Fri, 1 May 2020 17:03:01 +0000 (10:03 -0700)
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>
nvme-print.c

index 42e27a39f24eff1b953c45712de8516d37da2b36..74142804d9202a663fcad93095427085eb1aaac6 100644 (file)
@@ -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,