Skip to contentSkip to conversation

ndctl, monitor: add ndctl monitor daemon

PATCH Superseded QI Fuli 3 participants 13 messages Jul 13, 2018

Subsystems (2)

v12 of 13 Superseded Latest is v13 →

lore
Share & tools
lore

QI Fuli

author
#0 lore raw

v12 cover ndctl, monitor: add ndctl monitor daemon

This is the v12 patch for ndctl monitor, a tiny daemon to monitor the smart events of nvdimm DIMMs. Since NVDIMM does not have a feature like mirroring, if it breaks down, the data will be impossible to restore. Ndctl monitor daemon will catch the smart events notify from firmware and outputs notification to logfile, therefore users can replace NVDIMM before it is completely broken.

---
Change log since v11:
- Adding log_standard()
- Adding [-u | --human] option
- Fixing man page
- Refactoring unit test
- Updating configuration file and systemd unit file to RPM spec file

Change log since v10:
- Adding unit test
- Adding fflush to log_file()

Change log since v9:
- Replacing ndctl_cmd_smart_get_event_flags() with ndctl_dimm_get_event_flags()
- Adding ndctl_dimm_get_health() api
- Adding ndctl_dimm_get_flags() api
- Adding ndctl_dimm_is_flag_supported api
- Adding manpage

Change log since v8:
- Adding ndctl_cmd_smart_get_event_flags() api
- Adding monitor_filter_arg to the union in util_filter_ctx
- Removing is_dir()
- Replacing malloc + vsprintf with vasprintf() in log_file() and log_syslog()
- Adding parse_monitor_event()
- Refactoring util_dimm_event_filter()
- Adding event_flags to monitor
- Refactoring dimm_event_to_json()
- Adding check_dimm_supported_threshold_alarms()
- Fixing fail token

Change log since v7:
- Replacing logreport() with log_file() and log_syslog()
- Refactoring read_config_file()
- Replacing set_confile() with parse_config()
- Fixing the ndctl/ndct.conf file

Change log since v6:
- Changing License to GPL-2.0
- Adding event object to output notification
- Adding [--dimm-event] option to filter notification by event type
- Rewriting read_config_file()
- Replacing monitor_dimm_event() with monitor_event()
- Renaming some variables

Change log since v5:
- Fixing systemd unit file cannot be installed bug
- Adding license to ./util/abspath.c

Change log since v4:
- Adding OPTION_FILENAME to make sure filename is correct
- Adding configuration file
- Adding [--config-file] option to override the default configuration
- Making some options support multiple space-seperated arguments
- Making systemctl enable ndctl-monitor.service command work
- Making systemctl restart ndctl-monitor.service command work
- Making the directory of systemd unit file to be configurable
- Changing log_file() and log_syslog() to logreport()
- Changing date format in notification to nanoseconds since epoch
- Changing select() to epoll()
- Adding filter_bus() and filter_region()

Change log since v3:
- Removing create-monitor, show-monitor, list-monitor, destroy-monitor
- Adding [--daemon] option to run ndctl monitor as a daemon
- Using systemd to manage ndctl monitor daemon
- Replacing filter_monitor_dimm() with filter_dimm()

Change log since v2:
- Changing the interface of daemon to the ndctl command line
- Changing the name of daemon form "nvdimmd" to "monitor"
- Removing the config file, unit_file, nvdimmd dir
- Removing nvdimmd_test program
- Adding ndctl/monitor.c

Change log since v1:
- Adding a config file(/etc/nvdimmd/nvdimmd.conf)
- Using struct log_ctx instead of syslog()
- Using log_syslog() to save the notify messages to syslog
- Using log_file() to save the notify messages to special file
- Adding LOG_NOTICE level to log_priority
- Using automake instead of Makefile
- Adding a new util file(nvdimmd/util.c) including helper functions needed for nvdimm daemon
- Adding nvdimmd_test program

QI Fuli (5):
ndctl, monitor: add a new command - monitor
ndctl, monitor: add main ndctl monitor configuration file ndctl, monitor: add the unit file of systemd for ndctl-monitor service ndctl, documentation: add man page for monitor
ndctl, test: add a new unit test for monitor

 .gitignore                            |   1 +
 Documentation/ndctl/Makefile.am       |   3 +-
 Documentation/ndctl/ndctl-monitor.txt | 104 +++++
 autogen.sh                            |   3 +-
 builtin.h                             |   1 +
 configure.ac                          |  22 +
 ndctl.spec.in                         |   2 +
 ndctl/Makefile.am                     |  12 +-
 ndctl/lib/libndctl.c                  |  82 ++++
 ndctl/lib/libndctl.sym                |   4 +
 ndctl/libndctl.h                      |  10 +
 ndctl/monitor.c                       | 649 ++++++++++++++++++++++++++
 ndctl/monitor.conf                    |  41 ++
 ndctl/ndctl-monitor.service           |   7 +
 ndctl/ndctl.c                         |   1 +
 test/Makefile.am                      |  14 +-
 test/list-smart-dimm.c                | 117 +++++
 test/monitor.sh                       | 176 +++++++
 util/filter.h                         |   9 +
 19 files changed, 1253 insertions(+), 5 deletions(-)
 create mode 100644 Documentation/ndctl/ndctl-monitor.txt
 create mode 100644 ndctl/monitor.c
 create mode 100644 ndctl/monitor.conf
 create mode 100644 ndctl/ndctl-monitor.service
 create mode 100644 test/list-smart-dimm.c
 create mode 100755 test/monitor.sh
Signature · 7 lines
2.18.0


_______________________________________________
Linux-nvdimm mailing list
[email protected]
https://lists.01.org/mailman/listinfo/linux-nvdimm
author
#1 lore raw

PATCH v12 1/5 ndctl, monitor: add a new command - monitor

Ndctl monitor is used for monitoring the smart events of NVDIMMs. When a smart event fires, monitor will output the notifications which include dimm health status and event information to syslog, standard output or a file by setting [--log] option. The notifications follow json format and can be consumed by log collectors like Fluentd.

The objects to monitor can be selected by setting [--dimm] [--region] [--namespace] [--bus] options and the event type can be filtered by setting [--dimm-event] option. These options support multiple space-separated arguments.

Ndctl monitor can be forked as a daemon by using [--daemon] option, such as:

   # ndctl monitor --daemon --log /var/log/ndctl/monitor.log
---
 builtin.h              |   1 +
 ndctl/Makefile.am      |   3 +-
 ndctl/lib/libndctl.c   |  82 +++++++
 ndctl/lib/libndctl.sym |   4 +
 ndctl/libndctl.h       |  10 +
 ndctl/monitor.c        | 539 +++++++++++++++++++++++++++++++++++++++++
 ndctl/ndctl.c          |   1 +
 util/filter.h          |   9 +
 8 files changed, 648 insertions(+), 1 deletion(-)
 create mode 100644 ndctl/monitor.c
builtin.h +1 -0
index d3cc723..675a6ce 100644
@@ -39,6 +39,7 @@ int cmd_inject_error(int argc, const char **argv, void *ctx);
 int cmd_wait_scrub(int argc, const char **argv, void *ctx);
 int cmd_start_scrub(int argc, const char **argv, void *ctx);
 int cmd_list(int argc, const char **argv, void *ctx);
+int cmd_monitor(int argc, const char **argv, void *ctx);
 #ifdef ENABLE_TEST
 int cmd_test(int argc, const char **argv, void *ctx);
 #endif
ndctl/Makefile.am +2 -1
index 0f56871..083609a 100644
@@ -15,7 +15,8 @@ ndctl_SOURCES = ndctl.c \
 		util/json-smart.c \
 		util/json-firmware.c \
 		inject-error.c \
-		inject-smart.c
+		inject-smart.c \
+		monitor.c
 
 if ENABLE_DESTRUCTIVE
 ndctl_SOURCES += ../test/blk_namespaces.c \
