summaryrefslogtreecommitdiffstats
path: root/0128-RHBZ-1222123-mpathconf-allow.patch
blob: ad9873791798668fe5c9d63af3d246681f794df8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
---
 multipath/mpathconf |  135 +++++++++++++++++++++++++++++++++++++++++++++++-----
 1 file changed, 124 insertions(+), 11 deletions(-)

Index: multipath-tools-130222/multipath/mpathconf
===================================================================
--- multipath-tools-130222.orig/multipath/mpathconf
+++ multipath-tools-130222/multipath/mpathconf
@@ -1,4 +1,4 @@
-#!/bin/sh
+#!/bin/bash
 #
 # Copyright (C) 2010 Red Hat, Inc. All rights reserved.
 #
@@ -17,7 +17,7 @@
 # This program was largely ripped off from lvmconf
 #
 
-unset ENABLE FIND FRIENDLY MODULE MULTIPATHD HAVE_DISABLE HAVE_FIND HAVE_BLACKLIST HAVE_DEFAULTS HAVE_FRIENDLY HAVE_MULTIPATHD HAVE_MODULE SHOW_STATUS CHANGED_CONFIG
+unset ENABLE FIND FRIENDLY MODULE MULTIPATHD HAVE_DISABLE HAVE_WWID_DISABLE HAVE_FIND HAVE_BLACKLIST HAVE_EXCEPTIONS HAVE_DEFAULTS HAVE_FRIENDLY HAVE_MULTIPATHD HAVE_MODULE HAVE_OUTFILE SHOW_STATUS CHANGED_CONFIG WWID_LIST
 
 DEFAULT_CONFIG="# device-mapper-multipath configuration file
 
@@ -38,8 +38,10 @@ defaults {
 }"
 
 CONFIGFILE="/etc/multipath.conf"
+OUTPUTFILE="/etc/multipath.conf"
 MULTIPATHDIR="/etc/multipath"
 TMPFILE="/etc/multipath/.multipath.conf.tmp"
+WWIDS=0
 
 function usage
 {
@@ -48,13 +50,60 @@ function usage
 	echo "Commands:"
 	echo "Enable: --enable "
 	echo "Disable: --disable"
+	echo "Only allow certain wwids (instead of enable): --allow <WWID>"
 	echo "Set user_friendly_names (Default y): --user_friendly_names <y|n>"
 	echo "Set find_multipaths (Default y): --find_multipaths <y|n>"
 	echo "Load the dm-multipath modules on enable (Default y): --with_module <y|n>"
 	echo "start/stop/reload multipathd (Default n): --with_multipathd <y|n>"
+	echo "select output file (Default /etc/multipath.conf): --outfile <FILE>"
 	echo ""
 }
 
+function get_dm_deps
+{
+	shift 3
+	while [ -n "$1" -a -n "$2" ]; do
+		MAJOR=$(echo $1 | tr -d '(,')
+		MINOR=$(echo $2 | tr -d ')')
+		UUID=`dmsetup info -c --noheadings -o uuid -j $MAJOR -m $MINOR  2> /dev/null`
+		if [ -n "$UUID" ] ; then
+			set_dm_wwid $UUID
+		fi
+		shift 2
+	done
+}
+
+function set_dm_wwid
+{
+	if [[ "$1" =~ ^part[[:digit:]]+-mpath- ]] ; then
+		WWID_LIST[$WWIDS]="${1##part*-mpath-}"
+		((WWIDS++))
+	elif [[ "$1" =~ ^mpath- ]] ; then
+		WWID_LIST[$WWIDS]="${1##mpath-}"
+		((WWIDS++))
+	else
+		get_dm_deps `dmsetup deps -u $1`
+	fi
+}
+
+function set_wwid
+{
+	UUID=""
+	if [[ "$1" =~ ^[[:digit:]]+:[[:digit:]]+$ ]] ; then
+		MAJOR=${1%%:*}
+		MINOR=${1##*:}
+		UUID=`dmsetup info -c --noheadings -o uuid -j $MAJOR -m $MINOR  2> /dev/null`
+	else
+		UUID=`dmsetup info -c --noheadings -o uuid $1 2> /dev/null`
+	fi
+	if [ -n "$UUID" ] ; then
+		set_dm_wwid $UUID
+	else
+		WWID_LIST[$WWIDS]="$1"
+		((WWIDS++))
+	fi
+}
+
 function parse_args
 {
 	while [ -n "$1" ]; do
@@ -67,6 +116,16 @@ function parse_args
 				ENABLE=0
 				shift
 				;;
+			--allow)
+				ENABLE=2
+				if [ -n "$2" ]; then
+					set_wwid $2
+					shift 2
+				else
+					usage
+					exit 1
+				fi
+				;;
 			--user_friendly_names)
 				if [ -n "$2" ]; then
 					FRIENDLY=$2
@@ -103,6 +162,16 @@ function parse_args
 					exit 1
 				fi
 				;;
+			--outfile)
+				if [ -n "$2" ]; then
+					OUTPUTFILE=$2
+					HAVE_OUTFILE=1
+					shift 2
+				else
+					usage
+					exit 1
+				fi
+				;;
 			*)
 				usage
 				exit
@@ -137,6 +206,22 @@ function validate_args
 		echo "--with_multipathd must be either 'y' or 'n'"
 		exit 1
 	fi
+	if [ "$ENABLE" = 2 -a -z "$HAVE_OUTFILE" ]; then
+		echo "Because --allow makes changes that cannot be automatically reversed,"
+		echo "you must set --outfile when you set --allow"
+		exit 1
+	fi
+}
+
+function add_blacklist_exceptions
+{
+	echo "blacklist_exceptions {" >> $TMPFILE
+	INDEX=0
+	while [ "$INDEX" -lt "$WWIDS" ] ; do
+		echo "	wwid \"${WWID_LIST[$INDEX]}\"" >> $TMPFILE
+		((INDEX++))
+	done
+	echo "}" >> $TMPFILE
 }
 
 umask 0077
