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
91 changes: 16 additions & 75 deletions fabrics.c
Original file line number Diff line number Diff line change
Expand Up @@ -584,34 +584,6 @@ int fabrics_discovery(const char *desc, int argc, char **argv, bool connect)
return ret;
}

static void nvme_parse_tls_args(const char *keyring, const char *tls_key,
const char *tls_key_identity,
struct nvme_fabrics_config *cfg, nvme_ctrl_t c)
{
if (keyring) {
char *endptr;
long id = strtol(keyring, &endptr, 0);

if (endptr != keyring)
cfg->keyring = id;
else
nvme_ctrl_set_keyring(c, keyring);
}

if (tls_key_identity)
nvme_ctrl_set_tls_key_identity(c, tls_key_identity);

if (tls_key) {
char *endptr;
long id = strtol(tls_key, &endptr, 0);

if (endptr != tls_key)
cfg->tls_key = id;
else
nvme_ctrl_set_tls_key(c, tls_key);
}
}

int fabrics_connect(const char *desc, int argc, char **argv)
{
_cleanup_free_ char *hnqn = NULL;
Expand Down Expand Up @@ -924,24 +896,15 @@ int fabrics_disconnect_all(const char *desc, int argc, char **argv)

int fabrics_config(const char *desc, int argc, char **argv)
{
char *subsysnqn = NULL;
char *transport = NULL, *traddr = NULL;
char *trsvcid = NULL, *hostnqn = NULL, *hostid = NULL;
char *host_traddr = NULL, *host_iface = NULL;
_cleanup_free_ char *hnqn = NULL;
_cleanup_free_ char *hid = NULL;
char *hostkey = NULL, *ctrlkey = NULL;
char *keyring = NULL, *tls_key = NULL, *tls_key_identity = NULL;
char *config_file = PATH_NVMF_CONFIG;
unsigned int verbose = 0;
bool scan_tree = false, modify_config = false, update_config = false;
_cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL;
int ret;
char *config_file = PATH_NVMF_CONFIG;
struct nvme_fabrics_config cfg;
struct fabric_args fa = { };
bool scan_tree = false, modify_config = false, update_config = false;
unsigned int verbose = 0;
int ret;

NVMF_ARGS(opts, fa, cfg,
OPT_STRING("dhchap-ctrl-secret", 'C', "STR", &ctrlkey, nvmf_ctrlkey),
OPT_STRING("config", 'J', "FILE", &config_file, nvmf_config_file),
OPT_INCR("verbose", 'v', &verbose, "Increase logging verbosity"),
OPT_FLAG("scan", 'R', &scan_tree, "Scan current NVMeoF topology"),
Expand Down Expand Up @@ -980,52 +943,30 @@ int fabrics_config(const char *desc, int argc, char **argv)
}

if (modify_config) {
nvme_host_t h;
nvme_subsystem_t s;
nvme_ctrl_t c;
_cleanup_free_ struct nvmf_context *fctx = NULL;

if (!subsysnqn) {
if (!fa.subsysnqn) {
fprintf(stderr,
"required argument [--nqn | -n] needed with --modify\n");
return -EINVAL;
}

if (!transport) {
if (!fa.transport) {
fprintf(stderr,
"required argument [--transport | -t] needed with --modify\n");
return -EINVAL;
}

if (!hostnqn)
hostnqn = hnqn = nvmf_hostnqn_from_file();
if (!hostid && hnqn)
hostid = hid = nvmf_hostid_from_file();
h = nvme_lookup_host(ctx, hostnqn, hostid);
if (!h) {
fprintf(stderr, "Failed to lookup host '%s'\n",
hostnqn);
return -ENODEV;
}
if (hostkey)
nvme_host_set_dhchap_key(h, hostkey);
s = nvme_lookup_subsystem(h, NULL, subsysnqn);
if (!s) {
fprintf(stderr, "Failed to lookup subsystem '%s'\n",
subsysnqn);
return -ENODEV;
}
c = nvme_lookup_ctrl(s, transport, traddr,
host_traddr, host_iface,
trsvcid, NULL);
if (!c) {
fprintf(stderr, "Failed to lookup controller\n");
return -ENODEV;
}
if (ctrlkey)
nvme_ctrl_set_dhchap_key(c, ctrlkey);
nvme_parse_tls_args(keyring, tls_key, tls_key_identity, &cfg, c);
ret = create_common_context(ctx, persistent, &fa,
&cfg, NULL, &fctx);
if (ret)
return ret;

nvmf_update_config(c, &cfg);
ret = nvmf_config_modify(ctx, fctx);
if (ret) {
fprintf(stderr, "failed to update config\n");
return ret;
}
}

if (update_config)
Expand Down
2 changes: 1 addition & 1 deletion libnvme/examples/discover-loop.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ int main()
ret = nvme_scan(NULL, &ctx);
if (ret)
return ret;
ret = nvme_default_host(ctx, &h);
ret = nvme_host_get(ctx, NULL, NULL, &h);
if (ret) {
fprintf(stderr, "Failed to allocated memory\n");
return ret;
Expand Down
17 changes: 11 additions & 6 deletions libnvme/libnvme/nvme.i
Original file line number Diff line number Diff line change
Expand Up @@ -556,9 +556,7 @@ struct nvme_ns {
const char *hostkey = NULL,
const char *hostsymname = NULL) {
nvme_host_t h;
if (hostnqn)
h = nvme_lookup_host(ctx, hostnqn, hostid);
if (nvme_default_host(ctx, &h))
if (nvme_host_get(ctx, hostnqn, hostid, &h))
return NULL;
if (hostsymname)
nvme_host_set_hostsymname(h, hostsymname);
Expand Down Expand Up @@ -602,15 +600,22 @@ struct nvme_ns {
}
%};

%pythonappend nvme_subsystem::nvme_subsystem(struct nvme_host *host,
%pythonappend nvme_subsystem::nvme_subsystem(struct nvme_global_ctx *ctx,
struct nvme_host *host,
const char *subsysnqn,
const char *name) {
self.__parent = host # Keep a reference to parent to ensure garbage collection happens in the right order}
%extend nvme_subsystem {
nvme_subsystem(struct nvme_host *host,
nvme_subsystem(struct nvme_global_ctx *ctx,
struct nvme_host *host,
const char *subsysnqn,
const char *name = NULL) {
return nvme_lookup_subsystem(host, name, subsysnqn);
struct nvme_subsystem *s;

if (nvme_subsystem_get(ctx, host, name, subsysnqn, &s))
return NULL;

return s;
}
~nvme_subsystem() {
nvme_free_subsystem($self);
Expand Down
8 changes: 3 additions & 5 deletions libnvme/src/libnvme.ld
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ LIBNVME_2_0 {
nvme_create_ctrl;
nvme_create_global_ctx;
nvme_ctrl_config_match;
nvme_ctrl_find;
nvme_ctrl_first_ns;
nvme_ctrl_first_path;
nvme_ctrl_get_address;
Expand Down Expand Up @@ -56,7 +55,6 @@ LIBNVME_2_0 {
nvme_ctrl_set_tls_key_identity;
nvme_ctrl_set_unique_discovery_ctrl;
nvme_ctrls_filter;
nvme_default_host;
nvme_describe_key_serial;
nvme_disconnect_ctrl;
nvme_dump_config;
Expand Down Expand Up @@ -100,6 +98,7 @@ LIBNVME_2_0 {
nvme_get_telemetry_max;
nvme_get_uuid_list;
nvme_get_version;
nvme_host_get;
nvme_host_get_dhchap_key;
nvme_host_get_global_ctx;
nvme_host_get_hostid;
Expand All @@ -126,11 +125,8 @@ LIBNVME_2_0 {
nvme_insert_tls_key_compat;
nvme_insert_tls_key_versioned;
nvme_ipaddrs_eq;
nvme_lookup_ctrl;
nvme_lookup_host;
nvme_lookup_key;
nvme_lookup_keyring;
nvme_lookup_subsystem;
nvme_mi_admin_admin_passthru;
nvme_mi_admin_xfer;
nvme_mi_aem_disable;
Expand Down Expand Up @@ -249,6 +245,7 @@ LIBNVME_2_0 {
nvme_subsys_filter;
nvme_subsystem_first_ctrl;
nvme_subsystem_first_ns;
nvme_subsystem_get;
nvme_subsystem_get_application;
nvme_subsystem_get_fw_rev;
nvme_subsystem_get_host;
Expand Down Expand Up @@ -283,6 +280,7 @@ LIBNVME_2_0 {
nvmf_add_ctrl;
nvmf_adrfam_str;
nvmf_cms_str;
nvmf_config_modify;
nvmf_connect;
nvmf_connect_config_json;
nvmf_connect_ctrl;
Expand Down
107 changes: 79 additions & 28 deletions libnvme/src/nvme/fabrics.c
Original file line number Diff line number Diff line change
Expand Up @@ -2115,6 +2115,35 @@ static int set_discovery_kato(struct nvmf_context *fctx,
return tmo;
}

static void nvme_parse_tls_args(const char *keyring, const char *tls_key,
const char *tls_key_identity,
struct nvme_fabrics_config *cfg, nvme_ctrl_t c)
{
if (keyring) {
char *endptr;
long id = strtol(keyring, &endptr, 0);

if (endptr != keyring)
cfg->keyring = id;
else
nvme_ctrl_set_keyring(c, keyring);
}

if (tls_key_identity)
nvme_ctrl_set_tls_key_identity(c, tls_key_identity);

if (tls_key) {
char *endptr;
long id = strtol(tls_key, &endptr, 0);

if (endptr != tls_key)
cfg->tls_key = id;
else
nvme_ctrl_set_tls_key(c, tls_key);
}
}


static int _nvmf_discovery(struct nvme_global_ctx *ctx,
struct nvmf_context *fctx, bool connect,
struct nvme_ctrl *c)
Expand Down Expand Up @@ -2621,6 +2650,56 @@ int nvmf_discovery_config_file(struct nvme_global_ctx *ctx,
return 0;
}

int nvmf_config_modify(struct nvme_global_ctx *ctx,
struct nvmf_context *fctx)
{
_cleanup_free_ char *hnqn = NULL;
_cleanup_free_ char *hid = NULL;
struct nvme_host *h;
struct nvme_subsystem *s;
struct nvme_ctrl *c;

if (!fctx->hostnqn)
fctx->hostnqn = hnqn = nvmf_hostnqn_from_file();
if (!fctx->hostid && hnqn)
fctx->hostid = hid = nvmf_hostid_from_file();

h = nvme_lookup_host(ctx, fctx->hostnqn, fctx->hostid);
if (!h) {
nvme_msg(ctx, LOG_ERR, "Failed to lookup host '%s'\n",
fctx->hostnqn);
return -ENODEV;
}

if (fctx->hostkey)
nvme_host_set_dhchap_key(h, fctx->hostkey);

s = nvme_lookup_subsystem(h, NULL, fctx->subsysnqn);
if (!s) {
nvme_msg(ctx, LOG_ERR, "Failed to lookup subsystem '%s'\n",
fctx->subsysnqn);
return -ENODEV;
}

c = nvme_lookup_ctrl(s, fctx->transport, fctx->traddr,
fctx->host_traddr, fctx->host_iface,
fctx->trsvcid, NULL);
if (!c) {
nvme_msg(ctx, LOG_ERR, "Failed to lookup controller\n");
return -ENODEV;
}

if (fctx->ctrlkey)
nvme_ctrl_set_dhchap_key(c, fctx->ctrlkey);

nvme_parse_tls_args(fctx->keyring, fctx->tls_key,
fctx->tls_key_identity, fctx->cfg, c);

nvmf_update_config(c, fctx->cfg);

return 0;
}

#define NBFT_SYSFS_FILENAME "NBFT*"

static int nbft_filter(const struct dirent *dent)
Expand Down Expand Up @@ -3283,34 +3362,6 @@ int nvmf_discovery(struct nvme_global_ctx *ctx, struct nvmf_context *fctx,
return ret;
}

static void nvme_parse_tls_args(const char *keyring, const char *tls_key,
const char *tls_key_identity,
struct nvme_fabrics_config *cfg, nvme_ctrl_t c)
{
if (keyring) {
char *endptr;
long id = strtol(keyring, &endptr, 0);

if (endptr != keyring)
cfg->keyring = id;
else
nvme_ctrl_set_keyring(c, keyring);
}

if (tls_key_identity)
nvme_ctrl_set_tls_key_identity(c, tls_key_identity);

if (tls_key) {
char *endptr;
long id = strtol(tls_key, &endptr, 0);

if (endptr != tls_key)
cfg->tls_key = id;
else
nvme_ctrl_set_tls_key(c, tls_key);
}
}

int nvmf_connect(struct nvme_global_ctx *ctx, struct nvmf_context *fctx)
{
struct nvme_host *h;
Expand Down
13 changes: 13 additions & 0 deletions libnvme/src/nvme/fabrics.h
Original file line number Diff line number Diff line change
Expand Up @@ -632,6 +632,19 @@ int nvmf_connect(struct nvme_global_ctx *ctx, struct nvmf_context *fctx);
int nvmf_connect_config_json(struct nvme_global_ctx *ctx,
struct nvmf_context *fctx);

/**
* nvmf_config_modify() - Modify and update the configurtion
* @ctx: Global context
* @fctx: Fabrics context
*
* Update the current configuration by adding the crypto
* information.
*
* Return: 0 on success, or a negative error code on failure.
*/
int nvmf_config_modify(struct nvme_global_ctx *ctx,
struct nvmf_context *fctx);

/**
* struct nbft_file_entry - Linked list entry for NBFT files
* @next: Pointer to next entry
Expand Down
14 changes: 14 additions & 0 deletions libnvme/src/nvme/private.h
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,20 @@ void *__nvme_alloc(size_t len);

void *__nvme_realloc(void *p, size_t len);

nvme_host_t nvme_lookup_host(struct nvme_global_ctx *ctx, const char *hostnqn,
const char *hostid);
nvme_subsystem_t nvme_lookup_subsystem(struct nvme_host *h,
const char *name,
const char *subsysnqn);
nvme_ctrl_t nvme_lookup_ctrl(nvme_subsystem_t s, const char *transport,
const char *traddr, const char *host_traddr,
const char *host_iface, const char *trsvcid,
nvme_ctrl_t p);
nvme_ctrl_t nvme_ctrl_find(nvme_subsystem_t s, const char *transport,
const char *traddr, const char *trsvcid,
const char *subsysnqn, const char *host_traddr,
const char *host_iface);

#if (LOG_FUNCNAME == 1)
#define __nvme_log_func __func__
#else
Expand Down
Loading