Compare commits

..

No commits in common. 'i9c-beta' and 'c9' have entirely different histories.
i9c-beta ... c9

2
.gitignore vendored

@ -1 +1 @@
SOURCES/nvme-cli-2.9.1.tar.gz
SOURCES/nvme-cli-2.4.tar.gz

@ -1 +1 @@
33eaae0a2334451553952ac701f8568a52fd2a98 SOURCES/nvme-cli-2.9.1.tar.gz
6583ee6fa9f715cbff11dd40aae7417e9e791691 SOURCES/nvme-cli-2.4.tar.gz

@ -1,20 +0,0 @@
diff --git a/fabrics.c b/fabrics.c
index 871c20ede093..90c3e5d6c602 100644
--- a/fabrics.c
+++ b/fabrics.c
@@ -643,6 +643,7 @@ char *nvmf_hostid_from_hostnqn(const char *hostnqn)
void nvmf_check_hostid_and_hostnqn(const char *hostid, const char *hostnqn, unsigned int verbose)
{
+#if 0
_cleanup_free_ char *hostid_from_file = NULL;
_cleanup_free_ char *hostid_from_hostnqn = NULL;
@@ -665,6 +666,7 @@ void nvmf_check_hostid_and_hostnqn(const char *hostid, const char *hostnqn, unsi
fprintf(stderr,
"warning: use hostid which does not match uuid in hostnqn\n");
}
+#endif
}
int nvmf_discover(const char *desc, int argc, char **argv, bool connect)

