Skip to content

Commit efc6a86

Browse files
committed
private: make fabrics parts optional in global context
In the first step mark all fabrics parts global context optional. After all fabrics related functions are clearly identified, it's possible to move them to the right place later. Signed-off-by: Daniel Wagner <[email protected]>
1 parent aecc0e1 commit efc6a86

4 files changed

Lines changed: 34 additions & 6 deletions

File tree

libnvme/src/nvme/lib.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@
1111
#include <libgen.h>
1212
#include <strings.h>
1313

14+
#ifdef CONFIG_FABRICS
15+
#include <sys/types.h>
16+
17+
#include <ifaddrs.h>
18+
#endif
19+
1420
#include <sys/ioctl.h>
1521

1622
#include <libnvme.h>
@@ -72,10 +78,12 @@ __public void libnvme_free_global_ctx(struct libnvme_global_ctx *ctx)
7278
if (!ctx)
7379
return;
7480

81+
#ifdef CONFIG_FABRICS
7582
freeifaddrs(ctx->ifaddrs_cache); /* NULL-safe */
7683
ctx->ifaddrs_cache = NULL;
77-
7884
free(ctx->options);
85+
#endif
86+
7987
libnvme_for_each_host_safe(ctx, h, _h)
8088
__libnvme_free_host(h);
8189
libnvme_mi_for_each_endpoint_safe(ctx, ep, tmp)

libnvme/src/nvme/private.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
*/
88
#pragma once
99

10-
#include <ifaddrs.h>
1110
#include <poll.h>
1211

1312
#include <sys/ioctl.h>
@@ -295,8 +294,10 @@ struct libnvme_global_ctx {
295294
bool ioctl_probing;
296295
bool create_only;
297296
bool dry_run;
297+
#ifdef CONFIG_FABRICS
298298
struct libnvme_fabric_options *options;
299299
struct ifaddrs *ifaddrs_cache; /* init with libnvme_getifaddrs() */
300+
#endif
300301

301302
enum libnvme_io_uring_state uring_state;
302303
#ifdef CONFIG_LIBURING

libnvme/src/nvme/tree.c

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,23 @@
99
#include <dirent.h>
1010
#include <errno.h>
1111
#include <fcntl.h>
12-
#include <ifaddrs.h>
1312
#include <libgen.h>
1413
#include <stdint.h>
1514
#include <stdio.h>
1615
#include <stdlib.h>
1716
#include <string.h>
1817
#include <unistd.h>
1918

20-
#include <arpa/inet.h>
21-
#include <netdb.h>
2219
#include <sys/stat.h>
2320
#include <sys/types.h>
2421

22+
#ifdef CONFIG_FABRICS
23+
#include <ifaddrs.h>
24+
#include <netdb.h>
25+
26+
#include <arpa/inet.h>
27+
#endif
28+
2529
#include <ccan/endian/endian.h>
2630
#include <ccan/list/list.h>
2731

@@ -1067,18 +1071,21 @@ __public void libnvme_free_ctrl(libnvme_ctrl_t c)
10671071

10681072
static bool traddr_is_hostname(const char *transport, const char *traddr)
10691073
{
1070-
char addrstr[NVMF_TRADDR_SIZE];
10711074

10721075
if (!traddr || !transport)
10731076
return false;
10741077
if (!strcmp(traddr, "none"))
10751078
return false;
1079+
#ifdef CONFIG_FABRICS
1080+
char addrstr[NVMF_TRADDR_SIZE];
1081+
10761082
if (strcmp(transport, "tcp") &&
10771083
strcmp(transport, "rdma"))
10781084
return false;
10791085
if (inet_pton(AF_INET, traddr, addrstr) > 0 ||
10801086
inet_pton(AF_INET6, traddr, addrstr) > 0)
10811087
return false;
1088+
#endif
10821089
return true;
10831090
}
10841091

@@ -1157,6 +1164,7 @@ __public int libnvme_create_ctrl(struct libnvme_global_ctx *ctx,
11571164
return _libnvme_create_ctrl(ctx, &fctx, cp);
11581165
}
11591166

1167+
#ifdef CONFIG_FABRICS
11601168
/**
11611169
* _tcp_ctrl_match_host_traddr_no_src_addr() - Match host_traddr w/o src_addr
11621170
* @c: An existing controller instance
@@ -1383,6 +1391,7 @@ static bool _tcp_match_ctrl(struct libnvme_ctrl *c,
13831391

13841392
return true;
13851393
}
1394+
#endif
13861395

13871396
/**
13881397
* _match_ctrl() - Check if controller matches candidate (non TCP transport)
@@ -1425,6 +1434,7 @@ static bool _match_ctrl(struct libnvme_ctrl *c,
14251434

14261435
return true;
14271436
}
1437+
14281438
/**
14291439
* _candidate_init() - Init candidate and get the matching function
14301440
*
@@ -1469,6 +1479,7 @@ static ctrl_match_t _candidate_init(struct libnvme_global_ctx *ctx,
14691479
candidate->well_known_nqn = true;
14701480
}
14711481

1482+
#ifdef CONFIG_FABRICS
14721483
if (streq0(fctx->transport, "tcp")) {
14731484
candidate->iface_list = libnvme_getifaddrs(ctx); /* TCP only */
14741485
candidate->addreq = libnvme_ipaddrs_eq;
@@ -1479,6 +1490,7 @@ static ctrl_match_t _candidate_init(struct libnvme_global_ctx *ctx,
14791490
candidate->addreq = libnvme_ipaddrs_eq;
14801491
return _match_ctrl;
14811492
}
1493+
#endif
14821494

14831495
/* All other transport types */
14841496
candidate->addreq = streqcase0;

libnvme/src/nvme/util.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@
1616
#include <string.h>
1717
#include <unistd.h>
1818

19+
#if defined(HAVE_NETDB) || defined(CONFIG_FABRICS)
20+
#include <sys/types.h>
21+
#include <ifaddrs.h>
22+
#endif
23+
1924
#include <arpa/inet.h>
2025
#include <netdb.h>
2126
#include <sys/param.h>
@@ -981,6 +986,7 @@ void *__libnvme_realloc(void *p, size_t len)
981986
return result;
982987
}
983988

989+
#ifdef CONFIG_FABRICS
984990
const struct ifaddrs *libnvme_getifaddrs(struct libnvme_global_ctx *ctx)
985991
{
986992
if (!ctx->ifaddrs_cache) {
@@ -992,6 +998,7 @@ const struct ifaddrs *libnvme_getifaddrs(struct libnvme_global_ctx *ctx)
992998

993999
return ctx->ifaddrs_cache;
9941000
}
1001+
#endif
9951002

9961003
/* This used instead of basename() due to behavioral differences between
9971004
* the POSIX and the GNU version. This is the glibc implementation.

0 commit comments

Comments
 (0)