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
8 changes: 4 additions & 4 deletions libnvme/libnvme/nvme.i
Original file line number Diff line number Diff line change
Expand Up @@ -1238,26 +1238,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
4 changes: 0 additions & 4 deletions libnvme/src/libnvme.ld
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,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 @@ -118,7 +116,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 @@ -230,7 +227,6 @@ LIBNVME_2_0 {
nvme_scan_tls_keys;
nvme_scan_topology;
nvme_set_application;
nvme_set_debug;
nvme_set_dry_run;
nvme_set_etdas;
nvme_set_keyring;
Expand Down
18 changes: 10 additions & 8 deletions libnvme/src/nvme/fabrics.c
Original file line number Diff line number Diff line change
Expand Up @@ -748,7 +748,8 @@ static int build_options(nvme_host_t h, nvme_ctrl_t c, char **argstr)
}

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 @@ -1246,7 +1247,7 @@ static int nvmf_connect_disc_entry(nvme_host_t h,
static int nvme_discovery_log(const struct nvme_get_discovery_args *args,
struct nvmf_discovery_log **logp)
{
struct nvme_global_ctx *ctx = ctx_from_ctrl(args->c);
struct nvme_global_ctx *ctx = args->c->ctx;
struct nvmf_discovery_log *log;
int retries = 0;
int err;
Expand Down Expand Up @@ -2707,7 +2708,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 @@ -2723,7 +2725,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 @@ -2745,12 +2747,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 @@ -2975,7 +2977,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 @@ -3165,7 +3167,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
7 changes: 5 additions & 2 deletions libnvme/src/nvme/fabrics.h
Original file line number Diff line number Diff line change
Expand Up @@ -657,21 +657,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