]> git.pld-linux.org Git - projects/geninitrd.git/commitdiff
- modularize dmraid
authorElan Ruusamäe <glen@pld-linux.org>
Mon, 24 Nov 2008 00:17:49 +0000 (00:17 +0000)
committerElan Ruusamäe <glen@pld-linux.org>
Mon, 24 Nov 2008 00:17:49 +0000 (00:17 +0000)
svn-id: @10003

Makefile
geninitrd
mod-dmraid.sh [new file with mode: 0644]

index 846c4d7ddddf0d9a9efdaa4ea13b4a9f534e2828..a48e427e9b91ab04005e7bb6018b1a2dfaf81639 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -1,6 +1,6 @@
 # when making release, make sure you do it as RELEASE document describes
 VERSION                := 10000
-MODS           := mod-luks.sh mod-multipath.sh
+MODS           := mod-luks.sh mod-multipath.sh mod-dmraid.sh
 FILES          := Makefile geninitrd.sysconfig geninitrd functions $(MODS) geninitrd.8 geninitrd.8.xml ChangeLog
 prefix         := /usr
 mandir         := $(prefix)/share/man
index 56ae9a13f2ca947f25e94ef53c9af1029408596f..bdc295baa40ecbca8711f996ea00215b7d8fc484 100755 (executable)
--- a/geninitrd
+++ b/geninitrd
@@ -82,8 +82,6 @@ have_nfs=no
 have_lvm=no
 # if we should init md (softraid) at boot
 have_md=no
