nvdimm.lists.linux.dev archive mirror
 help / color / mirror / Atom feed
* [ndctl PATCH 0/8] ndctl: device-dax tests
@ 2016-08-16 17:21 Dan Williams
  2016-08-16 17:21 ` [ndctl PATCH 1/8] ndctl: centralize libndctl context init across commands Dan Williams
                   ` (7 more replies)
  0 siblings, 8 replies; 9+ messages in thread
From: Dan Williams @ 2016-08-16 17:21 UTC (permalink / raw)
  To: linux-nvdimm

- enable tests of the ndctl built-in commands to be authored in C rather
  than Shell

- add apis for retrieving the region-seed and available size

- test the creation and destruction of device-dax instances, and that
  destruction (region unbind) triggers unmap of current mappings.

---

Dan Williams (8):
      ndctl: centralize libndctl context init across commands
      libdaxctl: add daxctl_region_get_available_size()
      libdaxctl: add daxctl_region_get_seed()
      test: teach test/libndctl about device-dax seeds
      test: refactor / export ndctl_get_test_dev()
      test, create-namespace: reset global data
      test: convert device-dax test from shell to C
      test, device-dax: check mappings invalidated on namespace reconfiguration


 daxctl/lib/libdaxctl-private.h    |    3 +
 daxctl/lib/libdaxctl.c            |   77 ++++++++++++++++--
 daxctl/lib/libdaxctl.sym          |    7 ++
 daxctl/libdaxctl.h                |    4 +
 ndctl/builtin-bat.c               |    6 +
 ndctl/builtin-create-nfit.c       |    3 -
 ndctl/builtin-help.c              |    2 
 ndctl/builtin-list.c              |    9 --
 ndctl/builtin-read-labels.c       |    9 --
 ndctl/builtin-test.c              |    8 +-
 ndctl/builtin-xable-region.c      |   17 +---
 ndctl/builtin-xaction-namespace.c |   46 ++++++-----
 ndctl/builtin-zero-labels.c       |    9 --
 ndctl/builtin.h                   |   29 +++----
 ndctl/ndctl.c                     |   17 +++-
 test.h                            |   17 ++--
 test/Makefile.am                  |   13 +++
 test/blk_namespaces.c             |   24 +++---
 test/dax-dev.c                    |   42 ++++++----
 test/device-dax.c                 |  159 +++++++++++++++++++++++++++++++++----
 test/device-dax.sh                |   40 ---------
 test/dpa-alloc.c                  |   19 ++--
 test/libndctl.c                   |   33 ++++----
 test/parent-uuid.c                |   19 ++--
 test/pmem_namespaces.c            |   22 +++--
 25 files changed, 406 insertions(+), 228 deletions(-)
 delete mode 100755 test/device-dax.sh
_______________________________________________
Linux-nvdimm mailing list
Linux-nvdimm@lists.01.org
https://lists.01.org/mailman/listinfo/linux-nvdimm

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [ndctl PATCH 1/8] ndctl: centralize libndctl context init across commands
  2016-08-16 17:21 [ndctl PATCH 0/8] ndctl: device-dax tests Dan Williams
