Fix nqn upper vs lower case

Resolves: #2045147

Signed-off-by: Maurizio Lombardi <mlombard@redhat.com>
This commit is contained in:
Maurizio Lombardi 2022-02-07 10:13:09 +01:00
parent ed979f6548
commit f0893277af
5 changed files with 209 additions and 1 deletions

View File

@ -0,0 +1,39 @@
From 45223fd3c5a13da9209c4f44d7593cb42cab94fb Mon Sep 17 00:00:00 2001
From: Maurizio Lombardi <mlombard@redhat.com>
Date: Tue, 14 Dec 2021 10:09:42 +0100
Subject: [PATCH 1/4] nvme: do not leak an open file handle
We performed a "sec_fd=open(cfg.file)" earlier, so we should not
overwrite the handle.
Signed-off-by: Maurizio Lombardi <mlombard@redhat.com>
---
nvme.c | 9 +--------
1 file changed, 1 insertion(+), 8 deletions(-)
diff --git a/nvme.c b/nvme.c
index 862f9b6..5beeac7 100644
--- a/nvme.c
+++ b/nvme.c
@@ -4379,17 +4379,10 @@ static int sec_send(int argc, char **argv, struct command *cmd, struct plugin *p
fprintf(stderr, "WARNING: --tl not dword aligned; unaligned bytes may be truncated\n");
if (strlen(cfg.file) == 0) {
+ close(sec_fd);
sec_fd = STDIN_FILENO;
sec_size = cfg.tl;
} else {
- sec_fd = open(cfg.file, O_RDONLY);
- if (sec_fd < 0) {
- fprintf(stderr, "Failed to open %s: %s\n",
- cfg.file, strerror(errno));
- err = -EINVAL;
- goto close_fd;
- }
-
err = fstat(sec_fd, &sb);
if (err < 0) {
perror("fstat");
--
2.27.0

View File

@ -0,0 +1,35 @@
From b580886dbc322b2a71d6c0c1b71f9fca7b750b02 Mon Sep 17 00:00:00 2001
From: Maurizio Lombardi <mlombard@redhat.com>
Date: Tue, 14 Dec 2021 09:58:09 +0100
Subject: [PATCH 2/4] nvme-topology: fix memory leaks in
nvme_logical_block_size_from_ns_char()
Free the allocated strings before returning from the function
Signed-off-by: Maurizio Lombardi <mlombard@redhat.com>
---
nvme-topology.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/nvme-topology.c b/nvme-topology.c
index 0a22f6b..6be2b09 100644
--- a/nvme-topology.c
+++ b/nvme-topology.c
@@ -686,10 +686,13 @@ int nvme_logical_block_size_from_ns_char(const char *dev)
return -EINVAL;
s = nvme_get_ctrl_attr(path, "logical_block_size");
+ free(path);
if (!s)
return -EINVAL;
- return atoi(s);
+ ret = atoi(s);
+ free(s);
+ return ret;
}
void *mmap_registers(const char *dev)
--
2.27.0

View File

@ -0,0 +1,37 @@
From 58c23ceb12d16756b2222a55d1d9dc5f34bb4fa4 Mon Sep 17 00:00:00 2001
From: James Smart <jsmart2021@gmail.com>
Date: Fri, 17 Dec 2021 11:32:32 -0800
Subject: [PATCH 3/4] nvme-cli: nvmf-connect@.service: Remove matching from
default syntax
commit 53aab69a0add added the "--matching" argument to the systemd
connect script that issues connect-all to a discovery controller. When
this argument is used, only discovery log entries whose target port
traddr's match the traddr of the discovery controller will be connected
to. This eliminates the ability to do referrals by the discovery
controller.
Revert the commit so that the "--matching" argument is not default
behavior.
Signed-off-by: James Smart <jsmart2021@gmail.com>
CC: Martin Wilck <mwilck@suse.com>
Signed-off-by: Daniel Wagner <dwagner@suse.de>
Link: https://lore.kernel.org/r/20211217193232.29034-1-jsmart2021@gmail.com
---
nvmf-autoconnect/systemd/nvmf-connect@.service | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/nvmf-autoconnect/systemd/nvmf-connect@.service b/nvmf-autoconnect/systemd/nvmf-connect@.service
index 5fbf081..c60f146 100644
--- a/nvmf-autoconnect/systemd/nvmf-connect@.service
+++ b/nvmf-autoconnect/systemd/nvmf-connect@.service
@@ -11,4 +11,4 @@ Requires=nvmf-connect.target
[Service]
Type=simple
Environment="CONNECT_ARGS=%i"
-ExecStart=/bin/sh -c "nvme connect-all --matching --quiet `/bin/echo -e '${CONNECT_ARGS}'`"
+ExecStart=/bin/sh -c "nvme connect-all --quiet `/bin/echo -e '${CONNECT_ARGS}'`"
--
2.27.0

View File

@ -0,0 +1,86 @@
From 1264c6323937c4a0342174fdd9be5a66ab1eaf24 Mon Sep 17 00:00:00 2001
From: James Smart <jsmart2021@gmail.com>
Date: Fri, 17 Dec 2021 14:20:22 -0800
Subject: [PATCH 4/4] nvme-cli: Make connect-all matching be case insensitive
The comparison routine that checks discovery controller traddr with a
discovery log traddr uses a simple strncmp. For FC, which kicks off
connect-all requests vay systemd, the nvme-fc transport will build
traddr strings with lower case hexadecimal. Some FC discovery
controllers return traddr strings with upper case hexadecimal. There
was is no rqmt in the NVME-FC spec that it be upper or lower case.
Given the case difference, the connect-all fails the match logic and
doesn't connect to storage.
Revise the traddr comparison routine to duplicate the strings and
convert them to lower case for comparison.
Signed-off-by: James Smart <jsmart2021@gmail.com>
Signed-off-by: Daniel Wagner <dwagner@suse.de>
Link: https://lore.kernel.org/r/20211217222022.30516-1-jsmart2021@gmail.com
---
fabrics.c | 26 +++++++++++++++++++++++++-
1 file changed, 25 insertions(+), 1 deletion(-)
diff --git a/fabrics.c b/fabrics.c
index 0766729..a1e2593 100644
--- a/fabrics.c
+++ b/fabrics.c
@@ -34,6 +34,7 @@
#include <stddef.h>
#include <syslog.h>
#include <time.h>
+#include <ctype.h>
#include <sys/types.h>
#include <arpa/inet.h>
@@ -681,6 +682,12 @@ static int space_strip_len(int max, const char *str)
return i + 1;
}
+static void strtolower(char *str)
+{
+ for ( ; *str; str++)
+ *str = tolower(*str);
+}
+
static void print_discovery_log(struct nvmf_disc_rsp_page_hdr *log, int numrec,
int instance)
{
@@ -1385,7 +1392,9 @@ static bool cargs_match_found(struct nvmf_disc_rsp_page_entry *entry)
static bool should_connect(struct nvmf_disc_rsp_page_entry *entry)
{
+ char *dctrl_traddr, *log_traddr;
int len;
+ bool connect = true;
if (cargs_match_found(entry))
return false;
@@ -1398,7 +1407,22 @@ static bool should_connect(struct nvmf_disc_rsp_page_entry *entry)
return true;
len = space_strip_len(NVMF_TRADDR_SIZE, entry->traddr);
- return !strncmp(fabrics_cfg.traddr, entry->traddr, len);
+
+ dctrl_traddr = strdup(fabrics_cfg.traddr);
+ log_traddr = strndup(entry->traddr, len);
+ if (!dctrl_traddr || !log_traddr)
+ goto free_exit;
+
+ strtolower(dctrl_traddr);
+ strtolower(log_traddr);
+
+ connect = (strlen(dctrl_traddr) == len) &&
+ !strcmp(dctrl_traddr, log_traddr);
+
+free_exit:
+ free(log_traddr);
+ free(dctrl_traddr);
+ return connect;
}
static int connect_ctrls(struct nvmf_disc_rsp_page_hdr *log, int numrec)
--
2.27.0

View File

@ -3,7 +3,7 @@
Name: nvme-cli
Version: 1.16
Release: 2%{?dist}
Release: 3%{?dist}
Summary: NVMe management command line interface
License: GPLv2+
@ -14,6 +14,10 @@ Patch0: nvme-cli-makefile-dont-install-host-params-patch
Patch1: 0001-fabrics-fix-nvme-connect-segfault-if-transport-type-.patch
Patch2: 0002-fabrics-fix-a-buffer-overrun.patch
Patch3: 0003-bash-Fix-nvme-completion.patch
Patch4: 0004-nvme-do-not-leak-an-open-file-handle.patch
Patch5: 0005-nvme-topology-fix-memory-leaks-in-nvme_logical_block.patch
Patch6: 0006-nvme-cli-nvmf-connect-.service-Remove-matching-from-.patch
Patch7: 0007-nvme-cli-Make-connect-all-matching-be-case-insensiti.patch
BuildRequires: libuuid-devel
BuildRequires: gcc
@ -30,6 +34,10 @@ nvme-cli provides NVM-Express user space tooling for Linux.
%patch1 -p1
%patch2 -p1
%patch3 -p1
%patch4 -p1
%patch5 -p1
%patch6 -p1
%patch7 -p1
%build
@ -87,6 +95,9 @@ if [ $1 -eq 1 ] || [ $1 -eq 2 ]; then
fi
%changelog
* Mon Feb 07 2022 Maurizio Lombardi <mlombard@redhat.com> - 1.16-3
- Add a few bugfixes
* Mon Dec 13 2021 Maurizio Lombardi <mlombard@redhat.com> - 1.16-2
- Update to the latest version