All of lore.kernel.org
 help / color / mirror / Atom feed
* [ndctl PATCH 0/3] ndctl disable-dimm and label-read-failure unit test
@ 2016-09-14  1:00 Dan Williams
  2016-09-14  1:00 ` [ndctl PATCH 1/3] ndctl: {enable|disable}-dimm commands Dan Williams
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Dan Williams @ 2016-09-14  1:00 UTC (permalink / raw)
  To: linux-nvdimm

We recently discovered that the kernel does not properly check and fail
unknown status results in DSM commands.  This highlighted a larger
concern that we expect the kernel to fail regions when one of the
required dimm-label-areas is unavailable.

- Add ndctl commands for disabling/enabling dimms as helper for cases
  where a platform owner wants to refresh the driver's cached copy of
  the labels.

- Add a new unit test to validate that when a disabled dimm is detected
  any attempt to enable a related region fails.

- Fix up the build system to allow util/log.c and util/sysfs.c to be
  used in tests as well as the libraries.

---

Dan Williams (3):
      ndctl: {enable|disable}-dimm commands
      build: build libraries and utilities in separate directories
      test, dsm-fail: test get_config_size DSM failures


 Documentation/Makefile.am            |    4 +
 Documentation/dimm-description.txt   |   15 ++
 Documentation/ndctl-disable-dimm.txt |   22 +++
 Documentation/ndctl-enable-dimm.txt  |   22 +++
 Documentation/xable-dimm-options.txt |    9 +
 Makefile.am                          |    2 
 configure.ac                         |    3 
 daxctl/Makefile.am                   |   27 ----
 daxctl/lib/Makefile.am               |   28 ++++
 ndctl/Makefile.am                    |   51 +-------
 ndctl/builtin-test.c                 |    5 +
 ndctl/builtin-xable-dimm.c           |  115 ++++++++++++++++++
 ndctl/builtin.h                      |    2 
 ndctl/lib/Makefile.am                |   46 +++++++
 ndctl/ndctl.c                        |    2 
 test.h                               |    1 
 test/Makefile.am                     |   10 ++
 test/dsm-fail.c                      |  216 ++++++++++++++++++++++++++++++++++
 18 files changed, 504 insertions(+), 76 deletions(-)
 create mode 100644 Documentation/dimm-description.txt
 create mode 100644 Documentation/ndctl-disable-dimm.txt
 create mode 100644 Documentation/ndctl-enable-dimm.txt
 create mode 100644 Documentation/xable-dimm-options.txt
 delete mode 100644 daxctl/Makefile.am
 create mode 100644 daxctl/lib/Makefile.am
 create mode 100644 ndctl/builtin-xable-dimm.c
 create mode 100644 ndctl/lib/Makefile.am
 create mode 100644 test/dsm-fail.c
_______________________________________________
Linux-nvdimm mailing list
Linux-nvdimm@lists.01.org
https://lists.01.org/mailman/listinfo/linux-nvdimm

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

* [ndctl PATCH 1/3] ndctl: {enable|disable}-dimm commands
  2016-09-14  1:00 [ndctl PATCH 0/3] ndctl disable-dimm and label-read-failure unit test Dan Williams
@ 2016-09-14  1:00 ` Dan Williams
  2016-09-14  1:00 ` [ndctl PATCH 2/3] build: build libraries and utilities in separate directories Dan Williams
  2016-09-14  1:00 ` [ndctl PATCH 3/3] test, dsm-fail: test get_config_size DSM failures Dan Williams
  2 siblings, 0 replies; 4+ messages in thread
From: Dan Williams @ 2016-09-14  1:00 UTC (permalink / raw)
  To: linux-nvdimm

Similar to ndctl {enable|disable}-region it may be useful to disable and
re-enable a dimm.  This refreshes the kernel's cached copy of a namespace
label, provided that any regions that the dimm contributes to have also been
disabled.

Cc: Vishal Verma <vishal.l.verma@intel.com>
Signed-off-by: Dan Williams <dan.j.williams@intel.com>
---
 Documentation/Makefile.am            |    4 +
 Documentation/dimm-description.txt   |   15 ++++
 Documentation/ndctl-disable-dimm.txt |   22 +++++++
 Documentation/ndctl-enable-dimm.txt  |   22 +++++++
 Documentation/xable-dimm-options.txt |    9 +++
 ndctl/Makefile.am                    |    1 
 ndctl/builtin-xable-dimm.c           |  115 ++++++++++++++++++++++++++++++++++
 ndctl/builtin.h                      |    2 +
 ndctl/ndctl.c                        |    2 +
 9 files changed, 192 insertions(+)
 create mode 100644 Documentation/dimm-description.txt
 create mode 100644 Documentation/ndctl-disable-dimm.txt
 create mode 100644 Documentation/ndctl-enable-dimm.txt
 create mode 100644 Documentation/xable-dimm-options.txt
 create mode 100644 ndctl/builtin-xable-dimm.c

