Blame SOURCES/bz1654172-1-fence_scsi-watchdog-retry-support.patch

7f4c66
From 11a63822fbdc0a9ebe1b668b26a59f1cc9649f6c Mon Sep 17 00:00:00 2001
7f4c66
From: Oyvind Albrigtsen <oalbrigt@redhat.com>
7f4c66
Date: Wed, 24 Oct 2018 14:51:27 +0200
7f4c66
Subject: [PATCH] fence_scsi: watchdog retries support
7f4c66
7f4c66
---
7f4c66
 agents/scsi/fence_scsi.py          | 60 ++++++++++++++++++++----------
7f4c66
 tests/data/metadata/fence_scsi.xml |  4 +-
7f4c66
 2 files changed, 43 insertions(+), 21 deletions(-)
7f4c66
7f4c66
diff --git a/agents/scsi/fence_scsi.py b/agents/scsi/fence_scsi.py
7f4c66
index 79ada4fa..8a1e4c77 100644
7f4c66
--- a/agents/scsi/fence_scsi.py
7f4c66
+++ b/agents/scsi/fence_scsi.py
7f4c66
@@ -158,13 +158,15 @@ def get_reservation_key(options, dev):
7f4c66
 	return match.group(1) if match else None
7f4c66
 
7f4c66
 
7f4c66
-def get_registration_keys(options, dev):
7f4c66
+def get_registration_keys(options, dev, fail=True):
7f4c66
 	reset_dev(options,dev)
7f4c66
 	keys = []
7f4c66
 	cmd = options["--sg_persist-path"] + " -n -i -k -d " + dev
7f4c66
 	out = run_cmd(options, cmd)
7f4c66
 	if out["err"]:
7f4c66
-		fail_usage("Cannot get registration keys")
7f4c66
+		fail_usage("Cannot get registration keys", fail)
7f4c66
+		if not fail:
7f4c66
+			return []
7f4c66
 	for line in out["out"].split("\n"):
7f4c66
 		match = re.search(r"\s+0x(\S+)\s*", line)
7f4c66
 		if match:
7f4c66
@@ -218,9 +220,8 @@ def get_key(fail=True):
7f4c66
 	try:
7f4c66
 		f = open(file_path, "r")
7f4c66
 	except IOError:
7f4c66
-		if fail:
7f4c66
-			fail_usage("Failed: Cannot open file \""+ file_path + "\"")
7f4c66
-		else:
7f4c66
+		fail_usage("Failed: Cannot open file \""+ file_path + "\"", fail)
7f4c66
+		if not fail:
7f4c66
 			return None
7f4c66
 	return f.readline().strip().lower()
7f4c66
 
7f4c66
@@ -244,9 +245,8 @@ def dev_read(fail=True):
7f4c66
 	try:
7f4c66
 		f = open(file_path, "r")
7f4c66
 	except IOError:
7f4c66
-		if fail:
7f4c66
-			fail_usage("Failed: Cannot open file \"" + file_path + "\"")
7f4c66
-		else:
7f4c66
+		fail_usage("Failed: Cannot open file \"" + file_path + "\"", fail)
7f4c66
+		if not fail:
7f4c66
 			return None
7f4c66
 	# get not empty lines from file
7f4c66
 	devs = [line.strip() for line in f if line.strip()]
7f4c66
@@ -371,14 +371,20 @@ def define_new_opts():
7f4c66
 	}
7f4c66
 
7f4c66
 
7f4c66
-def scsi_check_get_verbose():
7f4c66
+def scsi_check_get_options(options):
7f4c66
 	try:
7f4c66
-		f = open("/etc/sysconfig/watchdog", "r")
7f4c66
+		f = open("/etc/sysconfig/stonith", "r")
7f4c66
 	except IOError:
7f4c66
-		return False
7f4c66
-	match = re.search(r"^\s*verbose=yes", "".join(f.readlines()), re.MULTILINE)
7f4c66
+		return options
7f4c66
+
7f4c66
+	match = re.findall(r"^\s*(\S*)\s*=\s*(\S*)\s*", "".join(f.readlines()), re.MULTILINE)
7f4c66
+
7f4c66
+	for m in match:
7f4c66
+		options[m[0].lower()] = m[1].lower()
7f4c66
+
7f4c66
 	f.close()
