Blame SOURCES/bz1922437-fence_mpath-watchdog-retry-support.patch

c2359a
From 2c9ce6a7667e09010d498ca9d9bcf6e476123bbb Mon Sep 17 00:00:00 2001
c2359a
From: Oyvind Albrigtsen <oalbrigt@redhat.com>
c2359a
Date: Thu, 20 May 2021 12:51:12 +0200
c2359a
Subject: [PATCH] fence_mpath: watchdog retries support
c2359a
c2359a
Added options to be able to be able to set number of retries and sleep between retries.
c2359a
---
c2359a
 agents/mpath/fence_mpath.py         | 44 +++++++++++++++++++++--------
c2359a
 tests/data/metadata/fence_mpath.xml |  4 ++-
c2359a
 2 files changed, 35 insertions(+), 13 deletions(-)
c2359a
c2359a
diff --git a/agents/mpath/fence_mpath.py b/agents/mpath/fence_mpath.py
c2359a
index 08dab6536..61ab1f205 100644
c2359a
--- a/agents/mpath/fence_mpath.py
c2359a
+++ b/agents/mpath/fence_mpath.py
c2359a
@@ -4,6 +4,7 @@
c2359a
 import stat
c2359a
 import re
c2359a
 import os
c2359a
+import time
c2359a
 import logging
c2359a
 import atexit
c2359a
 import ctypes
c2359a
@@ -167,14 +168,20 @@ def dev_read(options, fail=True):
c2359a
 	store_fh.close()
c2359a
 	return dev_key
c2359a
 
c2359a
-def mpath_check_get_verbose():
c2359a
+def mpath_check_get_options(options):
c2359a
 	try:
c2359a
-		f = open("/etc/sysconfig/watchdog", "r")
c2359a
+		f = open("/etc/sysconfig/stonith", "r")
c2359a
 	except IOError:
c2359a
-		return False
c2359a
-	match = re.search(r"^\s*verbose=yes", "".join(f.readlines()), re.MULTILINE)
c2359a
+		return options
c2359a
+
c2359a
+	match = re.findall(r"^\s*(\S*)\s*=\s*(\S*)\s*", "".join(f.readlines()), re.MULTILINE)
c2359a
+
c2359a
+	for m in match:
c2359a
+		options[m[0].lower()] = m[1].lower()
c2359a
+
c2359a
 	f.close()
c2359a
-	return bool(match)
c2359a
+
c2359a
+	return options
c2359a
 
c2359a
 def mpath_check(hardreboot=False):
c2359a
 	if len(sys.argv) >= 3 and sys.argv[1] == "repair":
c2359a
@@ -183,18 +190,27 @@ def mpath_check(hardreboot=False):
c2359a
 	options["--mpathpersist-path"] = "/usr/sbin/mpathpersist"
c2359a
 	options["--store-path"] = "/var/run/cluster"
c2359a
 	options["--power-timeout"] = "5"
c2359a
-	if mpath_check_get_verbose():
c2359a
+	options["retry"] = "0"
c2359a
+	options["retry-sleep"] = "1"
c2359a
+	options = mpath_check_get_options(options)
c2359a
+	if "verbose" in options and options["verbose"] == "yes":
c2359a
 		logging.getLogger().setLevel(logging.DEBUG)
c2359a
 	devs = dev_read(options, fail=False)
c2359a
 	if not devs:
c2359a
 		logging.error("No devices found")
c2359a
 		return 0
c2359a
 	for dev, key in list(devs.items()):
c2359a
-		if key in get_registration_keys(options, dev, fail=False):
c2359a
-			logging.debug("key " + key + " registered with device " + dev)
c2359a
-			return 0
c2359a
-		else:
c2359a
-			logging.debug("key " + key + " not registered with device " + dev)
c2359a
+		for n in range(int(options["retry"]) + 1):
c2359a
+			if n > 0:
c2359a
+				logging.debug("retry: " + str(n) + " of " + options["retry"])
c2359a
+			if key in get_registration_keys(options, dev, fail=False):
c2359a
+				logging.debug("key " + key + " registered with device " + dev)
c2359a
+				return 0
c2359a
+			else:
c2359a
+				logging.debug("key " + key + " not registered with device " + dev)
c2359a
+
c2359a
+			if n < int(options["retry"]):
c2359a
+				time.sleep(float(options["retry-sleep"]))
c2359a
 	logging.debug("key " + key + " registered with any devices")
c2359a
 
c2359a
 	if hardreboot == True:
c2359a
@@ -289,7 +305,11 @@ def main():
c2359a
 device(s). The result is that only registered nodes may write to the \
c2359a
 device(s). When a node failure occurs, the fence_mpath agent will remove the \
c2359a
 key belonging to the failed node from the device(s). The failed node will no \
c2359a
-longer be able to write to the device(s). A manual reboot is required."
c2359a
+longer be able to write to the device(s). A manual reboot is required.\
c2359a
+\n.P\n\
c2359a
+When used as a watchdog device you can define e.g. retry=1, retry-sleep=2 and \
c2359a
+verbose=yes parameters in /etc/sysconfig/stonith if you have issues with it \
c2359a
+failing."
c2359a
 	docs["vendorurl"] = "https://www.sourceware.org/dm/"
c2359a
 	show_docs(options, docs)
c2359a
 
c2359a
diff --git a/tests/data/metadata/fence_mpath.xml b/tests/data/metadata/fence_mpath.xml
c2359a
index 524776aa0..0255d4b4e 100644
c2359a
--- a/tests/data/metadata/fence_mpath.xml
c2359a
+++ b/tests/data/metadata/fence_mpath.xml
c2359a
@@ -1,7 +1,9 @@
c2359a
 
c2359a
 <resource-agent name="fence_mpath" shortdesc="Fence agent for multipath persistent reservation" >
c2359a
 <longdesc>fence_mpath is an I/O fencing agent that uses SCSI-3 persistent reservations to control access multipath devices. Underlying devices must support SCSI-3 persistent reservations (SPC-3 or greater) as well as the "preempt-and-abort" subcommand.
c2359a
-The fence_mpath agent works by having a unique key for each node that has to be set in /etc/multipath.conf. Once registered, a single node will become the reservation holder by creating a "write exclusive, registrants only" reservation on the device(s). The result is that only registered nodes may write to the device(s). When a node failure occurs, the fence_mpath agent will remove the key belonging to the failed node from the device(s). The failed node will no longer be able to write to the device(s). A manual reboot is required.</longdesc>
c2359a
+The fence_mpath agent works by having a unique key for each node that has to be set in /etc/multipath.conf. Once registered, a single node will become the reservation holder by creating a "write exclusive, registrants only" reservation on the device(s). The result is that only registered nodes may write to the device(s). When a node failure occurs, the fence_mpath agent will remove the key belonging to the failed node from the device(s). The failed node will no longer be able to write to the device(s). A manual reboot is required.
c2359a
+
c2359a
+When used as a watchdog device you can define e.g. retry=1, retry-sleep=2 and verbose=yes parameters in /etc/sysconfig/stonith if you have issues with it failing.</longdesc>
c2359a
 <vendor-url>https://www.sourceware.org/dm/</vendor-url>
c2359a
 <parameters>
c2359a
 	<parameter name="action" unique="0" required="1">