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

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