Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
136 changes: 91 additions & 45 deletions fabrics.c
Original file line number Diff line number Diff line change
Expand Up @@ -110,15 +110,33 @@
const char *keyring;
const char *tls_key;
const char *tls_key_identity;
int queue_size;
int nr_io_queues;
int reconnect_delay;
int ctrl_loss_tmo;
int fast_io_fail_tmo;
int keep_alive_tmo;
int nr_write_queues;
int nr_poll_queues;
int tos;
long keyring_id;
long tls_key_id;
long tls_configured_key_id;
bool duplicate_connect;
bool disable_sqflow;
bool hdr_digest;
bool data_digest;
bool tls;
bool concat;
};

#define NVMF_ARGS(n, f, c, ...) \
#define NVMF_ARGS(n, f, ...) \

Check failure on line 133 in fabrics.c

View workflow job for this annotation

GitHub Actions / checkpatch review

ERROR: Macros with complex values should be enclosed in parentheses

Check failure on line 133 in fabrics.c

View workflow job for this annotation

GitHub Actions / checkpatch review

WARNING: line length of 95 exceeds 80 columns
NVME_ARGS(n, \
OPT_STRING("transport", 't', "STR", &f.transport, nvmf_tport), \
OPT_STRING("nqn", 'n', "STR", &f.subsysnqn, nvmf_nqn), \
OPT_STRING("traddr", 'a', "STR", &f.traddr, nvmf_traddr), \
OPT_STRING("trsvcid", 's', "STR", &f.trsvcid, nvmf_trsvcid), \
OPT_STRING("host-traddr", 'w', "STR", &f.host_traddr, nvmf_htraddr), \

Check failure on line 139 in fabrics.c

View workflow job for this annotation

GitHub Actions / checkpatch review

WARNING: line length of 98 exceeds 80 columns
OPT_STRING("host-iface", 'f', "STR", &f.host_iface, nvmf_hiface), \
OPT_STRING("hostnqn", 'q', "STR", &f.hostnqn, nvmf_hostnqn), \
OPT_STRING("hostid", 'I', "STR", &f.hostid, nvmf_hostid), \
Expand All @@ -127,25 +145,31 @@
OPT_STRING("keyring", 0, "STR", &f.keyring, nvmf_keyring), \
OPT_STRING("tls-key", 0, "STR", &f.tls_key, nvmf_tls_key), \
OPT_STRING("tls-key-identity", 0, "STR", &f.tls_key_identity, nvmf_tls_key_identity), \
OPT_INT("nr-io-queues", 'i', &c.nr_io_queues, nvmf_nr_io_queues), \
OPT_INT("nr-write-queues", 'W', &c.nr_write_queues, nvmf_nr_write_queues), \
OPT_INT("nr-poll-queues", 'P', &c.nr_poll_queues, nvmf_nr_poll_queues), \
OPT_INT("queue-size", 'Q', &c.queue_size, nvmf_queue_size), \
OPT_INT("keep-alive-tmo", 'k', &c.keep_alive_tmo, nvmf_keep_alive_tmo), \
OPT_INT("reconnect-delay", 'c', &c.reconnect_delay, nvmf_reconnect_delay), \
OPT_INT("ctrl-loss-tmo", 'l', &c.ctrl_loss_tmo, nvmf_ctrl_loss_tmo), \
OPT_INT("fast_io_fail_tmo", 'F', &c.fast_io_fail_tmo, nvmf_fast_io_fail_tmo),\
OPT_INT("tos", 'T', &c.tos, nvmf_tos), \
OPT_INT("tls_key", 0, &c.tls_key, nvmf_tls_key_legacy), \
OPT_FLAG("duplicate-connect", 'D', &c.duplicate_connect, nvmf_dup_connect), \
OPT_FLAG("disable-sqflow", 0, &c.disable_sqflow, nvmf_disable_sqflow), \
OPT_FLAG("hdr-digest", 'g', &c.hdr_digest, nvmf_hdr_digest), \
OPT_FLAG("data-digest", 'G', &c.data_digest, nvmf_data_digest), \
OPT_FLAG("tls", 0, &c.tls, nvmf_tls), \
OPT_FLAG("concat", 0, &c.concat, nvmf_concat), \
OPT_INT("nr-io-queues", 'i', &f.nr_io_queues, nvmf_nr_io_queues), \

Check failure on line 148 in fabrics.c

View workflow job for this annotation

GitHub Actions / checkpatch review

WARNING: line length of 98 exceeds 80 columns
OPT_INT("nr-write-queues", 'W', &f.nr_write_queues, nvmf_nr_write_queues), \

Check failure on line 149 in fabrics.c

View workflow job for this annotation

GitHub Actions / checkpatch review

WARNING: line length of 98 exceeds 80 columns
OPT_INT("nr-poll-queues", 'P', &f.nr_poll_queues, nvmf_nr_poll_queues), \

Check failure on line 150 in fabrics.c

View workflow job for this annotation

GitHub Actions / checkpatch review

WARNING: line length of 98 exceeds 80 columns
OPT_INT("queue-size", 'Q', &f.queue_size, nvmf_queue_size), \

Check failure on line 151 in fabrics.c

View workflow job for this annotation

GitHub Actions / checkpatch review

WARNING: line length of 98 exceeds 80 columns
OPT_INT("keep-alive-tmo", 'k', &f.keep_alive_tmo, nvmf_keep_alive_tmo), \

Check failure on line 152 in fabrics.c

View workflow job for this annotation

GitHub Actions / checkpatch review

WARNING: line length of 98 exceeds 80 columns
OPT_INT("reconnect-delay", 'c', &f.reconnect_delay, nvmf_reconnect_delay), \
OPT_INT("ctrl-loss-tmo", 'l', &f.ctrl_loss_tmo, nvmf_ctrl_loss_tmo), \
OPT_INT("fast_io_fail_tmo", 'F', &f.fast_io_fail_tmo, nvmf_fast_io_fail_tmo),\
OPT_INT("tos", 'T', &f.tos, nvmf_tos), \
OPT_INT("tls_key", 0, &f.tls_key_id, nvmf_tls_key_legacy), \
OPT_FLAG("duplicate-connect", 'D', &f.duplicate_connect, nvmf_dup_connect), \
OPT_FLAG("disable-sqflow", 0, &f.disable_sqflow, nvmf_disable_sqflow), \
OPT_FLAG("hdr-digest", 'g', &f.hdr_digest, nvmf_hdr_digest), \
OPT_FLAG("data-digest", 'G', &f.data_digest, nvmf_data_digest), \
OPT_FLAG("tls", 0, &f.tls, nvmf_tls), \
OPT_FLAG("concat", 0, &f.concat, nvmf_concat), \
##__VA_ARGS__ \
)

