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

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