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

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