static void nvmf_default_args(struct nvmf_args *fa)
{
memset(fa, 0, sizeof(*fa));
fa->tos = -1;
fa->ctrl_loss_tmo = NVMF_DEF_CTRL_LOSS_TMO;
}

static void save_discovery_log(char *raw, struct nvmf_discovery_log *log)
{
Expand Down Expand Up @@ -174,7 +198,7 @@
struct nvmf_args *fa);

struct cb_fabrics_data {
struct libnvme_fabrics_config *cfg;
struct nvmf_args *fa;
nvme_print_flags_t flags;
bool quiet;
char *raw;
Expand Down Expand Up @@ -274,20 +298,49 @@
fclose(cfd->f);
}

static int set_fabrics_options(struct libnvmf_context *fctx,
struct nvmf_args *fa)
{
struct libnvme_fabrics_config *fcfg;

fcfg = libnvmf_context_get_fabrics_config(fctx);
if (!fcfg)
return -EINVAL;

libnvme_fabrics_config_set_nr_io_queues(fcfg, fa->nr_io_queues);
libnvme_fabrics_config_set_reconnect_delay(fcfg, fa->reconnect_delay);
libnvme_fabrics_config_set_ctrl_loss_tmo(fcfg, fa->ctrl_loss_tmo);
libnvme_fabrics_config_set_fast_io_fail_tmo(fcfg, fa->fast_io_fail_tmo);
libnvme_fabrics_config_set_keep_alive_tmo(fcfg, fa->keep_alive_tmo);
libnvme_fabrics_config_set_nr_write_queues(fcfg, fa->nr_write_queues);
libnvme_fabrics_config_set_nr_poll_queues(fcfg, fa->nr_poll_queues);
libnvme_fabrics_config_set_tos(fcfg, fa->tos);
libnvme_fabrics_config_set_keyring_id(fcfg, fa->keyring_id);
libnvme_fabrics_config_set_tls_key_id(fcfg, fa->tls_key_id);
libnvme_fabrics_config_set_tls_configured_key_id(fcfg, fa->tls_configured_key_id);
libnvme_fabrics_config_set_duplicate_connect(fcfg, fa->duplicate_connect);
libnvme_fabrics_config_set_disable_sqflow(fcfg, fa->disable_sqflow);
libnvme_fabrics_config_set_hdr_digest(fcfg, fa->hdr_digest);
libnvme_fabrics_config_set_data_digest(fcfg, fa->data_digest);
libnvme_fabrics_config_set_tls(fcfg, fa->tls);
libnvme_fabrics_config_set_concat(fcfg, fa->concat);

return 0;
}

