Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions libnvme/doc/config-schema.json.in
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@
"type": "string",
"maxLength": 223
},
"persistent_discovery_ctrl": {
"description": "Enable/disable Persistent Discovery Controller",
"type": "boolean"
},
"ports": {
"description": "Array of NVMe subsystem ports",
"type": "array",
Expand Down
1 change: 1 addition & 0 deletions libnvme/libnvme/accessors.i
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ struct libnvme_subsystem {
const char * firmware;
%immutable subsystype;
const char * subsystype;
bool pdc_enabled;
%extend {
%immutable iopolicy;
const char * iopolicy;
Expand Down
2 changes: 2 additions & 0 deletions libnvme/src/libnvme.ld
Original file line number Diff line number Diff line change
Expand Up @@ -159,10 +159,12 @@ LIBNVME_3 {
libnvme_subsystem_first_ns;
libnvme_subsystem_get_host;
libnvme_subsystem_get_iopolicy;
libnvme_subsystem_get_pdc_enabled;
libnvme_subsystem_lookup_namespace;
libnvme_subsystem_next_ctrl;
libnvme_subsystem_next_ns;
libnvme_subsystem_release_fds;
libnvme_subsystem_set_pdc_enabled;
libnvme_transport_handle_get_fd;
libnvme_transport_handle_get_mi_ep;
libnvme_transport_handle_get_name;
Expand Down
13 changes: 13 additions & 0 deletions libnvme/src/nvme/accessors.c
Original file line number Diff line number Diff line change
Expand Up @@ -563,6 +563,19 @@ __libnvme_public const char *libnvme_subsystem_get_subsystype(
return p->subsystype;
}

__libnvme_public void libnvme_subsystem_set_pdc_enabled(
struct libnvme_subsystem *p,
bool pdc_enabled)
{
p->pdc_enabled = pdc_enabled;
}

__libnvme_public bool libnvme_subsystem_get_pdc_enabled(
const struct libnvme_subsystem *p)
{
return p->pdc_enabled;
}

/****************************************************************************
* Accessors for: struct libnvme_host
****************************************************************************/
Expand Down
17 changes: 17 additions & 0 deletions libnvme/src/nvme/accessors.h
Original file line number Diff line number Diff line change
Expand Up @@ -739,6 +739,23 @@ const char *libnvme_subsystem_get_firmware(const struct libnvme_subsystem *p);
*/
const char *libnvme_subsystem_get_subsystype(const struct libnvme_subsystem *p);

/**
* libnvme_subsystem_set_pdc_enabled() - Set pdc_enabled.
* @p: The &struct libnvme_subsystem instance to update.
* @pdc_enabled: Value to assign to the pdc_enabled field.
*/
void libnvme_subsystem_set_pdc_enabled(
struct libnvme_subsystem *p,
bool pdc_enabled);

/**
* libnvme_subsystem_get_pdc_enabled() - Get pdc_enabled.
* @p: The &struct libnvme_subsystem instance to query.
*
* Return: The value of the pdc_enabled field.
*/
bool libnvme_subsystem_get_pdc_enabled(const struct libnvme_subsystem *p);

/****************************************************************************
* Accessors for: struct libnvme_host
****************************************************************************/
Expand Down
3 changes: 1 addition & 2 deletions libnvme/src/nvme/fabrics.c
Original file line number Diff line number Diff line change
Expand Up @@ -2416,9 +2416,8 @@ static int _nvmf_discovery(struct libnvme_global_ctx *ctx,
if (!(eflags & NVMF_DISC_EFLAGS_EPCSD))
disconnect = true;
else
disconnect = false;
disconnect = libnvme_subsystem_get_pdc_enabled(s);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, this makes a lot of sense to me.

}

set_discovery_kato(&nfctx);
} else {
/* NVME_NQN_NVME */
Expand Down
15 changes: 14 additions & 1 deletion libnvme/src/nvme/json.c
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ static void json_parse_port(libnvme_subsystem_t s, struct json_object *port_obj)

static void json_parse_subsys(libnvme_host_t h, struct json_object *subsys_obj)
{
struct json_object *nqn_obj, *port_array;
struct json_object *nqn_obj, *port_array, *attr_obj;
libnvme_subsystem_t s;
const char *nqn = "";
int p;
Expand All @@ -140,6 +140,10 @@ static void json_parse_subsys(libnvme_host_t h, struct json_object *subsys_obj)
if (!s)
return;

attr_obj = json_object_object_get(subsys_obj, "persistent_discovery_ctrl");
if (attr_obj)
libnvme_subsystem_set_pdc_enabled(s, json_object_get_boolean(attr_obj));

port_array = json_object_object_get(subsys_obj, "ports");
if (!port_array)
return;
Expand Down Expand Up @@ -378,6 +382,7 @@ static void json_update_subsys(struct json_object *subsys_array,
const char *subsysnqn = libnvme_subsystem_get_subsysnqn(s);
struct json_object *subsys_obj = json_object_new_object();
struct json_object *port_array;
bool pdc_enabled = libnvme_subsystem_get_pdc_enabled(s);

/* Skip discovery subsystems as the nqn is not unique */
if (!strcmp(subsysnqn, NVME_DISC_SUBSYS_NAME)) {
Expand All @@ -387,6 +392,10 @@ static void json_update_subsys(struct json_object *subsys_array,

json_object_object_add(subsys_obj, "nqn",
json_object_new_string(subsysnqn));
if (pdc_enabled != libnvme_host_is_pdc_enabled(s->h, DEFAULT_PDC_ENABLED))
json_object_object_add(subsys_obj, "persistent_discovery_ctrl",
json_object_new_boolean(pdc_enabled));

port_array = json_object_new_array();
libnvme_subsystem_for_each_ctrl(s, c) {
json_update_port(port_array, c);
Expand Down Expand Up @@ -620,11 +629,15 @@ static void json_dump_subsys(struct json_object *subsys_array,
{
struct json_object *subsys_obj = json_object_new_object();
struct json_object *ns_array;
bool pdc_enabled = libnvme_subsystem_get_pdc_enabled(s);

json_object_object_add(subsys_obj, "name",
json_object_new_string(libnvme_subsystem_get_name(s)));
json_object_object_add(subsys_obj, "nqn",
json_object_new_string(libnvme_subsystem_get_subsysnqn(s)));
if (pdc_enabled != libnvme_host_is_pdc_enabled(s->h, DEFAULT_PDC_ENABLED))
json_object_object_add(subsys_obj, "persistent_discovery_ctrl",
json_object_new_boolean(pdc_enabled));

ns_array = json_object_new_array();
if (!json_dump_subsys_multipath(s, ns_array))
Expand Down
1 change: 1 addition & 0 deletions libnvme/src/nvme/private.h
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,7 @@ struct libnvme_subsystem { // !generate-accessors:read=generated,write=none !ge
char *firmware;
char *subsystype;
char *iopolicy; // !access:read=custom
bool pdc_enabled; // !access:read=generated,write=generated
};

struct libnvme_host { // !generate-accessors:read=generated,write=none !generate-python:alias=Host
Expand Down
7 changes: 7 additions & 0 deletions libnvme/src/nvme/tree.c
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,12 @@ struct libnvme_subsystem *nvme_alloc_subsystem(struct libnvme_host *h,
free(s);
return NULL;
}
/*
* Use the default from the host.
* Any value from the 'subsystem' json configuration
* will override it.
*/
s->pdc_enabled = libnvme_host_is_pdc_enabled(h, DEFAULT_PDC_ENABLED);

if (name)
libnvme_init_subsystem(s, name);
Expand Down Expand Up @@ -503,6 +509,7 @@ static int libnvme_create_host(struct libnvme_global_ctx *ctx,
list_head_init(&h->subsystems);
list_node_init(&h->entry);
h->ctx = ctx;
h->pdc_enabled = DEFAULT_PDC_ENABLED;

list_add_tail(&ctx->hosts, &h->entry);

Expand Down
Loading