Blame SOURCES/bz1552330-vdo-vol.patch

05afe3
From 8b07d095acbbb1069c1fb44142ccfdd0aeed075f Mon Sep 17 00:00:00 2001
05afe3
From: Oyvind Albrigtsen <oalbrigt@redhat.com>
05afe3
Date: Wed, 16 May 2018 14:10:49 +0200
05afe3
Subject: [PATCH] vdo-vol: new resource agent
05afe3
05afe3
---
05afe3
 doc/man/Makefile.am   |   3 +-
05afe3
 heartbeat/Makefile.am |   1 +
05afe3
 heartbeat/vdo-vol     | 234 ++++++++++++++++++++++++++++++++++++++++++
05afe3
 3 files changed, 237 insertions(+), 1 deletion(-)
05afe3
 create mode 100755 heartbeat/vdo-vol
05afe3
05afe3
diff --git a/doc/man/Makefile.am b/doc/man/Makefile.am
05afe3
index c59126d1..8d94c10c 100644
05afe3
--- a/doc/man/Makefile.am
05afe3
+++ b/doc/man/Makefile.am
05afe3
@@ -158,11 +158,12 @@ man_MANS	       = ocf_heartbeat_AoEtarget.7 \
05afe3
                           ocf_heartbeat_slapd.7 \
05afe3
                           ocf_heartbeat_sybaseASE.7 \
05afe3
                           ocf_heartbeat_sg_persist.7 \
05afe3
-			  ocf_heartbeat_mpathpersist.7 \
05afe3
+                          ocf_heartbeat_mpathpersist.7 \
05afe3
                           ocf_heartbeat_symlink.7 \
05afe3
                           ocf_heartbeat_syslog-ng.7 \
05afe3
                           ocf_heartbeat_tomcat.7 \
05afe3
                           ocf_heartbeat_varnish.7 \
05afe3
+                          ocf_heartbeat_vdo-vol.7 \
05afe3
                           ocf_heartbeat_vmware.7 \
05afe3
                           ocf_heartbeat_zabbixserver.7
05afe3
 
05afe3
diff --git a/heartbeat/Makefile.am b/heartbeat/Makefile.am
05afe3
index 4f5059e2..a68fa978 100644
05afe3
--- a/heartbeat/Makefile.am
05afe3
+++ b/heartbeat/Makefile.am
05afe3
@@ -162,6 +162,7 @@ ocf_SCRIPTS	     =  AoEtarget		\
05afe3
 			syslog-ng		\
05afe3
 			tomcat			\
05afe3
 			varnish			\
05afe3
+			vdo-vol			\
05afe3
 			vmware			\
05afe3
 			vsftpd			\
05afe3
 			zabbixserver
