Skip to content

Commit f65f16a

Browse files
committed
nbft: add global context as first argument to nbft API
Add the global context to the nbft related API. This allows to issue warnings/errors via the global context. Signed-off-by: Daniel Wagner <[email protected]>
1 parent 9f3b05e commit f65f16a

8 files changed

Lines changed: 264 additions & 186 deletions

File tree

libnvme/libnvme/nvme.i

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1236,26 +1236,26 @@ struct nvme_ns {
12361236
return output;
12371237
}
12381238

1239-
PyObject *nbft_get(const char * filename)
1239+
PyObject *nbft_get(struct nvme_global_ctx *ctx, const char * filename)
12401240
{
12411241
struct nbft_info *nbft;
12421242
PyObject *output;
12431243
int ret;
12441244

1245-
ret = nvme_nbft_read(&nbft, filename);
1245+
ret = nvme_nbft_read(ctx, &nbft, filename);
12461246
if (ret) {
12471247
Py_RETURN_NONE;
12481248
}
12491249

12501250
output = nbft_to_pydict(nbft);
1251-
nvme_nbft_free(nbft);
1251+
nvme_nbft_free(ctx, nbft);
12521252
return output;
12531253
}
12541254
%};
12551255

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

12601260
// We want to swig all the #define and enum from types.h, but none of the structs.
12611261
#pragma SWIG nowarn=503 // Supress warnings about unnamed struct

libnvme/libnvme/tests/test-nbft.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,9 @@ def setUp(self):
7777

7878
def test_read_nbft_file(self):
7979
"""Make sure we get expected data when reading from binary NBFT file"""
80-
actual_nbft = nvme.nbft_get(args.filename)
80+
ctx = nvme.global_ctx()
81+
ctx.log_level('debug')
82+
actual_nbft = nvme.nbft_get(ctx, args.filename)
8183
self.assertEqual(actual_nbft, self.expected_nbft)
8284

8385

libnvme/src/nvme/fabrics.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2606,7 +2606,8 @@ static int nbft_filter(const struct dirent *dent)
26062606
return !fnmatch(NBFT_SYSFS_FILENAME, dent->d_name, FNM_PATHNAME);
26072607
}
26082608

2609-
int nvmf_nbft_read_files(char *path, struct nbft_file_entry **head)
2609+
int nvmf_nbft_read_files(struct nvme_global_ctx *ctx, char *path,
2610+
struct nbft_file_entry **head)
26102611
{
26112612
struct nbft_file_entry *entry = NULL;
26122613
struct nbft_info *nbft;
@@ -2622,7 +2623,7 @@ int nvmf_nbft_read_files(char *path, struct nbft_file_entry **head)
26222623
snprintf(filename, sizeof(filename), "%s/%s", path,
26232624
dent[i]->d_name);
26242625

2625-
ret = nvme_nbft_read(&nbft, filename);
2626+
ret = nvme_nbft_read(ctx, &nbft, filename);
26262627
if (!ret) {
26272628
struct nbft_file_entry *new;
26282629

@@ -2644,12 +2645,12 @@ int nvmf_nbft_read_files(char *path, struct nbft_file_entry **head)
26442645
return 0;
26452646
}
26462647

2647-
void nvmf_nbft_free(struct nbft_file_entry *head)
2648+
void nvmf_nbft_free(struct nvme_global_ctx *ctx, struct nbft_file_entry *head)
26482649
{
26492650
while (head) {
26502651
struct nbft_file_entry *next = head->next;
26512652

2652-
nvme_nbft_free(head->nbft);
2653+
nvme_nbft_free(ctx, head->nbft);
26532654
free(head);
26542655

26552656
head = next;
@@ -2874,7 +2875,7 @@ int nvmf_discovery_nbft(struct nvme_global_ctx *ctx,
28742875
/* TODO: print discovery-type info from NBFT tables */
28752876
return 0;
28762877

2877-
ret = nvmf_nbft_read_files(nbft_path, &entry);
2878+
ret = nvmf_nbft_read_files(ctx, nbft_path, &entry);
28782879
if (ret) {
28792880
if (ret != -ENOENT)
28802881
nvme_msg(ctx, LOG_ERR,
@@ -3067,7 +3068,7 @@ int nvmf_discovery_nbft(struct nvme_global_ctx *ctx,
30673068
}
30683069
}
30693070
out_free:
3070-
nvmf_nbft_free(entry);
3071+
nvmf_nbft_free(ctx, entry);
30713072
return ret;
30723073
}
30733074

libnvme/src/nvme/fabrics.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -644,21 +644,24 @@ struct nbft_file_entry {
644644

645645
/**
646646
* nvmf_nbft_read_files() - Read NBFT files from path
647+
* @ctx: struct nvme_global_ctx object
647648
* @path: Path to NBFT files
648649
* @head: Pointer to store linked list of NBFT file entries
649650
*
650651
* Reads NBFT files from the specified path and populates a linked list.
651652
*
652653
* Return: 0 on success, or a negative error code on failure.
653654
*/
654-
int nvmf_nbft_read_files(char *path, struct nbft_file_entry **head);
655+
int nvmf_nbft_read_files(struct nvme_global_ctx *ctx, char *path,
656+
struct nbft_file_entry **head);
655657

656658
/**
657659
* nvmf_nbft_free() - Free NBFT file entry list
660+
* @ctx: struct nvme_global_ctx object
658661
* @head: Head of the NBFT file entry list
659662
*
660663
* Frees all memory associated with the NBFT file entry list.
661664
*/
662-
void nvmf_nbft_free(struct nbft_file_entry *head);
665+
void nvmf_nbft_free(struct nvme_global_ctx *ctx, struct nbft_file_entry *head);
663666

664667
#endif /* _LIBNVME_FABRICS_H */

0 commit comments

Comments
 (0)