-# if we should init dmraid at boot
-have_dmraid=no
 
 usage() {
        uname_r=$(uname -r)
@@ -103,7 +101,7 @@ usage() {
        echo ""
        echo "example:"
        echo "  $PROGRAM -f --initrdfs=rom /boot/initrd-$uname_r.gz $uname_r"
-       exit 1
+       exit 0
 }
 
 msg() {
@@ -724,34 +722,6 @@ dm_export() {
        esac
 }
 
-
-# find dmraid modules for $devpath
-# returns false if $devpath is not on dmraid
-find_modules_dmraid() {
-       local devpath="$1"
-
-       # get blockdev itself (without partition)
-       # /dev/mapper/sil_ahbgadcbchfc3 -> /dev/mapper/sil_ahbgadcbchfc
-       local blockdev=${devpath%%[0-9]*}
-       local raidname=${blockdev#/dev/mapper/}
-       local found=0
-
-       local dev phydevs=$(dmraid -r -cdevpath,raidname | awk -F, -vv="$raidname" '{if ($2 == v) print $1}')
-       for dev in $phydevs; do
-               find_modules_for_devpath $dev
-               lvm_ignore_devices="$lvm_ignore_devices $dev"
-               found=1
-       done
-
-       if [ $found = 0 ]; then
-               return 1
-       fi
-
-       findmodule "dm-mirror"
-       have_dmraid=yes
-       return 0
-}
-
 # find modules for $devpath
 find_modules_for_devpath() {
        local devpath="$1"
@@ -807,7 +777,7 @@ find_modules_for_devpath() {
                # fallback
        fi
 
-       if is_yes "$USE_DMRAID" && is_yes "$(echo "$devpath" | awk '/^\/dev\/mapper\/(sil|hpt37x|hpt45x|isw|lsi|nvidia|pdc|sil|via|dos)_/ { print "yes"; }')"; then
+       if is_dmraid "$devpath"; then
                if find_modules_dmraid "$devpath"; then
                        return
                fi
@@ -1110,26 +1080,6 @@ initrd_gen_stop_udevd() {
 }
 
 
-initrd_gen_dmraid() {
-       if [ ! -x /sbin/dmraid-initrd ]; then
-               die "/sbin/dmraid-initrd is missing!"
-       fi
-
-       inst_d /sbin
-       inst_exec /sbin/dmraid-initrd /sbin/dmraid
-
-       mount_dev
-       mount_sys
-       initrd_gen_devices
-       add_linuxrc <<-EOF
-               # 2 secs was enough for my system to initialize. but really this is udev issue?
-               usleep 2000000
-               : 'Activating Device-Mapper RAID(s)'
-               /sbin/dmraid -ay -i
-
-               debugshell
-       EOF
-}
 
 initrd_gen_bootsplash() {
        local target="$1"
@@ -1607,14 +1557,12 @@ if [ -f /etc/udev/udev.conf -a -x /sbin/initrd-udevd ]; then
        . /etc/udev/udev.conf
 fi
 
-if [ -x /sbin/dmraid-initrd ]; then
-       USE_DMRAID=yes
-fi
-
 # cryptsetup luks addon
 . /etc/geninitrd/mod-luks.sh
 # dm-multipath addon
 . /etc/geninitrd/mod-multipath.sh
+# dmraid addon
+. /etc/geninitrd/mod-dmraid.sh
 
 if [ -x /sbin/initrd-blkid ]; then
        USE_BLKID=yes
@@ -1776,7 +1724,8 @@ while [ $# -gt 0 ]; do
                elif [ -z "$kernel" ]; then
                        kernel="$1"
                else
-                       usage
+                       usage >&2
+                       exit 1
                fi
                ;;
        esac
@@ -1785,7 +1734,8 @@ while [ $# -gt 0 ]; do
 done
 
 if [ -z "$target" -o -z "$kernel" ]; then
-       usage
+       usage >&2
+       exit 1
 fi
 
 if [ ! -f /boot/vmlinuz-"$kernel" ]; then
diff --git a/mod-dmraid.sh b/mod-dmraid.sh
new file mode 100644 (file)
index 0000000..b8f2bf1
--- /dev/null
@@ -0,0 +1,81 @@
+#!/bin/sh
+#
+# geninitrd mod: dmraid
+
+# if we should init dmraid at boot
+have_dmraid=no
+
+if [ -x /sbin/dmraid-initrd ]; then
+       USE_DMRAID=yes
+else
+       USE_DMRAID=no
+fi
+
+# return true if dmraid is set on $devpath
+# @param       string $devpath device node to be examined
+# @access      public
+is_dmraid() {
+       local devpath="$1"
+
+       # dmraid disabled
+       if ! is_yes "$USE_DMRAID"; then
+               return 1
+       fi
+
+       if ! is_yes "$(echo "$devpath" | awk '/^\/dev\/mapper\/(sil|hpt37x|hpt45x|isw|lsi|nvidia|pdc|sil|via|dos)_/ { print "yes"; }')"; then
+               return
+       fi
+}
+
+# find dmraid modules for $devpath
+# @param       $devpath        device to be examined
+# @return      false if $devpath is not on dmraid
+# @access      public
+find_modules_dmraid() {
+       local devpath="$1"
+
+       # get blockdev itself (without partition)
+       # /dev/mapper/sil_ahbgadcbchfc3 -> /dev/mapper/sil_ahbgadcbchfc
+       local blockdev=${devpath%%[0-9]*}
+       local raidname=${blockdev#/dev/mapper/}
+       local found=0
+
+       local dev phydevs=$(dmraid -r -cdevpath,raidname | awk -F, -vv="$raidname" '{if ($2 == v) print $1}')
+       for dev in $phydevs; do
+               find_modules_for_devpath $dev
+               lvm_ignore_devices="$lvm_ignore_devices $dev"
+               found=1
+       done
+
+       if [ $found = 0 ]; then
+               return 1
+       fi
+
+       findmodule "dm-mirror"
+       have_dmraid=yes
+       return 0
+}
+
+# generate initrd fragment for dmraid
+# @access      public
+initrd_gen_dmraid() {
+       if [ ! -x /sbin/dmraid-initrd ]; then
+               die "/sbin/dmraid-initrd is missing!"
+       fi
+
+       inst_d /sbin
+       inst_exec /sbin/dmraid-initrd /sbin/dmraid
+
+       mount_dev
+       mount_sys
+       initrd_gen_devices
+       add_linuxrc <<-EOF
+               # 2 secs was enough for my system to initialize.
+               # XXX: shouldn't just call 'udevadm settle' ?
+               usleep 2000000
+               : 'Activating Device-Mapper RAID(s)'
+               /sbin/dmraid -ay -i
+
+               debugshell
+       EOF
+}
This page took 0.447996 seconds and 4 git commands to generate.