Skip to content

Commit 646dff7

Browse files
Martin Belangerdwsuse
authored andcommitted
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 <[email protected]>
1 parent 82feba2 commit 646dff7

7 files changed

Lines changed: 70 additions & 5 deletions

File tree

doc/config-schema.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@
2525
"description": "NVMe host ID",
2626
"type": "string"
2727
},
28+
"hostsymname": {
29+
"description": "NVMe host symbolic name",
30+
"type": "string"
31+
},
2832
"required": [ "hostnqn" ],
2933
"subsystems": {
3034
"description": "Array of NVMe subsystem properties",

libnvme/nvme.i

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -280,8 +280,10 @@ struct nvme_root {
280280
struct nvme_host {
281281
%immutable hostnqn;
282282
%immutable hostid;
283+
%immutable hostsymname;
283284
char *hostnqn;
284285
char *hostid;
286+
char *hostsymname;
285287
char *dhchap_key;
286288
};
287289

@@ -396,14 +398,28 @@ struct nvme_ns {
396398

397399
%extend nvme_host {
398400
nvme_host(struct nvme_root *r, const char *hostnqn = NULL,
399-
const char *hostid = NULL) {
400-
if (!hostnqn)
401-
return nvme_default_host(r);
402-
return nvme_lookup_host(r, hostnqn, hostid);
401+
const char *hostid = NULL, const char *hostsymname = NULL) {
402+
403+
nvme_host_t h = hostnqn ? nvme_lookup_host(r, hostnqn, hostid) : nvme_default_host(r);
404+
if (hostsymname)
405+
nvme_host_set_hostsymname(h, hostsymname);
406+
return h;
403407
}
404408
~nvme_host() {
405409
nvme_free_host($self);
406410
}
411+
%define SET_SYMNAME_DOCSTRING
412+
"@brief Set or Clear Host's Symbolic Name
413+
414+
@param hostsymname: A symbolic name, or None to clear the symbolic name.
415+
@type hostsymname: str|None
416+
417+
@return: None"
418+
%enddef
419+
%feature("autodoc", SET_SYMNAME_DOCSTRING) set_symname;
420+
void set_symname(const char *hostsymname) {
421+
nvme_host_set_hostsymname($self, hostsymname);
422+
}
407423
char *__str__() {
408424
static char tmp[2048];
409425

src/libnvme.map

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,10 @@ LIBNVME_1_0 {
144144
nvme_host_get_dhchap_key;
145145
nvme_host_get_hostid;
146146
nvme_host_get_hostnqn;
147+
nvme_host_get_hostsymname;
147148
nvme_host_get_root;
148149
nvme_host_set_dhchap_key;
150+
nvme_host_set_hostsymname;
149151
nvme_identify;
150152
nvme_identify_active_ns_list;
151153
nvme_identify_allocated_ns;

src/nvme/json.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,9 @@ static void json_parse_host(nvme_root_t r, struct json_object *host_obj)
146146
attr_obj = json_object_object_get(host_obj, "dhchap_key");
147147
if (attr_obj)
148148
nvme_host_set_dhchap_key(h, json_object_get_string(attr_obj));
149+
attr_obj = json_object_object_get(host_obj, "hostsymname");
150+
if (attr_obj)
151+
nvme_host_set_hostsymname(h, json_object_get_string(attr_obj));
149152
subsys_array = json_object_object_get(host_obj, "subsystems");
150153
if (!subsys_array)
151154
return;
@@ -288,7 +291,7 @@ int json_update_config(nvme_root_t r, const char *config_file)
288291
json_root = json_object_new_array();
289292
nvme_for_each_host(r, h) {
290293
nvme_subsystem_t s;
291-
const char *hostnqn, *hostid, *dhchap_key;
294+
const char *hostnqn, *hostid, *dhchap_key, *hostsymname;
292295

293296
host_obj = json_object_new_object();
294297
if (!host_obj)
@@ -304,6 +307,10 @@ int json_update_config(nvme_root_t r, const char *config_file)
304307
if (dhchap_key)
305308
json_object_object_add(host_obj, "dhchap_key",
306309
json_object_new_string(dhchap_key));
310+
hostsymname = nvme_host_get_hostsymname(h);
311+
if (hostsymname)
312+
json_object_object_add(host_obj, "hostsymname",
313+
json_object_new_string(hostsymname));
307314
subsys_array = json_object_new_array();
308315
nvme_for_each_subsystem(h, s) {
309316
json_update_subsys(subsys_array, s);

src/nvme/private.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ struct nvme_host {
109109
char *hostnqn;
110110
char *hostid;
111111
char *dhchap_key;
112+
char *hostsymname;
112113
};
113114

114115
struct nvme_root {

src/nvme/tree.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,9 @@ nvme_host_t nvme_default_host(nvme_root_t r)
6464
hostid = nvmf_hostid_from_file();
6565

6666
h = nvme_lookup_host(r, hostnqn, hostid);
67+
68+
nvme_host_set_hostsymname(h, NULL);
69+
6770
default_host = h;
6871
free(hostnqn);
6972
if (hostid)
@@ -211,6 +214,21 @@ const char *nvme_host_get_hostid(nvme_host_t h)
211214
return h->hostid;
212215
}
213216

217+
const char *nvme_host_get_hostsymname(nvme_host_t h)
218+
{
219+
return h->hostsymname;
220+
}
221+
222+
void nvme_host_set_hostsymname(nvme_host_t h, const char *hostsymname)
223+
{
224+
if (h->hostsymname) {
225+
free(h->hostsymname);
226+
h->hostsymname = NULL;
227+
}
228+
if (hostsymname)
229+
h->hostsymname = strdup(hostsymname);
230+
}
231+
214232
const char *nvme_host_get_dhchap_key(nvme_host_t h)
215233
{
216234
return h->dhchap_key;
@@ -390,6 +408,7 @@ static void __nvme_free_host(struct nvme_host *h)
390408
free(h->hostid);
391409
if (h->dhchap_key)
392410
free(h->dhchap_key);
411+
nvme_host_set_hostsymname(h, NULL);
393412
h->r->modified = true;
394413
free(h);
395414
}

src/nvme/tree.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1167,4 +1167,20 @@ char *nvme_get_path_attr(nvme_path_t p, const char *attr);
11671167
*/
11681168
nvme_ns_t nvme_scan_namespace(const char *name);
11691169

1170+
/**
1171+
* nvme_host_get_hostsymname() - Get the host's symbolic name
1172+
* @h: Host for which the symbolic name should be returned.
1173+
*
1174+
* Return: The symbolic name or NULL if a symbolic name hasn't been
1175+
* configure.
1176+
*/
1177+
const char *nvme_host_get_hostsymname(nvme_host_t h);
1178+
1179+
/**
1180+
* nvme_host_set_hostsymname() - Set the host's symbolic name
1181+
* @h: Host for which the symbolic name should be set.
1182+
* @hostsymname: Symbolic name
1183+
*/
1184+
void nvme_host_set_hostsymname(nvme_host_t h, const char *hostsymname);
1185+
11701186
#endif /* _LIBNVME_TREE_H */

0 commit comments

Comments
 (0)