All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] nvme-cli: Make connect-all matching be case insensitive
@ 2021-12-17 22:20 James Smart
  2021-12-21 13:02 ` Daniel Wagner
  0 siblings, 1 reply; 2+ messages in thread
From: James Smart @ 2021-12-17 22:20 UTC (permalink / raw)
  To: linux-nvme; +Cc: James Smart

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>

---
v2: handle strdup failures
---
 fabrics.c | 26 +++++++++++++++++++++++++-
 1 file changed, 25 insertions(+), 1 deletion(-)

diff --git a/fabrics.c b/fabrics.c
index d691191..ab4488c 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)
 {
@@ -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 = true;
 
 	if (cargs_match_found(entry))
 		return false;
@@ -1396,7 +1405,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.26.2



^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH v2] nvme-cli: Make connect-all matching be case insensitive
  2021-12-17 22:20 [PATCH v2] nvme-cli: Make connect-all matching be case insensitive James Smart
@ 2021-12-21 13:02 ` Daniel Wagner
  0 siblings, 0 replies; 2+ messages in thread
From: Daniel Wagner @ 2021-12-21 13:02 UTC (permalink / raw)
  To: linux-nvme, James Smart; +Cc: Daniel Wagner

On Fri, 17 Dec 2021 14:20:22 -0800, James Smart wrote:
> 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.
> 
> [...]

Applied, thanks!

[1/1] nvme-cli: Make connect-all matching be case insensitive
      commit: 1264c6323937c4a0342174fdd9be5a66ab1eaf24

Best regards,
-- 
Daniel Wagner <dwagner@suse.de>


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-12-21 13:03 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-12-17 22:20 [PATCH v2] nvme-cli: Make connect-all matching be case insensitive James Smart
2021-12-21 13:02 ` Daniel Wagner

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.