Skip to contentSkip to conversation

multipath-tools: fixes for systemd watchdog

PATCH In review Martin Wilck 2 participants 3 messages Nov 19, 2024 Device mapper

lore
Share & tools
lore
#0 lore raw

v3 cover multipath-tools: fixes for systemd watchdog

After Ben Marzinski's feedback to v1 of this series, reworked the watchdog logic completely, and moved it in to multipathd. The watchdog interval is now independent of the checker interval. systemd's watchdog enablement logic is correctly followed, and better fallbacks are used in case of unreasonable settings in the unit file.

Changes v2->v3 (suggested by Ben Marzinski)
- Use time stamp in watchdog_tick
- Use unsigned long long in get_watchdog_interval

Changes v1->v2 (suggested by Ben Marzinski)
- Complete rewrite.

Martin Wilck (1):
multipathd: move systemd watchdog handling into daemon

 libmultipath/config.c | 25 ----------------
 libmultipath/config.h |  1 -
 multipathd/main.c     | 70 ++++++++++++++++++++++++++++++++++---------
 3 files changed, 56 insertions(+), 40 deletions(-)
Signature · 1 line
2.47.0
#1 lore raw

PATCH v3 1/1 multipathd: move systemd watchdog handling into daemon

Only multipathd needs to take care of notifying systemd. There's no need to track this information in struct config, or to limit our checker interval to it, as checkerloop() wakes up every second anyway.

While at it, fix the watchdog enablement logic:

- the watchdog should only be active if WATCHDOG_PID is either unset, or matches the daemon's PID, and if WATCHDOG_USEC is not 0.
- the watchdog should trigger twice per systemd-set interval.
- if WatchdogSec= is set to an unreasonable value, make a smarter choice than just disabling the watchdog, and print a more meaningful error message.

Use timestamp comparison to make sure the watchdog is triggered even if a checkerloop iteration takes more than a second.

---
 libmultipath/config.c | 25 ----------------
 libmultipath/config.h |  1 -
 multipathd/main.c     | 70 ++++++++++++++++++++++++++++++++++---------
 3 files changed, 56 insertions(+), 40 deletions(-)
libmultipath/config.c +0 -25
index 0e3a5cc..8b424d1 100644
@@ -858,27 +858,6 @@ process_config_dir(struct config *conf, char *dir)
 	pthread_cleanup_pop(1);
 }
 
-#ifdef USE_SYSTEMD
-static void set_max_checkint_from_watchdog(struct config *conf)
-{
-	char *envp = getenv("WATCHDOG_USEC");
-	unsigned long checkint;
-
-	if (envp && sscanf(envp, "%lu", &checkint) == 1) {
-		/* Value is in microseconds */
-		checkint /= 1000000;
-		if (checkint < 1 || checkint > UINT_MAX) {
-			condlog(1, "invalid value for WatchdogSec: \"%s\"", envp);
-			return;
-		}
-		if (conf->max_checkint == 0 || conf->max_checkint > checkint)
-			conf->max_checkint = checkint;
-		condlog(3, "enabling watchdog, interval %ld", checkint);
-		conf->use_watchdog = true;
-	}
-}
-#endif
-
 static int init_config__ (const char *file, struct config *conf);
 
 int init_config(const char *file)
@@ -916,7 +895,6 @@ int init_config__ (const char *file, struct config *conf)
 	conf->attribute_flags = 0;
 	conf->reassign_maps = DEFAULT_REASSIGN_MAPS;
 	conf->checkint = CHECKINT_UNDEF;
-	conf->use_watchdog = false;
 	conf->max_checkint = 0;
 	conf->force_sync = DEFAULT_FORCE_SYNC;
 	conf->partition_delim = (default_partition_delim != NULL ?
@@ -967,9 +945,6 @@ int init_config__ (const char *file, struct config *conf)
 	/*
 	 * fill the voids left in the config file
 	 */
-#ifdef USE_SYSTEMD
-	set_max_checkint_from_watchdog(conf);
-#endif
 	if (conf->max_checkint == 0) {
 		if (conf->checkint == CHECKINT_UNDEF)
 			conf->checkint = DEFAULT_CHECKINT;
libmultipath/config.h +0 -1
index 94cdf25..5b4ebf8 100644
@@ -148,7 +148,6 @@ struct config {
 	unsigned int checkint;
 	unsigned int max_checkint;
 	unsigned int adjust_int;
-	bool use_watchdog;
 	int pgfailback;
 	int rr_weight;
 	int no_path_retry;
multipathd/main.c +56 -14

94 lines not on this page · raw message

Signature · 1 line
2.47.0
maintainer Reviewed-by on v3 1/1
#2 lore raw

Re: [PATCH v3 1/1] multipathd: move systemd watchdog handling into daemon

Quoted 13 lines · Martin Wilck

Only multipathd needs to take care of notifying systemd. There's no need to track this information in struct config, or to limit our checker interval to it, as checkerloop() wakes up every second anyway.

While at it, fix the watchdog enablement logic:

- the watchdog should only be active if WATCHDOG_PID is either unset, or matches the daemon's PID, and if WATCHDOG_USEC is not 0.
- the watchdog should trigger twice per systemd-set interval.
- if WatchdogSec= is set to an unreasonable value, make a smarter choice than just disabling the watchdog, and print a more meaningful error message.

Quoted 4 lines

Use timestamp comparison to make sure the watchdog is triggered even if a checkerloop iteration takes more than a second.