updates for v52
Subsystems (4)
cover updates for v52
1/ Add new apis for retrieving the resource base address and the
effective capacity for pmem namespaces in 'raw' or 'memory' mode.
2/ Add a -t option to 'ndctl list' to filter based on 'pmem' or 'blk'
region types.
3/ Add a unit test for the new 'clear poison' functionality targeting
the 4.6 kernel.
4/ Miscellaneous updates and fixlets
---
Dan Williams (8):
ndctl: make --enable-local the default
ndctl: ndctl_{namespace|pfn}_get_resource
ndctl: refresh dynamic pfn attributes from a duplicate
ndctl: use the pfn trimmed size for memory mode namespaces ndctl create-namespace: fall back to blk if no pmem
ndctl: make test/dax-dev more robust
ndctl: add filter-by-type to the 'list' command
ndctl: test clear poison
Documentation/ndctl-list.txt | 4 ++ Makefile.am | 3 +- builtin-list.c | 21 +++++++++++++ builtin-xaction-namespace.c | 68 ++++++++++++++++++++++++++++++++---------- configure.ac | 4 +- lib/libndctl.c | 38 +++++++++++++++++++++++ lib/libndctl.sym | 3 ++ lib/ndctl/libndctl.h | 3 ++ test/clear.sh | 67 +++++++++++++++++++++++++++++++++++++++++ test/dax-dev.c | 7 ++++ util/json.c | 24 +++++++++++---- 11 files changed, 213 insertions(+), 29 deletions(-) create mode 100755 test/clear.sh
_______________________________________________
Linux-nvdimm mailing list
[email protected]
https://lists.01.org/mailman/listinfo/linux-nvdimm
PATCH 1/8 ndctl: make --enable-local the default
Using the kernel provided header is only useful when you want to de-feature ndctl at compile-time. Otherwise, ndctl is responsible for failing gracefully when it finds it is running against an older kernel that is missing newer capabilities. The kernel is responsible for making sure that old ndctl binaries continue to operate on newer kernels.
--- configure.ac | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
configure.ac +2 -2
@@ -85,8 +85,8 @@ PKG_CHECK_MODULES([UUID], [uuid]) PKG_CHECK_MODULES([JSON], [json-c]) AC_ARG_ENABLE([local], - AS_HELP_STRING([--enable-local], [build with local ndctl.h @<:@default=system@:>@]), - [], [enable_local=no]) + AS_HELP_STRING([--disable-local], [build against kernel ndctl.h @<:@default=system@:>@]), + [], [enable_local=yes]) AS_IF([test "x$enable_local" = "xyes"], [], [ AC_CHECK_HEADER([linux/ndctl.h], [
_______________________________________________
Linux-nvdimm mailing list
[email protected]
https://lists.01.org/mailman/listinfo/linux-nvdimm
PATCH 2/8 ndctl: ndctl_{namespace|pfn}_get_resource
In reply to Dan WilliamsRetrieve the physical address corresponding to sector-0 of a pmem device. Note that ndctl_pfn_get_resource() is only valid while the given pfn instance is enabled.
--- lib/libndctl.c | 36 +++++++++++++++++++++++++++++++++++- lib/libndctl.sym | 3 +++ lib/ndctl/libndctl.h | 3 +++ 3 files changed, 41 insertions(+), 1 deletion(-)
lib/libndctl.c +35 -1
@@ -246,7 +246,7 @@ struct ndctl_namespace {char *bdev;int type, id, buf_len, raw_mode;int generation; -unsigned long long size; +unsigned long long resource, size;char *alt_name;uuid_t uuid;struct ndctl_lbasize lbasize;
@@ -297,6 +297,7 @@ struct ndctl_pfn {struct list_node list;enum ndctl_pfn_loc loc;unsigned long align; +unsigned long long resource, size;char *pfn_path;char *pfn_buf;char *bdev;
@@ -2669,6 +2670,12 @@ static int add_namespace(void *parent, int id, const char *ndns_base) goto err_read; ndns->size =strtoull (buf,NULL ,0 ); +sprintf (path,"%s/resource" , ndns_base); +if (sysfs_read_attr (ctx, path, buf) <0 ) + ndns->resource =ULLONG_MAX ; +else + ndns->resource =strtoull (buf,NULL ,0 ); +sprintf (path,"%s/force_raw" , ndns_base);if (sysfs_read_attr (ctx, path, buf) <0 ) goto err_read;
@@ -3312,6 +3319,11 @@ NDCTL_EXPORT unsigned long long ndctl_namespace_get_size(struct ndctl_namespacereturn ndns->size; } +NDCTL_EXPORT unsigned long long ndctl_namespace_get_resource (struct ndctl_namespace *ndns) +{ +return ndns->resource; +} +static int namespace_set_size (struct ndctl_namespace *ndns,unsigned long long size) {
@@ -3853,6 +3865,18 @@ static int add_pfn(void *parent, int id, const char *pfn_base)else pfn->align =strtoul (buf,NULL ,0 ); +sprintf (path,"%s/resource" , pfn_base); +if (sysfs_read_attr (ctx, path, buf) <0 ) + pfn->resource =ULLONG_MAX ; +else + pfn->resource =strtoull (buf,NULL ,0 ); + +sprintf (path,"%s/size" , pfn_base); +if (sysfs_read_attr (ctx, path, buf) <0 ) + pfn->size =ULLONG_MAX ; +else + pfn->size =strtoull (buf,NULL ,0 ); +free (path); ndctl_pfn_foreach(region, pfn_dup)if (pfn->id == pfn_dup->id) {
@@ -3924,6 +3948,16 @@ NDCTL_EXPORT void ndctl_pfn_get_uuid(struct ndctl_pfn *pfn, uuid_t uu)memcpy (uu, pfn->uuid,sizeof (uuid_t)); } +NDCTL_EXPORT unsigned long long ndctl_pfn_get_size (struct ndctl_pfn *pfn) +{ +return pfn->size; +} + +NDCTL_EXPORT unsigned long long ndctl_pfn_get_resource (struct ndctl_pfn *pfn) +{ +return pfn->resource; +} + NDCTL_EXPORT int ndctl_pfn_set_uuid(struct ndctl_pfn *pfn, uuid_t uu) {struct ndctl_ctx *ctx =ndctl_pfn_get_ctx (pfn);
lib/libndctl.sym +3 -0
@@ -149,6 +149,7 @@ global: ndctl_namespace_set_alt_name; ndctl_namespace_get_size; ndctl_namespace_set_size; + ndctl_namespace_get_resource; ndctl_namespace_get_supported_sector_size; ndctl_namespace_get_sector_size; ndctl_namespace_get_num_sector_sizes;
@@ -197,6 +198,8 @@ global: ndctl_pfn_get_location; ndctl_pfn_set_location; ndctl_pfn_get_align; + ndctl_pfn_get_size; + ndctl_pfn_get_resource; ndctl_pfn_set_align; ndctl_pfn_set_namespace; ndctl_pfn_get_bus;
lib/ndctl/libndctl.h +3 -0
@@ -353,6 +353,7 @@ const char *ndctl_namespace_get_alt_name(struct ndctl_namespace *ndns);int ndctl_namespace_set_alt_name (struct ndctl_namespace *ndns,const char *alt_name);unsigned long long ndctl_namespace_get_size (struct ndctl_namespace *ndns); +unsigned long long ndctl_namespace_get_resource (struct ndctl_namespace *ndns);int ndctl_namespace_set_size (struct ndctl_namespace *ndns,unsigned long long size); unsigned int ndctl_namespace_get_supported_sector_size(
@@ -430,6 +431,8 @@ int ndctl_pfn_set_uuid(struct ndctl_pfn *pfn, uuid_t uu);void ndctl_pfn_get_uuid (struct ndctl_pfn *pfn,uuid_t uu);int ndctl_pfn_set_align (struct ndctl_pfn *pfn,unsigned long align);unsigned long ndctl_pfn_get_align (struct ndctl_pfn *pfn); +unsigned long long ndctl_pfn_get_resource (struct ndctl_pfn *pfn); +unsigned long long ndctl_pfn_get_size (struct ndctl_pfn *pfn);int ndctl_pfn_set_namespace (struct ndctl_pfn *pfn,struct ndctl_namespace *ndns);struct ndctl_namespace *ndctl_pfn_get_namespace (struct ndctl_pfn *pfn);int ndctl_pfn_enable (struct ndctl_pfn *pfn);
_______________________________________________
Linux-nvdimm mailing list
[email protected]
https://lists.01.org/mailman/listinfo/linux-nvdimm
PATCH 3/8 ndctl: refresh dynamic pfn attributes from a duplicate
In reply to Dan WilliamsWhen we find a duplicate of an existing ndctl_pfn instance in add_pfn, it may have a more up to date value of the 'size' or 'resource' because those values are only valid while the instance is active. Copy those updates over before throwing away the duplicate.
--- lib/libndctl.c | 2 ++ 1 file changed, 2 insertions(+)
lib/libndctl.c +2 -0
@@ -3880,6 +3880,8 @@ static int add_pfn(void *parent, int id, const char *pfn_base)free (path); ndctl_pfn_foreach(region, pfn_dup)if (pfn->id == pfn_dup->id) { + pfn_dup->resource = pfn->resource; + pfn_dup->size = pfn->size;free_pfn (pfn,NULL );return 1 ; }
_______________________________________________
Linux-nvdimm mailing list
[email protected]
https://lists.01.org/mailman/listinfo/linux-nvdimm
PATCH 4/8 ndctl: use the pfn trimmed size for memory mode namespaces
In reply to Dan WilliamsIf the kernel reports the size of the namespace after the memmap allocation is removed use that value, otherwise don't emit raw namespace size since it is not accurate.
For the btt case, the effective size is further constrained by the sector geometry, so userspace should just use the block device size. Otherwise, the size and base address of the namespace is useful for hypervisors that want to establish their own host-physical-address mappings for a guest to consume.
--- util/json.c | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-)
util/json.c +17 -7
@@ -1,3 +1,4 @@ +#include <limits.h> #include <util/json.h> #include <uuid/uuid.h> #include <json-c/json.h>
@@ -76,6 +77,8 @@ bool util_namespace_active(struct ndctl_namespace *ndns)struct json_object *util_namespace_to_json (struct ndctl_namespace *ndns) {struct json_object *jndns =json_object_new_object (); +unsigned long long size =ULLONG_MAX ; +enum ndctl_namespace_mode mode;struct json_object *jobj;const char *bdev =NULL ;struct ndctl_btt *btt;
@@ -91,14 +94,22 @@ struct json_object *util_namespace_to_json(struct ndctl_namespace *ndns) goto err;json_object_object_add (jndns,"dev" , jobj); -switch (ndctl_namespace_get_mode (ndns)) { + btt =ndctl_namespace_get_btt (ndns); + pfn =ndctl_namespace_get_pfn (ndns); + mode =ndctl_namespace_get_mode (ndns); +switch (mode) {case NDCTL_NS_MODE_MEMORY : +if (pfn)/* dynamic memory mode */ + size =ndctl_pfn_get_size (pfn); +else /* native/static memory mode */ + size =ndctl_namespace_get_size (ndns); jobj =json_object_new_string ("memory" );break ;case NDCTL_NS_MODE_SAFE : jobj =json_object_new_string ("sector" );break ;case NDCTL_NS_MODE_RAW : + size =ndctl_namespace_get_size (ndns); jobj =json_object_new_string ("raw" );break ;default :
@@ -107,13 +118,12 @@ struct json_object *util_namespace_to_json(struct ndctl_namespace *ndns)if (jobj)json_object_object_add (jndns,"mode" , jobj); - jobj =json_object_new_int64 (ndctl_namespace_get_size (ndns)); -if (!jobj) - goto err; -json_object_object_add (jndns,"size" , jobj); +if (size <ULLONG_MAX ) { + jobj =json_object_new_int64 (size); +if (jobj) +json_object_object_add (jndns,"size" , jobj); + } - btt =ndctl_namespace_get_btt (ndns); - pfn =ndctl_namespace_get_pfn (ndns);if (btt) {ndctl_btt_get_uuid (btt, uuid);uuid_unparse (uuid, buf);
_______________________________________________
Linux-nvdimm mailing list
[email protected]
https://lists.01.org/mailman/listinfo/linux-nvdimm
PATCH 5/8 ndctl create-namespace: fall back to blk if no pmem
In reply to Dan WilliamsArrange for ndctl create-namespace to search for blk capacity by default. This supports a use case of calling 'ndctl create-namespace' with no options until it returns an error to allocate all the persistent memory capacity in a system.
--- builtin-xaction-namespace.c | 68 ++++++++++++++++++++++++++++++++----------- 1 file changed, 51 insertions(+), 17 deletions(-)
builtin-xaction-namespace.c +51 -17
@@ -37,6 +37,7 @@static bool verbose;static bool force; static struct parameters { + bool do_scan; const char *bus; const char *map; const char *type;
@@ -109,21 +110,9 @@ enum namespace_action { ACTION_CREATE, }; -/* -* parse_namespace_options - basic parsing sanity checks before we start -* looking at actual namespace devices and available resources. -*/ -static const char *parse_namespace_options (int argc,const char **argv, -enum namespace_action mode,const struct option *options, -char *xable_usage) +static int set_defaults (void ) { -const char *const u[] = { - xable_usage, -NULL - }; -int i, rc =0 ; - - argc =parse_options (argc, argv, options, u,0 ); +int rc =0 ;if (param.type) {if (strcmp (param.type,"pmem" ) ==0 )
@@ -211,6 +200,28 @@ static const char *parse_namespace_options(int argc, const char **argv, }else if (!param.reconfig) param.sector_size ="4096" ; +return rc; +} + +/* +* parse_namespace_options - basic parsing sanity checks before we start +* looking at actual namespace devices and available resources. +*/ +static const char *parse_namespace_options (int argc,const char **argv, +enum namespace_action mode,const struct option *options, +char *xable_usage) +{ +const char *const u[] = { + xable_usage, +NULL + }; +int i, rc =0 ; + + param.do_scan = argc ==1 ; + argc =parse_options (argc, argv, options, u,0 ); + + rc =set_defaults (); +if (argc ==0 && mode !=ACTION_CREATE ) {error ("specify a namespace to %s, or \"all\"\n" , mode ==ACTION_ENABLE ?"enable" :"disable" );
@@ -603,6 +614,8 @@ static int do_xaction_namespace(const char *namespace, rc =0 ;continue ; } +if (rc ==0 ) + rc =1 ; goto done; } ndctl_namespace_foreach(region, ndns) {
@@ -619,7 +632,11 @@ static int do_xaction_namespace(const char *namespace, rc =ndctl_namespace_enable (ndns);break ;case ACTION_CREATE : -return namespace_reconfig (region, ndns); + rc =namespace_reconfig (region, ndns); +if (rc <0 ) + goto done; + rc =1 ; + goto done; }if (rc >=0 ) success++;
@@ -682,8 +699,25 @@ int cmd_create_namespace(int argc, const char **argv) ACTION_CREATE, create_options, xable_usage);int created =do_xaction_namespace (namespace,ACTION_CREATE ); -if (created <0 ) +if (created <1 && param.do_scan) { +/* +* In the default scan case we try pmem first and then +* fallback to blk before giving up. +*/ +memset (¶m,0 ,sizeof (param)); + param.type ="blk" ; +set_defaults (); + created =do_xaction_namespace (NULL ,ACTION_CREATE ); + } + +if (created <0 || (!namespace && created <1 )) {fprintf (stderr,"failed to %s namespace\n" , namespace ?"reconfigure" :"create" ); -return created; +if (!namespace) + created = -ENODEV ; + } + +if (created <0 ) +return created; +return 0 ; }
_______________________________________________
Linux-nvdimm mailing list
[email protected]
https://lists.01.org/mailman/listinfo/linux-nvdimm
PATCH 6/8 ndctl: make test/dax-dev more robust
In reply to Dan WilliamsAccept a pfn-enabled configuration for the test device to make the test suite more reliable when restarting after a failure or forced termination.
--- test/dax-dev.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
test/dax-dev.c +6 -1
@@ -32,6 +32,7 @@ static int emit_e820_device(int loglevel, struct ndctl_test *test)const char *bdev;struct ndctl_ctx *ctx;struct ndctl_bus *bus; +struct ndctl_pfn *pfn;struct ndctl_region *region;struct ndctl_namespace *ndns;enum ndctl_namespace_mode mode;
@@ -61,7 +62,11 @@ static int emit_e820_device(int loglevel, struct ndctl_test *test)if (mode >=0 && mode !=NDCTL_NS_MODE_MEMORY ) goto out; - bdev =ndctl_namespace_get_block_device (ndns); + pfn =ndctl_namespace_get_pfn (ndns); +if (pfn) + bdev =ndctl_pfn_get_block_device (pfn); +else + bdev =ndctl_namespace_get_block_device (ndns);if (!bdev) goto out;
_______________________________________________
Linux-nvdimm mailing list
[email protected]
https://lists.01.org/mailman/listinfo/linux-nvdimm
PATCH 7/8 ndctl: add filter-by-type to the 'list' command
In reply to Dan WilliamsLimit region, and subsequently namespace, scanning by interface type ('pmem' or 'blk').
--- Documentation/ndctl-list.txt | 4 ++++ builtin-list.c | 21 +++++++++++++++++++++ 2 files changed, 25 insertions(+)
Documentation/ndctl-list.txt +4 -0
@@ -60,6 +60,10 @@ OPTIONS --region=:: include::xable-region-options.txt[] +-t:: +--type=:: + Filter listing by region type ('pmem' or 'blk') + -B:: --buses:: Include bus info in the listing
builtin-list.c +21 -0
@@ -29,6 +29,7 @@ static struct {static struct {const char *bus;const char *region; +const char *type; } param;static int did_fail;
@@ -197,6 +198,8 @@ int cmd_list(int argc, const char **argv)OPT_STRING ('b' ,"bus" , ¶m.bus,"bus-id" ,"filter by bus" ),OPT_STRING ('r' ,"region" , ¶m.region,"region-id" ,"filter by region" ), +OPT_STRING ('t' ,"type" , ¶m.type,"region-type" , +"filter by region-type" ),OPT_BOOLEAN ('B' ,"buses" , &list.buses,"include bus info" ),OPT_BOOLEAN ('D' ,"dimms" , &list.dimms,"include dimm info" ), OPT_BOOLEAN('R', "regions", &list.regions,
@@ -216,14 +219,29 @@ int cmd_list(int argc, const char **argv)struct json_object *jbuses =NULL ;struct ndctl_ctx *ctx;struct ndctl_bus *bus; +unsigned int type =0 ;int i, rc; argc =parse_options (argc, argv, options, u,0 );for (i =0 ; i < argc; i++)error ("unknown parameter \"%s\"\n" , argv[i]); +if (param.type && (strcmp (param.type,"pmem" ) !=0 + &&strcmp (param.type,"blk" ) !=0 )) { +error ("unknown type \"%s\" must be \"pmem\" or \"blk\"\n" , + param.type); + argc++; + } +if (argc)usage_with_options (u, options); +if (param.type) { +if (strcmp (param.type,"pmem" ) ==0 ) + type =ND_DEVICE_REGION_PMEM ; +else + type =ND_DEVICE_REGION_BLK ; + } + rc =ndctl_new (&ctx);if (rc <0 )return rc;
@@ -293,6 +311,9 @@ int cmd_list(int argc, const char **argv)if (!util_region_filter (region, param.region))continue ; +if (type &&ndctl_region_get_type (region) != type) +continue ; +if (!list.regions) { jnamespaces =list_namespaces (region, jbus, jnamespaces, true);
_______________________________________________
Linux-nvdimm mailing list
[email protected]
https://lists.01.org/mailman/listinfo/linux-nvdimm
PATCH 8/8 ndctl: test clear poison
In reply to Dan WilliamsNow that nfit_test arranges for poison to be injected into the middle of pmem ranges, add the following tests:
1/ Expect errors to be present and cause I/O failures
2/ Expect writes to those sectors to clear poison
--- Makefile.am | 3 ++- test/clear.sh | 67 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 69 insertions(+), 1 deletion(-) create mode 100755 test/clear.sh
Makefile.am +2 -1
@@ -141,7 +141,8 @@ pkgconfig_DATA = lib/libndctl.pc EXTRA_DIST += lib/libndctl.pc.in CLEANFILES += lib/libndctl.pc -TESTS = test/libndctl test/dpa-alloc test/parent-uuid test/create.sh +TESTS = test/libndctl test/dpa-alloc test/parent-uuid test/create.sh \ + test/clear.sh check_PROGRAMS = test/libndctl test/dpa-alloc test/parent-uuid if ENABLE_DESTRUCTIVE
test/clear.sh new file +67 -0
67 lines not on this page · raw message
_______________________________________________
Linux-nvdimm mailing list
[email protected]
https://lists.01.org/mailman/listinfo/linux-nvdimm