ndctl/lib/libndctl.c +82 -0

88 lines not on this page · raw message

ndctl/lib/libndctl.sym +4 -0
index 8932ef6..9b36960 100644
@@ -371,4 +371,8 @@ global:
 LIBNDCTL_17 {
 global:
 	ndctl_dimm_smart_inject_supported;
+	ndctl_dimm_get_health;
+	ndctl_dimm_get_flags;
+	ndctl_dimm_get_event_flags;
+	ndctl_dimm_is_flag_supported;
 } LIBNDCTL_16;
ndctl/libndctl.h +10 -0
index 8a96c84..6a6bb0d 100644
@@ -73,6 +73,12 @@ typedef unsigned char uuid_t[16];
 extern "C" {
 #endif
 
+#define ND_EVENT_SPARES_REMAINING	(1 << 0)
+#define ND_EVENT_MEDIA_TEMPERATURE	(1 << 1)
+#define ND_EVENT_CTRL_TEMPERATURE	(1 << 2)
+#define ND_EVENT_HEALTH_STATE		(1 << 3)
+#define ND_EVENT_UNCLEAN_SHUTDOWN	(1 << 4)
+
 size_t ndctl_min_namespace_size(void);
 size_t ndctl_sizeof_namespace_index(void);
 size_t ndctl_sizeof_namespace_label(void);
@@ -170,6 +176,10 @@ int ndctl_dimm_failed_map(struct ndctl_dimm *dimm);
 int ndctl_dimm_smart_pending(struct ndctl_dimm *dimm);
 int ndctl_dimm_failed_flush(struct ndctl_dimm *dimm);
 int ndctl_dimm_get_health_eventfd(struct ndctl_dimm *dimm);
+unsigned int ndctl_dimm_get_health(struct ndctl_dimm *dimm);
+unsigned int ndctl_dimm_get_flags(struct ndctl_dimm *dimm);
+unsigned int ndctl_dimm_get_event_flags(struct ndctl_dimm *dimm);
+int ndctl_dimm_is_flag_supported(struct ndctl_dimm *dimm, unsigned int flag);
 unsigned int ndctl_dimm_handle_get_node(struct ndctl_dimm *dimm);
 unsigned int ndctl_dimm_handle_get_socket(struct ndctl_dimm *dimm);
 unsigned int ndctl_dimm_handle_get_imc(struct ndctl_dimm *dimm);
ndctl/monitor.c new file +539 -0

539 lines not on this page · raw message

ndctl/ndctl.c +1 -0
index 7daadeb..73dabfa 100644
@@ -89,6 +89,7 @@ static struct cmd_struct commands[] = {
 	{ "wait-scrub", cmd_wait_scrub },
 	{ "start-scrub", cmd_start_scrub },
 	{ "list", cmd_list },
+	{ "monitor", cmd_monitor},
 	{ "help", cmd_help },
 	#ifdef ENABLE_TEST
 	{ "test", cmd_test },
util/filter.h +9 -0
index effda24..c2cdddf 100644
@@ -13,6 +13,7 @@
 #ifndef _UTIL_FILTER_H_
 #define _UTIL_FILTER_H_
 #include <stdbool.h>
+#include <ccan/list/list.h>
 
 struct ndctl_bus *util_bus_filter(struct ndctl_bus *bus, const char *ident);
 struct ndctl_region *util_region_filter(struct ndctl_region *region,
@@ -50,6 +51,13 @@ struct list_filter_arg {
 	unsigned long flags;
 };
 
+struct monitor_filter_arg {
+	struct list_head dimms;
+	int maxfd_dimm;
+	int num_dimm;
+	unsigned long flags;
+};
+
 /*
  * struct util_filter_ctx - control and callbacks for util_filter_walk()
  * ->filter_bus() and ->filter_region() return bool because the
@@ -67,6 +75,7 @@ struct util_filter_ctx {
 	union {
 		void *arg;
 		struct list_filter_arg *list;
+		struct monitor_filter_arg *monitor;
 	};
 };
 
Signature · 7 lines
2.18.0


_______________________________________________
Linux-nvdimm mailing list
[email protected]
https://lists.01.org/mailman/listinfo/linux-nvdimm
maintainer
#2 lore raw

Re: [ndctl PATCH v12 1/5] ndctl, monitor: add a new command - monitor

Hi Qi,

Quoted 28 lines · QI Fuli

Ndctl monitor is used for monitoring the smart events of NVDIMMs. When a smart event fires, monitor will output the notifications which include dimm health status and event information to syslog, standard output or a file by setting [--log] option. The notifications follow json format and can be consumed by log collectors like Fluentd.

The objects to monitor can be selected by setting [--dimm] [--region] [--namespace] [--bus] options and the event type can be filtered by setting [--dimm-event] option. These options support multiple space-separated arguments.

Ndctl monitor can be forked as a daemon by using [--daemon] option, such as:

   # ndctl monitor --daemon --log /var/log/ndctl/monitor.log
---
 builtin.h              |   1 +
 ndctl/Makefile.am      |   3 +-
 ndctl/lib/libndctl.c   |  82 +++++++
 ndctl/lib/libndctl.sym |   4 +
 ndctl/libndctl.h       |  10 +
 ndctl/monitor.c        | 539 +++++++++++++++++++++++++++++++++++++++++
 ndctl/ndctl.c          |   1 +
 util/filter.h          |   9 +
 8 files changed, 648 insertions(+), 1 deletion(-)
 create mode 100644 ndctl/monitor.c

[..]

Quoted 8 lines
ndctl/monitor.c new file +8 -0
+
+#define fail(fmt, ...) \
+do { \
+	did_fail = 1; \
+	dbg(ctx, "ndctl-%s:%s:%d: " fmt, \
+			VERSION, __func__, __LINE__, ##__VA_ARGS__); \
+} while (0)
+

ndctl/monitor.c line 56

Quoted 10 lines
ndctl/monitor.c new file +10 -0
+static void log_syslog(struct ndctl_ctx *ctx, int priority, const char *file,
+		int line, const char *fn, const char *format, va_list args)
+{
+	char *buf;
+
+	if (vasprintf(&buf, format, args) < 0) {
+		fail("vasprintf error\n");
+		return;
+	}
+	syslog(priority, "%s\n", buf);

I think from each of the log functions, we should remove the '\n'. Currently, this results in an extra newline for error messages like unsupported dimms. For consistency, the newline is always added at the 'top level' when the string is being composed. All functions that pass through or handle the string later shouldn't add newlines.

It is ok for the error messages in this function to have newlines, like in the "vasprintf error" case.

Quoted 9 lines
ndctl/monitor.c new file +9 -0
+
+	free(buf);
+	return;
+}
+
+static void log_standard(struct ndctl_ctx *ctx, int priority, const char *file,
+		int line, const char *fn, const char *format, va_list args)
+{
+	char *buf;

ndctl/monitor.c line 75

Quoted 10 lines
ndctl/monitor.c new file +10 -0
+
+	if (vasprintf(&buf, format, args) < 0) {
+		fail("vasprintf error\n");
+		return;
+	}
+
+	if (priority == 6)
+		fprintf(stdout, "%s\n", buf);
+	else
+		fprintf(stderr, "%s\n", buf);

Same as above for both fprintf statements.

Quoted 13 lines
ndctl/monitor.c new file +13 -0
+
+	free(buf);
+	return;
+}
+
+static void log_file(struct ndctl_ctx *ctx, int priority, const char *file,
+		int line, const char *fn, const char *format, va_list args)
+{
+	FILE *f;
+	char *buf;
+
+	if (vasprintf(&buf, format, args) < 0) {
+		fail("vasprintf error\n");

ndctl/monitor.c line 98

Quoted 10 lines
ndctl/monitor.c new file +10 -0
+		return;
+	}
+
+	f = fopen(monitor.log, "a+");
+	if (!f) {
+		ndctl_set_log_fn(ctx, log_syslog);
+		fail("open logfile %s failed\n%s", monitor.log, buf);
+		goto end;
+	}
+	fprintf(f, "%s\n", buf);

Same as above.

Quoted 7 lines
ndctl/monitor.c new file +7 -0
+	fflush(f);
+	fclose(f);
+end:
+	free(buf);
+	return;
+}
+

[..]

Quoted 47 lines
ndctl/monitor.c new file +47 -0
+
+static int notify_dimm_event(struct monitor_dimm *mdimm)
+{
+	struct json_object *jmsg, *jdimm, *jobj;
+	struct timespec ts;
+	char timestamp[32];
+	struct ndctl_ctx *ctx = ndctl_dimm_get_ctx(mdimm->dimm);
+
+	jmsg = json_object_new_object();
+	if (!jmsg) {
+		fail("\n");
+		return -1;
+	}
+
+	clock_gettime(CLOCK_REALTIME, &ts);
+	sprintf(timestamp, "%10ld.%09ld", ts.tv_sec, ts.tv_nsec);
+	jobj = json_object_new_string(timestamp);
+	if (!jobj) {
+		fail("\n");
+		return -1;
+	}
+	json_object_object_add(jmsg, "timestamp", jobj);
+
+	jobj = json_object_new_int(getpid());
+	if (!jobj) {
+		fail("\n");
+		return -1;
+	}
+	json_object_object_add(jmsg, "pid", jobj);
+
+	jobj = dimm_event_to_json(mdimm);
+	if (!jobj) {
+		fail("\n");
+		return -1;
+	}
+	json_object_object_add(jmsg, "event", jobj);
+
+	jdimm = util_dimm_to_json(mdimm->dimm, 0);
+	if (!jdimm) {
+		fail("\n");
+		return -1;
+	}
+	json_object_object_add(jmsg, "dimm", jdimm);
+
+	jobj = util_dimm_health_to_json(mdimm->dimm);
+	if (!jobj) {
+		fail("\n");

ndctl/monitor.c line 222

Quoted 10 lines
ndctl/monitor.c new file +10 -0
+		return -1;
+	}
+	json_object_object_add(jdimm, "health", jobj);
+
+	if (monitor.human)
+		notice(ctx, "%s", json_object_to_json_string_ext(jmsg,
+						JSON_C_TO_STRING_PRETTY));
+	else
+		notice(ctx, "%s", json_object_to_json_string_ext(jmsg,
+						JSON_C_TO_STRING_PLAIN));

And since the log functions no longer add newlines, these notice() strings should have a newline.

Quoted 7 lines
ndctl/monitor.c new file +7 -0
+
+	free(jobj);
+	free(jdimm);
+	free(jmsg);
+	return 0;
+}
+

[..]

Quoted 31 lines
ndctl/monitor.c new file +31 -0
+int cmd_monitor(int argc, const char **argv, void *ctx)
+{
+	const struct option options[] = {
+		OPT_STRING('b', "bus", &param.bus, "bus-id", "filter by bus"),
+		OPT_STRING('r', "region", &param.region, "region-id",
+				"filter by region"),
+		OPT_STRING('d', "dimm", &param.dimm, "dimm-id",
+				"filter by dimm"),
+		OPT_STRING('n', "namespace", &param.namespace,
+				"namespace-id", "filter by namespace id"),
+		OPT_STRING('D', "dimm-event", &monitor.dimm_event,
+			"name of event type", "filter by DIMM event type"),
+		OPT_FILENAME('l', "log", &monitor.log,
+				"<file> | syslog | standard",
+				"where to output the monitor's notification"),
+		OPT_BOOLEAN('x', "daemon", &monitor.daemon,
+				"run ndctl monitor as a daemon"),
+		OPT_BOOLEAN('u', "human", &monitor.human,
+				"use human friendly output formats"),
+		OPT_END(),
+	};
+	const char * const u[] = {
+		"ndctl monitor [<options>]",
+		NULL
+	};
+	const char *prefix = "./";
+	struct util_filter_ctx fctx = { 0 };
+	struct monitor_filter_arg mfa = { 0 };
+	int i;
+
+	argc = parse_options_prefix(argc, argv, prefix, options, u, 0);

ndctl/monitor.c line 497

Quoted 10 lines
ndctl/monitor.c new file +10 -0
+	for (i = 0; i < argc; i++) {
+		error("unknown parameter \"%s\"\n", argv[i]);
+	}
+	if (argc)
+		usage_with_options(u, options);
+
+	ndctl_set_log_fn((struct ndctl_ctx *)ctx, log_standard);
+	ndctl_set_log_priority((struct ndctl_ctx *)ctx, LOG_NOTICE);
+
+	if (monitor.log) {

I think you were trying to special case the option of ./syslog and ./standard so that they are treated as files (but I'm not sure that's needed?)

ndctl/monitor.c line 499

Quoted 2 lines
ndctl/monitor.c new file +2 -0
+		if (strcmp(monitor.log, "./syslog") == 0)
+			ndctl_set_log_fn((struct ndctl_ctx *)ctx, log_syslog);

I think this is broken as we need 'syslog' to select log_syslog, and not './syslog'

ndctl/monitor.c line 501

Quoted 2 lines
ndctl/monitor.c new file +2 -0
+		else if (strcmp(monitor.log, "./standard") != 0)
+			ndctl_set_log_fn((struct ndctl_ctx *)ctx, log_file);

I think the flow we want here is:

	/* default to log_standard */
	ndctl_set_log_fn((struct ndctl_ctx *)ctx, log_standard);
	ndctl_set_log_priority((struct ndctl_ctx *)ctx, LOG_NOTICE);

	if (monitor.log) {
		/*
		 * we have to add a './' prefix to the comparisons
		 * as fix_filename adds it to monitor.log for us
		 */
		if (strncmp(monitor.log, "./syslog", 8) == 0)
			ndctl_set_log_fn((struct ndctl_ctx *)ctx, log_syslog);
		else if (strncmp(monitor.log, "./standard", 10) == 0)
			; /* default, already set */
		else
			ndctl_set_log_fn((struct ndctl_ctx *)ctx, log_file);
	}

The final log_file case should be a catch-all for anything supplied that is not exactly 'syslog' or 'standard'. Note that I used strncmp instead of strcmp to match exactly.

This does mean that if someone supplies "./syslog" intending to write to a file called syslog in the current directory, it will instead log to syslog. But I think that is fine, it can be documented as a quirk of the option parsing code (parse_options_prefix adds the './' prefix via fix_filename for OPTION_FILENAME). If they do want a file called 'syslog' or 'standard' they can specify it as an absolute path (starting with '/'), and fix_filename won't touch it.

Quoted 28 lines
ndctl/monitor.c new file +28 -0
+	}
+
+	if (monitor.daemon) {
+		if (daemon(0, 0) != 0) {
+			err((struct ndctl_ctx *)ctx, "daemon start failed\n");
+			goto out;
+		}
+		notice((struct ndctl_ctx *)ctx, "ndctl monitor daemon started\n");
+	}
+
+	if (parse_monitor_event(&monitor))
+		goto out;
+
+	fctx.filter_bus = filter_bus;
+	fctx.filter_dimm = filter_dimm;
+	fctx.filter_region = filter_region;
+	fctx.filter_namespace = NULL;
+	fctx.arg = &mfa;
+	list_head_init(&mfa.dimms);
+	mfa.num_dimm = 0;
+	mfa.maxfd_dimm = -1;
+	mfa.flags = 0;
+
+	if (util_filter_walk(ctx, &fctx, &param))
+		goto out;
+
+	if (!mfa.num_dimm) {
+		err((struct ndctl_ctx *)ctx, "no dimms to monitor\n");

ndctl/monitor.c line 539

Quoted 10 lines
ndctl/monitor.c new file +10 -0
+		goto out;
+	}
+
+	if (monitor_event(ctx, &mfa))
+		goto out;
+
+	return 0;
+out:
+	return 1;
+}

_______________________________________________
Linux-nvdimm mailing list
[email protected]
https://lists.01.org/mailman/listinfo/linux-nvdimm

author
#3 lore raw

PATCH v12 2/5 ndctl, monitor: add main ndctl monitor configuration file

In reply to QI Fuli

This patch adds the main configuration file(/etc/ndctl/monitor.conf) of ndctl monitor. It contains the configuration directives that give ndctl monitor instructions. Users can change the configuration by editing this file or using [--config-file] option to override this file. The changed value will work after restart ndctl monitor service.

---
 ndctl.spec.in      |   1 +
 ndctl/Makefile.am  |   5 +++
 ndctl/monitor.c    | 110 +++++++++++++++++++++++++++++++++++++++++++++
 ndctl/monitor.conf |  41 +++++++++++++++++
 4 files changed, 157 insertions(+)
 create mode 100644 ndctl/monitor.conf
ndctl.spec.in +1 -0
index e2c879c..42760fa 100644
@@ -141,6 +141,7 @@ make check
 %{_includedir}/ndctl/
 %{_libdir}/libndctl.so
 %{_libdir}/pkgconfig/libndctl.pc
+%{_sysconfdir}/ndctl/monitor.conf
 
 %files -n DAX_DNAME
 %defattr(-,root,root)
ndctl/Makefile.am +5 -0
index 083609a..4d0cccc 100644
@@ -42,3 +42,8 @@ ndctl_SOURCES += ../test/libndctl.c \
 		 ../test/core.c \
 		 test.c
 endif
+
+monitor_config_file = monitor.conf
+monitor_configdir = /etc/ndctl/
+monitor_config_DATA = $(monitor_config_file)
+EXTRA_DIST += $(monitor_config_file)
ndctl/monitor.c +110 -0

135 lines not on this page · raw message

ndctl/monitor.conf new file +41 -0

41 lines not on this page · raw message

Signature · 7 lines
2.18.0


_______________________________________________
Linux-nvdimm mailing list
[email protected]
https://lists.01.org/mailman/listinfo/linux-nvdimm
maintainer
#4 lore raw

Re: [ndctl PATCH v12 2/5] ndctl, monitor: add main ndctl monitor configuration file

Quoted 32 lines · QI Fuli

This patch adds the main configuration file(/etc/ndctl/monitor.conf) of ndctl monitor. It contains the configuration directives that give ndctl monitor instructions. Users can change the configuration by editing this file or using [--config-file] option to override this file. The changed value will work after restart ndctl monitor service.

---
 ndctl.spec.in      |   1 +
 ndctl/Makefile.am  |   5 +++
 ndctl/monitor.c    | 110 +++++++++++++++++++++++++++++++++++++++++++++
 ndctl/monitor.conf |  41 +++++++++++++++++
 4 files changed, 157 insertions(+)
 create mode 100644 ndctl/monitor.conf
ndctl.spec.in +1 -0
index e2c879c..42760fa 100644
@@ -141,6 +141,7 @@ make check
 %{_includedir}/ndctl/
 %{_libdir}/libndctl.so
 %{_libdir}/pkgconfig/libndctl.pc
+%{_sysconfdir}/ndctl/monitor.conf
 
 %files -n DAX_DNAME
 %defattr(-,root,root)
ndctl/Makefile.am +0 -0
index 083609a..4d0cccc 100644

ndctl/Makefile.am ndctl_SOURCES += ../test/libndctl.c \ · line 47

Quoted 6 lines
ndctl/Makefile.am +3 -0
@@ -42,3 +42,8 @@ ndctl_SOURCES += ../test/libndctl.c \
 		 ../test/core.c \
 		 test.c
 endif
+
+monitor_config_file = monitor.conf
+monitor_configdir = /etc/ndctl/

This path can't be hard coded - we need to pass it in from autoconf via a variable. Also see below in monitor.c.

Quoted 32 lines
ndctl/Makefile.am +2 -0
+monitor_config_DATA = $(monitor_config_file)
+EXTRA_DIST += $(monitor_config_file)
ndctl/monitor.c +15 -0
index caf8c3d..0b0f8f8 100644
@@ -19,6 +19,7 @@
 
 static struct monitor {
 	const char *log;
+	const char *config_file;
 	const char *dimm_event;
 	bool daemon;
 	bool human;
@@ -454,6 +455,109 @@ dimm_event_all:
 	return 0;
 }
 
+static void parse_config(const char **arg, char *key, char *val, char *ident)
+{
+	struct strbuf value = STRBUF_INIT;
+	size_t arg_len = *arg ? strlen(*arg) : 0;
+
+	if (!ident || !key || (strcmp(ident, key) != 0))
+		return;
+
+	if (arg_len) {
+		strbuf_add(&value, *arg, arg_len);
+		strbuf_addstr(&value, " ");
+	}
+	strbuf_addstr(&value, val);
+	*arg = strbuf_detach(&value, NULL);

ndctl/monitor.c dimm_event_all: · line 481

Quoted 10 lines
ndctl/monitor.c +10 -0
+}
+
+static int read_config_file(struct ndctl_ctx *ctx, struct monitor *_monitor,
+		struct util_filter_params *_param)
+{
+	FILE *f;
+	int line = 0;
+	size_t len = 0;
+	char *buf, *value, *config_file;
+	const char *def_config_file = "/etc/ndctl/monitor.conf";

Here too, the path needs to come via the same autoconf define as above.

Quoted 140 lines
ndctl/monitor.c +85 -0
+
+	if (_monitor->config_file)
+		config_file = strdup(_monitor->config_file);
+	else
+		config_file = strdup(def_config_file);
+	if (!config_file) {
+		fail("strdup default config file failed\n");
+		goto out;
+	}
+
+	buf = malloc(BUF_SIZE);
+	if (!buf) {
+		fail("malloc read config-file buf error\n");
+		goto out;
+	}
+
+	f = fopen(config_file, "r");
+	if (!f) {
+		fail("config-file: %s cannot be opened\n", config_file);
+		goto out;
+	}
+
+	while (fgets(buf, BUF_SIZE, f)) {
+		value = NULL;
+		line++;
+
+		while (isspace(*buf))
+			buf++;
+
+		if (*buf == '#' || *buf == '\0')
+			continue;
+
+		value = strchr(buf, '=');
+		if (!value) {
+			fail("config-file syntax error, skip line[%i]\n", line);
+			continue;
+		}
+
+		value[0] = '\0';
+		value++;
+
+		while (isspace(value[0]))
+			value++;
+
+		len = strlen(buf);
+		if (len == 0)
+			continue;
+		while (isspace(buf[len-1]))
+			len--;
+		buf[len] = '\0';
+
+		len = strlen(value);
+		if (len == 0)
+			continue;
+		while (isspace(value[len-1]))
+			len--;
+		value[len] = '\0';
+
+		if (len == 0)
+			continue;
+
+		parse_config(&_param->bus, "bus", value, buf);
+		parse_config(&_param->dimm, "dimm", value, buf);
+		parse_config(&_param->region, "region", value, buf);
+		parse_config(&_param->namespace, "namespace", value, buf);
+		parse_config(&_monitor->dimm_event, "dimm-event", value, buf);
+
+		if (!_monitor->log)
+			parse_config(&_monitor->log, "log", value, buf);
+	}
+	fclose(f);
+	free(config_file);
+	return 0;
+out:
+	if (config_file)
+		free(config_file);
+	return 1;
+}
+
 int cmd_monitor(int argc, const char **argv, void *ctx)
 {
 	const struct option options[] = {
@@ -469,6 +573,8 @@ int cmd_monitor(int argc, const char **argv, void *ctx)
 		OPT_FILENAME('l', "log", &monitor.log,
 				"<file> | syslog | standard",
 				"where to output the monitor's notification"),
+		OPT_FILENAME('c', "config-file", &monitor.config_file,
+				"config-file", "override the default config"),
 		OPT_BOOLEAN('x', "daemon", &monitor.daemon,
 				"run ndctl monitor as a daemon"),
 		OPT_BOOLEAN('u', "human", &monitor.human,
@@ -494,7 +600,11 @@ int cmd_monitor(int argc, const char **argv, void *ctx)
 	ndctl_set_log_fn((struct ndctl_ctx *)ctx, log_standard);
 	ndctl_set_log_priority((struct ndctl_ctx *)ctx, LOG_NOTICE);
 
+	if (read_config_file((struct ndctl_ctx *)ctx, &monitor, &param))
+		goto out;
+
 	if (monitor.log) {
+		fix_filename(prefix, (const char **)&monitor.log);
 		if (strcmp(monitor.log, "./syslog") == 0)
 			ndctl_set_log_fn((struct ndctl_ctx *)ctx, log_syslog);
 		else if (strcmp(monitor.log, "./standard") != 0)
ndctl/monitor.conf new file +31 -0
new file mode 100644
index 0000000..857aadf
@@ -0,0 +1,41 @@
+# This is the main ndctl monitor configuration file. It contains the
+# configuration directives that give ndctl monitor instructions.
+# You can change the configuration of ndctl monitor by editing this
+# file or using [--config-file=<file>] option to override this one.
+# The changed value will work after restart ndctl monitor service.
+
+# In this file, lines starting with a hash (#) are comments.
+# The configurations should follow <key> = <value> style.
+# Multiple space-separated values are allowed, but except the following
+# characters: : ? / \ % " ' $ & ! * { } [ ] ( ) = < > @
+
+# The objects to monitor are filtered via dimm's name by setting key "dimm".
+# If this value is different from the value of [--dimm=<value>] option,
+# both of the values will work.
+# dimm = all
+
+# The objects to monitor are filtered via its parent bus by setting key "bus".
+# If this value is different from the value of [--bus=<value>] option,
+# both of the values will work.
+# bus = all
+
+# The objects to monitor are filtered via region by setting key "region".
+# If this value is different from the value of [--region=<value>] option,
+# both of the values will work.
+# region = all
+
+# The objects to monitor are filtered via namespace by setting key "namespace".
+# If this value is different from the value of [--namespace=<value>] option,
+# both of the values will work.
+# namespace = all
+

ndctl/monitor.conf line 41

Quoted 10 lines
ndctl/monitor.conf new file +10 -0
+# The DIMM events to monitor are filtered via event type by setting key
+# "dimm-event". If this value is different from the value of
+# [--dimm-event=<value>] option, both of the values will work.
+# dimm-event = all
+
+# Users can choose to output the notifications to syslog (log=syslog),
+# to standard output (log=standard) or to write into a special file (log=<file>)
+# by setting key "log". If this value is in conflict with the value of
+# [--log=<value>] option, this value will be ignored.
+# log = /var/log/ndctl/monitor.log

_______________________________________________
Linux-nvdimm mailing list
[email protected]
https://lists.01.org/mailman/listinfo/linux-nvdimm

author
#5 lore raw

PATCH v12 3/5 ndctl, monitor: add the unit file of systemd for ndctl-monitor service

In reply to QI Fuli

This patch adds the systemd unit file for ndctl-monitor service. The systemd unit directory can be configured by setting environment variable "--with-systemd-unit-dir[=DIR]".

A monitor daemon can be started as a system service:

   # systemctl start ndctl-monitor.service
---
 autogen.sh                  |  3 ++-
 configure.ac                | 22 ++++++++++++++++++++++
 ndctl.spec.in               |  1 +
 ndctl/Makefile.am           |  4 ++++
 ndctl/ndctl-monitor.service |  7 +++++++
 5 files changed, 36 insertions(+), 1 deletion(-)
 create mode 100644 ndctl/ndctl-monitor.service
autogen.sh +2 -1
index 2a52688..21b0e25 100755
@@ -17,7 +17,8 @@ libdir() {
 
 args="--prefix=/usr \
 --sysconfdir=/etc \
---libdir=$(libdir /usr/lib)"
+--libdir=$(libdir /usr/lib) \
+--with-systemd-unit-dir"
 
 echo
 echo "----------------------------------------------------------------"
configure.ac +22 -0
index cf44260..a5ba9a1 100644
@@ -143,6 +143,27 @@ AC_CHECK_FUNCS([ \
 	secure_getenv\
 ])
 
+PKG_PROG_PKG_CONFIG
+AC_ARG_WITH([systemd-unit-dir],
+	AS_HELP_STRING([--with-systemd-unit-dir[=DIR]],
+		[Directory for systemd service files]),
+	[],
+	[with_systemd_unit_dir=yes])
+
+if test "x$with_systemd_unit_dir" = "xyes"; then
+	def_systemd_unit_dir=$($PKG_CONFIG --variable=systemdsystemunitdir systemd)
+	if test "x$def_systemd_unit_dir" = "x"; then
+		AC_MSG_ERROR([systemd support requested but pkg-config unable to query systemd package])
+		with_systemd_unit_dir=no
+	else
+		with_systemd_unit_dir="$def_systemd_unit_dir"
+	fi
+fi
+
+AS_IF([test "x$with_systemd_unit_dir" != "xno"],
+	[AC_SUBST([systemd_unitdir], [$with_systemd_unit_dir])])
+AM_CONDITIONAL([ENABLE_SYSTEMD_UNIT_DIR], [test "x$with_systemd_unit_dir" != "xno"])
+
 my_CFLAGS="\
 -Wall \
 -Wchar-subscripts \
@@ -184,6 +205,7 @@ AC_MSG_RESULT([
         sysconfdir:             ${sysconfdir}
         libdir:                 ${libdir}
         includedir:             ${includedir}
+	systemd-unit-dir:	${systemd_unitdir}
 
         compiler:               ${CC}
         cflags:                 ${CFLAGS}
ndctl.spec.in +1 -0
index 42760fa..6f7d299 100644
@@ -142,6 +142,7 @@ make check
 %{_libdir}/libndctl.so
 %{_libdir}/pkgconfig/libndctl.pc
 %{_sysconfdir}/ndctl/monitor.conf
+%{_unitdir}/ndctl-monitor.service
 
 %files -n DAX_DNAME
 %defattr(-,root,root)
ndctl/Makefile.am +4 -0
index 4d0cccc..087ddc5 100644
@@ -47,3 +47,7 @@ monitor_config_file = monitor.conf
 monitor_configdir = /etc/ndctl/
 monitor_config_DATA = $(monitor_config_file)
 EXTRA_DIST += $(monitor_config_file)
+
+if ENABLE_SYSTEMD_UNIT_DIR
+systemd_unit_DATA = ndctl-monitor.service
+endif
ndctl/ndctl-monitor.service new file +7 -0
new file mode 100644
index 0000000..44f9326
@@ -0,0 +1,7 @@
+[Unit]
+Description=Ndctl Monitor Daemon
+
+[Service]
+Type=forking
+ExecStart=/usr/bin/ndctl monitor --daemon
+ExecStop=/bin/kill ${MAINPID}
Signature · 7 lines
2.18.0


_______________________________________________
Linux-nvdimm mailing list
[email protected]
https://lists.01.org/mailman/listinfo/linux-nvdimm
#6 lore raw

Re: [ndctl PATCH v12 3/5] ndctl, monitor: add the unit file of systemd for ndctl-monitor service

Hi Qi,

Quoted 64 lines · QI Fuli

This patch adds the systemd unit file for ndctl-monitor service. The systemd unit directory can be configured by setting environment variable "--with-systemd-unit-dir[=DIR]".

A monitor daemon can be started as a system service:

   # systemctl start ndctl-monitor.service
---
 autogen.sh                  |  3 ++-
 configure.ac                | 22 ++++++++++++++++++++++
 ndctl.spec.in               |  1 +
 ndctl/Makefile.am           |  4 ++++
 ndctl/ndctl-monitor.service |  7 +++++++
 5 files changed, 36 insertions(+), 1 deletion(-)
 create mode 100644 ndctl/ndctl-monitor.service
autogen.sh +2 -1
index 2a52688..21b0e25 100755
@@ -17,7 +17,8 @@ libdir() {
 
 args="--prefix=/usr \
 --sysconfdir=/etc \
---libdir=$(libdir /usr/lib)"
+--libdir=$(libdir /usr/lib) \
+--with-systemd-unit-dir"
 
 echo
 echo "----------------------------------------------------------------"
configure.ac +21 -0
index cf44260..a5ba9a1 100644
@@ -143,6 +143,27 @@ AC_CHECK_FUNCS([ \
 	secure_getenv\
 ])
 
+PKG_PROG_PKG_CONFIG
+AC_ARG_WITH([systemd-unit-dir],
+	AS_HELP_STRING([--with-systemd-unit-dir[=DIR]],
+		[Directory for systemd service files]),
+	[],
+	[with_systemd_unit_dir=yes])
+
+if test "x$with_systemd_unit_dir" = "xyes"; then
+	def_systemd_unit_dir=$($PKG_CONFIG --variable=systemdsystemunitdir systemd)
+	if test "x$def_systemd_unit_dir" = "x"; then
+		AC_MSG_ERROR([systemd support requested but pkg-config unable to query systemd package])
+		with_systemd_unit_dir=no
+	else
+		with_systemd_unit_dir="$def_systemd_unit_dir"
+	fi
+fi
+
+AS_IF([test "x$with_systemd_unit_dir" != "xno"],
+	[AC_SUBST([systemd_unitdir], [$with_systemd_unit_dir])])
+AM_CONDITIONAL([ENABLE_SYSTEMD_UNIT_DIR], [test "x$with_systemd_unit_dir" != "xno"])
+
 my_CFLAGS="\
 -Wall \
 -Wchar-subscripts \

configure.ac AC_MSG_RESULT([ · line 209

Quoted 5 lines
configure.ac +1 -0
@@ -184,6 +205,7 @@ AC_MSG_RESULT([
         sysconfdir:             ${sysconfdir}
         libdir:                 ${libdir}
         includedir:             ${includedir}
 
+	systemd-unit-dir:	${systemd_unitdir}

not tab, white space is good here.

ndctl.spec.in make check · line 146

Quoted 13 lines
configure.ac +0 -0
         compiler:               ${CC}
         cflags:                 ${CFLAGS}
ndctl.spec.in +1 -0
index 42760fa..6f7d299 100644
@@ -142,6 +142,7 @@ make check
 %{_libdir}/libndctl.so
 %{_libdir}/pkgconfig/libndctl.pc
 
 %{_sysconfdir}/ndctl/monitor.conf
+%{_unitdir}/ndctl-monitor.service

The monitor conf and service should be included in ndctl package, so, why don't you add such as the following ?

%files
%defattr(-,root,root)
%license util/COPYING licenses/BSD-MIT licenses/CC0 %{_bindir}/ndctl
%{_mandir}/man1/ndctl*
%{bashcompdir}/ %{_sysconfdir}/ndctl/monitor.conf %{_unitdir}/ndctl-monitor.service

Thanks,
Masa

Quoted 22 lines
ndctl.spec.in +0 -0
 %files -n DAX_DNAME
 %defattr(-,root,root)
ndctl/Makefile.am +4 -0
index 4d0cccc..087ddc5 100644
@@ -47,3 +47,7 @@ monitor_config_file = monitor.conf
 monitor_configdir = /etc/ndctl/
 monitor_config_DATA = $(monitor_config_file)
 EXTRA_DIST += $(monitor_config_file)
+
+if ENABLE_SYSTEMD_UNIT_DIR
+systemd_unit_DATA = ndctl-monitor.service
+endif
ndctl/ndctl-monitor.service new file +0 -0
new file mode 100644
index 0000000..44f9326

ndctl/ndctl-monitor.service line 7

Quoted 7 lines
ndctl/ndctl-monitor.service new file +7 -0
@@ -0,0 +1,7 @@
+[Unit]
+Description=Ndctl Monitor Daemon
+
+[Service]
+Type=forking
+ExecStart=/usr/bin/ndctl monitor --daemon
+ExecStop=/bin/kill ${MAINPID}

_______________________________________________
Linux-nvdimm mailing list
[email protected]
https://lists.01.org/mailman/listinfo/linux-nvdimm

maintainer
#7 lore raw

Re: [ndctl PATCH v12 3/5] ndctl, monitor: add the unit file of systemd for ndctl-monitor service

Quoted 94 lines · Masayoshi Mizuma

Hi Qi,

Quoted 68 lines · QI Fuli

This patch adds the systemd unit file for ndctl-monitor service. The systemd unit directory can be configured by setting environment variable "--with-systemd-unit-dir[=DIR]".

A monitor daemon can be started as a system service:

   # systemctl start ndctl-monitor.service
---
 autogen.sh                  |  3 ++-
 configure.ac                | 22 ++++++++++++++++++++++
 ndctl.spec.in               |  1 +
 ndctl/Makefile.am           |  4 ++++
 ndctl/ndctl-monitor.service |  7 +++++++
 5 files changed, 36 insertions(+), 1 deletion(-)
 create mode 100644 ndctl/ndctl-monitor.service
autogen.sh +2 -2
index 2a52688..21b0e25 100755
@@ -17,7 +17,8 @@ libdir() {
 
 args="--prefix=/usr \
 --sysconfdir=/etc \
---libdir=$(libdir /usr/lib)"
+--libdir=$(libdir /usr/lib) \
+--with-systemd-unit-dir"
 
 echo
 echo "----------------------------------------------------------
------"
configure.ac +21 -0
index cf44260..a5ba9a1 100644
@@ -143,6 +143,27 @@ AC_CHECK_FUNCS([ \
 	secure_getenv\
 ])
 
+PKG_PROG_PKG_CONFIG
+AC_ARG_WITH([systemd-unit-dir],
+	AS_HELP_STRING([--with-systemd-unit-dir[=DIR]],
+		[Directory for systemd service files]),
+	[],
+	[with_systemd_unit_dir=yes])
+
+if test "x$with_systemd_unit_dir" = "xyes"; then
+	def_systemd_unit_dir=$($PKG_CONFIG --
 variable=systemdsystemunitdir systemd)
+	if test "x$def_systemd_unit_dir" = "x"; then
+		AC_MSG_ERROR([systemd support requested but pkg-
 config unable to query systemd package])
+		with_systemd_unit_dir=no
+	else
+		with_systemd_unit_dir="$def_systemd_unit_dir"
+	fi
+fi
+
+AS_IF([test "x$with_systemd_unit_dir" != "xno"],
+	[AC_SUBST([systemd_unitdir], [$with_systemd_unit_dir])])
+AM_CONDITIONAL([ENABLE_SYSTEMD_UNIT_DIR], [test
 "x$with_systemd_unit_dir" != "xno"])
+

my_CFLAGS="\
-Wall \
-Wchar-subscripts \

configure.ac AC_MSG_RESULT([ · line 208

Quoted 4 lines
configure.ac +1 -0
@@ -184,6 +205,7 @@ AC_MSG_RESULT([
         sysconfdir:             ${sysconfdir}
         libdir:                 ${libdir}
         includedir:             ${includedir}
+	systemd-unit-dir:	${systemd_unitdir}

not tab, white space is good here.

ndctl.spec.in make check · line 145

Quoted 12 lines
configure.ac +0 -0
         compiler:               ${CC}
         cflags:                 ${CFLAGS}
ndctl.spec.in +1 -0
index 42760fa..6f7d299 100644
@@ -142,6 +142,7 @@ make check
 %{_libdir}/libndctl.so
 %{_libdir}/pkgconfig/libndctl.pc
 %{_sysconfdir}/ndctl/monitor.conf
+%{_unitdir}/ndctl-monitor.service

The monitor conf and service should be included in ndctl package, so, why don't you add such as the following ?

Quoted 9 lines

%files
%defattr(-,root,root)
%license util/COPYING licenses/BSD-MIT licenses/CC0 %{_bindir}/ndctl
%{_mandir}/man1/ndctl*
%{bashcompdir}/ %{_sysconfdir}/ndctl/monitor.conf %{_unitdir}/ndctl-monitor.service

Yes these files need to be in the %files section, and not in the %files -n DNAME section (which is for the ndctl-devel package).
_______________________________________________
Linux-nvdimm mailing list
[email protected]
https://lists.01.org/mailman/listinfo/linux-nvdimm

maintainer
#8 lore raw

Re: [ndctl PATCH v12 3/5] ndctl, monitor: add the unit file of systemd for ndctl-monitor service

Quoted 107 lines · Vishal L
Quoted 96 lines · Masayoshi Mizuma

Hi Qi,

Quoted 69 lines · QI Fuli

This patch adds the systemd unit file for ndctl-monitor service. The systemd unit directory can be configured by setting environment
variable "--with-systemd-unit-dir[=DIR]".

A monitor daemon can be started as a system service:

   # systemctl start ndctl-monitor.service
---
 autogen.sh                  |  3 ++-
 configure.ac                | 22 ++++++++++++++++++++++
 ndctl.spec.in               |  1 +
 ndctl/Makefile.am           |  4 ++++
 ndctl/ndctl-monitor.service |  7 +++++++
 5 files changed, 36 insertions(+), 1 deletion(-)
 create mode 100644 ndctl/ndctl-monitor.service
autogen.sh +2 -2
index 2a52688..21b0e25 100755
@@ -17,7 +17,8 @@ libdir() {
 
 args="--prefix=/usr \
 --sysconfdir=/etc \
---libdir=$(libdir /usr/lib)"
+--libdir=$(libdir /usr/lib) \
+--with-systemd-unit-dir"
 
 echo
 echo "----------------------------------------------------------
------"
configure.ac +21 -0
index cf44260..a5ba9a1 100644
@@ -143,6 +143,27 @@ AC_CHECK_FUNCS([ \
 	secure_getenv\
 ])
 
+PKG_PROG_PKG_CONFIG
+AC_ARG_WITH([systemd-unit-dir],
+	AS_HELP_STRING([--with-systemd-unit-dir[=DIR]],
+		[Directory for systemd service files]),
+	[],
+	[with_systemd_unit_dir=yes])
+
+if test "x$with_systemd_unit_dir" = "xyes"; then
+	def_systemd_unit_dir=$($PKG_CONFIG --
 variable=systemdsystemunitdir systemd)
+	if test "x$def_systemd_unit_dir" = "x"; then
+		AC_MSG_ERROR([systemd support requested but pkg-
 config unable to query systemd package])
+		with_systemd_unit_dir=no
+	else
+		with_systemd_unit_dir="$def_systemd_unit_dir"
+	fi
+fi
+
+AS_IF([test "x$with_systemd_unit_dir" != "xno"],
+	[AC_SUBST([systemd_unitdir], [$with_systemd_unit_dir])])
+AM_CONDITIONAL([ENABLE_SYSTEMD_UNIT_DIR], [test
 "x$with_systemd_unit_dir" != "xno"])
+

my_CFLAGS="\
-Wall \
-Wchar-subscripts \

configure.ac AC_MSG_RESULT([ · line 208

Quoted 4 lines
configure.ac +1 -0
@@ -184,6 +205,7 @@ AC_MSG_RESULT([
         sysconfdir:             ${sysconfdir}
         libdir:                 ${libdir}
         includedir:             ${includedir}
+	systemd-unit-dir:	${systemd_unitdir}

not tab, white space is good here.

ndctl.spec.in make check · line 145

Quoted 12 lines
configure.ac +0 -0
         compiler:               ${CC}
         cflags:                 ${CFLAGS}
ndctl.spec.in +1 -0
index 42760fa..6f7d299 100644
@@ -142,6 +142,7 @@ make check
 %{_libdir}/libndctl.so
 %{_libdir}/pkgconfig/libndctl.pc
 %{_sysconfdir}/ndctl/monitor.conf
+%{_unitdir}/ndctl-monitor.service

The monitor conf and service should be included in ndctl package, so,
why don't you add such as the following ?

Quoted 9 lines

%files
%defattr(-,root,root)
%license util/COPYING licenses/BSD-MIT licenses/CC0 %{_bindir}/ndctl
%{_mandir}/man1/ndctl*
%{bashcompdir}/ %{_sysconfdir}/ndctl/monitor.conf %{_unitdir}/ndctl-monitor.service

Quoted 2 lines

Yes these files need to be in the %files section, and not in the %files -n DNAME section (which is for the ndctl-devel package).

Also according to this:
https://fedoraproject.org/wiki/Packaging:Systemd#Filesystem_locations

We'll need to add:

BuildRequires: systemd

Quoted 4 lines

_______________________________________________
Linux-nvdimm mailing list
[email protected]
https://lists.01.org/mailman/listinfo/linux-nvdimm

_______________________________________________
Linux-nvdimm mailing list
[email protected]
https://lists.01.org/mailman/listinfo/linux-nvdimm

author
#9 lore raw

PATCH v12 4/5 ndctl, documentation: add man page for monitor

In reply to QI Fuli

This patch is used to add man page for ndctl monitor command.

---
 Documentation/ndctl/Makefile.am       |   3 +-
 Documentation/ndctl/ndctl-monitor.txt | 104 ++++++++++++++++++++++++++
 2 files changed, 106 insertions(+), 1 deletion(-)
 create mode 100644 Documentation/ndctl/ndctl-monitor.txt
Documentation/ndctl/Makefile.am +2 -1
index 4fd9636..a30b139 100644
@@ -46,7 +46,8 @@ man1_MANS = \
 	ndctl-inject-error.1 \
 	ndctl-inject-smart.1 \
 	ndctl-update-firmware.1 \
-	ndctl-list.1
+	ndctl-list.1 \
+	ndctl-monitor.1
 
 CLEANFILES = $(man1_MANS)
 
Documentation/ndctl/ndctl-monitor.txt new file +104 -0

104 lines not on this page · raw message

Signature · 7 lines
2.18.0


_______________________________________________
Linux-nvdimm mailing list
[email protected]
https://lists.01.org/mailman/listinfo/linux-nvdimm
maintainer
#10 lore raw

Re: [ndctl PATCH v12 4/5] ndctl, documentation: add man page for monitor

Quoted 108 lines · QI Fuli

This patch is used to add man page for ndctl monitor command.

---
 Documentation/ndctl/Makefile.am       |   3 +-
 Documentation/ndctl/ndctl-monitor.txt | 104 ++++++++++++++++++++++++++
 2 files changed, 106 insertions(+), 1 deletion(-)
 create mode 100644 Documentation/ndctl/ndctl-monitor.txt
Documentation/ndctl/Makefile.am +2 -1
index 4fd9636..a30b139 100644
@@ -46,7 +46,8 @@ man1_MANS = \
 	ndctl-inject-error.1 \
 	ndctl-inject-smart.1 \
 	ndctl-update-firmware.1 \
-	ndctl-list.1
+	ndctl-list.1 \
+	ndctl-monitor.1
 
 CLEANFILES = $(man1_MANS)
 
Documentation/ndctl/ndctl-monitor.txt new file +79 -0
new file mode 100644
index 0000000..4f1803e
@@ -0,0 +1,104 @@
+// SPDX-License-Identifier: GPL-2.0
+
+ndctl-monitor(1)
+================
+
+NAME
+----
+ndctl-monitor - Monitor the smart events of nvdimm objects
+
+SYNOPSIS
+--------
+[verse]
+'ndctl monitor' [<options>]
+
+DESCRIPTION
+-----------
+Ndctl monitor is used for monitoring the smart events of nvdimm
+objects and dumping the json format notifications to syslog, standard
+output or a logfile.
+
+The objects to monitor and smart events to notify can be selected by
+setting options and/or the default configuration file
+(/etc/ndctl/monitor.conf). Both of the values in configuration file
+and in options will work. If there is a conflict, the values in
+options will override the values in configuration file. The changed
+values in configuration file will work after the monitor is restarted.
+
+The smart threshold evnet alarm of dimm will be turned on when the
+monitor gets started, if it is set off.
+
+EXAMPLES
+--------
+
+Run a monitor as a daemon to monitor DIMMs on bus "nfit_test.1"
+[verse]
+ndctl monitor --bus nfit_test.1 --daemon
+
+Run a monitor as a one-shot command and output the notifications to
+/var/log/ndctl.log
+[verse]
+ndctl monitor -log /var/log/ndctl.log
+
+Run a monitor daemon as a system service
+[verse]
+systemctl start ndctl-monitor.service
+
+OPTIONS
+-------
+-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.
+
+-d::
+--dimm=::
+	A 'nmemX' device name, or dimm id number. Select the devices to
+	monitor reference the given dimm.
+
+-r::
+--region=::
+	A 'regionX' device name, or a region id number. The keyword 'all'
+	can be specified to carry out the operation on every region in
+	the system, optionally filtered by bus id (see --bus= option).
+
+-n::
+--namespace=::
+	A 'namespaceX.Y' device name, or namespace region plus id tuple
+	'X.Y'.
+
+-l <file | syslog | standard>::
+--log=<file | syslog | standard>::
+	Output notifications to <file>, syslog or standard output.
+
+--daemon::
+	Run a monitor as a daemon.
+
+-D::
+--dimm-event=::

Documentation/ndctl/ndctl-monitor.txt line 89

Quoted 10 lines
Documentation/ndctl/ndctl-monitor.txt new file +10 -0
+	Name of an smart health event from the following:
+	- "dimm-spares-remaining": Spare Blocks Remaining value has gone
+	   below the pre-programmed threshold.
+	- "dimm-media-temperature": NVDIMM Media temperature value has
+	   gone above the pre-programmed threshold.
+	- "dimm-controller-temperature": NVDIMM Controller temperature
+	   value has gone above the pre-programmed threshold.
+	- "dimm-health-state": NVDIMM Normal Health Status has changed
+	- "dimm-unclean-shutdown": NVDIMM Last Shutdown Status was a
+	   unclean shutdown.

Can you add a short note here saying something like:
"The monitor will attempt to enable the alarm control bits for all specified events."

The rest of this looks good, thanks for the quick updates!

Quoted 5 lines
Documentation/ndctl/ndctl-monitor.txt new file +5 -0
+-u::
+--human::
+	Output monitor notification as human friendly json format instead
+	of the default machine friendly json format.
+

Documentation/ndctl/ndctl-monitor.txt line 104

Quoted 10 lines
Documentation/ndctl/ndctl-monitor.txt new file +10 -0
+COPYRIGHT
+---------
+Copyright (c) 2018, FUJITSU LIMITED. License GPLv2: GNU GPL version 2
+<http://gnu.org/licenses/gpl.html>. This is free software: you are
+free to change and redistribute it. There is NO WARRANTY, to the
+extent permitted by law.
+
+SEE ALSO
+--------
+linkndctl:ndctl-list[1], linkndctl:ndctl-inject-smart[1]

_______________________________________________
Linux-nvdimm mailing list
[email protected]
https://lists.01.org/mailman/listinfo/linux-nvdimm

author
#11 lore raw

PATCH v12 5/5 ndctl, test: add a new unit test for monitor

In reply to QI Fuli

Add a new unit test to test all options of the monitor command.

---
 .gitignore             |   1 +
 test/Makefile.am       |  14 +++-
 test/list-smart-dimm.c | 117 +++++++++++++++++++++++++++
 test/monitor.sh        | 176 +++++++++++++++++++++++++++++++++++++++++
 4 files changed, 306 insertions(+), 2 deletions(-)
 create mode 100644 test/list-smart-dimm.c
 create mode 100755 test/monitor.sh
.gitignore +1 -0
index 1016b3b..0baace4 100644
@@ -56,3 +56,4 @@ test/smart-notify
 test/fio.job
 test/local-write-0-verify.state
 test/ack-shutdown-count-set
+test/list-smart-dimm
test/Makefile.am +12 -2
index cd451e9..8c55056 100644
@@ -21,7 +21,8 @@ TESTS =\
 	btt-pad-compat.sh \
 	firmware-update.sh \
 	ack-shutdown-count-set \
-	rescan-partitions.sh
+	rescan-partitions.sh \
+	monitor.sh
 
 check_PROGRAMS =\
 	libndctl \
@@ -34,7 +35,8 @@ check_PROGRAMS =\
 	smart-listen \
 	hugetlb \
 	daxdev-errors \
-	ack-shutdown-count-set
+	ack-shutdown-count-set \
+	list-smart-dimm
 
 if ENABLE_DESTRUCTIVE
 TESTS +=\
@@ -151,3 +153,11 @@ multi_pmem_LDADD = \
 		$(UUID_LIBS) \
 		$(KMOD_LIBS) \
 		../libutil.a
+
+list_smart_dimm_SOURCES = \
+		list-smart-dimm.c \
+		../util/json.c
+list_smart_dimm_LDADD = \
+		$(LIBNDCTL_LIB) \
+		$(JSON_LIBS) \
+		../libutil.a
test/list-smart-dimm.c new file +117 -0

117 lines not on this page · raw message

test/monitor.sh new file +176 -0

176 lines not on this page · raw message

Signature · 7 lines
2.18.0


_______________________________________________
Linux-nvdimm mailing list
[email protected]
https://lists.01.org/mailman/listinfo/linux-nvdimm
#12 lore raw

Re: [ndctl PATCH v12 5/5] ndctl, test: add a new unit test for monitor

Hi Qi,

Quoted 5 lines · QI Fuli

Add a new unit test to test all options of the monitor command.

[...]

test/monitor.sh line 145

Quoted 11 lines
test/monitor.sh new file +10 -0
+test_filter_dimmevent()
+{
+	monitor_dimms="$(get_monitor_dimm | awk '{print $1}')"
+
+	start_monitor "-d $monitor_dimms -D dimm-unclean-shutdown"
+	inject_smart "-U"
+	check_result "$monitor_dimms"
+	stop_monitor
+
 
+	inject_value=$($NDCTL list -H -d $monitor_dimms | jq -r .[]."health"."spares_threshold")
        inject_value=$($NDCTL list -H -d $monitor_dimms | jq -r "(.[]) | .health.spares_threshold")

test/monitor.sh line 152

Quoted 8 lines
test/monitor.sh new file +7 -0
+	inject_value=$((inject_value - 1))
+	start_monitor "-d $monitor_dimms -D dimm-spares-remaining"
+	inject_smart "-s $inject_value"
+	check_result "$monitor_dimms"
+	stop_monitor
+
 
+	inject_value=$($NDCTL list -H -d $monitor_dimms | jq -r .[]."health"."temperature_threshold")
        inject_value=$($NDCTL list -H -d $monitor_dimms | jq -r "(.[]) | .health.temperature_threshold")

The rest looks good. Please feel free to add:...
Oh, it has already added, nice :-)

Quoted 1 line

Thanks,
Masa
_______________________________________________
Linux-nvdimm mailing list
[email protected]
https://lists.01.org/mailman/listinfo/linux-nvdimm