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

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