|
Tomas Bzatek |
986ba7 |
From 23daeedc53be9b5225cc6806434888c0a7a8e9bf Mon Sep 17 00:00:00 2001
|
|
Tomas Bzatek |
986ba7 |
From: Stuart Hayes <stuart_hayes@dell.com>
|
|
Tomas Bzatek |
986ba7 |
Date: Fri, 14 Apr 2023 22:01:07 -0400
|
|
Tomas Bzatek |
986ba7 |
Subject: [PATCH 03/11] nbft: add the nbft show plugin
|
|
Tomas Bzatek |
986ba7 |
|
|
Tomas Bzatek |
986ba7 |
Display contents of the ACPI NBFT files.
|
|
Tomas Bzatek |
986ba7 |
|
|
Tomas Bzatek |
986ba7 |
Usage: nvme nbft show <device> [OPTIONS]
|
|
Tomas Bzatek |
986ba7 |
|
|
Tomas Bzatek |
986ba7 |
Options:
|
|
Tomas Bzatek |
986ba7 |
[ --output-format=<FMT>, -o <FMT> ] --- Output format: normal|json
|
|
Tomas Bzatek |
986ba7 |
[ --subsystem, -s ] --- show NBFT subsystems
|
|
Tomas Bzatek |
986ba7 |
[ --hfi, -H ] --- show NBFT HFIs
|
|
Tomas Bzatek |
986ba7 |
[ --discovery, -d ] --- show NBFT discovery controllers
|
|
Tomas Bzatek |
986ba7 |
[ --nbft-path=<STR> ] --- user-defined path for NBFT tables
|
|
Tomas Bzatek |
986ba7 |
|
|
Tomas Bzatek |
986ba7 |
Signed-off-by: Stuart Hayes <stuart_hayes@dell.com>
|
|
Tomas Bzatek |
986ba7 |
Signed-off-by: Martin Wilck <mwilck@suse.com>
|
|
Tomas Bzatek |
986ba7 |
Signed-off-by: John Meneghini <jmeneghi@redhat.com>
|
|
Tomas Bzatek |
986ba7 |
---
|
|
Tomas Bzatek |
986ba7 |
plugins/meson.build | 1 +
|
|
Tomas Bzatek |
986ba7 |
plugins/nbft/nbft-plugin.c | 568 +++++++++++++++++++++++++++++++++++++
|
|
Tomas Bzatek |
986ba7 |
plugins/nbft/nbft-plugin.h | 18 ++
|
|
Tomas Bzatek |
986ba7 |
3 files changed, 587 insertions(+)
|
|
Tomas Bzatek |
986ba7 |
create mode 100644 plugins/nbft/nbft-plugin.c
|
|
Tomas Bzatek |
986ba7 |
create mode 100644 plugins/nbft/nbft-plugin.h
|
|
Tomas Bzatek |
986ba7 |
|
|
Tomas Bzatek |
986ba7 |
diff --git a/plugins/meson.build b/plugins/meson.build
|
|
Tomas Bzatek |
986ba7 |
index 2cf2486f..38b7cded 100644
|
|
Tomas Bzatek |
986ba7 |
--- a/plugins/meson.build
|
|
Tomas Bzatek |
986ba7 |
+++ b/plugins/meson.build
|
|
Tomas Bzatek |
986ba7 |
@@ -12,6 +12,7 @@ if json_c_dep.found()
|
|
Tomas Bzatek |
986ba7 |
'plugins/intel/intel-nvme.c',
|
|
Tomas Bzatek |
986ba7 |
'plugins/memblaze/memblaze-nvme.c',
|
|
Tomas Bzatek |
986ba7 |
'plugins/micron/micron-nvme.c',
|
|
Tomas Bzatek |
986ba7 |
+ 'plugins/nbft/nbft-plugin.c',
|
|
Tomas Bzatek |
986ba7 |
'plugins/netapp/netapp-nvme.c',
|
|
Tomas Bzatek |
986ba7 |
'plugins/nvidia/nvidia-nvme.c',
|
|
Tomas Bzatek |
986ba7 |
'plugins/scaleflux/sfx-nvme.c',
|
|
Tomas Bzatek |
986ba7 |
diff --git a/plugins/nbft/nbft-plugin.c b/plugins/nbft/nbft-plugin.c
|
|
Tomas Bzatek |
986ba7 |
new file mode 100644
|
|
Tomas Bzatek |
986ba7 |
index 00000000..6ae2525a
|
|
Tomas Bzatek |
986ba7 |
--- /dev/null
|
|
Tomas Bzatek |
986ba7 |
+++ b/plugins/nbft/nbft-plugin.c
|
|
Tomas Bzatek |
986ba7 |
@@ -0,0 +1,568 @@
|
|
Tomas Bzatek |
986ba7 |
+// SPDX-License-Identifier: GPL-2.0-or-later
|
|
Tomas Bzatek |
986ba7 |
+
|
|
Tomas Bzatek |
986ba7 |
+#include <errno.h>
|
|
Tomas Bzatek |
986ba7 |
+#include <stdio.h>
|
|
Tomas Bzatek |
986ba7 |
+#include <fnmatch.h>
|
|
Tomas Bzatek |
986ba7 |
+
|
|
Tomas Bzatek |
986ba7 |
+#include "nvme-print.h"
|
|
Tomas Bzatek |
986ba7 |
+#include "nvme.h"
|
|
Tomas Bzatek |
986ba7 |
+#include "nbft.h"
|
|
Tomas Bzatek |
986ba7 |
+#include "libnvme.h"
|
|
Tomas Bzatek |
986ba7 |
+#include "fabrics.h"
|
|
Tomas Bzatek |
986ba7 |
+
|
|
Tomas Bzatek |
986ba7 |
+#define CREATE_CMD
|
|
Tomas Bzatek |
986ba7 |
+#include "nbft-plugin.h"
|
|
Tomas Bzatek |
986ba7 |
+
|
|
Tomas Bzatek |
986ba7 |
+static const char dash[100] = {[0 ... 98] = '-', [99] = '\0'};
|
|
Tomas Bzatek |
986ba7 |
+
|
|
Tomas Bzatek |
986ba7 |
+#define PCI_SEGMENT(sbdf) ((sbdf & 0xffff0000) >> 16)
|
|
Tomas Bzatek |
986ba7 |
+#define PCI_BUS(sbdf) ((sbdf & 0x0000ff00) >> 8)
|
|
Tomas Bzatek |
986ba7 |
+#define PCI_DEV(sbdf) ((sbdf & 0x000000f8) >> 3)
|
|
Tomas Bzatek |
986ba7 |
+#define PCI_FUNC(sbdf) ((sbdf & 0x00000007) >> 0)
|
|
Tomas Bzatek |
986ba7 |
+
|
|
Tomas Bzatek |
986ba7 |
+static const char *pci_sbdf_to_string(__u16 pci_sbdf)
|
|
Tomas Bzatek |
986ba7 |
+{
|
|
Tomas Bzatek |
986ba7 |
+ static char pcidev[13];
|
|
Tomas Bzatek |
986ba7 |
+
|
|
Tomas Bzatek |
986ba7 |
+ snprintf(pcidev, sizeof(pcidev), "%x:%x:%x.%x",
|
|
Tomas Bzatek |
986ba7 |
+ PCI_SEGMENT(pci_sbdf),
|
|
Tomas Bzatek |
986ba7 |
+ PCI_BUS(pci_sbdf),
|
|
Tomas Bzatek |
986ba7 |
+ PCI_DEV(pci_sbdf),
|
|
Tomas Bzatek |
986ba7 |
+ PCI_FUNC(pci_sbdf));
|
|
Tomas Bzatek |
986ba7 |
+ return pcidev;
|
|
Tomas Bzatek |
986ba7 |
+}
|
|
Tomas Bzatek |
986ba7 |
+
|
|
Tomas Bzatek |
986ba7 |
+static char *mac_addr_to_string(unsigned char mac_addr[6])
|
|
Tomas Bzatek |
986ba7 |
+{
|
|
Tomas Bzatek |
986ba7 |
+ static char mac_string[18];
|
|
Tomas Bzatek |
986ba7 |
+
|
|
Tomas Bzatek |
986ba7 |
+ snprintf(mac_string, sizeof(mac_string), "%02x:%02x:%02x:%02x:%02x:%02x",
|
|
Tomas Bzatek |
986ba7 |
+ mac_addr[0],
|
|
Tomas Bzatek |
986ba7 |
+ mac_addr[1],
|
|
Tomas Bzatek |
986ba7 |
+ mac_addr[2],
|
|
Tomas Bzatek |
986ba7 |
+ mac_addr[3],
|
|
Tomas Bzatek |
986ba7 |
+ mac_addr[4],
|
|
Tomas Bzatek |
986ba7 |
+ mac_addr[5]);
|
|
Tomas Bzatek |
986ba7 |
+ return mac_string;
|
|
Tomas Bzatek |
986ba7 |
+}
|
|
Tomas Bzatek |
986ba7 |
+
|
|
Tomas Bzatek |
986ba7 |
+static json_object *hfi_to_json(struct nbft_info_hfi *hfi)
|
|
Tomas Bzatek |
986ba7 |
+{
|
|
Tomas Bzatek |
986ba7 |
+ struct json_object *hfi_json;
|
|
Tomas Bzatek |
986ba7 |
+
|
|
Tomas Bzatek |
986ba7 |
+ hfi_json = json_create_object();
|
|
Tomas Bzatek |
986ba7 |
+ if (!hfi_json)
|
|
Tomas Bzatek |
986ba7 |
+ return NULL;
|
|
Tomas Bzatek |
986ba7 |
+
|
|
Tomas Bzatek |
986ba7 |
+ if (json_object_add_value_int(hfi_json, "index", hfi->index)
|
|
Tomas Bzatek |
986ba7 |
+ || json_object_add_value_string(hfi_json, "transport", hfi->transport))
|
|
Tomas Bzatek |
986ba7 |
+ goto fail;
|
|
Tomas Bzatek |
986ba7 |
+
|
|
Tomas Bzatek |
986ba7 |
+ if (strcmp(hfi->transport, "tcp") == 0) {
|
|
Tomas Bzatek |
986ba7 |
+ if (json_object_add_value_string(hfi_json, "pcidev",
|
|
Tomas Bzatek |
986ba7 |
+ pci_sbdf_to_string(hfi->tcp_info.pci_sbdf))
|
|
Tomas Bzatek |
986ba7 |
+ || json_object_add_value_string(hfi_json, "mac_addr",
|
|
Tomas Bzatek |
986ba7 |
+ mac_addr_to_string(hfi->tcp_info.mac_addr))
|
|
Tomas Bzatek |
986ba7 |
+ || json_object_add_value_int(hfi_json, "vlan",
|
|
Tomas Bzatek |
986ba7 |
+ hfi->tcp_info.vlan)
|
|
Tomas Bzatek |
986ba7 |
+ || json_object_add_value_int(hfi_json, "ip_origin",
|
|
Tomas Bzatek |
986ba7 |
+ hfi->tcp_info.ip_origin)
|
|
Tomas Bzatek |
986ba7 |
+ || json_object_add_value_string(hfi_json, "ipaddr",
|
|
Tomas Bzatek |
986ba7 |
+ hfi->tcp_info.ipaddr)
|
|
Tomas Bzatek |
986ba7 |
+ || json_object_add_value_int(hfi_json, "subnet_mask_prefix",
|
|
Tomas Bzatek |
986ba7 |
+ hfi->tcp_info.subnet_mask_prefix)
|
|
Tomas Bzatek |
986ba7 |
+ || json_object_add_value_string(hfi_json, "gateway_ipaddr",
|
|
Tomas Bzatek |
986ba7 |
+ hfi->tcp_info.gateway_ipaddr)
|
|
Tomas Bzatek |
986ba7 |
+ || json_object_add_value_int(hfi_json, "route_metric",
|
|
Tomas Bzatek |
986ba7 |
+ hfi->tcp_info.route_metric)
|
|
Tomas Bzatek |
986ba7 |
+ || json_object_add_value_string(hfi_json, "primary_dns_ipaddr",
|
|
Tomas Bzatek |
986ba7 |
+ hfi->tcp_info.primary_dns_ipaddr)
|
|
Tomas Bzatek |
986ba7 |
+ || json_object_add_value_string(hfi_json, "secondary_dns_ipaddr",
|
|
Tomas Bzatek |
986ba7 |
+ hfi->tcp_info.secondary_dns_ipaddr)
|
|
Tomas Bzatek |
986ba7 |
+ || json_object_add_value_string(hfi_json, "dhcp_server_ipaddr",
|
|
Tomas Bzatek |
986ba7 |
+ hfi->tcp_info.dhcp_server_ipaddr)
|
|
Tomas Bzatek |
986ba7 |
+ || (hfi->tcp_info.host_name
|
|
Tomas Bzatek |
986ba7 |
+ && json_object_add_value_string(hfi_json, "host_name",
|
|
Tomas Bzatek |
986ba7 |
+ hfi->tcp_info.host_name))
|
|
Tomas Bzatek |
986ba7 |
+ || json_object_add_value_int(hfi_json, "this_hfi_is_default_route",
|
|
Tomas Bzatek |
986ba7 |
+ hfi->tcp_info.this_hfi_is_default_route)
|
|
Tomas Bzatek |
986ba7 |
+ || json_object_add_value_int(hfi_json, "dhcp_override",
|
|
Tomas Bzatek |
986ba7 |
+ hfi->tcp_info.dhcp_override))
|
|
Tomas Bzatek |
986ba7 |
+ goto fail;
|
|
Tomas Bzatek |
986ba7 |
+ else
|
|
Tomas Bzatek |
986ba7 |
+ return hfi_json;
|
|
Tomas Bzatek |
986ba7 |
+ }
|
|
Tomas Bzatek |
986ba7 |
+fail:
|
|
Tomas Bzatek |
986ba7 |
+ json_free_object(hfi_json);
|
|
Tomas Bzatek |
986ba7 |
+ return NULL;
|
|
Tomas Bzatek |
986ba7 |
+}
|
|
Tomas Bzatek |
986ba7 |
+
|
|
Tomas Bzatek |
986ba7 |
+static json_object *ssns_to_json(struct nbft_info_subsystem_ns *ss)
|
|
Tomas Bzatek |
986ba7 |
+{
|
|
Tomas Bzatek |
986ba7 |
+ struct json_object *ss_json;
|
|
Tomas Bzatek |
986ba7 |
+ struct json_object *hfi_array_json;
|
|
Tomas Bzatek |
986ba7 |
+ char json_str[40];
|
|
Tomas Bzatek |
986ba7 |
+ char *json_str_p;
|
|
Tomas Bzatek |
986ba7 |
+ int i;
|
|
Tomas Bzatek |
986ba7 |
+
|
|
Tomas Bzatek |
986ba7 |
+ ss_json = json_create_object();
|
|
Tomas Bzatek |
986ba7 |
+ if (!ss_json)
|
|
Tomas Bzatek |
986ba7 |
+ return NULL;
|
|
Tomas Bzatek |
986ba7 |
+
|
|
Tomas Bzatek |
986ba7 |
+ hfi_array_json = json_create_array();
|
|
Tomas Bzatek |
986ba7 |
+ if (!hfi_array_json)
|
|
Tomas Bzatek |
986ba7 |
+ goto fail;
|
|
Tomas Bzatek |
986ba7 |
+
|
|
Tomas Bzatek |
986ba7 |
+ for (i = 0; i < ss->num_hfis; i++)
|
|
Tomas Bzatek |
986ba7 |
+ if (json_array_add_value_object(hfi_array_json,
|
|
Tomas Bzatek |
986ba7 |
+ json_object_new_int(ss->hfis[i]->index)))
|
|
Tomas Bzatek |
986ba7 |
+ goto fail;
|
|
Tomas Bzatek |
986ba7 |
+
|
|
Tomas Bzatek |
986ba7 |
+ if (json_object_add_value_int(ss_json, "index", ss->index)
|
|
Tomas Bzatek |
986ba7 |
+ || json_object_add_value_int(ss_json, "num_hfis", ss->num_hfis)
|
|
Tomas Bzatek |
986ba7 |
+ || json_object_object_add(ss_json, "hfis", hfi_array_json)
|
|
Tomas Bzatek |
986ba7 |
+ || json_object_add_value_string(ss_json, "transport", ss->transport)
|
|
Tomas Bzatek |
986ba7 |
+ || json_object_add_value_string(ss_json, "traddr", ss->traddr)
|
|
Tomas Bzatek |
986ba7 |
+ || json_object_add_value_string(ss_json, "trsvcid", ss->trsvcid)
|
|
Tomas Bzatek |
986ba7 |
+ || json_object_add_value_int(ss_json, "subsys_port_id", ss->subsys_port_id)
|
|
Tomas Bzatek |
986ba7 |
+ || json_object_add_value_int(ss_json, "nsid", ss->nsid))
|
|
Tomas Bzatek |
986ba7 |
+ goto fail;
|
|
Tomas Bzatek |
986ba7 |
+
|
|
Tomas Bzatek |
986ba7 |
+ memset(json_str, 0, sizeof(json_str));
|
|
Tomas Bzatek |
986ba7 |
+ json_str_p = json_str;
|
|
Tomas Bzatek |
986ba7 |
+
|
|
Tomas Bzatek |
986ba7 |
+ switch (ss->nid_type) {
|
|
Tomas Bzatek |
986ba7 |
+ case NBFT_INFO_NID_TYPE_EUI64:
|
|
Tomas Bzatek |
986ba7 |
+ if (json_object_add_value_string(ss_json, "nid_type", "eui64"))
|
|
Tomas Bzatek |
986ba7 |
+ goto fail;
|
|
Tomas Bzatek |
986ba7 |
+ for (i = 0; i < 8; i++)
|
|
Tomas Bzatek |
986ba7 |
+ json_str_p += sprintf(json_str_p, "%02x", ss->nid[i]);
|
|
Tomas Bzatek |
986ba7 |
+ break;
|
|
Tomas Bzatek |
986ba7 |
+
|
|
Tomas Bzatek |
986ba7 |
+ case NBFT_INFO_NID_TYPE_NGUID:
|
|
Tomas Bzatek |
986ba7 |
+ if (json_object_add_value_string(ss_json, "nid_type", "nguid"))
|
|
Tomas Bzatek |
986ba7 |
+ goto fail;
|
|
Tomas Bzatek |
986ba7 |
+ for (i = 0; i < 16; i++)
|
|
Tomas Bzatek |
986ba7 |
+ json_str_p += sprintf(json_str_p, "%02x", ss->nid[i]);
|
|
Tomas Bzatek |
986ba7 |
+ break;
|
|
Tomas Bzatek |
986ba7 |
+
|
|
Tomas Bzatek |
986ba7 |
+ case NBFT_INFO_NID_TYPE_NS_UUID:
|
|
Tomas Bzatek |
986ba7 |
+ if (json_object_add_value_string(ss_json, "nid_type", "uuid"))
|
|
Tomas Bzatek |
986ba7 |
+ goto fail;
|
|
Tomas Bzatek |
986ba7 |
+ nvme_uuid_to_string(ss->nid, json_str);
|
|
Tomas Bzatek |
986ba7 |
+ break;
|
|
Tomas Bzatek |
986ba7 |
+
|
|
Tomas Bzatek |
986ba7 |
+ default:
|
|
Tomas Bzatek |
986ba7 |
+ break;
|
|
Tomas Bzatek |
986ba7 |
+ }
|
|
Tomas Bzatek |
986ba7 |
+ if (json_object_add_value_string(ss_json, "nid", json_str))
|
|
Tomas Bzatek |
986ba7 |
+ goto fail;
|
|
Tomas Bzatek |
986ba7 |
+
|
|
Tomas Bzatek |
986ba7 |
+ if ((ss->subsys_nqn
|
|
Tomas Bzatek |
986ba7 |
+ && json_object_add_value_string(ss_json, "subsys_nqn", ss->subsys_nqn))
|
|
Tomas Bzatek |
986ba7 |
+ || json_object_add_value_int(ss_json, "controller_id", ss->controller_id)
|
|
Tomas Bzatek |
986ba7 |
+ || json_object_add_value_int(ss_json, "asqsz", ss->asqsz)
|
|
Tomas Bzatek |
986ba7 |
+ || (ss->dhcp_root_path_string
|
|
Tomas Bzatek |
986ba7 |
+ && json_object_add_value_string(ss_json, "dhcp_root_path_string",
|
|
Tomas Bzatek |
986ba7 |
+ ss->dhcp_root_path_string))
|
|
Tomas Bzatek |
986ba7 |
+ || json_object_add_value_int(ss_json, "pdu_header_digest_required",
|
|
Tomas Bzatek |
986ba7 |
+ ss->pdu_header_digest_required)
|
|
Tomas Bzatek |
986ba7 |
+ || json_object_add_value_int(ss_json, "data_digest_required",
|
|
Tomas Bzatek |
986ba7 |
+ ss->data_digest_required))
|
|
Tomas Bzatek |
986ba7 |
+ goto fail;
|
|
Tomas Bzatek |
986ba7 |
+
|
|
Tomas Bzatek |
986ba7 |
+ return ss_json;
|
|
Tomas Bzatek |
986ba7 |
+fail:
|
|
Tomas Bzatek |
986ba7 |
+ json_free_object(ss_json);
|
|
Tomas Bzatek |
986ba7 |
+ return NULL;
|
|
Tomas Bzatek |
986ba7 |
+}
|
|
Tomas Bzatek |
986ba7 |
+
|
|
Tomas Bzatek |
986ba7 |
+static json_object *discovery_to_json(struct nbft_info_discovery *disc)
|
|
Tomas Bzatek |
986ba7 |
+{
|
|
Tomas Bzatek |
986ba7 |
+ struct json_object *disc_json;
|
|
Tomas Bzatek |
986ba7 |
+
|
|
Tomas Bzatek |
986ba7 |
+ disc_json = json_create_object();
|
|
Tomas Bzatek |
986ba7 |
+ if (!disc_json)
|
|
Tomas Bzatek |
986ba7 |
+ return NULL;
|
|
Tomas Bzatek |
986ba7 |
+
|
|
Tomas Bzatek |
986ba7 |
+ if (json_object_add_value_int(disc_json, "index", disc->index)
|
|
Tomas Bzatek |
986ba7 |
+ || (disc->security
|
|
Tomas Bzatek |
986ba7 |
+ && json_object_add_value_int(disc_json, "security", disc->security->index))
|
|
Tomas Bzatek |
986ba7 |
+ || (disc->hfi
|
|
Tomas Bzatek |
986ba7 |
+ && json_object_add_value_int(disc_json, "hfi", disc->hfi->index))
|
|
Tomas Bzatek |
986ba7 |
+ || (disc->uri
|
|
Tomas Bzatek |
986ba7 |
+ && json_object_add_value_string(disc_json, "uri", disc->uri))
|
|
Tomas Bzatek |
986ba7 |
+ || (disc->nqn
|
|
Tomas Bzatek |
986ba7 |
+ && json_object_add_value_string(disc_json, "nqn", disc->nqn))) {
|
|
Tomas Bzatek |
986ba7 |
+ json_free_object(disc_json);
|
|
Tomas Bzatek |
986ba7 |
+ return NULL;
|
|
Tomas Bzatek |
986ba7 |
+ } else
|
|
Tomas Bzatek |
986ba7 |
+ return disc_json;
|
|
Tomas Bzatek |
986ba7 |
+}
|
|
Tomas Bzatek |
986ba7 |
+
|
|
Tomas Bzatek |
986ba7 |
+static const char *primary_admin_host_flag_to_str(unsigned int primary)
|
|
Tomas Bzatek |
986ba7 |
+{
|
|
Tomas Bzatek |
986ba7 |
+ static const char * const str[] = {
|
|
Tomas Bzatek |
986ba7 |
+ [NBFT_INFO_PRIMARY_ADMIN_HOST_FLAG_NOT_INDICATED] = "not indicated",
|
|
Tomas Bzatek |
986ba7 |
+ [NBFT_INFO_PRIMARY_ADMIN_HOST_FLAG_UNSELECTED] = "unselected",
|
|
Tomas Bzatek |
986ba7 |
+ [NBFT_INFO_PRIMARY_ADMIN_HOST_FLAG_SELECTED] = "selected",
|
|
Tomas Bzatek |
986ba7 |
+ [NBFT_INFO_PRIMARY_ADMIN_HOST_FLAG_RESERVED] = "reserved",
|
|
Tomas Bzatek |
986ba7 |
+ };
|
|
Tomas Bzatek |
986ba7 |
+
|
|
Tomas Bzatek |
986ba7 |
+ if (primary > NBFT_INFO_PRIMARY_ADMIN_HOST_FLAG_RESERVED)
|
|
Tomas Bzatek |
986ba7 |
+ return "INVALID";
|
|
Tomas Bzatek |
986ba7 |
+ return str[primary];
|
|
Tomas Bzatek |
986ba7 |
+}
|
|
Tomas Bzatek |
986ba7 |
+
|
|
Tomas Bzatek |
986ba7 |
+static struct json_object *nbft_to_json(struct nbft_info *nbft, bool show_subsys,
|
|
Tomas Bzatek |
986ba7 |
+ bool show_hfi, bool show_discovery)
|
|
Tomas Bzatek |
986ba7 |
+{
|
|
Tomas Bzatek |
986ba7 |
+ struct json_object *nbft_json, *host_json;
|
|
Tomas Bzatek |
986ba7 |
+
|
|
Tomas Bzatek |
986ba7 |
+ nbft_json = json_create_object();
|
|
Tomas Bzatek |
986ba7 |
+ if (!nbft_json)
|
|
Tomas Bzatek |
986ba7 |
+ return NULL;
|
|
Tomas Bzatek |
986ba7 |
+
|
|
Tomas Bzatek |
986ba7 |
+ if (json_object_add_value_string(nbft_json, "filename", nbft->filename))
|
|
Tomas Bzatek |
986ba7 |
+ goto fail;
|
|
Tomas Bzatek |
986ba7 |
+
|
|
Tomas Bzatek |
986ba7 |
+ host_json = json_create_object();
|
|
Tomas Bzatek |
986ba7 |
+ if (!host_json)
|
|
Tomas Bzatek |
986ba7 |
+ goto fail;
|
|
Tomas Bzatek |
986ba7 |
+ if ((nbft->host.nqn
|
|
Tomas Bzatek |
986ba7 |
+ && json_object_add_value_string(host_json, "nqn", nbft->host.nqn))
|
|
Tomas Bzatek |
986ba7 |
+ || (nbft->host.id
|
|
Tomas Bzatek |
986ba7 |
+ && json_object_add_value_string(host_json, "id",
|
|
Tomas Bzatek |
986ba7 |
+ util_uuid_to_string(nbft->host.id))))
|
|
Tomas Bzatek |
986ba7 |
+ goto fail;
|
|
Tomas Bzatek |
986ba7 |
+ json_object_add_value_int(host_json, "host_id_configured",
|
|
Tomas Bzatek |
986ba7 |
+ nbft->host.host_id_configured);
|
|
Tomas Bzatek |
986ba7 |
+ json_object_add_value_int(host_json, "host_nqn_configured",
|
|
Tomas Bzatek |
986ba7 |
+ nbft->host.host_nqn_configured);
|
|
Tomas Bzatek |
986ba7 |
+ json_object_add_value_string(host_json, "primary_admin_host_flag",
|
|
Tomas Bzatek |
986ba7 |
+ primary_admin_host_flag_to_str(nbft->host.primary));
|
|
Tomas Bzatek |
986ba7 |
+ if (json_object_object_add(nbft_json, "host", host_json)) {
|
|
Tomas Bzatek |
986ba7 |
+ json_free_object(host_json);
|
|
Tomas Bzatek |
986ba7 |
+ goto fail;
|
|
Tomas Bzatek |
986ba7 |
+ }
|
|
Tomas Bzatek |
986ba7 |
+
|
|
Tomas Bzatek |
986ba7 |
+ if (show_subsys) {
|
|
Tomas Bzatek |
986ba7 |
+ struct json_object *subsys_array_json, *subsys_json;
|
|
Tomas Bzatek |
986ba7 |
+ struct nbft_info_subsystem_ns **ss;
|
|
Tomas Bzatek |
986ba7 |
+
|
|
Tomas Bzatek |
986ba7 |
+ subsys_array_json = json_create_array();
|
|
Tomas Bzatek |
986ba7 |
+ if (!subsys_array_json)
|
|
Tomas Bzatek |
986ba7 |
+ goto fail;
|
|
Tomas Bzatek |
986ba7 |
+ for (ss = nbft->subsystem_ns_list; ss && *ss; ss++) {
|
|
Tomas Bzatek |
986ba7 |
+ subsys_json = ssns_to_json(*ss);
|
|
Tomas Bzatek |
986ba7 |
+ if (!subsys_json)
|
|
Tomas Bzatek |
986ba7 |
+ goto fail;
|
|
Tomas Bzatek |
986ba7 |
+ if (json_object_array_add(subsys_array_json, subsys_json)) {
|
|
Tomas Bzatek |
986ba7 |
+ json_free_object(subsys_json);
|
|
Tomas Bzatek |
986ba7 |
+ goto fail;
|
|
Tomas Bzatek |
986ba7 |
+ }
|
|
Tomas Bzatek |
986ba7 |
+ }
|
|
Tomas Bzatek |
986ba7 |
+ if (json_object_object_add(nbft_json, "subsystem", subsys_array_json)) {
|
|
Tomas Bzatek |
986ba7 |
+ json_free_object(subsys_array_json);
|
|
Tomas Bzatek |
986ba7 |
+ goto fail;
|
|
Tomas Bzatek |
986ba7 |
+ }
|
|
Tomas Bzatek |
986ba7 |
+ }
|
|
Tomas Bzatek |
986ba7 |
+ if (show_hfi) {
|
|
Tomas Bzatek |
986ba7 |
+ struct json_object *hfi_array_json, *hfi_json;
|
|
Tomas Bzatek |
986ba7 |
+ struct nbft_info_hfi **hfi;
|
|
Tomas Bzatek |
986ba7 |
+
|
|
Tomas Bzatek |
986ba7 |
+ hfi_array_json = json_create_array();
|
|
Tomas Bzatek |
986ba7 |
+ if (!hfi_array_json)
|
|
Tomas Bzatek |
986ba7 |
+ goto fail;
|
|
Tomas Bzatek |
986ba7 |
+ for (hfi = nbft->hfi_list; hfi && *hfi; hfi++) {
|
|
Tomas Bzatek |
986ba7 |
+ hfi_json = hfi_to_json(*hfi);
|
|
Tomas Bzatek |
986ba7 |
+ if (!hfi_json)
|
|
Tomas Bzatek |
986ba7 |
+ goto fail;
|
|
Tomas Bzatek |
986ba7 |
+ if (json_object_array_add(hfi_array_json, hfi_json)) {
|
|
Tomas Bzatek |
986ba7 |
+ json_free_object(hfi_json);
|
|
Tomas Bzatek |
986ba7 |
+ goto fail;
|
|
Tomas Bzatek |
986ba7 |
+ }
|
|
Tomas Bzatek |
986ba7 |
+ }
|
|
Tomas Bzatek |
986ba7 |
+ if (json_object_object_add(nbft_json, "hfi", hfi_array_json)) {
|
|
Tomas Bzatek |
986ba7 |
+ json_free_object(hfi_array_json);
|
|
Tomas Bzatek |
986ba7 |
+ goto fail;
|
|
Tomas Bzatek |
986ba7 |
+ }
|
|
Tomas Bzatek |
986ba7 |
+ }
|
|
Tomas Bzatek |
986ba7 |
+ if (show_discovery) {
|
|
Tomas Bzatek |
986ba7 |
+ struct json_object *discovery_array_json, *discovery_json;
|
|
Tomas Bzatek |
986ba7 |
+ struct nbft_info_discovery **disc;
|
|
Tomas Bzatek |
986ba7 |
+
|
|
Tomas Bzatek |
986ba7 |
+ discovery_array_json = json_create_array();
|
|
Tomas Bzatek |
986ba7 |
+ if (!discovery_array_json)
|
|
Tomas Bzatek |
986ba7 |
+ goto fail;
|
|
Tomas Bzatek |
986ba7 |
+ for (disc = nbft->discovery_list; disc && *disc; disc++) {
|
|
Tomas Bzatek |
986ba7 |
+ discovery_json = discovery_to_json(*disc);
|
|
Tomas Bzatek |
986ba7 |
+ if (!discovery_json)
|
|
Tomas Bzatek |
986ba7 |
+ goto fail;
|
|
Tomas Bzatek |
986ba7 |
+ if (json_object_array_add(discovery_array_json, discovery_json)) {
|
|
Tomas Bzatek |
986ba7 |
+ json_free_object(discovery_json);
|
|
Tomas Bzatek |
986ba7 |
+ goto fail;
|
|
Tomas Bzatek |
986ba7 |
+ }
|
|
Tomas Bzatek |
986ba7 |
+ }
|
|
Tomas Bzatek |
986ba7 |
+ if (json_object_object_add(nbft_json, "discovery", discovery_array_json)) {
|
|
Tomas Bzatek |
986ba7 |
+ json_free_object(discovery_array_json);
|
|
Tomas Bzatek |
986ba7 |
+ goto fail;
|
|
Tomas Bzatek |
986ba7 |
+ }
|
|
Tomas Bzatek |
986ba7 |
+ }
|
|
Tomas Bzatek |
986ba7 |
+ return nbft_json;
|
|
Tomas Bzatek |
986ba7 |
+fail:
|
|
Tomas Bzatek |
986ba7 |
+ json_free_object(nbft_json);
|
|
Tomas Bzatek |
986ba7 |
+ return NULL;
|
|
Tomas Bzatek |
986ba7 |
+}
|
|
Tomas Bzatek |
986ba7 |
+
|
|
Tomas Bzatek |
986ba7 |
+static int json_show_nbfts(struct list_head *nbft_list, bool show_subsys,
|
|
Tomas Bzatek |
986ba7 |
+ bool show_hfi, bool show_discovery)
|
|
Tomas Bzatek |
986ba7 |
+{
|
|
Tomas Bzatek |
986ba7 |
+ struct json_object *nbft_json_array, *nbft_json;
|
|
Tomas Bzatek |
986ba7 |
+ struct nbft_file_entry *entry;
|
|
Tomas Bzatek |
986ba7 |
+
|
|
Tomas Bzatek |
986ba7 |
+ nbft_json_array = json_create_array();
|
|
Tomas Bzatek |
986ba7 |
+ if (!nbft_json_array)
|
|
Tomas Bzatek |
986ba7 |
+ return ENOMEM;
|
|
Tomas Bzatek |
986ba7 |
+
|
|
Tomas Bzatek |
986ba7 |
+ list_for_each(nbft_list, entry, node) {
|
|
Tomas Bzatek |
986ba7 |
+ nbft_json = nbft_to_json(entry->nbft, show_subsys, show_hfi, show_discovery);
|
|
Tomas Bzatek |
986ba7 |
+ if (!nbft_json)
|
|
Tomas Bzatek |
986ba7 |
+ goto fail;
|
|
Tomas Bzatek |
986ba7 |
+ if (json_object_array_add(nbft_json_array, nbft_json)) {
|
|
Tomas Bzatek |
986ba7 |
+ json_free_object(nbft_json);
|
|
Tomas Bzatek |
986ba7 |
+ goto fail;
|
|
Tomas Bzatek |
986ba7 |
+ }
|
|
Tomas Bzatek |
986ba7 |
+ }
|
|
Tomas Bzatek |
986ba7 |
+
|
|
Tomas Bzatek |
986ba7 |
+ json_print_object(nbft_json_array, NULL);
|
|
Tomas Bzatek |
986ba7 |
+ printf("\n");
|
|
Tomas Bzatek |
986ba7 |
+ json_free_object(nbft_json_array);
|
|
Tomas Bzatek |
986ba7 |
+ return 0;
|
|
Tomas Bzatek |
986ba7 |
+fail:
|
|
Tomas Bzatek |
986ba7 |
+ json_free_object(nbft_json_array);
|
|
Tomas Bzatek |
986ba7 |
+ return ENOMEM;
|
|
Tomas Bzatek |
986ba7 |
+}
|
|
Tomas Bzatek |
986ba7 |
+
|
|
Tomas Bzatek |
986ba7 |
+static void print_nbft_hfi_info(struct nbft_info *nbft)
|
|
Tomas Bzatek |
986ba7 |
+{
|
|
Tomas Bzatek |
986ba7 |
+ struct nbft_info_hfi **hfi;
|
|
Tomas Bzatek |
986ba7 |
+ unsigned int ip_width = 8, gw_width = 8, dns_width = 8;
|
|
Tomas Bzatek |
986ba7 |
+
|
|
Tomas Bzatek |
986ba7 |
+ hfi = nbft->hfi_list;
|
|
Tomas Bzatek |
986ba7 |
+ if (!hfi || !*hfi)
|
|
Tomas Bzatek |
986ba7 |
+ return;
|
|
Tomas Bzatek |
986ba7 |
+
|
|
Tomas Bzatek |
986ba7 |
+ for (; *hfi; hfi++) {
|
|
Tomas Bzatek |
986ba7 |
+ unsigned int len;
|
|
Tomas Bzatek |
986ba7 |
+
|
|
Tomas Bzatek |
986ba7 |
+ len = strlen((*hfi)->tcp_info.ipaddr);
|
|
Tomas Bzatek |
986ba7 |
+ if (len > ip_width)
|
|
Tomas Bzatek |
986ba7 |
+ ip_width = len;
|
|
Tomas Bzatek |
986ba7 |
+ len = strlen((*hfi)->tcp_info.gateway_ipaddr);
|
|
Tomas Bzatek |
986ba7 |
+ if (len > gw_width)
|
|
Tomas Bzatek |
986ba7 |
+ gw_width = len;
|
|
Tomas Bzatek |
986ba7 |
+ len = strlen((*hfi)->tcp_info.primary_dns_ipaddr);
|
|
Tomas Bzatek |
986ba7 |
+ if (len > dns_width)
|
|
Tomas Bzatek |
986ba7 |
+ dns_width = len;
|
|
Tomas Bzatek |
986ba7 |
+ }
|
|
Tomas Bzatek |
986ba7 |
+
|
|
Tomas Bzatek |
986ba7 |
+ printf("\nNBFT HFIs:\n\n");
|
|
Tomas Bzatek |
986ba7 |
+ printf("%-3.3s|%-4.4s|%-10.10s|%-17.17s|%-4.4s|%-*.*s|%-4.4s|%-*.*s|%-*.*s\n",
|
|
Tomas Bzatek |
986ba7 |
+ "Idx", "Trsp", "PCI Addr", "MAC Addr", "DHCP",
|
|
Tomas Bzatek |
986ba7 |
+ ip_width, ip_width, "IP Addr", "Mask",
|
|
Tomas Bzatek |
986ba7 |
+ gw_width, gw_width, "Gateway", dns_width, dns_width, "DNS");
|
|
Tomas Bzatek |
986ba7 |
+ printf("%-.3s+%-.4s+%-.10s+%-.17s+%-.4s+%-.*s+%-.4s+%-.*s+%-.*s\n",
|
|
Tomas Bzatek |
986ba7 |
+ dash, dash, dash, dash, dash, ip_width, dash, dash,
|
|
Tomas Bzatek |
986ba7 |
+ gw_width, dash, dns_width, dash);
|
|
Tomas Bzatek |
986ba7 |
+ for (hfi = nbft->hfi_list; *hfi; hfi++)
|
|
Tomas Bzatek |
986ba7 |
+ printf("%-3d|%-4.4s|%-10.10s|%-17.17s|%-4.4s|%-*.*s|%-4d|%-*.*s|%-*.*s\n",
|
|
Tomas Bzatek |
986ba7 |
+ (*hfi)->index,
|
|
Tomas Bzatek |
986ba7 |
+ (*hfi)->transport,
|
|
Tomas Bzatek |
986ba7 |
+ pci_sbdf_to_string((*hfi)->tcp_info.pci_sbdf),
|
|
Tomas Bzatek |
986ba7 |
+ mac_addr_to_string((*hfi)->tcp_info.mac_addr),
|
|
Tomas Bzatek |
986ba7 |
+ (*hfi)->tcp_info.dhcp_override ? "yes" : "no",
|
|
Tomas Bzatek |
986ba7 |
+ ip_width, ip_width, (*hfi)->tcp_info.ipaddr,
|
|
Tomas Bzatek |
986ba7 |
+ (*hfi)->tcp_info.subnet_mask_prefix,
|
|
Tomas Bzatek |
986ba7 |
+ gw_width, gw_width, (*hfi)->tcp_info.gateway_ipaddr,
|
|
Tomas Bzatek |
986ba7 |
+ dns_width, dns_width, (*hfi)->tcp_info.primary_dns_ipaddr);
|
|
Tomas Bzatek |
986ba7 |
+}
|
|
Tomas Bzatek |
986ba7 |
+
|
|
Tomas Bzatek |
986ba7 |
+static void print_nbft_discovery_info(struct nbft_info *nbft)
|
|
Tomas Bzatek |
986ba7 |
+{
|
|
Tomas Bzatek |
986ba7 |
+ struct nbft_info_discovery **disc;
|
|
Tomas Bzatek |
986ba7 |
+ unsigned int nqn_width = 20, uri_width = 12;
|
|
Tomas Bzatek |
986ba7 |
+
|
|
Tomas Bzatek |
986ba7 |
+ disc = nbft->discovery_list;
|
|
Tomas Bzatek |
986ba7 |
+ if (!disc || !*disc)
|
|
Tomas Bzatek |
986ba7 |
+ return;
|
|
Tomas Bzatek |
986ba7 |
+
|
|
Tomas Bzatek |
986ba7 |
+ for (; *disc; disc++) {
|
|
Tomas Bzatek |
986ba7 |
+ size_t len;
|
|
Tomas Bzatek |
986ba7 |
+
|
|
Tomas Bzatek |
986ba7 |
+ len = strlen((*disc)->uri);
|
|
Tomas Bzatek |
986ba7 |
+ if (len > uri_width)
|
|
Tomas Bzatek |
986ba7 |
+ uri_width = len;
|
|
Tomas Bzatek |
986ba7 |
+ len = strlen((*disc)->nqn);
|
|
Tomas Bzatek |
986ba7 |
+ if (len > nqn_width)
|
|
Tomas Bzatek |
986ba7 |
+ nqn_width = len;
|
|
Tomas Bzatek |
986ba7 |
+ }
|
|
Tomas Bzatek |
986ba7 |
+
|
|
Tomas Bzatek |
986ba7 |
+ printf("\nNBFT Discovery Controllers:\n\n");
|
|
Tomas Bzatek |
986ba7 |
+ printf("%-3.3s|%-*.*s|%-*.*s\n", "Idx", uri_width, uri_width, "URI",
|
|
Tomas Bzatek |
986ba7 |
+ nqn_width, nqn_width, "NQN");
|
|
Tomas Bzatek |
986ba7 |
+ printf("%-.3s+%-.*s+%-.*s\n", dash, uri_width, dash, nqn_width, dash);
|
|
Tomas Bzatek |
986ba7 |
+ for (disc = nbft->discovery_list; *disc; disc++)
|
|
Tomas Bzatek |
986ba7 |
+ printf("%-3d|%-*.*s|%-*.*s\n", (*disc)->index,
|
|
Tomas Bzatek |
986ba7 |
+ uri_width, uri_width, (*disc)->uri,
|
|
Tomas Bzatek |
986ba7 |
+ nqn_width, nqn_width, (*disc)->nqn);
|
|
Tomas Bzatek |
986ba7 |
+}
|
|
Tomas Bzatek |
986ba7 |
+
|
|
Tomas Bzatek |
986ba7 |
+#define HFIS_LEN 20
|
|
Tomas Bzatek |
986ba7 |
+static size_t print_hfis(const struct nbft_info_subsystem_ns *ss, char buf[HFIS_LEN])
|
|
Tomas Bzatek |
986ba7 |
+{
|
|
Tomas Bzatek |
986ba7 |
+ char hfi_buf[HFIS_LEN];
|
|
Tomas Bzatek |
986ba7 |
+ size_t len, ofs;
|
|
Tomas Bzatek |
986ba7 |
+ int i;
|
|
Tomas Bzatek |
986ba7 |
+
|
|
Tomas Bzatek |
986ba7 |
+ len = snprintf(hfi_buf, sizeof(hfi_buf), "%d", ss->hfis[0]->index);
|
|
Tomas Bzatek |
986ba7 |
+ for (i = 1; i < ss->num_hfis; i++) {
|
|
Tomas Bzatek |
986ba7 |
+ ofs = len;
|
|
Tomas Bzatek |
986ba7 |
+ len += snprintf(hfi_buf + ofs, sizeof(hfi_buf) - ofs, ",%d",
|
|
Tomas Bzatek |
986ba7 |
+ ss->hfis[i]->index);
|
|
Tomas Bzatek |
986ba7 |
+ /*
|
|
Tomas Bzatek |
986ba7 |
+ * If the list doesn't fit in HFIS_LEN characters,
|
|
Tomas Bzatek |
986ba7 |
+ * truncate and end with "..."
|
|
Tomas Bzatek |
986ba7 |
+ */
|
|
Tomas Bzatek |
986ba7 |
+ if (len >= sizeof(hfi_buf)) {
|
|
Tomas Bzatek |
986ba7 |
+ while (ofs < sizeof(hfi_buf) - 1)
|
|
Tomas Bzatek |
986ba7 |
+ hfi_buf[ofs++] = '.';
|
|
Tomas Bzatek |
986ba7 |
+ hfi_buf[ofs] = '\0';
|
|
Tomas Bzatek |
986ba7 |
+ len = sizeof(hfi_buf) - 1;
|
|
Tomas Bzatek |
986ba7 |
+ break;
|
|
Tomas Bzatek |
986ba7 |
+ }
|
|
Tomas Bzatek |
986ba7 |
+ }
|
|
Tomas Bzatek |
986ba7 |
+ if (buf)
|
|
Tomas Bzatek |
986ba7 |
+ memcpy(buf, hfi_buf, len + 1);
|
|
Tomas Bzatek |
986ba7 |
+ return len;
|
|
Tomas Bzatek |
986ba7 |
+}
|
|
Tomas Bzatek |
986ba7 |
+
|
|
Tomas Bzatek |
986ba7 |
+
|
|
Tomas Bzatek |
986ba7 |
+static void print_nbft_subsys_info(struct nbft_info *nbft)
|
|
Tomas Bzatek |
986ba7 |
+{
|
|
Tomas Bzatek |
986ba7 |
+ struct nbft_info_subsystem_ns **ss;
|
|
Tomas Bzatek |
986ba7 |
+ unsigned int nqn_width = 20, adr_width = 8, hfi_width = 4;
|
|
Tomas Bzatek |
986ba7 |
+
|
|
Tomas Bzatek |
986ba7 |
+ ss = nbft->subsystem_ns_list;
|
|
Tomas Bzatek |
986ba7 |
+ if (!ss || !*ss)
|
|
Tomas Bzatek |
986ba7 |
+ return;
|
|
Tomas Bzatek |
986ba7 |
+ for (; *ss; ss++) {
|
|
Tomas Bzatek |
986ba7 |
+ size_t len;
|
|
Tomas Bzatek |
986ba7 |
+
|
|
Tomas Bzatek |
986ba7 |
+ len = strlen((*ss)->subsys_nqn);
|
|
Tomas Bzatek |
986ba7 |
+ if (len > nqn_width)
|
|
Tomas Bzatek |
986ba7 |
+ nqn_width = len;
|
|
Tomas Bzatek |
986ba7 |
+ len = strlen((*ss)->traddr);
|
|
Tomas Bzatek |
986ba7 |
+ if (len > adr_width)
|
|
Tomas Bzatek |
986ba7 |
+ adr_width = len;
|
|
Tomas Bzatek |
986ba7 |
+ len = print_hfis(*ss, NULL);
|
|
Tomas Bzatek |
986ba7 |
+ if (len > hfi_width)
|
|
Tomas Bzatek |
986ba7 |
+ hfi_width = len;
|
|
Tomas Bzatek |
986ba7 |
+ }
|
|
Tomas Bzatek |
986ba7 |
+
|
|
Tomas Bzatek |
986ba7 |
+ printf("\nNBFT Subsystems:\n\n");
|
|
Tomas Bzatek |
986ba7 |
+ printf("%-3.3s|%-*.*s|%-4.4s|%-*.*s|%-5.5s|%-*.*s\n",
|
|
Tomas Bzatek |
986ba7 |
+ "Idx", nqn_width, nqn_width, "NQN",
|
|
Tomas Bzatek |
986ba7 |
+ "Trsp", adr_width, adr_width, "Address", "SvcId", hfi_width, hfi_width, "HFIs");
|
|
Tomas Bzatek |
986ba7 |
+ printf("%-.3s+%-.*s+%-.4s+%-.*s+%-.5s+%-.*s\n",
|
|
Tomas Bzatek |
986ba7 |
+ dash, nqn_width, dash, dash, adr_width, dash, dash, hfi_width, dash);
|
|
Tomas Bzatek |
986ba7 |
+ for (ss = nbft->subsystem_ns_list; *ss; ss++) {
|
|
Tomas Bzatek |
986ba7 |
+ char hfi_buf[HFIS_LEN];
|
|
Tomas Bzatek |
986ba7 |
+
|
|
Tomas Bzatek |
986ba7 |
+ print_hfis(*ss, hfi_buf);
|
|
Tomas Bzatek |
986ba7 |
+ printf("%-3d|%-*.*s|%-4.4s|%-*.*s|%-5.5s|%-*.*s\n",
|
|
Tomas Bzatek |
986ba7 |
+ (*ss)->index, nqn_width, nqn_width, (*ss)->subsys_nqn,
|
|
Tomas Bzatek |
986ba7 |
+ (*ss)->transport, adr_width, adr_width, (*ss)->traddr,
|
|
Tomas Bzatek |
986ba7 |
+ (*ss)->trsvcid, hfi_width, hfi_width, hfi_buf);
|
|
Tomas Bzatek |
986ba7 |
+ }
|
|
Tomas Bzatek |
986ba7 |
+}
|
|
Tomas Bzatek |
986ba7 |
+
|
|
Tomas Bzatek |
986ba7 |
+static void normal_show_nbft(struct nbft_info *nbft, bool show_subsys,
|
|
Tomas Bzatek |
986ba7 |
+ bool show_hfi, bool show_discovery)
|
|
Tomas Bzatek |
986ba7 |
+{
|
|
Tomas Bzatek |
986ba7 |
+ printf("%s:\n", nbft->filename);
|
|
Tomas Bzatek |
986ba7 |
+ if ((!nbft->hfi_list || !*nbft->hfi_list) &&
|
|
Tomas Bzatek |
986ba7 |
+ (!nbft->security_list || !*nbft->security_list) &&
|
|
Tomas Bzatek |
986ba7 |
+ (!nbft->discovery_list || !*nbft->discovery_list) &&
|
|
Tomas Bzatek |
986ba7 |
+ (!nbft->subsystem_ns_list || !*nbft->subsystem_ns_list))
|
|
Tomas Bzatek |
986ba7 |
+ printf("(empty)\n");
|
|
Tomas Bzatek |
986ba7 |
+ else {
|
|
Tomas Bzatek |
986ba7 |
+ if (show_subsys)
|
|
Tomas Bzatek |
986ba7 |
+ print_nbft_subsys_info(nbft);
|
|
Tomas Bzatek |
986ba7 |
+ if (show_hfi)
|
|
Tomas Bzatek |
986ba7 |
+ print_nbft_hfi_info(nbft);
|
|
Tomas Bzatek |
986ba7 |
+ if (show_discovery)
|
|
Tomas Bzatek |
986ba7 |
+ print_nbft_discovery_info(nbft);
|
|
Tomas Bzatek |
986ba7 |
+ }
|
|
Tomas Bzatek |
986ba7 |
+}
|
|
Tomas Bzatek |
986ba7 |
+
|
|
Tomas Bzatek |
986ba7 |
+static void normal_show_nbfts(struct list_head *nbft_list, bool show_subsys,
|
|
Tomas Bzatek |
986ba7 |
+ bool show_hfi, bool show_discovery)
|
|
Tomas Bzatek |
986ba7 |
+{
|
|
Tomas Bzatek |
986ba7 |
+ bool not_first = false;
|
|
Tomas Bzatek |
986ba7 |
+ struct nbft_file_entry *entry;
|
|
Tomas Bzatek |
986ba7 |
+
|
|
Tomas Bzatek |
986ba7 |
+ list_for_each(nbft_list, entry, node) {
|
|
Tomas Bzatek |
986ba7 |
+ if (not_first)
|
|
Tomas Bzatek |
986ba7 |
+ printf("\n");
|
|
Tomas Bzatek |
986ba7 |
+ normal_show_nbft(entry->nbft, show_subsys, show_hfi, show_discovery);
|
|
Tomas Bzatek |
986ba7 |
+ not_first = true;
|
|
Tomas Bzatek |
986ba7 |
+ }
|
|
Tomas Bzatek |
986ba7 |
+}
|
|
Tomas Bzatek |
986ba7 |
+
|
|
Tomas Bzatek |
986ba7 |
+int show_nbft(int argc, char **argv, struct command *cmd, struct plugin *plugin)
|
|
Tomas Bzatek |
986ba7 |
+{
|
|
Tomas Bzatek |
986ba7 |
+ const char *desc = "Display contents of the ACPI NBFT files.";
|
|
Tomas Bzatek |
986ba7 |
+ struct list_head nbft_list;
|
|
Tomas Bzatek |
986ba7 |
+ char *format = "normal";
|
|
Tomas Bzatek |
986ba7 |
+ char *nbft_path = NBFT_SYSFS_PATH;
|
|
Tomas Bzatek |
986ba7 |
+ enum nvme_print_flags flags = -1;
|
|
Tomas Bzatek |
986ba7 |
+ int ret;
|
|
Tomas Bzatek |
986ba7 |
+ bool show_subsys = false, show_hfi = false, show_discovery = false;
|
|
Tomas Bzatek |
986ba7 |
+
|
|
Tomas Bzatek |
986ba7 |
+ OPT_ARGS(opts) = {
|
|
Tomas Bzatek |
986ba7 |
+ OPT_FMT("output-format", 'o', &format, "Output format: normal|json"),
|
|
Tomas Bzatek |
986ba7 |
+ OPT_FLAG("subsystem", 's', &show_subsys, "show NBFT subsystems"),
|
|
Tomas Bzatek |
986ba7 |
+ OPT_FLAG("hfi", 'H', &show_hfi, "show NBFT HFIs"),
|
|
Tomas Bzatek |
986ba7 |
+ OPT_FLAG("discovery", 'd', &show_discovery, "show NBFT discovery controllers"),
|
|
Tomas Bzatek |
986ba7 |
+ OPT_STRING("nbft-path", 0, "STR", &nbft_path, "user-defined path for NBFT tables"),
|
|
Tomas Bzatek |
986ba7 |
+ OPT_END()
|
|
Tomas Bzatek |
986ba7 |
+ };
|
|
Tomas Bzatek |
986ba7 |
+
|
|
Tomas Bzatek |
986ba7 |
+ ret = argconfig_parse(argc, argv, desc, opts);
|
|
Tomas Bzatek |
986ba7 |
+ if (ret)
|
|
Tomas Bzatek |
986ba7 |
+ return ret;
|
|
Tomas Bzatek |
986ba7 |
+
|
|
Tomas Bzatek |
986ba7 |
+ if (!(show_subsys || show_hfi || show_discovery))
|
|
Tomas Bzatek |
986ba7 |
+ show_subsys = show_hfi = show_discovery = true;
|
|
Tomas Bzatek |
986ba7 |
+
|
|
Tomas Bzatek |
986ba7 |
+ if (!strcmp(format, ""))
|
|
Tomas Bzatek |
986ba7 |
+ flags = -1;
|
|
Tomas Bzatek |
986ba7 |
+ else if (!strcmp(format, "normal"))
|
|
Tomas Bzatek |
986ba7 |
+ flags = NORMAL;
|
|
Tomas Bzatek |
986ba7 |
+ else if (!strcmp(format, "json"))
|
|
Tomas Bzatek |
986ba7 |
+ flags = JSON;
|
|
Tomas Bzatek |
986ba7 |
+ else
|
|
Tomas Bzatek |
986ba7 |
+ return EINVAL;
|
|
Tomas Bzatek |
986ba7 |
+
|
|
Tomas Bzatek |
986ba7 |
+ list_head_init(&nbft_list);
|
|
Tomas Bzatek |
986ba7 |
+ ret = read_nbft_files(&nbft_list, nbft_path);
|
|
Tomas Bzatek |
986ba7 |
+ if (!ret) {
|
|
Tomas Bzatek |
986ba7 |
+ if (flags == NORMAL)
|
|
Tomas Bzatek |
986ba7 |
+ normal_show_nbfts(&nbft_list, show_subsys, show_hfi, show_discovery);
|
|
Tomas Bzatek |
986ba7 |
+ else if (flags == JSON)
|
|
Tomas Bzatek |
986ba7 |
+ ret = json_show_nbfts(&nbft_list, show_subsys, show_hfi, show_discovery);
|
|
Tomas Bzatek |
986ba7 |
+ free_nbfts(&nbft_list);
|
|
Tomas Bzatek |
986ba7 |
+ }
|
|
Tomas Bzatek |
986ba7 |
+ return ret;
|
|
Tomas Bzatek |
986ba7 |
+}
|
|
Tomas Bzatek |
986ba7 |
diff --git a/plugins/nbft/nbft-plugin.h b/plugins/nbft/nbft-plugin.h
|
|
Tomas Bzatek |
986ba7 |
new file mode 100644
|
|
Tomas Bzatek |
986ba7 |
index 00000000..018349d9
|
|
Tomas Bzatek |
986ba7 |
--- /dev/null
|
|
Tomas Bzatek |
986ba7 |
+++ b/plugins/nbft/nbft-plugin.h
|
|
Tomas Bzatek |
986ba7 |
@@ -0,0 +1,18 @@
|
|
Tomas Bzatek |
986ba7 |
+/* SPDX-License-Identifier: GPL-2.0-or-later */
|
|
Tomas Bzatek |
986ba7 |
+#undef CMD_INC_FILE
|
|
Tomas Bzatek |
986ba7 |
+#define CMD_INC_FILE plugins/nbft/nbft-plugin
|
|
Tomas Bzatek |
986ba7 |
+
|
|
Tomas Bzatek |
986ba7 |
+#if !defined(NBFT) || defined(CMD_HEADER_MULTI_READ)
|
|
Tomas Bzatek |
986ba7 |
+#define NBFT
|
|
Tomas Bzatek |
986ba7 |
+
|
|
Tomas Bzatek |
986ba7 |
+#include "cmd.h"
|
|
Tomas Bzatek |
986ba7 |
+
|
|
Tomas Bzatek |
986ba7 |
+PLUGIN(NAME("nbft", "ACPI NBFT table extensions", NVME_VERSION),
|
|
Tomas Bzatek |
986ba7 |
+ COMMAND_LIST(
|
|
Tomas Bzatek |
986ba7 |
+ ENTRY("show", "Show contents of ACPI NBFT tables", show_nbft)
|
|
Tomas Bzatek |
986ba7 |
+ )
|
|
Tomas Bzatek |
986ba7 |
+);
|
|
Tomas Bzatek |
986ba7 |
+
|
|
Tomas Bzatek |
986ba7 |
+#endif
|
|
Tomas Bzatek |
986ba7 |
+
|
|
Tomas Bzatek |
986ba7 |
+#include "define_cmd.h"
|
|
Tomas Bzatek |
986ba7 |
--
|
|
Tomas Bzatek |
986ba7 |
2.39.2
|
|
Tomas Bzatek |
986ba7 |
|