diff --git a/Documentation/Makefile.am b/Documentation/Makefile.am
index f0593e4fc7eb..63ef1ce7f2d7 100644
--- a/Documentation/Makefile.am
+++ b/Documentation/Makefile.am
@@ -4,6 +4,8 @@ man1_MANS = \
 	ndctl-read-labels.1 \
 	ndctl-enable-region.1 \
 	ndctl-disable-region.1 \
+	ndctl-enable-dimm.1 \
+	ndctl-disable-dimm.1 \
 	ndctl-enable-namespace.1 \
 	ndctl-disable-namespace.1 \
 	ndctl-create-namespace.1 \
@@ -17,6 +19,8 @@ XML_DEPS = \
 	Makefile \
 	region-description.txt \
 	xable-region-options.txt \
+	dimm-description.txt \
+	xable-dimm-options.txt \
 	xable-namespace-options.txt \
 	labels-description.txt \
 	labels-options.txt
diff --git a/Documentation/dimm-description.txt b/Documentation/dimm-description.txt
new file mode 100644
index 000000000000..95d0891c0b13
--- /dev/null
+++ b/Documentation/dimm-description.txt
@@ -0,0 +1,15 @@
+DESCRIPTION
+-----------
+A generic DIMM device object, named /dev/nmemX, is registered for each
+memory device indicated in the ACPI NFIT table, or other platform NVDIMM
+resource discovery mechanism.  The LIBNVDIMM core provides a built-in
+driver for these DIMM devices.  The driver is responsible for
+determining if the DIMM implements a namespace label area, and
+initializing the kernel's in-memory copy of that label data.
+
+The kernel performs runtime modifications of that data when namespace
+provisioning actions are taken, and actively blocks userspace from
+initiating label data changes while the DIMM is active in any region.
+Disabling a DIMM, after all the regions it is a member of have been
+disabled, allows userspace to manually update the label data to be
+consumed when the DIMM is next enabled.
diff --git a/Documentation/ndctl-disable-dimm.txt b/Documentation/ndctl-disable-dimm.txt
new file mode 100644
index 000000000000..b87314ffd197
--- /dev/null
+++ b/Documentation/ndctl-disable-dimm.txt
@@ -0,0 +1,22 @@
+ndctl-disable-dimm(1)
+=======================
+
+NAME
+----
+ndctl-disable-dimm - disable one or more idle dimms
+
+SYNOPSIS
+--------
+[verse]
+'ndctl disable-dimm' <dimm> [<options>]
+
+include::dimm-description.txt[]
+
+OPTIONS
+-------
+<dimm>::
+include::xable-dimm-options.txt[]
+
+SEE ALSO
+--------
+linkndctl:ndctl-enable-dimm[1]
diff --git a/Documentation/ndctl-enable-dimm.txt b/Documentation/ndctl-enable-dimm.txt
new file mode 100644
index 000000000000..0b0c6e0c965e
--- /dev/null
+++ b/Documentation/ndctl-enable-dimm.txt
@@ -0,0 +1,22 @@
+ndctl-enable-dimm(1)
+====================
+
+NAME
+----
+ndctl-enable-dimm - enable one more dimms
+
+SYNOPSIS
+--------
+[verse]
+'ndctl enable-dimm' <dimm> [<options>]
+
+include::dimm-description.txt[]
+
+OPTIONS
+-------
+<dimm>::
+include::xable-dimm-options.txt[]
+
+SEE ALSO
+--------
+linkndctl:ndctl-disable-dimm[1]
diff --git a/Documentation/xable-dimm-options.txt b/Documentation/xable-dimm-options.txt
new file mode 100644
index 000000000000..ad79208a61eb
--- /dev/null
+++ b/Documentation/xable-dimm-options.txt
@@ -0,0 +1,9 @@
+	A 'nmemX' device name, or a dimm id number. The keyword 'all' can
+	be specified to carry out the operation on every dimm in the system,
+	optionally filtered by bus id (see --bus= option).
+
+-b::
+--bus=::
+	Enforce that the operation only be carried on devices that are
+	attached to the given bus. Where 'bus' can be a provider name or a bus
+	id number.
diff --git a/ndctl/Makefile.am b/ndctl/Makefile.am
index 04f3a63ff999..f7d0a96af4f9 100644
--- a/ndctl/Makefile.am
+++ b/ndctl/Makefile.am
@@ -39,6 +39,7 @@ ndctl_SOURCES = ndctl.c \
 		builtin-create-nfit.c \
 		builtin-xaction-namespace.c \
 		builtin-xable-region.c \
