All of lore.kernel.org
 help / color / mirror / Atom feed
From: Dan Williams <dan.j.williams@intel.com>
To: linux-nvdimm@lists.01.org
Subject: [ndctl PATCH 15/17] ndctl, test: trigger notifications
Date: Fri, 01 Dec 2017 15:25:49 -0800	[thread overview]
Message-ID: <151217074949.28402.12570925189107616348.stgit@dwillia2-desk3.amr.corp.intel.com> (raw)
In-Reply-To: <151217066885.28402.7962437173336388439.stgit@dwillia2-desk3.amr.corp.intel.com>

Provide a standalone test that can be run against any nvdimm bus to try
to trigger SMART notifications.

Signed-off-by: Dan Williams <dan.j.williams@intel.com>
---
 test/Makefile.am    |    4 +
 test/smart-notify.c |  220 +++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 224 insertions(+)
 create mode 100644 test/smart-notify.c

diff --git a/test/Makefile.am b/test/Makefile.am
index 6698d6cfbab5..85736c3cce09 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -25,6 +25,7 @@ check_PROGRAMS =\
 	parent-uuid \
 	multi-pmem \
 	dax-errors \
+	smart-notify \
 	daxdev-errors
 
 if ENABLE_DESTRUCTIVE
@@ -100,6 +101,9 @@ device_dax_LDADD = \
 		$(JSON_LIBS) \
 		../libutil.a
 
+smart_notify_SOURCES = smart-notify.c
+smart_notify_LDADD = $(LIBNDCTL_LIB)
+
 multi_pmem_SOURCES = \
 		multi-pmem.c \
 		$(testcore) \
