]> www.infradead.org Git - users/sagi/libnvme.git/commitdiff
libnvme: add 'application' setting to the subsystem
authorHannes Reinecke <hare@suse.de>
Thu, 20 Apr 2023 10:10:17 +0000 (12:10 +0200)
committerDaniel Wagner <wagi@monom.org>
Mon, 12 Jun 2023 14:51:15 +0000 (16:51 +0200)
Add an 'application' string to the subsystem to indicate which
application should manage this particular subsystem.

Signed-off-by: Hannes Reinecke <hare@suse.de>
doc/config-schema.json.in
libnvme/nvme.i
src/libnvme.map
src/nvme/json.c
src/nvme/private.h
src/nvme/tree.c
src/nvme/tree.h

index bde3d91c2902afa59ae44a4f7a57bc35000d3a60..4bbc4cbf4f39a4abda83283b4a029d9c89750295 100644 (file)
                    "type": "array",
                    "items": { "$ref": "#/$defs/port" }
                },
+               "application": {
+                   "description": "Program managing this subsystem",
+                   "type": "string"
+               },
                "required": [ "nqn" ]
            }
        },
index 8b461e6e9b86a1eafe920253910aba7195e8aab9..2d39a5d92060cff37a79e2791672812c4f98d292 100644 (file)
@@ -346,10 +346,12 @@ struct nvme_subsystem {
        %immutable model;
        %immutable serial;
        %immutable firmware;
+       %immutable application;
        char *subsysnqn;
        char *model;
        char *serial;
        char *firmware;
+       char *application;
 };
 
 struct nvme_ctrl {
index 5b118d4950c0d9b1c59fd925eca02f6417b78c72..47ac71051766f17bc892aafca292d67b59522c65 100644 (file)
@@ -2,9 +2,11 @@
 
 LIBNVME_1_5 {
        global:
-               nvme_nbft_read;
-               nvme_nbft_free;
                nvme_ipaddrs_eq;
+               nvme_nbft_free;
+               nvme_nbft_read;
+               nvme_subsystem_get_application;
+               nvme_subsystem_set_application;
 };
 
 LIBNVME_1_4 {
index a74b5a4d1108a9115c6293cf79a0d4d2705bf211..3e711a7cfdd38da1cbf319ea2ebd90498adebc9a 100644 (file)
@@ -127,7 +127,7 @@ static void json_parse_port(nvme_subsystem_t s, struct json_object *port_obj)
 
 static void json_parse_subsys(nvme_host_t h, struct json_object *subsys_obj)
 {
-       struct json_object *nqn_obj, *port_array;
+       struct json_object *nqn_obj, *app_obj, *port_array;
        nvme_subsystem_t s;
        const char *nqn;
        int p;
@@ -137,6 +137,12 @@ static void json_parse_subsys(nvme_host_t h, struct json_object *subsys_obj)
                return;
        nqn = json_object_get_string(nqn_obj);
        s = nvme_lookup_subsystem(h, NULL, nqn);
+       if (!s)
+               return;
+       app_obj = json_object_object_get(subsys_obj, "application");
+       if (app_obj)
+               nvme_subsystem_set_application(s, json_object_get_string(app_obj));
+
        port_array = json_object_object_get(subsys_obj, "ports");
        if (!port_array)
                return;
@@ -350,7 +356,7 @@ static void json_update_subsys(struct json_object *subsys_array,
                               nvme_subsystem_t s)
 {
        nvme_ctrl_t c;
-       const char *subsysnqn = nvme_subsystem_get_nqn(s);
+       const char *subsysnqn = nvme_subsystem_get_nqn(s), *app;
        struct json_object *subsys_obj = json_object_new_object();
        struct json_object *port_array;
 
@@ -360,6 +366,10 @@ static void json_update_subsys(struct json_object *subsys_array,
 
        json_object_object_add(subsys_obj, "nqn",
                               json_object_new_string(subsysnqn));
+       app = nvme_subsystem_get_application(s);
+       if (app)
+               json_object_object_add(subsys_obj, "application",
+                                      json_object_new_string(app));
        port_array = json_object_new_array();
        nvme_subsystem_for_each_ctrl(s, c) {
                json_update_port(port_array, c);
index 47ce7ca3d486a4cbf730f751cbf66e34f7d52015..8fa9ccdcf5b9d33578400b289d81bc5c376ca401 100644 (file)
@@ -104,6 +104,7 @@ struct nvme_subsystem {
        char *serial;
        char *firmware;
        char *subsystype;
+       char *application;
 };
 
 struct nvme_host {
index c7ade353c9940ae8c65563a7796848c04d354185..6f4e4bd1b9542e03a9ab5f38d00c9f2b943f4bd9 100644 (file)
@@ -316,6 +316,19 @@ const char *nvme_subsystem_get_type(nvme_subsystem_t s)
        return s->subsystype;
 }
 
+const char *nvme_subsystem_get_application(nvme_subsystem_t s)
+{
+       return s->application;
+}
+
+void nvme_subsystem_set_application(nvme_subsystem_t s, const char *a)
+{
+       if (s->application)
+               free(s->application);
+       if (a)
+               s->application = strdup(a);
+}
+
 nvme_ctrl_t nvme_subsystem_first_ctrl(nvme_subsystem_t s)
 {
        return list_top(&s->ctrls, struct nvme_ctrl, entry);
index e4a5126c4e2b6aca7e21a117c3b2c120313bfdf9..57d2767e2f3eeda467e42616615925e21c492fb8 100644 (file)
@@ -1104,6 +1104,23 @@ const char *nvme_subsystem_get_name(nvme_subsystem_t s);
  */
 const char *nvme_subsystem_get_type(nvme_subsystem_t s);
 
+/**
+ * nvme_subsystem_get_application() - Return the application string
+ * @s: nvme_subsystem_t object
+ *
+ * Return: Managing application string or NULL if not set.
+ */
+const char *nvme_subsystem_get_application(nvme_subsystem_t s);
+
+/**
+ * nvme_subsystem_set_application() - Set the application string
+ * @s: nvme_subsystem_t object
+ * @a:  application string
+ *
+ * Sets the managing application string for @s.
+ */
+void nvme_subsystem_set_application(nvme_subsystem_t s, const char *a);
+
 /**
  * nvme_scan_topology() - Scan NVMe topology and apply filter
  * @r:     nvme_root_t object