[pve-devel] [PATCH 1/1] dmeventd: ensure service gets stopped normally on shutdown

Thomas Lamprecht t.lamprecht at proxmox.com
Thu Oct 5 14:05:25 CEST 2017


cherry-pick two patches which ensure that dmeventd gets always
stopped when requested (i.e. if exiting is not ok at the moment it
gets scheduled for the next possible moment and not thrown away) and
which also ensures that it gets stopped more safely on shutdown.

This addresses a issue where when LVM(thin) was used on a host
shutdown could hang need 90 seconds longer, seemingly hanging for
this time as without debug log active no message got shown.
---
 .../0004-dmeventd-schedule-exit-on-break.patch     | 82 ++++++++++++++++++++++
 ...d-ensure-service-gets-stopped-on-shutdown.patch | 46 ++++++++++++
 patchdir/series                                    |  2 +
 3 files changed, 130 insertions(+)
 create mode 100644 patchdir/0004-dmeventd-schedule-exit-on-break.patch
 create mode 100644 patchdir/0005-dmeventd-ensure-service-gets-stopped-on-shutdown.patch

diff --git a/patchdir/0004-dmeventd-schedule-exit-on-break.patch b/patchdir/0004-dmeventd-schedule-exit-on-break.patch
new file mode 100644
index 0000000..ed5dd44
--- /dev/null
+++ b/patchdir/0004-dmeventd-schedule-exit-on-break.patch
@@ -0,0 +1,82 @@
+From 9940c2f754e3292b6d96628682c254941ae6cc58 Mon Sep 17 00:00:00 2001
+From: Zdenek Kabelac <zkabelac at redhat.com>
+Date: Wed, 4 Oct 2017 13:58:21 +0200
+Subject: [PATCH] dmeventd: schedule exit on break
+
+When dmeventd receives SIGTERM/INT/HUP/QUIT it validates if exit is possible.
+If there was any device still monitored, such exit request used to
+be ignored/refused. This 'usually' worked reasonably well, however if there
+is very short time period between last device is unmonitored and signal
+reception - there was possibility such EXIT was ignored, as dmeventd has
+not yet got into idle state even commands like 'vgchange -an' has already
+finished.
+
+This patch changes logic towards scheduling EXIT to the nearest
+point when there is no monitored device.
+
+EXIT is never forgotten.
+
+NOTE: if there is only a single monitored device and someone sends
+SIGTERM and later someone uses i.e. 'lvchange --refresh' after
+unmonitoring dmeventd will exit and new instance needs to be
+started.
+
+cherry picked from commit 9940c2f754e3292b6d96628682c254941ae6cc58
+
+Signed-off-by: Thomas Lamprecht <t.lamprecht at proxmox.com>
+---
+ daemons/dmeventd/dmeventd.c | 13 ++++++++-----
+ 1 files changed, 8 insertions(+), 5 deletions(-)
+
+diff --git a/daemons/dmeventd/dmeventd.c b/daemons/dmeventd/dmeventd.c
+index 3a92ab6..cc520d3 100644
+--- a/daemons/dmeventd/dmeventd.c
++++ b/daemons/dmeventd/dmeventd.c
+@@ -62,6 +62,8 @@
+ 
+ #include <syslog.h>
+ 
++#define DM_SIGNALED_EXIT  1
++#define DM_SCHEDULED_EXIT 2
+ static volatile sig_atomic_t _exit_now = 0;	/* set to '1' when signal is given to exit */
+ 
+ /* List (un)link macros. */
+@@ -1750,7 +1752,7 @@ static void _init_thread_signals(void)
+  */
+ static void _exit_handler(int sig __attribute__((unused)))
+ {
+-	_exit_now = 1;
++	_exit_now = DM_SIGNALED_EXIT;
+ }
+ 
+ #ifdef __linux__
+@@ -2248,6 +2250,8 @@ int main(int argc, char *argv[])
+ 	for (;;) {
+ 		if (_idle_since) {
+ 			if (_exit_now) {
++				if (_exit_now == DM_SCHEDULED_EXIT)
++					break; /* Only prints shutdown message */
+ 				log_info("dmeventd detected break while being idle "
+ 					 "for %ld second(s), exiting.",
+ 					 (long) (time(NULL) - _idle_since));
+@@ -2264,15 +2268,14 @@ int main(int argc, char *argv[])
+ 					break;
+ 				}
+ 			}
+-		} else if (_exit_now) {
+-			_exit_now = 0;
++		} else if (_exit_now == DM_SIGNALED_EXIT) {
++			_exit_now = DM_SCHEDULED_EXIT;
+ 			/*
+ 			 * When '_exit_now' is set, signal has been received,
+ 			 * but can not simply exit unless all
+ 			 * threads are done processing.
+ 			 */
+-			log_warn("WARNING: There are still devices being monitored.");
+-			log_warn("WARNING: Refusing to exit.");
++			log_info("dmeventd received break, scheduling exit.");
+ 		}
+ 		_process_request(&fifos);
+ 		_cleanup_unused_threads();
+-- 
+2.9.3
diff --git a/patchdir/0005-dmeventd-ensure-service-gets-stopped-on-shutdown.patch b/patchdir/0005-dmeventd-ensure-service-gets-stopped-on-shutdown.patch
new file mode 100644
index 0000000..d731649
--- /dev/null
+++ b/patchdir/0005-dmeventd-ensure-service-gets-stopped-on-shutdown.patch
@@ -0,0 +1,46 @@
+From a781b1c1788461595f382918bb1fc210d248d444 Mon Sep 17 00:00:00 2001
+From: Thomas Lamprecht <t.lamprecht at proxmox.com>
+Date: Thu, 5 Oct 2017 12:52:15 +0200
+Subject: [PATCH] dmeventd: ensure systemd service gets stopped on shutdown
+
+Add these for dmeventd systemd unit (dm-event.service):
+
+  Before: shutdown.target
+  Conflicts: shutdown.target
+
+This will cause the dmeventd to be properly stopped at shutdown (after
+all the dmeventd clients unregistered their devices from monitoring)
+with dm-event.service's stop action (there's no direct action defined
+for the "stop" so systemd sends SIGTERM instead).
+
+Before, we let dmeventd to get killed only as part of the very last
+SIGTERM/SIGKILL for all the remaining processes late in the shutdown
+sequence so we may have missed some logs if dmeventd encountered an
+error during its shutdown (logging facilities are already off at this
+late time in shutdown sequence).
+
+Ref: https://www.redhat.com/archives/lvm-devel/2017-October/msg00000.html
+
+cherry picked from commit a781b1c1788461595f382918bb1fc210d248d444
+
+Signed-off-by: Thomas Lamprecht <t.lamprecht at proxmox.com>
+---
+ scripts/dm_event_systemd_red_hat.service.in | 3 ++-
+ 1 file changed, 2 insertions(+), 1 deletion(-)
+
+diff --git a/scripts/dm_event_systemd_red_hat.service.in b/scripts/dm_event_systemd_red_hat.service.in
+index 7c607aa..4924d39 100644
+--- a/scripts/dm_event_systemd_red_hat.service.in
++++ b/scripts/dm_event_systemd_red_hat.service.in
+@@ -3,7 +3,8 @@ Description=Device-mapper event daemon
+ Documentation=man:dmeventd(8)
+ Requires=dm-event.socket
+ After=dm-event.socket
+-Before=local-fs-pre.target
++Before=local-fs-pre.target shutdown.target
++Conflicts=shutdown.target
+ DefaultDependencies=no
+ 
+ [Service]
+-- 
+2.9.3
diff --git a/patchdir/series b/patchdir/series
index 04c3677..9190687 100644
--- a/patchdir/series
+++ b/patchdir/series
@@ -1,3 +1,5 @@
 0001-filter-zvols-and-PVE-VG-by-default.patch
 0002-enable-issue_discards-by-default.patch
 0003-disable-use-lvmetad.patch
+0004-dmeventd-schedule-exit-on-break.patch
+0005-dmeventd-ensure-service-gets-stopped-on-shutdown.patch
-- 
2.11.0





More information about the pve-devel mailing list