SVN: geninitrd/trunk/mod-multipath.sh

glen glen at pld-linux.org
Wed Jun 17 22:44:43 CEST 2009


Author: glen
Date: Wed Jun 17 22:44:43 2009
New Revision: 10395

Modified:
   geninitrd/trunk/mod-multipath.sh
Log:
- update to parse multipath-tools-0.4.8-9.x86_64 output and handle udev-core-141-1.x86_64

Modified: geninitrd/trunk/mod-multipath.sh
==============================================================================
--- geninitrd/trunk/mod-multipath.sh	(original)
+++ geninitrd/trunk/mod-multipath.sh	Wed Jun 17 22:44:43 2009
@@ -27,6 +27,9 @@
 	if ! is_yes "$USE_MULTIPATH"; then
 		return 1
 	fi
+if [ "$devpath" = /dev/sys/rootfs ]; then
+	devpath=/dev/mapper/LUN-14
+fi
 
 	# multipath nodes are under device mapper
 	if [[ "$devpath" != /dev/mapper/* ]]; then
@@ -40,6 +43,8 @@
 	fi
 
 	local MPATH_WWID=${DM_UUID##*-}
+
+	# just check if it is valid.
 	local info=$(multipath -l $MPATH_WWID)
 	if [ -z "$info" ]; then
 		return 1
@@ -56,6 +61,9 @@
 find_modules_multipath() {
 	local devpath="$1"
 
+if [ "$devpath" = /dev/sys/rootfs ]; then
+	devpath=/dev/mapper/LUN-14
+fi
 	DM_NAME=
 	eval $(dm_export "$devpath")
 	if [ -z "$DM_NAME" ]; then
@@ -77,20 +85,24 @@
 
 	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
-		find_modules_for_devpath $dev
-		lvm_ignore_devices="$lvm_ignore_devices $dev"
+
+	local p list
+	list=$(mp_parse_devs "$info")
+	for p in $list; do
+		find_modules_for_devpath $p
+		lvm_ignore_devices="$lvm_ignore_devices $p"
 	done
 
-	local hw hwhandlers=$(echo "$info" | awk '/hwhandler=1/{sub(/.*hwhandler=1 /, ""); sub(/\]$/, ""); print}')
-	for hw in $hwhandlers; do
-		find_module "dm-$hw"
+	# TODO: handle newer multipath-tools:
+	# size=7.0G features='0' hwhandler='0' wp=rw
+	list=$(echo "$info" | awk '/hwhandler=1/{sub(/.*hwhandler=1 /, ""); sub(/\]$/, ""); print}')
+	for p in $list; do
+		find_module "dm-$p"
 	done
 
-	local target targets=$(echo "$info" | awk '/prio=/{print $2}' | sort -u)
-	for target in $targets; do
-		find_module "dm-$target"
+	list=$(mp_parse_policy "$info")
+	for p in $list; do
+		find_module "dm-$p"
 	done
 
 	find_module "dm-mod"
@@ -105,8 +117,16 @@
 	inst_exec /sbin/multipath /sbin
 
 	# for udev callouts
-	inst_exec /sbin/scsi_id /lib/udev
-	inst_exec /sbin/mpath* /sbin
+	local scsi_id=$(find_tool /lib/udev/scsi_id /sbin/scsi_id)
+	inst_exec $scsi_id /lib/udev
+
+	if [ -d /lib/multipath ]; then
+		inst_d /lib/multipath
+		inst_exec /lib/multipath/* /lib/multipath
+	else
+		inst_exec /sbin/mpath* /sbin
+	fi
+
 	egrep -v '^([ 	]*$|#)' /etc/multipath.conf > $DESTDIR/etc/multipath.conf
 
 	if [ -f /etc/multipath/bindings ]; then
@@ -176,3 +196,75 @@
 	esac
 }
 
+# parse blockdevices behind multipath device
+# takes 'multipath -l' output as input
+mp_parse_devs() {
+	local info="$1"
+
+	# parse "0:0:1:0 sdf" -> /dev/sdf
+	#
+	# multipath-tools-0.4.8-0.12.amd64
+	# LUN-02 (36006016002c11800ce520d27c6ebda11) dm-0 DGC     ,RAID 10
+	# [size=12G][features=1 queue_if_no_path][hwhandler=1 emc]
+	# \_ round-robin 0 [prio=0][active]
+	#  \_ 0:0:0:0 sda 8:0   [active][undef]
+	# \_ round-robin 0 [prio=0][enabled]
+	#  \_ 0:0:1:0 sdf 8:80  [active][undef]
+	#
+	# multipath-tools-0.4.8-9.x86_64
+	# LUN-14 (36006016002c118006f4f8bccc7fada11) dm-3 ,
+	# size=7.0G features='0' hwhandler='0' wp=rw
+	# |-+- policy='round-robin 0' prio=-1 status=enabled
+	# | `- #:#:#:# sde 8:64 failed undef running
+	# `-+- policy='round-robin 0' prio=-1 status=active
+	#   `- #:#:#:# sdb 8:16 active undef running
+
+	echo "$info" | awk '{
+		if (match($0, /[#0-9]+:[#0-9]+:[#0-9]+:[#0-9]+ [^ ]+ [0-9]+:[0-9]/)) {
+			# take whole matched part into "l" variable
+			l = substr($0, RSTART, RLENGTH);
+			split(l, a, " ");
+			printf("/dev/%s\n", a[2])
+		}
+	}'
+}
+
+# parse policy output for each device
+# takes 'multipath -l' output as input
+mp_parse_policy() {
+	local info="$1"
+
+	# multipath-tools-0.4.8-0.12.amd64
+	# LUN-02 (36006016002c11800ce520d27c6ebda11) dm-0 DGC     ,RAID 10
+	# [size=12G][features=1 queue_if_no_path][hwhandler=1 emc]
+	# \_ round-robin 0 [prio=0][active]
+	#  \_ 0:0:0:0 sda 8:0   [active][undef]
+	# \_ round-robin 0 [prio=0][enabled]
+	#  \_ 0:0:1:0 sdf 8:80  [active][undef]
+	#
+	# multipath-tools-0.4.8-9.x86_64
+	# LUN-14 (36006016002c118006f4f8bccc7fada11) dm-3 ,
+	# size=7.0G features='0' hwhandler='0' wp=rw
+	# |-+- policy='round-robin 0' prio=-1 status=enabled
+	# | `- #:#:#:# sde 8:64 failed undef running
+	# `-+- policy='round-robin 0' prio=-1 status=active
+	#   `- #:#:#:# sdb 8:16 active undef running
+
+	echo "$info" | awk '
+		# multipath-tools-0.4.8-0.12.amd64
+		/\[prio=/{
+			print $2
+		}
+		# multipath-tools-0.4.8-9.x86_64
+		/policy=/{
+			if (match($0, /policy=[^ ]+/)) {
+				# take whole matched part into "l" variable
+				l = substr($0, RSTART, RLENGTH);
+				# remove policy= and single quote,
+				# which we can not use in this awk inline script, therefore the %c hack
+				sub(sprintf("^policy=%c?", 39), "", l);
+				print l
+			}
+		}
+	' | sort -u
+}


More information about the pld-cvs-commit mailing list