Skip to contentSkip to conversation

nvme-cli: Make connect-all matching be case insensitive

PATCH Superseded James Smart 1 participant 1 message Dec 17, 2021 NVMe

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 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.

---
 fabrics.c | 21 ++++++++++++++++++++-
 1 file changed, 20 insertions(+), 1 deletion(-)
fabrics.c +20 -1
index d691191..f3bbf50 100644
@@ -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)
 {
@@ -1383,7 +1390,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 = false;
 
 	if (cargs_match_found(entry))
 		return false;
@@ -1396,7 +1405,17 @@ 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);
+	strtolower(dctrl_traddr);
+	strtolower(log_traddr);
+
+	connect = (strlen(dctrl_traddr) == len) &&
+		  !strcmp(dctrl_traddr, log_traddr);
+
+	free(log_traddr);
+	free(dctrl_traddr);
+	return connect;
 }
 
 static int connect_ctrls(struct nvmf_disc_rsp_page_hdr *log, int numrec)
Signature · 1 line
2.26.2