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

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