Blame SOURCES/bz1905820-LVM-activate-fix-return-codes.patch

ff491c
From 640c2b57f0f3e7256d587ddd5960341cb38b1982 Mon Sep 17 00:00:00 2001
ff491c
From: Reid Wahl <nrwahl@protonmail.com>
ff491c
Date: Sun, 13 Dec 2020 14:58:34 -0800
ff491c
Subject: [PATCH] LVM-activate: Fix return codes
ff491c
ff491c
OCF_ERR_ARGS should be used when the configuration isn't valid for the
ff491c
**local** node, and so the resource should not attempt to start again
ff491c
locally until the issue is corrected.
ff491c
ff491c
OCF_ERR_CONFIGURED should be used when the configuration isn't valid on
ff491c
**any** node, and so the resource should not attempt to start again
ff491c
anywhere until the issue is corrected.
ff491c
ff491c
One remaining gray area: Should lvmlockd/lvmetad/clvmd improperly
ff491c
running (or improperly not running) be an OCF_ERR_GENERIC or
ff491c
OCF_ERR_ARGS? The fact that it's a state issue rather than a config
ff491c
issue suggests OCF_ERR_GENERIC. The fact that it won't be fixed without
ff491c
user intervention suggests OCF_ERR_ARGS. The approach here is to use
ff491c
GENERIC for all of these. One can make the case that "improperly
ff491c
running" should use ARGS, since a process must be manually stopped to
ff491c
fix the issue, and that "improperly not running" should use GENERIC,
ff491c
since there's a small chance the process died and will be recovered in
ff491c
some way.
ff491c
ff491c
More info about return code meanings:
ff491c
  - https://clusterlabs.org/pacemaker/doc/2.1/Pacemaker_Administration/html/agents.html#how-are-ocf-return-codes-interpreted
ff491c
ff491c
Resolves: RHBZ#1905820
ff491c
ff491c
Signed-off-by: Reid Wahl <nrwahl@protonmail.com>
ff491c
---
ff491c
 heartbeat/LVM-activate | 47 +++++++++++++++++++++---------------------
ff491c
 1 file changed, 23 insertions(+), 24 deletions(-)
ff491c
ff491c
diff --git a/heartbeat/LVM-activate b/heartbeat/LVM-activate
ff491c
index c86606637..e951a08e9 100755
ff491c
--- a/heartbeat/LVM-activate
ff491c
+++ b/heartbeat/LVM-activate
ff491c
@@ -333,8 +333,7 @@ config_verify()
ff491c
 	real=$(lvmconfig "$name" | cut -d'=' -f2)
ff491c
 	if [ "$real" != "$expect" ]; then
ff491c
 		ocf_exit_reason "config item $name: expect=$expect but real=$real"
ff491c
-		exit $OCF_ERR_CONFIGURED
ff491c
-
ff491c
+		exit $OCF_ERR_ARGS
ff491c
 	fi
ff491c
 
ff491c
 	return $OCF_SUCCESS
ff491c
@@ -366,12 +365,12 @@ lvmlockd_check()
ff491c
 		fi
ff491c
 
ff491c
 		ocf_exit_reason "lvmlockd daemon is not running!"
ff491c
-		exit $OCF_ERR_CONFIGURED
ff491c
+		exit $OCF_ERR_GENERIC
ff491c
 	fi
ff491c
 
ff491c
 	if pgrep clvmd >/dev/null 2>&1 ; then
ff491c
 		ocf_exit_reason "clvmd daemon is running unexpectedly."
ff491c
-		exit $OCF_ERR_CONFIGURED
ff491c
+		exit $OCF_ERR_GENERIC
ff491c
 	fi
ff491c
 
ff491c
 	return $OCF_SUCCESS
ff491c
@@ -402,17 +401,17 @@ clvmd_check()
ff491c
 	# Good: clvmd is running, and lvmlockd is not running
ff491c
 	if ! pgrep clvmd >/dev/null 2>&1 ; then
ff491c
 		ocf_exit_reason "clvmd daemon is not running!"
ff491c
-		exit $OCF_ERR_CONFIGURED
ff491c
+		exit $OCF_ERR_GENERIC
ff491c
 	fi
ff491c
 
ff491c
 	if pgrep lvmetad >/dev/null 2>&1 ; then
ff491c
 		ocf_exit_reason "Please stop lvmetad daemon when clvmd is running."
ff491c
-		exit $OCF_ERR_CONFIGURED
ff491c
+		exit $OCF_ERR_GENERIC
ff491c
 	fi
ff491c
 
ff491c
 	if pgrep lvmlockd >/dev/null 2>&1 ; then
ff491c
 		ocf_exit_reason "lvmlockd daemon is running unexpectedly."
ff491c
-		exit $OCF_ERR_CONFIGURED
ff491c
+		exit $OCF_ERR_GENERIC
ff491c
 	fi
ff491c
 
ff491c
 	return $OCF_SUCCESS
ff491c
@@ -424,12 +423,12 @@ systemid_check()
ff491c
 	source=$(lvmconfig 'global/system_id_source' 2>/dev/null | cut -d"=" -f2)
ff491c
 	if [ "$source" = "" ] || [ "$source" = "none" ]; then
ff491c
 		ocf_exit_reason "system_id_source in lvm.conf is not set correctly!"
ff491c
-		exit $OCF_ERR_CONFIGURED
ff491c
+		exit $OCF_ERR_ARGS
ff491c
 	fi
ff491c
 
ff491c
 	if [ -z ${SYSTEM_ID} ]; then
ff491c
 		ocf_exit_reason "local/system_id is not set!"
