Skip to content
Open
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
8 changes: 4 additions & 4 deletions libnvme/libnvme/nvme.i
Original file line number Diff line number Diff line change
Expand Up @@ -1236,26 +1236,26 @@ struct nvme_ns {
return output;
}

PyObject *nbft_get(const char * filename)
PyObject *nbft_get(struct nvme_global_ctx *ctx, const char * filename)
{
struct nbft_info *nbft;
PyObject *output;
int ret;

ret = nvme_nbft_read(&nbft, filename);
ret = nvme_nbft_read(ctx, &nbft, filename);
if (ret) {
Py_RETURN_NONE;
}

output = nbft_to_pydict(nbft);
nvme_nbft_free(nbft);
nvme_nbft_free(ctx, nbft);
return output;
}
%};

%feature("autodoc", "@return an NBFT table as a dict on success, None otherwise.\n"
"@param filename: file to read") nbft_get;
PyObject *nbft_get(const char * filename);
PyObject *nbft_get(struct nvme_global_ctx *ctx, const char * filename);

// We want to swig all the #define and enum from types.h, but none of the structs.
#pragma SWIG nowarn=503 // Supress warnings about unnamed struct
Expand Down
4 changes: 3 additions & 1 deletion libnvme/libnvme/tests/test-nbft.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,9 @@ def setUp(self):

def test_read_nbft_file(self):
"""Make sure we get expected data when reading from binary NBFT file"""
actual_nbft = nvme.nbft_get(args.filename)
ctx = nvme.global_ctx()
ctx.log_level('debug')
actual_nbft = nvme.nbft_get(ctx, args.filename)
self.assertEqual(actual_nbft, self.expected_nbft)


