Skip to content

Commit f6a35ec

Browse files
committed
fabrics: replace fabrics options with fabrics context
Retire the libnvme_fabrics_options type from the public API as any modification is breaking ABI. The libnvmf_context has been introduced as replacement, with an extendable getter/setter API. Signed-off-by: Daniel Wagner <[email protected]>
1 parent 0d24817 commit f6a35ec

4 files changed

Lines changed: 37 additions & 30 deletions

File tree

libnvme/examples/discover-loop.c

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -53,38 +53,41 @@ int main()
5353
{
5454
struct nvmf_discovery_log *log = NULL;
5555
struct libnvme_global_ctx *ctx;
56+
struct libnvmf_context *fctx;
5657
libnvme_host_t h;
5758
libnvme_ctrl_t c;
5859
int ret;
59-
struct libnvme_fabrics_config cfg;
6060
struct libnvmf_discovery_args *args;
6161

62-
libnvmf_default_config(&cfg);
63-
6462
ctx = libnvme_create_global_ctx(stdout, LIBNVME_DEFAULT_LOGLEVEL);
6563
if (!ctx)
6664
return 1;
6765

66+
ret = libnvmf_context_create(ctx, NULL, NULL, NULL, NULL, &fctx);
67+
if (ret)
68+
goto free_ctx;
69+
6870
ret = libnvme_scan_topology(ctx, NULL, NULL);
69-
if (ret) {
70-
libnvme_free_global_ctx(ctx);
71-
return 1;
72-
}
71+
if (ret)
72+
goto free_fctx;
73+
7374
ret = libnvme_get_host(ctx, NULL, NULL, &h);
7475
if (ret) {
7576
fprintf(stderr, "Failed to allocated memory\n");
76-
return 1;
77+
goto free_fctx;
7778
}
79+
7880
ret = libnvme_create_ctrl(ctx, NVME_DISC_SUBSYS_NAME, "loop",
7981
NULL, NULL, NULL, NULL, &c);
8082
if (ret) {
8183
fprintf(stderr, "Failed to allocate memory\n");
82-
return 1;
84+
goto free_fctx;
8385
}
84-
ret = libnvmf_add_ctrl(h, c, &cfg);
86+
87+
ret = libnvmf_add_ctrl(h, c, fctx);
8588
if (ret) {
8689
fprintf(stderr, "no controller found\n");
87-
return 1;
90+
goto free_fctx;
8891
}
8992

9093
ret = libnvmf_discovery_args_create(&args);
@@ -102,7 +105,11 @@ int main()
102105
else
103106
print_discover_log(log);
104107

108+
free_fctx:
109+
libnvmf_context_free(fctx);
110+
free_ctx:
105111
libnvme_free_global_ctx(ctx);
106112
free(log);
107-
return 0;
113+
114+
return ret ? 1 : 0;
108115
}

