Blame SOURCES/0090-RH-add-support-to-mpathconf-for-setting-arbitrary-de.patch

c14208
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
c14208
From: Benjamin Marzinski <bmarzins@redhat.com>
c14208
Date: Wed, 2 Feb 2022 17:00:21 -0600
c14208
Subject: [PATCH] RH: add support to mpathconf for setting arbitrary default
c14208
 options
c14208
c14208
mpathconf now supports --option <name>:[<value>] for setting, changing,
c14208
or removing options from the defaults section of multipath.conf.
c14208
c14208
Signed-off-by: Benjamin Marzinski <bmarzins@redhat.com>
c14208
---
c14208
 multipath/mpathconf   | 58 ++++++++++++++++++++++++++++++++++++++++---
c14208
 multipath/mpathconf.8 |  7 ++++++
c14208
 2 files changed, 62 insertions(+), 3 deletions(-)
c14208
c14208
diff --git a/multipath/mpathconf b/multipath/mpathconf
c14208
index 5f2285ab..870512c0 100644
c14208
--- a/multipath/mpathconf
c14208
+++ b/multipath/mpathconf
c14208
@@ -17,7 +17,7 @@
c14208
 # This program was largely ripped off from lvmconf
c14208
 #
c14208
 
c14208
-unset ENABLE FIND FRIENDLY PROPERTY FOREIGN MODULE MULTIPATHD HAVE_DISABLE HAVE_WWID_DISABLE HAVE_FIND HAVE_BLACKLIST HAVE_EXCEPTIONS HAVE_DEFAULTS HAVE_FRIENDLY HAVE_PROPERTY HAVE_FOREIGN HAVE_MULTIPATHD HAVE_MODULE HAVE_OUTFILE SHOW_STATUS CHANGED_CONFIG WWID_LIST
c14208
+unset ENABLE FIND FRIENDLY PROPERTY FOREIGN MODULE MULTIPATHD HAVE_DISABLE HAVE_WWID_DISABLE HAVE_FIND HAVE_BLACKLIST HAVE_EXCEPTIONS HAVE_DEFAULTS HAVE_FRIENDLY HAVE_PROPERTY HAVE_FOREIGN HAVE_MULTIPATHD HAVE_MODULE HAVE_OUTFILE SHOW_STATUS CHANGED_CONFIG WWID_LIST HAVE_OPTION OPTION_NAME OPTION_VALUE
c14208
 
c14208
 DEFAULT_CONFIG="# device-mapper-multipath configuration file
c14208
 
c14208
@@ -57,6 +57,7 @@ function usage
c14208
 	echo "Set find_multipaths (Default y): --find_multipaths <yes|no|strict|greedy|smart>"
c14208
 	echo "Set default property blacklist (Default y): --property_blacklist <y|n>"
c14208
 	echo "Set enable_foreign to show foreign devices (Default n): --enable_foreign <y|n>"
c14208
+	echo "Add/Change/Remove option in defaults section: --option <option_name>:<value>"
c14208
 	echo "Load the dm-multipath modules on enable (Default y): --with_module <y|n>"
c14208
 	echo "start/stop/reload multipathd (Default n): --with_multipathd <y|n>"
c14208
 	echo "select output file (Default /etc/multipath.conf): --outfile <FILE>"
c14208
@@ -167,6 +168,20 @@ function parse_args
c14208
 					exit 1
c14208
 				fi
c14208
 				;;
c14208
+			--option)
c14208
+				if [ -n "$2" ]; then
c14208
+					OPTION_NAME=$(echo $2 | cut -s -f1 -d:)
c14208
+					OPTION_VALUE=$(echo $2 | cut -s -f2 -d:)
c14208
+					if [ -z "$OPTION_NAME" ]; then
c14208
+						usage
c14208
+						exit 1
c14208
+					fi
c14208
+					shift 2
c14208
+				else
c14208
+					usage
c14208
+					exit 1
c14208
+				fi
c14208
+				;;
c14208
 			--enable_foreign)
c14208
 				if [ -n "$2" ]; then
c14208
 					FOREIGN=$2
c14208
@@ -213,12 +228,15 @@ function parse_args
c14208
 
c14208
 function validate_args
