Skip to content

Commit 4fd3c54

Browse files
committed
libnvme: make fabrics optional
The fabrics part is rather large and usually is not necessary for embedded use cases. Also it is very Linux specific and makes any porting attempts really hard. Thus make the fabrics part optional. Signed-off-by: Daniel Wagner <[email protected]>
1 parent afcbd98 commit 4fd3c54

19 files changed

Lines changed: 223 additions & 141 deletions

libnvme/examples/meson.build

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,17 @@ executable(
3535
],
3636
)
3737

38-
executable(
39-
'discover-loop',
40-
['discover-loop.c'],
41-
dependencies: [
42-
config_dep,
43-
ccan_dep,
44-
libnvme_dep,
45-
],
46-
)
38+
if want_fabrics
39+
executable(
40+
'discover-loop',
41+
['discover-loop.c'],
42+
dependencies: [
43+
config_dep,
44+
ccan_dep,
45+
libnvme_dep,
46+
],
47+
)
48+
endif
4749

4850
executable(
4951
'mi-mctp',
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ extern "C" {
1515
#endif
1616

1717
#include <nvme/cmds.h>
18-
#include <nvme/fabrics.h>
18+
@FABRICS_INCLUDE@
1919
#include <nvme/filters.h>
2020
#include <nvme/ioctl.h>
2121
#include <nvme/lib-types.h>

libnvme/src/libnvme.ld

Lines changed: 0 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -270,70 +270,6 @@ LIBNVME_3 {
270270
nvme_uuid_from_string;
271271
nvme_uuid_random;
272272
nvme_uuid_to_string;
273-
nvmf_add_ctrl;
274-
nvmf_adrfam_str;
275-
nvmf_cms_str;
276-
nvmf_config_modify;
277-
nvmf_connect;
278-
nvmf_connect_config_json;
279-
nvmf_connect_ctrl;
280-
nvmf_context_create;
281-
nvmf_context_set_connection;
282-
nvmf_context_set_crypto;
283-
nvmf_context_set_device;
284-
nvmf_context_set_discovery_cbs;
285-
nvmf_context_set_discovery_defaults;
286-
nvmf_context_set_fabrics_config;
287-
nvmf_context_set_hostnqn;
288-
nvmf_context_set_persistent;
289-
nvmf_default_config;
290-
nvmf_discovery;
291-
nvmf_discovery_config_file;
292-
nvmf_discovery_config_json;
293-
nvmf_discovery_ctx_already_connected_set;
294-
nvmf_discovery_ctx_connected_set;
295-
nvmf_discovery_ctx_create;
296-
nvmf_discovery_ctx_ctrlkey_set;
297-
nvmf_discovery_ctx_decide_retry_set;
298-
nvmf_discovery_ctx_default_fabrics_config_set;
299-
nvmf_discovery_ctx_device_set;
300-
nvmf_discovery_ctx_discovery_log_set;
301-
nvmf_discovery_ctx_host_iface_set;
302-
nvmf_discovery_ctx_host_traddr_set;
303-
nvmf_discovery_ctx_hostid_set;
304-
nvmf_discovery_ctx_hostkey_set;
305-
nvmf_discovery_ctx_hostnqn_set;
306-
nvmf_discovery_ctx_keep_alive_timeout;
307-
nvmf_discovery_ctx_keyring_set;
308-
nvmf_discovery_ctx_max_retries;
309-
nvmf_discovery_ctx_parser_cleanup_set;
310-
nvmf_discovery_ctx_parser_init_set;
311-
nvmf_discovery_ctx_parser_next_line_set;
312-
nvmf_discovery_ctx_persistent_set;
313-
nvmf_discovery_ctx_subsysnqn_set;
314-
nvmf_discovery_ctx_tls_key_identity_set;
315-
nvmf_discovery_ctx_tls_key_set;
316-
nvmf_discovery_ctx_traddr_set;
317-
nvmf_discovery_ctx_transport_set;
318-
nvmf_discovery_ctx_trsvcid_set;
319-
nvmf_discovery_nbft;
320-
nvmf_eflags_str;
321-
nvmf_exat_ptr_next;
322-
nvmf_free_uri;
323-
nvmf_get_default_trsvcid;
324-
nvmf_get_discovery_log;
325-
nvmf_get_discovery_wargs;
326-
nvmf_is_registration_supported;
327-
nvmf_nbft_free;
328-
nvmf_nbft_read_files;
329-
nvmf_prtype_str;
330-
nvmf_qptype_str;
331-
nvmf_register_ctrl;
332-
nvmf_sectype_str;
333-
nvmf_subtype_str;
334-
nvmf_treq_str;
335-
nvmf_trtype_str;
336-
nvmf_update_config;
337273
local:
338274
*;
339275
};

libnvme/src/libnvmf.ld

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
# SPDX-License-Identifier: LGPL-2.1-or-later
2+
3+
LIBNVMF_3 {
4+
global:
5+
nvmf_add_ctrl;
6+
nvmf_adrfam_str;
7+
nvmf_cms_str;
8+
nvmf_config_modify;
9+
nvmf_connect;
10+
nvmf_connect_config_json;
11+
nvmf_connect_ctrl;
12+
nvmf_context_create;
13+
nvmf_context_set_connection;
14+
nvmf_context_set_crypto;
15+
nvmf_context_set_device;
16+
nvmf_context_set_discovery_cbs;
17+
nvmf_context_set_discovery_defaults;
18+
nvmf_context_set_fabrics_config;
19+
nvmf_context_set_hostnqn;
20+
nvmf_context_set_persistent;
21+
nvmf_default_config;
22+
nvmf_discovery;
23+
nvmf_discovery_config_file;
24+
nvmf_discovery_config_json;
25+
nvmf_discovery_ctx_already_connected_set;
26+
nvmf_discovery_ctx_connected_set;
27+
nvmf_discovery_ctx_create;
28+
nvmf_discovery_ctx_ctrlkey_set;
29+
nvmf_discovery_ctx_decide_retry_set;
30+
nvmf_discovery_ctx_default_fabrics_config_set;
31+
nvmf_discovery_ctx_device_set;
32+
nvmf_discovery_ctx_discovery_log_set;
33+
nvmf_discovery_ctx_host_iface_set;
34+
nvmf_discovery_ctx_host_traddr_set;
35+
nvmf_discovery_ctx_hostid_set;
36+
nvmf_discovery_ctx_hostkey_set;
37+
nvmf_discovery_ctx_hostnqn_set;
38+
nvmf_discovery_ctx_keep_alive_timeout;
39+
nvmf_discovery_ctx_keyring_set;
40+
nvmf_discovery_ctx_max_retries;
41+
nvmf_discovery_ctx_parser_cleanup_set;
42+
nvmf_discovery_ctx_parser_init_set;
43+
nvmf_discovery_ctx_parser_next_line_set;
44+
nvmf_discovery_ctx_persistent_set;
45+
nvmf_discovery_ctx_subsysnqn_set;
46+
nvmf_discovery_ctx_tls_key_identity_set;
47+
nvmf_discovery_ctx_tls_key_set;
48+
nvmf_discovery_ctx_traddr_set;
49+
nvmf_discovery_ctx_transport_set;
50+
nvmf_discovery_ctx_trsvcid_set;
51+
nvmf_discovery_nbft;
52+
nvmf_eflags_str;
53+
nvmf_exat_ptr_next;
54+
nvmf_free_uri;
55+
nvmf_get_default_trsvcid;
56+
nvmf_get_discovery_log;
57+
nvmf_get_discovery_wargs;
58+
nvmf_is_registration_supported;
59+
nvmf_nbft_free;
60+
nvmf_nbft_read_files;
61+
nvmf_prtype_str;
62+
nvmf_qptype_str;
63+
nvmf_register_ctrl;
64+
nvmf_sectype_str;
65+
nvmf_subtype_str;
66+
nvmf_treq_str;
67+
nvmf_trtype_str;
68+
nvmf_update_config;
69+
local:
70+
*;
71+
};

libnvme/src/meson.build

Lines changed: 48 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ sources = [
1010
'nvme/base64.c',
1111
'nvme/cmds.c',
1212
'nvme/crc32.c',
13-
'nvme/fabrics.c',
1413
'nvme/filters.c',
1514
'nvme/ioctl.c',
1615
'nvme/lib.c',
@@ -23,6 +22,29 @@ sources = [
2322
'nvme/tree.c',
2423
'nvme/util.c',
2524
]
25+
headers = [
26+
'nvme/accessors.h',
27+
'nvme/cmds.h',
28+
'nvme/filters.h',
29+
'nvme/ioctl.h',
30+
'nvme/lib-types.h',
31+
'nvme/lib.h',
32+
'nvme/linux.h',
33+
'nvme/mi.h',
34+
'nvme/nbft.h',
35+
'nvme/tree.h',
36+
'nvme/types.h',
37+
'nvme/util.h',
38+
]
39+
40+
if want_fabrics
41+
sources += [
42+
'nvme/fabrics.c',
43+
]
44+
headers += [
45+
'nvme/fabrics.h',
46+
]
47+
endif
2648

2749
if json_c_dep.found()
2850
sources += 'nvme/json.c'
@@ -42,16 +64,35 @@ deps = [
4264
openssl_dep,
4365
]
4466

45-
ldfile = 'libnvme.ld'
67+
nvme_ld = meson.current_source_dir() / 'libnvme.ld'
68+
nvmf_ld = meson.current_source_dir() / 'libnvmf.ld'
69+
70+
link_args = [
71+
'-Wl,--version-script=@0@'.format(nvme_ld),
72+
'-Wl,--version-script=@0@'.format(accessors_ld_full_path),
73+
]
74+
75+
libconf = configuration_data()
76+
if want_fabrics
77+
link_args += '-Wl,--version-script=@0@'.format(nvmf_ld)
78+
libconf.set('FABRICS_INCLUDE', '#include <nvme/fabrics.h>')
79+
else
80+
libconf.set('FABRICS_INCLUDE', '')
81+
endif
82+
83+
libnvme_header = configure_file(
84+
input: 'libnvme.h.in',
85+
output: 'libnvme.h',
86+
configuration: libconf,
87+
install: true,
88+
install_dir: prefixdir / get_option('includedir')
89+
)
4690

4791
libnvme = library(
4892
'nvme', # produces libnvme.so
4993
sources,
5094
version: libnvme_so_version,
51-
link_args: [
52-
'-Wl,--version-script=@0@'.format(meson.current_source_dir() / ldfile),
53-
'-Wl,--version-script=@0@'.format(accessors_ld_full_path),
54-
],
95+
link_args: link_args,
5596
dependencies: deps,
5697
install: true,
5798
)
@@ -90,27 +131,12 @@ libnvme_test_dep = declare_dependency(
90131
mode = 'rw-r--r--'
91132
install_headers(
92133
[
93-
'libnvme.h',
94134
'libnvme-mi.h',
95135
],
96136
install_mode: mode,
97137
)
98138
install_headers(
99-
[
100-
'nvme/accessors.h',
101-
'nvme/cmds.h',
102-
'nvme/fabrics.h',
103-
'nvme/filters.h',
104-
'nvme/ioctl.h',
105-
'nvme/lib-types.h',
106-
'nvme/lib.h',
107-
'nvme/linux.h',
108-
'nvme/mi.h',
109-
'nvme/nbft.h',
110-
'nvme/tree.h',
111-
'nvme/types.h',
112-
'nvme/util.h',
113-
],
139+
headers,
114140
subdir: 'nvme',
115141
install_mode: mode,
116142
)

libnvme/src/nvme/fabrics.c

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -333,13 +333,6 @@ static const struct nvme_fabric_options default_supported_options = {
333333
.trsvcid = true,
334334
};
335335

336-
void nvmf_default_config(struct nvme_fabrics_config *cfg)
337-
{
338-
memset(cfg, 0, sizeof(*cfg));
339-
cfg->tos = -1;
340-
cfg->ctrl_loss_tmo = NVMF_DEF_CTRL_LOSS_TMO;
341-
}
342-
343336
#define MERGE_CFG_OPTION(c, n, o, d) \
344337
if ((c)->o == d) (c)->o = (n)->o
345338
static struct nvme_fabrics_config *merge_config(nvme_ctrl_t c,

libnvme/src/nvme/fabrics.h

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -594,15 +594,7 @@ int nvmf_connect_config_json(struct nvme_global_ctx *ctx,
594594
int nvmf_config_modify(struct nvme_global_ctx *ctx,
595595
struct nvmf_context *fctx);
596596

597-
/**
598-
* struct nbft_file_entry - Linked list entry for NBFT files
599-
* @next: Pointer to next entry
600-
* @nbft: Pointer to NBFT info structure
601-
*/
602-
struct nbft_file_entry {
603-
struct nbft_file_entry *next;
604-
struct nbft_info *nbft;
605-
};
597+
struct nbft_file_entry;
606598

607599
/**
608600
* nvmf_nbft_read_files() - Read NBFT files from path

libnvme/src/nvme/nbft.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1254,3 +1254,14 @@ int nvme_nbft_read(struct nvme_global_ctx *ctx, struct nbft_info **nbft,
12541254
* @nbft: Parsed NBFT table data.
12551255
*/
12561256
void nvme_nbft_free(struct nvme_global_ctx *ctx, struct nbft_info *nbft);
1257+
1258+
/**
1259+
* struct nbft_file_entry - Linked list entry for NBFT files
1260+
* @next: Pointer to next entry
1261+
* @nbft: Pointer to NBFT info structure
1262+
*/
1263+
struct nbft_file_entry {
1264+
struct nbft_file_entry *next;
1265+
struct nbft_info *nbft;
1266+
};
1267+

libnvme/src/nvme/tree.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1118,6 +1118,13 @@ static bool traddr_is_hostname(const char *transport, const char *traddr)
11181118
return true;
11191119
}
11201120

1121+
void nvmf_default_config(struct nvme_fabrics_config *cfg)
1122+
{
1123+
memset(cfg, 0, sizeof(*cfg));
1124+
cfg->tos = -1;
1125+
cfg->ctrl_loss_tmo = NVMF_DEF_CTRL_LOSS_TMO;
1126+
}
1127+
11211128
int nvme_create_ctrl(struct nvme_global_ctx *ctx,
11221129
const char *subsysnqn, const char *transport,
11231130
const char *traddr, const char *host_traddr,

libnvme/test/ioctl/meson.build

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -52,17 +52,19 @@ ana = executable(
5252
)
5353
test('libnvme - ana', ana, env: mock_ioctl_env)
5454

55-
discovery = executable(
56-
'test-discovery',
57-
'discovery.c',
58-
dependencies: [
59-
config_dep,
60-
ccan_dep,
61-
libnvme_dep,
62-
],
63-
link_with: mock_ioctl,
64-
)
65-
test('libnvme - discovery', discovery, env: mock_ioctl_env)
55+
if want_fabrics
56+
discovery = executable(
57+
'test-discovery',
58+
'discovery.c',
59+
dependencies: [
60+
config_dep,
61+
ccan_dep,
62+
libnvme_dep,
63+
],
64+
link_with: mock_ioctl,
65+
)
66+
test('libnvme - discovery', discovery, env: mock_ioctl_env)
67+
endif
6668

6769
features = executable(
6870
'test-features',

0 commit comments

Comments
 (0)