libnvme/libnvme/nvme.i

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -769,16 +769,15 @@ struct libnvmf_context {};
769769
struct libnvmf_context *fctx = NULL) {
770770
int ret;
771771
const char *dev;
772-
const struct libnvme_fabrics_config *cfg = fctx ? &fctx->cfg : NULL;
773772

774773
dev = libnvme_ctrl_get_name($self);
775-
if (dev && !(cfg && cfg->duplicate_connect)) {
774+
if (dev && !(fctx && fctx->cfg.duplicate_connect)) {
776775
connect_err = -ENVME_CONNECT_ALREADY;
777776
return;
778777
}
779778

780779
Py_BEGIN_ALLOW_THREADS /* Release Python GIL */
781-
ret = libnvmf_add_ctrl(h, $self, cfg);
780+
ret = libnvmf_add_ctrl(h, $self, fctx);
782781
Py_END_ALLOW_THREADS /* Reacquire Python GIL */
783782

784783
if (ret) {

libnvme/src/nvme/fabrics.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1058,15 +1058,15 @@ static const char *lookup_context(struct libnvme_global_ctx *ctx, libnvme_ctrl_t
10581058
}
10591059

10601060
__public int libnvmf_add_ctrl(libnvme_host_t h, libnvme_ctrl_t c,
1061-
const struct libnvme_fabrics_config *cfg)
1061+
const struct libnvmf_context *fctx)
10621062
{
10631063
libnvme_subsystem_t s;
10641064
const char *root_app, *app;
10651065
__cleanup_free char *argstr = NULL;
10661066
int ret;
10671067

10681068
/* highest prio have configs from command line */
1069-
merge_config(c, cfg);
1069+
merge_config(c, &fctx->cfg);
10701070

10711071
/* apply configuration from config file (JSON) */
10721072
s = libnvme_lookup_subsystem(h, NULL, libnvme_ctrl_get_subsysnqn(c));
@@ -1292,7 +1292,7 @@ static int nvmf_connect_disc_entry(libnvme_host_t h,
12921292
/* update tls or concat */
12931293
nvmf_update_tls_concat(e, c, h);
12941294

1295-
ret = libnvmf_add_ctrl(h, c, &fctx->cfg);
1295+
ret = libnvmf_add_ctrl(h, c, fctx);
12961296
if (!ret) {
12971297
*cp = c;
12981298
return 0;
@@ -1303,7 +1303,7 @@ static int nvmf_connect_disc_entry(libnvme_host_t h,
13031303
libnvme_msg(h->ctx, LIBNVME_LOG_INFO, "failed to connect controller, "
13041304
"retry with disabling SQ flow control\n");
13051305
c->cfg.disable_sqflow = false;
1306-
ret = libnvmf_add_ctrl(h, c, &fctx->cfg);
1306+
ret = libnvmf_add_ctrl(h, c, fctx);
13071307
if (!ret) {
13081308
*cp = c;
13091309
return 0;
@@ -2160,7 +2160,7 @@ static int libnvme_add_ctrl(struct libnvmf_context *fctx,
21602160
int err;
21612161

21622162
retry:
2163-
err = libnvmf_add_ctrl(h, c, &fctx->cfg);
2163+
err = libnvmf_add_ctrl(h, c, fctx);
21642164
if (!err)
21652165
return 0;
21662166
if (fctx->decide_retry(fctx, err, fctx->user_data))
@@ -2658,7 +2658,7 @@ static int nbft_connect(struct libnvme_global_ctx *ctx,
26582658
/* Update tls or concat */
26592659
nvmf_update_tls_concat(e, c, h);
26602660

2661-
ret = libnvmf_add_ctrl(h, c, &fctx->cfg);
2661+
ret = libnvmf_add_ctrl(h, c, fctx);
26622662

26632663
/* Resume logging */
26642664
if (ss && ss->unavailable && saved_log_level < 1)

libnvme/src/nvme/fabrics.h

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,14 @@
2323
/* default to 600 seconds of reconnect attempts before giving up */
2424
#define NVMF_DEF_CTRL_LOSS_TMO 600
2525

26+
/*
27+
* struct libnvmf_context - Opaque context for fabrics operations
28+
*
29+
* Used to manage state and configuration for fabrics discovery and connect
30+
* operations.
31+
*/
32+
struct libnvmf_context;
33+
2634
/**
2735
* struct libnvme_fabrics_config - Defines all linux nvme fabrics initiator options
2836
* @queue_size: Number of IO queue entries
@@ -210,7 +218,7 @@ void libnvmf_update_config(libnvme_ctrl_t c,
210218
* libnvmf_add_ctrl() - Connect a controller and update topology
211219
* @h: Host to which the controller should be attached
212220
* @c: Controller to be connected
213-
* @cfg: Default configuration for the controller
221+
* @fctx: Fabrics context
214222
*
215223
* Issues a 'connect' command to the NVMe-oF controller and inserts @c
216224
* into the topology using @h as parent.
@@ -219,7 +227,7 @@ void libnvmf_update_config(libnvme_ctrl_t c,
219227
* Return: 0 on success, or an error code on failure.
220228
*/
221229
int libnvmf_add_ctrl(libnvme_host_t h, libnvme_ctrl_t c,
222-
const struct libnvme_fabrics_config *cfg);
230+
const struct libnvmf_context *fctx);
223231

224232
/**
225233
* libnvmf_connect_ctrl() - Connect a controller
@@ -339,13 +347,6 @@ void libnvmf_free_uri(struct libnvme_fabrics_uri *uri);
339347
*/
340348
const char *libnvmf_get_default_trsvcid(const char *transport,
341349
bool discovery_ctrl);
342-
/*
343-
* struct libnvmf_context - Opaque context for fabrics operations
344-
*
345-
* Used to manage state and configuration for fabrics discovery and connect
346-
* operations.
347-
*/
348-
struct libnvmf_context;
349350

350351
/**
351352
* libnvmf_context_create() - Create a new fabrics context for discovery/connect

0 commit comments

Comments
 (0)