Skip to content

Commit 1264c63

Browse files
jsmart-ghdwsuse
authored andcommitted
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. Signed-off-by: James Smart <jsmart2021@gmail.com> Signed-off-by: Daniel Wagner <dwagner@suse.de> Link: https://lore.kernel.org/r/20211217222022.30516-1-jsmart2021@gmail.com
1 parent 58c23ce commit 1264c63

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

fabrics.c

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
#include <stddef.h>
3535
#include <syslog.h>
3636
#include <time.h>
37+
#include <ctype.h>
3738

3839
#include <sys/types.h>
3940
#include <arpa/inet.h>
@@ -681,6 +682,12 @@ static int space_strip_len(int max, const char *str)
681682
return i + 1;
682683
}
683684

685+
static void strtolower(char *str)
686+
{
687+
for ( ; *str; str++)
688+
*str = tolower(*str);
689+
}
690+
684691
static void print_discovery_log(struct nvmf_disc_rsp_page_hdr *log, int numrec,
685692
int instance)
686693
{
@@ -1385,7 +1392,9 @@ static bool cargs_match_found(struct nvmf_disc_rsp_page_entry *entry)
13851392

13861393
static bool should_connect(struct nvmf_disc_rsp_page_entry *entry)
13871394
{
1395+
char *dctrl_traddr, *log_traddr;
13881396
int len;
1397+
bool connect = true;
13891398

13901399
if (cargs_match_found(entry))
13911400
return false;
@@ -1398,7 +1407,22 @@ static bool should_connect(struct nvmf_disc_rsp_page_entry *entry)
13981407
return true;
13991408

14001409
len = space_strip_len(NVMF_TRADDR_SIZE, entry->traddr);
1401-
return !strncmp(fabrics_cfg.traddr, entry->traddr, len);
1410+
1411+
dctrl_traddr = strdup(fabrics_cfg.traddr);
1412+
log_traddr = strndup(entry->traddr, len);
1413+
if (!dctrl_traddr || !log_traddr)
1414+
goto free_exit;
1415+
1416+
strtolower(dctrl_traddr);
1417+
strtolower(log_traddr);
1418+
1419+
connect = (strlen(dctrl_traddr) == len) &&
1420+
!strcmp(dctrl_traddr, log_traddr);
1421+
1422+
free_exit:
1423+
free(log_traddr);
1424+
free(dctrl_traddr);
1425+
return connect;
14021426
}
14031427

14041428
static int connect_ctrls(struct nvmf_disc_rsp_page_hdr *log, int numrec)

0 commit comments

Comments
 (0)