Blame SOURCES/bz1552330-vdo-vol.patch

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