c14208
 {
c14208
-	if [ "$ENABLE" = "0" ] && [ -n "$FRIENDLY" -o -n "$FIND" -o -n "$PROPERTY" -o -n "$MODULE" ]; then
c14208
+	if [ "$ENABLE" = "0" ] && [ -n "$FRIENDLY" -o -n "$FIND" -o -n "$PROPERTY" -o -n "$MODULE" -o -n "$FOREIGN" -o -n "$OPTION_NAME" ]; then
c14208
 		echo "ignoring extra parameters on disable"
c14208
 		FRIENDLY=""
c14208
 		FIND=""
c14208
 		PROPERTY=""
c14208
 		MODULE=""
c14208
+		FOREIGN=""
c14208
+		OPTION_NAME=""
c14208
+		OPTION_VALUE=""
c14208
 	fi
c14208
 	if [ -n "$FRIENDLY" ] && [ "$FRIENDLY" != "y" -a "$FRIENDLY" != "n" ]; then
c14208
 		echo "--user_friendly_names must be either 'y' or 'n'"
c14208
@@ -240,7 +258,19 @@ function validate_args
c14208
 		echo "--enable_foreign must be either 'y' or 'n'"
c14208
 		exit 1
c14208
 	fi
c14208
-	if [ -z "$ENABLE" -a -z "$FIND" -a -z "$FRIENDLY" -a -z "$PROPERTY" -a -z "$FOREIGN" ]; then
c14208
+	if [ -n "$OPTION_NAME" ]; then
c14208
+		if [[ $OPTION_NAME =~ [[:space:]]|#|\"|!|\{|\} ]]; then
c14208
+			echo "--option name \"$OPTION_NAME\" is invalid"
c14208
+			exit 1
c14208
+		elif [[ $OPTION_VALUE =~ \"|#|!|\{|\} ]]; then
c14208
+			echo "--option value \"$OPTION_VALUE\" is invalid"
c14208
+			exit 1
c14208
+		fi
c14208
+		if [[ $OPTION_VALUE =~ [[:space:]] ]]; then
c14208
+			OPTION_VALUE=\"$OPTION_VALUE\"
c14208
+		fi
c14208
+	fi
c14208
+	if [ -z "$ENABLE" -a -z "$FIND" -a -z "$FRIENDLY" -a -z "$PROPERTY" -a -z "$FOREIGN" -a -z "$OPTION_NAME" ]; then
c14208
 		SHOW_STATUS=1
c14208
 	fi
c14208
 	if [ -n "$MODULE" ] && [ "$MODULE" != "y" -a "$MODULE" != "n" ]; then
c14208
@@ -349,6 +379,13 @@ if [ "$HAVE_DEFAULTS" = "1" ]; then
c14208
 	elif sed -n '/^defaults[[:space:]]*{/,/^}/ p' $TMPFILE | grep -q "^[[:space:]]*enable_foreign" ; then
c14208
 		HAVE_FOREIGN=2
c14208
 	fi
c14208
+	if [ -n "$OPTION_NAME" ]; then
c14208
+		if sed -n '/^defaults[[:space:]]*{/,/^}/ p' $TMPFILE | grep -q '^[[:space:]]*'"$OPTION_NAME"'[[:space:]][[:space:]]*'"$OPTION_VALUE" ; then
c14208
+			HAVE_OPTION=1
c14208
+		elif sed -n '/^defaults[[:space:]]*{/,/^}/ p' $TMPFILE | grep -q '^[[:space:]]*'"$OPTION_NAME"'\([[:space:]].*\)\?$' ; then
c14208
+			HAVE_OPTION=0
c14208
+		fi
c14208
+	fi
c14208
 fi
c14208
 
c14208
 if [ "$HAVE_EXCEPTIONS" = "1" ]; then
c14208
@@ -523,6 +560,21 @@ elif [ "$FOREIGN" = "n" ]; then
c14208
 	fi
c14208
 fi
c14208
 
c14208
+if [ -n "$OPTION_NAME" -a -n "$OPTION_VALUE" ]; then
c14208
+	if [ -z "$HAVE_OPTION" ]; then
c14208
+		sed -i '/^defaults[[:space:]]*{/ a\
c14208
+	'"$OPTION_NAME"' '"$OPTION_VALUE"'
c14208
+' $TMPFILE
c14208
+		CHANGED_CONFIG=1
c14208
+	elif [ "$HAVE_OPTION" = 0 ]; then
c14208
+		sed -i '/^defaults[[:space:]]*{/,/^}/ s/^[[:space:]]*'"$OPTION_NAME"'\([[:space:]].*\)\?$/	'"$OPTION_NAME"' '"$OPTION_VALUE"'/' $TMPFILE
c14208
+		CHANGED_CONFIG=1
c14208
+	fi
c14208
+elif [ -n "$OPTION_NAME" -a -n "$HAVE_OPTION" ]; then
c14208
+	sed -i '/^defaults[[:space:]]*{/,/^}/{/^[[:space:]]*'"$OPTION_NAME"'\([[:space:]].*\)\?$/d}' $TMPFILE
c14208
+	CHANGED_CONFIG=1
c14208
+fi
c14208
+
c14208
 if [ -f "$OUTPUTFILE" ]; then
c14208
 	cp $OUTPUTFILE $OUTPUTFILE.old
c14208
 	if [ $? != 0 ]; then
c14208
diff --git a/multipath/mpathconf.8 b/multipath/mpathconf.8
c14208
index 83515eb4..63fe633e 100644
c14208
--- a/multipath/mpathconf.8
c14208
+++ b/multipath/mpathconf.8
c14208
@@ -101,6 +101,13 @@ to the
c14208
 defaults section. if set to \fBy\fP, this removes the line, if present. This
c14208
 command can be used along with any other command.
c14208
 .TP
c14208
+.B --option \fB<option_name>:[<value>]\fP
c14208
+Sets the defaults section option \fB<option_name>\fP to \fB<value>\fP. If the
c14208
+option was not previously set in the defaults section, it is added. If it was
c14208
+set, its value is changed to \fB<value>\fP. If \fB<value>\fP is left blank,
c14208
+then the option is removed from the defaults section, if was set there. This
c14208
+command can be used along with any other command.
c14208
+.TP
c14208
 .B --outfile \fB<filename>\fP
c14208
 Write the resulting multipath configuration to \fB<filename>\fP instead of
c14208
 \fB/etc/multipath.conf\fP.