Blame SOURCES/fence_mpath-watchdog-support.patch

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