Blame SOURCES/fence_mpath-watchdog-support.patch

658b6c
From 199b1efee0ba1f01c27ca689a15465cf4a258ee6 Mon Sep 17 00:00:00 2001
658b6c
From: Oyvind Albrigtsen <oalbrigt@redhat.com>
658b6c
Date: Mon, 22 Jan 2018 11:27:28 +0100
658b6c
Subject: [PATCH] fence_mpath: add watchdog support
658b6c
658b6c
---
658b6c
 agents/Makefile.am                  | 11 ++++++++
658b6c
 agents/mpath/fence_mpath.py         | 50 ++++++++++++++++++++++++++++++++++---
658b6c
 configure.ac                        |  6 +++++
658b6c
 make/fencebuild.mk                  |  2 +-
658b6c
 tests/data/metadata/fence_mpath.xml |  2 +-
658b6c
 5 files changed, 66 insertions(+), 5 deletions(-)
658b6c
658b6c
diff --git a/agents/Makefile.am b/agents/Makefile.am
658b6c
index 2524a3ab..833d2af5 100644
658b6c
--- a/agents/Makefile.am
658b6c
+++ b/agents/Makefile.am
658b6c
@@ -50,6 +50,11 @@ zvm_fence_zvm_SOURCES		= zvm/fence_zvm.c
658b6c
 zvm_fence_zvm_CFLAGS		= -D_GNU_SOURCE -Izvm
658b6c
 endif
658b6c
 
658b6c
+if BUILD_FENCE_MPATH
658b6c
+mpathdatadir			= $(CLUSTERDATA)
658b6c
+mpathdata_SCRIPTS		= mpath/fence_mpath_check mpath/fence_mpath_check_hardreboot
658b6c
+endif
658b6c
+
658b6c
 if BUILD_FENCE_SCSI
658b6c
 scsidatadir			= $(CLUSTERDATA)
658b6c
 scsidata_SCRIPTS		= scsi/fence_scsi_check scsi/fence_scsi_check_hardreboot
658b6c
@@ -72,6 +77,12 @@ manual/fence_ack_manual: manual/fence_ack_manual.in
658b6c
 		-e 's#@clustervarrun@#${CLUSTERVARRUN}#g' \
658b6c
 	> $@
658b6c
 
658b6c
+mpath/fence_mpath_check: mpath/fence_mpath
658b6c
+	cp $^ $@
658b6c
+
658b6c
+mpath/fence_mpath_check_hardreboot: mpath/fence_mpath
658b6c
+	cp $^ $@
658b6c
+
658b6c
 scsi/fence_scsi_check: scsi/fence_scsi
658b6c
 	cp $^ $@
658b6c
 
658b6c
diff --git a/agents/mpath/fence_mpath.py b/agents/mpath/fence_mpath.py
658b6c
index ac5bc794..d9ac2ef5 100644
658b6c
--- a/agents/mpath/fence_mpath.py
658b6c
+++ b/agents/mpath/fence_mpath.py
658b6c
@@ -143,25 +143,63 @@ def dev_write(options, dev):
658b6c
 		store_fh.write(dev + "\t" + options["--key"] + "\n")
658b6c
 	store_fh.close()
658b6c
 
658b6c
-def dev_read(options):
658b6c
+def dev_read(options, fail=True):
658b6c
 	dev_key = {}
658b6c
 	file_path = options["--store-path"] + "/mpath.devices"
658b6c
 	try:
658b6c
 		store_fh = open(file_path, "r")
658b6c
 	except IOError:
658b6c
-		fail_usage("Failed: Cannot open file \"" + file_path + "\"")
658b6c
+		if fail:
658b6c
+			fail_usage("Failed: Cannot open file \"" + file_path + "\"")
658b6c
+		else:
658b6c
+			return None
658b6c
 	# get not empty lines from file
658b6c
 	for (device, key) in [line.strip().split() for line in store_fh if line.strip()]:
658b6c
 		dev_key[device] = key
658b6c
 	store_fh.close()
658b6c
 	return dev_key
658b6c
 
658b6c
+def mpath_check_get_verbose():
658b6c
+	try:
658b6c
+		f = open("/etc/sysconfig/watchdog", "r")
658b6c
+	except IOError:
658b6c
+		return False
658b6c
+	match = re.search(r"^\s*verbose=yes", "".join(f.readlines()), re.MULTILINE)
658b6c
+	f.close()
658b6c
+	return bool(match)
658b6c
+
658b6c
+def mpath_check(hardreboot=False):
658b6c
+	if len(sys.argv) >= 3 and sys.argv[1] == "repair":
658b6c
+		return int(sys.argv[2])
658b6c
+	options = {}
658b6c
+	options["--mpathpersist-path"] = "/usr/sbin/mpathpersist"
658b6c
+	options["--store-path"] = "/var/run/cluster"
658b6c
+	options["--power-timeout"] = "5"
658b6c
+	if mpath_check_get_verbose():
658b6c
+		logging.getLogger().setLevel(logging.DEBUG)
658b6c
+	devs = dev_read(options, fail=False)
658b6c
+	if not devs:
658b6c
+		logging.error("No devices found")
658b6c
+		return 0
658b6c
+	for dev, key in list(devs.items()):
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
+	logging.debug("key " + key + " registered with any devices")
658b6c
+
658b6c
+	if hardreboot == True:
658b6c
+		libc = ctypes.cdll['libc.so.6']
658b6c
+		libc.reboot(0x1234567)
658b6c
+	return 2
658b6c
+
658b6c
 def define_new_opts():
