Blame SOURCES/bz1538689-vdo-vol.patch

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