@ 2016-08-16 17:21 ` Dan Williams
  2016-08-16 17:21 ` [ndctl PATCH 2/8] libdaxctl: add daxctl_region_get_available_size() Dan Williams
                   ` (6 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: Dan Williams @ 2016-08-16 17:21 UTC (permalink / raw)
  To: linux-nvdimm

Each command currently establishes its own libndctl context. This is
redundant and prevents unit test scenarios where we examine the state of
the context after command execution. Move context init to be external to
each command.

Signed-off-by: Dan Williams <dan.j.williams@intel.com>
---
 ndctl/builtin-bat.c               |    6 +++---
 ndctl/builtin-create-nfit.c       |    3 ++-
 ndctl/builtin-help.c              |    2 +-
 ndctl/builtin-list.c              |    9 ++-------
 ndctl/builtin-read-labels.c       |    9 +--------
 ndctl/builtin-test.c              |    8 ++++----
 ndctl/builtin-xable-region.c      |   17 ++++++-----------
 ndctl/builtin-xaction-namespace.c |   34 +++++++++++++---------------------
 ndctl/builtin-zero-labels.c       |    9 +--------
 ndctl/builtin.h                   |   29 +++++++++++++++--------------
 ndctl/ndctl.c                     |   17 ++++++++++++++---
 test.h                            |   13 +++++++------
 test/blk_namespaces.c             |   24 ++++++++++++------------
 test/dpa-alloc.c                  |   19 +++++++++----------
 test/libndctl.c                   |   18 ++++++++----------
 test/parent-uuid.c                |   19 +++++++++----------
 test/pmem_namespaces.c            |   22 +++++++++++-----------
 17 files changed, 118 insertions(+), 140 deletions(-)

diff --git a/ndctl/builtin-bat.c b/ndctl/builtin-bat.c
index a83eb0fec063..48b41dab6d92 100644
--- a/ndctl/builtin-bat.c
+++ b/ndctl/builtin-bat.c
@@ -4,7 +4,7 @@
 #include <limits.h>
 #include <util/parse-options.h>
 
-int cmd_bat(int argc, const char **argv)
+int cmd_bat(int argc, const char **argv, struct ndctl_ctx *ctx)
 {
 	int loglevel = LOG_DEBUG, i, rc;
 	struct ndctl_test *test;
@@ -39,12 +39,12 @@ int cmd_bat(int argc, const char **argv)
 		return EXIT_FAILURE;
 	}
 
-	rc = test_blk_namespaces(loglevel, test);
+	rc = test_blk_namespaces(loglevel, test, ctx);
 	fprintf(stderr, "test_blk_namespaces: %s\n", rc ? "FAIL" : "PASS");
 	if (rc && rc != 77)
 		return rc;
 
-	rc = test_pmem_namespaces(loglevel, test);
+	rc = test_pmem_namespaces(loglevel, test, ctx);
 	fprintf(stderr, "test_pmem_namespaces: %s\n", rc ? "FAIL" : "PASS");
 	return ndctl_test_result(test, rc);
 }
diff --git a/ndctl/builtin-create-nfit.c b/ndctl/builtin-create-nfit.c
index fad6b9a4b65d..780bb84580f5 100644
--- a/ndctl/builtin-create-nfit.c
+++ b/ndctl/builtin-create-nfit.c
@@ -163,7 +163,8 @@ static int write_nfit(struct nfit *nfit, const char *file, int force)
 	return rc;
 }
 
-int cmd_create_nfit(int argc, const char **argv)
+struct ndctl_ctx;
+int cmd_create_nfit(int argc, const char **argv, struct ndctl_ctx *ctx)
 {
 	int i, rc = -ENXIO, force = 0;
 	const char * const u[] = {
diff --git a/ndctl/builtin-help.c b/ndctl/builtin-help.c
index 55d3114c4bf8..14ad9d5738d0 100644
--- a/ndctl/builtin-help.c
+++ b/ndctl/builtin-help.c
@@ -137,7 +137,7 @@ static int show_man_page(const char *ndctl_cmd)
 	return -1;
 }
 
-int cmd_help(int argc, const char **argv)
+int cmd_help(int argc, const char **argv, struct ndctl_ctx *ctx)
 {
 	const char * const builtin_help_subcommands[] = {
 		"enable-region", "disable-region", "zero-labels",
diff --git a/ndctl/builtin-list.c b/ndctl/builtin-list.c
index 0875ca95cd14..1486cb1dedc3 100644
--- a/ndctl/builtin-list.c
+++ b/ndctl/builtin-list.c
@@ -188,7 +188,7 @@ static int num_list_flags(void)
 	return list.buses + list.dimms + list.regions + list.namespaces;
 }
 
-int cmd_list(int argc, const char **argv)
+int cmd_list(int argc, const char **argv, struct ndctl_ctx *ctx)
 {
 	const struct option options[] = {
 		OPT_STRING('b', "bus", &param.bus, "bus-id", "filter by bus"),
@@ -218,10 +218,9 @@ int cmd_list(int argc, const char **argv)
 	struct json_object *jregions = NULL;
 	struct json_object *jdimms = NULL;
 	struct json_object *jbuses = NULL;
-	struct ndctl_ctx *ctx;
 	struct ndctl_bus *bus;
 	unsigned int type = 0;
-	int i, rc;
+	int i;
 
         argc = parse_options(argc, argv, options, u, 0);
 	for (i = 0; i < argc; i++)
@@ -252,10 +251,6 @@ int cmd_list(int argc, const char **argv)
 			type = ND_DEVICE_REGION_BLK;
 	}
 
-	rc = ndctl_new(&ctx);
-	if (rc < 0)
-		return rc;
-
 	ndctl_bus_foreach(ctx, bus) {
 		struct json_object *jbus = NULL;
 		struct ndctl_region *region;
diff --git a/ndctl/builtin-read-labels.c b/ndctl/builtin-read-labels.c
index 9dd90c92304e..207d44ce7f68 100644
--- a/ndctl/builtin-read-labels.c
+++ b/ndctl/builtin-read-labels.c
@@ -315,7 +315,7 @@ static int do_read_dimm(FILE *f_out, struct ndctl_dimm *dimm, const char **argv,
 	return rc;
 }
 
-int cmd_read_labels(int argc, const char **argv)
+int cmd_read_labels(int argc, const char **argv, struct ndctl_ctx *ctx)
 {
 	const char *nmem_bus = NULL, *output = NULL;
 	bool verbose = false, json = false;
@@ -334,7 +334,6 @@ int cmd_read_labels(int argc, const char **argv)
 	};
 	struct json_object *jdimms = NULL;
 	struct ndctl_dimm *dimm;
-	struct ndctl_ctx *ctx;
 	struct ndctl_bus *bus;
 	int i, rc, count = 0, err = 0;
 	FILE *f_out = NULL;
@@ -373,10 +372,6 @@ int cmd_read_labels(int argc, const char **argv)
 		}
 	}
 
-	rc = ndctl_new(&ctx);
-	if (rc < 0)
-		goto out;
-
         ndctl_bus_foreach(ctx, bus) {
 		if (!util_bus_filter(bus, nmem_bus))
 			continue;
@@ -396,8 +391,6 @@ int cmd_read_labels(int argc, const char **argv)
 
 	fprintf(stderr, "read %d nmem%s\n", count, count > 1 ? "s" : "");
 
-	ndctl_unref(ctx);
-
  out:
 	if (jdimms) {
 		util_display_json_array(f_out, jdimms, JSON_C_TO_STRING_PRETTY);
diff --git a/ndctl/builtin-test.c b/ndctl/builtin-test.c
index 9c3b7a827128..d9c5b0f28d6e 100644
--- a/ndctl/builtin-test.c
+++ b/ndctl/builtin-test.c
@@ -14,7 +14,7 @@ static char *result(int rc)
 		return "PASS";
 }
 
-int cmd_test(int argc, const char **argv)
+int cmd_test(int argc, const char **argv, struct ndctl_ctx *ctx)
 {
 	struct ndctl_test *test;
 	int loglevel = LOG_DEBUG, i, rc;
@@ -44,17 +44,17 @@ int cmd_test(int argc, const char **argv)
 	else
 		test = ndctl_test_new(0);
 
-	rc = test_libndctl(loglevel, test);
+	rc = test_libndctl(loglevel, test, ctx);
 	fprintf(stderr, "test-libndctl: %s\n", result(rc));
 	if (rc && rc != 77)
 		return rc;
 
-	rc = test_dpa_alloc(loglevel, test);
+	rc = test_dpa_alloc(loglevel, test, ctx);
 	fprintf(stderr, "test-dpa-alloc: %s\n", result(rc));
 	if (rc && rc != 77)
 		return rc;
 
-	rc = test_parent_uuid(loglevel, test);
+	rc = test_parent_uuid(loglevel, test, ctx);
 	fprintf(stderr, "test-parent-uuid: %s\n", result(rc));
 
 	return ndctl_test_result(test, rc);
diff --git a/ndctl/builtin-xable-region.c b/ndctl/builtin-xable-region.c
index 1de1e97634cf..41f465a4543f 100644
--- a/ndctl/builtin-xable-region.c
+++ b/ndctl/builtin-xable-region.c
@@ -37,20 +37,15 @@ static const char *parse_region_options(int argc, const char **argv,
 }
 
 static int do_xable_region(const char *region_arg,
-		int (*xable_fn)(struct ndctl_region *))
+		int (*xable_fn)(struct ndctl_region *), struct ndctl_ctx *ctx)
 {
 	int rc = -ENXIO, success = 0;
 	struct ndctl_region *region;
-	struct ndctl_ctx *ctx;
 	struct ndctl_bus *bus;
 
 	if (!region_arg)
 		goto out;
 
-	rc = ndctl_new(&ctx);
-	if (rc < 0)
-		goto out;
-
         ndctl_bus_foreach(ctx, bus) {
 		if (!util_bus_filter(bus, region_bus))
 			continue;
@@ -64,17 +59,17 @@ static int do_xable_region(const char *region_arg,
 	}
 
 	rc = success;
-	ndctl_unref(ctx);
  out:
 	region_bus = NULL;
 	return rc;
 }
 
-int cmd_disable_region(int argc, const char **argv)
+int cmd_disable_region(int argc, const char **argv, struct ndctl_ctx *ctx)
 {
 	char *xable_usage = "ndctl disable-region <region> [<options>]";
 	const char *region = parse_region_options(argc, argv, xable_usage);
-	int disabled = do_xable_region(region, ndctl_region_disable_invalidate);
+	int disabled = do_xable_region(region, ndctl_region_disable_invalidate,
+			ctx);
 
 	if (disabled < 0) {
 		fprintf(stderr, "error disabling regions: %s\n",
@@ -90,11 +85,11 @@ int cmd_disable_region(int argc, const char **argv)
 	}
 }
 
-int cmd_enable_region(int argc, const char **argv)
+int cmd_enable_region(int argc, const char **argv, struct ndctl_ctx *ctx)
 {
 	char *xable_usage = "ndctl enable-region <region> [<options>]";
 	const char *region = parse_region_options(argc, argv, xable_usage);
-	int enabled = do_xable_region(region, ndctl_region_enable);
+	int enabled = do_xable_region(region, ndctl_region_enable, ctx);
 
 	if (enabled < 0) {
 		fprintf(stderr, "error enabling regions: %s\n",
diff --git a/ndctl/builtin-xaction-namespace.c b/ndctl/builtin-xaction-namespace.c
index 9c7a64ef38d9..12ade241ff64 100644
--- a/ndctl/builtin-xaction-namespace.c
+++ b/ndctl/builtin-xaction-namespace.c
@@ -684,22 +684,17 @@ static int namespace_reconfig(struct ndctl_region *region,
 }
 
 static int do_xaction_namespace(const char *namespace,
-		enum namespace_action action)
+		enum namespace_action action, struct ndctl_ctx *ctx)
 {
 	struct ndctl_namespace *ndns, *_n;
 	int rc = -ENXIO, success = 0;
 	struct ndctl_region *region;
 	const char *ndns_name;
-	struct ndctl_ctx *ctx;
 	struct ndctl_bus *bus;
 
 	if (!namespace && action != ACTION_CREATE)
 		return rc;
 
-	rc = ndctl_new(&ctx);
-	if (rc < 0)
-		return rc;
-
 	if (verbose)
 		ndctl_set_log_priority(ctx, LOG_DEBUG);
 
@@ -732,7 +727,7 @@ static int do_xaction_namespace(const char *namespace,
 				}
 				if (rc == 0)
 					rc = 1;
-				goto done;
+				return rc;
 			}
 			ndctl_namespace_foreach_safe(region, ndns, _n) {
 				ndns_name = ndctl_namespace_get_devname(ndns);
@@ -753,9 +748,8 @@ static int do_xaction_namespace(const char *namespace,
 				case ACTION_CREATE:
 					rc = namespace_reconfig(region, ndns);
 					if (rc < 0)
-						goto done;
-					rc = 1;
-					goto done;
+						return rc;
+					return 1;
 				}
 				if (rc >= 0)
 					success++;
@@ -764,17 +758,15 @@ static int do_xaction_namespace(const char *namespace,
 	}
 
 	rc = success;
- done:
-	ndctl_unref(ctx);
 	return rc;
 }
 
-int cmd_disable_namespace(int argc, const char **argv)
+int cmd_disable_namespace(int argc, const char **argv, struct ndctl_ctx *ctx)
 {
 	char *xable_usage = "ndctl disable-namespace <namespace> [<options>]";
 	const char *namespace = parse_namespace_options(argc, argv,
 			ACTION_DISABLE, base_options, xable_usage);
-	int disabled = do_xaction_namespace(namespace, ACTION_DISABLE);
+	int disabled = do_xaction_namespace(namespace, ACTION_DISABLE, ctx);
 
 	if (disabled < 0) {
 		fprintf(stderr, "error disabling namespaces: %s\n",
@@ -790,12 +782,12 @@ int cmd_disable_namespace(int argc, const char **argv)
 	}
 }
 
-int cmd_enable_namespace(int argc, const char **argv)
+int cmd_enable_namespace(int argc, const char **argv, struct ndctl_ctx *ctx)
 {
 	char *xable_usage = "ndctl enable-namespace <namespace> [<options>]";
 	const char *namespace = parse_namespace_options(argc, argv,
 			ACTION_ENABLE, base_options, xable_usage);
-	int enabled = do_xaction_namespace(namespace, ACTION_ENABLE);
+	int enabled = do_xaction_namespace(namespace, ACTION_ENABLE, ctx);
 
 	if (enabled < 0) {
 		fprintf(stderr, "error enabling namespaces: %s\n",
@@ -811,12 +803,12 @@ int cmd_enable_namespace(int argc, const char **argv)
 	}
 }
 
-int cmd_create_namespace(int argc, const char **argv)
+int cmd_create_namespace(int argc, const char **argv, struct ndctl_ctx *ctx)
 {
 	char *xable_usage = "ndctl create-namespace [<options>]";
 	const char *namespace = parse_namespace_options(argc, argv,
 			ACTION_CREATE, create_options, xable_usage);
-	int created = do_xaction_namespace(namespace, ACTION_CREATE);
+	int created = do_xaction_namespace(namespace, ACTION_CREATE, ctx);
 
 	if (created < 1 && param.do_scan) {
 		/*
@@ -826,7 +818,7 @@ int cmd_create_namespace(int argc, const char **argv)
 		memset(&param, 0, sizeof(param));
 		param.type = "blk";
 		set_defaults(ACTION_CREATE);
-		created = do_xaction_namespace(NULL, ACTION_CREATE);
+		created = do_xaction_namespace(NULL, ACTION_CREATE, ctx);
 	}
 
 	if (created < 0 || (!namespace && created < 1)) {
@@ -841,12 +833,12 @@ int cmd_create_namespace(int argc, const char **argv)
 	return 0;
 }
 
-int cmd_destroy_namespace(int argc , const char **argv)
+int cmd_destroy_namespace(int argc , const char **argv, struct ndctl_ctx *ctx)
 {
 	char *xable_usage = "ndctl destroy-namespace <namespace> [<options>]";
 	const char *namespace = parse_namespace_options(argc, argv,
 			ACTION_DESTROY, destroy_options, xable_usage);
-	int destroyed = do_xaction_namespace(namespace, ACTION_DESTROY);
+	int destroyed = do_xaction_namespace(namespace, ACTION_DESTROY, ctx);
 
 	if (destroyed < 0) {
 		fprintf(stderr, "error destroying namespaces: %s\n",
diff --git a/ndctl/builtin-zero-labels.c b/ndctl/builtin-zero-labels.c
index 649bd9eb9c08..2fe466e6ba34 100644
--- a/ndctl/builtin-zero-labels.c
+++ b/ndctl/builtin-zero-labels.c
@@ -29,7 +29,7 @@ static int do_zero_dimm(struct ndctl_dimm *dimm, const char **argv, int argc,
 	return rc;
 }
 
-int cmd_zero_labels(int argc, const char **argv)
+int cmd_zero_labels(int argc, const char **argv, struct ndctl_ctx *ctx)
 {
 	const char *nmem_bus = NULL;
 	bool verbose = false;
@@ -44,7 +44,6 @@ int cmd_zero_labels(int argc, const char **argv)
 		NULL
 	};
 	struct ndctl_dimm *dimm;
-	struct ndctl_ctx *ctx;
 	struct ndctl_bus *bus;
 	int i, rc, count, err = 0;
 
@@ -64,10 +63,6 @@ int cmd_zero_labels(int argc, const char **argv)
 		}
 	}
 
-	rc = ndctl_new(&ctx);
-	if (rc < 0)
-		return rc;
-
 	count = 0;
         ndctl_bus_foreach(ctx, bus) {
 		if (!util_bus_filter(bus, nmem_bus))
@@ -85,8 +80,6 @@ int cmd_zero_labels(int argc, const char **argv)
 
 	fprintf(stderr, "zeroed %d nmem%s\n", count, count > 1 ? "s" : "");
 
-	ndctl_unref(ctx);
-
 	/*
 	 * 0 if all dimms zeroed, count if at least 1 dimm zeroed, < 0
 	 * if all errors
diff --git a/ndctl/builtin.h b/ndctl/builtin.h
index 53ec25b8a76a..46cd5d2d439c 100644
--- a/ndctl/builtin.h
+++ b/ndctl/builtin.h
@@ -3,26 +3,27 @@
 extern const char ndctl_usage_string[];
 extern const char ndctl_more_info_string[];
 
+struct ndctl_ctx;
 struct cmd_struct {
 	const char *cmd;
-	int (*fn)(int, const char **);
+	int (*fn)(int, const char **, struct ndctl_ctx *ctx);
 };
 
-int cmd_create_nfit(int argc, const char **argv);
-int cmd_enable_namespace(int argc, const char **argv);
-int cmd_create_namespace(int argc, const char **argv);
-int cmd_destroy_namespace(int argc, const char **argv);
-int cmd_disable_namespace(int argc, const char **argv);
-int cmd_enable_region(int argc, const char **argv);
-int cmd_disable_region(int argc, const char **argv);
-int cmd_zero_labels(int argc, const char **argv);
-int cmd_read_labels(int argc, const char **argv);
-int cmd_help(int argc, const char **argv);
-int cmd_list(int argc, const char **argv);
+int cmd_create_nfit(int argc, const char **argv, struct ndctl_ctx *ctx);
+int cmd_enable_namespace(int argc, const char **argv, struct ndctl_ctx *ctx);
+int cmd_create_namespace(int argc, const char **argv, struct ndctl_ctx *ctx);
+int cmd_destroy_namespace(int argc, const char **argv, struct ndctl_ctx *ctx);
+int cmd_disable_namespace(int argc, const char **argv, struct ndctl_ctx *ctx);
+int cmd_enable_region(int argc, const char **argv, struct ndctl_ctx *ctx);
+int cmd_disable_region(int argc, const char **argv, struct ndctl_ctx *ctx);
+int cmd_zero_labels(int argc, const char **argv, struct ndctl_ctx *ctx);
+int cmd_read_labels(int argc, const char **argv, struct ndctl_ctx *ctx);
+int cmd_list(int argc, const char **argv, struct ndctl_ctx *ctx);
+int cmd_help(int argc, const char **argv, struct ndctl_ctx *ctx);
 #ifdef ENABLE_TEST
-int cmd_test(int argc, const char **argv);
+int cmd_test(int argc, const char **argv, struct ndctl_ctx *ctx);
 #endif
 #ifdef ENABLE_DESTRUCTIVE
-int cmd_bat(int argc, const char **argv);
+int cmd_bat(int argc, const char **argv, struct ndctl_ctx *ctx);
 #endif
 #endif /* _NDCTL_BUILTIN_H_ */
diff --git a/ndctl/ndctl.c b/ndctl/ndctl.c
index bf0754cb454c..77f90d6087ba 100644
--- a/ndctl/ndctl.c
+++ b/ndctl/ndctl.c
@@ -6,6 +6,7 @@
 #include <sys/stat.h>
 #include <sys/types.h>
 #include <builtin.h>
+#include <ndctl/libndctl.h>
 #include <ccan/array_size/array_size.h>
 
 #include <util/strbuf.h>
@@ -16,7 +17,7 @@ const char ndctl_more_info_string[] =
 	"See 'ndctl help COMMAND' for more information on a specific command.\n"
 	" ndctl --list-cmds to see all available commands";
 
-static int cmd_version(int argc, const char **argv)
+static int cmd_version(int argc, const char **argv, struct ndctl_ctx *ctx)
 {
 	printf("%s\n", VERSION);
 	return 0;
@@ -101,8 +102,18 @@ static int run_builtin(struct cmd_struct *p, int argc, const char **argv)
 {
 	int status;
 	struct stat st;
-
-	status = p->fn(argc, argv);
+	struct ndctl_ctx *ctx;
+
+	/*
+	 * Yes, establishing the ndctl context here makes this code less
+	 * generic, but it allows for unit testing the top level
+	 * interface to the built-in commands.
+	 */
+	status = ndctl_new(&ctx);
+	if (status)
+		return status;
+	status = p->fn(argc, argv, ctx);
+	ndctl_unref(ctx);
 
 	if (status)
 		return status & 0xff;
diff --git a/test.h b/test.h
index 5425be1bc107..1ac03aa09762 100644
--- a/test.h
+++ b/test.h
@@ -12,10 +12,11 @@ int __ndctl_test_attempt(struct ndctl_test *test, unsigned int kver,
 void __ndctl_test_skip(struct ndctl_test *test, const char *caller, int line);
 #define ndctl_test_skip(t) __ndctl_test_skip(t, __func__, __LINE__)
 
-int test_parent_uuid(int loglevel, struct ndctl_test *test);
-int test_direct_io(int loglevel, struct ndctl_test *test);
-int test_dpa_alloc(int loglevel, struct ndctl_test *test);
-int test_libndctl(int loglevel, struct ndctl_test *test);
-int test_blk_namespaces(int loglevel, struct ndctl_test *test);
-int test_pmem_namespaces(int loglevel, struct ndctl_test *test);
+struct ndctl_ctx;
+int test_parent_uuid(int loglevel, struct ndctl_test *test, struct ndctl_ctx *ctx);
+int test_direct_io(int loglevel, struct ndctl_test *test, struct ndctl_ctx *ctx);
+int test_dpa_alloc(int loglevel, struct ndctl_test *test, struct ndctl_ctx *ctx);
+int test_libndctl(int loglevel, struct ndctl_test *test, struct ndctl_ctx *ctx);
+int test_blk_namespaces(int loglevel, struct ndctl_test *test, struct ndctl_ctx *ctx);
+int test_pmem_namespaces(int loglevel, struct ndctl_test *test, struct ndctl_ctx *ctx);
 #endif /* __TEST_H__ */
diff --git a/test/blk_namespaces.c b/test/blk_namespaces.c
index 2e25c19b2f59..6b36c8c9fc03 100644
--- a/test/blk_namespaces.c
+++ b/test/blk_namespaces.c
@@ -214,11 +214,11 @@ static int ns_do_io(const char *bdev)
 
 static const char *comm = "test-blk-namespaces";
 
-int test_blk_namespaces(int log_level, struct ndctl_test *test)
+int test_blk_namespaces(int log_level, struct ndctl_test *test,
+		struct ndctl_ctx *ctx)
 {
-	int rc;
 	char bdev[50];
-	struct ndctl_ctx *ctx;
+	int rc = -ENXIO;
 	struct ndctl_bus *bus;
 	struct ndctl_dimm *dimm;
 	struct kmod_module *mod = NULL;
@@ -229,10 +229,6 @@ int test_blk_namespaces(int log_level, struct ndctl_test *test)
 	if (!ndctl_test_attempt(test, KERNEL_VERSION(4, 2, 0)))
 		return 77;
 
-	rc = ndctl_new(&ctx);
-	if (rc < 0)
-		return rc;
-
 	ndctl_set_log_priority(ctx, log_level);
 
 	bus = ndctl_bus_get_by_provider(ctx, "ACPI.NFIT");
@@ -250,7 +246,7 @@ int test_blk_namespaces(int log_level, struct ndctl_test *test)
 		fprintf(stderr, "ACPI.NFIT unavailable falling back to nfit_test\n");
 		kmod_ctx = kmod_new(NULL, NULL);
 		if (!kmod_ctx)
-			goto err_kmod;
+			return rc;
 		kmod_set_log_priority(kmod_ctx, log_level);
 
 		rc = kmod_module_new_from_name(kmod_ctx, "nfit_test", &mod);
@@ -282,7 +278,7 @@ int test_blk_namespaces(int log_level, struct ndctl_test *test)
                 if (rc < 0) {
                         fprintf(stderr, "failed to zero %s\n",
                                         ndctl_dimm_get_devname(dimm));
-                        return rc;
+			goto err_module;
                 }
         }
 
@@ -364,14 +360,13 @@ int test_blk_namespaces(int log_level, struct ndctl_test *test)
  err_module:
 	if (kmod_ctx)
 		kmod_unref(kmod_ctx);
- err_kmod:
-	ndctl_unref(ctx);
 	return rc;
 }
 
 int __attribute__((weak)) main(int argc, char *argv[])
 {
 	struct ndctl_test *test = ndctl_test_new(0);
+	struct ndctl_ctx *ctx;
 	int rc;
 
 	comm = argv[0];
@@ -380,6 +375,11 @@ int __attribute__((weak)) main(int argc, char *argv[])
 		return EXIT_FAILURE;
 	}
 
-	rc = test_blk_namespaces(LOG_DEBUG, test);
+	rc = ndctl_new(&ctx);
+	if (rc)
+		return ndctl_test_result(test, rc);
+
+	rc = test_blk_namespaces(LOG_DEBUG, test, ctx);
+	ndctl_unref(ctx);
 	return ndctl_test_result(test, rc);
 }
diff --git a/test/dpa-alloc.c b/test/dpa-alloc.c
index 87f374fe0540..8b100abeb466 100644
--- a/test/dpa-alloc.c
+++ b/test/dpa-alloc.c
@@ -290,9 +290,8 @@ static int do_test(struct ndctl_ctx *ctx, struct ndctl_test *test)
 	return 0;
 }
 
-int test_dpa_alloc(int loglevel, struct ndctl_test *test)
+int test_dpa_alloc(int loglevel, struct ndctl_test *test, struct ndctl_ctx *ctx)
 {
-	struct ndctl_ctx *ctx;
 	struct kmod_module *mod;
 	struct kmod_ctx *kmod_ctx;
 	int err, result = EXIT_FAILURE;
@@ -300,15 +299,11 @@ int test_dpa_alloc(int loglevel, struct ndctl_test *test)
 	if (!ndctl_test_attempt(test, KERNEL_VERSION(4, 2, 0)))
 		return 77;
 
-	err = ndctl_new(&ctx);
-	if (err < 0)
-		exit(EXIT_FAILURE);
-
 	ndctl_set_log_priority(ctx, loglevel);
 
 	kmod_ctx = kmod_new(NULL, NULL);
 	if (!kmod_ctx)
-		goto err_kmod;
+		return result;
 
 	err = kmod_module_new_from_name(kmod_ctx, NFIT_TEST_MODULE, &mod);
 	if (err < 0)
@@ -331,14 +326,13 @@ int test_dpa_alloc(int loglevel, struct ndctl_test *test)
 
  err_module:
 	kmod_unref(kmod_ctx);
- err_kmod:
-	ndctl_unref(ctx);
 	return result;
 }
 
 int __attribute__((weak)) main(int argc, char *argv[])
 {
 	struct ndctl_test *test = ndctl_test_new(0);
+	struct ndctl_ctx *ctx;
 	int rc;
 
 	if (!test) {
@@ -346,6 +340,11 @@ int __attribute__((weak)) main(int argc, char *argv[])
 		return EXIT_FAILURE;
 	}
 
-	rc = test_dpa_alloc(LOG_DEBUG, test);
+	rc = ndctl_new(&ctx);
+	if (rc)
+		return ndctl_test_result(test, rc);
+
+	rc = test_dpa_alloc(LOG_DEBUG, test, ctx);
+	ndctl_unref(ctx);
 	return ndctl_test_result(test, rc);
 }
diff --git a/test/libndctl.c b/test/libndctl.c
index 684235d65eac..de2c47c3f91b 100644
--- a/test/libndctl.c
+++ b/test/libndctl.c
@@ -2505,10 +2505,9 @@ static do_test_fn do_test[] = {
 	do_test1,
 };
 
-int test_libndctl(int loglevel, struct ndctl_test *test)
+int test_libndctl(int loglevel, struct ndctl_test *test, struct ndctl_ctx *ctx)
 {
 	unsigned int i;
-	struct ndctl_ctx *ctx;
 	struct kmod_module *mod;
 	struct kmod_ctx *kmod_ctx;
 	struct daxctl_ctx *daxctl_ctx;
@@ -2517,17 +2516,13 @@ int test_libndctl(int loglevel, struct ndctl_test *test)
 	if (!ndctl_test_attempt(test, KERNEL_VERSION(4, 2, 0)))
 		return 77;
 
-	err = ndctl_new(&ctx);
-	if (err < 0)
-		exit(EXIT_FAILURE);
-
 	ndctl_set_log_priority(ctx, loglevel);
 	daxctl_ctx = ndctl_get_daxctl_ctx(ctx);
 	daxctl_set_log_priority(daxctl_ctx, loglevel);
 
 	kmod_ctx = kmod_new(NULL, NULL);
 	if (!kmod_ctx)
-		goto err_kmod;
+		return result;
 	kmod_set_log_priority(kmod_ctx, loglevel);
 
 	err = kmod_module_new_from_name(kmod_ctx, NFIT_TEST_MODULE, &mod);
@@ -2558,14 +2553,13 @@ int test_libndctl(int loglevel, struct ndctl_test *test)
 
  err_module:
 	kmod_unref(kmod_ctx);
- err_kmod:
-	ndctl_unref(ctx);
 	return result;
 }
 
 int __attribute__((weak)) main(int argc, char *argv[])
 {
 	struct ndctl_test *test = ndctl_test_new(0);
+	struct ndctl_ctx *ctx;
 	int rc;
 
 	if (!test) {
@@ -2573,6 +2567,10 @@ int __attribute__((weak)) main(int argc, char *argv[])
 		return EXIT_FAILURE;
 	}
 
-	rc = test_libndctl(LOG_DEBUG, test);
+	rc = ndctl_new(&ctx);
+	if (rc)
+		return ndctl_test_result(test, rc);
+	rc = test_libndctl(LOG_DEBUG, test, ctx);
+	ndctl_unref(ctx);
 	return ndctl_test_result(test, rc);
 }
diff --git a/test/parent-uuid.c b/test/parent-uuid.c
index 676b3ad63b15..89c13956985e 100644
--- a/test/parent-uuid.c
+++ b/test/parent-uuid.c
@@ -220,9 +220,8 @@ static int do_test(struct ndctl_ctx *ctx)
 	return 0;
 }
 
-int test_parent_uuid(int loglevel, struct ndctl_test *test)
+int test_parent_uuid(int loglevel, struct ndctl_test *test, struct ndctl_ctx *ctx)
 {
-	struct ndctl_ctx *ctx;
 	struct kmod_module *mod;
 	struct kmod_ctx *kmod_ctx;
 	int err, result = EXIT_FAILURE;
@@ -230,15 +229,11 @@ int test_parent_uuid(int loglevel, struct ndctl_test *test)
 	if (!ndctl_test_attempt(test, KERNEL_VERSION(4, 3, 0)))
 		return 77;
 
-	err = ndctl_new(&ctx);
-	if (err < 0)
-		exit(EXIT_FAILURE);
-
 	ndctl_set_log_priority(ctx, loglevel);
 
 	kmod_ctx = kmod_new(NULL, NULL);
 	if (!kmod_ctx)
-		goto err_kmod;
+		return result;
 
 	err = kmod_module_new_from_name(kmod_ctx, NFIT_TEST_MODULE, &mod);
 	if (err < 0)
@@ -261,14 +256,13 @@ int test_parent_uuid(int loglevel, struct ndctl_test *test)
 
  err_module:
 	kmod_unref(kmod_ctx);
- err_kmod:
-	ndctl_unref(ctx);
 	return result;
 }
 
 int __attribute__((weak)) main(int argc, char *argv[])
 {
 	struct ndctl_test *test = ndctl_test_new(0);
+	struct ndctl_ctx *ctx;
 	int rc;
 
 	if (!test) {
@@ -276,6 +270,11 @@ int __attribute__((weak)) main(int argc, char *argv[])
 		return EXIT_FAILURE;
 	}
 
-	rc = test_parent_uuid(LOG_DEBUG, test);
+	rc = ndctl_new(&ctx);
+	if (rc)
+		return ndctl_test_result(test, rc);
+
+	rc = test_parent_uuid(LOG_DEBUG, test, ctx);
+	ndctl_unref(ctx);
 	return ndctl_test_result(test, rc);
 }
diff --git a/test/pmem_namespaces.c b/test/pmem_namespaces.c
index 8edfaba2d7f3..908706bce4bb 100644
--- a/test/pmem_namespaces.c
+++ b/test/pmem_namespaces.c
@@ -178,25 +178,21 @@ static int ns_do_io(const char *bdev)
 
 static const char *comm = "test-pmem-namespaces";
 
-int test_pmem_namespaces(int log_level, struct ndctl_test *test)
+int test_pmem_namespaces(int log_level, struct ndctl_test *test,
+		struct ndctl_ctx *ctx)
 {
 	struct ndctl_region *region, *pmem_region = NULL;
 	struct kmod_ctx *kmod_ctx = NULL;
 	struct kmod_module *mod = NULL;
 	struct ndctl_namespace *ndns;
 	struct ndctl_dimm *dimm;
-	struct ndctl_ctx *ctx;
 	struct ndctl_bus *bus;
+	int rc = -ENXIO;
 	char bdev[50];
-	int rc;
 
 	if (!ndctl_test_attempt(test, KERNEL_VERSION(4, 2, 0)))
 		return 77;
 
-	rc = ndctl_new(&ctx);
-	if (rc < 0)
-		return rc;
-
 	ndctl_set_log_priority(ctx, log_level);
 
 	bus = ndctl_bus_get_by_provider(ctx, "ACPI.NFIT");
@@ -214,7 +210,7 @@ int test_pmem_namespaces(int log_level, struct ndctl_test *test)
 		fprintf(stderr, "ACPI.NFIT unavailable falling back to nfit_test\n");
 		kmod_ctx = kmod_new(NULL, NULL);
 		if (!kmod_ctx)
-			goto err_kmod;
+			return rc;
 		kmod_set_log_priority(kmod_ctx, log_level);
 
 		rc = kmod_module_new_from_name(kmod_ctx, "nfit_test", &mod);
@@ -289,14 +285,13 @@ int test_pmem_namespaces(int log_level, struct ndctl_test *test)
 
  err_module:
 	kmod_unref(kmod_ctx);
- err_kmod:
-	ndctl_unref(ctx);
 	return rc;
 }
 
 int __attribute__((weak)) main(int argc, char *argv[])
 {
 	struct ndctl_test *test = ndctl_test_new(0);
+	struct ndctl_ctx *ctx;
 	int rc;
 
 	comm = argv[0];
@@ -305,6 +300,11 @@ int __attribute__((weak)) main(int argc, char *argv[])
 		return EXIT_FAILURE;
 	}
 
-	rc = test_pmem_namespaces(LOG_DEBUG, test);
+	rc = ndctl_new(&ctx);
+	if (rc)
+		return ndctl_test_result(test, rc);
+
+	rc = test_pmem_namespaces(LOG_DEBUG, test, ctx);
+	ndctl_unref(ctx);
 	return ndctl_test_result(test, rc);
 }

_______________________________________________
Linux-nvdimm mailing list
Linux-nvdimm@lists.01.org
https://lists.01.org/mailman/listinfo/linux-nvdimm

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [ndctl PATCH 2/8] libdaxctl: add daxctl_region_get_available_size()
  2016-08-16 17:21 [ndctl PATCH 0/8] ndctl: device-dax tests Dan Williams
  2016-08-16 17:21 ` [ndctl PATCH 1/8] ndctl: centralize libndctl context init across commands Dan Williams