diff --git a/test/smart-notify.c b/test/smart-notify.c
new file mode 100644
index 000000000000..24e9a213836b
--- /dev/null
+++ b/test/smart-notify.c
@@ -0,0 +1,220 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/* Copyright(c) 2017 Intel Corporation. All rights reserved. */
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+#include <syslog.h>
+#include <stdlib.h>
+#include <ndctl/libndctl.h>
+
+static void do_notify(struct ndctl_dimm *dimm)
+{
+	struct ndctl_cmd *s_cmd = ndctl_dimm_cmd_new_smart(dimm);
+	struct ndctl_cmd *st_cmd = NULL, *sst_cmd = NULL;
+	unsigned int orig_mtemp, orig_ctemp, orig_spare;
+	const char *name = ndctl_dimm_get_devname(dimm);
+	unsigned int alarm, mtemp, ctemp, spare, valid;
+	int rc, i;
+
+	if (!s_cmd) {
+		fprintf(stderr, "%s: no smart command support\n", name);
+		goto out;
+	}
+
+	rc = ndctl_cmd_submit(s_cmd);
+	if (rc) {
+		fprintf(stderr, "%s: smart command failed: %d %s\n", name,
+				rc, strerror(errno));
+		goto out;
+	}
+
+	valid = ndctl_cmd_smart_get_flags(s_cmd);
+	alarm = ndctl_cmd_smart_get_alarm_flags(s_cmd);
+	mtemp = ndctl_cmd_smart_get_media_temperature(s_cmd);
+	ctemp = ndctl_cmd_smart_get_ctrl_temperature(s_cmd);
+	spare = ndctl_cmd_smart_get_spares(s_cmd);
+	fprintf(stderr, "%s: (smart) alarm%s: %#x mtemp%s: %.2f ctemp%s: %.2f spares%s: %d\n",
+			name,
+			valid & ND_SMART_ALARM_VALID ? "" : "(invalid)", alarm,
+			valid & ND_SMART_MTEMP_VALID ? "" : "(invalid)",
+			ndctl_decode_smart_temperature(mtemp),
+			valid & ND_SMART_CTEMP_VALID ? "" : "(invalid)",
+			ndctl_decode_smart_temperature(ctemp),
+			valid & ND_SMART_SPARES_VALID ? "" : "(invalid)", spare);
+
+	st_cmd = ndctl_dimm_cmd_new_smart_threshold(dimm);
+	if (!st_cmd) {
+		fprintf(stderr, "%s: no smart threshold command support\n", name);
+		goto out;
+	}
+
+	rc = ndctl_cmd_submit(st_cmd);
+	if (rc) {
+		fprintf(stderr, "%s: smart threshold command failed: %d %s\n",
+				name, rc, strerror(errno));
+		goto out;
+	}
+
+	alarm = ndctl_cmd_smart_threshold_get_alarm_control(st_cmd);
+	mtemp = ndctl_cmd_smart_threshold_get_media_temperature(st_cmd);
+	ctemp = ndctl_cmd_smart_threshold_get_ctrl_temperature(st_cmd);
+	spare = ndctl_cmd_smart_threshold_get_spares(st_cmd);
+	fprintf(stderr, "%s: (smart thresh) alarm: %#x mtemp: %.2f ctemp: %.2f spares: %d\n",
+			name, alarm, ndctl_decode_smart_temperature(mtemp),
+			ndctl_decode_smart_temperature(ctemp), spare);
+
+	orig_mtemp = mtemp;
+	orig_ctemp = ctemp;
+	orig_spare = spare;
+
+	sst_cmd = ndctl_dimm_cmd_new_smart_set_threshold(st_cmd);
+	if (!sst_cmd) {
+		fprintf(stderr, "%s: no smart set threshold command support\n", name);
+		goto out;
+	}
+
+	alarm = ndctl_cmd_smart_threshold_get_supported_alarms(sst_cmd);
+	if (!alarm) {
+		fprintf(stderr, "%s: no smart set threshold command support\n", name);
+		goto out;
+	}
+
+
+	fprintf(stderr, "%s: supported alarms: %#x\n", name, alarm);
+
+	/*
+	 * free the cmd now since we only needed the alarms and will
+	 * create + issue a set_threshold test for each alarm
+	 */
+	ndctl_cmd_unref(sst_cmd);
+
+	for (i = 0; i < 3; i++) {
+		unsigned int set_alarm = 1 << i;
+
+		if (!(alarm & set_alarm))
+			continue;
+
+		sst_cmd = ndctl_dimm_cmd_new_smart_set_threshold(st_cmd);
+		if (!sst_cmd) {
+			fprintf(stderr, "%s: alloc failed: smart set threshold\n",
+					name);
+			goto out;
+		}
+
+		switch (set_alarm) {
+		case ND_SMART_SPARE_TRIP:
+			fprintf(stderr, "%s: set spare threshold: 99\n", name);
+			ndctl_cmd_smart_threshold_set_spares(sst_cmd, 99);
+			ndctl_cmd_smart_threshold_set_media_temperature(
+					sst_cmd, orig_mtemp);
+			ndctl_cmd_smart_threshold_set_ctrl_temperature(
+					sst_cmd, orig_ctemp);
+			break;
+		case ND_SMART_MTEMP_TRIP:
+			mtemp = ndctl_cmd_smart_get_media_temperature(s_cmd);
+			if (mtemp & (1 << 15))
+				mtemp *= 2;
+			else
+				mtemp /= 2;
+			fprintf(stderr, "%s: set mtemp threshold: %.2f\n", name,
+					ndctl_decode_smart_temperature(mtemp));
+			ndctl_cmd_smart_threshold_set_spares(
+					sst_cmd, orig_spare);
+			ndctl_cmd_smart_threshold_set_media_temperature(
+					sst_cmd, mtemp);
+			ndctl_cmd_smart_threshold_set_ctrl_temperature(
+					sst_cmd, orig_ctemp);
+			break;
+		case ND_SMART_CTEMP_TRIP:
+			ctemp = ndctl_cmd_smart_get_ctrl_temperature(s_cmd);
+			if (ctemp & (1 << 15))
+				ctemp *= 2;
+			else
+				ctemp /= 2;
+			fprintf(stderr, "%s: set ctemp threshold: %.2f\n", name,
+					ndctl_decode_smart_temperature(ctemp));
+
+			ndctl_cmd_smart_threshold_set_spares(
+					sst_cmd, orig_spare);
+			ndctl_cmd_smart_threshold_set_media_temperature(
+					sst_cmd, orig_mtemp);
+			ndctl_cmd_smart_threshold_set_ctrl_temperature(
+					sst_cmd, ctemp);
+
+			break;
+		default:
+			break;
+		}
+
+		ndctl_cmd_smart_threshold_set_alarm_control(sst_cmd, set_alarm);
+		rc = ndctl_cmd_submit(sst_cmd);
+		if (rc) {
+			fprintf(stderr, "%s: smart set threshold command failed: %d %s\n",
+					name, rc, strerror(errno));
+			goto out;
+		}
+
+		ndctl_cmd_unref(sst_cmd);
+	}
+
+	fprintf(stderr, "%s: set thresholds back to defaults\n", name);
+	sst_cmd = ndctl_dimm_cmd_new_smart_set_threshold(st_cmd);
+	if (!sst_cmd) {
+		fprintf(stderr, "%s: alloc failed: smart set threshold\n",
+				name);
+		goto out;
+	}
+
+	rc = ndctl_cmd_submit(sst_cmd);
+	if (rc) {
+		fprintf(stderr, "%s: smart set threshold defaults failed: %d %s\n",
+				name, rc, strerror(errno));
+		goto out;
+	}
+
+out:
+	ndctl_cmd_unref(sst_cmd);
+	ndctl_cmd_unref(st_cmd);
+	ndctl_cmd_unref(s_cmd);
+}
+
+static void test_dimm_notify(struct ndctl_bus *bus)
+{
+	struct ndctl_dimm *dimm;
+
+	ndctl_dimm_foreach(bus, dimm)
+		do_notify(dimm);
+}
+
+int main(int argc, char *argv[])
+{
+	struct ndctl_ctx *ctx;
+	struct ndctl_bus *bus;
+	int rc = EXIT_FAILURE;
+	const char *provider;
+
+	rc = ndctl_new(&ctx);
+	if (rc < 0)
+		return EXIT_FAILURE;
+
+	if (argc != 2) {
+		fprintf(stderr, "usage: smart-notify <nvdimm-bus-provider>\n");
+		goto out;
+	}
+
+	ndctl_set_log_priority(ctx, LOG_DEBUG);
+
+	provider = argv[1];
+	bus = ndctl_bus_get_by_provider(ctx, provider);
+	if (!bus) {
+		fprintf(stderr, "smart-notify: unable to find bus (%s)\n",
+				provider);
+		goto out;
+	}
+
+	rc = EXIT_SUCCESS;
+	test_dimm_notify(bus);
+out:
+	ndctl_unref(ctx);
+	return rc;
+}

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

  parent reply	other threads:[~2017-12-01 23:29 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-12-01 23:24 [ndctl PATCH 00/16] ndctl: update SMART support for NVDIMM_FAMILY_INTEL Dan Williams
2017-12-01 23:24 ` [ndctl PATCH 01/17] libndctl: rename dimm dsm_mask to cmd_mask Dan Williams
2017-12-01 23:24 ` [ndctl PATCH 02/17] libndctl: add nfit_dsm_mask as a private dimm property Dan Williams
2017-12-01 23:24 ` [ndctl PATCH 03/17] ndctl, smart: rename 'temperature' helpers to 'media_temperature' Dan Williams
2017-12-01 23:24 ` [ndctl PATCH 04/17] ndctl, intel: switch to ND_CMD_CALL passthrough for SMART commands Dan Williams
2017-12-01 23:24 ` [ndctl PATCH 05/17] ndctl: remove support for compiling against the kernel ndctl.h header Dan Williams
2017-12-01 23:25 ` [ndctl PATCH 06/17] ndctl, test: emit smart field names Dan Williams
2017-12-01 23:25 ` [ndctl PATCH 07/17] ndctl, smart: cleanup smart_cmd_op() macro Dan Williams
2017-12-01 23:25 ` [ndctl PATCH 08/17] ndctl, test: reset all nfit_test data for each test/libndctl run Dan Williams
2017-12-01 23:25 ` [ndctl PATCH 09/17] ndctl, region: cleanup error message Dan Williams
2017-12-01 23:25 ` [ndctl PATCH 10/17] ndctl: support set smart alarm/threshold Dan Williams
2017-12-01 23:25 ` [ndctl PATCH 11/17] ndctl: refactor 'smart_ops' into generic 'dimm_ops' Dan Williams
2017-12-01 23:25 ` [ndctl PATCH 12/17] ndctl, debug: improve do_cmd output for ND_CMD_CALL Dan Williams
2017-12-01 23:25 ` [ndctl PATCH 13/17] ndctl, list: teach the list command about the 'fsdax' and 'devdax' modes Dan Williams
2017-12-01 23:25 ` [ndctl PATCH 14/17] ndctl, smart: move smart temperature parsing to a library routine Dan Williams
2017-12-01 23:25 ` Dan Williams [this message]
2017-12-01 23:25 ` [ndctl PATCH 16/17] ndctl, test: listen for smart notifications Dan Williams
2017-12-01 23:25 ` [ndctl PATCH 17/17] ndctl, test: hugetlb fault Dan Williams
2017-12-01 23:36 ` [ndctl PATCH 00/16] ndctl: update SMART support for NVDIMM_FAMILY_INTEL Dan Williams

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=151217074949.28402.12570925189107616348.stgit@dwillia2-desk3.amr.corp.intel.com \
    --to=dan.j.williams@intel.com \
    --cc=linux-nvdimm@lists.01.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.