Skip to content

Commit d76eb46

Browse files
committed
tree: use traddr_is_hostname from fabrics
This function exists in two files with slightly different implementations. Use a single shared implementation instead. Signed-off-by: Daniel Wagner <[email protected]>
1 parent ca601a1 commit d76eb46

5 files changed

Lines changed: 33 additions & 26 deletions

File tree

libnvme/src/meson.build

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@ if want_fabrics
5050
'nvme/nbft.h',
5151
'nvme/accessors-fabrics.h',
5252
]
53+
else
54+
sources += [
55+
'nvme/no-fabrics.c',
56+
]
5357
endif
5458

5559
if want_mi

libnvme/src/nvme/fabrics.c

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -737,16 +737,23 @@ static int inet_pton_with_scope(struct libnvme_global_ctx *ctx, int af,
737737
return ret;
738738
}
739739

740-
static bool traddr_is_hostname(struct libnvme_global_ctx *ctx, libnvme_ctrl_t c)
740+
bool traddr_is_hostname(const char *transport, const char *traddr)
741741
{
742-
struct sockaddr_storage addr;
743742

744-
if (!c->traddr)
743+
char addrstr[NVMF_TRADDR_SIZE];
744+
745+
if (!traddr || !transport)
745746
return false;
746-
if (strcmp(c->transport, "tcp") && strcmp(c->transport, "rdma"))
747+
if (!strcmp(traddr, "none"))
747748
return false;
748-
if (inet_pton_with_scope(ctx, AF_UNSPEC, c->traddr, c->trsvcid, &addr) == 0)
749+
750+
if (strcmp(transport, "tcp") &&
751+
strcmp(transport, "rdma"))
749752
return false;
753+
if (inet_pton(AF_INET, traddr, addrstr) > 0 ||
754+
inet_pton(AF_INET6, traddr, addrstr) > 0)
755+
return false;
756+
750757
return true;
751758
}
752759

@@ -1140,7 +1147,7 @@ __public int libnvmf_add_ctrl(libnvme_host_t h, libnvme_ctrl_t c)
11401147
}
11411148

11421149
libnvme_ctrl_set_discovered(c, true);
1143-
if (traddr_is_hostname(h->ctx, c)) {
1150+
if (traddr_is_hostname(c->transport, c->traddr)) {
11441151
char *traddr = c->traddr;
11451152

11461153
if (hostname2traddr(h->ctx, traddr, &c->traddr)) {

libnvme/src/nvme/no-fabrics.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// SPDX-License-Identifier: LGPL-2.1-or-later
2+
/*
3+
* This file is part of libnvme.
4+
* Copyright (c) 2026 SUSE Software Solutions
5+
*
6+
* Authors: Daniel Wagner <[email protected]>
7+
*/
8+
9+
#include "private-fabrics.h"
10+
11+
bool traddr_is_hostname(const char *transport, const char *traddr)
12+
{
13+
return false;
14+
}

libnvme/src/nvme/private-fabrics.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,3 +80,5 @@ struct libnvmf_discovery_args { /*!generate-accessors*/
8080
int max_retries;
8181
__u8 lsp;
8282
};
83+
84+
bool traddr_is_hostname(const char *transport, const char *traddr);

libnvme/src/nvme/tree.c

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1046,26 +1046,6 @@ __public void libnvme_free_ctrl(libnvme_ctrl_t c)
10461046
__libnvme_free_ctrl(c);
10471047
}
10481048

1049-
static bool traddr_is_hostname(const char *transport, const char *traddr)
1050-
{
1051-
1052-
if (!traddr || !transport)
1053-
return false;
1054-
if (!strcmp(traddr, "none"))
1055-
return false;
1056-
#ifdef CONFIG_FABRICS
1057-
char addrstr[NVMF_TRADDR_SIZE];
1058-
1059-
if (strcmp(transport, "tcp") &&
1060-
strcmp(transport, "rdma"))
1061-
return false;
1062-
if (inet_pton(AF_INET, traddr, addrstr) > 0 ||
1063-
inet_pton(AF_INET6, traddr, addrstr) > 0)
1064-
return false;
1065-
#endif
1066-
return true;
1067-
}
1068-
10691049
__public void libnvmf_default_config(struct libnvme_fabrics_config *cfg)
10701050
{
10711051
cfg->tos = -1;

0 commit comments

Comments
 (0)