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

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