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
10 changes: 5 additions & 5 deletions fabrics.c
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ static int create_common_context(struct nvme_global_ctx *ctx,
return 0;

err:
free(fctx);
nvmf_context_free(fctx);
return err;
}

Expand Down Expand Up @@ -425,7 +425,7 @@ static int create_discovery_context(struct nvme_global_ctx *ctx,
return 0;

err:
free(fctx);
nvmf_context_free(fctx);
return err;
}

Expand Down Expand Up @@ -480,7 +480,7 @@ int fabrics_discovery(const char *desc, int argc, char **argv, bool connect)
char *context = NULL;
nvme_print_flags_t flags;
_cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL;
_cleanup_free_ struct nvmf_context *fctx = NULL;
_cleanup_nvmf_context_ struct nvmf_context *fctx = NULL;
int ret;
struct nvme_fabrics_config cfg;
struct nvmf_args fa = { .subsysnqn = NVME_DISC_SUBSYS_NAME };
Expand Down Expand Up @@ -592,7 +592,7 @@ int fabrics_connect(const char *desc, int argc, char **argv)
char *config_file = NULL;
char *context = NULL;
_cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL;
_cleanup_free_ struct nvmf_context *fctx = NULL;
_cleanup_nvmf_context_ struct nvmf_context *fctx = NULL;
_cleanup_nvme_ctrl_ nvme_ctrl_t c = NULL;
int ret;
nvme_print_flags_t flags;
Expand Down Expand Up @@ -931,7 +931,7 @@ int fabrics_config(const char *desc, int argc, char **argv)
}

