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

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