add "Path Access" field in command "nvme list"
v2 cover add "Path Access" field in command "nvme list"
This patch V2 is to add "Path Access" field in command "nvme list". I have adjusted the patches order, added proper commit description, modified the "State" to "Path Access".
When NVMe Subsystem is connected with one or more controllers via fabric, such as NVMe-oF over RDMA, if the link or NVMe Subsystem array is faulty, some nvme disks on the host are unavailable and they won't be deleted immediately. But the "nvme list" command does not show these faulty disks. So add "Path Access" field in command "nvme list", and display the access status of each disk for users. for examples:
[root@localhost nvme-cli]# nvme list
Node SN Model Namespace Usage Format FW Rev Path Access
--------- -------------------- ------------ --------- -------------------------- ---------------- -------- ------------
nvme1n1 2102352TSB10KC000015 Huawei-XSG1 1 0.00 B / 0.00 B 0 B + 0 B 1000001 faulty nvme0n1 2102352TSB10KC000015 Huawei-XSG1 1 0.00 B / 1.07 GB 512 B + 0 B 1000001 live
[root@localhost nvme-cli]#
chengjike (1):
initialize disk "access" variable
src/nvme/private.h | 1 + src/nvme/tree.c | 57 ++++++++++++++++++++++++++++++++++++++++++---- src/nvme/tree.h | 8 +++++++ 3 files changed, 61 insertions(+), 5 deletions(-)
chengjike (1):
add "Path Access" entry in command output
nvme-print.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-)
Signature · 7 lines
2.21.0.windows.1 _______________________________________________ Linux-nvme mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-nvme
PATCH v2 1/2 initialize disk "access" variable
When it is failed to get nvme_id_ns data from NVMe Subsystem, the failure may be caused by a link disconnection or an error code returned by the subsystem(such as NVME_SC_*). Then the "access" of disk is set to "faulty"(otherwise, set the value to "live"). Some displaying content of fault device can be obtained from the disk attribute files.
--- src/nvme/private.h | 1 + src/nvme/tree.c | 57 ++++++++++++++++++++++++++++++++++++++++++---- src/nvme/tree.h | 8 +++++++ 3 files changed, 61 insertions(+), 5 deletions(-)
src/nvme/private.h +1 -0
@@ -37,6 +37,7 @@ struct nvme_ns {__u32 nsid;char *name;char *sysfs_dir; +char *access;int lba_shift;int lba_size;
src/nvme/tree.c +52 -5
91 lines not on this page · raw message
src/nvme/tree.h +8 -0
@@ -452,6 +452,14 @@ const char *nvme_ns_get_sysfs_dir(nvme_ns_t n);*/ const char *nvme_ns_get_name (nvme_ns_t n); +/** +* nvme_ns_get_access() - +* @n: +* +* Return: +*/ +const char *nvme_ns_get_access (nvme_ns_t n); +/** * nvme_ns_get_firmware() - * @n:
Signature · 7 lines
2.21.0.windows.1 _______________________________________________ Linux-nvme mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-nvme
Re: [PATCH V2 nvme-cli 1/2] initialize disk "access" variable
Quoted 8 lines · chengjike
External email: Use caution opening links or attachments
When it is failed to get
nvme_id_nsdata from NVMe Subsystem, the failure may be caused by a link disconnection or an error code returned by thesubsystem(such as NVME_SC_*). Then the "access" of disk is set to "faulty"(otherwise, set the value to "live"). Some displaying content of fault device can be obtained from the disk attribute files.
commit log is overly long and somewhat needs an improvement about what code changes we are doing... see below comments...
Quoted 47 lines
Signed-off-by chengjike <[email protected]>--- src/nvme/private.h | 1 + src/nvme/tree.c | 57 ++++++++++++++++++++++++++++++++++++++++++---- src/nvme/tree.h | 8 +++++++ 3 files changed, 61 insertions(+), 5 deletions(-)src/nvme/private.h +1
-0@@ -37,6 +37,7 @@ struct nvme_ns {__u32 nsid;char *name;char *sysfs_dir; +char *access;int lba_shift;int lba_size;src/nvme/tree.c +3
-4@@ -229,9 +229,11 @@ nvme_ns_t nvme_subsystem_next_ns(nvme_subsystem_t s, nvme_ns_t n)static void __nvme_free_ns (struct nvme_ns *n) {list_del_init (&n->entry); -close (n->fd); +if (n->fd >0 ) +close (n->fd);free (n->name);free (n->sysfs_dir); +free (n->access);free (n); }@@ -1023,9 +1025,6 @@ static int nvme_configure_ctrl(nvme_ctrl_t c, const char *path,closedir (d); c->fd =nvme_open (name); -if (c->fd <0 ) -return c->fd; - c->name =strdup (name); c->sysfs_dir = (char *)path; c->firmware =nvme_get_ctrl_attr (c,"firmware_rev" );
src/nvme/tree.c const char *nvme_ns_get_name(nvme_ns_t n) · line 1283
Quoted 8 lines
src/nvme/tree.c +5
-0@@ -1277,6 +1276,11 @@ const char *nvme_ns_get_name(nvme_ns_t n)return n->name; } +const char *nvme_ns_get_access (nvme_ns_t n) +{ +return n->access; +} +
why introduce a function that is not used in this patch ? Is this a prep patch if so please update the commit log accordingly.
Quoted 9 lines
src/nvme/tree.c +2
-0const char *nvme_ns_get_model (nvme_ns_t n) {return n->c ? n->c->model : n->s->model;@@ -1515,6 +1519,37 @@ free_ns:return NULL ; } +static nvme_ns_t nvme_ns_get_local_data (const char *name,const char *path) +{
src/nvme/tree.c free_ns: · line 1533
Quoted 10 lines
src/nvme/tree.c +10
-0+struct nvme_ns *n; +char *ns_id; + + n =calloc (1 ,sizeof (*n)); +if (!n) { + errno =ENOMEM ; +return NULL ; + } +memset (n,0 ,sizeof (struct nvme_ns )); +
setting the memory to zero when allocating from calloc() ?
src/nvme/tree.c free_ns: · line 1538
Quoted 5 lines
src/nvme/tree.c +5
-0+ n->name =strdup (name); + n->fd =-1 ; + ns_id =nvme_get_attr (path,"nsid" ); +if (!ns_id) + goto free_ns;
this label is used only once just return here and remove the goto label.
src/nvme/tree.c free_ns: · line 1550
Quoted 12 lines
src/nvme/tree.c +12
-0+ n->nsid =atoi (ns_id); +free (ns_id); + +list_head_init (&n->paths); +list_node_init (&n->entry); + +return n; + +free_ns: +free (n->name); +free (n); +return NULL ;
above error handling code should be moved to if (!ns_id) ...
Quoted 33 lines
src/nvme/tree.c +15
-1+} +static struct nvme_ns *__nvme_scan_namespace (const char *sysfs_dir,const char *name) {struct nvme_ns *n;@@ -1528,9 +1563,21 @@ static struct nvme_ns *__nvme_scan_namespace(const char *sysfs_dir, const char * } n =nvme_ns_open (name); -if (!n) +if (!n) { + n =nvme_ns_get_local_data (name, path); +if (!n) + goto free_path; + ret =asprintf (&n->access,"%s" ,"faulty" ); +if (ret <0 ) + goto free_path; + goto get_attr; + } + + ret =asprintf (&n->access,"%s" ,"live" ); +if (ret <0 ) goto free_path; +get_attr: n->sysfs_dir = path;return n;src/nvme/tree.h +0
-0
src/nvme/tree.h const char *nvme_ns_get_sysfs_dir(nvme_ns_t n); · line 460
Quoted 9 lines
src/nvme/tree.h +6
-0@@ -452,6 +452,14 @@ const char *nvme_ns_get_sysfs_dir(nvme_ns_t n);*/ const char *nvme_ns_get_name (nvme_ns_t n); +/** +* nvme_ns_get_access() - +* @n: +* +* Return: +*/
Wrong function documentation comment, you need to be more descriptive wht the function is doing...
Quoted 8 lines
src/nvme/tree.h +2
-1+const char *nvme_ns_get_access (nvme_ns_t n); +/** * nvme_ns_get_firmware() - * @n: -- 2.21.0.windows.1
_______________________________________________
Linux-nvme mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-nvme
Re: [PATCH V2 nvme-cli 1/2] initialize disk "access" variable
Quoted 157 lines · Chaitanya Kulkarni
Quoted 8 lines · chengjike
External email: Use caution opening links or attachments
When it is failed to get
nvme_id_nsdata from NVMe Subsystem, the failure may be caused by a link disconnection or an error code returned by thesubsystem(such as NVME_SC_*). Then the "access" of disk is set to "faulty"(otherwise, set the value to "live"). Some displaying content of fault device can be obtained from the disk attribute files.commit log is overly long and somewhat needs an improvement about what code changes we are doing... see below comments...
Quoted 47 lines
Signed-off-by chengjike <[email protected]>--- src/nvme/private.h | 1 + src/nvme/tree.c | 57 ++++++++++++++++++++++++++++++++++++++++++---- src/nvme/tree.h | 8 +++++++ 3 files changed, 61 insertions(+), 5 deletions(-)src/nvme/private.h +1
-0@@ -37,6 +37,7 @@ struct nvme_ns {__u32 nsid;char *name;char *sysfs_dir; +char *access;int lba_shift;int lba_size;src/nvme/tree.c +3
-4@@ -229,9 +229,11 @@ nvme_ns_t nvme_subsystem_next_ns(nvme_subsystem_t s, nvme_ns_t n)static void __nvme_free_ns (struct nvme_ns *n) {list_del_init (&n->entry); -close (n->fd); +if (n->fd >0 ) +close (n->fd);free (n->name);free (n->sysfs_dir); +free (n->access);free (n); }@@ -1023,9 +1025,6 @@ static int nvme_configure_ctrl(nvme_ctrl_t c, const char *path,closedir (d); c->fd =nvme_open (name); -if (c->fd <0 ) -return c->fd; - c->name =strdup (name); c->sysfs_dir = (char *)path; c->firmware =nvme_get_ctrl_attr (c,"firmware_rev" );src/nvme/tree.c const char *nvme_ns_get_name(nvme_ns_t n) · line 1283
Quoted 8 lines
src/nvme/tree.c +5
-0@@ -1277,6 +1276,11 @@ const char *nvme_ns_get_name(nvme_ns_t n)return n->name; } +const char *nvme_ns_get_access (nvme_ns_t n) +{ +return n->access; +} +why introduce a function that is not used in this patch ? Is this a prep patch if so please update the commit log accordingly.
Quoted 9 lines
src/nvme/tree.c +2
-0const char *nvme_ns_get_model (nvme_ns_t n) {return n->c ? n->c->model : n->s->model;@@ -1515,6 +1519,37 @@ free_ns:return NULL ; } +static nvme_ns_t nvme_ns_get_local_data (const char *name,const char *path) +{src/nvme/tree.c free_ns: · line 1533
Quoted 10 lines
src/nvme/tree.c +10
-0+struct nvme_ns *n; +char *ns_id; + + n =calloc (1 ,sizeof (*n)); +if (!n) { + errno =ENOMEM ; +return NULL ; + } +memset (n,0 ,sizeof (struct nvme_ns )); +setting the memory to zero when allocating from
calloc()?src/nvme/tree.c free_ns: · line 1538
Quoted 5 lines
src/nvme/tree.c +5
-0+ n->name =strdup (name); + n->fd =-1 ; + ns_id =nvme_get_attr (path,"nsid" ); +if (!ns_id) + goto free_ns;this label is used only once just return here and remove the goto label.
src/nvme/tree.c free_ns: · line 1550
Quoted 12 lines
src/nvme/tree.c +12
-0+ n->nsid =atoi (ns_id); +free (ns_id); + +list_head_init (&n->paths); +list_node_init (&n->entry); + +return n; + +free_ns: +free (n->name); +free (n); +return NULL ;above error handling code should be moved to if (!ns_id) ...
Quoted 33 lines
src/nvme/tree.c +15
-1+} +static struct nvme_ns *__nvme_scan_namespace (const char *sysfs_dir,const char *name) {struct nvme_ns *n;@@ -1528,9 +1563,21 @@ static struct nvme_ns *__nvme_scan_namespace(const char *sysfs_dir, const char * } n =nvme_ns_open (name); -if (!n) +if (!n) { + n =nvme_ns_get_local_data (name, path); +if (!n) + goto free_path; + ret =asprintf (&n->access,"%s" ,"faulty" ); +if (ret <0 ) + goto free_path; + goto get_attr; + } + + ret =asprintf (&n->access,"%s" ,"live" ); +if (ret <0 ) goto free_path; +get_attr: n->sysfs_dir = path;return n;src/nvme/tree.h +0
-0src/nvme/tree.h const char *nvme_ns_get_sysfs_dir(nvme_ns_t n); · line 460
Quoted 9 lines
src/nvme/tree.h +6
-0@@ -452,6 +452,14 @@ const char *nvme_ns_get_sysfs_dir(nvme_ns_t n);*/ const char *nvme_ns_get_name (nvme_ns_t n); +/** +* nvme_ns_get_access() - +* @n: +* +* Return: +*/ Wrong function documentation comment, you need to be more descriptive wht the function is doing...
Quoted 8 lines
Quoted 8 lines
src/nvme/tree.h +2
-1+const char *nvme_ns_get_access (nvme_ns_t n); +/** * nvme_ns_get_firmware() - * @n: -- 2.21.0.windows.1
Hi, Chaitanya
Thank you for your comments very much.
This patch is a prep patch, and the "nvme_ns_get_access" function is used in the next patch. In addition, I will resend patch V3 based on your comments.
_______________________________________________
Linux-nvme mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-nvme
PATCH v2 2/2 add "Path Access" entry in command output
In reply to chengjikeWhen users run commands such as nvme list, nvme list -o json, nvme list -v -o json, the "Path Access" entry of each disk is displayed.
--- nvme-print.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-)
nvme-print.c +9 -6
@@ -5649,10 +5649,10 @@ static void nvme_show_list_item(nvme_ns_t n)snprintf (format,sizeof (format),"%3.0f %2sB + %2d B" , (double )lba, l_suffix,nvme_ns_get_meta_size (n)); -printf ("%-21s %-20s %-40s %-9d %-26s %-16s %-8s\n" , +printf ("%-21s %-20s %-40s %-9d %-26s %-16s %-8s %-12s\n" ,nvme_ns_get_name (n),nvme_ns_get_serial (n),nvme_ns_get_model (n),nvme_ns_get_nsid (n), usage, format, -nvme_ns_get_firmware (n)); +nvme_ns_get_firmware (n),nvme_ns_get_access (n)); }static void nvme_show_simple_list (nvme_root_t r)
@@ -5662,10 +5662,10 @@ static void nvme_show_simple_list(nvme_root_t r)nvme_ctrl_t c;nvme_ns_t n; -printf ("%-21s %-20s %-40s %-9s %-26s %-16s %-8s\n" , -"Node" ,"SN" ,"Model" ,"Namespace" ,"Usage" ,"Format" ,"FW Rev" ); -printf ("%-.21s %-.20s %-.40s %-.9s %-.26s %-.16s %-.8s\n" , dash, dash, - dash, dash, dash, dash, dash); +printf ("%-21s %-20s %-40s %-9s %-26s %-16s %-8s %-12s\n" , +"Node" ,"SN" ,"Model" ,"Namespace" ,"Usage" ,"Format" ,"FW Rev" ,"Path Access" ); +printf ("%-.21s %-.20s %-.40s %-.9s %-.26s %-.16s %-.8s %-.12s\n" , dash, dash, + dash, dash, dash, dash, dash, dash);nvme_for_each_host (r, h) {nvme_for_each_subsystem (h, s) {
@@ -5841,6 +5841,7 @@ static void json_detail_list(nvme_root_t r)json_object_add_value_int (jns,"maxlba" ,nvme_ns_get_lba_count (n));json_object_add_value_int (jns,"capacity" , nsze);json_object_add_value_int (jns,"sector" , lba); +json_object_add_value_string (jns,"path access" ,nvme_ns_get_access (n));json_array_add_value_object (jnss, jns); }
@@ -5873,6 +5874,7 @@ static void json_detail_list(nvme_root_t r)json_object_add_value_int (jns,"maxlba" ,nvme_ns_get_lba_count (n));json_object_add_value_int (jns,"capacity" , nsze);json_object_add_value_int (jns,"sector" , lba); +json_object_add_value_string (jns,"path access" ,nvme_ns_get_access (n));json_array_add_value_object (jnss, jns); }
@@ -5907,6 +5909,7 @@ static struct json_object *json_list_item(nvme_ns_t n)json_object_add_value_int (jdevice,"maxlba" ,nvme_ns_get_lba_count (n));json_object_add_value_int (jdevice,"capacity" , nsze);json_object_add_value_int (jdevice,"sector" , lba); +json_object_add_value_string (jdevice,"path access" ,nvme_ns_get_access (n));return jdevice; }
Signature · 7 lines
2.21.0.windows.1 _______________________________________________ Linux-nvme mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-nvme