@ -0,0 +1,75 @@
From 34c197e0ac2d57734ab775f00b2d0758aca7b82f Mon Sep 17 00:00:00 2001
From: John Meneghini <jmeneghi@redhat.com>
Date: Fri, 14 Apr 2023 10:53:58 -0400
Subject: [PATCH] nbft: make lookup_ctrl function public
To prepare for the addition of nbft functionality fixup the fabrics
declarations.
Signed-off-by: John Meneghini <jmeneghi@redhat.com>
---
fabrics.c | 12 ++----------
fabrics.h | 10 ++++++++++
2 files changed, 12 insertions(+), 10 deletions(-)
diff --git a/fabrics.c b/fabrics.c
index f8078e59..80827b16 100644
--- a/fabrics.c
+++ b/fabrics.c
@@ -43,6 +43,7 @@
#include "libnvme.h"
#include "nvme-print.h"
#include "nvme-print-json.h"
+#include "fabrics.h"
#define PATH_NVMF_DISC SYSCONFDIR "/nvme/discovery.conf"
#define PATH_NVMF_CONFIG SYSCONFDIR "/nvme/config.json"
@@ -110,15 +111,6 @@ static const char *nvmf_config_file = "Use specified JSON configuration file or
OPT_FLAG("data-digest", 'G', &c.data_digest, nvmf_data_digest), \
OPT_FLAG("tls", 0, &c.tls, nvmf_tls) \
-struct tr_config {
- const char *subsysnqn;
- const char *transport;
- const char *traddr;
- const char *host_traddr;
- const char *host_iface;
- const char *trsvcid;
-};
-
/*
* Compare two C strings and handle NULL pointers gracefully.
* If either of the two strings is NULL, return 0
@@ -202,7 +194,7 @@ static nvme_ctrl_t lookup_discovery_ctrl(nvme_root_t r, struct tr_config *trcfg)
return __lookup_ctrl(r, trcfg, disc_ctrl_config_match);
}
-static nvme_ctrl_t lookup_ctrl(nvme_root_t r, struct tr_config *trcfg)
+nvme_ctrl_t lookup_ctrl(nvme_root_t r, struct tr_config *trcfg)
{
return __lookup_ctrl(r, trcfg, ctrl_config_match);
}
diff --git a/fabrics.h b/fabrics.h
index d1e16fc5..02cebf5d 100644
--- a/fabrics.h
+++ b/fabrics.h
@@ -2,6 +2,16 @@
#ifndef _FABRICS_H
#define _FABRICS_H
+struct tr_config {
+ const char *subsysnqn;
+ const char *transport;
+ const char *traddr;
+ const char *host_traddr;
+ const char *host_iface;
+ const char *trsvcid;
+};
+
+extern nvme_ctrl_t lookup_ctrl(nvme_root_t r, struct tr_config *trcfg);
extern int nvmf_discover(const char *desc, int argc, char **argv, bool connect);
extern int nvmf_connect(const char *desc, int argc, char **argv);
extern int nvmf_disconnect(const char *desc, int argc, char **argv);
--
2.39.1

@ -0,0 +1,451 @@
From a71a08532b5f06ee19ee2ff118a23cec4ecb6719 Mon Sep 17 00:00:00 2001
From: Stuart Hayes <stuart_hayes@dell.com>
Date: Wed, 15 Jun 2022 11:42:50 -0500
Subject: [PATCH] nbft: added NBFT v1.0 table support
Added support for parsing the contents of the NBFT table (per NVMe-oF
boot specification v1.0) with the connect-all and discover commands.
nvme discover/connect-all --nbft ignore /etc/nvme config and use NBFT tables
nvme discover/connect-all --no-nbft ignore NBFT tables and use /etc/nvme config
nvme discover/connect-all --nbft-path=<STR> user-defined path for NBFT tables
Signed-off-by: Stuart Hayes <stuart_hayes@dell.com>
Signed-off-by: Martin Belanger <martin.belanger@dell.com>
Use the new nbft public API.
Signed-off-by: Tomas Bzatek <tbzatek@redhat.com>
Signed-off-by: Martin Wilck <mwilck@suse.com>
Signed-off-by: John Meneghini <jmeneghi@redhat.com>
---
Documentation/nvme-connect-all.txt | 25 ++++
Documentation/nvme-discover.txt | 27 +++-
fabrics.c | 17 +++
meson.build | 1 +
nbft.c | 202 +++++++++++++++++++++++++++++
nbft.h | 19 +++
6 files changed, 290 insertions(+), 1 deletion(-)
create mode 100644 nbft.c
create mode 100644 nbft.h
diff --git a/Documentation/nvme-connect-all.txt b/Documentation/nvme-connect-all.txt
index 44bb4f94..cbb7ca6c 100644
--- a/Documentation/nvme-connect-all.txt
+++ b/Documentation/nvme-connect-all.txt
@@ -35,6 +35,9 @@ SYNOPSIS
[--tls ]
[--quiet | -S]
[--dump-config | -O]
+ [--nbft]
+ [--no-nbft]
+ [--nbft-path=<STR>]
DESCRIPTION
-----------
@@ -198,6 +201,16 @@ OPTIONS
--dump-config::
Print out resulting JSON configuration file to stdout.
+--nbft::
+ Only look at NBFT tables
+
+--no-nbft::
+ Do not look at NBFT tables
+
+--nbft-path=<STR>::
+ Use a user-defined path to the NBFT tables
+
+
EXAMPLES
--------
@@ -210,6 +223,18 @@ the RDMA network. Port 4420 is used by default:
--hostnqn=host1-rogue-nqn
------------
+
+* Issue a 'nvme connect-all' command using the default system defined NBFT tables:
++
+-----------
+# nvme connect-all --nbft
+------------
++
+* Issue a 'nvme connect-all' command with a user-defined path for the NBFT table:
++
+-----------
+# nvme connet-all --nbft-path=/sys/firmware/acpi/tables/NBFT1
+------------
++
* Issue a 'nvme connect-all' command using a @SYSCONFDIR@/nvme/discovery.conf file:
+
-----------
diff --git a/Documentation/nvme-discover.txt b/Documentation/nvme-discover.txt
index d4df75c2..b040c688 100644
--- a/Documentation/nvme-discover.txt
+++ b/Documentation/nvme-discover.txt
@@ -37,6 +37,9 @@ SYNOPSIS
[--dump-config | -O]
[--output-format=<fmt> | -o <fmt>]
[--force]
+ [--nbft]
+ [--no-nbft]
+ [--nbft-path=<STR>]
DESCRIPTION
-----------
@@ -68,7 +71,7 @@ Note that the base NVMe specification defines the NQN (NVMe Qualified
Name) format which an NVMe endpoint (device, subsystem, etc) must
follow to guarantee a unique name under the NVMe standard.
In particular, the Host NQN uniquely identifies the NVMe Host, and
-may be used by the the Discovery Controller to control what NVMe Target
+may be used by the Discovery Controller to control what NVMe Target
resources are allocated to the NVMe Host for a connection.
A Discovery Controller has it's own NQN defined in the NVMe-over-Fabrics
@@ -229,6 +232,16 @@ OPTIONS
Combined with --persistent flag, always create new
persistent discovery connection.
+--nbft::
+ Only look at NBFT tables
+
+--no-nbft::
+ Do not look at NBFT tables
+
+--nbft-path=<STR>::
+ Use a user-defined path to the NBFT tables
+
+
EXAMPLES
--------
* Query the Discover Controller with IP4 address 192.168.1.3 for all
@@ -240,6 +253,18 @@ Port 4420 is used by default:
--hostnqn=host1-rogue-nqn
------------
+
+* Issue a 'nvme discover' command using the default system defined NBFT tables:
++
+-----------
+# nvme discover --nbft
+------------
++
+* Issue a 'nvme discover' command with a user-defined path for the NBFT table:
++
+-----------
+# nvme discover --nbft-path=/sys/firmware/acpi/tables/NBFT1
+------------
++
* Issue a 'nvme discover' command using a @SYSCONFDIR@/nvme/discovery.conf file:
+
-----------
diff --git a/fabrics.c b/fabrics.c
index 80827b16..0edbd299 100644
--- a/fabrics.c
+++ b/fabrics.c
@@ -40,6 +40,7 @@
#include "common.h"
#include "nvme.h"
+#include "nbft.h"
#include "libnvme.h"
#include "nvme-print.h"
#include "nvme-print-json.h"
@@ -710,6 +711,7 @@ int nvmf_discover(const char *desc, int argc, char **argv, bool connect)
{
char *subsysnqn = NVME_DISC_SUBSYS_NAME;
char *hostnqn = NULL, *hostid = NULL, *hostkey = NULL;
+ char *hostnqn_arg, *hostid_arg;
char *transport = NULL, *traddr = NULL, *trsvcid = NULL;
char *config_file = PATH_NVMF_CONFIG;
char *hnqn = NULL, *hid = NULL;
@@ -724,6 +726,8 @@ int nvmf_discover(const char *desc, int argc, char **argv, bool connect)
char *device = NULL;
bool force = false;
bool json_config = false;
+ bool nbft = false, nonbft = false;
+ char *nbft_path = NBFT_SYSFS_PATH;
OPT_ARGS(opts) = {
OPT_STRING("device", 'd', "DEV", &device, "use existing discovery controller device"),
@@ -736,6 +740,9 @@ int nvmf_discover(const char *desc, int argc, char **argv, bool connect)
OPT_INCR("verbose", 'v', &verbose, "Increase logging verbosity"),
OPT_FLAG("dump-config", 'O', &dump_config, "Dump configuration file to stdout"),
OPT_FLAG("force", 0, &force, "Force persistent discovery controller creation"),
+ OPT_FLAG("nbft", 0, &nbft, "Only look at NBFT tables"),
+ OPT_FLAG("no-nbft", 0, &nonbft, "Do not look at NBFT tables"),
+ OPT_STRING("nbft-path", 0, "STR", &nbft_path, "user-defined path for NBFT tables"),
OPT_END()
};
@@ -768,6 +775,8 @@ int nvmf_discover(const char *desc, int argc, char **argv, bool connect)
if (!nvme_read_config(r, config_file))
json_config = true;
+ hostnqn_arg = hostnqn;
+ hostid_arg = hostid;
if (!hostnqn)
hostnqn = hnqn = nvmf_hostnqn_from_file();
if (!hostnqn)
@@ -789,6 +798,14 @@ int nvmf_discover(const char *desc, int argc, char **argv, bool connect)
nvme_host_set_dhchap_key(h, hostkey);
if (!device && !transport && !traddr) {
+ if (!nonbft)
+ discover_from_nbft(r, hostnqn_arg, hostid_arg,
+ hostnqn, hostid, desc, connect,
+ &cfg, nbft_path, flags, verbose);
+
+ if (nbft)
+ goto out_free;
+
if (json_config)
ret = discover_from_json_config_file(r, h, desc,
connect, &cfg,
diff --git a/meson.build b/meson.build
index 43ce5f9b..7ec357a9 100644
--- a/meson.build
+++ b/meson.build
@@ -240,6 +240,7 @@ incdir = include_directories(['ccan'])
################################################################################
sources = [
+ 'nbft.c',
'fabrics.c',
'nvme.c',
'nvme-models.c',
diff --git a/nbft.c b/nbft.c
new file mode 100644
index 00000000..14347287
--- /dev/null
+++ b/nbft.c
@@ -0,0 +1,202 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+
+#include <errno.h>
+#include <stdio.h>
+#include <fnmatch.h>
+
+#include "nvme.h"
+#include "nbft.h"
+#include "libnvme.h"
+#include "fabrics.h"
+
+#define NBFT_SYSFS_FILENAME "NBFT*"
+
+static void print_connect_msg(nvme_ctrl_t c)
+{
+ printf("device: %s\n", nvme_ctrl_get_name(c));
+}
+
+static void json_connect_msg(nvme_ctrl_t c)
+{
+ struct json_object *root;
+
+ root = json_create_object();
+ json_object_add_value_string(root, "device", nvme_ctrl_get_name(c));
+
+ json_print_object(root, NULL);
+ printf("\n");
+ json_free_object(root);
+}
+
+int nbft_filter(const struct dirent *dent)
+{
+ return !fnmatch(NBFT_SYSFS_FILENAME, dent->d_name, FNM_PATHNAME);
+}
+
+int read_nbft_files(struct list_head *nbft_list, char *path)
+{
+ struct dirent **dent;
+ char filename[PATH_MAX];
+ int i, count, ret;
+ struct nbft_file_entry *entry;
+ struct nbft_info *nbft;
+
+ count = scandir(path, &dent, nbft_filter, NULL);
+ if (count < 0) {
+ fprintf(stderr, "Failed to open %s.\n", path);
+ return -1;
+ }
+
+ for (i = 0; i < count; i++) {
+ snprintf(filename, sizeof(filename), "%s/%s", path, dent[i]->d_name);
+ ret = nvme_nbft_read(&nbft, filename);
+ if (!ret) {
+ entry = calloc(1, sizeof(*entry));
+ entry->nbft = nbft;
+ list_add_tail(nbft_list, &entry->node);
+ }
+ free(dent[i]);
+ }
+ free(dent);
+ return 0;
+}
+
+void free_nbfts(struct list_head *nbft_list)
+{
+ struct nbft_file_entry *entry;
+
+ while ((entry = list_pop(nbft_list, struct nbft_file_entry, node))) {
+ nvme_nbft_free(entry->nbft);
+ free(entry);
+ }
+}
+
+int discover_from_nbft(nvme_root_t r, char *hostnqn_arg, char *hostid_arg,
+ char *hostnqn_sys, char *hostid_sys,
+ const char *desc, bool connect,
+ const struct nvme_fabrics_config *cfg, char *nbft_path,
+ enum nvme_print_flags flags, bool verbose)
+{
+ char *hostnqn = NULL, *hostid = NULL, *host_traddr = NULL;
+ nvme_host_t h;
+ nvme_ctrl_t c;
+ int ret, i;
+ struct list_head nbft_list;
+ struct nbft_file_entry *entry;
+ struct nbft_info_subsystem_ns **ss;
+ struct nbft_info_hfi *hfi;
+
+ if (!connect)
+ /* to do: print discovery-type info from NBFT tables */
+ return 0;
+
+ list_head_init(&nbft_list);
+ ret = read_nbft_files(&nbft_list, nbft_path);
+ if (ret)
+ goto out_free_2;
+
+ list_for_each(&nbft_list, entry, node)
+ for (ss = entry->nbft->subsystem_ns_list; ss && *ss; ss++)
+ for (i = 0; i < (*ss)->num_hfis; i++) {
+ nvme_ctrl_t cl;
+
+ hfi = (*ss)->hfis[i];
+ if (hostnqn_arg)
+ hostnqn = hostnqn_arg;
+ else {
+ hostnqn = entry->nbft->host.nqn;
+ if (!hostnqn)
+ hostnqn = hostnqn_sys;
+ }
+
+ if (hostid_arg)
+ hostid = hostid_arg;
+ else if (*entry->nbft->host.id) {
+ hostid = (char *)util_uuid_to_string(entry->nbft->host.id);
+ if (!hostid)
+ hostid = hostid_sys;
+ }
+
+ h = nvme_lookup_host(r, hostnqn, hostid);
+ if (!h) {
+ errno = ENOMEM;
+ goto out_free;
+ }
+
+ if (!cfg->host_traddr) {
+ host_traddr = NULL;
+ if (!strncmp((*ss)->transport, "tcp", 3))
+ host_traddr = hfi->tcp_info.ipaddr;
+ }
+
+ struct tr_config trcfg = {
+ .subsysnqn = (*ss)->subsys_nqn,
+ .transport = (*ss)->transport,
+ .traddr = (*ss)->traddr,
+ .host_traddr = host_traddr,
+ .host_iface = NULL,
+ .trsvcid = (*ss)->trsvcid,
+ };
+
+ /* Already connected ? */
+ cl = lookup_ctrl(r, &trcfg);
+ if (cl && nvme_ctrl_get_name(cl))
+ continue;
+
+ c = nvme_create_ctrl(r, (*ss)->subsys_nqn, (*ss)->transport,
+ (*ss)->traddr, host_traddr, NULL,
+ (*ss)->trsvcid);
+ if (!c) {
+ errno = ENOMEM;
+ goto out_free;
+ }
+
+ errno = 0;
+ ret = nvmf_add_ctrl(h, c, cfg);
+
+ /*
+ * With TCP/DHCP, it can happen that the OS
+ * obtains a different local IP address than the
+ * firmware had. Retry without host_traddr.
+ */
+ if (ret == -1 && errno == ENVME_CONNECT_WRITE &&
+ !strcmp((*ss)->transport, "tcp") &&
+ strlen(hfi->tcp_info.dhcp_server_ipaddr) > 0) {
+ nvme_free_ctrl(c);
+
+ trcfg.host_traddr = NULL;
+ cl = lookup_ctrl(r, &trcfg);
+ if (cl && nvme_ctrl_get_name(cl))
+ continue;
+
+ c = nvme_create_ctrl(r, (*ss)->subsys_nqn, (*ss)->transport,
+ (*ss)->traddr,
+ NULL, NULL, (*ss)->trsvcid);
+ if (!c) {
+ errno = ENOMEM;
+ goto out_free;
+ }
+ errno = 0;
+ ret = nvmf_add_ctrl(h, c, cfg);
+ if (ret == 0 && verbose >= 1)
+ fprintf(stderr,
+ "connect with host_traddr=\"%s\" failed, success after omitting host_traddr\n",
+ host_traddr);
+ }
+
+ if (ret)
+ fprintf(stderr, "no controller found\n");
+ else {
+ if (flags == NORMAL)
+ print_connect_msg(c);
+ else if (flags == JSON)
+ json_connect_msg(c);
+ }
+out_free:
+ if (errno == ENOMEM)
+ goto out_free_2;
+ }
+out_free_2:
+ free_nbfts(&nbft_list);
+ return errno;
+}
diff --git a/nbft.h b/nbft.h
new file mode 100644
index 00000000..0e09733f
--- /dev/null
+++ b/nbft.h
@@ -0,0 +1,19 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+
+#include <ccan/list/list.h>
+
+#define NBFT_SYSFS_PATH "/sys/firmware/acpi/tables"
+
+struct nbft_file_entry {
+ struct list_node node;
+ struct nbft_info *nbft;
+};
+
+int read_nbft_files(struct list_head *nbft_list, char *path);
+void free_nbfts(struct list_head *nbft_list);
+
+extern int discover_from_nbft(nvme_root_t r, char *hostnqn_arg, char *hostid_arg,
+ char *hostnqn_sys, char *hostid_sys,
+ const char *desc, bool connect,
+ const struct nvme_fabrics_config *cfg, char *nbft_path,
+ enum nvme_print_flags flags, bool verbose);
--
2.39.1