Expand Down
5 changes: 1 addition & 4 deletions libnvme/src/libnvme.map
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ LIBNVME_2_0 {
nvme_close;
nvme_create_ctrl;
nvme_create_global_ctx;
nvme_create_host;
nvme_ctrl_config_match;
nvme_ctrl_find;
nvme_ctrl_first_ns;
Expand Down Expand Up @@ -90,12 +91,10 @@ LIBNVME_2_0 {
nvme_get_attr;
nvme_get_ctrl_attr;
nvme_get_ctrl_telemetry;
nvme_get_debug;
nvme_get_directive_receive_length;
nvme_get_feature_length;
nvme_get_host_telemetry;
nvme_get_log;
nvme_get_logging_level;
nvme_get_logical_block_size;
nvme_get_new_host_telemetry;
nvme_get_ns_attr;
Expand Down Expand Up @@ -125,7 +124,6 @@ LIBNVME_2_0 {
nvme_init_copy_range_f3;
nvme_init_ctrl;
nvme_init_ctrl_list;
nvme_init_default_logging;
nvme_init_dsm_range;
nvme_init_logging;
nvme_insert_tls_key;
Expand Down Expand Up @@ -239,7 +237,6 @@ LIBNVME_2_0 {
nvme_scan_tls_keys;
nvme_scan_topology;
nvme_set_application;
nvme_set_debug;
nvme_set_dry_run;
nvme_set_keyring;
nvme_set_property;
Expand Down
44 changes: 27 additions & 17 deletions libnvme/src/nvme/fabrics.c
Original file line number Diff line number Diff line change
Expand Up @@ -732,7 +732,8 @@ static int build_options(nvme_host_t h, nvme_ctrl_t c, char **argstr)
ctrlkey = nvme_ctrl_get_dhchap_key(c);

if (cfg->tls) {
ret = __nvme_import_keys_from_config(h, c, &keyring_id, &key_id);
ret = __nvme_import_keys_from_config(h, c,
&keyring_id, &key_id);
if (ret)
return ret;

Expand Down Expand Up @@ -2045,7 +2046,7 @@ static nvme_ctrl_t lookup_ctrl(nvme_host_t h, struct fabric_args *trcfg)
return NULL;
}

static int lookup_host(struct nvme_global_ctx *ctx,
static int lookup_or_create_host(struct nvme_global_ctx *ctx,
struct nvmf_context *fctx, struct nvme_host **host)
{
_cleanup_free_ char *hnqn = NULL;
Expand All @@ -2058,9 +2059,14 @@ static int lookup_host(struct nvme_global_ctx *ctx,
return err;

h = nvme_lookup_host(ctx, hnqn, hid);
if (!h)
if (h)
goto out;

err = nvme_create_host(ctx, fctx->hostnqn, fctx->hostid, &h);
if (err)
return -ENOMEM;

out:
*host = h;

return 0;
Expand Down Expand Up @@ -2437,7 +2443,7 @@ int nvmf_discovery_config_json(struct nvme_global_ctx *ctx,
struct nvme_ctrl *c;
int ret = 0, err;

err = lookup_host(ctx, fctx, &h);
err = lookup_or_create_host(ctx, fctx, &h);
if (err)
return err;

Expand Down Expand Up @@ -2486,7 +2492,7 @@ int nvmf_connect_config_json(struct nvme_global_ctx *ctx,
nvme_ctrl_t c, _c;
int ret = 0, err;

err = lookup_host(ctx, fctx, &h);
err = lookup_or_create_host(ctx, fctx, &h);
if (err)
return err;

Expand Down Expand Up @@ -2542,7 +2548,7 @@ int nvmf_discovery_config_file(struct nvme_global_ctx *ctx,
struct nvme_ctrl *c;
int err;

err = lookup_host(ctx, fctx, &h);
err = lookup_or_create_host(ctx, fctx, &h);
if (err)
return err;

Expand Down Expand Up @@ -2600,7 +2606,8 @@ static int nbft_filter(const struct dirent *dent)
return !fnmatch(NBFT_SYSFS_FILENAME, dent->d_name, FNM_PATHNAME);
}

int nvmf_nbft_read_files(char *path, struct nbft_file_entry **head)
int nvmf_nbft_read_files(struct nvme_global_ctx *ctx, char *path,
struct nbft_file_entry **head)
{
struct nbft_file_entry *entry = NULL;
struct nbft_info *nbft;
Expand All @@ -2616,7 +2623,7 @@ int nvmf_nbft_read_files(char *path, struct nbft_file_entry **head)
snprintf(filename, sizeof(filename), "%s/%s", path,
dent[i]->d_name);

ret = nvme_nbft_read(&nbft, filename);
ret = nvme_nbft_read(ctx, &nbft, filename);
if (!ret) {
struct nbft_file_entry *new;

Expand All @@ -2638,12 +2645,12 @@ int nvmf_nbft_read_files(char *path, struct nbft_file_entry **head)
return 0;
}

void nvmf_nbft_free(struct nbft_file_entry *head)
void nvmf_nbft_free(struct nvme_global_ctx *ctx, struct nbft_file_entry *head)
{
while (head) {
struct nbft_file_entry *next = head->next;

nvme_nbft_free(head->nbft);
nvme_nbft_free(ctx, head->nbft);
free(head);

head = next;
Expand Down Expand Up @@ -2856,7 +2863,7 @@ int nvmf_discovery_nbft(struct nvme_global_ctx *ctx,
struct nvme_host *h;
int ret, rr, i;

ret = lookup_host(ctx, fctx, &h);
ret = lookup_or_create_host(ctx, fctx, &h);
if (ret)
return ret;

Expand All @@ -2868,7 +2875,7 @@ int nvmf_discovery_nbft(struct nvme_global_ctx *ctx,
/* TODO: print discovery-type info from NBFT tables */
return 0;

ret = nvmf_nbft_read_files(nbft_path, &entry);
ret = nvmf_nbft_read_files(ctx, nbft_path, &entry);
if (ret) {
if (ret != -ENOENT)
nvme_msg(ctx, LOG_ERR,
Expand Down Expand Up @@ -2899,8 +2906,11 @@ int nvmf_discovery_nbft(struct nvme_global_ctx *ctx,

h = nvme_lookup_host(ctx, hostnqn, hostid);
if (!h) {
ret = -ENOENT;
goto out_free;
ret = nvme_create_host(ctx, hostnqn, hostid, &h);
if (ret) {
ret = -ENOENT;
goto out_free;
}
}

/* Subsystem Namespace Descriptor List */
Expand Down Expand Up @@ -3058,7 +3068,7 @@ int nvmf_discovery_nbft(struct nvme_global_ctx *ctx,
}
}
out_free:
nvmf_nbft_free(entry);
nvmf_nbft_free(ctx, entry);
return ret;
}

Expand Down Expand Up @@ -3154,7 +3164,7 @@ int nvmf_discovery(struct nvme_global_ctx *ctx, struct nvmf_context *fctx,
struct nvme_host *h;
int ret;

ret = lookup_host(ctx, fctx, &h);
ret = lookup_or_create_host(ctx, fctx, &h);
if (ret)
return ret;

Expand Down Expand Up @@ -3289,7 +3299,7 @@ int nvmf_connect(struct nvme_global_ctx *ctx, struct nvmf_context *fctx)
struct nvme_ctrl *c;
int err;

err = lookup_host(ctx, fctx, &h);
err = lookup_or_create_host(ctx, fctx, &h);
if (err)
return err;

Expand Down
7 changes: 5 additions & 2 deletions libnvme/src/nvme/fabrics.h
Original file line number Diff line number Diff line change
Expand Up @@ -644,21 +644,24 @@ struct nbft_file_entry {

/**
* nvmf_nbft_read_files() - Read NBFT files from path
* @ctx: struct nvme_global_ctx object
* @path: Path to NBFT files
* @head: Pointer to store linked list of NBFT file entries
*
* Reads NBFT files from the specified path and populates a linked list.
*
* Return: 0 on success, or a negative error code on failure.
*/
int nvmf_nbft_read_files(char *path, struct nbft_file_entry **head);
int nvmf_nbft_read_files(struct nvme_global_ctx *ctx, char *path,
struct nbft_file_entry **head);

/**
* nvmf_nbft_free() - Free NBFT file entry list
* @ctx: struct nvme_global_ctx object
* @head: Head of the NBFT file entry list
*
* Frees all memory associated with the NBFT file entry list.
*/
void nvmf_nbft_free(struct nbft_file_entry *head);
void nvmf_nbft_free(struct nvme_global_ctx *ctx, struct nbft_file_entry *head);

#endif /* _LIBNVME_FABRICS_H */
Loading
Loading