]> git.pld-linux.org Git - projects/geninitrd.git/blobdiff - mod-multipath.sh
no need to mess with magic values, let the "magic" be value
[projects/geninitrd.git] / mod-multipath.sh
index 9b28cf11c7c5e896353ee236fa991f77553b2c53..2a6121b9acac8f3462b6451ed5d6cb9b340d5c57 100644 (file)
@@ -1,5 +1,6 @@
 #!/bin/sh
-#
+MULTIPATH_RCSID='$Revision$ $Date::                            $'
+
 # geninitrd mod: dm-multipath
 USE_MULTIPATH=${USE_MULTIPATH:-yes}
 
@@ -24,12 +25,9 @@ is_multipath() {
        local devpath="$1"
 
        # multipath disabled
-       if ! is_yes "$USE_MULTIPATH"; then
+       if is_no "$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
@@ -39,7 +37,7 @@ fi
        DM_NAME=
        eval $(dm_export "$devpath")
        if [ -z "$DM_NAME" ]; then
-               die "dm_export failed unexpectedly"
+               die "Couldn't extract DM_NAME from $devpath"
        fi
 
        local MPATH_WWID=${DM_UUID##*-}
@@ -61,13 +59,10 @@ fi
 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
-               die "dm_export failed unexpectedly"
+               die "Couldn't extract DM_NAME from $devpath"
        fi
 
        # Partition:
@@ -93,11 +88,9 @@ fi
                lvm_ignore_devices="$lvm_ignore_devices $p"
        done
 
-       # 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}')
+       list=$(mp_parse_hwhandler "$info")
        for p in $list; do
-               find_module "dm-$p"
+               find_module "$p"
        done
 
        list=$(mp_parse_policy "$info")
@@ -112,17 +105,21 @@ fi
 # generate initrd fragment
 # @access      public
 initrd_gen_multipath() {
+       if ! is_yes "$have_multipath"; then
+               return
+       fi
+
        inst_d /sbin /lib/udev /etc/multipath
        inst_exec /sbin/kpartx /sbin
        inst_exec /sbin/multipath /sbin
 
        # for udev callouts
-       local scsi_id=$(find_tool /lib/udev/scsi_id /sbin/scsi_id)
+       local scsi_id=$(find_tool /$_lib/udev/scsi_id /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
+       if [ -d /$_lib/multipath ]; then
+               inst_d /$_lib/multipath
+               inst_exec /$_lib/multipath/* /$_lib/multipath
        else
                inst_exec /sbin/mpath* /sbin
        fi
@@ -268,3 +265,31 @@ mp_parse_policy() {
                }
        ' | sort -u
 }
+
+# parse hwhandler from multipath output
+# takes 'multipath -l' output as input
+mp_parse_hwhandler() {
+       local info="$1"
+
+       # TODO: actually the dm-emc vs scsi-dh-emc is dependant on kernel version
+       # not version of the tools installed
+
+       # multipath-tools-0.4.8-0.12.amd64
+       # [size=12G][features=1 queue_if_no_path][hwhandler=1 emc]
+       #
+       # multipath-tools-0.4.8-11.x86_64
+       # size=7.0G features='0' hwhandler='0' wp=rw
+       # size=2.0G features='1 queue_if_no_path' hwhandler='1 emc' wp=rw
+       echo "$info" | sed -ne "
+               # multipath-tools-0.4.8-0.12.amd64
+               /\[hwhandler=1/{
+                       s,^.*\[hwhandler=1 \([^]]*\)\].*$,dm-\1,
+                       p
+               }
+               # multipath-tools-0.4.8-11.x86_64
+               /hwhandler='1/{
+                       s,^.*hwhandler='1 \([^']*\)'.*$,scsi-dh-\1,
+                       p
+               }
+       " | sort -u
+}
This page took 0.049809 seconds and 4 git commands to generate.