From 365236266944718fbb3202fc1e7c6f382db72387 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Elan=20Ruusam=C3=A4e?= Date: Mon, 24 Nov 2008 00:17:49 +0000 Subject: [PATCH] - modularize dmraid svn-id: @10003 --- Makefile | 2 +- geninitrd | 66 +++++------------------------------------ mod-dmraid.sh | 81 +++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 90 insertions(+), 59 deletions(-) create mode 100644 mod-dmraid.sh diff --git a/Makefile b/Makefile index 846c4d7..a48e427 100644 --- 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 diff --git a/geninitrd b/geninitrd index 56ae9a1..bdc295b 100755 --- 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 index 0000000..b8f2bf1 --- /dev/null +++ b/mod-dmraid.sh @@ -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 +} -- 2.44.0