@ -1,76 +0,0 @@
From 42f788edccb954fe8b54c43809523e603c99f63c Mon Sep 17 00:00:00 2001
From: Maurizio Lombardi <mlombard@redhat.com>
Date: Wed, 22 May 2024 15:06:18 +0200
Subject: [PATCH] nvme: telemetry: report the correct error if the ioctl()
fails.
It's wrong to assume that if the ioctl() returns a non-zero number
then the errno variable is set.
The ioctl() might return an NVMe Status error to inform the caller
that the requested log page is not supported, in that case errno is left
untouched.
The original code didn't handle this case and returned "-errno" even when
the latter was zero. The caller interpreted this as a successful operation
and this might lead to improperly dereferencing the log page pointer.
$ nvme telemetry-log /dev/nvme0 --output-file=telemetry_log.bin
ERROR: get_telemetry_log: : write failed with error : Bad address
Fix this bug by returning the NVMe status if errno is zero:
$ nvme telemetry-log /dev/nvme0 --output-file=telemetry_log.bin
NVMe status: Invalid Log Page: The log page indicated is invalid(0x109)
Failed to acquire telemetry log 265!
Signed-off-by: Maurizio Lombardi <mlombard@redhat.com>
---
nvme.c | 18 ++++++++++++++----
1 file changed, 14 insertions(+), 4 deletions(-)
diff --git a/nvme.c b/nvme.c
index d722b91e5ed8..226413bc0eda 100644
--- a/nvme.c
+++ b/nvme.c
@@ -717,7 +717,10 @@ static int get_log_telemetry_ctrl(struct nvme_dev *dev, bool rae, size_t size,
err = nvme_cli_get_log_telemetry_ctrl(dev, rae, 0, size, log);
if (err) {
free(log);
- return -errno;
+ if (errno)
+ return -errno;
+ else
+ return err;
}
*buf = log;
@@ -737,7 +740,10 @@ static int get_log_telemetry_host(struct nvme_dev *dev, size_t size,
err = nvme_cli_get_log_telemetry_host(dev, 0, size, log);
if (err) {
free(log);
- return -errno;
+ if (errno)
+ return -errno;
+ else
+ return err;
}
*buf = log;
@@ -757,8 +763,12 @@ static int __create_telemetry_log_host(struct nvme_dev *dev,
return -ENOMEM;
err = nvme_cli_get_log_create_telemetry_host(dev, log);
- if (err)
- return -errno;
+ if (err) {
+ if (errno)
+ return -errno;
+ else
+ return err;
+ }
err = parse_telemetry_da(dev, da, log, size);
if (err)
--
2.43.0

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

@ -1,63 +0,0 @@
From fac45ce03315479b0d30e71316e669d9d4ffb31c Mon Sep 17 00:00:00 2001
From: Greg Joyce <gjoyce@linux.ibm.com>
Date: Fri, 10 May 2024 14:23:11 -0500
Subject: [PATCH] sed: only re-read partition table after unlock.
The partition table was being re-read after both lock and
unlock operations. The re-read would fail with an error
message after a lock since the partition was no longer readable.
Signed-off-by: Greg Joyce <gjoyce@linux.ibm.com>
---
plugins/sed/sedopal_cmd.c | 27 ++++++++++++++-------------
1 file changed, 14 insertions(+), 13 deletions(-)
diff --git a/plugins/sed/sedopal_cmd.c b/plugins/sed/sedopal_cmd.c
index 21ebd360c219..221f62b15186 100644
--- a/plugins/sed/sedopal_cmd.c
+++ b/plugins/sed/sedopal_cmd.c
@@ -251,8 +251,21 @@ int sedopal_cmd_lock(int fd)
*/
int sedopal_cmd_unlock(int fd)
{
+ int rc;
+
+ rc = sedopal_lock_unlock(fd, OPAL_RW);
+
+ /*
+ * If the unlock was successful, force a re-read of the
+ * partition table. Return rc of unlock operation.
+ */
+ if (rc == 0) {
+ if (ioctl(fd, BLKRRPART, 0) != 0)
+ fprintf(stderr,
+ "Warning: failed re-reading partition\n");
+ }
- return sedopal_lock_unlock(fd, OPAL_RW);
+ return rc;
}
/*
@@ -275,18 +288,6 @@ int sedopal_lock_unlock(int fd, int lock_state)
if (rc != 0)
fprintf(stderr,
"Error: failed locking or unlocking - %d\n", rc);
-
- /*
- * If the unlock was successful, force a re-read of the
- * partition table.
- */
- if (rc == 0) {
- rc = ioctl(fd, BLKRRPART, 0);
- if (rc != 0)
- fprintf(stderr,
- "Error: failed re-reading partition\n");
- }
-
return rc;
}
--
2.43.0

@ -0,0 +1,35 @@
From e1afeffcbb78e252bbb0d21d2f4ed0fffeb59105 Mon Sep 17 00:00:00 2001
From: Maurizio Lombardi <mlombard@redhat.com>
Date: Tue, 23 May 2023 15:08:40 +0200
Subject: [PATCH] Revert "nvme: Masks SSTAT in sanize-log output"
The NVME_SANITIZE_SSTAT_STATUS_MASK is used to mask the
3 least significant bits (representing the status of the most recent
sanitize operation) of the SSTAT field.
The SSTAT field is 16 bits wide and contains other information too, such
as the Global Data Erased bit and the number of completed passes.
Revert this commit so nvme-cli will print the entire SSTAT field
This reverts commit 7092ff55c5d9017231a68fa4dbb9a37b42d61d61.
---
nvme-print.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/nvme-print.c b/nvme-print.c
index c989435d..735ec193 100644
--- a/nvme-print.c
+++ b/nvme-print.c
@@ -4423,7 +4423,7 @@ void nvme_show_sanitize_log(struct nvme_sanitize_log_page *sanitize,
printf("\n");
printf("Sanitize Status (SSTAT) : %#x\n",
- le16_to_cpu(sanitize->sstat) & NVME_SANITIZE_SSTAT_STATUS_MASK);
+ le16_to_cpu(sanitize->sstat));
if (human)
nvme_show_sanitize_log_sstat(le16_to_cpu(sanitize->sstat));
--
2.39.3

@ -0,0 +1,118 @@
From 94d6c2b5088292e101da3e1d078e155a5af32f56 Mon Sep 17 00:00:00 2001
From: Tokunori Ikegami <ikegami.t@gmail.com>
Date: Sun, 14 May 2023 17:39:00 +0900
Subject: [PATCH] util: Fix suffix_si_parse to parse no decimal point but
suffix value correctly
For example create-ns command --ncap-si paramter value 800G parsed to 0 as invalid value.
Signed-off-by: Tokunori Ikegami <ikegami.t@gmail.com>
---
unit/test-suffix-si-parse.c | 6 +++++
util/suffix.c | 50 +++++++++++++++++++++++++++----------
2 files changed, 43 insertions(+), 13 deletions(-)
diff --git a/unit/test-suffix-si-parse.c b/unit/test-suffix-si-parse.c
index bc924552..54cff0e6 100644
--- a/unit/test-suffix-si-parse.c
+++ b/unit/test-suffix-si-parse.c
@@ -43,6 +43,12 @@ static struct tonum_test tonum_tests[] = {
{ "2,33", 0, -EINVAL },
{ "3..3", 0, -EINVAL },
{ "123.12MM", 0, -EINVAL },
+ { "800G", 800000000000, 0 },
+ { "800GG", 0, -EINVAL },
+ { "800G800", 0, -EINVAL },
+ { "800.0G", 800000000000, 0 },
+ { "800.G", 0, -EINVAL },
+ { "800.", 0, -EINVAL },
};
void tonum_test(struct tonum_test *test)
diff --git a/util/suffix.c b/util/suffix.c
index 8ed080d4..f010f3b6 100644
--- a/util/suffix.c
+++ b/util/suffix.c
@@ -40,6 +40,7 @@
#include <float.h>
#include <limits.h>
#include <locale.h>
+#include <stdio.h>
static struct si_suffix {
long double magnitude;
@@ -68,11 +69,26 @@ const char *suffix_si_get(double *value)
return suffix;
}
+static bool suffix_si_check(const char val)
+{
+ int i;
+ struct si_suffix *s;
+
+ for (i = 0; i < ARRAY_SIZE(si_suffixes); i++) {
+ s = &si_suffixes[i];
+
+ if (val == *s->suffix)
+ return true;
+ }
+
+ return false;
+}
+
int suffix_si_parse(const char *str, char **endptr, uint64_t *val)
{
- unsigned long long num, frac;
+ unsigned long long num, frac = 0;
char *sep, *tmp;
- int frac_len, len, i;
+ int frac_len = 0, len, i;
num = strtoull(str, endptr, 0);
if (str == *endptr ||
@@ -93,23 +109,31 @@ int suffix_si_parse(const char *str, char **endptr, uint64_t *val)
len = 0;
for (i = 0; i < len; i++) {
+ if (suffix_si_check((*endptr)[i]))
+ break;
if (((*endptr)[i] == '\0') || (*endptr)[i] != sep[i])
return -EINVAL;
}
- *endptr += len;
- tmp = *endptr;
- /* extract the digits after decimal point */
- frac = strtoull(tmp, endptr, 0);
- if (tmp == *endptr ||
- ((frac == ULLONG_MAX) && errno == ERANGE))
- return -EINVAL;
+ if (suffix_si_check((*endptr)[i])) {
+ if ((*endptr)[i + 1] != '\0')
+ return -EINVAL;
+ } else {
+ *endptr += len;
+ tmp = *endptr;
+
+ /* extract the digits after decimal point */
+ frac = strtoull(tmp, endptr, 0);
+ if (tmp == *endptr ||
+ ((frac == ULLONG_MAX) && errno == ERANGE))
+ return -EINVAL;
- /* test that we have max one character as suffix */
- if ((*endptr)[0] != '\0' && (*endptr)[1] != '\0')
- return -EINVAL;
+ /* test that we have max one character as suffix */
+ if ((*endptr)[0] != '\0' && (*endptr)[1] != '\0')
+ return -EINVAL;
- frac_len = *endptr - tmp;
+ frac_len = *endptr - tmp;
+ }
for (i = 0; i < ARRAY_SIZE(si_suffixes); i++) {
struct si_suffix *s = &si_suffixes[i];
--
2.39.3

@ -1,5 +0,0 @@
#!/bin/bash
if [[ "$1" == nbft* ]] && [[ "$2" == "up" ]]; then
systemctl start nvmf-connect-nbft.service
fi

@ -1,15 +0,0 @@
# Boot from NVMe over TCP (NBFT)
#
# For NVMe/TCP connections that provide namespaces containing rootfs
# it is crucial to react on carrier events and reconnect any missing
# NVMe/TCP connections as defined in the ACPI NBFT table. A custom
# /usr/lib/NetworkManager/dispatcher.d/99-nvme-nbft-connect.sh hook
# will respawn nvmf-connect-nbft.service on such occasion.
[device-nbft-no-ignore-carrier]
# only affects nbft0, nbft1, ... interfaces
match-device=interface-name:nbft*
# react on link up/down events
ignore-carrier=no

@ -1,596 +0,0 @@
From ca58ecc64852fc413a04f41d953914720d05459f Mon Sep 17 00:00:00 2001
From: Tomas Bzatek <tbzatek@redhat.com>
Date: Wed, 24 Apr 2024 17:46:19 +0200
Subject: [PATCH 1/5] fabrics: Make some symbols public
Needed for nbft, useful to have public.
Signed-off-by: Tomas Bzatek <tbzatek@redhat.com>
---
fabrics.c | 24 ++++++++++++------------
fabrics.h | 6 ++++++
2 files changed, 18 insertions(+), 12 deletions(-)
diff --git a/fabrics.c b/fabrics.c
index 0b70d290a9..a82a56c7b0 100644
--- a/fabrics.c
+++ b/fabrics.c
@@ -195,9 +195,9 @@ static nvme_ctrl_t __create_discover_ctrl(nvme_root_t r, nvme_host_t h,
return c;
}
-static nvme_ctrl_t create_discover_ctrl(nvme_root_t r, nvme_host_t h,
- struct nvme_fabrics_config *cfg,
- struct tr_config *trcfg)
+nvme_ctrl_t nvmf_create_discover_ctrl(nvme_root_t r, nvme_host_t h,
+ struct nvme_fabrics_config *cfg,
+ struct tr_config *trcfg)
{
_cleanup_free_ struct nvme_id_ctrl *id = NULL;
nvme_ctrl_t c;
@@ -378,8 +378,7 @@ static int __discover(nvme_ctrl_t c, struct nvme_fabrics_config *defcfg,
return 0;
}
-static char *get_default_trsvcid(const char *transport,
- bool discovery_ctrl)
+char *nvmf_get_default_trsvcid(const char *transport, bool discovery_ctrl)
{
if (!transport)
return NULL;
@@ -465,7 +464,7 @@ static int discover_from_conf_file(nvme_root_t r, nvme_host_t h,
goto next;
if (!trsvcid)
- trsvcid = get_default_trsvcid(transport, true);
+ trsvcid = nvmf_get_default_trsvcid(transport, true);
struct tr_config trcfg = {
.subsysnqn = subsysnqn,
@@ -485,7 +484,7 @@ static int discover_from_conf_file(nvme_root_t r, nvme_host_t h,
}
}
- c = create_discover_ctrl(r, h, &cfg, &trcfg);
+ c = nvmf_create_discover_ctrl(r, h, &cfg, &trcfg);
if (!c)
goto next;
@@ -549,7 +548,8 @@ static int discover_from_json_config_file(nvme_root_t r, nvme_host_t h,
trsvcid = nvme_ctrl_get_trsvcid(c);
if (!trsvcid || !strcmp(trsvcid, ""))
- trsvcid = get_default_trsvcid(transport, true);
+ trsvcid = nvmf_get_default_trsvcid(transport,
+ true);
if (force)
subsysnqn = nvme_ctrl_get_subsysnqn(c);
@@ -579,7 +579,7 @@ static int discover_from_json_config_file(nvme_root_t r, nvme_host_t h,
}
}
- cn = create_discover_ctrl(r, h, &cfg, &trcfg);
+ cn = nvmf_create_discover_ctrl(r, h, &cfg, &trcfg);
if (!cn)
continue;
@@ -806,7 +806,7 @@ int nvmf_discover(const char *desc, int argc, char **argv, bool connect)
}
if (!trsvcid)
- trsvcid = get_default_trsvcid(transport, true);
+ trsvcid = nvmf_get_default_trsvcid(transport, true);
struct tr_config trcfg = {
.subsysnqn = subsysnqn,
@@ -876,7 +876,7 @@ int nvmf_discover(const char *desc, int argc, char **argv, bool connect)
}
if (!c) {
/* No device or non-matching device, create a new controller */
- c = create_discover_ctrl(r, h, &cfg, &trcfg);
+ c = nvmf_create_discover_ctrl(r, h, &cfg, &trcfg);
if (!c) {
if (errno != ENVME_CONNECT_IGNORED)
fprintf(stderr,
@@ -1005,7 +1005,7 @@ int nvmf_connect(const char *desc, int argc, char **argv)
if (hostkey)
nvme_host_set_dhchap_key(h, hostkey);
if (!trsvcid)
- trsvcid = get_default_trsvcid(transport, false);
+ trsvcid = nvmf_get_default_trsvcid(transport, false);
struct tr_config trcfg = {
.subsysnqn = subsysnqn,
diff --git a/fabrics.h b/fabrics.h
index c16df60472..aec305dc31 100644
--- a/fabrics.h
+++ b/fabrics.h
@@ -18,5 +18,11 @@ extern int nvmf_disconnect(const char *desc, int argc, char **argv);
extern int nvmf_disconnect_all(const char *desc, int argc, char **argv);
extern int nvmf_config(const char *desc, int argc, char **argv);
extern int nvmf_dim(const char *desc, int argc, char **argv);
+extern nvme_ctrl_t nvmf_create_discover_ctrl(nvme_root_t r, nvme_host_t h,
+ struct nvme_fabrics_config *cfg,
+ struct tr_config *trcfg);
+extern char *nvmf_get_default_trsvcid(const char *transport,
+ bool discovery_ctrl);
+
#endif
From 996fd5554157949ed77154eecd0f8236590cc716 Mon Sep 17 00:00:00 2001
From: Tomas Bzatek <tbzatek@redhat.com>
Date: Wed, 24 Apr 2024 17:47:02 +0200
Subject: [PATCH 2/5] util/cleanup: Add cleanup for struct nvme_fabrics_uri
libnvme cleanup definitions are not part of public API.
Signed-off-by: Tomas Bzatek <tbzatek@redhat.com>
---
util/cleanup.h | 8 ++++++++
1 file changed, 8 insertions(+)
diff -up nvme-cli-2.9.1/util/cleanup.h.bak nvme-cli-2.9.1/util/cleanup.h
--- nvme-cli-2.9.1/util/cleanup.h.bak 2024-06-21 15:53:35.839852234 +0200
+++ nvme-cli-2.9.1/util/cleanup.h 2024-05-03 16:03:42.000000000 +0200
@@ -34,4 +34,12 @@ static inline void close_file(int *f)
}
#define _cleanup_file_ __cleanup__(close_file)
+static inline void free_uri(struct nvme_fabrics_uri **uri)
+{
+ if (*uri)
+ nvme_free_uri(*uri);
+}
+
+#define _cleanup_uri_ __cleanup__(free_uri)
+
#endif
From 2f79015b83faff4947d29fb172d6f92d81f078e2 Mon Sep 17 00:00:00 2001
From: Tomas Bzatek <tbzatek@redhat.com>
Date: Wed, 24 Apr 2024 17:52:46 +0200
Subject: [PATCH 3/5] nbft: Perform actual discovery
This adds actual discovery support for Discovery Descriptor records.
SSNS records are connected first. Discovery Descriptor records
are checked for any existing (back-)reference from SSNS records
and are skipped if so. It is assumed in such case that the pre-OS
driver has succeeded in discovery and filled SSNS records
accordingly.
In case no SSNS record references the particular Discovery
record, an actual discovery is performed.
Signed-off-by: Tomas Bzatek <tbzatek@redhat.com>
---
nbft.c | 232 ++++++++++++++++++++++++++++++++++++++++++++++++++++++---
nbft.h | 2 +-
2 files changed, 223 insertions(+), 11 deletions(-)
diff --git a/nbft.c b/nbft.c
index 7ff8765a80..995b31ca54 100644
--- a/nbft.c
+++ b/nbft.c
@@ -7,6 +7,7 @@
#include <libnvme.h>
+#include "common.h"
#include "nvme.h"
#include "nbft.h"
#include "fabrics.h"
@@ -77,12 +78,38 @@ void free_nbfts(struct list_head *nbft_list)
}
}
+static bool validate_uri(struct nbft_info_discovery *dd,
+ struct nvme_fabrics_uri *uri)
+{
+ if (!uri) {
+ fprintf(stderr,
+ "Discovery Descriptor %d: failed to parse URI %s\n",
+ dd->index, dd->uri);
+ return false;
+ }
+ if (strcmp(uri->scheme, "nvme") != 0) {
+ fprintf(stderr,
+ "Discovery Descriptor %d: unsupported scheme '%s'\n",
+ dd->index, uri->scheme);
+ return false;
+ }
+ if (!uri->protocol || strcmp(uri->protocol, "tcp") != 0) {
+ fprintf(stderr,
+ "Discovery Descriptor %d: unsupported transport '%s'\n",
+ dd->index, uri->protocol);
+ return false;
+ }
+
+ return true;
+}
+
/* returns 0 for success or negative errno otherwise */
static int do_connect(nvme_root_t r,
nvme_host_t h,
+ struct nvmf_disc_log_entry *e,
struct nbft_info_subsystem_ns *ss,
struct tr_config *trcfg,
- const struct nvme_fabrics_config *cfg,
+ struct nvme_fabrics_config *cfg,
enum nvme_print_flags flags,
unsigned int verbose)
{
@@ -111,6 +138,12 @@ static int do_connect(nvme_root_t r,
nvme_init_logging(r, -1, false, false);
}
+ if (e) {
+ if (e->trtype == NVMF_TRTYPE_TCP &&
+ e->tsas.tcp.sectype != NVMF_TCP_SECTYPE_NONE)
+ cfg->tls = true;
+ }
+
errno = 0;
ret = nvmf_add_ctrl(h, c, cfg);
@@ -145,10 +178,114 @@ static int do_connect(nvme_root_t r,
return 0;
}
+static int do_discover(struct nbft_info_discovery *dd,
+ nvme_root_t r,
+ nvme_host_t h,
+ nvme_ctrl_t c,
+ struct nvme_fabrics_config *defcfg,
+ struct tr_config *deftrcfg,
+ enum nvme_print_flags flags,
+ unsigned int verbose)
+{
+ struct nvmf_discovery_log *log = NULL;
+ int i;
+ int ret;
+
+ struct nvme_get_discovery_args args = {
+ .c = c,
+ .args_size = sizeof(args),
+ .max_retries = 10 /* MAX_DISC_RETRIES */,
+ .result = 0,
+ .timeout = NVME_DEFAULT_IOCTL_TIMEOUT,
+ .lsp = 0,
+ };
+
+ log = nvmf_get_discovery_wargs(&args);
+ if (!log) {
+ fprintf(stderr,
+ "Discovery Descriptor %d: failed to get discovery log: %s\n",
+ dd->index, nvme_strerror(errno));
+ return -errno;
+ }
+
+ for (i = 0; i < le64_to_cpu(log->numrec); i++) {
+ struct nvmf_disc_log_entry *e = &log->entries[i];
+ nvme_ctrl_t cl;
+ int tmo = defcfg->keep_alive_tmo;
+
+ struct tr_config trcfg = {
+ .subsysnqn = e->subnqn,
+ .transport = nvmf_trtype_str(e->trtype),
+ .traddr = e->traddr,
+ .host_traddr = deftrcfg->host_traddr,
+ .host_iface = deftrcfg->host_iface,
+ .trsvcid = e->trsvcid,
+ };
+
+ if (e->subtype == NVME_NQN_CURR)
+ continue;
+
+ /* Already connected ? */
+ cl = lookup_ctrl(h, &trcfg);
+ if (cl && nvme_ctrl_get_name(cl))
+ continue;
+
+ /* Skip connect if the transport types don't match */
+ if (strcmp(nvme_ctrl_get_transport(c),
+ nvmf_trtype_str(e->trtype)))
+ continue;
+
+ if (e->subtype == NVME_NQN_DISC) {
+ nvme_ctrl_t child;
+
+ child = nvmf_connect_disc_entry(h, e, defcfg, NULL);
+ do_discover(dd, r, h, child, defcfg, &trcfg,
+ flags, verbose);
+ nvme_disconnect_ctrl(child);
+ nvme_free_ctrl(child);
+ } else {
+ ret = do_connect(r, h, e, NULL, &trcfg,
+ defcfg, flags, verbose);
+
+ /*
+ * With TCP/DHCP, it can happen that the OS
+ * obtains a different local IP address than the
+ * firmware had. Retry without host_traddr.
+ */
+ if (ret == -ENVME_CONNECT_ADDRNOTAVAIL &&
+ !strcmp(trcfg.transport, "tcp") &&
+ strlen(dd->hfi->tcp_info.dhcp_server_ipaddr) > 0) {
+ const char *htradr = trcfg.host_traddr;
+
+ trcfg.host_traddr = NULL;
+ ret = do_connect(r, h, e, NULL, &trcfg,
+ defcfg, flags, verbose);
+
+ if (ret == 0 && verbose >= 1)
+ fprintf(stderr,
+ "Discovery Descriptor %d: connect with host_traddr=\"%s\" failed, success after omitting host_traddr\n",
+ dd->index,
+ htradr);
+ }
+
+ if (ret)
+ fprintf(stderr, "Discovery Descriptor %d: no controller found\n",
+ dd->index);
+ if (ret == -ENOMEM)
+ break;
+ }
+
+ defcfg->keep_alive_tmo = tmo;
+ }
+
+ free(log);
+ return 0;
+}
+
int discover_from_nbft(nvme_root_t r, char *hostnqn_arg, char *hostid_arg,
char *hostnqn_sys, char *hostid_sys,
const char *desc, bool connect,
- const struct nvme_fabrics_config *cfg, char *nbft_path,
+ struct nvme_fabrics_config *cfg, char *nbft_path,
enum nvme_print_flags flags, unsigned int verbose)
{
char *hostnqn = NULL, *hostid = NULL, *host_traddr = NULL;
@@ -158,6 +295,7 @@ int discover_from_nbft(nvme_root_t r, char *hostnqn_arg, char *hostid_arg,
struct nbft_file_entry *entry = NULL;
struct nbft_info_subsystem_ns **ss;
struct nbft_info_hfi *hfi;
+ struct nbft_info_discovery **dd;
if (!connect)
/* to do: print discovery-type info from NBFT tables */
@@ -192,15 +330,15 @@ int discover_from_nbft(nvme_root_t r, char *hostnqn_arg, char *hostid_arg,
if (!h)
goto out_free;
+ /* Subsystem Namespace Descriptor List */
for (ss = entry->nbft->subsystem_ns_list; ss && *ss; ss++)
for (i = 0; i < (*ss)->num_hfis; i++) {
hfi = (*ss)->hfis[i];
- if (!cfg->host_traddr) {
- host_traddr = NULL;
- if (!strncmp((*ss)->transport, "tcp", 3))
- host_traddr = hfi->tcp_info.ipaddr;
- }
+ host_traddr = NULL;
+ if (!cfg->host_traddr &&
+ !strncmp((*ss)->transport, "tcp", 3))
+ host_traddr = hfi->tcp_info.ipaddr;
struct tr_config trcfg = {
.subsysnqn = (*ss)->subsys_nqn,
@@ -211,7 +349,7 @@ int discover_from_nbft(nvme_root_t r, char *hostnqn_arg, char *hostid_arg,
.trsvcid = (*ss)->trsvcid,
};
- ret = do_connect(r, h, *ss, &trcfg,
+ ret = do_connect(r, h, NULL, *ss, &trcfg,
cfg, flags, verbose);
/*
@@ -220,11 +358,11 @@ int discover_from_nbft(nvme_root_t r, char *hostnqn_arg, char *hostid_arg,
* firmware had. Retry without host_traddr.
*/
if (ret == -ENVME_CONNECT_ADDRNOTAVAIL &&
- !strcmp((*ss)->transport, "tcp") &&
+ !strcmp(trcfg.transport, "tcp") &&
strlen(hfi->tcp_info.dhcp_server_ipaddr) > 0) {
trcfg.host_traddr = NULL;
- ret = do_connect(r, h, *ss, &trcfg,
+ ret = do_connect(r, h, NULL, *ss, &trcfg,
cfg, flags, verbose);
if (ret == 0 && verbose >= 1)
@@ -241,6 +379,80 @@ int discover_from_nbft(nvme_root_t r, char *hostnqn_arg, char *hostid_arg,
if (ret == -ENOMEM)
goto out_free;
}
+
+ /* Discovery Descriptor List */
+ for (dd = entry->nbft->discovery_list; dd && *dd; dd++) {
+ nvme_ctrl_t c;
+ bool linked = false;
+ _cleanup_uri_ struct nvme_fabrics_uri *uri = NULL;
+ _cleanup_free_ char *trsvcid = NULL;
+
+ /* only perform discovery when no SSNS record references it */
+ for (ss = entry->nbft->subsystem_ns_list; ss && *ss; ss++)
+ if ((*ss)->discovery &&
+ (*ss)->discovery->index == (*dd)->index &&
+ /* unavailable boot attempts are not discovered
+ * and may get transferred along with a well-known
+ * discovery NQN into an SSNS record.
+ */
+ strcmp((*ss)->subsys_nqn, NVME_DISC_SUBSYS_NAME) != 0) {
+ linked = true;
+ break;
+ }
+ if (linked)
+ continue;
+
+ hfi = (*dd)->hfi;
+ uri = nvme_parse_uri((*dd)->uri);
+ if (!validate_uri(*dd, uri))
+ continue;
+
+ host_traddr = NULL;
+ if (!cfg->host_traddr &&
+ !strncmp(uri->protocol, "tcp", 3))
+ host_traddr = hfi->tcp_info.ipaddr;
+ if (uri->port > 0) {
+ if (asprintf(&trsvcid, "%d", uri->port) < 0) {
+ errno = ENOMEM;
+ goto out_free;
+ }
+ } else
+ trsvcid = strdup(nvmf_get_default_trsvcid(uri->protocol, true));
+
+ struct tr_config trcfg = {
+ .subsysnqn = NVME_DISC_SUBSYS_NAME,
+ .transport = uri->protocol,
+ .traddr = uri->host,
+ .host_traddr = host_traddr,
+ .host_iface = NULL,
+ .trsvcid = trsvcid,
+ };
+
+ c = nvmf_create_discover_ctrl(r, h, cfg, &trcfg);
+ if (!c && errno == ENVME_CONNECT_ADDRNOTAVAIL &&
+ !strcmp(trcfg.transport, "tcp") &&
+ strlen(hfi->tcp_info.dhcp_server_ipaddr) > 0) {
+ trcfg.host_traddr = NULL;
+ c = nvmf_create_discover_ctrl(r, h, cfg, &trcfg);
+ }
+
+ if (!c) {
+ fprintf(stderr,
+ "Discovery Descriptor %d: failed to add discovery controller: %s\n",
+ (*dd)->index,
+ nvme_strerror(errno));
+ if (errno == ENOMEM)
+ goto out_free;
+ continue;
+ }
+
+ ret = do_discover(*dd, r, h, c, cfg, &trcfg,
+ flags, verbose);
+ nvme_disconnect_ctrl(c);
+ nvme_free_ctrl(c);
+ if (ret == -ENOMEM)
+ goto out_free;
+ }
}
out_free:
free_nbfts(&nbft_list);
diff --git a/nbft.h b/nbft.h
index 0f7e33cee5..5dfb8704fd 100644
--- a/nbft.h
+++ b/nbft.h
@@ -15,5 +15,5 @@ void free_nbfts(struct list_head *nbft_list);
extern int discover_from_nbft(nvme_root_t r, char *hostnqn_arg, char *hostid_arg,
char *hostnqn_sys, char *hostid_sys,
const char *desc, bool connect,
- const struct nvme_fabrics_config *cfg, char *nbft_path,
+ struct nvme_fabrics_config *cfg, char *nbft_path,
enum nvme_print_flags flags, unsigned int verbose);
From 1074da1dbbbef229bf7e42a3cb644ab5b9745267 Mon Sep 17 00:00:00 2001
From: Tomas Bzatek <tbzatek@redhat.com>
Date: Thu, 25 Apr 2024 15:54:53 +0200
Subject: [PATCH 4/5] nbft: Skip SSNS records pointing to well-known discovery
NQN
Depending on a pre-OS implementation, boot attempts pointing
to the well-known discovery NQN may get transformed in
an SSNS record (and marked as 'unavailable') in case
the discovery cannot be performed. Otherwise the NBFT
table should be populated by discovered records instead.
Signed-off-by: Tomas Bzatek <tbzatek@redhat.com>
---
nbft.c | 9 +++++++++
1 file changed, 9 insertions(+)
diff --git a/nbft.c b/nbft.c
index 995b31ca54..9d1834d0db 100644
--- a/nbft.c
+++ b/nbft.c
@@ -335,6 +335,15 @@ int discover_from_nbft(nvme_root_t r, char *hostnqn_arg, char *hostid_arg,
for (i = 0; i < (*ss)->num_hfis; i++) {
hfi = (*ss)->hfis[i];
+ /* Skip discovery NQN records */
+ if (strcmp((*ss)->subsys_nqn, NVME_DISC_SUBSYS_NAME) == 0) {
+ if (verbose >= 1)
+ fprintf(stderr,
+ "SSNS %d points to well-known discovery NQN, skipping\n",
+ (*ss)->index);
+ continue;
+ }
+
host_traddr = NULL;
if (!cfg->host_traddr &&
!strncmp((*ss)->transport, "tcp", 3))
From 8b4c30014ed17fa226a34a3dd92167f122ccec42 Mon Sep 17 00:00:00 2001
From: Tomas Bzatek <tbzatek@redhat.com>
Date: Mon, 20 May 2024 17:43:01 +0200
Subject: [PATCH 5/5] nbft: Reuse existing discovery controller
Attempt to look up and use existing (persistent) discovery
controller.
Signed-off-by: Tomas Bzatek <tbzatek@redhat.com>
---
nbft.c | 21 +++++++++++++++------
1 file changed, 15 insertions(+), 6 deletions(-)
diff --git a/nbft.c b/nbft.c
index 9d1834d0db..8c03a1f53b 100644
--- a/nbft.c
+++ b/nbft.c
@@ -393,6 +393,7 @@ int discover_from_nbft(nvme_root_t r, char *hostnqn_arg, char *hostid_arg,
for (dd = entry->nbft->discovery_list; dd && *dd; dd++) {
nvme_ctrl_t c;
bool linked = false;
+ bool persistent = false;
_cleanup_uri_ struct nvme_fabrics_uri *uri = NULL;
_cleanup_free_ char *trsvcid = NULL;
@@ -437,12 +438,19 @@ int discover_from_nbft(nvme_root_t r, char *hostnqn_arg, char *hostid_arg,
.trsvcid = trsvcid,
};
- c = nvmf_create_discover_ctrl(r, h, cfg, &trcfg);
- if (!c && errno == ENVME_CONNECT_ADDRNOTAVAIL &&
- !strcmp(trcfg.transport, "tcp") &&
- strlen(hfi->tcp_info.dhcp_server_ipaddr) > 0) {
- trcfg.host_traddr = NULL;
+ /* Lookup existing discovery controller */
+ c = lookup_ctrl(h, &trcfg);
+ if (c && nvme_ctrl_get_name(c))
+ persistent = true;
+
+ if (!c) {
c = nvmf_create_discover_ctrl(r, h, cfg, &trcfg);
+ if (!c && errno == ENVME_CONNECT_ADDRNOTAVAIL &&
+ !strcmp(trcfg.transport, "tcp") &&
+ strlen(hfi->tcp_info.dhcp_server_ipaddr) > 0) {
+ trcfg.host_traddr = NULL;
+ c = nvmf_create_discover_ctrl(r, h, cfg, &trcfg);
+ }
}
if (!c) {
@@ -457,7 +465,8 @@ int discover_from_nbft(nvme_root_t r, char *hostnqn_arg, char *hostid_arg,
ret = do_discover(*dd, r, h, c, cfg, &trcfg,
flags, verbose);
- nvme_disconnect_ctrl(c);
+ if (!persistent)
+ nvme_disconnect_ctrl(c);
nvme_free_ctrl(c);
if (ret == -ENOMEM)
goto out_free;

@ -1,24 +1,20 @@
#%%global commit0 bdbb4da0979fbdc079cf98410cdb31cf799e83b3
#%%global shortcommit0 %%(c=%%{commit0}; echo ${c:0:7})
%global nmlibdir %{_prefix}/lib/NetworkManager
Name: nvme-cli
Version: 2.9.1
Release: 6%{?dist}
Version: 2.4
Release: 10%{?dist}
Summary: NVMe management command line interface
License: GPL-2.0-only
License: GPLv2+
URL: https://github.com/linux-nvme/nvme-cli
Source0: %{url}/archive/v%{version}/%{name}-%{version}.tar.gz
Source1: 99-nvme-nbft-connect.sh
Source2: 99-nvme-nbft-no-ignore-carrier.conf
Patch0: 0001-Revert-fabrics-Use-corresponding-hostid-when-hostnqn.patch
Patch1: 0002-nvme-telemetry-report-the-correct-error-if-the-ioctl.patch
# https://issues.redhat.com/browse/RHEL-37601
Patch2: nvme-cli-2.10-nbft-discovery.patch
Patch3: 0003-sed-only-re-read-partition-table-after-unlock.patch
Patch0: 0001-nbft-make-lookup_ctrl-function-public.patch
Patch1: 0002-nbft-added-NBFT-v1.0-table-support.patch
Patch2: 0003-nbft-add-the-nbft-show-plugin.patch
Patch3: 0004-Revert-nvme-Masks-SSTAT-in-sanize-log-output.patch
Patch4: 0005-util-Fix-suffix_si_parse-to-parse-no-decimal-point-b.patch
BuildRequires: meson >= 0.50.0
BuildRequires: gcc gcc-c++
@ -26,7 +22,7 @@ BuildRequires: libuuid-devel
BuildRequires: systemd-devel
BuildRequires: systemd-rpm-macros
BuildRequires: zlib-devel
BuildRequires: libnvme-devel >= 1.9-2
BuildRequires: libnvme-devel >= 1.4-5
BuildRequires: json-c-devel >= 0.14
BuildRequires: asciidoc
BuildRequires: xmlto
@ -37,7 +33,14 @@ Requires: util-linux
nvme-cli provides NVM-Express user space tooling for Linux.
%prep
%autosetup -p1 -n %{name}-%{version}
#%%setup -qn %%{name}-%%{commit0}
%setup -q
%patch0 -p1
%patch1 -p1
%patch2 -p1
%patch3 -p1
%patch4 -p1
%build
%meson -Dudevrulesdir=%{_udevrulesdir} -Dsystemddir=%{_unitdir} -Ddocs=all -Ddocs-build=true -Dhtmldir=%{_pkgdocdir}
@ -45,10 +48,6 @@ nvme-cli provides NVM-Express user space tooling for Linux.
%install
%meson_install
mkdir -p $RPM_BUILD_ROOT%{nmlibdir}/dispatcher.d
mkdir -p $RPM_BUILD_ROOT%{nmlibdir}/conf.d
%{__install} -pm 755 %{SOURCE1} $RPM_BUILD_ROOT%{nmlibdir}/dispatcher.d/
%{__install} -pm 644 %{SOURCE2} $RPM_BUILD_ROOT%{nmlibdir}/conf.d/
# Do not install the dracut rule yet. See rhbz 1742764
# Do we want to keep this here? Now that we have boot support for nvme/fc + tcp?
@ -70,17 +69,13 @@ rm -rf %{buildroot}%{_pkgdocdir}/nvme
%config(noreplace) %{_sysconfdir}/nvme/discovery.conf
%{_unitdir}/nvmefc-boot-connections.service
%{_unitdir}/nvmf-autoconnect.service
%{_unitdir}/nvmf-connect-nbft.service
%{_unitdir}/nvmf-connect.target
%{_unitdir}/nvmf-connect@.service
%{_udevrulesdir}/65-persistent-net-nbft.rules
%{_udevrulesdir}/70-nvmf-autoconnect.rules
%{_udevrulesdir}/71-nvmf-netapp.rules
%{_udevrulesdir}/71-nvmf-iopolicy-netapp.rules
# Do not install the dracut rule yet. See rhbz 1742764
# Is this still true? Now that we support nvme-of boot, do we want to install this file?
# /usr/lib/dracut/dracut.conf.d/70-nvmf-autoconnect.conf
%{nmlibdir}/dispatcher.d/99-nvme-nbft-connect.sh
%{nmlibdir}/conf.d/99-nvme-nbft-no-ignore-carrier.conf
%post
if [ $1 -eq 1 ] || [ $1 -eq 2 ]; then
@ -101,46 +96,6 @@ if [ $1 -eq 1 ] || [ $1 -eq 2 ]; then
fi
%changelog
* Sat Oct 12 2024 Arkady L. Shane <tigro@msvsphere-os.ru> - 2.9.1-6.inferit
- Rebuit for MSVSphere-9.5
* Thu Aug 22 2024 Tomas Bzatek <tbzatek@redhat.com> - 2.9.1-6
- Install NetworkManager override for nbft interfaces
- Rename reconnect NetworkManager hook to 99-nvme-nbft-connect.sh
* Tue Aug 06 2024 Maurizio Lombardi <mlombard@redhat.com> - 2.9.1-5
- Fix RHEL-38372
* Wed Jul 24 2024 Tomas Bzatek <tbzatek@redhat.com> - 2.9.1-4
- Backport NBFT discovery support (RHEL-37601)
* Wed June 19 2024 Maurizio Lombardi <mlombard@redhat.com> - 2.9.1-3
- Fix RHEL-36139
* Tue May 07 2024 Tomas Bzatek <tbzatek@redhat.com> - 2.9.1-2
- Install custom nvmf-connect-nbft.sh NetworkManager hook (RHEL-18912)
* Tue May 07 2024 Maurizio Lombardi <mlombard@redhat.com> - 2.9.1-1
- Update to version 2.9.1
* Wed Apr 03 2024 Maurizio Lombardi <mlombard@redhat.com> - 2.8-1
- Update to version 2.8
* Thu Feb 22 2024 Maurizio Lombardi <mlombard@redhat.com> - 2.6-5
- Fix for RHEL-13107
* Mon Nov 13 2023 Maurizio Lombardi <mlombard@redhat.com> - 2.6-4
- Fix for RHEL-16216 (revert 1:1 mapping between hostnqn and hostid)
* Wed Nov 08 2023 Maurizio Lombardi <mlombard@redhat.com> - 2.6-3
- Fixes for RHEL-12566
* Mon Nov 06 2023 Maurizio Lombardi <mlombard@redhat.com> - 2.6-2
- Rebuild for side-tag
* Tue Oct 31 2023 Maurizio Lombardi <mlombard@redhat.com> - 2.6-1
- Update to version 2.6
* Mon Aug 21 2023 John Meneghini <jmeneghi@redhat.com> - 2.4-10
- JIRA: https://issues.redhat.com/browse/RHEL-1492

Loading…
Cancel
Save