ndctl/dimm: Fix to dump namespace indexs and labels
PATCH 1/1 ndctl/dimm: Fix to dump namespace indexs and labels
The following bug is caused by setting the size of Label Index Block to a fixed 256 bytes.
Use the following Qemu command to start a Guest with 2MB label-size:
-object memory-backend-file,id=mem1,share=on,mem-path=/dev/dax1.1,size=14G,align=2M -device nvdimm,memdev=mem1,id=nv1,label-size=2M
There is a namespace in the Guest as follows:
$ ndctl list
[
{
"dev":"namespace0.0",
"mode":"devdax",
"map":"dev",
"size":14780727296,
"uuid":"58ad5282-5a16-404f-b8ee-e28b4c784eb8",
"chardev":"dax0.0",
"align":2097152,
"name":"namespace0.0"
}
]Fail to read labels. The result is as follows:
$ ndctl read-labels -u nmem0 [ ] read 0 nmem
If using the following Qemu command to start the Guest with 128K label-size, this label can be read correctly.
-object memory-backend-file,id=mem1,share=on,mem-path=/dev/dax1.1,size=14G,align=2M -device nvdimm,memdev=mem1,id=nv1,label-size=128K
The size of a Label Index Block depends on how many label slots fit into the label storage area. The minimum size of an index block is 256 bytes and the size must be a multiple of 256 bytes. For a storage area of 128KB, the corresponding Label Index Block size is 256 bytes. But if the label storage area is not 128KB, the Label Index Block size should not be 256 bytes.
Namespace Label Index Block appears twice at the top of the label storage area. Following the two index blocks, an array for storing labels takes up the remainder of the label storage area.
For obtaining the size of Namespace Index Block, we also cannot rely on the field of 'mysize' in this index block since it might be corrupted. Similar to the linux kernel, we use sizeof_namespace_index() to get the size of Namespace Index Block. Then we can also correctly calculate the starting offset of the following namespace labels.
--- ndctl/dimm.c | 19 +++++++++++++++---- ndctl/lib/dimm.c | 5 +++++ ndctl/lib/libndctl.sym | 1 + ndctl/libndctl.h | 1 + 4 files changed, 22 insertions(+), 4 deletions(-)
ndctl/dimm.c +15 -4
@@ -94,13 +94,18 @@ static struct json_object *dump_label_json(struct ndctl_dimm *dimm,struct json_object *jarray =json_object_new_array ();struct json_object *jlabel =NULL ;struct namespace_label nslabel; +unsigned int nsindex_size;unsigned int slot =-1 ;ssize_t offset;if (!jarray)return NULL ; -for (offset =NSINDEX_ALIGN *2 ; offset < size; + nsindex_size =ndctl_dimm_sizeof_namespace_index (dimm); +if (nsindex_size ==0 ) +return NULL ; + +for (offset = nsindex_size *2 ; offset < size; offset +=ndctl_dimm_sizeof_namespace_label (dimm)) { ssize_t len = min_t(ssize_t, ndctl_dimm_sizeof_namespace_label(dimm),
@@ -204,17 +209,23 @@ static struct json_object *dump_label_json(struct ndctl_dimm *dimm,return jarray; } -static struct json_object *dump_index_json (struct ndctl_cmd *cmd_read,ssize_t size) +static struct json_object *dump_index_json (struct ndctl_dimm *dimm, +struct ndctl_cmd *cmd_read,ssize_t size) {struct json_object *jarray =json_object_new_array ();struct json_object *jindex =NULL ;struct namespace_index nsindex; +unsigned int nsindex_size;ssize_t offset;if (!jarray)return NULL ; -for (offset =0 ; offset <NSINDEX_ALIGN *2 ; offset +=NSINDEX_ALIGN ) { + nsindex_size =ndctl_dimm_sizeof_namespace_index (dimm); +if (nsindex_size ==0 ) +return NULL ; + +for (offset =0 ; offset < nsindex_size *2 ; offset += nsindex_size) {ssize_t len =min_t (ssize_t,sizeof (nsindex), size - offset);struct json_object *jobj;
@@ -288,7 +299,7 @@ static struct json_object *dump_json(struct ndctl_dimm *dimm, goto err;json_object_object_add (jdimm,"dev" , jobj); - jindex =dump_index_json (cmd_read, size); + jindex =dump_index_json (dimm, cmd_read, size);if (!jindex) goto err;json_object_object_add (jdimm,"index" , jindex);
ndctl/lib/dimm.c +5 -0
@@ -256,6 +256,11 @@ static int __label_validate(struct nvdimm_data *ndd)return -EINVAL ; } +NDCTL_EXPORT unsigned int ndctl_dimm_sizeof_namespace_index(struct ndctl_dimm *dimm) +{ +return sizeof_namespace_index (&dimm->ndd); +} +/* * If the dimm labels have not been previously validated this routine * will make up a default size. Otherwise, it will pick the size based
ndctl/lib/libndctl.sym +1 -0
@@ -290,6 +290,7 @@ global: ndctl_dimm_validate_labels; ndctl_dimm_init_labels; ndctl_dimm_sizeof_namespace_label; + ndctl_dimm_sizeof_namespace_index; ndctl_mapping_get_position; ndctl_namespace_set_enforce_mode; ndctl_namespace_get_enforce_mode;
ndctl/libndctl.h +1 -0
@@ -335,6 +335,7 @@ int ndctl_dimm_init_labels(struct ndctl_dimm *dimm, enum ndctl_namespace_version v);unsigned long ndctl_dimm_get_available_labels (struct ndctl_dimm *dimm);unsigned int ndctl_dimm_sizeof_namespace_label (struct ndctl_dimm *dimm); +unsigned int ndctl_dimm_sizeof_namespace_index (struct ndctl_dimm *dimm);unsigned int ndctl_cmd_cfg_size_get_size (struct ndctl_cmd *cfg_size);ssize_t ndctl_cmd_cfg_read_get_data (struct ndctl_cmd *cfg_read,void *buf,unsigned int len,unsigned int offset);
Signature · 1 line
2.21.3
Hi Dan,
This is the second version of the patch.
Any comments?
Thanks,
Jingqi
Quoted 158 lines · Jingqi
The following bug is caused by setting the size of Label Index Block to a fixed 256 bytes.
Use the following Qemu command to start a Guest with 2MB label-size:
-object memory-backend-file,id=mem1,share=on,mem-path=/dev/dax1.1,size=14G,align=2M -device nvdimm,memdev=mem1,id=nv1,label-size=2MThere is a namespace in the Guest as follows:
$ ndctl list [ { "dev":"namespace0.0", "mode":"devdax", "map":"dev", "size":14780727296, "uuid":"58ad5282-5a16-404f-b8ee-e28b4c784eb8", "chardev":"dax0.0", "align":2097152, "name":"namespace0.0" } ]Fail to read labels. The result is as follows:
$ ndctl read-labels -u nmem0 [ ] read 0 nmemIf using the following Qemu command to start the Guest with 128K label-size, this label can be read correctly.
-object memory-backend-file,id=mem1,share=on,mem-path=/dev/dax1.1,size=14G,align=2M -device nvdimm,memdev=mem1,id=nv1,label-size=128KThe size of a Label Index Block depends on how many label slots fit into the label storage area. The minimum size of an index block is 256 bytes and the size must be a multiple of 256 bytes. For a storage area of 128KB, the corresponding Label Index Block size is 256 bytes. But if the label storage area is not 128KB, the Label Index Block size should not be 256 bytes.
Namespace Label Index Block appears twice at the top of the label storage area. Following the two index blocks, an array for storing labels takes up the remainder of the label storage area.
For obtaining the size of Namespace Index Block, we also cannot rely on the field of 'mysize' in this index block since it might be corrupted. Similar to the linux kernel, we use
sizeof_namespace_index()to get the size of Namespace Index Block. Then we can also correctly calculate the starting offset of the following namespace labels.Suggested-by Dan Williams <[email protected]>Signed-off-by Jingqi Liu <[email protected]>--- ndctl/dimm.c | 19 +++++++++++++++---- ndctl/lib/dimm.c | 5 +++++ ndctl/lib/libndctl.sym | 1 + ndctl/libndctl.h | 1 + 4 files changed, 22 insertions(+), 4 deletions(-)ndctl/dimm.c +15
-4@@ -94,13 +94,18 @@ static struct json_object *dump_label_json(struct ndctl_dimm *dimm,struct json_object *jarray =json_object_new_array ();struct json_object *jlabel =NULL ;struct namespace_label nslabel; +unsigned int nsindex_size;unsigned int slot =-1 ;ssize_t offset;if (!jarray)return NULL ; -for (offset =NSINDEX_ALIGN *2 ; offset < size; + nsindex_size =ndctl_dimm_sizeof_namespace_index (dimm); +if (nsindex_size ==0 ) +return NULL ; + +for (offset = nsindex_size *2 ; offset < size; offset +=ndctl_dimm_sizeof_namespace_label (dimm)) { ssize_t len = min_t(ssize_t, ndctl_dimm_sizeof_namespace_label(dimm),@@ -204,17 +209,23 @@ static struct json_object *dump_label_json(struct ndctl_dimm *dimm,return jarray; } -static struct json_object *dump_index_json (struct ndctl_cmd *cmd_read,ssize_t size) +static struct json_object *dump_index_json (struct ndctl_dimm *dimm, +struct ndctl_cmd *cmd_read,ssize_t size) {struct json_object *jarray =json_object_new_array ();struct json_object *jindex =NULL ;struct namespace_index nsindex; +unsigned int nsindex_size;ssize_t offset;if (!jarray)return NULL ; -for (offset =0 ; offset <NSINDEX_ALIGN *2 ; offset +=NSINDEX_ALIGN ) { + nsindex_size =ndctl_dimm_sizeof_namespace_index (dimm); +if (nsindex_size ==0 ) +return NULL ; + +for (offset =0 ; offset < nsindex_size *2 ; offset += nsindex_size) {ssize_t len =min_t (ssize_t,sizeof (nsindex), size - offset);struct json_object *jobj;@@ -288,7 +299,7 @@ static struct json_object *dump_json(struct ndctl_dimm *dimm, goto err;json_object_object_add (jdimm,"dev" , jobj); - jindex =dump_index_json (cmd_read, size); + jindex =dump_index_json (dimm, cmd_read, size);if (!jindex) goto err;json_object_object_add (jdimm,"index" , jindex);ndctl/lib/dimm.c +5
-0@@ -256,6 +256,11 @@ static int __label_validate(struct nvdimm_data *ndd)return -EINVAL ; } +NDCTL_EXPORT unsigned int ndctl_dimm_sizeof_namespace_index(struct ndctl_dimm *dimm) +{ +return sizeof_namespace_index (&dimm->ndd); +} +/* * If the dimm labels have not been previously validated this routine * will make up a default size. Otherwise, it will pick the size based ndctl/lib/libndctl.sym +1
-0@@ -290,6 +290,7 @@ global: ndctl_dimm_validate_labels; ndctl_dimm_init_labels; ndctl_dimm_sizeof_namespace_label; + ndctl_dimm_sizeof_namespace_index; ndctl_mapping_get_position; ndctl_namespace_set_enforce_mode; ndctl_namespace_get_enforce_mode;ndctl/libndctl.h +1
-0@@ -335,6 +335,7 @@ int ndctl_dimm_init_labels(struct ndctl_dimm *dimm, enum ndctl_namespace_version v);unsigned long ndctl_dimm_get_available_labels (struct ndctl_dimm *dimm);unsigned int ndctl_dimm_sizeof_namespace_label (struct ndctl_dimm *dimm); +unsigned int ndctl_dimm_sizeof_namespace_index (struct ndctl_dimm *dimm);unsigned int ndctl_cmd_cfg_size_get_size (struct ndctl_cmd *cfg_size);ssize_t ndctl_cmd_cfg_read_get_data (struct ndctl_cmd *cfg_read,void *buf,unsigned int len,unsigned int offset);
[ add Vishal ]
Quoted 44 lines · Jingqi Liu
The following bug is caused by setting the size of Label Index Block to a fixed 256 bytes.
Use the following Qemu command to start a Guest with 2MB label-size:
-object memory-backend-file,id=mem1,share=on,mem-path=/dev/dax1.1,size=14G,align=2M -device nvdimm,memdev=mem1,id=nv1,label-size=2MThere is a namespace in the Guest as follows:
$ ndctl list [ { "dev":"namespace0.0", "mode":"devdax", "map":"dev", "size":14780727296, "uuid":"58ad5282-5a16-404f-b8ee-e28b4c784eb8", "chardev":"dax0.0", "align":2097152, "name":"namespace0.0" } ]Fail to read labels. The result is as follows:
$ ndctl read-labels -u nmem0 [ ] read 0 nmemIf using the following Qemu command to start the Guest with 128K label-size, this label can be read correctly.
-object memory-backend-file,id=mem1,share=on,mem-path=/dev/dax1.1,size=14G,align=2M -device nvdimm,memdev=mem1,id=nv1,label-size=128KThe size of a Label Index Block depends on how many label slots fit into the label storage area. The minimum size of an index block is 256 bytes and the size must be a multiple of 256 bytes. For a storage area of 128KB, the corresponding Label Index Block size is 256 bytes. But if the label storage area is not 128KB, the Label Index Block size should not be 256 bytes.
Namespace Label Index Block appears twice at the top of the label storage area. Following the two index blocks, an array for storing labels takes up the remainder of the label storage area.
Quoted 8 lines
For obtaining the size of Namespace Index Block, we also cannot rely on the field of 'mysize' in this index block since it might be corrupted. Similar to the linux kernel, we use
sizeof_namespace_index()to get the size of Namespace Index Block. Then we can also correctly calculate the starting offset of the following namespace labels.Suggested-by Dan Williams <[email protected]>Signed-off-by Jingqi Liu <[email protected]>
Apologies for the delay in responding, this looks good and passes my tests:
Verma, Vishal L
maintainerQuoted 49 lines · Jingqi Liu
The following bug is caused by setting the size of Label Index Block to a fixed 256 bytes.
Use the following Qemu command to start a Guest with 2MB label-size:
-object memory-backend-file,id=mem1,share=on,mem-path=/dev/dax1.1,size=14G,align=2M -device nvdimm,memdev=mem1,id=nv1,label-size=2MThere is a namespace in the Guest as follows:
$ ndctl list [ { "dev":"namespace0.0", "mode":"devdax", "map":"dev", "size":14780727296, "uuid":"58ad5282-5a16-404f-b8ee-e28b4c784eb8", "chardev":"dax0.0", "align":2097152, "name":"namespace0.0" } ]Fail to read labels. The result is as follows:
$ ndctl read-labels -u nmem0 [ ] read 0 nmemIf using the following Qemu command to start the Guest with 128K label-size, this label can be read correctly.
-object memory-backend-file,id=mem1,share=on,mem-path=/dev/dax1.1,size=14G,align=2M -device nvdimm,memdev=mem1,id=nv1,label-size=128KThe size of a Label Index Block depends on how many label slots fit into the label storage area. The minimum size of an index block is 256 bytes and the size must be a multiple of 256 bytes. For a storage area of 128KB, the corresponding Label Index Block size is 256 bytes. But if the label storage area is not 128KB, the Label Index Block size should not be 256 bytes.
Namespace Label Index Block appears twice at the top of the label storage area. Following the two index blocks, an array for storing labels takes up the remainder of the label storage area.
For obtaining the size of Namespace Index Block, we also cannot rely on the field of 'mysize' in this index block since it might be corrupted. Similar to the linux kernel, we use
sizeof_namespace_index()to get the size of Namespace Index Block. Then we can also correctly calculate the starting offset of the following namespace labels.
Quoted 8 lines
Suggested-by Dan Williams <[email protected]>Signed-off-by Jingqi Liu <[email protected]>--- ndctl/dimm.c | 19 +++++++++++++++---- ndctl/lib/dimm.c | 5 +++++ ndctl/lib/libndctl.sym | 1 + ndctl/libndctl.h | 1 + 4 files changed, 22 insertions(+), 4 deletions(-)
Hi Jingqi,
This looks fine, one comment below.
[..]
ndctl/lib/libndctl.sym global: · line 293
Quoted 10 lines
ndctl/lib/libndctl.sym +1
-0@@ -290,6 +290,7 @@ global: ndctl_dimm_validate_labels; ndctl_dimm_init_labels; ndctl_dimm_sizeof_namespace_label; + ndctl_dimm_sizeof_namespace_index;
This can't go into an 'old' section of the symbol version script - if you base off the current 'pending' branch, you should see a LIBNDCTL_26 section at the bottom. You can add this there.
Quoted 15 lines
ndctl/lib/libndctl.sym +0
-0ndctl_mapping_get_position; ndctl_namespace_set_enforce_mode; ndctl_namespace_get_enforce_mode;ndctl/libndctl.h +1
-0@@ -335,6 +335,7 @@ int ndctl_dimm_init_labels(struct ndctl_dimm *dimm, enum ndctl_namespace_version v);unsigned long ndctl_dimm_get_available_labels (struct ndctl_dimm *dimm);unsigned int ndctl_dimm_sizeof_namespace_label (struct ndctl_dimm *dimm); +unsigned int ndctl_dimm_sizeof_namespace_index (struct ndctl_dimm *dimm);unsigned int ndctl_cmd_cfg_size_get_size (struct ndctl_cmd *cfg_size);ssize_t ndctl_cmd_cfg_read_get_data (struct ndctl_cmd *cfg_read,void *buf,unsigned int len,unsigned int offset);
Hi Vishal,
Thanks for your comments.
Quoted 65 lines · Vishal L
Quoted 49 lines · Jingqi Liu
The following bug is caused by setting the size of Label Index Block to a fixed 256 bytes.
Use the following Qemu command to start a Guest with 2MB label-size:
-object memory-backend-file,id=mem1,share=on,mem-path=/dev/dax1.1,size=14G,align=2M -device nvdimm,memdev=mem1,id=nv1,label-size=2MThere is a namespace in the Guest as follows:
$ ndctl list [ { "dev":"namespace0.0", "mode":"devdax", "map":"dev", "size":14780727296, "uuid":"58ad5282-5a16-404f-b8ee-e28b4c784eb8", "chardev":"dax0.0", "align":2097152, "name":"namespace0.0" } ]Fail to read labels. The result is as follows:
$ ndctl read-labels -u nmem0 [ ] read 0 nmemIf using the following Qemu command to start the Guest with 128K label-size, this label can be read correctly.
-object memory-backend-file,id=mem1,share=on,mem-path=/dev/dax1.1,size=14G,align=2M -device nvdimm,memdev=mem1,id=nv1,label-size=128KThe size of a Label Index Block depends on how many label slots fit into the label storage area. The minimum size of an index block is 256 bytes and the size must be a multiple of 256 bytes. For a storage area of 128KB, the corresponding Label Index Block size is 256 bytes. But if the label storage area is not 128KB, the Label Index Block size should not be 256 bytes.
Namespace Label Index Block appears twice at the top of the label storage area. Following the two index blocks, an array for storing labels takes up the remainder of the label storage area.
For obtaining the size of Namespace Index Block, we also cannot rely on the field of 'mysize' in this index block since it might be corrupted. Similar to the linux kernel, we use
sizeof_namespace_index()to get the size of Namespace Index Block. Then we can also correctly calculate the starting offset of the following namespace labels.Quoted 8 lines
Suggested-by Dan Williams <[email protected]>Signed-off-by Jingqi Liu <[email protected]>--- ndctl/dimm.c | 19 +++++++++++++++---- ndctl/lib/dimm.c | 5 +++++ ndctl/lib/libndctl.sym | 1 + ndctl/libndctl.h | 1 + 4 files changed, 22 insertions(+), 4 deletions(-)Hi Jingqi,
This looks fine, one comment below.
[..]
Quoted 1 line
Quoted 13 lines
ndctl/lib/libndctl.sym global: · line 293
Quoted 9 lines
ndctl/lib/libndctl.sym +1
-0@@ -290,6 +290,7 @@ global: ndctl_dimm_validate_labels; ndctl_dimm_init_labels; ndctl_dimm_sizeof_namespace_label; + ndctl_dimm_sizeof_namespace_index;This can't go into an 'old' section of the symbol version script - if you base off the current 'pending' branch, you should see a
LIBNDCTL_26section at the bottom. You can add this there.
It's based on the current 'master' branch.
I don't see a LIBNDCTL_26 section, just 'LIBNDCTL_25'.
How about adding 'ndctl_dimm_sizeof_namespace_index' to LIBNDCTL_25 section ?
Thanks,
Jingqi
Verma, Vishal L
maintainerQuoted 17 lines · Jingqi
Quoted 16 lines
[..]
ndctl/lib/libndctl.sym global: · line 293
Quoted 10 lines
ndctl/lib/libndctl.sym +1
-0@@ -290,6 +290,7 @@ global: ndctl_dimm_validate_labels; ndctl_dimm_init_labels; ndctl_dimm_sizeof_namespace_label; + ndctl_dimm_sizeof_namespace_index;This can't go into an 'old' section of the symbol version script - if you base off the current 'pending' branch, you should see a
LIBNDCTL_26section at the bottom. You can add this there.
Quoted 5 lines
It's based on the current 'master' branch.
I don't see aLIBNDCTL_26section, just 'LIBNDCTL_25'. How about adding 'ndctl_dimm_sizeof_namespace_index' toLIBNDCTL_25section ?
No - so once a release happens, that section is 'closed' forever. The master branch coincides with the v71 release. That release had added new symbols in the LIBNDCTL_25 section, and that section is now done. New symbols after v71 need to go in a new section, LIBNDCTL_26.
The pending branch just happens to have patches that added a new symbol, so the new section is already created for you - so if you rebase to pending, you can just reuse that. Alternatively, base off master, and create a new LIBNDCTL_26 section, and I'll fix up the trivial conflict when merging.
Hope this clarifies things a bit!
Thanks,
-Vishal
Quoted 28 lines · Vishal L
Quoted 17 lines · Jingqi
Quoted 16 lines
[..]
ndctl/lib/libndctl.sym global: · line 293
Quoted 10 lines
ndctl/lib/libndctl.sym +1
-0@@ -290,6 +290,7 @@ global: ndctl_dimm_validate_labels; ndctl_dimm_init_labels; ndctl_dimm_sizeof_namespace_label; + ndctl_dimm_sizeof_namespace_index;This can't go into an 'old' section of the symbol version script - if you base off the current 'pending' branch, you should see a
LIBNDCTL_26section at the bottom. You can add this there.Quoted 5 lines
It's based on the current 'master' branch.
I don't see aLIBNDCTL_26section, just 'LIBNDCTL_25'. How about adding 'ndctl_dimm_sizeof_namespace_index' toLIBNDCTL_25section ?No - so once a release happens, that section is 'closed' forever. The master branch coincides with the v71 release. That release had added new symbols in the
LIBNDCTL_25section, and that section is now done. New symbols after v71 need to go in a new section,LIBNDCTL_26.
Quoted 7 lines
The pending branch just happens to have patches that added a new symbol, so the new section is already created for you - so if you rebase to pending, you can just reuse that. Alternatively, base off master, and create a new
LIBNDCTL_26section, and I'll fix up the trivial conflict when merging.Hope this clarifies things a bit!
Got it.
Thanks your clarification.
The other modifications of this patch are based on the master branch. So for this file, I'll base off master.
Thank you for fixing up the conflict when merging.
Thanks,
Jingqi
Quoted 4 lines
Thanks,
-Vishal