+		builtin-xable-dimm.c \
 		builtin-list.c \
 		builtin-test.c \
 		builtin-help.c \
diff --git a/ndctl/builtin-xable-dimm.c b/ndctl/builtin-xable-dimm.c
new file mode 100644
index 000000000000..4bdbc7f8eea3
--- /dev/null
+++ b/ndctl/builtin-xable-dimm.c
@@ -0,0 +1,115 @@
+#include <stdio.h>
+#include <errno.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <util/filter.h>
+#include <util/parse-options.h>
+#include <ndctl/libndctl.h>
+
+static const char *dimm_bus;
+
+static const struct option dimm_options[] = {
+	OPT_STRING('b', "bus", &dimm_bus, "bus-id",
+			"<dimm> must be on a bus with an id/provider of <bus-id>"),
+	OPT_END(),
+};
+
+static const char *parse_dimm_options(int argc, const char **argv,
+		char *xable_usage)
+{
+	const char * const u[] = {
+		xable_usage,
+		NULL
+	};
+	int i;
+
+        argc = parse_options(argc, argv, dimm_options, u, 0);
+
+	if (argc == 0)
+		error("specify a dimm to disable, or \"all\"\n");
+	for (i = 1; i < argc; i++)
+		error("unknown extra parameter \"%s\"\n", argv[i]);
+	if (argc == 0 || argc > 1) {
+		usage_with_options(u, dimm_options);
+		return NULL; /* we won't return from usage_with_options() */
+	}
+	return argv[0];
+}
+
+static int do_xable_dimm(const char *dimm_arg,
+		int (*xable_fn)(struct ndctl_dimm *), struct ndctl_ctx *ctx)
+{
+	int rc = -ENXIO, skip = 0, success = 0;
+	struct ndctl_dimm *dimm;
+	struct ndctl_bus *bus;
+
+	if (!dimm_arg)
+		goto out;
+
+        ndctl_bus_foreach(ctx, bus) {
+		if (!util_bus_filter(bus, dimm_bus))
+			continue;
+
+		ndctl_dimm_foreach(bus, dimm) {
+			if (!util_dimm_filter(dimm, dimm_arg))
+				continue;
+			if (xable_fn == ndctl_dimm_disable
+					&& ndctl_dimm_is_active(dimm)) {
+				fprintf(stderr, "%s is active, skipping...\n",
+						ndctl_dimm_get_devname(dimm));
+				skip++;
+				continue;
+			}
+			if (xable_fn(dimm) == 0)
+				success++;
+		}
+	}
+
+	rc = success;
+	if (!success && skip)
+		rc = EBUSY;
+ out:
+	dimm_bus = NULL;
+	return rc;
+}
+
+int cmd_disable_dimm(int argc, const char **argv, struct ndctl_ctx *ctx)
+{
+	char *xable_usage = "ndctl disable-dimm <dimm> [<options>]";
+	const char *dimm = parse_dimm_options(argc, argv, xable_usage);
+	int disabled = do_xable_dimm(dimm, ndctl_dimm_disable,
+			ctx);
+
+	if (disabled < 0) {
+		fprintf(stderr, "error disabling dimms: %s\n",
+				strerror(-disabled));
+		return disabled;
+	} else if (disabled == 0) {
+		fprintf(stderr, "disabled 0 dimms\n");
+		return 0;
+	} else {
+		fprintf(stderr, "disabled %d dimm%s\n", disabled,
+				disabled > 1 ? "s" : "");
+		return 0;
+	}
+}
+
+int cmd_enable_dimm(int argc, const char **argv, struct ndctl_ctx *ctx)
+{
+	char *xable_usage = "ndctl enable-dimm <dimm> [<options>]";
+	const char *dimm = parse_dimm_options(argc, argv, xable_usage);
+	int enabled = do_xable_dimm(dimm, ndctl_dimm_enable, ctx);
+
+	if (enabled < 0) {
+		fprintf(stderr, "error enabling dimms: %s\n",
+				strerror(-enabled));
+		return enabled;
+	} else if (enabled == 0) {
+		fprintf(stderr, "enabled 0 dimms\n");
+		return 0;
+	} else {
+		fprintf(stderr, "enabled %d dimm%s\n", enabled,
+				enabled > 1 ? "s" : "");
+		return 0;
+	}
+}
diff --git a/ndctl/builtin.h b/ndctl/builtin.h
index 46cd5d2d439c..ec55865ecea8 100644
--- a/ndctl/builtin.h
+++ b/ndctl/builtin.h
@@ -16,6 +16,8 @@ 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_enable_dimm(int argc, const char **argv, struct ndctl_ctx *ctx);
+int cmd_disable_dimm(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);
diff --git a/ndctl/ndctl.c b/ndctl/ndctl.c
index 77f90d6087ba..aaeb3f7c2bec 100644
--- a/ndctl/ndctl.c
+++ b/ndctl/ndctl.c
@@ -32,6 +32,8 @@ static struct cmd_struct commands[] = {
 	{ "destroy-namespace", cmd_destroy_namespace },
 	{ "enable-region", cmd_enable_region },
 	{ "disable-region", cmd_disable_region },
+	{ "enable-dimm", cmd_enable_dimm },
+	{ "disable-dimm", cmd_disable_dimm },
 	{ "zero-labels", cmd_zero_labels },
 	{ "read-labels", cmd_read_labels },
 	{ "list", cmd_list },

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

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

* [ndctl PATCH 2/3] build: build libraries and utilities in separate directories
  2016-09-14  1:00 [ndctl PATCH 0/3] ndctl disable-dimm and label-read-failure unit test Dan Williams
  2016-09-14  1:00 ` [ndctl PATCH 1/3] ndctl: {enable|disable}-dimm commands Dan Williams
@ 2016-09-14  1:00 ` Dan Williams
  2016-09-14  1:00 ` [ndctl PATCH 3/3] test, dsm-fail: test get_config_size DSM failures Dan Williams
  2 siblings, 0 replies; 4+ messages in thread
From: Dan Williams @ 2016-09-14  1:00 UTC (permalink / raw)
  To: linux-nvdimm

When trying to add an "ndctl test" user of the util/log.c and
util/sysfs.c routines, automake complained about util/log.o being
already built for a library when trying to include it in the utility.
Move the library build into ndctl/lib/ rather than re-using ndctl/.

Signed-off-by: Dan Williams <dan.j.williams@intel.com>
---
 Makefile.am            |    2 +-
 configure.ac           |    3 ++-
 daxctl/Makefile.am     |   27 ---------------------------
 daxctl/lib/Makefile.am |   28 ++++++++++++++++++++++++++++
 ndctl/Makefile.am      |   47 -----------------------------------------------
 ndctl/lib/Makefile.am  |   46 ++++++++++++++++++++++++++++++++++++++++++++++
 6 files changed, 77 insertions(+), 76 deletions(-)
 delete mode 100644 daxctl/Makefile.am
 create mode 100644 daxctl/lib/Makefile.am
 create mode 100644 ndctl/lib/Makefile.am

diff --git a/Makefile.am b/Makefile.am
index ce1032e3381d..9eb396639efe 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -1,7 +1,7 @@
 include Makefile.am.in
 
 ACLOCAL_AMFLAGS = -I m4 ${ACLOCAL_FLAGS}
-SUBDIRS = . daxctl ndctl
+SUBDIRS = . daxctl/lib ndctl/lib ndctl
 if ENABLE_DOCS
 SUBDIRS += Documentation
 endif
diff --git a/configure.ac b/configure.ac
index 7bc97be9039d..7b4af616cf2b 100644
--- a/configure.ac
+++ b/configure.ac
@@ -260,7 +260,8 @@ AC_SUBST([my_CFLAGS])
 AC_CONFIG_HEADERS(config.h)
 AC_CONFIG_FILES([
         Makefile
-        daxctl/Makefile
+        daxctl/lib/Makefile
+        ndctl/lib/Makefile
         ndctl/Makefile
         test/Makefile
         Documentation/Makefile
diff --git a/daxctl/Makefile.am b/daxctl/Makefile.am
deleted file mode 100644
index 67ae5aed4a18..000000000000
--- a/daxctl/Makefile.am
+++ /dev/null
@@ -1,27 +0,0 @@
-include $(top_srcdir)/Makefile.am.in
-
-%.pc: %.pc.in Makefile
-	$(SED_PROCESS)
-
-lib_LTLIBRARIES = lib/libdaxctl.la
-
-lib_libdaxctl_la_SOURCES =\
-	libdaxctl.h \
-	lib/libdaxctl-private.h \
-	../util/sysfs.c \
-	../util/sysfs.h \
-	../util/log.c \
-	../util/log.h \
-	lib/libdaxctl.c
-
-EXTRA_DIST += lib/libdaxctl.sym
-
-lib_libdaxctl_la_LDFLAGS = $(AM_LDFLAGS) \
-	-version-info $(LIBDAXCTL_CURRENT):$(LIBDAXCTL_REVISION):$(LIBDAXCTL_AGE) \
-	-Wl,--version-script=$(top_srcdir)/daxctl/lib/libdaxctl.sym
-lib_libdaxctl_la_DEPENDENCIES = lib/libdaxctl.sym
-
-pkgconfigdir = $(libdir)/pkgconfig
-pkgconfig_DATA = lib/libdaxctl.pc
-EXTRA_DIST += lib/libdaxctl.pc.in
-CLEANFILES += lib/libdaxctl.pc
diff --git a/daxctl/lib/Makefile.am b/daxctl/lib/Makefile.am
new file mode 100644
index 000000000000..92783847266a
--- /dev/null
+++ b/daxctl/lib/Makefile.am
@@ -0,0 +1,28 @@
+include $(top_srcdir)/Makefile.am.in
+
+%.pc: %.pc.in Makefile
+	$(SED_PROCESS)
+
+pkginclude_HEADERS = ../libdaxctl.h
+lib_LTLIBRARIES = libdaxctl.la
+
+libdaxctl_la_SOURCES =\
+	../libdaxctl.h \
+	libdaxctl-private.h \
+	../../util/sysfs.c \
+	../../util/sysfs.h \
+	../../util/log.c \
+	../../util/log.h \
+	libdaxctl.c
+
+EXTRA_DIST += libdaxctl.sym
+
+libdaxctl_la_LDFLAGS = $(AM_LDFLAGS) \
+	-version-info $(LIBDAXCTL_CURRENT):$(LIBDAXCTL_REVISION):$(LIBDAXCTL_AGE) \
+	-Wl,--version-script=$(top_srcdir)/daxctl/lib/libdaxctl.sym
+libdaxctl_la_DEPENDENCIES = libdaxctl.sym
+
+pkgconfigdir = $(libdir)/pkgconfig
+pkgconfig_DATA = libdaxctl.pc
+EXTRA_DIST += libdaxctl.pc.in
+CLEANFILES += libdaxctl.pc
diff --git a/ndctl/Makefile.am b/ndctl/Makefile.am
index f7d0a96af4f9..f6cd3f1c235b 100644
--- a/ndctl/Makefile.am
+++ b/ndctl/Makefile.am
@@ -1,38 +1,5 @@
 include $(top_srcdir)/Makefile.am.in
 
-BUILT_SOURCES = libndctl.h
-lib/libndctl.h: libndctl.h.in
-	touch $(top_srcdir)/version.m4
-
-%.pc: %.pc.in Makefile
-	$(SED_PROCESS)
-
-pkginclude_HEADERS = libndctl.h
-lib_LTLIBRARIES = lib/libndctl.la
-
-lib_libndctl_la_SOURCES =\
-	libndctl.h \
-	lib/libndctl-private.h \
-	../util/log.c \
-	../util/log.h \
-	../util/sysfs.c \
-	../util/sysfs.h \
-	lib/libndctl.c
-
-lib_libndctl_la_LIBADD =\
-	../daxctl/lib/libdaxctl.la \
-	$(UDEV_LIBS) \
-	$(UUID_LIBS) \
-	$(KMOD_LIBS)
-
-if ENABLE_ARS
-lib_libndctl_la_SOURCES += lib/libndctl-ars.c
-endif
-
-if ENABLE_SMART
-lib_libndctl_la_SOURCES += lib/libndctl-smart.c
-endif
-
 bin_PROGRAMS = ndctl
 
 ndctl_SOURCES = ndctl.c \
@@ -71,17 +38,3 @@ ndctl_SOURCES += ../test/libndctl.c \
 		 ../test/parent-uuid.c \
 		 ../test/core.c
 endif
-
-
-
-EXTRA_DIST += lib/libndctl.sym
-
-lib_libndctl_la_LDFLAGS = $(AM_LDFLAGS) \
-	-version-info $(LIBNDCTL_CURRENT):$(LIBNDCTL_REVISION):$(LIBNDCTL_AGE) \
-	-Wl,--version-script=$(top_srcdir)/ndctl/lib/libndctl.sym
-lib_libndctl_la_DEPENDENCIES = lib/libndctl.sym
-
-pkgconfigdir = $(libdir)/pkgconfig
-pkgconfig_DATA = lib/libndctl.pc
-EXTRA_DIST += lib/libndctl.pc.in
-CLEANFILES += lib/libndctl.pc
diff --git a/ndctl/lib/Makefile.am b/ndctl/lib/Makefile.am
new file mode 100644
index 000000000000..ec3941a4a754
--- /dev/null
+++ b/ndctl/lib/Makefile.am
@@ -0,0 +1,46 @@
+include $(top_srcdir)/Makefile.am.in
+
+BUILT_SOURCES = ../libndctl.h
+../libndctl.h: ../libndctl.h.in
+	touch $(top_srcdir)/version.m4
+
+%.pc: %.pc.in Makefile
+	$(SED_PROCESS)
+
+pkginclude_HEADERS = ../libndctl.h
+lib_LTLIBRARIES = libndctl.la
+
+libndctl_la_SOURCES =\
+	libndctl.h \
+	libndctl-private.h \
+	../../util/log.c \
+	../../util/log.h \
+	../../util/sysfs.c \
+	../../util/sysfs.h \
+	libndctl.c
+
+libndctl_la_LIBADD =\
+	../../daxctl/lib/libdaxctl.la \
+	$(UDEV_LIBS) \
+	$(UUID_LIBS) \
+	$(KMOD_LIBS)
+
+if ENABLE_ARS
+libndctl_la_SOURCES += libndctl-ars.c
+endif
+
+if ENABLE_SMART
+libndctl_la_SOURCES += libndctl-smart.c
+endif
+
+EXTRA_DIST += libndctl.sym
+
+libndctl_la_LDFLAGS = $(AM_LDFLAGS) \
+	-version-info $(LIBNDCTL_CURRENT):$(LIBNDCTL_REVISION):$(LIBNDCTL_AGE) \
+	-Wl,--version-script=$(top_srcdir)/ndctl/lib/libndctl.sym
+libndctl_la_DEPENDENCIES = libndctl.sym
+
+pkgconfigdir = $(libdir)/pkgconfig
+pkgconfig_DATA = libndctl.pc
+EXTRA_DIST += libndctl.pc.in
+CLEANFILES += libndctl.pc

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

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

* [ndctl PATCH 3/3] test, dsm-fail: test get_config_size DSM failures
  2016-09-14  1:00 [ndctl PATCH 0/3] ndctl disable-dimm and label-read-failure unit test Dan Williams
  2016-09-14  1:00 ` [ndctl PATCH 1/3] ndctl: {enable|disable}-dimm commands Dan Williams
  2016-09-14  1:00 ` [ndctl PATCH 2/3] build: build libraries and utilities in separate directories Dan Williams
@ 2016-09-14  1:00 ` Dan Williams
  2 siblings, 0 replies; 4+ messages in thread
From: Dan Williams @ 2016-09-14  1:00 UTC (permalink / raw)
  To: linux-nvdimm

We expect that if the dimm driver fails to enable then any
label-data-dependent regions/namespaces will also fail to enable.

Signed-off-by: Dan Williams <dan.j.williams@intel.com>
---
 ndctl/Makefile.am    |    3 +
 ndctl/builtin-test.c |    5 +
 test.h               |    1 
 test/Makefile.am     |   10 ++
 test/dsm-fail.c      |  216 ++++++++++++++++++++++++++++++++++++++++++++++++++
 5 files changed, 235 insertions(+)
 create mode 100644 test/dsm-fail.c

diff --git a/ndctl/Makefile.am b/ndctl/Makefile.am
index f6cd3f1c235b..63f387b58de9 100644
--- a/ndctl/Makefile.am
+++ b/ndctl/Makefile.am
@@ -34,6 +34,9 @@ ndctl_LDADD =\
 
 if ENABLE_TEST
 ndctl_SOURCES += ../test/libndctl.c \
+		 ../test/dsm-fail.c \
+		 ../util/log.c \
+		 ../util/sysfs.c \
 		 ../test/dpa-alloc.c \
 		 ../test/parent-uuid.c \
 		 ../test/core.c
diff --git a/ndctl/builtin-test.c b/ndctl/builtin-test.c
index d9c5b0f28d6e..d8539a133d10 100644
--- a/ndctl/builtin-test.c
+++ b/ndctl/builtin-test.c
@@ -49,6 +49,11 @@ int cmd_test(int argc, const char **argv, struct ndctl_ctx *ctx)
 	if (rc && rc != 77)
 		return rc;
 
+	rc = test_dsm_fail(loglevel, test, ctx);
+	fprintf(stderr, "test-dsm-fail: %s\n", result(rc));
+	if (rc && rc != 77)
+		return rc;
+
 	rc = test_dpa_alloc(loglevel, test, ctx);
 	fprintf(stderr, "test-dpa-alloc: %s\n", result(rc));
 	if (rc && rc != 77)
diff --git a/test.h b/test.h
index 2940ac0f7396..bf708f38bfbf 100644
--- a/test.h
+++ b/test.h
@@ -18,6 +18,7 @@ struct ndctl_ctx;
 int test_parent_uuid(int loglevel, struct ndctl_test *test, struct ndctl_ctx *ctx);
 int test_dax_directio(int dax_fd, void *dax_addr, off_t offset);
 int test_dpa_alloc(int loglevel, struct ndctl_test *test, struct ndctl_ctx *ctx);
+int test_dsm_fail(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);
diff --git a/test/Makefile.am b/test/Makefile.am
index f0240fe5883a..5513f429869f 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -2,6 +2,7 @@ include $(top_srcdir)/Makefile.am.in
 
 TESTS =\
 	libndctl \
+	dsm-fail \
 	dpa-alloc \
 	parent-uuid \
 	create.sh \
@@ -10,6 +11,7 @@ TESTS =\
 
 check_PROGRAMS =\
 	libndctl \
+	dsm-fail \
 	dpa-alloc \
 	parent-uuid \
 	dax-errors
@@ -39,6 +41,14 @@ LIBNDCTL_LIB =\
 libndctl_SOURCES = libndctl.c core.c
 libndctl_LDADD = $(LIBNDCTL_LIB) $(UUID_LIBS) $(KMOD_LIBS)
 
+dsm_fail_SOURCES =\
+	dsm-fail.c \
+	core.c \
+	../util/log.c \
+	../util/sysfs.c
+
+dsm_fail_LDADD = $(LIBNDCTL_LIB) $(KMOD_LIBS)
+
 blk_ns_SOURCES = blk_namespaces.c core.c
 blk_ns_LDADD = $(LIBNDCTL_LIB) $(KMOD_LIBS)
 
diff --git a/test/dsm-fail.c b/test/dsm-fail.c
new file mode 100644
index 000000000000..e95a2f0a65a5
--- /dev/null
+++ b/test/dsm-fail.c
@@ -0,0 +1,216 @@
+/*
+ * Copyright (c) 2014-2016, Intel Corporation.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU Lesser General Public License,
+ * version 2.1, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope it will be useful, but WITHOUT ANY
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for
+ * more details.
+ */
+#include <stdio.h>
+#include <stddef.h>
+#include <stdlib.h>
+#include <string.h>
+#include <ctype.h>
+#include <errno.h>
+#include <syslog.h>
+#include <libkmod.h>
+#include <util/log.h>
+#include <util/sysfs.h>
+#include <linux/version.h>
+
+#include <ccan/array_size/array_size.h>
+#include <ndctl/libndctl.h>
+#ifdef HAVE_NDCTL_H
+#include <linux/ndctl.h>
+#else
+#include <ndctl.h>
+#endif
+#include <test.h>
+
+#define DIMM_PATH "/sys/devices/platform/nfit_test.0/nfit_test_dimm/test_dimm0"
+
+static void reset_bus(struct ndctl_bus *bus)
+{
+	struct ndctl_region *region;
+	struct ndctl_dimm *dimm;
+
+	/* disable all regions so that set_config_data commands are permitted */
+	ndctl_region_foreach(bus, region)
+		ndctl_region_disable_invalidate(region);
+
+	ndctl_dimm_foreach(bus, dimm)
+		ndctl_dimm_zero_labels(dimm);
+
+	/* set regions back to their default state */
+	ndctl_region_foreach(bus, region)
+		ndctl_region_enable(region);
+}
+
+static int do_test(struct ndctl_ctx *ctx, struct ndctl_test *test)
+{
+	struct ndctl_bus *bus = ndctl_bus_get_by_provider(ctx, "nfit_test.0");
+	struct ndctl_dimm *dimm, *victim = NULL;
+	char path[1024], buf[SYSFS_ATTR_SIZE];
+	struct ndctl_region *region;
+	struct log_ctx log_ctx;
+	unsigned int handle;
+	int rc;
+
+	if (!ndctl_test_attempt(test, KERNEL_VERSION(4, 9, 0)))
+		return 77;
+
+	if (!bus)
+		return -ENXIO;
+
+	log_init(&log_ctx, "test/dsm-fail", "NDCTL_TEST");
+
+	ndctl_bus_wait_probe(bus);
+
+	/* disable all regions so that we can disable a dimm */
+	ndctl_region_foreach(bus, region)
+		ndctl_region_disable_invalidate(region);
+
+	sprintf(path, "%s/handle", DIMM_PATH);
+	rc = __sysfs_read_attr(&log_ctx, path, buf);
+	if (rc) {
+		fprintf(stderr, "failed to retrieve test dimm handle\n");
+		return -ENXIO;
+	}
+
+	handle = strtoul(buf, NULL, 0);
+
+	ndctl_dimm_foreach(bus, dimm) {
+		if (ndctl_dimm_get_handle(dimm) == handle)
+			victim = dimm;
+
+		if (ndctl_dimm_disable(dimm)) {
+			fprintf(stderr, "failed to disable: %s\n",
+					ndctl_dimm_get_devname(dimm));
+			return -ENXIO;
+		}
+	}
+
+	if (!victim) {
+		fprintf(stderr, "failed to find victim dimm\n");
+		return -ENXIO;
+	}
+	fprintf(stderr, "victim: %s\n", ndctl_dimm_get_devname(victim));
+
+	sprintf(path, "%s/fail_cmd", DIMM_PATH);
+	sprintf(buf, "%#x\n", 1 << ND_CMD_GET_CONFIG_SIZE);
+	rc = __sysfs_write_attr(&log_ctx, path, buf);
+	if (rc) {
+		fprintf(stderr, "failed to set fail cmd mask\n");
+		return -ENXIO;
+	}
+
+	ndctl_dimm_foreach(bus, dimm) {
+		rc = ndctl_dimm_enable(dimm);
+		fprintf(stderr, "dimm: %s enable: %d\n",
+				ndctl_dimm_get_devname(dimm), rc);
+		if ((rc == 0) == (dimm == victim)) {
+			fprintf(stderr, "fail expected %s enable %s victim: %s\n",
+					ndctl_dimm_get_devname(dimm),
+					(dimm == victim) ? "failure" : "success",
+					ndctl_dimm_get_devname(victim));
+			rc = -ENXIO;
+			goto out;
+		}
+	}
+
+	ndctl_region_foreach(bus, region) {
+		bool has_victim = false;
+
+		ndctl_dimm_foreach_in_region(region, dimm) {
+			if (dimm == victim) {
+				has_victim = true;
+				break;
+			}
+		}
+
+		rc = ndctl_region_enable(region);
+		fprintf(stderr, "region: %s enable: %d has_victim: %d\n",
+				ndctl_region_get_devname(region), rc, has_victim);
+		if ((rc == 0) == has_victim) {
+			fprintf(stderr, "fail expected %s enable %s with %s disabled\n",
+					ndctl_region_get_devname(region),
+					has_victim ? "failure" : "success",
+					ndctl_dimm_get_devname(victim));
+			rc = -ENXIO;
+			goto out;
+		}
+	}
+
+	rc = 0;
+ out:
+	sprintf(buf, "0\n");
+	__sysfs_write_attr(&log_ctx, path, buf);
+	rc = ndctl_dimm_enable(victim);
+	if (rc) {
+		fprintf(stderr, "failed to enable victim: %s after clearing error\n",
+				ndctl_dimm_get_devname(victim));
+		rc = -ENXIO;
+	}
+	reset_bus(bus);
+
+	return rc;
+}
+
+int test_dsm_fail(int loglevel, struct ndctl_test *test, struct ndctl_ctx *ctx)
+{
+	struct kmod_module *mod;
+	struct kmod_ctx *kmod_ctx;
+	int result = EXIT_FAILURE, err;
+
+	ndctl_set_log_priority(ctx, loglevel);
+	kmod_ctx = kmod_new(NULL, NULL);
+	if (!kmod_ctx)
+		return result;
+	kmod_set_log_priority(kmod_ctx, loglevel);
+
+	err = kmod_module_new_from_name(kmod_ctx, "nfit_test", &mod);
+	if (err < 0)
+		goto err_module;
+
+	err = kmod_module_probe_insert_module(mod, KMOD_PROBE_APPLY_BLACKLIST,
+			NULL, NULL, NULL, NULL);
+	if (err < 0) {
+		result = 77;
+		ndctl_test_skip(test);
+		fprintf(stderr, "%s unavailable skipping tests\n",
+				"nfit_test");
+		goto err_module;
+	}
+
+	if (do_test(ctx, test) == 0)
+		result = EXIT_SUCCESS;
+
+	kmod_module_remove_module(mod, 0);
+
+ err_module:
+	kmod_unref(kmod_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) {
+		fprintf(stderr, "failed to initialize test\n");
+		return EXIT_FAILURE;
+	}
+
+	rc = ndctl_new(&ctx);
+	if (rc)
+		return ndctl_test_result(test, rc);
+	rc = test_dsm_fail(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] 4+ messages in thread

end of thread, other threads:[~2016-09-14  1:03 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-09-14  1:00 [ndctl PATCH 0/3] ndctl disable-dimm and label-read-failure unit test Dan Williams
2016-09-14  1:00 ` [ndctl PATCH 1/3] ndctl: {enable|disable}-dimm commands Dan Williams
2016-09-14  1:00 ` [ndctl PATCH 2/3] build: build libraries and utilities in separate directories Dan Williams
2016-09-14  1:00 ` [ndctl PATCH 3/3] test, dsm-fail: test get_config_size DSM failures Dan Williams

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.