Compare commits
No commits in common. 'i9c-beta' and 'c9' have entirely different histories.
@ -1 +1 @@
|
||||
SOURCES/libnvme-1.9.tar.gz
|
||||
SOURCES/libnvme-1.4.tar.gz
|
||||
|
@ -1 +1 @@
|
||||
7ce814bb26bd5fc33b99f5ba48d99538f23756cd SOURCES/libnvme-1.9.tar.gz
|
||||
1708e8659912cb695c3ac618a28518027f5833db SOURCES/libnvme-1.4.tar.gz
|
||||
|
@ -0,0 +1,399 @@
|
||||
From d123131f2e542e5a4c046cb65a68fc1fb97ea384 Mon Sep 17 00:00:00 2001
|
||||
From: Daniel Wagner <dwagner@suse.de>
|
||||
Date: Wed, 12 Apr 2023 11:59:45 +0200
|
||||
Subject: [PATCH] fabrics: Do not pass unsupported options to kernel
|
||||
|
||||
The kernel API might not support all options libnvme is supporting.
|
||||
Filter out all options which the kernel doesn't support.
|
||||
|
||||
Signed-off-by: Daniel Wagner <dwagner@suse.de>
|
||||
---
|
||||
src/nvme/fabrics.c | 216 ++++++++++++++++++++++++++++++++++++++-------
|
||||
src/nvme/private.h | 33 +++++++
|
||||
src/nvme/tree.c | 1 +
|
||||
3 files changed, 220 insertions(+), 30 deletions(-)
|
||||
|
||||
diff --git a/src/nvme/fabrics.c b/src/nvme/fabrics.c
|
||||
index 3c32e27..f9c26fe 100644
|
||||
--- a/src/nvme/fabrics.c
|
||||
+++ b/src/nvme/fabrics.c
|
||||
@@ -30,6 +30,7 @@
|
||||
#include <ccan/endian/endian.h>
|
||||
#include <ccan/list/list.h>
|
||||
#include <ccan/array_size/array_size.h>
|
||||
+#include <ccan/str/str.h>
|
||||
|
||||
#include "fabrics.h"
|
||||
#include "linux.h"
|
||||
@@ -261,7 +262,7 @@ void nvmf_update_config(nvme_ctrl_t c, const struct nvme_fabrics_config *cfg)
|
||||
UPDATE_CFG_OPTION(ctrl_cfg, cfg, tls, false);
|
||||
}
|
||||
|
||||
-static int add_bool_argument(char **argstr, char *tok, bool arg)
|
||||
+static int __add_bool_argument(char **argstr, char *tok, bool arg)
|
||||
{
|
||||
char *nstr;
|
||||
|
||||
@@ -277,7 +278,7 @@ static int add_bool_argument(char **argstr, char *tok, bool arg)
|
||||
return 0;
|
||||
}
|
||||
|
||||
-static int add_int_argument(char **argstr, char *tok, int arg, bool allow_zero)
|
||||
+static int __add_int_argument(char **argstr, char *tok, int arg, bool allow_zero)
|
||||
{
|
||||
char *nstr;
|
||||
|
||||
@@ -293,7 +294,7 @@ static int add_int_argument(char **argstr, char *tok, int arg, bool allow_zero)
|
||||
return 0;
|
||||
}
|
||||
|
||||
-static int add_int_or_minus_one_argument(char **argstr, char *tok, int arg)
|
||||
+static int __add_int_or_minus_one_argument(char **argstr, char *tok, int arg)
|
||||
{
|
||||
char *nstr;
|
||||
|
||||
@@ -309,7 +310,7 @@ static int add_int_or_minus_one_argument(char **argstr, char *tok, int arg)
|
||||
return 0;
|
||||
}
|
||||
|
||||
-static int add_argument(char **argstr, const char *tok, const char *arg)
|
||||
+static int __add_argument(char **argstr, const char *tok, const char *arg)
|
||||
{
|
||||
char *nstr;
|
||||
|
||||
@@ -325,6 +326,71 @@ static int add_argument(char **argstr, const char *tok, const char *arg)
|
||||
return 0;
|
||||
}
|
||||
|
||||
+#define add_bool_argument(o, argstr, tok, arg) \
|
||||
+({ \
|
||||
+ int ret; \
|
||||
+ if (r->options->tok) { \
|
||||
+ ret = __add_bool_argument(argstr, \
|
||||
+ stringify(tok), \
|
||||
+ arg); \
|
||||
+ } else { \
|
||||
+ nvme_msg(r, LOG_DEBUG, \
|
||||
+ "option \"%s\" ignored\n", \
|
||||
+ stringify(tok)); \
|
||||
+ ret = 0; \
|
||||
+ } \
|
||||
+ ret; \
|
||||
+})
|
||||
+
|
||||
+#define add_int_argument(o, argstr, tok, arg, allow_zero) \
|
||||
+({ \
|
||||
+ int ret; \
|
||||
+ if (r->options->tok) { \
|
||||
+ ret = __add_int_argument(argstr, \
|
||||
+ stringify(tok), \
|
||||
+ arg, \
|
||||
+ allow_zero); \
|
||||
+ } else { \
|
||||
+ nvme_msg(r, LOG_DEBUG, \
|
||||
+ "option \"%s\" ignored\n", \
|
||||
+ stringify(tok)); \
|
||||
+ ret = 0; \
|
||||
+ } \
|
||||
+ ret; \
|
||||
+})
|
||||
+
|
||||
+#define add_int_or_minus_one_argument(o, argstr, tok, arg) \
|
||||
+({ \
|
||||
+ int ret; \
|
||||
+ if (r->options->tok) { \
|
||||
+ ret = __add_int_or_minus_one_argument(argstr, \
|
||||
+ stringify(tok), \
|
||||
+ arg); \
|
||||
+ } else { \
|
||||
+ nvme_msg(r, LOG_DEBUG, \
|
||||
+ "option \"%s\" ignored\n", \
|
||||
+ stringify(tok)); \
|
||||
+ ret = 0; \
|
||||
+ } \
|
||||
+ ret; \
|
||||
+})
|
||||
+
|
||||
+#define add_argument(r, argstr, tok, arg) \
|
||||
+({ \
|
||||
+ int ret; \
|
||||
+ if (r->options->tok) { \
|
||||
+ ret = __add_argument(argstr, \
|
||||
+ stringify(tok), \
|
||||
+ arg); \
|
||||
+ } else { \
|
||||
+ nvme_msg(r, LOG_NOTICE, \
|
||||
+ "option \"%s\" ignored\n", \
|
||||
+ stringify(tok)); \
|
||||
+ ret = 0; \
|
||||
+ } \
|
||||
+ ret; \
|
||||
+})
|
||||
+
|
||||
static int inet4_pton(const char *src, uint16_t port,
|
||||
struct sockaddr_storage *addr)
|
||||
{
|
||||
@@ -453,6 +519,7 @@ static int build_options(nvme_host_t h, nvme_ctrl_t c, char **argstr)
|
||||
const char *transport = nvme_ctrl_get_transport(c);
|
||||
const char *hostnqn, *hostid, *hostkey, *ctrlkey;
|
||||
bool discover = false, discovery_nqn = false;
|
||||
+ nvme_root_t r = h->r;
|
||||
|
||||
if (!transport) {
|
||||
nvme_msg(h->r, LOG_ERR, "need a transport (-t) argument\n");
|
||||
@@ -487,60 +554,60 @@ static int build_options(nvme_host_t h, nvme_ctrl_t c, char **argstr)
|
||||
if (!hostkey)
|
||||
hostkey = nvme_ctrl_get_dhchap_host_key(c);
|
||||
ctrlkey = nvme_ctrl_get_dhchap_key(c);
|
||||
- if (add_argument(argstr, "transport", transport) ||
|
||||
- add_argument(argstr, "traddr",
|
||||
+ if (add_argument(r, argstr, transport, transport) ||
|
||||
+ add_argument(r, argstr, traddr,
|
||||
nvme_ctrl_get_traddr(c)) ||
|
||||
- add_argument(argstr, "host_traddr",
|
||||
+ add_argument(r, argstr, host_traddr,
|
||||
cfg->host_traddr) ||
|
||||
- add_argument(argstr, "host_iface",
|
||||
+ add_argument(r, argstr, host_iface,
|
||||
cfg->host_iface) ||
|
||||
- add_argument(argstr, "trsvcid",
|
||||
+ add_argument(r, argstr, trsvcid,
|
||||
nvme_ctrl_get_trsvcid(c)) ||
|
||||
- (hostnqn && add_argument(argstr, "hostnqn", hostnqn)) ||
|
||||
- (hostid && add_argument(argstr, "hostid", hostid)) ||
|
||||
+ (hostnqn && add_argument(r, argstr, hostnqn, hostnqn)) ||
|
||||
+ (hostid && add_argument(r, argstr, hostid, hostid)) ||
|
||||
(discover && !discovery_nqn &&
|
||||
- add_bool_argument(argstr, "discovery", true)) ||
|
||||
+ add_bool_argument(r, argstr, discovery, true)) ||
|
||||
(!discover && hostkey &&
|
||||
- add_argument(argstr, "dhchap_secret", hostkey)) ||
|
||||
+ add_argument(r, argstr, dhchap_secret, hostkey)) ||
|
||||
(!discover && ctrlkey &&
|
||||
- add_argument(argstr, "dhchap_ctrl_secret", ctrlkey)) ||
|
||||
+ add_argument(r, argstr, dhchap_ctrl_secret, ctrlkey)) ||
|
||||
(!discover &&
|
||||
- add_int_argument(argstr, "nr_io_queues",
|
||||
+ add_int_argument(r, argstr, nr_io_queues,
|
||||
cfg->nr_io_queues, false)) ||
|
||||
(!discover &&
|
||||
- add_int_argument(argstr, "nr_write_queues",
|
||||
+ add_int_argument(r, argstr, nr_write_queues,
|
||||
cfg->nr_write_queues, false)) ||
|
||||
(!discover &&
|
||||
- add_int_argument(argstr, "nr_poll_queues",
|
||||
+ add_int_argument(r, argstr, nr_poll_queues,
|
||||
cfg->nr_poll_queues, false)) ||
|
||||
(!discover &&
|
||||
- add_int_argument(argstr, "queue_size",
|
||||
+ add_int_argument(r, argstr, queue_size,
|
||||
cfg->queue_size, false)) ||
|
||||
- add_int_argument(argstr, "keep_alive_tmo",
|
||||
+ add_int_argument(r, argstr, keep_alive_tmo,
|
||||
cfg->keep_alive_tmo, false) ||
|
||||
- add_int_argument(argstr, "reconnect_delay",
|
||||
+ add_int_argument(r, argstr, reconnect_delay,
|
||||
cfg->reconnect_delay, false) ||
|
||||
(strcmp(transport, "loop") &&
|
||||
- add_int_or_minus_one_argument(argstr, "ctrl_loss_tmo",
|
||||
+ add_int_or_minus_one_argument(r, argstr, ctrl_loss_tmo,
|
||||
cfg->ctrl_loss_tmo)) ||
|
||||
(strcmp(transport, "loop") &&
|
||||
- add_int_argument(argstr, "fast_io_fail_tmo",
|
||||
+ add_int_argument(r, argstr, fast_io_fail_tmo,
|
||||
cfg->fast_io_fail_tmo, false)) ||
|
||||
(strcmp(transport, "loop") &&
|
||||
- add_int_argument(argstr, "tos", cfg->tos, true)) ||
|
||||
- add_int_argument(argstr, "keyring", cfg->keyring, false) ||
|
||||
+ add_int_argument(r, argstr, tos, cfg->tos, true)) ||
|
||||
+ add_int_argument(r, argstr, keyring, cfg->keyring, false) ||
|
||||
(!strcmp(transport, "tcp") &&
|
||||
- add_int_argument(argstr, "tls_key", cfg->tls_key, false)) ||
|
||||
- add_bool_argument(argstr, "duplicate_connect",
|
||||
+ add_int_argument(r, argstr, tls_key, cfg->tls_key, false)) ||
|
||||
+ add_bool_argument(r, argstr, duplicate_connect,
|
||||
cfg->duplicate_connect) ||
|
||||
- add_bool_argument(argstr, "disable_sqflow",
|
||||
+ add_bool_argument(r, argstr, disable_sqflow,
|
||||
cfg->disable_sqflow) ||
|
||||
(!strcmp(transport, "tcp") &&
|
||||
- add_bool_argument(argstr, "hdr_digest", cfg->hdr_digest)) ||
|
||||
+ add_bool_argument(r, argstr, hdr_digest, cfg->hdr_digest)) ||
|
||||
(!strcmp(transport, "tcp") &&
|
||||
- add_bool_argument(argstr, "data_digest", cfg->data_digest)) ||
|
||||
+ add_bool_argument(r, argstr, data_digest, cfg->data_digest)) ||
|
||||
(!strcmp(transport, "tcp") &&
|
||||
- add_bool_argument(argstr, "tls", cfg->tls))) {
|
||||
+ add_bool_argument(r, argstr, tls, cfg->tls))) {
|
||||
free(*argstr);
|
||||
return -1;
|
||||
}
|
||||
@@ -548,6 +615,92 @@ static int build_options(nvme_host_t h, nvme_ctrl_t c, char **argstr)
|
||||
return 0;
|
||||
}
|
||||
|
||||
+#define parse_option(r, v, name) \
|
||||
+ if (!strcmp(v, stringify(name))) { \
|
||||
+ r->options->name = true; \
|
||||
+ continue; \
|
||||
+ }
|
||||
+
|
||||
+static int __nvmf_supported_options(nvme_root_t r)
|
||||
+{
|
||||
+ char buf[0x1000], *options, *p, *v;
|
||||
+ int fd, ret;
|
||||
+ size_t len;
|
||||
+
|
||||
+ if (r->options)
|
||||
+ return 0;
|
||||
+
|
||||
+ r->options = calloc(1, sizeof(*r->options));
|
||||
+ if (!r->options)
|
||||
+ return -ENOMEM;
|
||||
+
|
||||
+ fd = open(nvmf_dev, O_RDONLY);
|
||||
+ if (fd < 0) {
|
||||
+ nvme_msg(r, LOG_ERR, "Failed to open %s: %s\n",
|
||||
+ nvmf_dev, strerror(errno));
|
||||
+ return -ENVME_CONNECT_OPEN;
|
||||
+ }
|
||||
+
|
||||
+ memset(buf, 0x0, sizeof(buf));
|
||||
+ len = read(fd, buf, sizeof(buf) - 1);
|
||||
+ if (len < 0) {
|
||||
+ nvme_msg(r, LOG_ERR, "Failed to read from %s: %s\n",
|
||||
+ nvmf_dev, strerror(errno));
|
||||
+ ret = -ENVME_CONNECT_READ;
|
||||
+ goto out_close;
|
||||
+ }
|
||||
+
|
||||
+ buf[len] = '\0';
|
||||
+ options = buf;
|
||||
+
|
||||
+ nvme_msg(r, LOG_DEBUG, "kernel supports: ");
|
||||
+
|
||||
+ while ((p = strsep(&options, ",\n")) != NULL) {
|
||||
+ if (!*p)
|
||||
+ continue;
|
||||
+ v = strsep(&p, "= ");
|
||||
+ if (!v)
|
||||
+ continue;
|
||||
+ nvme_msg(r, LOG_DEBUG, "%s ", v);
|
||||
+
|
||||
+ parse_option(r, v, cntlid);
|
||||
+ parse_option(r, v, ctrl_loss_tmo);
|
||||
+ parse_option(r, v, data_digest);
|
||||
+ parse_option(r, v, dhchap_ctrl_secret);
|
||||
+ parse_option(r, v, dhchap_secret);
|
||||
+ parse_option(r, v, disable_sqflow);
|
||||
+ parse_option(r, v, discovery);
|
||||
+ parse_option(r, v, duplicate_connect);
|
||||
+ parse_option(r, v, fast_io_fail_tmo);
|
||||
+ parse_option(r, v, hdr_digest);
|
||||
+ parse_option(r, v, host_iface);
|
||||
+ parse_option(r, v, host_traddr);
|
||||
+ parse_option(r, v, hostid);
|
||||
+ parse_option(r, v, hostnqn);
|
||||
+ parse_option(r, v, instance);
|
||||
+ parse_option(r, v, keep_alive_tmo);
|
||||
+ parse_option(r, v, keyring);
|
||||
+ parse_option(r, v, nqn);
|
||||
+ parse_option(r, v, nr_io_queues);
|
||||
+ parse_option(r, v, nr_poll_queues);
|
||||
+ parse_option(r, v, nr_write_queues);
|
||||
+ parse_option(r, v, queue_size);
|
||||
+ parse_option(r, v, reconnect_delay);
|
||||
+ parse_option(r, v, tls);
|
||||
+ parse_option(r, v, tls_key);
|
||||
+ parse_option(r, v, tos);
|
||||
+ parse_option(r, v, traddr);
|
||||
+ parse_option(r, v, transport);
|
||||
+ parse_option(r, v, trsvcid);
|
||||
+ }
|
||||
+ nvme_msg(r, LOG_DEBUG, "\n");
|
||||
+ ret = 0;
|
||||
+
|
||||
+out_close:
|
||||
+ close(fd);
|
||||
+ return ret;
|
||||
+}
|
||||
+
|
||||
static int __nvmf_add_ctrl(nvme_root_t r, const char *argstr)
|
||||
{
|
||||
int ret, fd, len = strlen(argstr);
|
||||
@@ -671,6 +824,9 @@ int nvmf_add_ctrl(nvme_host_t h, nvme_ctrl_t c,
|
||||
free(traddr);
|
||||
}
|
||||
|
||||
+ ret = __nvmf_supported_options(h->r);
|
||||
+ if (ret)
|
||||
+ return ret;
|
||||
ret = build_options(h, c, &argstr);
|
||||
if (ret)
|
||||
return ret;
|
||||
diff --git a/src/nvme/private.h b/src/nvme/private.h
|
||||
index a6ded21..47ce7ca 100644
|
||||
--- a/src/nvme/private.h
|
||||
+++ b/src/nvme/private.h
|
||||
@@ -120,6 +120,38 @@ struct nvme_host {
|
||||
* value */
|
||||
};
|
||||
|
||||
+struct nvme_fabric_options {
|
||||
+ bool cntlid;
|
||||
+ bool ctrl_loss_tmo;
|
||||
+ bool data_digest;
|
||||
+ bool dhchap_ctrl_secret;
|
||||
+ bool dhchap_secret;
|
||||
+ bool disable_sqflow;
|
||||
+ bool discovery;
|
||||
+ bool duplicate_connect;
|
||||
+ bool fast_io_fail_tmo;
|
||||
+ bool hdr_digest;
|
||||
+ bool host_iface;
|
||||
+ bool host_traddr;
|
||||
+ bool hostid;
|
||||
+ bool hostnqn;
|
||||
+ bool instance;
|
||||
+ bool keep_alive_tmo;
|
||||
+ bool keyring;
|
||||
+ bool nqn;
|
||||
+ bool nr_io_queues;
|
||||
+ bool nr_poll_queues;
|
||||
+ bool nr_write_queues;
|
||||
+ bool queue_size;
|
||||
+ bool reconnect_delay;
|
||||
+ bool tls;
|
||||
+ bool tls_key;
|
||||
+ bool tos;
|
||||
+ bool traddr;
|
||||
+ bool transport;
|
||||
+ bool trsvcid;
|
||||
+};
|
||||
+
|
||||
struct nvme_root {
|
||||
char *config_file;
|
||||
struct list_head hosts;
|
||||
@@ -130,6 +162,7 @@ struct nvme_root {
|
||||
bool log_timestamp;
|
||||
bool modified;
|
||||
bool mi_probe_enabled;
|
||||
+ struct nvme_fabric_options *options;
|
||||
};
|
||||
|
||||
int nvme_set_attr(const char *dir, const char *attr, const char *value);
|
||||
diff --git a/src/nvme/tree.c b/src/nvme/tree.c
|
||||
index 6b58483..c649408 100644
|
||||
--- a/src/nvme/tree.c
|
||||
+++ b/src/nvme/tree.c
|
||||
@@ -288,6 +288,7 @@ void nvme_free_tree(nvme_root_t r)
|
||||
{
|
||||
struct nvme_host *h, *_h;
|
||||
|
||||
+ free(r->options);
|
||||
nvme_for_each_host_safe(r, h, _h)
|
||||
__nvme_free_host(h);
|
||||
if (r->config_file)
|
||||
--
|
||||
2.31.1
|
||||
|
@ -1,32 +0,0 @@
|
||||
From 49a4cd8f62d05bb4e1b6e1365bad638c366cdba9 Mon Sep 17 00:00:00 2001
|
||||
From: Greg Joyce <gjoyce@linux.ibm.com>
|
||||
Date: Tue, 23 Jul 2024 01:04:42 +0530
|
||||
Subject: [PATCH] tree: handle no address phy slot dirs
|
||||
|
||||
Not all directories have an address. Verify addr before calling
|
||||
strcmp().
|
||||
|
||||
Fixes: 42ac45359635 ("tree: Add PCI physical slot number for controller")
|
||||
Signed-off-by: Greg Joyce <gjoyce@linux.ibm.com>
|
||||
---
|
||||
src/nvme/tree.c | 4 ++++
|
||||
1 file changed, 4 insertions(+)
|
||||
|
||||
diff --git a/src/nvme/tree.c b/src/nvme/tree.c
|
||||
index 288b23c73a1b..b0ee94047634 100644
|
||||
--- a/src/nvme/tree.c
|
||||
+++ b/src/nvme/tree.c
|
||||
@@ -1867,6 +1867,10 @@ static char *nvme_ctrl_lookup_phy_slot(nvme_root_t r, const char *address)
|
||||
return NULL;
|
||||
}
|
||||
addr = nvme_get_attr(path, "address");
|
||||
+
|
||||
+ /* some directories don't have an address entry */
|
||||
+ if (!addr)
|
||||
+ continue;
|
||||
if (strcmp(addr, target_addr) == 0)
|
||||
return strdup(entry->d_name);
|
||||
}
|
||||
--
|
||||
2.43.0
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,37 @@
|
||||
From 670ec98ebc986e62267145abb059b66ac5e51380 Mon Sep 17 00:00:00 2001
|
||||
From: Tomas Bzatek <tbzatek@redhat.com>
|
||||
Date: Thu, 13 Apr 2023 15:39:28 +0200
|
||||
Subject: [PATCH] nbft: Move added symbols to LIBNVME_1_5
|
||||
|
||||
---
|
||||
src/libnvme.map | 8 ++++++--
|
||||
1 file changed, 6 insertions(+), 2 deletions(-)
|
||||
|
||||
diff --git a/src/libnvme.map b/src/libnvme.map
|
||||
index 6aa9fd0..28de595 100644
|
||||
--- a/src/libnvme.map
|
||||
+++ b/src/libnvme.map
|
||||
@@ -1,5 +1,11 @@
|
||||
# SPDX-License-Identifier: LGPL-2.1-or-later
|
||||
|
||||
+LIBNVME_1_5 {
|
||||
+ global:
|
||||
+ nvme_nbft_read;
|
||||
+ nvme_nbft_free;
|
||||
+};
|
||||
+
|
||||
LIBNVME_1_4 {
|
||||
global:
|
||||
nvme_lookup_keyring;
|
||||
@@ -7,8 +13,6 @@ LIBNVME_1_4 {
|
||||
nvme_lookup_key;
|
||||
nvme_set_keyring;
|
||||
nvme_insert_tls_key;
|
||||
- nvme_nbft_read;
|
||||
- nvme_nbft_free;
|
||||
};
|
||||
|
||||
LIBNVME_1_3 {
|
||||
--
|
||||
2.39.1
|
||||
|
@ -0,0 +1,36 @@
|
||||
From 26e4343c2ba2db7a3c5696bbf61bb87942ac02bb Mon Sep 17 00:00:00 2001
|
||||
From: Tomas Bzatek <tbzatek@redhat.com>
|
||||
Date: Thu, 13 Apr 2023 17:28:42 +0200
|
||||
Subject: [PATCH] nbft: Fix nbft_ssns_flags endianness test
|
||||
|
||||
Missing flags endianness conversion leading to ssns_ext_info
|
||||
not being parsed on s390x and armhf.
|
||||
---
|
||||
src/nvme/nbft.c | 4 ++--
|
||||
1 file changed, 2 insertions(+), 2 deletions(-)
|
||||
|
||||
diff --git a/src/nvme/nbft.c b/src/nvme/nbft.c
|
||||
index f91d21b..940dd8e 100644
|
||||
--- a/src/nvme/nbft.c
|
||||
+++ b/src/nvme/nbft.c
|
||||
@@ -169,7 +169,7 @@ static int read_ssns_exended_info(struct nbft_info *nbft,
|
||||
"invalid ID in SSNS extended info descriptor");
|
||||
verify(raw_ssns_ei->version == 1,
|
||||
"invalid version in SSNS extended info descriptor");
|
||||
- verify(le16_to_cpu(raw_ssns_ei->ssns_index) == le16_to_cpu(ssns->index),
|
||||
+ verify(le16_to_cpu(raw_ssns_ei->ssns_index) == ssns->index,
|
||||
"SSNS index doesn't match extended info descriptor index");
|
||||
|
||||
if (!(le32_to_cpu(raw_ssns_ei->flags) & NBFT_SSNS_EXT_INFO_VALID))
|
||||
@@ -292,7 +292,7 @@ static int read_ssns(struct nbft_info *nbft,
|
||||
goto fail;
|
||||
|
||||
/* SSNS extended info */
|
||||
- if (raw_ssns->flags & NBFT_SSNS_EXTENDED_INFO_IN_USE) {
|
||||
+ if (le16_to_cpu(raw_ssns->flags) & NBFT_SSNS_EXTENDED_INFO_IN_USE) {
|
||||
struct nbft_ssns_ext_info *ssns_extended_info;
|
||||
|
||||
if (!get_heap_obj(raw_ssns, ssns_extended_info_desc_obj, 0,
|
||||
--
|
||||
2.39.1
|
||||
|
@ -0,0 +1,25 @@
|
||||
From 1617d1a3f42a25a2e99073811174609abcffc34d Mon Sep 17 00:00:00 2001
|
||||
From: Tomas Bzatek <tbzatek@redhat.com>
|
||||
Date: Thu, 13 Apr 2023 18:27:39 +0200
|
||||
Subject: [PATCH] nbft: Parse the {HOSTID,HOSTNQN}_CONFIGURED flags
|
||||
|
||||
---
|
||||
src/nvme/nbft.c | 2 ++
|
||||
1 file changed, 2 insertions(+)
|
||||
|
||||
diff --git a/src/nvme/nbft.c b/src/nvme/nbft.c
|
||||
index 940dd8e..c0af2b3 100644
|
||||
--- a/src/nvme/nbft.c
|
||||
+++ b/src/nvme/nbft.c
|
||||
@@ -560,6 +560,8 @@ static int parse_raw_nbft(struct nbft_info *nbft)
|
||||
nbft->host.id = (unsigned char *) &(host->host_id);
|
||||
if (get_heap_obj(host, host_nqn_obj, 1, &nbft->host.nqn) != 0)
|
||||
return -EINVAL;
|
||||
+ nbft->host.host_id_configured = host->flags & NBFT_HOST_HOSTID_CONFIGURED;
|
||||
+ nbft->host.host_nqn_configured = host->flags & NBFT_HOST_HOSTNQN_CONFIGURED;
|
||||
|
||||
/*
|
||||
* HFI
|
||||
--
|
||||
2.39.1
|
||||
|
@ -0,0 +1,26 @@
|
||||
From 00b48dd3c217a9271c1888e8dbeb4aa9d307e5bf Mon Sep 17 00:00:00 2001
|
||||
From: Martin Belanger <martin.belanger@dell.com>
|
||||
Date: Thu, 13 Apr 2023 09:27:04 -0400
|
||||
Subject: [PATCH] nbft: Doc typo - Use nvme_nbft_free() instead of nbft_free()
|
||||
|
||||
Signed-off-by: Martin Belanger <martin.belanger@dell.com>
|
||||
---
|
||||
src/nvme/nbft.c | 2 +-
|
||||
1 file changed, 1 insertion(+), 1 deletion(-)
|
||||
|
||||
diff --git a/src/nvme/nbft.c b/src/nvme/nbft.c
|
||||
index c0af2b3..a085768 100644
|
||||
--- a/src/nvme/nbft.c
|
||||
+++ b/src/nvme/nbft.c
|
||||
@@ -663,7 +663,7 @@ void nvme_nbft_free(struct nbft_info *nbft)
|
||||
* @filename: Filename of the raw NBFT table to read.
|
||||
*
|
||||
* Read and parse the specified NBFT file into a struct nbft_info.
|
||||
- * Free with nbft_free().
|
||||
+ * Free with nvme_nbft_free().
|
||||
*
|
||||
* Return: 0 on success, errno otherwise.
|
||||
*/
|
||||
--
|
||||
2.39.1
|
||||
|
@ -0,0 +1,64 @@
|
||||
From 961606f0d0547c3eebd47b79c363ab28c95a94ea Mon Sep 17 00:00:00 2001
|
||||
From: Martin Belanger <martin.belanger@dell.com>
|
||||
Date: Fri, 14 Apr 2023 11:19:23 -0400
|
||||
Subject: [PATCH] NBFT: Remove documentation from nbft.c since it's also in
|
||||
nbft.h
|
||||
|
||||
Also, replace nbft_free() by nvme_nbft_free() in documentation
|
||||
found in nbft.h.
|
||||
|
||||
Signed-off-by: Martin Belanger <martin.belanger@dell.com>
|
||||
---
|
||||
src/nvme/nbft.c | 15 ---------------
|
||||
src/nvme/nbft.h | 2 +-
|
||||
2 files changed, 1 insertion(+), 16 deletions(-)
|
||||
|
||||
diff --git a/src/nvme/nbft.c b/src/nvme/nbft.c
|
||||
index a085768..a1e17cd 100644
|
||||
--- a/src/nvme/nbft.c
|
||||
+++ b/src/nvme/nbft.c
|
||||
@@ -626,10 +626,6 @@ static int parse_raw_nbft(struct nbft_info *nbft)
|
||||
return 0;
|
||||
}
|
||||
|
||||
-/**
|
||||
- * nvme_nbft_free() - Free the struct nbft_info and its contents
|
||||
- * @nbft: Parsed NBFT table data.
|
||||
- */
|
||||
void nvme_nbft_free(struct nbft_info *nbft)
|
||||
{
|
||||
struct nbft_info_hfi **hfi;
|
||||
@@ -656,17 +652,6 @@ void nvme_nbft_free(struct nbft_info *nbft)
|
||||
free(nbft);
|
||||
}
|
||||
|
||||
-/**
|
||||
- * nvme_nbft_read() - Read and parse contents of an ACPI NBFT table
|
||||
- *
|
||||
- * @nbft: Parsed NBFT table data.
|
||||
- * @filename: Filename of the raw NBFT table to read.
|
||||
- *
|
||||
- * Read and parse the specified NBFT file into a struct nbft_info.
|
||||
- * Free with nvme_nbft_free().
|
||||
- *
|
||||
- * Return: 0 on success, errno otherwise.
|
||||
- */
|
||||
int nvme_nbft_read(struct nbft_info **nbft, const char *filename)
|
||||
{
|
||||
__u8 *raw_nbft = NULL;
|
||||
diff --git a/src/nvme/nbft.h b/src/nvme/nbft.h
|
||||
index c3caa85..6012e16 100644
|
||||
--- a/src/nvme/nbft.h
|
||||
+++ b/src/nvme/nbft.h
|
||||
@@ -1223,7 +1223,7 @@ struct nbft_info {
|
||||
* @filename: Filename of the raw NBFT table to read.
|
||||
*
|
||||
* Read and parse the specified NBFT file into a struct nbft_info.
|
||||
- * Free with nbft_free().
|
||||
+ * Free with nvme_nbft_free().
|
||||
*
|
||||
* Return: 0 on success, errno otherwise.
|
||||
*/
|
||||
--
|
||||
2.39.1
|
||||
|
@ -0,0 +1,105 @@
|
||||
From 4204cb3c79219926f750ede2d7e8b23a3852e72d Mon Sep 17 00:00:00 2001
|
||||
From: Caleb Sander <csander@purestorage.com>
|
||||
Date: Fri, 12 May 2023 10:49:46 -0600
|
||||
Subject: [PATCH] fabrics: check genctr after getting discovery entries
|
||||
Content-type: text/plain
|
||||
|
||||
From the NVMe base spec (version 2.0c, section 5.16.1.23):
|
||||
If the host reads the Discovery Log Page using multiple Get Log Page
|
||||
commands the host should ensure that there has not been a change in the
|
||||
contents of the data. The host should read the Discovery Log Page
|
||||
contents in order (i.e., with increasing Log Page Offset values) and
|
||||
then re-read the Generation Counter after the entire log page is
|
||||
transferred. If the Generation Counter does not match the original value
|
||||
read, the host should discard the log page read as the entries may be
|
||||
inconsistent.
|
||||
|
||||
nvme_get_log_page() will issue multiple Get Log Page commands
|
||||
to fetch the discovery log page if it exceeds 4 KB.
|
||||
Since GENCTR is at the start of the log page, this ordering is possible:
|
||||
- GENCTR is read by a Get Log Page command for the first 4 KB
|
||||
- The log page is modified, changing GENCTR
|
||||
- Other Get Log Page commands read the remainder of the log page
|
||||
So the check that GENCTR hasn't changed will incorrectly pass,
|
||||
despite the log page having been modified.
|
||||
This can lead to inconsistent, missing, or duplicate log page entries.
|
||||
|
||||
Ensure a GENCTR update is not missed
|
||||
by fetching log page header again after all entries.
|
||||
|
||||
Also use NVME_LOG_PAGE_PDU_SIZE to match other nvme_get_log_page() calls
|
||||
instead of hard-coding the 4 KB max transfer length.
|
||||
And ensure LPO is correctly reset if the log page is read again.
|
||||
|
||||
Signed-off-by: Caleb Sander <csander@purestorage.com>
|
||||
---
|
||||
src/nvme/fabrics.c | 32 ++++++++++++++++++++++++++------
|
||||
1 file changed, 26 insertions(+), 6 deletions(-)
|
||||
|
||||
diff --git a/src/nvme/fabrics.c b/src/nvme/fabrics.c
|
||||
index 1762898..eaee29b 100644
|
||||
--- a/src/nvme/fabrics.c
|
||||
+++ b/src/nvme/fabrics.c
|
||||
@@ -1036,9 +1036,10 @@ static struct nvmf_discovery_log *nvme_discovery_log(nvme_ctrl_t c,
|
||||
nvme_msg(r, LOG_DEBUG, "%s: get header (try %d/%d)\n",
|
||||
name, retries, max_retries);
|
||||
args->rae = true;
|
||||
+ args->lpo = 0;
|
||||
args->len = size;
|
||||
args->log = log;
|
||||
- ret = nvme_get_log_page(fd, 4096, args);
|
||||
+ ret = nvme_get_log_page(fd, NVME_LOG_PAGE_PDU_SIZE, args);
|
||||
if (ret) {
|
||||
nvme_msg(r, LOG_INFO,
|
||||
"%s: discover try %d/%d failed, error %d\n",
|
||||
@@ -1065,15 +1066,33 @@ static struct nvmf_discovery_log *nvme_discovery_log(nvme_ctrl_t c,
|
||||
}
|
||||
|
||||
nvme_msg(r, LOG_DEBUG,
|
||||
- "%s: get header and %" PRIu64
|
||||
+ "%s: get %" PRIu64
|
||||
" records (length %d genctr %" PRIu64 ")\n",
|
||||
name, numrec, size, genctr);
|
||||
|
||||
+ args->rae = true;
|
||||
+ args->lpo = sizeof(struct nvmf_discovery_log);
|
||||
+ args->len = size - sizeof(struct nvmf_discovery_log);
|
||||
+ args->log = log->entries;
|
||||
+ ret = nvme_get_log_page(fd, NVME_LOG_PAGE_PDU_SIZE, args);
|
||||
+ if (ret) {
|
||||
+ nvme_msg(r, LOG_INFO,
|
||||
+ "%s: discover try %d/%d failed, error %d\n",
|
||||
+ name, retries, max_retries, errno);
|
||||
+ goto out_free_log;
|
||||
+ }
|
||||
+
|
||||
+ /*
|
||||
+ * If the log page was read with multiple Get Log Page commands,
|
||||
+ * genctr must be checked afterwards to ensure atomicity
|
||||
+ */
|
||||
+ nvme_msg(r, LOG_DEBUG, "%s: get header again\n", name);
|
||||
+
|
||||
args->rae = false;
|
||||
- args->len = size;
|
||||
+ args->lpo = 0;
|
||||
+ args->len = sizeof(struct nvmf_discovery_log);
|
||||
args->log = log;
|
||||
- ret = nvme_get_log_page(fd, 4096, args);
|
||||
-
|
||||
+ ret = nvme_get_log_page(fd, NVME_LOG_PAGE_PDU_SIZE, args);
|
||||
if (ret) {
|
||||
nvme_msg(r, LOG_INFO,
|
||||
"%s: discover try %d/%d failed, error %d\n",
|
||||
@@ -1088,7 +1107,8 @@ static struct nvmf_discovery_log *nvme_discovery_log(nvme_ctrl_t c,
|
||||
errno = EAGAIN;
|
||||
} else if (numrec != le64_to_cpu(log->numrec)) {
|
||||
nvme_msg(r, LOG_INFO,
|
||||
- "%s: could only fetch %" PRIu64 " of %" PRIu64 " records\n",
|
||||
+ "%s: numrec changed unexpectedly "
|
||||
+ "from %" PRIu64 " to %" PRIu64 "\n",
|
||||
name, numrec, le64_to_cpu(log->numrec));
|
||||
errno = EBADSLT;
|
||||
} else {
|
||||
--
|
||||
2.39.3
|
||||
|
@ -0,0 +1,49 @@
|
||||
From 777b52152f8137048b72edc12ad2ae998df4c30a Mon Sep 17 00:00:00 2001
|
||||
From: Caleb Sander <csander@purestorage.com>
|
||||
Date: Fri, 12 May 2023 09:43:22 -0600
|
||||
Subject: [PATCH] ioctl: fix RAE bit on last Get Log Page command
|
||||
Content-type: text/plain
|
||||
|
||||
If nvme_get_log_page() requires multiple Get Log Page commands
|
||||
because the total log length exceeds the transfer length,
|
||||
args->rae is overwritten, causing the RAE bit to be set in all commands.
|
||||
Retrieve the value of args->rae before overwriting it
|
||||
so the RAE bit is set as requested in the last command.
|
||||
|
||||
Fixes: c23dbd4 ("linux: Change nvme_get_log_page to use nvme_get_log_args parm")
|
||||
Signed-off-by: Caleb Sander <csander@purestorage.com>
|
||||
---
|
||||
src/nvme/ioctl.c | 7 ++-----
|
||||
1 file changed, 2 insertions(+), 5 deletions(-)
|
||||
|
||||
diff --git a/src/nvme/ioctl.c b/src/nvme/ioctl.c
|
||||
index 6f9d724..b9710b3 100644
|
||||
--- a/src/nvme/ioctl.c
|
||||
+++ b/src/nvme/ioctl.c
|
||||
@@ -434,7 +434,7 @@ int nvme_get_log_page(int fd, __u32 xfer_len, struct nvme_get_log_args *args)
|
||||
{
|
||||
__u64 offset = 0, xfer, data_len = args->len;
|
||||
__u64 start = args->lpo;
|
||||
- bool retain = true;
|
||||
+ bool retain = args->rae;
|
||||
void *ptr = args->log;
|
||||
int ret;
|
||||
|
||||
@@ -454,13 +454,10 @@ int nvme_get_log_page(int fd, __u32 xfer_len, struct nvme_get_log_args *args)
|
||||
* last portion of this log page so the data remains latched
|
||||
* during the fetch sequence.
|
||||
*/
|
||||
- if (offset + xfer == data_len)
|
||||
- retain = args->rae;
|
||||
-
|
||||
args->lpo = start + offset;
|
||||
args->len = xfer;
|
||||
args->log = ptr;
|
||||
- args->rae = retain;
|
||||
+ args->rae = offset + xfer < data_len || retain;
|
||||
ret = nvme_get_log(args);
|
||||
if (ret)
|
||||
return ret;
|
||||
--
|
||||
2.39.3
|
||||
|
@ -1,609 +0,0 @@
|
||||
From 6829a6903c7a32a7b4dd32597c7f2a811b5a58bb Mon Sep 17 00:00:00 2001
|
||||
From: Tomas Bzatek <tbzatek@redhat.com>
|
||||
Date: Wed, 17 Apr 2024 18:04:34 +0200
|
||||
Subject: [PATCH 1/3] fabrics: Introduce simple URI parser
|
||||
|
||||
A very simple URI parser implementing URI syntax described
|
||||
in the Boot Specification, rev. 1.0.
|
||||
|
||||
Signed-off-by: Tomas Bzatek <tbzatek@redhat.com>
|
||||
---
|
||||
src/libnvme.map | 2 +
|
||||
src/nvme/fabrics.c | 116 +++++++++++++++++++++++++++++++++++++++++++++
|
||||
src/nvme/fabrics.h | 44 +++++++++++++++++
|
||||
3 files changed, 162 insertions(+)
|
||||
|
||||
diff -up libnvme-1.9/src/libnvme.map.bak libnvme-1.9/src/libnvme.map
|
||||
--- libnvme-1.9/src/libnvme.map.bak 2024-05-03 14:08:20.000000000 +0200
|
||||
+++ libnvme-1.9/src/libnvme.map 2024-06-21 15:46:53.920532333 +0200
|
||||
@@ -10,6 +10,8 @@ LIBNVME_1.9 {
|
||||
nvme_submit_passthru64;
|
||||
nvme_update_key;
|
||||
nvme_ctrl_get_cntlid;
|
||||
+ nvme_parse_uri;
|
||||
+ nvme_free_uri;
|
||||
};
|
||||
|
||||
LIBNVME_1_8 {
|
||||
diff --git a/src/nvme/fabrics.c b/src/nvme/fabrics.c
|
||||
index 6738e9dc..324a7321 100644
|
||||
--- a/src/nvme/fabrics.c
|
||||
+++ b/src/nvme/fabrics.c
|
||||
@@ -1703,3 +1703,119 @@ int nvmf_register_ctrl(nvme_ctrl_t c, enum nvmf_dim_tas tas, __u32 *result)
|
||||
*/
|
||||
return nvmf_dim(c, tas, NVMF_TRTYPE_TCP, nvme_get_adrfam(c), "", NULL, result);
|
||||
}
|
||||
+
|
||||
+struct nvme_fabrics_uri *nvme_parse_uri(const char *str)
|
||||
+{
|
||||
+ struct nvme_fabrics_uri *uri;
|
||||
+ _cleanup_free_ char *scheme = NULL;
|
||||
+ _cleanup_free_ char *authority = NULL;
|
||||
+ _cleanup_free_ char *path = NULL;
|
||||
+ const char *host;
|
||||
+ int i;
|
||||
+
|
||||
+ /* As defined in Boot Specification rev. 1.0:
|
||||
+ *
|
||||
+ * section 1.5.7: NVMe-oF URI Format
|
||||
+ * nvme+tcp://192.168.1.1:4420/
|
||||
+ * nvme+tcp://[FE80::1010]:4420/
|
||||
+ *
|
||||
+ * section 3.1.2.5.3: DHCP Root-Path - a hierarchical NVMe-oF URI Format
|
||||
+ * NVME<+PROTOCOL>://<SERVERNAME/IP>[:TRANSPORT PORT]/<SUBSYS NQN>/<NID>
|
||||
+ * or
|
||||
+ * NVME<+PROTOCOL>://<DISCOVERY CONTROLLER ADDRESS>[:DISCOVERY-
|
||||
+ * -CONTROLLER PORT]/NQN.2014-08.ORG.NVMEXPRESS.DISCOVERY/<NID>
|
||||
+ */
|
||||
+
|
||||
+ /* TODO: unescape? */
|
||||
+
|
||||
+ uri = calloc(1, sizeof(struct nvme_fabrics_uri));
|
||||
+ if (!uri)
|
||||
+ return NULL;
|
||||
+
|
||||
+ if (sscanf(str, "%m[^:/]://%m[^/?#]%ms",
|
||||
+ &scheme, &authority, &path) < 2) {
|
||||
+ nvme_free_uri(uri);
|
||||
+ errno = EINVAL;
|
||||
+ return NULL;
|
||||
+ }
|
||||
+
|
||||
+ if (sscanf(scheme, "%m[^+]+%ms",
|
||||
+ &uri->scheme, &uri->protocol) < 1) {
|
||||
+ nvme_free_uri(uri);
|
||||
+ errno = EINVAL;
|
||||
+ return NULL;
|
||||
+ }
|
||||
+
|
||||
+ /* split userinfo */
|
||||
+ host = strrchr(authority, '@');
|
||||
+ if (host) {
|
||||
+ host++;
|
||||
+ uri->userinfo = strndup(authority, host - authority);
|
||||
+ } else
|
||||
+ host = authority;
|
||||
+
|
||||
+ /* try matching IPv6 address first */
|
||||
+ if (sscanf(host, "[%m[^]]]:%d",
|
||||
+ &uri->host, &uri->port) < 1)
|
||||
+ /* treat it as IPv4/hostname */
|
||||
+ if (sscanf(host, "%m[^:]:%d",
|
||||
+ &uri->host, &uri->port) < 1) {
|
||||
+ nvme_free_uri(uri);
|
||||
+ errno = EINVAL;
|
||||
+ return NULL;
|
||||
+ }
|
||||
+
|
||||
+ /* split path into elements */
|
||||
+ if (path) {
|
||||
+ char *e, *elem;
|
||||
+
|
||||
+ /* separate the fragment */
|
||||
+ e = strrchr(path, '#');
|
||||
+ if (e) {
|
||||
+ uri->fragment = strdup(e + 1);
|
||||
+ *e = '\0';
|
||||
+ }
|
||||
+ /* separate the query string */
|
||||
+ e = strrchr(path, '?');
|
||||
+ if (e) {
|
||||
+ uri->query = strdup(e + 1);
|
||||
+ *e = '\0';
|
||||
+ }
|
||||
+
|
||||
+ /* count elements first */
|
||||
+ for (i = 0, e = path; *e; e++)
|
||||
+ if (*e == '/' && *(e + 1) != '/')
|
||||
+ i++;
|
||||
+ uri->path_segments = calloc(i + 2, sizeof(char *));
|
||||
+
|
||||
+ i = 0;
|
||||
+ elem = strtok_r(path, "/", &e);
|
||||
+ if (elem)
|
||||
+ uri->path_segments[i++] = strdup(elem);
|
||||
+ while (elem && strlen(elem)) {
|
||||
+ elem = strtok_r(NULL, "/", &e);
|
||||
+ if (elem)
|
||||
+ uri->path_segments[i++] = strdup(elem);
|
||||
+ }
|
||||
+ }
|
||||
+
|
||||
+ return uri;
|
||||
+}
|
||||
+
|
||||
+void nvme_free_uri(struct nvme_fabrics_uri *uri)
|
||||
+{
|
||||
+ char **s;
|
||||
+
|
||||
+ if (!uri)
|
||||
+ return;
|
||||
+ free(uri->scheme);
|
||||
+ free(uri->protocol);
|
||||
+ free(uri->userinfo);
|
||||
+ free(uri->host);
|
||||
+ for (s = uri->path_segments; s && *s; s++)
|
||||
+ free(*s);
|
||||
+ free(uri->path_segments);
|
||||
+ free(uri->query);
|
||||
+ free(uri->fragment);
|
||||
+ free(uri);
|
||||
+}
|
||||
diff --git a/src/nvme/fabrics.h b/src/nvme/fabrics.h
|
||||
index 4ebeb35e..3be35310 100644
|
||||
--- a/src/nvme/fabrics.h
|
||||
+++ b/src/nvme/fabrics.h
|
||||
@@ -67,6 +67,28 @@ struct nvme_fabrics_config {
|
||||
bool concat;
|
||||
};
|
||||
|
||||
+/**
|
||||
+ * struct nvme_fabrics_uri - Parsed URI structure
|
||||
+ * @scheme: Scheme name (typically 'nvme')
|
||||
+ * @protocol: Optional protocol/transport (e.g. 'tcp')
|
||||
+ * @userinfo: Optional user information component of the URI authority
|
||||
+ * @host: Host transport address
|
||||
+ * @port: The port subcomponent or 0 if not specified
|
||||
+ * @path_segments: NULL-terminated array of path segments
|
||||
+ * @query: Optional query string component (separated by '?')
|
||||
+ * @fragment: Optional fragment identifier component (separated by '#')
|
||||
+ */
|
||||
+struct nvme_fabrics_uri {
|
||||
+ char *scheme;
|
||||
+ char *protocol;
|
||||
+ char *userinfo;
|
||||
+ char *host;
|
||||
+ int port;
|
||||
+ char **path_segments;
|
||||
+ char *query;
|
||||
+ char *fragment;
|
||||
+};
|
||||
+
|
||||
/**
|
||||
* nvmf_trtype_str() - Decode TRTYPE field
|
||||
* @trtype: value to be decoded
|
||||
@@ -324,4 +346,26 @@ bool nvmf_is_registration_supported(nvme_ctrl_t c);
|
||||
*/
|
||||
int nvmf_register_ctrl(nvme_ctrl_t c, enum nvmf_dim_tas tas, __u32 *result);
|
||||
|
||||
+/**
|
||||
+ * nvme_parse_uri() - Parse the URI string
|
||||
+ * @str: URI string
|
||||
+ *
|
||||
+ * Parse the URI string as defined in the NVM Express Boot Specification.
|
||||
+ * Supported URI elements looks as follows:
|
||||
+ *
|
||||
+ * nvme+tcp://user@host:port/subsys_nqn/nid?query=val#fragment
|
||||
+ *
|
||||
+ * Return: &nvme_fabrics_uri structure on success; NULL on failure with errno
|
||||
+ * set.
|
||||
+ */
|
||||
+struct nvme_fabrics_uri *nvme_parse_uri(const char *str);
|
||||
+
|
||||
+/**
|
||||
+ * nvme_free_uri() - Free the URI structure
|
||||
+ * @uri: &nvme_fabrics_uri structure
|
||||
+ *
|
||||
+ * Free an &nvme_fabrics_uri structure.
|
||||
+ */
|
||||
+void nvme_free_uri(struct nvme_fabrics_uri *uri);
|
||||
+
|
||||
#endif /* _LIBNVME_FABRICS_H */
|
||||
|
||||
From 27ea060ef42c76ed1c88d92c435b88b481e7defb Mon Sep 17 00:00:00 2001
|
||||
From: Tomas Bzatek <tbzatek@redhat.com>
|
||||
Date: Wed, 17 Apr 2024 18:06:23 +0200
|
||||
Subject: [PATCH 2/3] tests: Add uriparser tests
|
||||
|
||||
Simple testcase both for valid and malformed URI strings.
|
||||
|
||||
Signed-off-by: Tomas Bzatek <tbzatek@redhat.com>
|
||||
---
|
||||
test/meson.build | 9 ++
|
||||
test/uriparser.c | 208 +++++++++++++++++++++++++++++++++++++++++++++++
|
||||
2 files changed, 217 insertions(+)
|
||||
create mode 100644 test/uriparser.c
|
||||
|
||||
diff --git a/test/meson.build b/test/meson.build
|
||||
index 93e69991..55992df7 100644
|
||||
--- a/test/meson.build
|
||||
+++ b/test/meson.build
|
||||
@@ -66,6 +66,15 @@ uuid = executable(
|
||||
|
||||
test('uuid', uuid)
|
||||
|
||||
+uriparser = executable(
|
||||
+ 'test-uriparser',
|
||||
+ ['uriparser.c'],
|
||||
+ dependencies: libnvme_dep,
|
||||
+ include_directories: [incdir, internal_incdir]
|
||||
+)
|
||||
+
|
||||
+test('uriparser', uriparser)
|
||||
+
|
||||
if conf.get('HAVE_NETDB')
|
||||
mock_ifaddrs = library(
|
||||
'mock-ifaddrs',
|
||||
diff --git a/test/uriparser.c b/test/uriparser.c
|
||||
new file mode 100644
|
||||
index 00000000..cf26bfd2
|
||||
--- /dev/null
|
||||
+++ b/test/uriparser.c
|
||||
@@ -0,0 +1,208 @@
|
||||
+// SPDX-License-Identifier: LGPL-2.1-or-later
|
||||
+/**
|
||||
+ * This file is part of libnvme.
|
||||
+ * Copyright (c) 2024 Tomas Bzatek <tbzatek@redhat.com>
|
||||
+ */
|
||||
+
|
||||
+#include <assert.h>
|
||||
+#include <string.h>
|
||||
+#include <stdbool.h>
|
||||
+#include <stdlib.h>
|
||||
+
|
||||
+#include <ccan/array_size/array_size.h>
|
||||
+
|
||||
+#include <libnvme.h>
|
||||
+#include <nvme/private.h>
|
||||
+
|
||||
+struct test_data {
|
||||
+ const char *uri;
|
||||
+ /* parsed data */
|
||||
+ const char *scheme;
|
||||
+ const char *host;
|
||||
+ const char *user;
|
||||
+ const char *proto;
|
||||
+ int port;
|
||||
+ const char *path[7];
|
||||
+ const char *query;
|
||||
+ const char *frag;
|
||||
+};
|
||||
+
|
||||
+static struct test_data test_data[] = {
|
||||
+ { "nvme://192.168.1.1", "nvme", "192.168.1.1" },
|
||||
+ { "nvme://192.168.1.1/", "nvme", "192.168.1.1" },
|
||||
+ { "nvme://192.168.1.1:1234", "nvme", "192.168.1.1", .port = 1234 },
|
||||
+ { "nvme://192.168.1.1:1234/", "nvme", "192.168.1.1", .port = 1234 },
|
||||
+ { "nvme+tcp://192.168.1.1", "nvme", "192.168.1.1", .proto = "tcp" },
|
||||
+ { "nvme+rdma://192.168.1.1/", "nvme", "192.168.1.1", .proto = "rdma" },
|
||||
+ { "nvme+tcp://192.168.1.1:1234",
|
||||
+ "nvme", "192.168.1.1", .proto = "tcp", .port = 1234 },
|
||||
+ { "nvme+tcp://192.168.1.1:1234/",
|
||||
+ "nvme", "192.168.1.1", .proto = "tcp", .port = 1234 },
|
||||
+ { "nvme+tcp://192.168.1.1:4420/path",
|
||||
+ "nvme", "192.168.1.1", .proto = "tcp", .port = 4420,
|
||||
+ .path = { "path", NULL }},
|
||||
+ { "nvme+tcp://192.168.1.1/path/",
|
||||
+ "nvme", "192.168.1.1", .proto = "tcp", .path = { "path", NULL }},
|
||||
+ { "nvme+tcp://192.168.1.1:4420/p1/p2/p3",
|
||||
+ "nvme", "192.168.1.1", .proto = "tcp", .port = 4420,
|
||||
+ .path = { "p1", "p2", "p3", NULL }},
|
||||
+ { "nvme+tcp://192.168.1.1:4420/p1/p2/p3/",
|
||||
+ "nvme", "192.168.1.1", .proto = "tcp", .port = 4420,
|
||||
+ .path = { "p1", "p2", "p3", NULL }},
|
||||
+ { "nvme+tcp://192.168.1.1:4420//p1//p2/////p3",
|
||||
+ "nvme", "192.168.1.1", .proto = "tcp", .port = 4420,
|
||||
+ .path = { "p1", "p2", "p3", NULL }},
|
||||
+ { "nvme+tcp://192.168.1.1:4420//p1//p2/////p3/",
|
||||
+ "nvme", "192.168.1.1", .proto = "tcp", .port = 4420,
|
||||
+ .path = { "p1", "p2", "p3", NULL }},
|
||||
+ { "nvme://[fe80::1010]", "nvme", "fe80::1010" },
|
||||
+ { "nvme://[fe80::1010]/", "nvme", "fe80::1010" },
|
||||
+ { "nvme://[fe80::1010]:1234", "nvme", "fe80::1010", .port = 1234 },
|
||||
+ { "nvme://[fe80::1010]:1234/", "nvme", "fe80::1010", .port = 1234 },
|
||||
+ { "nvme+tcp://[fe80::1010]", "nvme", "fe80::1010", .proto = "tcp" },
|
||||
+ { "nvme+rdma://[fe80::1010]/", "nvme", "fe80::1010", .proto = "rdma" },
|
||||
+ { "nvme+tcp://[fe80::1010]:1234",
|
||||
+ "nvme", "fe80::1010", .proto = "tcp", .port = 1234 },
|
||||
+ { "nvme+tcp://[fe80::1010]:1234/",
|
||||
+ "nvme", "fe80::1010", .proto = "tcp", .port = 1234 },
|
||||
+ { "nvme+tcp://[fe80::1010]:4420/path",
|
||||
+ "nvme", "fe80::1010", .proto = "tcp", .port = 4420,
|
||||
+ .path = { "path", NULL }},
|
||||
+ { "nvme+tcp://[fe80::1010]/path/",
|
||||
+ "nvme", "fe80::1010", .proto = "tcp", .path = { "path", NULL }},
|
||||
+ { "nvme+tcp://[fe80::1010]:4420/p1/p2/p3",
|
||||
+ "nvme", "fe80::1010", .proto = "tcp", .port = 4420,
|
||||
+ .path = { "p1", "p2", "p3", NULL }},
|
||||
+ { "nvme+tcp://[fe80::fc7d:8cff:fe5b:962e]:666/p1/p2/p3/",
|
||||
+ "nvme", "fe80::fc7d:8cff:fe5b:962e", .proto = "tcp", .port = 666,
|
||||
+ .path = { "p1", "p2", "p3", NULL }},
|
||||
+ { "nvme://h?query", "nvme", "h", .query = "query" },
|
||||
+ { "nvme://h/?query", "nvme", "h", .query = "query" },
|
||||
+ { "nvme://h/x?query",
|
||||
+ "nvme", "h", .path = { "x" }, .query = "query" },
|
||||
+ { "nvme://h/p1/?query",
|
||||
+ "nvme", "h", .path = { "p1" }, .query = "query" },
|
||||
+ { "nvme://h/p1/x?query",
|
||||
+ "nvme", "h", .path = { "p1", "x" }, .query = "query" },
|
||||
+ { "nvme://h#fragment", "nvme", "h", .frag = "fragment" },
|
||||
+ { "nvme://h/#fragment", "nvme", "h", .frag = "fragment" },
|
||||
+ { "nvme://h/x#fragment",
|
||||
+ "nvme", "h", .path = { "x" }, .frag = "fragment" },
|
||||
+ { "nvme://h/p1/#fragment",
|
||||
+ "nvme", "h", .path = { "p1" }, .frag = "fragment" },
|
||||
+ { "nvme://h/p1/x#fragment",
|
||||
+ "nvme", "h", .path = { "p1", "x" }, .frag = "fragment" },
|
||||
+ { "nvme://h/?query#fragment",
|
||||
+ "nvme", "h", .query = "query", .frag = "fragment" },
|
||||
+ { "nvme://h/x?query#fragment",
|
||||
+ "nvme", "h", .path = { "x" }, .query = "query", .frag = "fragment" },
|
||||
+ { "nvme://h/p1/?query#fragment",
|
||||
+ "nvme", "h", .path = { "p1" }, .query = "query", .frag = "fragment" },
|
||||
+ { "nvme://h/p1/x?query#fragment",
|
||||
+ "nvme", "h", .path = { "p1", "x" }, .query = "query",
|
||||
+ .frag = "fragment" },
|
||||
+ { "nvme://h/#fragment?query",
|
||||
+ "nvme", "h", .frag = "fragment?query" },
|
||||
+ { "nvme://h/x#fragment?query",
|
||||
+ "nvme", "h", .path = { "x" }, .frag = "fragment?query" },
|
||||
+ { "nvme://h/p1/#fragment?query",
|
||||
+ "nvme", "h", .path = { "p1" }, .frag = "fragment?query" },
|
||||
+ { "nvme://h/p1/x#fragment?query",
|
||||
+ "nvme", "h", .path = { "p1", "x" }, .frag = "fragment?query" },
|
||||
+ { "nvme://user@h", "nvme", "h", .user = "user" },
|
||||
+ { "nvme://user@h/", "nvme", "h", .user = "user" },
|
||||
+ { "nvme://user:pass@h/", "nvme", "h", .user = "user:pass" },
|
||||
+ { "nvme://[fe80::1010]@h/", "nvme", "h", .user = "[fe80::1010]" },
|
||||
+ { "nvme://u[fe80::1010]@h/", "nvme", "h", .user = "u[fe80::1010]" },
|
||||
+ { "nvme://u[aa:bb::cc]@h/", "nvme", "h", .user = "u[aa:bb::cc]" },
|
||||
+ { "nvme+rdma://u[aa:bb::cc]@[aa:bb::cc]:12345/p1/x?q=val#fr",
|
||||
+ "nvme", "aa:bb::cc", .proto = "rdma", .port = 12345,
|
||||
+ .user = "u[aa:bb::cc]", .path = { "p1", "x" },
|
||||
+ .query = "q=val", .frag = "fr" },
|
||||
+};
|
||||
+
|
||||
+const char *test_data_bad[] = {
|
||||
+ "",
|
||||
+ " ",
|
||||
+ "nonsense",
|
||||
+ "vnme:",
|
||||
+ "vnme:/",
|
||||
+ "vnme://",
|
||||
+ "vnme:///",
|
||||
+ "vnme+foo://",
|
||||
+ "nvme:hostname/",
|
||||
+ "nvme:/hostname/",
|
||||
+ "nvme:///hostname/",
|
||||
+ "nvme+foo:///hostname/",
|
||||
+};
|
||||
+
|
||||
+static void test_uriparser(void)
|
||||
+{
|
||||
+ printf("Testing URI parser:\n");
|
||||
+ for (int i = 0; i < ARRAY_SIZE(test_data); i++) {
|
||||
+ const struct test_data *d = &test_data[i];
|
||||
+ struct nvme_fabrics_uri *parsed_data;
|
||||
+ char **s;
|
||||
+ int i;
|
||||
+
|
||||
+ printf(" '%s'...", d->uri);
|
||||
+ parsed_data = nvme_parse_uri(d->uri);
|
||||
+ assert(parsed_data);
|
||||
+
|
||||
+ assert(strcmp(d->scheme, parsed_data->scheme) == 0);
|
||||
+ if (d->proto) {
|
||||
+ assert(parsed_data->protocol != NULL);
|
||||
+ assert(strcmp(d->proto, parsed_data->protocol) == 0);
|
||||
+ } else
|
||||
+ assert(d->proto == parsed_data->protocol);
|
||||
+ assert(strcmp(d->host, parsed_data->host) == 0);
|
||||
+ assert(d->port == parsed_data->port);
|
||||
+
|
||||
+ if (!parsed_data->path_segments)
|
||||
+ assert(d->path[0] == NULL);
|
||||
+ else {
|
||||
+ for (i = 0, s = parsed_data->path_segments;
|
||||
+ s && *s; s++, i++) {
|
||||
+ assert(d->path[i] != NULL);
|
||||
+ assert(strcmp(d->path[i], *s) == 0);
|
||||
+ }
|
||||
+ /* trailing NULL element */
|
||||
+ assert(d->path[i] == parsed_data->path_segments[i]);
|
||||
+ }
|
||||
+ if (d->query) {
|
||||
+ assert(parsed_data->query != NULL);
|
||||
+ assert(strcmp(d->query, parsed_data->query) == 0);
|
||||
+ } else
|
||||
+ assert(d->query == parsed_data->query);
|
||||
+ if (d->frag) {
|
||||
+ assert(parsed_data->fragment != NULL);
|
||||
+ assert(strcmp(d->frag, parsed_data->fragment) == 0);
|
||||
+ } else
|
||||
+ assert(d->frag == parsed_data->fragment);
|
||||
+ nvme_free_uri(parsed_data);
|
||||
+ printf(" OK\n");
|
||||
+ }
|
||||
+}
|
||||
+
|
||||
+static void test_uriparser_bad(void)
|
||||
+{
|
||||
+ printf("Testing malformed URI strings:\n");
|
||||
+ for (int i = 0; i < ARRAY_SIZE(test_data_bad); i++) {
|
||||
+ struct nvme_fabrics_uri *parsed_data;
|
||||
+
|
||||
+ printf(" '%s'...", test_data_bad[i]);
|
||||
+ parsed_data = nvme_parse_uri(test_data_bad[i]);
|
||||
+ assert(parsed_data == NULL);
|
||||
+ printf(" OK\n");
|
||||
+ }
|
||||
+}
|
||||
+
|
||||
+int main(int argc, char *argv[])
|
||||
+{
|
||||
+ test_uriparser();
|
||||
+ test_uriparser_bad();
|
||||
+
|
||||
+ fflush(stdout);
|
||||
+
|
||||
+ return 0;
|
||||
+}
|
||||
|
||||
From b2044e8f416b54df34e0d162b59ca0745db92927 Mon Sep 17 00:00:00 2001
|
||||
From: Tomas Bzatek <tbzatek@redhat.com>
|
||||
Date: Mon, 13 May 2024 17:38:25 +0200
|
||||
Subject: [PATCH 3/3] fabrics: Unescape URI elements
|
||||
|
||||
This adds support for unescaping percent-encoded URI parts.
|
||||
|
||||
Signed-off-by: Tomas Bzatek <tbzatek@redhat.com>
|
||||
---
|
||||
src/nvme/fabrics.c | 47 +++++++++++++++++++++++++++++++++++++---------
|
||||
test/uriparser.c | 13 +++++++++++++
|
||||
2 files changed, 51 insertions(+), 9 deletions(-)
|
||||
|
||||
diff --git a/src/nvme/fabrics.c b/src/nvme/fabrics.c
|
||||
index 324a7321..e5921f8b 100644
|
||||
--- a/src/nvme/fabrics.c
|
||||
+++ b/src/nvme/fabrics.c
|
||||
@@ -1704,12 +1704,41 @@ int nvmf_register_ctrl(nvme_ctrl_t c, enum nvmf_dim_tas tas, __u32 *result)
|
||||
return nvmf_dim(c, tas, NVMF_TRTYPE_TCP, nvme_get_adrfam(c), "", NULL, result);
|
||||
}
|
||||
|
||||
+#define IS_XDIGIT(c) ((c >= '0' && c <= '9') || \
|
||||
+ (c >= 'A' && c <= 'F') || \
|
||||
+ (c >= 'a' && c <= 'f'))
|
||||
+#define XDIGIT_VAL(c) ((c >= '0' && c <= '9') ? c - '0' : ( \
|
||||
+ (c >= 'A' && c <= 'F') ? c - 'A' + 10 : c - 'a' + 10))
|
||||
+
|
||||
+/* returns newly allocated string */
|
||||
+static char *unescape_uri(const char *str, int len)
|
||||
+{
|
||||
+ char *dst;
|
||||
+ int l;
|
||||
+ int i, j;
|
||||
+
|
||||
+ l = len > 0 ? len : strlen(str);
|
||||
+ dst = malloc(l + 1);
|
||||
+ for (i = 0, j = 0; i < l; i++, j++) {
|
||||
+ if (str[i] == '%' && i + 2 < l &&
|
||||
+ IS_XDIGIT(str[i + 1]) && IS_XDIGIT(str[i + 2])) {
|
||||
+ dst[j] = (XDIGIT_VAL(str[i + 1]) << 4) +
|
||||
+ XDIGIT_VAL(str[i + 2]);
|
||||
+ i += 2;
|
||||
+ } else
|
||||
+ dst[j] = str[i];
|
||||
+ }
|
||||
+ dst[j] = '\0';
|
||||
+ return dst;
|
||||
+}
|
||||
+
|
||||
struct nvme_fabrics_uri *nvme_parse_uri(const char *str)
|
||||
{
|
||||
struct nvme_fabrics_uri *uri;
|
||||
_cleanup_free_ char *scheme = NULL;
|
||||
_cleanup_free_ char *authority = NULL;
|
||||
_cleanup_free_ char *path = NULL;
|
||||
+ _cleanup_free_ char *h = NULL;
|
||||
const char *host;
|
||||
int i;
|
||||
|
||||
@@ -1726,8 +1755,6 @@ struct nvme_fabrics_uri *nvme_parse_uri(const char *str)
|
||||
* -CONTROLLER PORT]/NQN.2014-08.ORG.NVMEXPRESS.DISCOVERY/<NID>
|
||||
*/
|
||||
|
||||
- /* TODO: unescape? */
|
||||
-
|
||||
uri = calloc(1, sizeof(struct nvme_fabrics_uri));
|
||||
if (!uri)
|
||||
return NULL;
|
||||
@@ -1750,20 +1777,22 @@ struct nvme_fabrics_uri *nvme_parse_uri(const char *str)
|
||||
host = strrchr(authority, '@');
|
||||
if (host) {
|
||||
host++;
|
||||
- uri->userinfo = strndup(authority, host - authority);
|
||||
+ uri->userinfo = unescape_uri(authority, host - authority);
|
||||
} else
|
||||
host = authority;
|
||||
|
||||
/* try matching IPv6 address first */
|
||||
if (sscanf(host, "[%m[^]]]:%d",
|
||||
- &uri->host, &uri->port) < 1)
|
||||
+ &uri->host, &uri->port) < 1) {
|
||||
/* treat it as IPv4/hostname */
|
||||
if (sscanf(host, "%m[^:]:%d",
|
||||
- &uri->host, &uri->port) < 1) {
|
||||
+ &h, &uri->port) < 1) {
|
||||
nvme_free_uri(uri);
|
||||
errno = EINVAL;
|
||||
return NULL;
|
||||
}
|
||||
+ uri->host = unescape_uri(h, 0);
|
||||
+ }
|
||||
|
||||
/* split path into elements */
|
||||
if (path) {
|
||||
@@ -1772,13 +1801,13 @@ struct nvme_fabrics_uri *nvme_parse_uri(const char *str)
|
||||
/* separate the fragment */
|
||||
e = strrchr(path, '#');
|
||||
if (e) {
|
||||
- uri->fragment = strdup(e + 1);
|
||||
+ uri->fragment = unescape_uri(e + 1, 0);
|
||||
*e = '\0';
|
||||
}
|
||||
/* separate the query string */
|
||||
e = strrchr(path, '?');
|
||||
if (e) {
|
||||
- uri->query = strdup(e + 1);
|
||||
+ uri->query = unescape_uri(e + 1, 0);
|
||||
*e = '\0';
|
||||
}
|
||||
|
||||
@@ -1791,11 +1820,11 @@ struct nvme_fabrics_uri *nvme_parse_uri(const char *str)
|
||||
i = 0;
|
||||
elem = strtok_r(path, "/", &e);
|
||||
if (elem)
|
||||
- uri->path_segments[i++] = strdup(elem);
|
||||
+ uri->path_segments[i++] = unescape_uri(elem, 0);
|
||||
while (elem && strlen(elem)) {
|
||||
elem = strtok_r(NULL, "/", &e);
|
||||
if (elem)
|
||||
- uri->path_segments[i++] = strdup(elem);
|
||||
+ uri->path_segments[i++] = unescape_uri(elem, 0);
|
||||
}
|
||||
}
|
||||
|
||||
diff --git a/test/uriparser.c b/test/uriparser.c
|
||||
index cf26bfd2..09b2a732 100644
|
||||
--- a/test/uriparser.c
|
||||
+++ b/test/uriparser.c
|
||||
@@ -119,6 +119,19 @@ static struct test_data test_data[] = {
|
||||
"nvme", "aa:bb::cc", .proto = "rdma", .port = 12345,
|
||||
.user = "u[aa:bb::cc]", .path = { "p1", "x" },
|
||||
.query = "q=val", .frag = "fr" },
|
||||
+ { "nvme://ex%5Cmp%3Ae", "nvme", "ex\\mp:e" },
|
||||
+ { "nvme://ex%5Cmp%3Ae.com/", "nvme", "ex\\mp:e.com" },
|
||||
+ { "nvme://u%24er@ex%5Cmp%3Ae.com/", "nvme", "ex\\mp:e.com",
|
||||
+ .user = "u$er" },
|
||||
+ { "nvme+tcp://ex%5Cmp%3Ae.com:1234",
|
||||
+ "nvme", "ex\\mp:e.com", .proto = "tcp", .port = 1234 },
|
||||
+ { "nvme+tcp://ex%5Cmp%3Ae.com:1234/p1/ex%3Camp%3Ele/p3",
|
||||
+ "nvme", "ex\\mp:e.com", .proto = "tcp", .port = 1234,
|
||||
+ .path = { "p1", "ex<amp>le", "p3", NULL } },
|
||||
+ { "nvme+tcp://ex%5Cmp%3Ae.com:1234/p1/%3C%3E/p3?q%5E%24ry#fr%26gm%23nt",
|
||||
+ "nvme", "ex\\mp:e.com", .proto = "tcp", .port = 1234,
|
||||
+ .path = { "p1", "<>", "p3", NULL }, .query = "q^$ry",
|
||||
+ .frag = "fr&gm#nt" },
|
||||
};
|
||||
|
||||
const char *test_data_bad[] = {
|
Loading…
Reference in new issue