Blame SOURCES/0007-nvme-cli-Make-connect-all-matching-be-case-insensiti.patch

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