Skip to content

Commit 5ec01cf

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 <wagi@kernel.org>
1 parent cc7a827 commit 5ec01cf

File tree

8 files changed

+264
-186
lines changed

8 files changed

+264
-186
lines changed

libnvme/libnvme/nvme.i

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

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

1247-
ret = nvme_nbft_read(&nbft, filename);
1247+
ret = nvme_nbft_read(ctx, &nbft, filename);
12481248
if (ret) {
12491249
Py_RETURN_NONE;
12501250
}
12511251

12521252
output = nbft_to_pydict(nbft);
1253-
nvme_nbft_free(nbft);
1253+
nvme_nbft_free(ctx, nbft);
12541254
return output;
12551255
}
12561256
%};
12571257

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

12621262
// We want to swig all the #define and enum from types.h, but none of the structs.
12631263
#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
@@ -2708,7 +2708,8 @@ static int nbft_filter(const struct dirent *dent)
27082708
return !fnmatch(NBFT_SYSFS_FILENAME, dent->d_name, FNM_PATHNAME);
27092709
}
27102710

2711-
int nvmf_nbft_read_files(char *path, struct nbft_file_entry **head)
2711+
int nvmf_nbft_read_files(struct nvme_global_ctx *ctx, char *path,
2712+
struct nbft_file_entry **head)
27122713
{
27132714
struct nbft_file_entry *entry = NULL;
27142715
struct nbft_info *nbft;
@@ -2724,7 +2725,7 @@ int nvmf_nbft_read_files(char *path, struct nbft_file_entry **head)
27242725
snprintf(filename, sizeof(filename), "%s/%s", path,
27252726
dent[i]->d_name);
27262727

2727-
ret = nvme_nbft_read(&nbft, filename);
2728+
ret = nvme_nbft_read(ctx, &nbft, filename);
27282729
if (!ret) {
27292730
struct nbft_file_entry *new;
27302731

@@ -2746,12 +2747,12 @@ int nvmf_nbft_read_files(char *path, struct nbft_file_entry **head)
27462747
return 0;
27472748
}
27482749

2749-
void nvmf_nbft_free(struct nbft_file_entry *head)
2750+
void nvmf_nbft_free(struct nvme_global_ctx *ctx, struct nbft_file_entry *head)
27502751
{
27512752
while (head) {
27522753
struct nbft_file_entry *next = head->next;
27532754

2754-
nvme_nbft_free(head->nbft);
2755+
nvme_nbft_free(ctx, head->nbft);
27552756
free(head);
27562757

27572758
head = next;
@@ -2976,7 +2977,7 @@ int nvmf_discovery_nbft(struct nvme_global_ctx *ctx,
29762977
/* TODO: print discovery-type info from NBFT tables */
29772978
return 0;
29782979

2979-
ret = nvmf_nbft_read_files(nbft_path, &entry);
2980+
ret = nvmf_nbft_read_files(ctx, nbft_path, &entry);
29802981
if (ret) {
29812982
if (ret != -ENOENT)
29822983
nvme_msg(ctx, LOG_ERR,
@@ -3166,7 +3167,7 @@ int nvmf_discovery_nbft(struct nvme_global_ctx *ctx,
31663167
}
31673168
}
31683169
out_free:
3169-
nvmf_nbft_free(entry);
3170+
nvmf_nbft_free(ctx, entry);
31703171
return ret;
31713172
}
31723173

libnvme/src/nvme/fabrics.h

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

658658
/**
659659
* nvmf_nbft_read_files() - Read NBFT files from path
660+
* @ctx: struct nvme_global_ctx object
660661
* @path: Path to NBFT files
661662
* @head: Pointer to store linked list of NBFT file entries
662663
*
663664
* Reads NBFT files from the specified path and populates a linked list.
664665
*
665666
* Return: 0 on success, or a negative error code on failure.
666667
*/
667-
int nvmf_nbft_read_files(char *path, struct nbft_file_entry **head);
668+
int nvmf_nbft_read_files(struct nvme_global_ctx *ctx, char *path,
669+
struct nbft_file_entry **head);
668670

669671
/**
670672
* nvmf_nbft_free() - Free NBFT file entry list
673+
* @ctx: struct nvme_global_ctx object
671674
* @head: Head of the NBFT file entry list
672675
*
673676
* Frees all memory associated with the NBFT file entry list.
674677
*/
675-
void nvmf_nbft_free(struct nbft_file_entry *head);
678+
void nvmf_nbft_free(struct nvme_global_ctx *ctx, struct nbft_file_entry *head);
676679

677680
#endif /* _LIBNVME_FABRICS_H */

0 commit comments

Comments
 (0)