Author: glen
Date: Wed Nov 14 00:48:45 2007
New Revision: 9047

Modified:
   geninitrd/trunk/geninitrd
Log:
- 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

Modified: geninitrd/trunk/geninitrd
==============================================================================
--- geninitrd/trunk/geninitrd   (original)
+++ geninitrd/trunk/geninitrd   Wed Nov 14 00:48:45 2007
@@ -77,7 +77,7 @@
 # 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 @@
        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 @@
        # 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_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 @@
                done
 
                debugshell
-               /sbin/multipath -v 0 $WWID
+               /sbin/multipath -v 0 $MPATH_WWID
 
                for a in /dev/mapper/*; do
                        [ $a = /dev/mapper/control ] && continue
_______________________________________________
pld-cvs-commit mailing list
[email protected]
http://lists.pld-linux.org/mailman/listinfo/pld-cvs-commit

Reply via email to