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

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