@ 2016-08-16 17:21 ` Dan Williams
  2016-08-16 17:21 ` [ndctl PATCH 3/8] libdaxctl: add daxctl_region_get_seed() Dan Williams
                   ` (5 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: Dan Williams @ 2016-08-16 17:21 UTC (permalink / raw)
  To: linux-nvdimm

Retrieve the available_size attribute for a given dax_region.

As a side effect this rework region->region_path to carry the actual
path without the "dax" class prefix for finding child device-dax
instances.

Signed-off-by: Dan Williams <dan.j.williams@intel.com>
---
 daxctl/lib/libdaxctl-private.h |    3 ++
 daxctl/lib/libdaxctl.c         |   53 ++++++++++++++++++++++++++++++++++------
 daxctl/lib/libdaxctl.sym       |    6 +++++
 daxctl/libdaxctl.h             |    3 ++
 4 files changed, 57 insertions(+), 8 deletions(-)

diff --git a/daxctl/lib/libdaxctl-private.h b/daxctl/lib/libdaxctl-private.h
index abd78fd4cc52..a2924f1e93f5 100644
--- a/daxctl/lib/libdaxctl-private.h
+++ b/daxctl/lib/libdaxctl-private.h
@@ -18,10 +18,13 @@
 /**
  * struct daxctl_region - container for dax_devices
  */
+#define REGION_BUF_SIZE 50
 struct daxctl_region {
 	int id;
 	uuid_t uuid;
 	int refcount;
+	size_t buf_len;
+	void *region_buf;
 	int devices_init;
 	char *region_path;
 	struct daxctl_ctx *ctx;
diff --git a/daxctl/lib/libdaxctl.c b/daxctl/lib/libdaxctl.c
index 9d71a2952630..4f6bbc0cd7a6 100644
--- a/daxctl/lib/libdaxctl.c
+++ b/daxctl/lib/libdaxctl.c
@@ -191,10 +191,11 @@ DAXCTL_EXPORT void daxctl_region_unref(struct daxctl_region *region)
 		return;
 
 	ctx = region->ctx;
-	info(ctx, "region%d released\n", region->id);
+	dbg(ctx, "%s: %s\n", __func__, daxctl_region_get_devname(region));
 	list_for_each_safe(&region->devices, dev, _d, list)
 		free_dev(dev, &region->devices);
 	free(region->region_path);
+	free(region->region_buf);
 	free(region);
 }
 
@@ -208,7 +209,6 @@ DAXCTL_EXPORT struct daxctl_region *daxctl_new_region(struct daxctl_ctx *ctx,
 		int id, uuid_t uuid, const char *path)
 {
 	struct daxctl_region *region;
-	char *region_path;
 
 	region = calloc(1, sizeof(*region));
 	if (!region)
@@ -217,16 +217,18 @@ DAXCTL_EXPORT struct daxctl_region *daxctl_new_region(struct daxctl_ctx *ctx,
 	region->id = id;
 	region->refcount = 1;
 	uuid_copy(region->uuid, uuid);
-	if (asprintf(&region_path, "%s/dax", path) < 0)
-		region_path = NULL;
-	region->region_path = region_path;
+	region->region_path = strdup(path);
 	list_head_init(&region->devices);
+	region->buf_len = strlen(region->region_path) + REGION_BUF_SIZE;
+	region->region_buf = calloc(1, region->buf_len);
 
-	if (!region->region_path) {
+	if (!region->region_path || !region->region_buf) {
 		daxctl_region_unref(region);
 		region = NULL;
 	}
 
+	dbg(ctx, "%s: %s\n", __func__, daxctl_region_get_devname(region));
+
 	return region;
 }
 
@@ -295,18 +297,53 @@ DAXCTL_EXPORT int daxctl_region_get_id(struct daxctl_region *region)
 	return region->id;
 }
 
+DAXCTL_EXPORT const char *daxctl_region_get_devname(struct daxctl_region *region)
+{
+        return devpath_to_devname(region->region_path);
+}
+
+DAXCTL_EXPORT unsigned long long daxctl_region_get_available_size(
+		struct daxctl_region *region)
+{
+	struct daxctl_ctx *ctx = daxctl_region_get_ctx(region);
+	char *path = region->region_buf;
+	char buf[SYSFS_ATTR_SIZE], *end;
+	int len = region->buf_len;
+	unsigned long long avail;
+
+	if (snprintf(path, len, "%s/dax_region/available_size",
+				region->region_path) >= len) {
+		err(ctx, "%s: buffer too small!\n",
+				daxctl_region_get_devname(region));
+		return 0;
+	}
+
+	if (sysfs_read_attr(ctx, path, buf) < 0)
+		return 0;
+
+	avail = strtoull(buf, &end, 0);
+	if (buf[0] && *end == '\0')
+		return avail;
+	return 0;
+}
+
 static void dax_devices_init(struct daxctl_region *region)
 {
 	struct daxctl_ctx *ctx = daxctl_region_get_ctx(region);
 	char daxdev_fmt[50];
+	char *region_path;
 
 	if (region->devices_init)
 		return;
 
 	region->devices_init = 1;
 	sprintf(daxdev_fmt, "dax%d.", region->id);
-	sysfs_device_parse(ctx, region->region_path, daxdev_fmt, region,
-			add_dax_dev);
+	if (asprintf(&region_path, "%s/dax", region->region_path) < 0)
+		region_path = NULL;
+	if (region_path)
+		sysfs_device_parse(ctx, region_path, daxdev_fmt, region,
+				add_dax_dev);
+	free(region_path);
 }
 
 DAXCTL_EXPORT struct daxctl_dev *daxctl_dev_get_first(struct daxctl_region *region)
diff --git a/daxctl/lib/libdaxctl.sym b/daxctl/lib/libdaxctl.sym
index bdf3bd7da9b3..6fb11d8757cf 100644
--- a/daxctl/lib/libdaxctl.sym
+++ b/daxctl/lib/libdaxctl.sym
@@ -30,3 +30,9 @@ global:
 	daxctl_dev_get_minor;
 	daxctl_dev_get_size;
 } LIBNDCTL_1;
+
+LIBDAXCTL_3 {
+global:
+	daxctl_region_get_available_size;
+	daxctl_region_get_devname;
+} LIBNDCTL_2;
diff --git a/daxctl/libdaxctl.h b/daxctl/libdaxctl.h
index fbffe8c538b3..ada20ee1e9dd 100644
--- a/daxctl/libdaxctl.h
+++ b/daxctl/libdaxctl.h
@@ -41,6 +41,9 @@ void daxctl_region_unref(struct daxctl_region *region);
 void daxctl_region_get_uuid(struct daxctl_region *region, uuid_t uu);
 int daxctl_region_get_id(struct daxctl_region *region);
 struct daxctl_ctx *daxctl_region_get_ctx(struct daxctl_region *region);
+unsigned long long daxctl_region_get_available_size(
+		struct daxctl_region *region);
+const char *daxctl_region_get_devname(struct daxctl_region *region);
 
 struct daxctl_dev;
 struct daxctl_dev *daxctl_dev_get_first(struct daxctl_region *region);

_______________________________________________
Linux-nvdimm mailing list
Linux-nvdimm@lists.01.org
https://lists.01.org/mailman/listinfo/linux-nvdimm

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [ndctl PATCH 3/8] libdaxctl: add daxctl_region_get_seed()
  2016-08-16 17:21 [ndctl PATCH 0/8] ndctl: device-dax tests Dan Williams
  2016-08-16 17:21 ` [ndctl PATCH 1/8] ndctl: centralize libndctl context init across commands Dan Williams
  2016-08-16 17:21 ` [ndctl PATCH 2/8] libdaxctl: add daxctl_region_get_available_size() Dan Williams
@ 2016-08-16 17:21 ` Dan Williams
  2016-08-16 17:21 ` [ndctl PATCH 4/8] test: teach test/libndctl about device-dax seeds Dan Williams
                   ` (4 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: Dan Williams @ 2016-08-16 17:21 UTC (permalink / raw)
  To: linux-nvdimm

Retrieve the device-dax seed, next device-dax instance to configure for
the dax_region.

Signed-off-by: Dan Williams <dan.j.williams@intel.com>
---
 daxctl/lib/libdaxctl.c   |   24 ++++++++++++++++++++++++
 daxctl/lib/libdaxctl.sym |    1 +
 daxctl/libdaxctl.h       |    1 +
 3 files changed, 26 insertions(+)

diff --git a/daxctl/lib/libdaxctl.c b/daxctl/lib/libdaxctl.c
index 4f6bbc0cd7a6..ecdb99640115 100644
--- a/daxctl/lib/libdaxctl.c
+++ b/daxctl/lib/libdaxctl.c
@@ -327,6 +327,30 @@ DAXCTL_EXPORT unsigned long long daxctl_region_get_available_size(
 	return 0;
 }
 
+DAXCTL_EXPORT struct daxctl_dev *daxctl_region_get_dev_seed(
+		struct daxctl_region *region)
+{
+	struct daxctl_ctx *ctx = daxctl_region_get_ctx(region);
+	char *path = region->region_buf;
+	int len = region->buf_len;
+	char buf[SYSFS_ATTR_SIZE];
+	struct daxctl_dev *dev;
+
+	if (snprintf(path, len, "%s/dax_region/seed", region->region_path) >= len) {
+		err(ctx, "%s: buffer too small!\n",
+				daxctl_region_get_devname(region));
+		return NULL;
+	}
+
+	if (sysfs_read_attr(ctx, path, buf) < 0)
+		return NULL;
+
+	daxctl_dev_foreach(region, dev)
+		if (strcmp(buf, daxctl_dev_get_devname(dev)) == 0)
+			return dev;
+	return NULL;
+}
+
 static void dax_devices_init(struct daxctl_region *region)
 {
 	struct daxctl_ctx *ctx = daxctl_region_get_ctx(region);
diff --git a/daxctl/lib/libdaxctl.sym b/daxctl/lib/libdaxctl.sym
index 6fb11d8757cf..e74d75bf7847 100644
--- a/daxctl/lib/libdaxctl.sym
+++ b/daxctl/lib/libdaxctl.sym
@@ -35,4 +35,5 @@ LIBDAXCTL_3 {
 global:
 	daxctl_region_get_available_size;
 	daxctl_region_get_devname;
+	daxctl_region_get_dev_seed;
 } LIBNDCTL_2;
diff --git a/daxctl/libdaxctl.h b/daxctl/libdaxctl.h
index ada20ee1e9dd..bb7aa363a605 100644
--- a/daxctl/libdaxctl.h
+++ b/daxctl/libdaxctl.h
@@ -44,6 +44,7 @@ struct daxctl_ctx *daxctl_region_get_ctx(struct daxctl_region *region);
 unsigned long long daxctl_region_get_available_size(
 		struct daxctl_region *region);
 const char *daxctl_region_get_devname(struct daxctl_region *region);
+struct daxctl_dev *daxctl_region_get_dev_seed(struct daxctl_region *region);
 
 struct daxctl_dev;
 struct daxctl_dev *daxctl_dev_get_first(struct daxctl_region *region);

_______________________________________________
Linux-nvdimm mailing list
Linux-nvdimm@lists.01.org
https://lists.01.org/mailman/listinfo/linux-nvdimm

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [ndctl PATCH 4/8] test: teach test/libndctl about device-dax seeds
  2016-08-16 17:21 [ndctl PATCH 0/8] ndctl: device-dax tests Dan Williams
                   ` (2 preceding siblings ...)
  2016-08-16 17:21 ` [ndctl PATCH 3/8] libdaxctl: add daxctl_region_get_seed() Dan Williams
@ 2016-08-16 17:21 ` Dan Williams
  2016-08-16 17:21 ` [ndctl PATCH 5/8] test: refactor / export ndctl_get_test_dev() Dan Williams
                   ` (3 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: Dan Williams @ 2016-08-16 17:21 UTC (permalink / raw)
  To: linux-nvdimm

Starting the with v4.9 kernel the default number of device-dax instances
per-region will be 2, and seed devices are legitimately zero-sized.

Signed-off-by: Dan Williams <dan.j.williams@intel.com>
---
 test/libndctl.c |   15 +++++++++------
 1 file changed, 9 insertions(+), 6 deletions(-)

diff --git a/test/libndctl.c b/test/libndctl.c
index de2c47c3f91b..30b78a2824f1 100644
--- a/test/libndctl.c
+++ b/test/libndctl.c
@@ -623,9 +623,9 @@ static int validate_dax(struct ndctl_dax *dax)
 	const char *devname = ndctl_namespace_get_devname(ndns);
 	struct ndctl_region *region = ndctl_dax_get_region(dax);
 	struct daxctl_region *dax_region = NULL;
+	int rc = -ENXIO, fd, count, dax_expect;
+	struct daxctl_dev *dax_dev, *seed;
 	uuid_t uuid, region_uuid;
-	struct daxctl_dev *dax_dev;
-	int rc = -ENXIO, fd, count;
 	char devpath[50];
 
 	dax_region = ndctl_dax_get_daxctl_region(dax);
@@ -663,7 +663,8 @@ static int validate_dax(struct ndctl_dax *dax)
 		goto out;
 	}
 
-	if (daxctl_dev_get_size(dax_dev) <= 0) {
+	seed = daxctl_region_get_dev_seed(dax_region);
+	if (dax_dev != seed && daxctl_dev_get_size(dax_dev) <= 0) {
 		fprintf(stderr, "%s: expected non-zero sized dax device\n",
 				devname);
 		goto out;
@@ -680,9 +681,11 @@ static int validate_dax(struct ndctl_dax *dax)
 	count = 0;
 	daxctl_dev_foreach(dax_region, dax_dev)
 		count++;
-	if (count != 1) {
-		fprintf(stderr, "%s: expected 1 dax device, got %d\n",
-				devname, count);
+	dax_expect = seed ? 2 : 1;
+	if (count != dax_expect) {
+		fprintf(stderr, "%s: expected %d dax device%s, got %d\n",
+				devname, dax_expect, dax_expect == 1 ? "" : "s",
+				count);
 		rc = -ENXIO;
 		goto out;
 	}

_______________________________________________
Linux-nvdimm mailing list
Linux-nvdimm@lists.01.org
https://lists.01.org/mailman/listinfo/linux-nvdimm

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [ndctl PATCH 5/8] test: refactor / export ndctl_get_test_dev()
  2016-08-16 17:21 [ndctl PATCH 0/8] ndctl: device-dax tests Dan Williams
                   ` (3 preceding siblings ...)
  2016-08-16 17:21 ` [ndctl PATCH 4/8] test: teach test/libndctl about device-dax seeds Dan Williams
@ 2016-08-16 17:21 ` Dan Williams
  2016-08-16 17:21 ` [ndctl PATCH 6/8] test, create-namespace: reset global data Dan Williams
                   ` (2 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: Dan Williams @ 2016-08-16 17:21 UTC (permalink / raw)
  To: linux-nvdimm

Provide a common C api for tests to locate an "memmap=ss!nn" defined
namespace for destructive tests.

Signed-off-by: Dan Williams <dan.j.williams@intel.com>
---
 test.h         |    3 ++-
 test/dax-dev.c |   42 +++++++++++++++++++++++++++---------------
 2 files changed, 29 insertions(+), 16 deletions(-)

diff --git a/test.h b/test.h
index 1ac03aa09762..120798f2dd75 100644
--- a/test.h
+++ b/test.h
@@ -1,7 +1,7 @@
 #ifndef __TEST_H__
 #define __TEST_H__
 struct ndctl_test;
-struct ndctl_test;
+struct ndctl_ctx;
 struct ndctl_test *ndctl_test_new(unsigned int kver);
 int ndctl_test_result(struct ndctl_test *test, int rc);
 int ndctl_test_get_skipped(struct ndctl_test *test);
@@ -11,6 +11,7 @@ int __ndctl_test_attempt(struct ndctl_test *test, unsigned int kver,
 #define ndctl_test_attempt(t, v) __ndctl_test_attempt(t, v, __func__, __LINE__)
 void __ndctl_test_skip(struct ndctl_test *test, const char *caller, int line);
 #define ndctl_test_skip(t) __ndctl_test_skip(t, __func__, __LINE__)
+struct ndctl_namespace *ndctl_get_test_dev(struct ndctl_ctx *ctx);
 
 struct ndctl_ctx;
 int test_parent_uuid(int loglevel, struct ndctl_test *test, struct ndctl_ctx *ctx);
diff --git a/test/dax-dev.c b/test/dax-dev.c
index 519df324fdc8..0183b7af2052 100755
--- a/test/dax-dev.c
+++ b/test/dax-dev.c
@@ -25,12 +25,11 @@
 #include <linux/version.h>
 #include <ndctl/libndctl.h>
 
-static int emit_e820_device(int loglevel, struct ndctl_test *test)
+struct ndctl_namespace *ndctl_get_test_dev(struct ndctl_ctx *ctx)
 {
-	int err, fd;
 	char path[256];
 	const char *bdev;
-	struct ndctl_ctx *ctx;
+	int fd, rc = -ENXIO;
 	struct ndctl_bus *bus;
 	struct ndctl_dax *dax;
 	struct ndctl_pfn *pfn;
@@ -38,15 +37,6 @@ static int emit_e820_device(int loglevel, struct ndctl_test *test)
 	struct ndctl_namespace *ndns;
 	enum ndctl_namespace_mode mode;
 
-	if (!ndctl_test_attempt(test, KERNEL_VERSION(4, 3, 0)))
-		return 77;
-
-	err = ndctl_new(&ctx);
-	if (err < 0)
-		return err;
-
-	ndctl_set_log_priority(ctx, loglevel);
-	err = -ENXIO;
 	bus = ndctl_bus_get_by_provider(ctx, "e820");
 	if (!bus)
 		goto out;
@@ -85,16 +75,38 @@ static int emit_e820_device(int loglevel, struct ndctl_test *test)
 	fd = open(path, O_RDWR | O_EXCL);
 	if (fd < 0)
 		goto out;
-	err = 0;
+	close(fd);
+	rc = 0;
 
  out:
-	if (err) {
+	return rc ? NULL : ndns;
+}
+
+static int emit_e820_device(int loglevel, struct ndctl_test *test)
+{
+	int err;
+	struct ndctl_ctx *ctx;
+	struct ndctl_namespace *ndns;
+
+	if (!ndctl_test_attempt(test, KERNEL_VERSION(4, 3, 0)))
+		return 77;
+
+	err = ndctl_new(&ctx);
+	if (err < 0)
+		return err;
+
+	ndctl_set_log_priority(ctx, loglevel);
+
+	ndns = ndctl_get_test_dev(ctx);
+	if (!ndns) {
 		fprintf(stderr, "%s: failed to find usable victim device\n",
 				__func__);
 		ndctl_test_skip(test);
 		err = 77;
-	} else
+	} else {
 		fprintf(stdout, "%s\n", ndctl_namespace_get_devname(ndns));
+		err = 0;
+	}
 	ndctl_unref(ctx);
 	return err;
 }

_______________________________________________
Linux-nvdimm mailing list
Linux-nvdimm@lists.01.org
https://lists.01.org/mailman/listinfo/linux-nvdimm

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [ndctl PATCH 6/8] test, create-namespace: reset global data
  2016-08-16 17:21 [ndctl PATCH 0/8] ndctl: device-dax tests Dan Williams
                   ` (4 preceding siblings ...)
  2016-08-16 17:21 ` [ndctl PATCH 5/8] test: refactor / export ndctl_get_test_dev() Dan Williams
@ 2016-08-16 17:21 ` Dan Williams
  2016-08-16 17:22 ` [ndctl PATCH 7/8] test: convert device-dax test from shell to C Dan Williams
  2016-08-16 17:22 ` [ndctl PATCH 8/8] test, device-dax: check mappings invalidated on namespace reconfiguration Dan Williams
  7 siblings, 0 replies; 9+ messages in thread
From: Dan Williams @ 2016-08-16 17:21 UTC (permalink / raw)
  To: linux-nvdimm

Before we add unit tests that call cmd_create_namespace() directly, we
need to ensure that consecutive calls to cmd_create_namespace() behave
the same as consecutive invocations of 'ndctl create-namespace'. I.e.
re-initialize global parameter to zero.

Signed-off-by: Dan Williams <dan.j.williams@intel.com>
---
 ndctl/builtin-xaction-namespace.c |   12 ++++++++++++
 test.h                            |    1 +
 2 files changed, 13 insertions(+)

diff --git a/ndctl/builtin-xaction-namespace.c b/ndctl/builtin-xaction-namespace.c
index 12ade241ff64..13811ea22da1 100644
--- a/ndctl/builtin-xaction-namespace.c
+++ b/ndctl/builtin-xaction-namespace.c
@@ -51,6 +51,18 @@ static struct parameters {
 	const char *sector_size;
 } param;
 
+void builtin_xaction_namespace_reset(void)
+{
+	/*
+	 * Initialize parameter data for the unit test case where
+	 * multiple calls to cmd_<action>_namespace() are made without
+	 * an intervening exit().
+	 */
+	verbose = false;
+	force = false;
+	memset(&param, 0, sizeof(param));
+}
+
 #define NSLABEL_NAME_LEN 64
 struct parsed_parameters {
 	enum ndctl_pfn_loc loc;
diff --git a/test.h b/test.h
index 120798f2dd75..331d4131e2c7 100644
--- a/test.h
+++ b/test.h
@@ -12,6 +12,7 @@ int __ndctl_test_attempt(struct ndctl_test *test, unsigned int kver,
 void __ndctl_test_skip(struct ndctl_test *test, const char *caller, int line);
 #define ndctl_test_skip(t) __ndctl_test_skip(t, __func__, __LINE__)
 struct ndctl_namespace *ndctl_get_test_dev(struct ndctl_ctx *ctx);
+void builtin_xaction_namespace_reset(void);
 
 struct ndctl_ctx;
 int test_parent_uuid(int loglevel, struct ndctl_test *test, struct ndctl_ctx *ctx);

_______________________________________________
Linux-nvdimm mailing list
Linux-nvdimm@lists.01.org
https://lists.01.org/mailman/listinfo/linux-nvdimm

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [ndctl PATCH 7/8] test: convert device-dax test from shell to C
  2016-08-16 17:21 [ndctl PATCH 0/8] ndctl: device-dax tests Dan Williams
                   ` (5 preceding siblings ...)
  2016-08-16 17:21 ` [ndctl PATCH 6/8] test, create-namespace: reset global data Dan Williams
@ 2016-08-16 17:22 ` Dan Williams
  2016-08-16 17:22 ` [ndctl PATCH 8/8] test, device-dax: check mappings invalidated on namespace reconfiguration Dan Williams
  7 siblings, 0 replies; 9+ messages in thread
From: Dan Williams @ 2016-08-16 17:22 UTC (permalink / raw)
  To: linux-nvdimm

In preparation for expanded device-dax unit tests, convert the existing
implementation to be entirely C-based.

Signed-off-by: Dan Williams <dan.j.williams@intel.com>
---
 test/Makefile.am   |   13 ++++-
 test/device-dax.c  |  128 ++++++++++++++++++++++++++++++++++++++++++++++------
 test/device-dax.sh |   40 ----------------
 3 files changed, 124 insertions(+), 57 deletions(-)
 delete mode 100755 test/device-dax.sh

diff --git a/test/Makefile.am b/test/Makefile.am
index ab566148e1f4..d13c138bb28a 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -20,7 +20,7 @@ TESTS +=\
 	pmem-ns \
 	dax-dev \
 	dax.sh \
-	device-dax.sh \
+	device-dax \
 	mmap.sh
 
 check_PROGRAMS +=\
@@ -57,4 +57,13 @@ dax_dev_LDADD = $(LIBNDCTL_LIB)
 dax_pmd_SOURCES = dax-pmd.c
 mmap_SOURCES = mmap.c
 dax_errors_SOURCES = dax-errors.c
-device_dax_SOURCES = device-dax.c
+device_dax_SOURCES = \
+		device-dax.c \
+		dax-dev.c \
+		core.c \
+		../ndctl/builtin-xaction-namespace.c \
+		../ndctl/util/json.c
+device_dax_LDADD = \
+		$(LIBNDCTL_LIB) \
+		$(JSON_LIBS) \
+		../libutil.a
diff --git a/test/device-dax.c b/test/device-dax.c
index addf93f59252..7b624ea5bc8f 100644
--- a/test/device-dax.c
+++ b/test/device-dax.c
@@ -1,32 +1,130 @@
-#include <sys/mman.h>
-#include <sys/types.h>
-#include <sys/stat.h>
 #include <fcntl.h>
-#include <linux/falloc.h>
 #include <stdio.h>
-#include <string.h>
 #include <errno.h>
 #include <unistd.h>
+#include <stdlib.h>
+#include <syslog.h>
+#include <string.h>
+#include <sys/stat.h>
+#include <sys/mman.h>
+#include <sys/types.h>
+#include <linux/falloc.h>
+#include <linux/version.h>
+#include <ndctl/libndctl.h>
+#include <daxctl/libdaxctl.h>
+#include <ccan/array_size/array_size.h>
+
+#include <ndctl/builtin.h>
+#include <test.h>
+
+static int create_namespace(int argc, const char **argv, struct ndctl_ctx *ctx)
+{
+	builtin_xaction_namespace_reset();
+	return cmd_create_namespace(argc, argv, ctx);
+}
+
+static int reset_device_dax(struct ndctl_namespace *ndns)
+{
+	struct ndctl_ctx *ctx = ndctl_namespace_get_ctx(ndns);
+	const char *argv[] = {
+		"__func__", "-v", "-m", "raw", "-f", "-e", "",
+	};
+	int argc = ARRAY_SIZE(argv);
+
+	argv[argc - 1] = ndctl_namespace_get_devname(ndns);
+	return create_namespace(argc, argv, ctx);
+}
+
+static int setup_device_dax(struct ndctl_namespace *ndns)
+{
+	struct ndctl_ctx *ctx = ndctl_namespace_get_ctx(ndns);
+	const char *argv[] = {
+		"__func__", "-v", "-m", "dax", "-M", "dev", "-f", "-e", "",
+	};
+	int argc = ARRAY_SIZE(argv);
+
+	argv[argc - 1] = ndctl_namespace_get_devname(ndns);
+	return create_namespace(argc, argv, ctx);
+}
 
-int main(int argc, char *argv[])
+static int test_device_dax(int loglevel, struct ndctl_test *test,
+		struct ndctl_ctx *ctx)
 {
-	char *buf;
-	int fd;
+	int fd, rc, *p;
+	char *buf, path[100];
+	struct ndctl_dax *dax;
+	struct daxctl_dev *dev;
+	struct ndctl_namespace *ndns;
+	struct daxctl_region *dax_region;
+
+	if (!ndctl_test_attempt(test, KERNEL_VERSION(4, 7, 0)))
+		return 77;
+
+	ndctl_set_log_priority(ctx, loglevel);
 
-	if (argc < 2) {
-		perror("argc invalid");
-		return -EINVAL;
+	ndns = ndctl_get_test_dev(ctx);
+	if (!ndns) {
+		fprintf(stderr, "%s: failed to find suitable namespace\n",
+				__func__);
+		return 77;
 	}
 
-	fd = open(argv[1], O_RDWR);
+	rc = setup_device_dax(ndns);
+	if (rc < 0) {
+		fprintf(stderr, "%s: failed device-dax setup\n",
+				ndctl_namespace_get_devname(ndns));
+		return rc;
+	}
+
+	dax = ndctl_namespace_get_dax(ndns);
+	dax_region = ndctl_dax_get_daxctl_region(dax);
+	dev = daxctl_dev_get_first(dax_region);
+	if (!dev) {
+		fprintf(stderr, "%s: failed to find device-dax instance\n",
+				ndctl_namespace_get_devname(ndns));
+		return -ENXIO;
+	}
+
+	sprintf(path, "/dev/%s", daxctl_dev_get_devname(dev));
+
+	fd = open(path, O_RDWR);
 	if (fd < 0) {
-		perror("fd");
-		return 1;
+		fprintf(stderr, "%s: failed to open device-dax instance\n",
+				daxctl_dev_get_devname(dev));
+		return -ENXIO;
 	}
 
 	buf = mmap(NULL, 2UL << 20, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0);
-	*((int *) (buf + (1UL << 20))) = 0;
+	p = (int *) (buf + (1UL << 20));
+	*p = 0;
+
+	rc = reset_device_dax(ndns);
+	if (rc < 0) {
+		fprintf(stderr, "%s: failed to reset device-dax instance\n",
+				ndctl_namespace_get_devname(ndns));
+		return rc;
+	}
 
 	close(fd);
 	return 0;
 }
+
+int __attribute__((weak)) main(int argc, char *argv[])
+{
+	struct ndctl_test *test = ndctl_test_new(0);
+	struct ndctl_ctx *ctx;
+	int rc;
+
+	if (!test) {
+		fprintf(stderr, "failed to initialize test\n");
+		return EXIT_FAILURE;
+	}
+
+	rc = ndctl_new(&ctx);
+	if (rc < 0)
+		return ndctl_test_result(test, rc);
+
+	rc = test_device_dax(LOG_DEBUG, test, ctx);
+	ndctl_unref(ctx);
+	return ndctl_test_result(test, rc);
+}
diff --git a/test/device-dax.sh b/test/device-dax.sh
deleted file mode 100755
index 6bc724fe7c95..000000000000
--- a/test/device-dax.sh
+++ /dev/null
@@ -1,40 +0,0 @@
-#!/bin/bash
-NDCTL="../ndctl/ndctl"
-json2var="s/[{}\",]//g; s/:/=/g; s/\]//g"
-rc=77
-
-err() {
-	rc=$?
-	echo "device-dax: failed at line $1"
-	exit $rc
-}
-
-eval $(uname -r | awk -F. '{print "maj="$1 ";" "min="$2}')
-if [ $maj -lt 4 ]; then
-	echo "kernel $maj.$min lacks device-dax"
-	exit $rc
-elif [ $maj -eq 4 -a $min -lt 7 ]; then
-	echo "kernel $maj.$min lacks device-dax"
-	exit $rc
-fi
-
-set -e -x
-trap 'err $LINENO' ERR
-
-dev=$(./dax-dev)
-json=$($NDCTL list -N -n $dev)
-eval $(echo $json | sed -e "$json2var")
-
-# setup a device-dax configuration
-json=$($NDCTL create-namespace -v -m dax -M dev -f -e $dev)
-eval $(echo $json | sed -e "$json2var")
-[ $mode != "dax" ] && echo "fail: $LINENO" &&  exit 1
-
-./device-dax /dev/$chardev
-
-# revert namespace to raw mode
-json=$($NDCTL create-namespace -v -m raw -f -e $dev)
-eval $(echo $json | sed -e "$json2var")
-[ $mode != "memory" ] && echo "fail: $LINENO" &&  exit 1
-
-exit 0

_______________________________________________
Linux-nvdimm mailing list
Linux-nvdimm@lists.01.org
https://lists.01.org/mailman/listinfo/linux-nvdimm

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [ndctl PATCH 8/8] test, device-dax: check mappings invalidated on namespace reconfiguration
  2016-08-16 17:21 [ndctl PATCH 0/8] ndctl: device-dax tests Dan Williams
                   ` (6 preceding siblings ...)
  2016-08-16 17:22 ` [ndctl PATCH 7/8] test: convert device-dax test from shell to C Dan Williams
@ 2016-08-16 17:22 ` Dan Williams
  7 siblings, 0 replies; 9+ messages in thread
From: Dan Williams @ 2016-08-16 17:22 UTC (permalink / raw)
  To: linux-nvdimm

Validate that the kernel does not leak mappings past the end of life of
the namespace device.  I.e. ndctl_dax_delete() == "mappings return
SIGBUS".

Signed-off-by: Dan Williams <dan.j.williams@intel.com>
---
 test/device-dax.c |   31 ++++++++++++++++++++++++++++++-
 1 file changed, 30 insertions(+), 1 deletion(-)

diff --git a/test/device-dax.c b/test/device-dax.c
index 7b624ea5bc8f..1a67a27ab134 100644
--- a/test/device-dax.c
+++ b/test/device-dax.c
@@ -5,6 +5,8 @@
 #include <stdlib.h>
 #include <syslog.h>
 #include <string.h>
+#include <signal.h>
+#include <setjmp.h>
 #include <sys/stat.h>
 #include <sys/mman.h>
 #include <sys/types.h>
@@ -17,6 +19,8 @@
 #include <ndctl/builtin.h>
 #include <test.h>
 
+static sigjmp_buf sj_env;
+
 static int create_namespace(int argc, const char **argv, struct ndctl_ctx *ctx)
 {
 	builtin_xaction_namespace_reset();
@@ -47,16 +51,31 @@ static int setup_device_dax(struct ndctl_namespace *ndns)
 	return create_namespace(argc, argv, ctx);
 }
 
+static void sigbus(int sig, siginfo_t *siginfo, void *d)
+{
+	siglongjmp(sj_env, 1);
+}
+
 static int test_device_dax(int loglevel, struct ndctl_test *test,
 		struct ndctl_ctx *ctx)
 {
 	int fd, rc, *p;
 	char *buf, path[100];
+	struct sigaction act;
 	struct ndctl_dax *dax;
 	struct daxctl_dev *dev;
 	struct ndctl_namespace *ndns;
 	struct daxctl_region *dax_region;
 
+	memset (&act, 0, sizeof(act));
+	act.sa_sigaction = sigbus;
+	act.sa_flags = SA_SIGINFO;
+
+	if (sigaction(SIGBUS, &act, 0)) {
+		perror("sigaction");
+		return 1;
+	}
+
 	if (!ndctl_test_attempt(test, KERNEL_VERSION(4, 7, 0)))
 		return 77;
 
@@ -105,8 +124,18 @@ static int test_device_dax(int loglevel, struct ndctl_test *test,
 		return rc;
 	}
 
+	/* test fault after device-dax instance disabled */
+	if (sigsetjmp(sj_env, 1)) {
+		/* got sigbus, success */
+		close(fd);
+		return 0;
+	}
+
+	*p = 0xff;
+	fprintf(stderr, "%s: failed to unmap after reset\n",
+			daxctl_dev_get_devname(dev));
 	close(fd);
-	return 0;
+	return EXIT_FAILURE;
 }
 
 int __attribute__((weak)) main(int argc, char *argv[])

_______________________________________________
Linux-nvdimm mailing list
Linux-nvdimm@lists.01.org
https://lists.01.org/mailman/listinfo/linux-nvdimm

^ permalink raw reply related	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2016-08-16 17:24 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-08-16 17:21 [ndctl PATCH 0/8] ndctl: device-dax tests Dan Williams
2016-08-16 17:21 ` [ndctl PATCH 1/8] ndctl: centralize libndctl context init across commands Dan Williams
2016-08-16 17:21 ` [ndctl PATCH 2/8] libdaxctl: add daxctl_region_get_available_size() Dan Williams
2016-08-16 17:21 ` [ndctl PATCH 3/8] libdaxctl: add daxctl_region_get_seed() Dan Williams
2016-08-16 17:21 ` [ndctl PATCH 4/8] test: teach test/libndctl about device-dax seeds Dan Williams
2016-08-16 17:21 ` [ndctl PATCH 5/8] test: refactor / export ndctl_get_test_dev() Dan Williams
2016-08-16 17:21 ` [ndctl PATCH 6/8] test, create-namespace: reset global data Dan Williams
2016-08-16 17:22 ` [ndctl PATCH 7/8] test: convert device-dax test from shell to C Dan Williams
2016-08-16 17:22 ` [ndctl PATCH 8/8] test, device-dax: check mappings invalidated on namespace reconfiguration Dan Williams

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).