From 646dff7324f379f3b7276ebbfff35e320f0a3b44 Mon Sep 17 00:00:00 2001 From: Martin Belanger Date: Tue, 15 Feb 2022 15:54:38 -0500 Subject: [PATCH] tree: Add host symbolic name 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 --- doc/config-schema.json | 4 ++++ libnvme/nvme.i | 24 ++++++++++++++++++++---- src/libnvme.map | 2 ++ src/nvme/json.c | 9 ++++++++- src/nvme/private.h | 1 + src/nvme/tree.c | 19 +++++++++++++++++++ src/nvme/tree.h | 16 ++++++++++++++++ 7 files changed, 70 insertions(+), 5 deletions(-) diff --git a/doc/config-schema.json b/doc/config-schema.json index 3240d9b8..a7bbdf17 100644 --- a/doc/config-schema.json +++ b/doc/config-schema.json @@ -25,6 +25,10 @@ "description": "NVMe host ID", "type": "string" }, + "hostsymname": { + "description": "NVMe host symbolic name", + "type": "string" + }, "required": [ "hostnqn" ], "subsystems": { "description": "Array of NVMe subsystem properties", diff --git a/libnvme/nvme.i b/libnvme/nvme.i index 256b1eae..071b20df 100644 --- a/libnvme/nvme.i +++ b/libnvme/nvme.i @@ -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]; diff --git a/src/libnvme.map b/src/libnvme.map index 85470344..7d1e5470 100644 --- a/src/libnvme.map +++ b/src/libnvme.map @@ -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; diff --git a/src/nvme/json.c b/src/nvme/json.c index 309cd2e7..3d19ea05 100644 --- a/src/nvme/json.c +++ b/src/nvme/json.c @@ -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); diff --git a/src/nvme/private.h b/src/nvme/private.h index 6b7d6267..43c65ea5 100644 --- a/src/nvme/private.h +++ b/src/nvme/private.h @@ -109,6 +109,7 @@ struct nvme_host { char *hostnqn; char *hostid; char *dhchap_key; + char *hostsymname; }; struct nvme_root { diff --git a/src/nvme/tree.c b/src/nvme/tree.c index 0806fe00..51bbf149 100644 --- a/src/nvme/tree.c +++ b/src/nvme/tree.c @@ -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); } diff --git a/src/nvme/tree.h b/src/nvme/tree.h index 64c58347..8bd20e55 100644 --- a/src/nvme/tree.h +++ b/src/nvme/tree.h @@ -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 */ -- 2.50.1