Skip to content

Commit 128aac4

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 b23b99a commit 128aac4

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
@@ -1063,15 +1063,15 @@ static const char *lookup_context(struct libnvme_global_ctx *ctx, libnvme_ctrl_t
10631063
}
10641064

10651065
__public int libnvmf_add_ctrl(libnvme_host_t h, libnvme_ctrl_t c,
1066-
const struct libnvme_fabrics_config *cfg)
1066+
const struct libnvmf_context *fctx)
10671067
{
10681068
libnvme_subsystem_t s;
10691069
const char *root_app, *app;
10701070
__cleanup_free char *argstr = NULL;
10711071
int ret;
10721072

10731073
/* highest prio have configs from command line */
1074-
merge_config(c, cfg);
1074+
merge_config(c, &fctx->cfg);
10751075

10761076
/* apply configuration from config file (JSON) */
10771077
s = libnvme_lookup_subsystem(h, NULL, libnvme_ctrl_get_subsysnqn(c));
@@ -1297,7 +1297,7 @@ static int nvmf_connect_disc_entry(libnvme_host_t h,
12971297
/* update tls or concat */
12981298
nvmf_update_tls_concat(e, c, h);
12991299

1300-
ret = libnvmf_add_ctrl(h, c, &fctx->cfg);
1300+
ret = libnvmf_add_ctrl(h, c, fctx);
13011301
if (!ret) {
13021302
*cp = c;
13031303
return 0;
@@ -1308,7 +1308,7 @@ static int nvmf_connect_disc_entry(libnvme_host_t h,
13081308
libnvme_msg(h->ctx, LIBNVME_LOG_INFO, "failed to connect controller, "
13091309
"retry with disabling SQ flow control\n");
13101310
c->cfg.disable_sqflow = false;
1311-
ret = libnvmf_add_ctrl(h, c, &fctx->cfg);
1311+
ret = libnvmf_add_ctrl(h, c, fctx);
13121312
if (!ret) {
13131313
*cp = c;
13141314
return 0;
@@ -2165,7 +2165,7 @@ static int libnvme_add_ctrl(struct libnvmf_context *fctx,
21652165
int err;
21662166

21672167
retry:
2168-
err = libnvmf_add_ctrl(h, c, &fctx->cfg);
2168+
err = libnvmf_add_ctrl(h, c, fctx);
21692169
if (!err)
21702170
return 0;
21712171
if (fctx->decide_retry(fctx, err, fctx->user_data))
@@ -2663,7 +2663,7 @@ static int nbft_connect(struct libnvme_global_ctx *ctx,
26632663
/* Update tls or concat */
26642664
nvmf_update_tls_concat(e, c, h);
26652665

2666-
ret = libnvmf_add_ctrl(h, c, &fctx->cfg);
2666+
ret = libnvmf_add_ctrl(h, c, fctx);
26672667

26682668
/* Resume logging */
26692669
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)