Add Subsystem/Ctrl/Namespace relations (nvme-cli)
v2 cover Add Subsystem/Ctrl/Namespace relations (nvme-cli)
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...).
Changes from v1:
- Added Reviewed-by sign (thanks Minwoo Im)
- Added check for invalid nsid (proposed by Minwoo Im)
- Fixed the output for native NVMe multipath
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 | 52 +++++++---- nvme.c | 281 ++++++++++++++++++++++++----------------------------------- nvme.h | 9 +- 4 files changed, 158 insertions(+), 190 deletions(-)
Signature · 1 line
1.8.3.1
PATCH v2 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 | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-)
nvme.c +9 -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,11 @@ 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); +if (!cfg.namespace_id) +return -EINVAL ; + + 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 39 lines · Max Gurtovoy
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.
Reviewed-by Minwoo Im <minwoo.im at samsung.com>Signed-off-by Max Gurtovoy <maxg at mellanox.com>--- nvme.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-)nvme.c +4
-4@@ -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[] = {
nvme.c static int list_ns(int argc, char **argv, struct command *cmd, struct plugin *pl · line 980
Quoted 6 lines
nvme.c +2
-1@@ -976,7 +976,11 @@ 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); +if (!cfg.namespace_id) +return -EINVAL ;
Would it be useful to include an error message here? I don't like playing the guessing game about what I did wrong when I just get the help message back.
Quoted 7 lines
nvme.c +3
-0+ + 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])
PATCH v2 1/9 nvme: update list-ns nsid option
Quoted 3 lines · Kenneth
Would it be useful to include an error message here? I don't like playing the guessing game about what I did wrong when I just get the help message back.
Yup good idea. I'll fix that in V3.
-Max.
PATCH v2 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
@@ -1797,7 +1797,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 v2 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 v2 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 v2 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
@@ -985,11 +985,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 v2 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 v2 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 7/9 nvme-print: Introduce show_nvme_ctrl helper
Quoted 30 lines · Max Gurtovoy
This is a preparation patch for adding namespaces attribute for each controller.
Signed-off-by Max Gurtovoy <maxg at mellanox.com>--- nvme-print.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-)nvme-print.c +7
-0@@ -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" );
nvme-print.c static void show_nvme_subsystem(struct subsys_list_item *item) · line 2862
Quoted 10 lines
nvme-print.c +2
-7-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]); }
This looks good to me.
PATCH v2 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 v2 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-subsys3 - NQN=nqn.2014.08.org.nvmexpress:80868086CVCQ5234001C400AGN INTEL SSDPEDMW400G4 \
+- nvme0 pcie 0000:08:00.0 live
\
+- nvme3n1
nvme-subsys4 - NQN=testsubsystem_0
\
+- nvme4 rdma traddr=1.212.99.85 trsvcid=4420 live
\
+- nvme4c1n1 +- nvme4c1n2 +- nvme4c1n3 +- nvme5 rdma traddr=1.212.99.85 trsvcid=4420 live \ +- nvme4c2n1 +- nvme4c2n2 +- nvme4c2n3
Instead of:
----------------
nvme-subsys3 - NQN=nqn.2014.08.org.nvmexpress:80868086CVCQ5234001C400AGN INTEL SSDPEDMW400G4 \
+- nvme0 pcie 0000:08:00.0
nvme-subsys4 - NQN=testsubsystem_0
\
+- nvme4 rdma traddr=1.212.99.85 trsvcid=4420 +- nvme5 rdma traddr=1.212.99.85 trsvcid=4420
The new json output is (partial):
--------------------------
{
"Name" : "nvme-subsys4",
"NQN" : "testsubsystem_0",
"Ctrls" : [
{
"Name" : "nvme4",
"Transport" : "rdma",
"Address" : "traddr=1.212.99.85 trsvcid=4420",
"State" : "live",
"Namespaces" : [
{
"Name" : "nvme4c1n1"
},
{
"Name" : "nvme4c1n2"
},
{
"Name" : "nvme4c1n3"
}
]
},
{
"Name" : "nvme5",
"Transport" : "rdma",
"Address" : "traddr=1.212.99.85 trsvcid=4420",
"State" : "live",
"Namespaces" : [
{
"Name" : "nvme4c2n1"
},
{
"Name" : "nvme4c2n2"
},
{
"Name" : "nvme4c2n3"
}
]
}
]
}--- nvme-print.c | 23 ++++++++++++- nvme.c | 110 ++++++++++++++++++++++++++++++++++++++++++++--------------- nvme.h | 6 ++++ 3 files changed, 111 insertions(+), 28 deletions(-)
nvme-print.c +22 -1
@@ -2845,8 +2845,15 @@ 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); +for (i =0 ; i < item->ns_num; i++) { +if (!i) +printf (" \\\n" ); +printf (" +- %s\n" , item->namespaces[i].name); + } }
@@ -2875,7 +2882,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 +2911,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 +83 -27
141 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 12 lines · Max Gurtovoy
Add an association between subsystems/ctrls/namespaces using "nvme list-subsys" command. Now this command will show the following:
nvme-subsys3 - NQN=nqn.2014.08.org.nvmexpress:80868086CVCQ5234001C400AGN INTEL SSDPEDMW400G4 \
+- nvme0 pcie 0000:08:00.0 live
\
+- nvme3n1
nvme-subsys4 - NQN=testsubsystem_0
\
+- nvme4 rdma traddr=1.212.99.85 trsvcid=4420 live
\
Quoted 9 lines
+- nvme4c1n1 +- nvme4c1n2 +- nvme4c1n3 +- nvme5 rdma traddr=1.212.99.85 trsvcid=4420 live \ +- nvme4c2n1 +- nvme4c2n2 +- nvme4c2n3
Quoted 44 lines
The new json output is (partial):
--------------------------{ "Name" : "nvme-subsys4", "NQN" : "testsubsystem_0", "Ctrls" : [ { "Name" : "nvme4", "Transport" : "rdma", "Address" : "traddr=1.212.99.85 trsvcid=4420", "State" : "live", "Namespaces" : [ { "Name" : "nvme4c1n1" }, { "Name" : "nvme4c1n2" }, { "Name" : "nvme4c1n3" } ] }, { "Name" : "nvme5", "Transport" : "rdma", "Address" : "traddr=1.212.99.85 trsvcid=4420", "State" : "live", "Namespaces" : [ { "Name" : "nvme4c2n1" }, { "Name" : "nvme4c2n2" }, { "Name" : "nvme4c2n3" } ] } ] }Signed-off-by Max Gurtovoy <maxg at mellanox.com>
Sagi Grimberg
maintainerv2 cover Add Subsystem/Ctrl/Namespace relations (nvme-cli)
In reply to Max GurtovoyQuoted 9 lines
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...).
Can you split patches 1-5 to a separate fixes series? Would be easier to review.
As for the list-subsys, I think that when passing the namespace handle it should only output the corresponding namespace from each controller.
list-subsys in my mind should probably stay as is without a namespace handle passed because it doesn't give any meaningful information without the mpath-namespace to slaves mapping.
Instead, a more effective display would be the mapping of each mpath namespace to the corresponding slave namespaces. Perhaps with a new command "list-mpath"?
On a side question, what does this information give the user if the slave devices don't have a device node?