[readonly/geninitrd: 527/1068] - allow using user_friendly_names in multipath.conf and still use wwid in initrd - mpath_wwid= optio

draenog draenog at pld-linux.org
Sat Nov 2 19:56:42 CET 2013


commit 7548b2108a7940faff3144df73daa87e394903a6
Author: Elan Ruusamäe <glen at pld-linux.org>
Date:   Tue Nov 13 23:48:45 2007 +0000

    - allow using user_friendly_names in multipath.conf and still use wwid in initrd
    - mpath_wwid= option can override mpath wwwid to activate in initrd
    
    svn-id: @9047

 geninitrd | 77 ++++++++++++++++++++++++++++++++++++++++++++++++++-------------
 1 file changed, 62 insertions(+), 15 deletions(-)
---
diff --git a/geninitrd b/geninitrd
index 650ba56..03d3d66 100755
--- a/geninitrd
+++ b/geninitrd
@@ -77,7 +77,7 @@ have_dmraid=no
 # if we should init dm-multipath at boot
 have_multipath=no
 # dm-multipath wwid which is used for rootfs
-MULTIPATH_WWID=
+MPATH_WWID=
 
 usage() {
 	uname_r=$(uname -r)
@@ -684,22 +684,69 @@ _check_lvm() {
 	return $rc
 }
 
+# return dependencies MAJOR:MINOR [MAJOR:MINOR] for DM_NAME
+# TODO: patch `dmsetup export`
+dm_deps() {
+	local dm_name="$1"
+	dmsetup deps $dm_name | sed -e 's/, /:/g;s/^.\+ dependencies[^:]: //;s/[()]//g;'
+}
+
+# export info from dmsetup
+# param can be:
+# - MAJOR:MINOR
+# - /dev/dm-MINOR
+# - /dev/mapper/DM_NAME
+dm_export() {
+	local arg="$1"
+
+	case "$arg" in
+	*:*)
+		local maj=${arg%:*} min=${arg#*:}
+		dmsetup -j $maj -m $min export
+		;;
+	/dev/dm-*)
+		local min=${arg#*dm-}
+		local maj=$(awk '$2 == "device-mapper" {print $1}' /proc/devices)
+		dm_export $maj:$min
+		;;
+	/dev/mapper/*)
+		local dm_name=${arg#/dev/mapper/}
+		dmsetup export $dm_name
+		;;
+	*)
+		die "dm_export: unexpected $arg"
+		;;
+	esac
+}
+
 # find dm-multipath modules for $devpath
 # returns false if $devpath is not dm-multipath
 find_modules_multipath() {
 	local devpath="$1"
 
-	# remove partition, if any
-	local disk=${devpath%p[0-9]*}
-	# need only dm name
-	MULTIPATH_WWID=${disk#/dev/mapper/}
+	DM_NAME=
+	eval $(dm_export "$devpath")
+	if [ -z "$DM_NAME" ]; then
+		die "dm_export failed unexpectedly"
+	fi
+	mpath_wwid=${DM_UUID##*-}
+
+	if [ "$DM_TARGET_TYPES" != multipath ]; then
+		local dep deps=$(dm_deps $DM_NAME)
+		# must be a partition, fetch deps and retry
+		for dep in $deps; do
+			find_modules_multipath $dep && return
+		done
+		die "Couldn't find underlying device from $DM_NAME"
+	fi
 
-	local info=$(multipath -l $MULTIPATH_WWID)
+	MPATH_WWID=${DM_UUID##*-}
+	local info=$(multipath -l $MPATH_WWID)
 	if [ -z "$info" ]; then
 		return 1
 	fi
 
-	debug "Finding modules for dm-multipath"
+	debug "Finding modules for dm-multipath (WWID=$MPATH_WWID)"
 	have_multipath=yes
 	local dev phydevs=$(echo "$info" | awk '$2 ~ /^[0-9]+:[0-9]+:[0-9]+:[0-9]+$/{printf("/dev/%s\n", $3)}')
 	for dev in $phydevs; do
@@ -1031,7 +1078,7 @@ initrd_gen_multipath() {
 	# for udev callouts
 	inst_exec /sbin/scsi_id /lib/udev
 	inst_exec /sbin/mpath* /sbin
-	inst /etc/multipath.conf /etc
+	egrep -v '^([ 	]*$|#)' /etc/multipath.conf > $DESTDIR/etc/multipath.conf
 	if [ -f /var/lib/multipath/bindings ]; then
 		inst /var/lib/multipath/bindings /var/lib/multipath
 	else
@@ -1042,15 +1089,15 @@ initrd_gen_multipath() {
 	initrd_gen_devices
 
 	mount_sys
-	echo "export WWID=$MULTIPATH_WWID" | add_linuxrc
+	echo "export MPATH_WWID=$MPATH_WWID" | add_linuxrc
 	add_linuxrc <<-'EOF'
-		# parse wwid= from kernel commandline
+		# parse mpath_wwid= from kernel commandline
 		for arg in $CMDLINE; do
-			if [ "${arg##wwid=}" != "${arg}" ]; then
-				WWID=${arg##wwid=}
-				if [ "$WWID" = "*" ]; then
+			if [ "${arg##mpath_wwid=}" != "${arg}" ]; then
+				MPATH_WWID=${arg##mpath_wwid=}
+				if [ "$MPATH_WWID" = "*" ]; then
 					# '*' would mean activate all WWID-s
-					WWID=
+					MPATH_WWID=
 					echo "multipath: Activating all WWID-s"
 				else
 					echo "multipath: Activating WWID=$WWID"
@@ -1059,7 +1106,7 @@ initrd_gen_multipath() {
 		done
 
 		debugshell
-		/sbin/multipath -v 0 $WWID
+		/sbin/multipath -v 0 $MPATH_WWID
 
 		for a in /dev/mapper/*; do
 			[ $a = /dev/mapper/control ] && continue
================================================================

---- gitweb:

http://git.pld-linux.org/gitweb.cgi/readonly/geninitrd.git/commitdiff/147754ca159d40ca5eb541074dc043d8cbd92090



More information about the pld-cvs-commit mailing list