7f4c66
-	return bool(match)
7f4c66
+
7f4c66
+	return options
7f4c66
 
7f4c66
 
7f4c66
 def scsi_check(hardreboot=False):
7f4c66
@@ -388,7 +394,10 @@ def scsi_check(hardreboot=False):
7f4c66
 	options["--sg_turs-path"] = "@SG_TURS_PATH@"
7f4c66
 	options["--sg_persist-path"] = "@SG_PERSIST_PATH@"
7f4c66
 	options["--power-timeout"] = "5"
7f4c66
-	if scsi_check_get_verbose():
7f4c66
+	options["retry"] = "0"
7f4c66
+	options["retry-sleep"] = "1"
7f4c66
+	options = scsi_check_get_options(options)
7f4c66
+	if "verbose" in options and options["verbose"] == "yes":
7f4c66
 		logging.getLogger().setLevel(logging.DEBUG)
7f4c66
 	devs = dev_read(fail=False)
7f4c66
 	if not devs:
7f4c66
@@ -399,11 +408,18 @@ def scsi_check(hardreboot=False):
7f4c66
 		logging.error("Key not found")
7f4c66
 		return 0
7f4c66
 	for dev in devs:
7f4c66
-		if key in get_registration_keys(options, dev):
7f4c66
-			logging.debug("key " + key + " registered with device " + dev)
7f4c66
-			return 0
7f4c66
-		else:
7f4c66
-			logging.debug("key " + key + " not registered with device " + dev)
7f4c66
+		for n in range(int(options["retry"]) + 1):
7f4c66
+			if n > 0:
7f4c66
+				logging.debug("retry: " + str(n) + " of " + options["retry"])
7f4c66
+			if key in get_registration_keys(options, dev, fail=False):
7f4c66
+				logging.debug("key " + key + " registered with device " + dev)
7f4c66
+				return 0
7f4c66
+			else:
7f4c66
+				logging.debug("key " + key + " not registered with device " + dev)
7f4c66
+
7f4c66
+			if n < int(options["retry"]):
7f4c66
+				time.sleep(float(options["retry-sleep"]))
7f4c66
+
7f4c66
 	logging.debug("key " + key + " registered with any devices")
7f4c66
 
7f4c66
 	if hardreboot == True:
7f4c66
@@ -452,7 +468,11 @@ def main():
7f4c66
 device(s). The result is that only registered nodes may write to the \
7f4c66
 device(s). When a node failure occurs, the fence_scsi agent will remove the \
7f4c66
 key belonging to the failed node from the device(s). The failed node will no \
7f4c66
-longer be able to write to the device(s). A manual reboot is required."
7f4c66
+longer be able to write to the device(s). A manual reboot is required.\
7f4c66
+\n.P\n\
7f4c66
+When used as a watchdog device you can define e.g. retry=1, retry-sleep=2 and \
7f4c66
+verbose=yes parameters in /etc/sysconfig/stonith if you have issues with it \
7f4c66
+failing."
7f4c66
 	docs["vendorurl"] = ""
7f4c66
 	show_docs(options, docs)
7f4c66
 
7f4c66
diff --git a/tests/data/metadata/fence_scsi.xml b/tests/data/metadata/fence_scsi.xml
7f4c66
index 45a84168..b8cdabd1 100644
7f4c66
--- a/tests/data/metadata/fence_scsi.xml
7f4c66
+++ b/tests/data/metadata/fence_scsi.xml
7f4c66
@@ -1,7 +1,9 @@
7f4c66
 
7f4c66
 <resource-agent name="fence_scsi" shortdesc="Fence agent for SCSI persistent reservation" >
7f4c66
 <longdesc>fence_scsi is an I/O fencing agent that uses SCSI-3 persistent reservations to control access to shared storage devices. These devices must support SCSI-3 persistent reservations (SPC-3 or greater) as well as the "preempt-and-abort" subcommand.
7f4c66
-The fence_scsi agent works by having each node in the cluster register a unique key with the SCSI device(s). 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_scsi 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>
7f4c66
+The fence_scsi agent works by having each node in the cluster register a unique key with the SCSI device(s). 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_scsi 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.
7f4c66
+
7f4c66
+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>
7f4c66
 <vendor-url></vendor-url>
7f4c66
 <parameters>
7f4c66
 	<parameter name="action" unique="0" required="1">