@@ -160,6 +245,10 @@ if grep -q "^blacklist[[:space:]]*{" $TM
 	HAVE_BLACKLIST=1
 fi
 
+if grep -q "^blacklist_exceptions[[:space:]]*{" $TMPFILE ; then
+	HAVE_EXCEPTIONS=1
+fi
+
 if grep -q "^defaults[[:space:]]*{" $TMPFILE ; then
 	HAVE_DEFAULTS=1
 fi
@@ -183,11 +272,19 @@ fi
 if [ "$HAVE_BLACKLIST" = "1" ]; then
 	if sed -n '/^blacklist[[:space:]]*{/,/^}/ p' $TMPFILE | grep -q "^[[:space:]]*devnode \"\.\?\*\"" ; then
 		HAVE_DISABLE=1
-	elif sed -n '/^blacklist[[:space:]]*{/,/^}/ p' $TMPFILE | grep -q "^[[:space:]]*#[#[:space:]]*devnode \"\.\?\*\"" ; then
+	elif sed -n '/^blacklist[[:space:]]*{/,/^}/ p' $TMPFILE | grep -q "^[[:space:]]*#[[:space:]]*devnode \"\.\?\*\"" ; then
 		HAVE_DISABLE=0
 	fi
 fi
 
+if [ "$HAVE_BLACKLIST" = "1" ]; then
+	if sed -n '/^blacklist[[:space:]]*{/,/^}/ p' $TMPFILE | grep -q "^[[:space:]]*wwid \"\.\?\*\"" ; then
+		HAVE_WWID_DISABLE=1
+	elif sed -n '/^blacklist[[:space:]]*{/,/^}/ p' $TMPFILE | grep -q "^[[:space:]]*#[[:space:]]*wwid \"\.\?\*\"" ; then
+		HAVE_WWID_DISABLE=0
+	fi
+fi
+
 if [ "$HAVE_DEFAULTS" = "1" ]; then
 	if sed -n '/^defaults[[:space:]]*{/,/^}/ p' $TMPFILE | grep -q "^[[:space:]]*find_multipaths[[:space:]]*\(yes\|1\)" ; then
 		HAVE_FIND=1
@@ -255,17 +352,33 @@ defaults {
 _EOF_
 fi
 
-if [ "$ENABLE" = 1 ]; then
+if [ "$ENABLE" = 2 ]; then
+	if [ "$HAVE_DISABLE" = 1 ]; then
+		sed -i '/^blacklist[[:space:]]*{/,/^}/ s/^[[:space:]]*devnode \"\.\?\*\"/#	devnode ".*"/' $TMPFILE
+	fi
+	if [ -z "$HAVE_WWID_DISABLE" ]; then
+		sed -i '/^blacklist[[:space:]]*{/ a\
+	wwid ".*"
+' $TMPFILE
+	elif [ "$HAVE_WWID_DISABLE" = 0 ]; then
+		sed -i '/^blacklist[[:space:]]*{/,/^}/ s/^[[:space:]]*#[[:space:]]*wwid \"\.\?\*\"/	wwid ".*"/' $TMPFILE
+	fi
+	if [ "$HAVE_EXCEPTIONS" = 1 ]; then
+		sed -i '/^blacklist_exceptions[[:space:]]*{/,/^}/d' $TMPFILE
+	fi
+	echo $HAVE_WWID_DISABLE
+	add_blacklist_exceptions
+elif [ "$ENABLE" = 1 ]; then
 	if [ "$HAVE_DISABLE" = 1 ]; then
 		sed -i '/^blacklist[[:space:]]*{/,/^}/ s/^[[:space:]]*devnode \"\.\?\*\"/#	devnode ".*"/' $TMPFILE
 	fi
 elif [ "$ENABLE" = 0 ]; then
 	if [ -z "$HAVE_DISABLE" ]; then
 		sed -i '/^blacklist[[:space:]]*{/ a\
-	devnode "*"
+	devnode ".*"
 ' $TMPFILE
 	elif [ "$HAVE_DISABLE" = 0 ]; then
-		sed -i '/^blacklist[[:space:]]*{/,/^}/ s/^[[:space:]]*#[#[:space:]]*devnode \"\.\?\*\"/	devnode ".*"/' $TMPFILE
+		sed -i '/^blacklist[[:space:]]*{/,/^}/ s/^[[:space:]]*#[[:space:]]*devnode \"\.\?\*\"/	devnode ".*"/' $TMPFILE
 	fi
 fi
 
@@ -303,17 +416,17 @@ elif [ "$FRIENDLY" = "y" ]; then
 	fi
 fi
 
-if [ -f "$CONFIGFILE" ]; then
-	cp $CONFIGFILE $CONFIGFILE.old
+if [ -f "$OUTPUTFILE" ]; then
+	cp $OUTPUTFILE $OUTPUTFILE.old
 	if [ $? != 0 ]; then
-		echo "failed to backup old config file, $CONFIGFILE not updated"
+		echo "failed to backup old config file, $OUTPUTFILE not updated"
 		exit 1
 	fi
 fi
 
-cp $TMPFILE $CONFIGFILE
+cp $TMPFILE $OUTPUTFILE
 if [ $? != 0 ]; then
-	echo "failed to copy new config file into place, check $CONFIGFILE is still OK"
+	echo "failed to copy new config file into place, check $OUTPUTFILE is still OK"
 	exit 1
 fi