05afe3
diff --git a/heartbeat/vdo-vol b/heartbeat/vdo-vol
05afe3
new file mode 100755
05afe3
index 00000000..074339db
05afe3
--- /dev/null
05afe3
+++ b/heartbeat/vdo-vol
05afe3
@@ -0,0 +1,234 @@
05afe3
+#!/bin/sh
05afe3
+#
05afe3
+#  License:      GNU General Public License (GPL)
05afe3
+#  (c) 2018 O. Albrigtsen
05afe3
+#           and Linux-HA contributors
05afe3
+#
05afe3
+# -----------------------------------------------------------------------------
05afe3
+#      O C F    R E S O U R C E    S C R I P T   S P E C I F I C A T I O N
05afe3
+# -----------------------------------------------------------------------------
05afe3
+#
05afe3
+# NAME
05afe3
+#       vdo-vol : OCF resource agent script for VDO (Virtual Data Optimizer)
05afe3
+#
05afe3
+
05afe3
+# Initialization:
05afe3
+: ${OCF_FUNCTIONS_DIR=${OCF_ROOT}/lib/heartbeat}
05afe3
+. ${OCF_FUNCTIONS_DIR}/ocf-shellfuncs
05afe3
+
05afe3
+# Defaults
05afe3
+OCF_RESKEY_volume_default=""
05afe3
+
05afe3
+: ${OCF_RESKEY_volume=${OCF_RESKEY_volume_default}}
05afe3
+
05afe3
+
05afe3
+vdo_usage() {
05afe3
+  cat <
05afe3
+    usage: $0 (start|stop|validate-all|meta-data|help|usage|monitor)
05afe3
+    $0 manages VDO (Virtual Data Optimizer) volume(s) as an OCF HA resource.
05afe3
+    The 'start' operation starts the instance.
05afe3
+    The 'stop' operation stops the instance.
05afe3
+    The 'status' operation reports whether the instance is running
05afe3
+    The 'monitor' operation reports whether the instance seems to be working
05afe3
+    The 'validate-all' operation reports whether the parameters are valid
05afe3
+END
05afe3
+}
05afe3
+
05afe3
+vdo_meta_data() {
05afe3
+        cat <
05afe3
+
05afe3
+
05afe3
+<resource-agent name="vdo-vol">
05afe3
+<version>0.75</version>
05afe3
+
05afe3
+<longdesc lang="en">
05afe3
+OCF Resource script for VDO (Virtual Data Optimizer) volume(s). It manages VDO volume(s) as a HA resource.
05afe3
+
05afe3
+The configuration file needs to be synced to all nodes, and the systemd vdo service must be disabled when
05afe3
+using this agent.
05afe3
+</longdesc>
05afe3
+<shortdesc lang="en">VDO resource agent</shortdesc>
05afe3
+
05afe3
+<parameters>
05afe3
+
05afe3
+<parameter name="config">
05afe3
+    <longdesc lang="en">Configuration file</longdesc>
05afe3
+    <shortdesc lang="en">Config file</shortdesc>
05afe3
+    <content type="string" default="${OCF_RESKEY_config_default}" />
05afe3
+</parameter>
05afe3
+
05afe3
+<parameter name="volume">
05afe3
+    <longdesc lang="en">VDO Volume (leave empty for all)</longdesc>
05afe3
+    <shortdesc lang="en">Volume (empty for all)</shortdesc>
05afe3
+    <content type="string" default="${OCF_RESKEY_volume_default}" />
05afe3
+</parameter>
05afe3
+
05afe3
+</parameters>
05afe3
+
05afe3
+<actions>
05afe3
+<action name="start" timeout="60s" />
05afe3
+<action name="stop" timeout="20s" />
05afe3
+<action name="status" timeout="20s" />
05afe3
+<action name="monitor" depth="0" timeout="20s" interval="10s" start-delay="10s" />
05afe3
+<action name="validate-all" timeout="20s" />
05afe3
+<action name="meta-data" timeout="20s" />
05afe3
+</actions>
05afe3
+</resource-agent>
05afe3
+END
05afe3
+}
05afe3
+
05afe3
+
05afe3
+rebuild() {
05afe3
+		ocf_log warn "${OCF_RESKEY_volume} is in $MODE mode, starting in rebuild mode"
05afe3
+
05afe3
+		vdo stop $OPTIONS
05afe3
+
05afe3
+		while vdo_monitor skiprocheck; do
05afe3
+			sleep 1
05afe3
+		done
05afe3
+
05afe3
+		vdo start $OPTIONS --forceRebuild
05afe3
+
05afe3
+		while ! vdo_monitor; do
05afe3
+			sleep 1
05afe3
+		done
05afe3
+
05afe3
+		return $?
05afe3
+}
05afe3
+
05afe3
+vdo_start() {
05afe3
+	# if resource is already running,no need to continue code after this.
05afe3
+	if vdo_monitor; then
05afe3
+		ocf_log info "VDO volume(s): ${OCF_RESKEY_volume} is already active"
05afe3
+		return $OCF_SUCCESS
05afe3
+	fi
05afe3
+
05afe3
+	vdo activate $OPTIONS
05afe3
+	vdo start $OPTIONS
05afe3
+
05afe3
+	while ! vdo_monitor skiprocheck; do
05afe3
+		sleep 1
05afe3
+	done
05afe3
+
05afe3
+	MODE=$(vdostats --verbose ${OCF_RESKEY_volume} | grep "operating mode" | awk '{print $NF}')
05afe3
+	if [ $(echo "$MODE" | grep -v "normal" | wc -l) -gt 0 ]; then
05afe3
+		rebuild
05afe3
+	fi
05afe3
+
05afe3
+	if [ $? -eq $OCF_SUCCESS ]; then
05afe3
+		ocf_log info "VDO volume(s): ${OCF_RESKEY_volume} activated"
05afe3
+		return ${OCF_SUCCESS}
05afe3
+	fi
05afe3
+
05afe3
+	return $?
05afe3
+}
05afe3
+
05afe3
+vdo_stop() {
05afe3
+	vdo_monitor skiprocheck
05afe3
+	if [ $? -ne $OCF_SUCCESS ]; then
05afe3
+		# Currently not running. Nothing to do.
05afe3
+		ocf_log info "VDO volume(s): ${OCF_RESKEY_volume} already deactivated"
05afe3
+
05afe3
+		return $OCF_SUCCESS
05afe3
+	fi
05afe3
+
05afe3
+	vdo stop $OPTIONS
05afe3
+	vdo deactivate $OPTIONS
05afe3
+
05afe3
+	# Wait for process to stop
05afe3
+	while vdo_monitor skiprocheck; do
05afe3
+		sleep 1
05afe3
+	done
05afe3
+
05afe3
+	return $OCF_SUCCESS
05afe3
+}
05afe3
+
05afe3
+vdo_monitor(){
05afe3
+	status=$(vdo status $OPTIONS 2>&1)
05afe3
+	MODE=$(vdostats vdo_vol --verbose | grep "operating mode" | awk '{print $NF}')
05afe3
+
05afe3
+	case "$status" in
05afe3
+		*"Device mapper status: not available"*)
05afe3
+			return $OCF_NOT_RUNNING
05afe3
+			;;
05afe3
+		*"Device mapper status: "*online*)
05afe3
+			if [ "$MODE" = "read-only" ] && [ "$1" != "skiprocheck" ]; then
05afe3
+				ocf_log err "VDO volume(s): ${OCF_RESKEY_volume} is in $MODE mode."
05afe3
+				return $OCF_ERR_GENERIC
05afe3
+			else
05afe3
+				return $OCF_SUCCESS
05afe3
+			fi
05afe3
+			;;
05afe3
+		*)
05afe3
+			ocf_log err "VDO volume(s): ${OCF_RESKEY_volume} failed\n$status"
05afe3
+			return $OCF_ERR_GENERIC;;
05afe3
+	esac
05afe3
+}
05afe3
+
05afe3
+vdo_validate_all(){
05afe3
+	check_binary "vdo"
05afe3
+
05afe3
+	if systemctl is-enabled vdo > /dev/null 2>&1; then
05afe3
+		ocf_exit_reason "systemd service vdo needs to be disabled"
05afe3
+		exit $OCF_ERR_CONFIGURED
05afe3
+	fi
05afe3
+
05afe3
+	if [ -n "${OCF_RESKEY_config}" ] && [ ! -f "${OCF_RESKEY_config}" ]; then
05afe3
+		ocf_exit_reason "Configuration file: ${OCF_RESKEY_config} not found"
05afe3
+		exit $OCF_ERR_CONFIGURED
05afe3
+	fi
05afe3
+
05afe3
+	return $OCF_SUCCESS
05afe3
+}
05afe3
+
05afe3
+
05afe3
+# **************************** MAIN SCRIPT ************************************
05afe3
+
05afe3
+# Make sure meta-data and usage always succeed
05afe3
+case $__OCF_ACTION in
05afe3
+	meta-data)
05afe3
+		vdo_meta_data
05afe3
+		exit $OCF_SUCCESS
05afe3
+		;;
05afe3
+	usage|help)
05afe3
+		vdo_usage
05afe3
+		exit $OCF_SUCCESS
05afe3
+		;;
05afe3
+esac
05afe3
+
05afe3
+# This OCF agent script need to be run as root user.
05afe3
+if ! ocf_is_root; then
05afe3
+        echo  "$0 agent script need to be run as root user."
05afe3
+        ocf_log debug "$0 agent script need to be run as root user."
05afe3
+        exit $OCF_ERR_GENERIC
05afe3
+fi
05afe3
+
05afe3
+if [ -z "${OCF_RESKEY_volume}" ]; then
05afe3
+	OPTIONS="-a"
05afe3
+else
05afe3
+	OPTIONS="-n ${OCF_RESKEY_volume}"
05afe3
+fi
05afe3
+
05afe3
+if [ -n "${OCF_RESKEY_config}" ]; then
05afe3
+	OPTIONS="$OPTIONS -f ${OCF_RESKEY_config}"
05afe3
+fi
05afe3
+
05afe3
+# Translate each action into the appropriate function call
05afe3
+case $__OCF_ACTION in
05afe3
+	start)
05afe3
+		vdo_validate_all
05afe3
+		vdo_start;;
05afe3
+	stop)
05afe3
+		vdo_stop;;
05afe3
+	status|monitor)
05afe3
+		vdo_monitor;;
05afe3
+	validate-all)
05afe3
+		;;
05afe3
+	*)
05afe3
+		vdo_usage
05afe3
+                exit $OCF_ERR_UNIMPLEMENTED;;
05afe3
+esac
05afe3
+
05afe3
+exit $?
05afe3
+
05afe3
+# End of this script
05afe3
-- 
05afe3
2.17.1
05afe3