Skip to content

Commit 20865a4

Browse files
authored
Merge pull request #564 from igaw/make-pdc-optional
tree: Add persistent_discovery_ctrl config flag
2 parents 2d1ef47 + 19d6fab commit 20865a4

6 files changed

Lines changed: 55 additions & 2 deletions

File tree

doc/config-schema.json.in

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@
3333
"description": "NVMe host symbolic name",
3434
"type": "string"
3535
},
36+
"persistent_discovery_ctrl": {
37+
"description": "Enable/disable Persistent Discovery Controller",
38+
"type": "boolean"
39+
},
3640
"required": [ "hostnqn" ],
3741
"subsystems": {
3842
"description": "Array of NVMe subsystem properties",

src/libnvme.map

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

33
LIBNVME_1_3 {
44
global:
5+
nvme_ctrl_is_unique_discovery_ctrl;
6+
nvme_ctrl_set_unique_discovery_ctrl;
57
nvme_fdp_reclaim_unit_handle_status;
68
nvme_fdp_reclaim_unit_handle_update;
79
nvme_io_mgmt_recv;
810
nvme_io_mgmt_send;
9-
nvme_ctrl_is_unique_discovery_ctrl;
10-
nvme_ctrl_set_unique_discovery_ctrl;
11+
nvme_host_is_pdc_enabled;
12+
nvme_host_set_pdc_enabled;
1113
};
1214

1315
LIBNVME_1_2 {

src/nvme/json.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,9 @@ static void json_parse_host(nvme_root_t r, struct json_object *host_obj)
148148
attr_obj = json_object_object_get(host_obj, "hostsymname");
149149
if (attr_obj)
150150
nvme_host_set_hostsymname(h, json_object_get_string(attr_obj));
151+
attr_obj = json_object_object_get(host_obj, "persistent_discovery_ctrl");
152+
if (attr_obj)
153+
nvme_host_set_pdc_enabled(h, json_object_get_boolean(attr_obj));
151154
subsys_array = json_object_object_get(host_obj, "subsystems");
152155
if (!subsys_array)
153156
return;
@@ -354,6 +357,9 @@ int json_update_config(nvme_root_t r, const char *config_file)
354357
if (hostsymname)
355358
json_object_object_add(host_obj, "hostsymname",
356359
json_object_new_string(hostsymname));
360+
if (h->pdc_enabled_valid)
361+
json_object_object_add(host_obj, "persistent_discovery_ctrl",
362+
json_object_new_boolean(h->pdc_enabled));
357363
subsys_array = json_object_new_array();
358364
nvme_for_each_subsystem(h, s) {
359365
json_update_subsys(subsys_array, s);
@@ -492,6 +498,9 @@ int json_dump_tree(nvme_root_t r)
492498
if (dhchap_key)
493499
json_object_object_add(host_obj, "dhchap_key",
494500
json_object_new_string(dhchap_key));
501+
if (h->pdc_enabled_valid)
502+
json_object_object_add(host_obj, "persistent_discovery_ctrl",
503+
json_object_new_boolean(h->pdc_enabled));
495504
subsys_array = json_object_new_array();
496505
nvme_for_each_subsystem(h, s) {
497506
json_dump_subsys(subsys_array, s);

src/nvme/private.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,9 @@ struct nvme_host {
115115
char *hostid;
116116
char *dhchap_key;
117117
char *hostsymname;
118+
bool pdc_enabled;
119+
bool pdc_enabled_valid; /* set if pdc_enabled doesn't have an undefined
120+
* value */
118121
};
119122

120123
struct nvme_root {

src/nvme/tree.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,19 @@ void nvme_host_set_dhchap_key(nvme_host_t h, const char *key)
252252
h->dhchap_key = strdup(key);
253253
}
254254

255+
void nvme_host_set_pdc_enabled(nvme_host_t h, bool enabled)
256+
{
257+
h->pdc_enabled_valid = true;
258+
h->pdc_enabled = enabled;
259+
}
260+
261+
bool nvme_host_is_pdc_enabled(nvme_host_t h, bool fallback)
262+
{
263+
if (h->pdc_enabled_valid)
264+
return h->pdc_enabled;
265+
return fallback;
266+
}
267+
255268
nvme_subsystem_t nvme_first_subsystem(nvme_host_t h)
256269
{
257270
return list_top(&h->subsystems, struct nvme_subsystem, entry);

src/nvme/tree.h

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,28 @@ const char *nvme_host_get_dhchap_key(nvme_host_t h);
106106
*/
107107
void nvme_host_set_dhchap_key(nvme_host_t h, const char *key);
108108

109+
/**
110+
* nvme_host_set_pdc_enabled() - Set Persistent Discovery Controller flag
111+
* @h: Host for which the falg should be set
112+
* @enabled: The bool to set the enabled flag
113+
*
114+
* When nvme_host_set_pdc_enabled() is not used to set the PDC flag,
115+
* nvme_host_is_pdc_enabled() will return the default value which was
116+
* passed into the function and not the undefined flag value.
117+
*/
118+
void nvme_host_set_pdc_enabled(nvme_host_t h, bool enabled);
119+
120+
/**
121+
* nvme_host_is_pdc_enabled() - Is Persistenct Discovery Controller enabled
122+
* @h: Host which to check if PDC is enabled
123+
* @fallback: The fallback default value of the flag when
124+
* @nvme_host_set_pdc_enabled has not be used
125+
* to set the flag.
126+
*
127+
* Return: true if PDC is enabled for @h, else false
128+
*/
129+
bool nvme_host_is_pdc_enabled(nvme_host_t h, bool fallback);
130+
109131
/**
110132
* nvme_default_host() - Initializes the default host
111133
* @r: &nvme_root_t object

0 commit comments

Comments
 (0)