if (modify_config) {
_cleanup_free_ struct nvmf_context *fctx = NULL;
_cleanup_nvmf_context_ struct nvmf_context *fctx = NULL;

if (!fa.subsysnqn) {
fprintf(stderr,
Expand Down
39 changes: 20 additions & 19 deletions libnvme/src/libnvme.ld
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ LIBNVME_3 {
nvme_close;
nvme_create_ctrl;
nvme_create_global_ctx;
nvme_ctrl_match_config;
nvme_create_raw_secret;
nvme_ctrl_first_ns;
nvme_ctrl_first_path;
nvme_ctrl_get_config;
Expand All @@ -17,26 +17,34 @@ LIBNVME_3 {
nvme_ctrl_get_subsystem;
nvme_ctrl_get_transport_handle;
nvme_ctrl_identify;
nvme_ctrl_match_config;
nvme_ctrl_next_ns;
nvme_ctrl_next_path;
nvme_ctrl_release_transport_handle;
nvme_reset_ctrl;
nvme_filter_ctrls;
nvme_describe_key_serial;
nvme_disconnect_ctrl;
nvme_dump_config;
nvme_dump_tree;
nvme_errno_to_string;
nvme_export_tls_key;
nvme_export_tls_key_versioned;
nvme_filter_ctrls;
nvme_filter_namespace;
nvme_filter_paths;
nvme_filter_subsys;
nvme_find_uuid;
nvme_first_host;
nvme_first_subsystem;
nvme_free_ctrl;
nvme_free_global_ctx;
nvme_free_host;
nvme_free_nbft;
nvme_free_ns;
nvme_free_subsystem;
nvme_gen_dhchap_key;
nvme_generate_hostid;
nvme_generate_hostnqn;
nvme_generate_hostnqn_from_hostid;
nvme_generate_tls_key_identity;
nvme_generate_tls_key_identity_compat;
nvme_get_ana_log_atomic;
Expand All @@ -48,6 +56,7 @@ LIBNVME_3 {
nvme_get_ctrl_telemetry;
nvme_get_directive_receive_length;
nvme_get_feature_length;
nvme_get_host;
nvme_get_host_telemetry;
nvme_get_log;
nvme_get_logging_level;
Expand All @@ -57,21 +66,16 @@ LIBNVME_3 {
nvme_get_nsid;
nvme_get_path_attr;
nvme_get_subsys_attr;
nvme_get_subsystem;
nvme_get_telemetry_log;
nvme_get_telemetry_max;
nvme_get_uuid_list;
nvme_get_version;
nvme_get_host;
nvme_host_get_global_ctx;
nvme_host_get_ids;
nvme_host_is_pdc_enabled;
nvme_host_release_fds;
nvme_host_set_pdc_enabled;
nvme_read_hostid;
nvme_generate_hostid;
nvme_read_hostnqn;
nvme_generate_hostnqn;
nvme_generate_hostnqn_from_hostid;
nvme_import_tls_key;
nvme_import_tls_key_versioned;
nvme_init_ctrl;
Expand Down Expand Up @@ -111,11 +115,8 @@ LIBNVME_3 {
nvme_mi_status_to_string;
nvme_mi_submit_entry;
nvme_mi_submit_exit;
nvme_filter_namespace;
nvme_namespace_first_path;
nvme_namespace_next_path;
nvme_free_nbft;
nvme_read_nbft;
nvme_next_host;
nvme_next_subsystem;
nvme_ns_compare;
Expand All @@ -132,7 +133,6 @@ LIBNVME_3 {
nvme_ns_get_uuid;
nvme_ns_identify;
nvme_ns_read;
nvme_rescan_ns;
nvme_ns_verify;
nvme_ns_write;
nvme_ns_write_uncorrectable;
Expand All @@ -142,11 +142,17 @@ LIBNVME_3 {
nvme_path_get_ctrl;
nvme_path_get_ns;
nvme_path_get_queue_depth;
nvme_filter_paths;
nvme_random_uuid;
nvme_read_config;
nvme_read_hostid;
nvme_read_hostnqn;
nvme_read_key;
nvme_read_nbft;
nvme_refresh_topology;
nvme_rescan_ctrl;
nvme_rescan_ns;
nvme_reset_ctrl;
nvme_reset_subsystem;
nvme_revoke_tls_key;
nvme_scan_ctrl;
nvme_scan_ctrl_namespace_paths;
Expand All @@ -169,16 +175,13 @@ LIBNVME_3 {
nvme_strerror;
nvme_submit_admin_passthru;
nvme_submit_io_passthru;
nvme_filter_subsys;
nvme_subsystem_first_ctrl;
nvme_subsystem_first_ns;
nvme_get_subsystem;
nvme_subsystem_get_host;
nvme_subsystem_lookup_namespace;
nvme_subsystem_next_ctrl;
nvme_subsystem_next_ns;
nvme_subsystem_release_fds;
nvme_reset_subsystem;
nvme_transport_handle_get_fd;
nvme_transport_handle_get_name;
nvme_transport_handle_is_blkdev;
Expand All @@ -190,9 +193,7 @@ LIBNVME_3 {
nvme_transport_handle_set_submit_exit;
nvme_unlink_ctrl;
nvme_update_key;
nvme_find_uuid;
nvme_uuid_from_string;
nvme_random_uuid;
nvme_uuid_to_string;
local:
*;
Expand Down
1 change: 1 addition & 0 deletions libnvme/src/libnvmf.ld
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ LIBNVMF_3 {
nvmf_connect_config_json;
nvmf_connect_ctrl;
nvmf_context_create;
nvmf_context_free;
nvmf_context_set_connection;
nvmf_context_set_crypto;
nvmf_context_set_device;
Expand Down
35 changes: 34 additions & 1 deletion libnvme/src/nvme/fabrics.c
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,8 @@ __public int nvmf_context_create(struct nvme_global_ctx *ctx,
if (!fctx)
return -ENOMEM;

fctx->ctx = ctx;

fctx->decide_retry = decide_retry;
fctx->connected = connected;
fctx->already_connected = already_connected;
Expand All @@ -214,6 +216,12 @@ __public int nvmf_context_create(struct nvme_global_ctx *ctx,
return 0;
}

__public void nvmf_context_free(struct nvmf_context *fctx)
{
free(fctx->tls_key);
free(fctx);
}

__public int nvmf_context_set_discovery_cbs(struct nvmf_context *fctx,
void (*discovery_log)(struct nvmf_context *fctx,
bool connect,
Expand Down Expand Up @@ -280,12 +288,37 @@ __public int nvmf_context_set_crypto(struct nvmf_context *fctx,
const char *keyring, const char *tls_key,
const char *tls_key_identity)
{
int err;

fctx->hostkey = hostkey;
fctx->ctrlkey = ctrlkey;
fctx->keyring = keyring;
fctx->tls_key = tls_key;
fctx->tls_key_identity = tls_key_identity;

if (!tls_key)
return 0;

if (!strncmp(tls_key, "pin:", 4)) {
_cleanup_free_ unsigned char *raw_secret = NULL;
_cleanup_free_ char *encoded_key = NULL;
int key_len = 32;

err = nvme_create_raw_secret(fctx->ctx, tls_key,
key_len, &raw_secret);
if (err)
return err;

err = nvme_export_tls_key(fctx->ctx, raw_secret,
key_len, &encoded_key);
if (err)
return err;

fctx->tls_key = encoded_key;
encoded_key = NULL;
return 0;
}

fctx->tls_key = strdup(tls_key);
return 0;
}

Expand Down
11 changes: 11 additions & 0 deletions libnvme/src/nvme/fabrics.h
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,17 @@ int nvmf_context_create(struct nvme_global_ctx *ctx,
const char *trsvcid, void *user_data),
void *user_data, struct nvmf_context **fctxp);

/**
* nvmf_context_free() - Free a fabrics context
* @fctx: Fabrics context to free
*
* Releases all resources associated with @fctx. The context must have
* been previously created with nvmf_context_create().
*
* After this call, @fctx must not be used.
*/
void nvmf_context_free(struct nvmf_context *fctx);

/**
* nvmf_context_set_discovery_cbs() - Set discovery callbacks for context
* @fctx: Fabrics context
Expand Down
Loading
Loading