Add Subsystem/Ctrl/Namespace relations
cover Add Subsystem/Ctrl/Namespace relations
This patchset introduce few small bug fixes for memory leaks, improve coding style, improve code readability and mainly focus on the "nvme list-subsys" command. This command will show the whole NVM subsystem list (same as "nvme list" does for namespaces).
The patchset ends with adding namespaces entry per each ctrl in the system. Actually, at first stage, we'll print only the namespace handle (nvme0n1 for example). Later on, we can add more attribute per demand (uuid, nguid, capacity, etc...).
Max Gurtovoy (9):
nvme: update list-ns nsid option
nvme: update description for "nvme list" command
fabrics: Fix memory leak of subsys list
nvme-print: fix json object memory leak
nvme: fix coding style issue
nvme: update list-subsys command to show the entire list
nvme-print: Introduce show_nvme_ctrl helper
nvme-print: Rename "Paths" --> "Ctrls" for json output in list-subsys
nvme: Retrieve namespaces during list-subsys cmd
fabrics.c | 6 +- nvme-print.c | 51 +++++++---- nvme.c | 274 +++++++++++++++++++++++------------------------------------ nvme.h | 9 +- 4 files changed, 150 insertions(+), 190 deletions(-)
Signature · 1 line
1.8.3.1
PATCH 1/9 nvme: update list-ns nsid option
This commit updates the optional nsid argument to define the wanted nsid for start, instead of starting from nsid + 1. E.g. in case we've wanted to get the list of namespaces starting from 1, before this commit, we used the "--namespace-id=0" option. Nsid 0 is not valid in NVMe spec, thus change it to start counting from the given nsid.
--- nvme.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-)
nvme.c +6 -5
@@ -950,9 +950,9 @@ close_fd:static int list_ns (int argc,char **argv,struct command *cmd,struct plugin *plugin) { -const char *desc ="For the specified device, show the " \ -"namespace list in a NVMe subsystem, optionally starting with a given namespace" ; -const char *namespace_id ="namespace number returned list should to start after" ; +const char *desc ="For the specified controller handle, show the " \ +"namespace list in the associated NVMe subsystem, optionally starting with a given nsid." ; +const char *namespace_id ="first nsid returned list should start from" ;const char *all ="show all namespaces in the subsystem, whether attached or inactive" ;int err, i, fd;__u32 ns_list[1024 ];
@@ -963,7 +963,7 @@ static int list_ns(int argc, char **argv, struct command *cmd, struct plugin *pl };struct config cfg = { - .namespace_id =0 , + .namespace_id =1 , };const struct argconfig_commandline_options command_line_options[] = {
@@ -976,7 +976,8 @@ static int list_ns(int argc, char **argv, struct command *cmd, struct plugin *plif (fd <0 )return fd; - err =nvme_identify_ns_list (fd, cfg.namespace_id, !!cfg.all, ns_list); + err =nvme_identify_ns_list (fd, cfg.namespace_id -1 , !!cfg.all, + ns_list);if (!err) {for (i =0 ; i <1024 ; i++)if (ns_list[i])
Signature · 1 line
1.8.3.1
PATCH 1/9 nvme: update list-ns nsid option
Quoted 48 lines
Subject: [PATCH 1/9] nvme: update list-ns nsid option
This commit updates the optional nsid argument to define the wanted nsid for start, instead of starting from nsid + 1. E.g. in case we've wanted to get the list of namespaces starting from 1, before this commit, we used the "--namespace-id=0" option. Nsid 0 is not valid in NVMe spec, thus change it to start counting from the given nsid.
Signed-off-by Max Gurtovoy <maxg at mellanox.com>--- nvme.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-)nvme.c +2
-3@@ -950,9 +950,9 @@ close_fd:static int list_ns (int argc,char **argv,struct command *cmd,struct plugin *plugin) { -const char *desc ="For the specified device, show the " \ - "namespace list in a NVMe subsystem, optionally starting with a given namespace"; - const char *namespace_id = "namespace number returned list should to start after"; +const char *desc ="For the specified controller handle, show the " \ + "namespace list in the associated NVMe subsystem,optionally starting with a given nsid.";
nvme.c +1
-0+ const char *namespace_id = "first nsid returned list should startfrom";
const char *all = "show all namespaces in the subsystem, whether
attached or inactive";nvme.c +1
-1int err, i, fd;__u32 ns_list[1024 ];@@ -963,7 +963,7 @@ static int list_ns(int argc, char **argv, struct command *cmd, struct plugin *pl };struct config cfg = { - .namespace_id =0 , + .namespace_id =1 , };const struct
argconfig_commandline_options
command_line_options[] = {
nvme.c static int list_ns(int argc, char **argv, struct command · line 979
Quoted 4 lines
nvme.c +0
-0@@ -976,7 +976,8 @@ static int list_ns(int argc, char **argv, struct command *cmd, struct plugin *plif (fd <0 )return fd;
Can we have invalid --namespace-id check here?
if (!cfg.namespace_id)
return -EINVAL;
Otherwise, It looks good to me.
Quoted 14 lines
nvme.c +2
-1- err =nvme_identify_ns_list (fd, cfg.namespace_id, !!cfg.all, ns_list); + err =nvme_identify_ns_list (fd, cfg.namespace_id -1 , !!cfg.all, + ns_list);if (!err) {for (i =0 ; i <1024 ; i++)if (ns_list[i])
--
1.8.3.1_______________________________________________
Linux-nvme mailing list
Linux-nvme at lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-nvme
PATCH 2/9 nvme: update description for "nvme list" command
In reply to Max GurtovoyThe "nvme list" command doesn't get any device handle as an input argument. This operation prints out a basic information for all NVMe namespaces in the system.
--- nvme.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
nvme.c +1 -1
@@ -1794,7 +1794,7 @@ static int list(int argc, char **argv, struct command *cmd, struct plugin *plugistruct list_item *list_items;unsigned int list_cnt =0 ;int fmt, ret, fd, i, n; -const char *desc ="Retrieve basic information for the given device" ; +const char *desc ="Retrieve basic information for all NVMe namespaces" ;struct config {char *output_format; };
Signature · 1 line
1.8.3.1
PATCH 2/9 nvme: update description for "nvme list" command
This looks good to me.
PATCH 3/9 fabrics: Fix memory leak of subsys list
In reply to Max Gurtovoy--- fabrics.c | 1 + 1 file changed, 1 insertion(+)
fabrics.c +1 -0
@@ -1203,5 +1203,6 @@ int disconnect_all(const char *desc, int argc, char **argv) } } out: +free_subsys_list (slist, subcnt);return ret; }
Signature · 1 line
1.8.3.1
PATCH 3/9 fabrics: Fix memory leak of subsys list
This looks good to me.
PATCH 4/9 nvme-print: fix json object memory leak
In reply to Max Gurtovoy--- nvme-print.c | 1 + 1 file changed, 1 insertion(+)
nvme-print.c +1 -0
@@ -2918,6 +2918,7 @@ void json_print_nvme_subsystem_list(struct subsys_list_item *slist, int n)json_object_add_value_array (root,"Subsystems" , subsystems);json_print_object (root,NULL );printf ("\n" ); +json_free_object (root); }static void show_registers_cap (struct nvme_bar_cap *cap)
Signature · 1 line
1.8.3.1
PATCH 4/9 nvme-print: fix json object memory leak
This looks good to me.
PATCH 5/9 nvme: fix coding style issue
In reply to Max GurtovoyIt's more common to use the following coding style:
if (condition) {
do_that;
do_this;
} else if (condition2) {
do_this;
} else {
do_that;
}
--- nvme.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
nvme.c +3 -3
@@ -982,11 +982,11 @@ static int list_ns(int argc, char **argv, struct command *cmd, struct plugin *plfor (i =0 ; i <1024 ; i++)if (ns_list[i])printf ("[%4u]:%#x\n" , i,le32_to_cpu (ns_list[i])); - } -else if (err >0 ) + }else if (err >0 ) {show_nvme_status (err); -else + }else {perror ("id namespace list" ); + }close (fd);
Signature · 1 line
1.8.3.1
PATCH 5/9 nvme: fix coding style issue
This looks good to me.
PATCH 6/9 nvme: update list-subsys command to show the entire list
In reply to Max GurtovoyMake it similar to "nvme list" command. For that, remove the unnecessary ana_state parsing (was introduced only if specific namespace handle was given).
--- fabrics.c | 5 +- nvme-print.c | 10 +--- nvme.c | 149 +++++++---------------------------------------------------- nvme.h | 3 +- 4 files changed, 23 insertions(+), 144 deletions(-)
fabrics.c +4 -1
@@ -1190,7 +1190,10 @@ int disconnect_all(const char *desc, int argc, char **argv)if (ret)return ret; - slist =get_subsys_list (&subcnt,NULL ,NVME_NSID_ALL ); + ret =get_subsys_list (&subcnt, &slist); +if (ret) +return ret; +for (i =0 ; i < subcnt; i++) {struct subsys_list_item *subsys = &slist[i];
nvme-print.c +2 -8
@@ -2851,12 +2851,10 @@ static void show_nvme_subsystem(struct subsys_list_item *item)printf ("\\\n" );for (i =0 ; i < item->nctrls; i++) { -printf (" +- %s %s %s %s %s\n" , item->ctrls[i].name, +printf (" +- %s %s %s %s\n" , item->ctrls[i].name, item->ctrls[i].transport, item->ctrls[i].address, - item->ctrls[i].state, - item->ctrls[i].ana_state ? - item->ctrls[i].ana_state :"" ); + item->ctrls[i].state); } }
@@ -2902,10 +2900,6 @@ void json_print_nvme_subsystem_list(struct subsys_list_item *slist, int n) slist[i].ctrls[j].address);json_object_add_value_string (path_attrs,"State" , slist[i].ctrls[j].state); -if (slist[i].ctrls[j].ana_state) -json_object_add_value_string (path_attrs, -"ANAState" , - slist[i].ctrls[j].ana_state);json_array_add_value_object (paths, path_attrs); }if (j) {
nvme.c +16 -133
230 lines not on this page · raw message
nvme.h +1 -2
@@ -147,7 +147,6 @@ struct ctrl_list_item {char *address;char *transport;char *state; -char *ana_state; };struct subsys_list_item {
@@ -174,7 +173,7 @@ extern const char *devicename;int __id_ctrl (int argc,char **argv,struct command *cmd,struct plugin *plugin,void (*vs)(__u8 *vs,struct json_object *root));int validate_output_format (char *format); -struct subsys_list_item *get_subsys_list (int *subcnt,char *subsysnqn,__u32 nsid); +int get_subsys_list (int *subcnt,struct subsys_list_item **pslist);void free_subsys_list (struct subsys_list_item *slist,int n);char *nvme_char_from_block (char *block);
Signature · 1 line
1.8.3.1
PATCH 7/9 nvme-print: Introduce show_nvme_ctrl helper
In reply to Max GurtovoyThis is a preparation patch for adding namespaces attribute for each controller.
--- nvme-print.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-)
nvme-print.c +9 -7
@@ -2843,6 +2843,13 @@ void json_sanitize_log(struct nvme_sanitize_log_page *sanitize_log, const char *json_free_object (root); } +static void show_nvme_ctrl (struct ctrl_list_item *item) +{ +printf (" +- %s %s %s %s\n" , item->name, item->transport, item->address, + item->state); +} + +static void show_nvme_subsystem (struct subsys_list_item *item) {int i;
@@ -2850,13 +2857,8 @@ static void show_nvme_subsystem(struct subsys_list_item *item)printf ("%s - NQN=%s\n" , item->name, item->subsysnqn);printf ("\\\n" ); -for (i =0 ; i < item->nctrls; i++) { -printf (" +- %s %s %s %s\n" , item->ctrls[i].name, - item->ctrls[i].transport, - item->ctrls[i].address, - item->ctrls[i].state); - } - +for (i =0 ; i < item->nctrls; i++) +show_nvme_ctrl (&item->ctrls[i]); }void show_nvme_subsystem_list (struct subsys_list_item *slist,int n)
Signature · 1 line
1.8.3.1
PATCH 8/9 nvme-print: Rename "Paths" --> "Ctrls" for json output in list-subsys
In reply to Max Gurtovoy--- nvme-print.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
nvme-print.c +2 -4
@@ -2904,10 +2904,8 @@ void json_print_nvme_subsystem_list(struct subsys_list_item *slist, int n) slist[i].ctrls[j].state);json_array_add_value_object (paths, path_attrs); } -if (j) { -json_object_add_value_array (subsystem_attrs,"Paths" , paths); - } - +if (j) +json_object_add_value_array (subsystem_attrs,"Ctrls" , paths); }if (i)
Signature · 1 line
1.8.3.1
PATCH 9/9 nvme: Retrieve namespaces during list-subsys cmd
In reply to Max GurtovoyAdd an association between subsystems/ctrls/namespaces using "nvme list-subsys" command. Now this command will show the following:
nvme-subsys4 - NQN=testsubsystem_0
\
+- nvme4 rdma traddr=12.212.99.85 trsvcid=4420 live \
+- nvme4n1 +- nvme4n2 +- nvme4n3 +- nvme5 rdma traddr=12.212.99.85 trsvcid=4420 live \ +- nvme5n1 +- nvme5n2 +- nvme5n3
Instead of:
----------------
nvme-subsys4 - NQN=testsubsystem_0
\
+- nvme4 rdma traddr=12.212.99.85 trsvcid=4420 +- nvme5 rdma traddr=12.212.99.85 trsvcid=4420
The new json output is:
--------------------------
{
"Name" : "nvme-subsys4",
"NQN" : "testsubsystem_0",
"Ctrls" : [
{
"Name" : "nvme4",
"Transport" : "rdma",
"Address" : "traddr=12.212.99.85 trsvcid=4420",
"State" : "live",
"Namespaces" : [
{
"Name" : "nvme4n1"
},
{
"Name" : "nvme4n2"
},
{
"Name" : "nvme4n3"
}
]
},
{
"Name" : "nvme5",
"Transport" : "rdma",
"Address" : "traddr=12.212.99.85 trsvcid=4420",
"State" : "live",
"Namespaces" : [
{
"Name" : "nvme5n1"
},
{
"Name" : "nvme5n2"
},
{
"Name" : "nvme5n3"
}
]
}
]
}--- nvme-print.c | 22 ++++++++++++- nvme.c | 106 ++++++++++++++++++++++++++++++++++++++++++++--------------- nvme.h | 6 ++++ 3 files changed, 106 insertions(+), 28 deletions(-)
nvme-print.c +21 -1
@@ -2845,8 +2845,14 @@ void json_sanitize_log(struct nvme_sanitize_log_page *sanitize_log, const char *static void show_nvme_ctrl (struct ctrl_list_item *item) { +int i; +printf (" +- %s %s %s %s\n" , item->name, item->transport, item->address, item->state); +printf (" \\\n" ); +for (i =0 ; i < item->ns_num; i++) { +printf (" +- %s\n" , item->namespaces[i].name); + } }
@@ -2875,7 +2881,9 @@ void json_print_nvme_subsystem_list(struct subsys_list_item *slist, int n)struct json_object *subsystem_attrs;struct json_array *paths;struct json_object *path_attrs; -int i, j; +struct json_array *namespaces; +struct json_object *ns_attrs; +int i, j, k; root =json_create_object (); subsystems =json_create_array ();
@@ -2902,6 +2910,18 @@ void json_print_nvme_subsystem_list(struct subsys_list_item *slist, int n) slist[i].ctrls[j].address);json_object_add_value_string (path_attrs,"State" , slist[i].ctrls[j].state); + + namespaces =json_create_array (); +for (k =0 ; k < slist[i].ctrls[j].ns_num; k++) { + ns_attrs =json_create_object (); +json_object_add_value_string (ns_attrs,"Name" , + slist[i].ctrls[j].namespaces[k].name); +json_array_add_value_object (namespaces, ns_attrs); + } +if (k) +json_object_add_value_array (path_attrs,"Namespaces" , + namespaces); +json_array_add_value_object (paths, path_attrs); }if (j)
nvme.c +79 -27
137 lines not on this page · raw message
nvme.h +6 -0
@@ -142,11 +142,17 @@ struct list_item {unsigned block; }; +struct ns_list_item { +char *name; +}; +struct ctrl_list_item {char *name;char *address;char *transport;char *state; +int ns_num; +struct ns_list_item *namespaces; };struct subsys_list_item {
Signature · 1 line
1.8.3.1
PATCH 9/9 nvme: Retrieve namespaces during list-subsys cmd
Quoted 16 lines · Max Gurtovoy
Add an association between subsystems/ctrls/namespaces using "nvme list-subsys" command. Now this command will show the following:
nvme-subsys4 - NQN=testsubsystem_0
\
+- nvme4 rdma traddr=12.212.99.85 trsvcid=4420 live \+- nvme4n1 +- nvme4n2 +- nvme4n3 +- nvme5 rdma traddr=12.212.99.85 trsvcid=4420 live \ +- nvme5n1 +- nvme5n2 +- nvme5n3
Quoted 6 lines
Instead of:
----------------
nvme-subsys4 - NQN=testsubsystem_0
\+- nvme4 rdma traddr=12.212.99.85 trsvcid=4420 +- nvme5 rdma traddr=12.212.99.85 trsvcid=4420
This is a terrific start. Your output indicates you are not using nvme native multipathing, though. Could you retry this command with that enabled (I'll try it tomorrow as well)?
PATCH 9/9 nvme: Retrieve namespaces during list-subsys cmd
Quoted 23 lines · Keith Busch
Quoted 16 lines · Max Gurtovoy
Add an association between subsystems/ctrls/namespaces using "nvme list-subsys" command. Now this command will show the following:
nvme-subsys4 - NQN=testsubsystem_0
\
+- nvme4 rdma traddr=12.212.99.85 trsvcid=4420 live\ +- nvme4n1 +- nvme4n2 +- nvme4n3 +- nvme5 rdma traddr=12.212.99.85 trsvcid=4420 live \ +- nvme5n1 +- nvme5n2 +- nvme5n3Quoted 6 lines
Instead of:
----------------
nvme-subsys4 - NQN=testsubsystem_0
\+- nvme4 rdma traddr=12.212.99.85 trsvcid=4420 +- nvme5 rdma traddr=12.212.99.85 trsvcid=4420
Quoted 3 lines
This is a terrific start. Your output indicates you are not using nvme native multipathing, though. Could you retry this command with that enabled (I'll try it tomorrow as well)?
Yup I'll configure the native multipath. But what is expected ?
should we print nvme4c1n1/nvme4c1n2/nvme4c1n3 for nvme4
and nvme4c2n1/nvme4c2n2/nvme4c2n3 for nvme5 ?
if so, I guess the information on the "IO-ble" devices nvme4n1/nvme4n2/nvme4n3 will not be printed.
something like:
nvme-subsys4 - NQN=testsubsystem_0
\
?+- nvme4 rdma traddr=12.212.99.85 trsvcid=4420 live ?\
? +- nvme4c1n1
? +- nvme4c1n2
? +- nvme4c1n3
?+- nvme5 rdma traddr=12.212.99.85 trsvcid=4420 live ?\
? +- nvme4c2n1
? +- nvme4c2n2
? +- nvme4c2n3
if this if fine I'll send a V2 with a small fix.
-Max.
Keith Busch
maintainerPATCH 9/9 nvme: Retrieve namespaces during list-subsys cmd
Quoted 54 lines · Max Gurtovoy
Quoted 23 lines · Keith Busch
Quoted 16 lines · Max Gurtovoy
Add an association between subsystems/ctrls/namespaces using "nvme list-subsys" command. Now this command will show the following:
nvme-subsys4 - NQN=testsubsystem_0
\
+- nvme4 rdma traddr=12.212.99.85 trsvcid=4420 live\ +- nvme4n1 +- nvme4n2 +- nvme4n3 +- nvme5 rdma traddr=12.212.99.85 trsvcid=4420 live \ +- nvme5n1 +- nvme5n2 +- nvme5n3Quoted 6 lines
Instead of:
----------------
nvme-subsys4 - NQN=testsubsystem_0
\+- nvme4 rdma traddr=12.212.99.85 trsvcid=4420 +- nvme5 rdma traddr=12.212.99.85 trsvcid=4420Quoted 3 lines
This is a terrific start. Your output indicates you are not using nvme native multipathing, though. Could you retry this command with that enabled (I'll try it tomorrow as well)?
Yup I'll configure the native multipath. But what is expected ?
should we print nvme4c1n1/nvme4c1n2/nvme4c1n3 for nvme4
and nvme4c2n1/nvme4c2n2/nvme4c2n3 for nvme5 ?
if so, I guess the information on the "IO-ble" devices nvme4n1/nvme4n2/nvme4n3 will not be printed.
something like:
nvme-subsys4 - NQN=testsubsystem_0
\
?+- nvme4 rdma traddr=12.212.99.85 trsvcid=4420 live ?\
? +- nvme4c1n1
? +- nvme4c1n2
? +- nvme4c1n3
?+- nvme5 rdma traddr=12.212.99.85 trsvcid=4420 live ?\
? +- nvme4c2n1
? +- nvme4c2n2
? +- nvme4c2n3
Quoted 1 line
if this if fine I'll send a V2 with a small fix.
I think we'd actually prefer not seeing the hidden block devices, but instead use the device name from the "head": nvme4n1, nvme4n2, etc...
[email protected]
maintainerPATCH 9/9 nvme: Retrieve namespaces during list-subsys cmd
Quoted 4 lines · Keith Busch
Quoted 1 line
if this if fine I'll send a V2 with a small fix.
I think we'd actually prefer not seeing the hidden block devices, but instead use the device name from the "head": nvme4n1, nvme4n2, etc...
Agreed. The hidden devices are an artefact we should expose to the user as little as possible.