static int cb_parser_next_line(struct libnvmf_context *fctx, void *user_data)
{
struct cb_fabrics_data *cfd = user_data;
struct libnvme_fabrics_config cfg;
struct nvmf_args fa = {};
struct nvmf_args fa;
char *ptr, *p, line[4096];
int argc, ret = 0;
bool force = false;

NVMF_ARGS(opts, fa, cfg,
NVMF_ARGS(opts, fa,
OPT_FLAG("persistent", 'p', &persistent, "persistent discovery connection"),
OPT_FLAG("force", 0, &force, "Force persistent discovery controller creation"));

memcpy(&cfg, cfd->cfg, sizeof(cfg));
memcpy(&fa, cfd->fa, sizeof(fa));
next:
if (fgets(line, sizeof(line), cfd->f) == NULL)
return -EOF;
Expand Down Expand Up @@ -315,7 +368,7 @@
if (ret)
return ret;

ret = libnvmf_context_set_fabrics_config(fctx, &cfg);
ret = set_fabrics_options(fctx, &fa);
if (ret)
return ret;

Expand Down Expand Up @@ -351,7 +404,6 @@

static int create_common_context(struct libnvme_global_ctx *ctx,
bool persistent, struct nvmf_args *fa,
struct libnvme_fabrics_config *cfg,
void *user_data, struct libnvmf_context **fctxp)
{
struct libnvmf_context *fctx;
Expand All @@ -372,7 +424,7 @@
if (err)
goto err;

err = libnvmf_context_set_fabrics_config(fctx, cfg);
err = set_fabrics_options(fctx, fa);
if (err)
goto err;

Expand All @@ -397,13 +449,12 @@
static int create_discovery_context(struct libnvme_global_ctx *ctx,
bool persistent, const char *device,
struct nvmf_args *fa,
struct libnvme_fabrics_config *cfg,
void *user_data, struct libnvmf_context **fctxp)
{
struct libnvmf_context *fctx;
int err;

err = create_common_context(ctx, persistent, fa, cfg, user_data,
err = create_common_context(ctx, persistent, fa, user_data,
&fctx);
if (err)
return err;
Expand Down Expand Up @@ -527,15 +578,14 @@
__cleanup_nvme_global_ctx struct libnvme_global_ctx *ctx = NULL;
__cleanup_nvmf_context struct libnvmf_context *fctx = NULL;
int ret;
struct libnvme_fabrics_config cfg;
struct nvmf_args fa = { .subsysnqn = NVME_DISC_SUBSYS_NAME };
char *device = NULL;
bool force = false;
bool json_config = false;
bool nbft = false, nonbft = false;
char *nbft_path = NBFT_SYSFS_PATH;

NVMF_ARGS(opts, fa, cfg,
NVMF_ARGS(opts, fa,
OPT_STRING("device", 'd', "DEV", &device, "use existing discovery controller device"),
OPT_FILE("raw", 'r', &raw, "save raw output to file"),
OPT_FLAG("persistent", 'p', &persistent, "persistent discovery connection"),
Expand All @@ -548,7 +598,7 @@
OPT_STRING("nbft-path", 0, "STR", &nbft_path, "user-defined path for NBFT tables"),
OPT_STRING("context", 0, "STR", &context, nvmf_context));

libnvmf_default_config(&cfg);
nvmf_default_args(&fa);

load_nvme_fabrics_module();

Expand Down Expand Up @@ -597,12 +647,12 @@
}

struct cb_fabrics_data dld = {
.cfg = &cfg,
.fa = &fa,
.flags = flags,
.raw = raw,
};
ret = create_discovery_context(ctx, persistent, device, &fa,
&cfg, &dld, &fctx);
&dld, &fctx);
if (ret)
return ret;

Expand Down Expand Up @@ -643,15 +693,14 @@
__cleanup_nvme_ctrl libnvme_ctrl_t c = NULL;
int ret;
nvme_print_flags_t flags;
struct libnvme_fabrics_config cfg = { 0 };
struct nvmf_args fa = { 0 };

NVMF_ARGS(opts, fa, cfg,
NVMF_ARGS(opts, fa,
OPT_STRING("config", 'J', "FILE", &config_file, nvmf_config_file),
OPT_FLAG("dump-config", 'O', &dump_config, "Dump JSON configuration to stdout"),
OPT_STRING("context", 0, "STR", &context, nvmf_context));

libnvmf_default_config(&cfg);
nvmf_default_args(&fa);

load_nvme_fabrics_module();

Expand Down Expand Up @@ -717,8 +766,7 @@
.quiet = dump_config,
.raw = raw,
};
ret = create_common_context(ctx, persistent, &fa,
&cfg, &cfd, &fctx);
ret = create_common_context(ctx, persistent, &fa, &cfd, &fctx);
if (ret)
return ret;

Expand Down Expand Up @@ -773,7 +821,7 @@
if (strcmp(libnvme_subsystem_get_subsysnqn(s), p))
continue;
libnvme_subsystem_for_each_ctrl(s, c) {
if (!libnvme_disconnect_ctrl(c))
if (!libnvmf_disconnect_ctrl(c))
i++;
}
}
Expand Down Expand Up @@ -856,7 +904,7 @@
"Did not find device %s\n", p);
return -ENODEV;
}
ret = libnvme_disconnect_ctrl(c);
ret = libnvmf_disconnect_ctrl(c);
if (ret)
fprintf(stderr,
"Failed to disconnect %s: %s\n",
Expand Down Expand Up @@ -922,7 +970,7 @@
else if (!strcmp(libnvme_ctrl_get_transport(c),
"pcie"))
continue;
if (libnvme_disconnect_ctrl(c))
if (libnvmf_disconnect_ctrl(c))
fprintf(stderr,
"failed to disconnect %s\n",
libnvme_ctrl_get_name(c));
Expand All @@ -938,18 +986,17 @@
bool scan_tree = false, modify_config = false, update_config = false;
__cleanup_nvme_global_ctx struct libnvme_global_ctx *ctx = NULL;
char *config_file = PATH_NVMF_CONFIG;
struct libnvme_fabrics_config cfg;
struct nvmf_args fa = { };
int ret;

NVMF_ARGS(opts, fa, cfg,
NVMF_ARGS(opts, fa,
OPT_STRING("config", 'J', "FILE", &config_file, nvmf_config_file),
OPT_FLAG("scan", 'R', &scan_tree, "Scan current NVMeoF topology"),
OPT_FLAG("modify", 'M', &modify_config, "Modify JSON configuration file"),
OPT_FLAG("dump", 'O', &dump_config, "Dump JSON configuration to stdout"),
OPT_FLAG("update", 'U', &update_config, "Update JSON configuration file"));

libnvmf_default_config(&cfg);
nvmf_default_args(&fa);

ret = argconfig_parse(argc, argv, desc, opts);
if (ret)
Expand Down Expand Up @@ -994,8 +1041,7 @@
return -EINVAL;
}

ret = create_common_context(ctx, persistent, &fa,
&cfg, NULL, &fctx);
ret = create_common_context(ctx, persistent, &fa, NULL, &fctx);
if (ret)
return ret;

Expand Down
41 changes: 26 additions & 15 deletions libnvme/examples/discover-loop.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,38 +53,45 @@ int main()
{
struct nvmf_discovery_log *log = NULL;
struct libnvme_global_ctx *ctx;
struct libnvmf_context *fctx;
libnvme_host_t h;
libnvme_ctrl_t c;
int ret;
struct libnvme_fabrics_config cfg;
struct libnvmf_discovery_args *args;

libnvmf_default_config(&cfg);

ctx = libnvme_create_global_ctx(stdout, LIBNVME_DEFAULT_LOGLEVEL);
if (!ctx)
return 1;

ret = libnvmf_context_create(ctx, NULL, NULL, NULL, NULL, &fctx);
if (ret)
goto free_ctx;

ret = libnvmf_context_set_connection(fctx, NVME_DISC_SUBSYS_NAME,
"loop", NULL, NULL, NULL, NULL);
if (ret)
goto free_ctx;

ret = libnvme_scan_topology(ctx, NULL, NULL);
if (ret) {
libnvme_free_global_ctx(ctx);
return 1;
}
if (ret)
goto free_fctx;

ret = libnvme_get_host(ctx, NULL, NULL, &h);
if (ret) {
fprintf(stderr, "Failed to allocated memory\n");
return 1;
goto free_fctx;
}
ret = libnvme_create_ctrl(ctx, NVME_DISC_SUBSYS_NAME, "loop",
NULL, NULL, NULL, NULL, &c);

ret = libnvmf_create_ctrl(ctx, fctx, &c);
if (ret) {
fprintf(stderr, "Failed to allocate memory\n");
return 1;
goto free_fctx;
}
ret = libnvmf_add_ctrl(h, c, &cfg);

ret = libnvmf_add_ctrl(h, c);
if (ret) {
fprintf(stderr, "no controller found\n");
return 1;
goto free_fctx;
}

ret = libnvmf_discovery_args_create(&args);
Expand All @@ -94,15 +101,19 @@ int main()
libnvmf_discovery_args_free(args);
}

libnvme_disconnect_ctrl(c);
libnvmf_disconnect_ctrl(c);
libnvme_free_ctrl(c);

if (ret)
fprintf(stderr, "nvmf-discover-log:%x\n", ret);
else
print_discover_log(log);

free_fctx:
libnvmf_context_free(fctx);
free_ctx:
libnvme_free_global_ctx(ctx);
free(log);
return 0;

return ret ? 1 : 0;
}
Loading
Loading