Skip to content

Commit 20a4eaf

Browse files
hreineckeigaw
authored andcommitted
libnvme: add 'application' setting to nvme_root
Add an 'application' string to the tree root to indicate which application manages this configuration. Signed-off-by: Hannes Reinecke <[email protected]>
1 parent 21e099a commit 20a4eaf

5 files changed

Lines changed: 39 additions & 0 deletions

File tree

libnvme/nvme.i

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,9 @@ PyObject *hostid_from_file();
326326

327327
struct nvme_root {
328328
%immutable config_file;
329+
%immutable application;
329330
char *config_file;
331+
char *application;
330332
};
331333

332334
struct nvme_host {

src/libnvme.map

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ LIBNVME_1_5 {
55
nvme_ipaddrs_eq;
66
nvme_nbft_free;
77
nvme_nbft_read;
8+
nvme_root_get_application;
9+
nvme_root_set_application;
810
nvme_subsystem_get_application;
911
nvme_subsystem_set_application;
1012
};

src/nvme/private.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ struct nvme_fabric_options {
155155

156156
struct nvme_root {
157157
char *config_file;
158+
char *application;
158159
struct list_head hosts;
159160
struct list_head endpoints; /* MI endpoints */
160161
FILE *fp;

src/nvme/tree.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,19 @@ int nvme_dump_tree(nvme_root_t r)
197197
return json_dump_tree(r);
198198
}
199199

200+
const char *nvme_root_get_application(nvme_root_t r)
201+
{
202+
return r->application;
203+
}
204+
205+
void nvme_root_set_application(nvme_root_t r, const char *a)
206+
{
207+
if (r->application)
208+
free(r->application);
209+
if (a)
210+
r->application = strdup(a);
211+
}
212+
200213
nvme_host_t nvme_first_host(nvme_root_t r)
201214
{
202215
return list_top(&r->hosts, struct nvme_host, entry);
@@ -293,6 +306,8 @@ void nvme_free_tree(nvme_root_t r)
293306
__nvme_free_host(h);
294307
if (r->config_file)
295308
free(r->config_file);
309+
if (r->application)
310+
free(r->application);
296311
free(r);
297312
}
298313

@@ -404,6 +419,8 @@ static void __nvme_free_subsystem(struct nvme_subsystem *s)
404419
free(s->firmware);
405420
if (s->subsystype)
406421
free(s->subsystype);
422+
if (s->application)
423+
free(s->application);
407424
free(s);
408425
}
409426

src/nvme/tree.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,23 @@ typedef bool (*nvme_scan_filter_t)(nvme_subsystem_t, nvme_ctrl_t,
4444
*/
4545
nvme_root_t nvme_create_root(FILE *fp, int log_level);
4646

47+
/**
48+
* nvme_root_set_application - Specify managing application
49+
* @r: &nvme_root_t object
50+
* @a: Application string
51+
*
52+
* Sets the managing application string for @r.
53+
*/
54+
void nvme_root_set_application(nvme_root_t r, const char *a);
55+
56+
/**
57+
* nvme_root_get_application - Get managing application
58+
* @r: &nvme_root_t object
59+
*
60+
* Returns the managing application string for @r or NULL if not set.
61+
*/
62+
const char *nvme_root_get_application(nvme_root_t r);
63+
4764
/**
4865
* nvme_free_tree() - Free root object
4966
* @r: &nvme_root_t object

0 commit comments

Comments
 (0)