ff491c
-		exit $OCF_ERR_CONFIGURED
ff491c
+		exit $OCF_ERR_ARGS
ff491c
 	fi
ff491c
 
ff491c
 	return $OCF_SUCCESS
ff491c
@@ -441,18 +440,18 @@ tagging_check()
ff491c
 	# The volume_list must be initialized to something in order to
ff491c
 	# guarantee our tag will be filtered on startup
ff491c
 	if ! lvm dumpconfig activation/volume_list; then
ff491c
-		ocf_log err  "LVM: Improper setup detected"
ff491c
+		ocf_log err "LVM: Improper setup detected"
ff491c
 		ocf_exit_reason "The volume_list filter must be initialized in lvm.conf for exclusive activation without clvmd"
ff491c
-		exit $OCF_ERR_CONFIGURED
ff491c
+		exit $OCF_ERR_ARGS
ff491c
 	fi
ff491c
 
ff491c
 	# Our tag must _NOT_ be in the volume_list.  This agent
ff491c
 	# overrides the volume_list during activation using the
ff491c
 	# special tag reserved for cluster activation
ff491c
 	if lvm dumpconfig activation/volume_list | grep -e "\"@${OUR_TAG}\"" -e "\"${VG}\"";  then
ff491c
-		ocf_log err "LVM:  Improper setup detected"
ff491c
+		ocf_log err "LVM: Improper setup detected"
ff491c
 		ocf_exit_reason "The volume_list in lvm.conf must not contain the cluster tag, \"${OUR_TAG}\", or volume group, ${VG}"
ff491c
-		exit $OCF_ERR_CONFIGURED
ff491c
+		exit $OCF_ERR_ARGS
ff491c
 	fi
ff491c
 
ff491c
 	return $OCF_SUCCESS
ff491c
@@ -463,13 +462,13 @@ read_parameters()
ff491c
 	if [ -z "$VG" ]
ff491c
 	then
ff491c
 		ocf_exit_reason "You must identify the volume group name!"
ff491c
-		exit $OCF_ERR_ARGS
ff491c
+		exit $OCF_ERR_CONFIGURED
ff491c
 	fi
ff491c
 
ff491c
 	if [ "$LV_activation_mode" != "shared" ] && [ "$LV_activation_mode" != "exclusive" ]
ff491c
 	then
ff491c
 		ocf_exit_reason "Invalid value for activation_mode: $LV_activation_mode"
ff491c
-		exit $OCF_ERR_ARGS
ff491c
+		exit $OCF_ERR_CONFIGURED
ff491c
 	fi
ff491c
 
ff491c
 	# Convert VG_access_mode from string to index
ff491c
@@ -519,8 +518,10 @@ lvm_validate() {
ff491c
 			exit $OCF_NOT_RUNNING
ff491c
 		fi
ff491c
 
ff491c
+		# Could be a transient error (e.g., iSCSI connection
ff491c
+		# issue) so use OCF_ERR_GENERIC
ff491c
 		ocf_exit_reason "Volume group[${VG}] doesn't exist, or not visible on this node!"
ff491c
-		exit $OCF_ERR_CONFIGURED
ff491c
+		exit $OCF_ERR_GENERIC
ff491c
 	fi
ff491c
 
ff491c
 	# Inconsistency might be due to missing physical volumes, which doesn't
ff491c
@@ -549,7 +550,7 @@ lvm_validate() {
ff491c
 	mode=$?
ff491c
 	if [ $VG_access_mode_num -ne 4 ] && [ $mode -ne $VG_access_mode_num ]; then
ff491c
 		ocf_exit_reason "The specified vg_access_mode doesn't match the lock_type on VG metadata!"
ff491c
-		exit $OCF_ERR_ARGS
ff491c
+		exit $OCF_ERR_CONFIGURED
ff491c
 	fi
ff491c
 
ff491c
 	# Nothing to do if the VG has no logical volume
ff491c
@@ -561,11 +562,11 @@ lvm_validate() {
ff491c
 
ff491c
 	# Check if the given $LV is in the $VG
ff491c
 	if [ -n "$LV" ]; then
ff491c
-		OUT=$(lvs --foreign --noheadings ${VG}/${LV} 2>&1)
ff491c
+		output=$(lvs --foreign --noheadings ${VG}/${LV} 2>&1)
ff491c
 		if [ $? -ne 0 ]; then
ff491c
-			ocf_log err "lvs: ${OUT}"
ff491c
+			ocf_log err "lvs: ${output}"
ff491c
 			ocf_exit_reason "LV ($LV) is not in the given VG ($VG)."
ff491c
-			exit $OCF_ERR_ARGS
ff491c
+			exit $OCF_ERR_CONFIGURED
ff491c
 		fi
ff491c
 	fi
ff491c
 
ff491c
@@ -580,7 +581,6 @@ lvm_validate() {
ff491c
 	3)
ff491c
 		systemid_check
ff491c
 		;;
ff491c
-
ff491c
 	4)
ff491c
 		tagging_check
ff491c
 		;;
ff491c
@@ -808,10 +808,9 @@ lvm_status() {
ff491c
 			dd if=${dm_name} of=/dev/null bs=1 count=1 >/dev/null \
ff491c
 				2>&1
ff491c
 			if [ $? -ne 0 ]; then
ff491c
-				return $OCF_NOT_RUNNING
ff491c
-			else
ff491c
-				return $OCF_SUCCESS
ff491c
+				return $OCF_ERR_GENERIC
ff491c
 			fi
ff491c
+			return $OCF_SUCCESS
ff491c
 			;;
ff491c
 		*)
ff491c
 			ocf_exit_reason "unsupported monitor level $OCF_CHECK_LEVEL"