658b6c
 	all_opt["devices"] = {
658b6c
 		"getopt" : "d:",
658b6c
 		"longopt" : "devices",
658b6c
 		"help" : "-d, --devices=[devices]        List of devices to use for current operation",
658b6c
-		"required" : "1",
658b6c
+		"required" : "0",
658b6c
 		"shortdesc" : "List of devices to use for current operation. Devices can \
658b6c
 be comma-separated list of device-mapper multipath devices (eg. /dev/mapper/3600508b400105df70000e00000ac0000 or /dev/mapper/mpath1). \
658b6c
 Each device must support SCSI-3 persistent reservations.",
658b6c
@@ -205,6 +243,12 @@ def main():
658b6c
 
658b6c
 	define_new_opts()
658b6c
 
658b6c
+	# fence_mpath_check
658b6c
+	if os.path.basename(sys.argv[0]) == "fence_mpath_check":
658b6c
+		sys.exit(mpath_check())
658b6c
+	elif os.path.basename(sys.argv[0]) == "fence_mpath_check_hardreboot":
658b6c
+		sys.exit(mpath_check(hardreboot=True))
658b6c
+
658b6c
 	options = check_input(device_opt, process_input(device_opt), other_conditions=True)
658b6c
 
658b6c
 	docs = {}
658b6c
diff --git a/configure.ac b/configure.ac
658b6c
index e8b24211..24b857b3 100644
658b6c
--- a/configure.ac
658b6c
+++ b/configure.ac
658b6c
@@ -148,6 +148,11 @@ if echo "$AGENTS_LIST" | grep -q -E "all|manual"; then
658b6c
 	AGENTS_LIST=$(echo "$AGENTS_LIST" | sed -E "s/manual( |$)//")
658b6c
 fi
658b6c
 
658b6c
+FENCE_MPATH=0
658b6c
+if echo "$AGENTS_LIST" | grep -q -E "all|mpath"; then
658b6c
+	FENCE_MPATH=1
658b6c
+fi
658b6c
+
658b6c
 FENCE_SCSI=0
658b6c
 if echo "$AGENTS_LIST" | grep -q -E "all|scsi"; then
658b6c
 	FENCE_SCSI=1
658b6c
@@ -312,6 +317,7 @@ AC_SUBST([SNMPBIN])
658b6c
 AC_SUBST([AGENTS_LIST])
658b6c
 AM_CONDITIONAL(BUILD_FENCE_KDUMP, test $FENCE_KDUMP -eq 1)
658b6c
 AM_CONDITIONAL(BUILD_FENCE_MANUAL, test $FENCE_MANUAL -eq 1)
658b6c
+AM_CONDITIONAL(BUILD_FENCE_MPATH, test $FENCE_MPATH -eq 1)
658b6c
 AM_CONDITIONAL(BUILD_FENCE_SCSI, test $FENCE_SCSI -eq 1)
658b6c
 AM_CONDITIONAL(BUILD_FENCE_ZVM, test $FENCE_ZVM -eq 1)
658b6c
 AM_CONDITIONAL(BUILD_XENAPILIB, test $XENAPILIB -eq 1)
658b6c
diff --git a/make/fencebuild.mk b/make/fencebuild.mk
658b6c
index e08d5200..6a7c6f63 100644
658b6c
--- a/make/fencebuild.mk
658b6c
+++ b/make/fencebuild.mk
658b6c
@@ -51,7 +51,7 @@ $(TARGET):
658b6c
 	$(call gen_agent_from_py)
658b6c
 
658b6c
 clean: clean-man
658b6c
-	rm -f $(CLEAN_TARGET:%.8=%) $(CLEAN_TARGET_ADDITIONAL) $(scsidata_SCRIPTS) */*.pyc *.pyc */*.wiki
658b6c
+	rm -f $(CLEAN_TARGET:%.8=%) $(CLEAN_TARGET_ADDITIONAL) $(mpathdata_SCRIPTS) $(scsidata_SCRIPTS) */*.pyc */*.wiki
658b6c
 
658b6c
 	if [ "$(abs_builddir)" = "$(abs_top_builddir)/lib" ]; then \
658b6c
 		rm -f $(TARGET); \
658b6c
diff --git a/tests/data/metadata/fence_mpath.xml b/tests/data/metadata/fence_mpath.xml
658b6c
index f384e50b..bbe9ad2b 100644
658b6c
--- a/tests/data/metadata/fence_mpath.xml
658b6c
+++ b/tests/data/metadata/fence_mpath.xml
658b6c
@@ -9,7 +9,7 @@ The fence_mpath agent works by having a unique key for each node that has to be
658b6c
 		<content type="string" default="off"  />
658b6c
 		<shortdesc lang="en">Fencing action</shortdesc>
658b6c
 	</parameter>
658b6c
-	<parameter name="devices" unique="0" required="1">
658b6c
+	<parameter name="devices" unique="0" required="0">
658b6c
 		<getopt mixed="-d, --devices=[devices]" />
658b6c
 		<content type="string"  />
658b6c
 		<shortdesc lang="en">List of devices to use for current operation. Devices can be comma-separated list of device-mapper multipath devices (eg. /dev/mapper/3600508b400105df70000e00000ac0000 or /dev/mapper/mpath1). Each device must support SCSI-3 persistent reservations.</shortdesc>