Skip to content

Commit 21e099a

Browse files
hreineckeigaw
authored andcommitted
libnvme: add 'application' setting to the subsystem
Add an 'application' string to the subsystem to indicate which application should manage this particular subsystem. Signed-off-by: Hannes Reinecke <[email protected]>
1 parent 28ecf61 commit 21e099a

7 files changed

Lines changed: 53 additions & 4 deletions

File tree

doc/config-schema.json.in

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,10 @@
5959
"type": "array",
6060
"items": { "$ref": "#/$defs/port" }
6161
},
62+
"application": {
63+
"description": "Program managing this subsystem",
64+
"type": "string"
65+
},
6266
"required": [ "nqn" ]
6367
}
6468
},

libnvme/nvme.i

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,10 +346,12 @@ struct nvme_subsystem {
346346
%immutable model;
347347
%immutable serial;
348348
%immutable firmware;
349+
%immutable application;
349350
char *subsysnqn;
350351
char *model;
351352
char *serial;
352353
char *firmware;
354+
char *application;
353355
};
354356

355357
struct nvme_ctrl {

src/libnvme.map

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@
22

33
LIBNVME_1_5 {
44
global:
5-
nvme_nbft_read;
6-
nvme_nbft_free;
75
nvme_ipaddrs_eq;
6+
nvme_nbft_free;
7+
nvme_nbft_read;
8+
nvme_subsystem_get_application;
9+
nvme_subsystem_set_application;
810
};
911

1012
LIBNVME_1_4 {

src/nvme/json.c

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ static void json_parse_port(nvme_subsystem_t s, struct json_object *port_obj)
127127

128128
static void json_parse_subsys(nvme_host_t h, struct json_object *subsys_obj)
129129
{
130-
struct json_object *nqn_obj, *port_array;
130+
struct json_object *nqn_obj, *app_obj, *port_array;
131131
nvme_subsystem_t s;
132132
const char *nqn;
133133
int p;
@@ -137,6 +137,12 @@ static void json_parse_subsys(nvme_host_t h, struct json_object *subsys_obj)
137137
return;
138138
nqn = json_object_get_string(nqn_obj);
139139
s = nvme_lookup_subsystem(h, NULL, nqn);
140+
if (!s)
141+
return;
142+
app_obj = json_object_object_get(subsys_obj, "application");
143+
if (app_obj)
144+
nvme_subsystem_set_application(s, json_object_get_string(app_obj));
145+
140146
port_array = json_object_object_get(subsys_obj, "ports");
141147
if (!port_array)
142148
return;
@@ -350,7 +356,7 @@ static void json_update_subsys(struct json_object *subsys_array,
350356
nvme_subsystem_t s)
351357
{
352358
nvme_ctrl_t c;
353-
const char *subsysnqn = nvme_subsystem_get_nqn(s);
359+
const char *subsysnqn = nvme_subsystem_get_nqn(s), *app;
354360
struct json_object *subsys_obj = json_object_new_object();
355361
struct json_object *port_array;
356362

@@ -360,6 +366,10 @@ static void json_update_subsys(struct json_object *subsys_array,
360366

361367
json_object_object_add(subsys_obj, "nqn",
362368
json_object_new_string(subsysnqn));
369+
app = nvme_subsystem_get_application(s);
370+
if (app)
371+
json_object_object_add(subsys_obj, "application",
372+
json_object_new_string(app));
363373
port_array = json_object_new_array();
364374
nvme_subsystem_for_each_ctrl(s, c) {
365375
json_update_port(port_array, c);

src/nvme/private.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ struct nvme_subsystem {
104104
char *serial;
105105
char *firmware;
106106
char *subsystype;
107+
char *application;
107108
};
108109

109110
struct nvme_host {

src/nvme/tree.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,19 @@ const char *nvme_subsystem_get_type(nvme_subsystem_t s)
316316
return s->subsystype;
317317
}
318318

319+
const char *nvme_subsystem_get_application(nvme_subsystem_t s)
320+
{
321+
return s->application;
322+
}
323+
324+
void nvme_subsystem_set_application(nvme_subsystem_t s, const char *a)
325+
{
326+
if (s->application)
327+
free(s->application);
328+
if (a)
329+
s->application = strdup(a);
330+
}
331+
319332
nvme_ctrl_t nvme_subsystem_first_ctrl(nvme_subsystem_t s)
320333
{
321334
return list_top(&s->ctrls, struct nvme_ctrl, entry);

src/nvme/tree.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1104,6 +1104,23 @@ const char *nvme_subsystem_get_name(nvme_subsystem_t s);
11041104
*/
11051105
const char *nvme_subsystem_get_type(nvme_subsystem_t s);
11061106

1107+
/**
1108+
* nvme_subsystem_get_application() - Return the application string
1109+
* @s: nvme_subsystem_t object
1110+
*
1111+
* Return: Managing application string or NULL if not set.
1112+
*/
1113+
const char *nvme_subsystem_get_application(nvme_subsystem_t s);
1114+
1115+
/**
1116+
* nvme_subsystem_set_application() - Set the application string
1117+
* @s: nvme_subsystem_t object
1118+
* @a: application string
1119+
*
1120+
* Sets the managing application string for @s.
1121+
*/
1122+
void nvme_subsystem_set_application(nvme_subsystem_t s, const char *a);
1123+
11071124
/**
11081125
* nvme_scan_topology() - Scan NVMe topology and apply filter
11091126
* @r: nvme_root_t object

0 commit comments

Comments
 (0)