]> www.infradead.org Git - users/sagi/libnvme.git/commitdiff
tree: Add host symbolic name
authorMartin Belanger <martin.belanger@dell.com>
Tue, 15 Feb 2022 20:54:38 +0000 (15:54 -0500)
committerDaniel Wagner <dwagner@suse.de>
Fri, 18 Feb 2022 10:18:32 +0000 (11:18 +0100)
The host symbolic name was introduced in TP8010. It is used for
explicit registration with discovery controllers using the
discovery information management (DIM) command.x

Signed-off-by: Martin Belanger <martin.belanger@dell.com>
doc/config-schema.json
libnvme/nvme.i
src/libnvme.map
src/nvme/json.c
src/nvme/private.h
src/nvme/tree.c
src/nvme/tree.h

index 3240d9b8a241231161ed83d2f9a9a7fc421fe4a4..a7bbdf17c1eb7f955861a2c215de7aea3025ca9e 100644 (file)
                    "description": "NVMe host ID",
                    "type": "string"
                },
+               "hostsymname": {
+                   "description": "NVMe host symbolic name",
+                   "type": "string"
+               },
                "required": [ "hostnqn" ],
                "subsystems": {
                    "description": "Array of NVMe subsystem properties",
index 256b1eae82f8b04cf62fe3a89f445b93813cdd92..071b20df4553957ddd69945d62912feb1fe5ee61 100644 (file)
@@ -280,8 +280,10 @@ struct nvme_root {
 struct nvme_host {
   %immutable hostnqn;
   %immutable hostid;
+  %immutable hostsymname;
   char *hostnqn;
   char *hostid;
+  char *hostsymname;
   char *dhchap_key;
 };
 
@@ -396,14 +398,28 @@ struct nvme_ns {
 
 %extend nvme_host {
   nvme_host(struct nvme_root *r, const char *hostnqn = NULL,
-           const char *hostid = NULL) {
-    if (!hostnqn)
-      return nvme_default_host(r);
-    return nvme_lookup_host(r, hostnqn, hostid);
+           const char *hostid = NULL, const char *hostsymname = NULL) {
+
+    nvme_host_t h = hostnqn ? nvme_lookup_host(r, hostnqn, hostid) : nvme_default_host(r);
+    if (hostsymname)
+        nvme_host_set_hostsymname(h, hostsymname);
+    return h;
   }
   ~nvme_host() {
     nvme_free_host($self);
   }
+%define SET_SYMNAME_DOCSTRING
+"@brief Set or Clear Host's Symbolic Name
+
+@param hostsymname: A symbolic name, or None to clear the symbolic name.
+@type hostsymname: str|None
+
+@return: None"
+%enddef
+  %feature("autodoc", SET_SYMNAME_DOCSTRING) set_symname;
+  void set_symname(const char *hostsymname) {
+    nvme_host_set_hostsymname($self, hostsymname);
+  }
   char *__str__() {
     static char tmp[2048];
 
index 854703442fb79f981e2cf429e28281f1272788d8..7d1e5470f6801a811b5b1596d070a17c920982e4 100644 (file)
@@ -144,8 +144,10 @@ LIBNVME_1_0 {
                nvme_host_get_dhchap_key;
                nvme_host_get_hostid;
                nvme_host_get_hostnqn;
+               nvme_host_get_hostsymname;
                nvme_host_get_root;
                nvme_host_set_dhchap_key;
+               nvme_host_set_hostsymname;
                nvme_identify;
                nvme_identify_active_ns_list;
                nvme_identify_allocated_ns;
index 309cd2e7da63fee6762f12c7386e9941f4388e91..3d19ea0501f1a5b9182de8076b6813fe0a5f21a9 100644 (file)
@@ -146,6 +146,9 @@ static void json_parse_host(nvme_root_t r, struct json_object *host_obj)
        attr_obj = json_object_object_get(host_obj, "dhchap_key");
        if (attr_obj)
                nvme_host_set_dhchap_key(h, json_object_get_string(attr_obj));
+       attr_obj = json_object_object_get(host_obj, "hostsymname");
+       if (attr_obj)
+               nvme_host_set_hostsymname(h, json_object_get_string(attr_obj));
        subsys_array = json_object_object_get(host_obj, "subsystems");
        if (!subsys_array)
                return;
@@ -288,7 +291,7 @@ int json_update_config(nvme_root_t r, const char *config_file)
        json_root = json_object_new_array();
        nvme_for_each_host(r, h) {
                nvme_subsystem_t s;
-               const char *hostnqn, *hostid, *dhchap_key;
+               const char *hostnqn, *hostid, *dhchap_key, *hostsymname;
 
                host_obj = json_object_new_object();
                if (!host_obj)
@@ -304,6 +307,10 @@ int json_update_config(nvme_root_t r, const char *config_file)
                if (dhchap_key)
                        json_object_object_add(host_obj, "dhchap_key",
                                               json_object_new_string(dhchap_key));
+               hostsymname = nvme_host_get_hostsymname(h);
+               if (hostsymname)
+                       json_object_object_add(host_obj, "hostsymname",
+                                              json_object_new_string(hostsymname));
                subsys_array = json_object_new_array();
                nvme_for_each_subsystem(h, s) {
                        json_update_subsys(subsys_array, s);
index 6b7d62676a8afbca304b81aeb8f123e2d267f7fb..43c65ea52b82069c05c861795dcf5688512e2dca 100644 (file)
@@ -109,6 +109,7 @@ struct nvme_host {
        char *hostnqn;
        char *hostid;
        char *dhchap_key;
+       char *hostsymname;
 };
 
 struct nvme_root {
index 0806fe00053e401e9e1a542581e0945f7e6936cf..51bbf1492f724c88648670225f0e7e105e343fd3 100644 (file)
@@ -64,6 +64,9 @@ nvme_host_t nvme_default_host(nvme_root_t r)
        hostid = nvmf_hostid_from_file();
 
        h = nvme_lookup_host(r, hostnqn, hostid);
+
+       nvme_host_set_hostsymname(h, NULL);
+
        default_host = h;
        free(hostnqn);
        if (hostid)
@@ -211,6 +214,21 @@ const char *nvme_host_get_hostid(nvme_host_t h)
        return h->hostid;
 }
 
+const char *nvme_host_get_hostsymname(nvme_host_t h)
+{
+       return h->hostsymname;
+}
+
+void nvme_host_set_hostsymname(nvme_host_t h, const char *hostsymname)
+{
+       if (h->hostsymname) {
+               free(h->hostsymname);
+               h->hostsymname = NULL;
+       }
+       if (hostsymname)
+               h->hostsymname = strdup(hostsymname);
+}
+
 const char *nvme_host_get_dhchap_key(nvme_host_t h)
 {
        return h->dhchap_key;
@@ -390,6 +408,7 @@ static void __nvme_free_host(struct nvme_host *h)
                free(h->hostid);
        if (h->dhchap_key)
                free(h->dhchap_key);
+       nvme_host_set_hostsymname(h, NULL);
        h->r->modified = true;
        free(h);
 }
index 64c5834795a6e7b1dccfc03eaaf42529ad623893..8bd20e55e90f7969e93334482af4efafe8bb6fd9 100644 (file)
@@ -1167,4 +1167,20 @@ char *nvme_get_path_attr(nvme_path_t p, const char *attr);
  */
 nvme_ns_t nvme_scan_namespace(const char *name);
 
+/**
+ * nvme_host_get_hostsymname() - Get the host's symbolic name
+ * @h: Host for which the symbolic name should be returned.
+ *
+ * Return: The symbolic name or NULL if a symbolic name hasn't been
+ * configure.
+ */
+const char *nvme_host_get_hostsymname(nvme_host_t h);
+
+/**
+ * nvme_host_set_hostsymname() - Set the host's symbolic name
+ * @h:                 Host for which the symbolic name should be set.
+ * @hostsymname:       Symbolic name
+ */
+void nvme_host_set_hostsymname(nvme_host_t h, const char *hostsymname);
+
 #endif /* _LIBNVME_TREE_H */