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

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