dracut-functions: code formatting corrected

master
Amadeusz Żołnowski 2011-03-25 15:56:46 +01:00 committed by Harald Hoyer
parent b991617f19
commit 0b70674329
1 changed files with 77 additions and 68 deletions

View File

@ -70,7 +70,7 @@ vercmp() {
} }


is_func() { is_func() {
[[ $(type -t $1) = "function" ]] [[ $(type -t $1) = "function" ]]
} }


# Function prints global variables in format name=value line by line. # Function prints global variables in format name=value line by line.
@ -119,25 +119,25 @@ get_fs_uuid() (
# finds the major:minor of the block device backing the root filesystem. # finds the major:minor of the block device backing the root filesystem.
find_block_device() { find_block_device() {
local x mpt majmin dev fs misc maj min local x mpt majmin dev fs misc maj min
if [[ $use_fstab != yes ]]; then if [[ $use_fstab != yes ]]; then
while read x x majmin x mpt x x fs dev misc; do while read x x majmin x mpt x x fs dev misc; do
[[ $fs = nfs ]] && { echo $dev; return 0;} [[ $fs = nfs ]] && { echo $dev; return 0;}
[[ $fs = nfs3 ]] && { echo $dev; return 0;} [[ $fs = nfs3 ]] && { echo $dev; return 0;}
[[ $fs = nfs4 ]] && { echo $dev; return 0;} [[ $fs = nfs4 ]] && { echo $dev; return 0;}
[[ $fs = btrfs ]] && { [[ $fs = btrfs ]] && {
ls -nLl "$dev" | { ls -nLl "$dev" | {
read x x x x maj min x; read x x x x maj min x
maj=${maj//,/}; maj=${maj//,/}
echo $maj:$min; echo $maj:$min
} && return 0 } && return 0
} }
if [[ $mpt = $1 ]] && [[ ${majmin#0:} = $majmin ]]; then if [[ $mpt = $1 ]] && [[ ${majmin#0:} = $majmin ]]; then
echo $majmin; echo $majmin
return 0 # we have a winner! return 0 # we have a winner!
fi fi
done < /proc/self/mountinfo done < /proc/self/mountinfo
fi fi
# fall back to /etc/fstab # fall back to /etc/fstab
while read dev mpt fs misc; do while read dev mpt fs misc; do
if [[ $mpt = $1 ]]; then if [[ $mpt = $1 ]]; then
[[ $fs = nfs ]] && { echo $dev; return 0;} [[ $fs = nfs ]] && { echo $dev; return 0;}
@ -146,14 +146,15 @@ find_block_device() {
[[ $dev != ${dev#UUID=} ]] && dev=/dev/disk/by-uuid/${dev#UUID=} [[ $dev != ${dev#UUID=} ]] && dev=/dev/disk/by-uuid/${dev#UUID=}
[[ $dev != ${dev#LABEL=} ]] && dev=/dev/disk/by-label/${dev#LABEL=} [[ $dev != ${dev#LABEL=} ]] && dev=/dev/disk/by-label/${dev#LABEL=}
[[ -b $dev ]] || return 1 # oops, not a block device. [[ -b $dev ]] || return 1 # oops, not a block device.
ls -nLl "$dev" | { ls -nLl "$dev" | {
read x x x x maj min x; read x x x x maj min x
maj=${maj//,/}; maj=${maj//,/}
echo $maj:$min; echo $maj:$min
} && return 0 } && return 0
fi fi
done < /etc/fstab done < /etc/fstab
return 1;
return 1
} }


find_root_block_device() { find_block_device /; } find_root_block_device() { find_block_device /; }
@ -162,24 +163,24 @@ find_root_block_device() { find_block_device /; }
# Stop when our helper function returns success # Stop when our helper function returns success
# $1 = function to call on every found block device # $1 = function to call on every found block device
# $2 = block device in major:minor format # $2 = block device in major:minor format
check_block_and_slaves() { check_block_and_slaves() {
local x local x
[[ -b /dev/block/$2 ]] || return 1 # Not a block device? So sorry. [[ -b /dev/block/$2 ]] || return 1 # Not a block device? So sorry.
"$1" $2 && return "$1" $2 && return
check_vol_slaves "$@" && return 0 check_vol_slaves "$@" && return 0
if [[ -f /sys/dev/block/$2/../dev ]]; then if [[ -f /sys/dev/block/$2/../dev ]]; then
check_block_and_slaves $1 $(cat "/sys/dev/block/$2/../dev") && return 0 check_block_and_slaves $1 $(cat "/sys/dev/block/$2/../dev") && return 0
fi fi
[[ -d /sys/dev/block/$2/slaves ]] || return 1 [[ -d /sys/dev/block/$2/slaves ]] || return 1
for x in /sys/dev/block/$2/slaves/*/dev; do for x in /sys/dev/block/$2/slaves/*/dev; do
[[ -f $x ]] || continue [[ -f $x ]] || continue
check_block_and_slaves $1 $(cat "$x") && return 0 check_block_and_slaves $1 $(cat "$x") && return 0
done done
return 1 return 1
} }


get_numeric_dev() { get_numeric_dev() {
ls -lH "$1" | { read a b c d maj min rest; printf "%d:%d" ${maj%%,} $min;} ls -lH "$1" | { read a b c d maj min rest; printf "%d:%d" ${maj%%,} $min; }
} }


# ugly workaround for the lvm design # ugly workaround for the lvm design
@ -189,17 +190,16 @@ get_numeric_dev() {
# but you cannot create the logical volume without the volume group. # but you cannot create the logical volume without the volume group.
# And the volume group might be bigger than the devices the LV needs. # And the volume group might be bigger than the devices the LV needs.
check_vol_slaves() { check_vol_slaves() {
for i in /dev/mapper/*; do for i in /dev/mapper/*; do
lv=$(get_numeric_dev $i) lv=$(get_numeric_dev $i)
if [[ $lv = $2 ]]; then if [[ $lv = $2 ]]; then
vg=$(lvm lvs --noheadings -o vg_name $i 2>/dev/null) vg=$(lvm lvs --noheadings -o vg_name $i 2>/dev/null)
# strip space # strip space
vg=$(echo $vg) vg=$(echo $vg)
if [[ $vg ]]; then if [[ $vg ]]; then
for pv in $(lvm vgs --noheadings -o pv_name "$vg" 2>/dev/null); \ for pv in $(lvm vgs --noheadings -o pv_name "$vg" 2>/dev/null)
do do
check_block_and_slaves $1 $(get_numeric_dev $pv) \ check_block_and_slaves $1 $(get_numeric_dev $pv) && return 0
&& return 0
done done
fi fi
fi fi
@ -228,7 +228,7 @@ inst_dir() {
local target=$(readlink "$file") local target=$(readlink "$file")
ln -sfn "$target" "${initdir}$file" || return 1 ln -sfn "$target" "${initdir}$file" || return 1
# resolve relative path and recursively install destination # resolve relative path and recursively install destination
[[ $target == ${target#/} ]] && target=$(dirname "$file")/$target [[ $target == ${target#/} ]] && target="$(dirname "$file")/$target"
inst_dir "$target" inst_dir "$target"
else else
# create directory # create directory
@ -242,7 +242,7 @@ inst_dir() {
# Location of the image dir is assumed to be $initdir # Location of the image dir is assumed to be $initdir
# We never overwrite the target if it exists. # We never overwrite the target if it exists.
inst_simple() { inst_simple() {
local src target local src target
[[ -f $1 ]] || return 1 [[ -f $1 ]] || return 1
src=$1 target="${2:-$1}" src=$1 target="${2:-$1}"
if ! [[ -d ${initdir}$target ]]; then if ! [[ -d ${initdir}$target ]]; then
@ -250,10 +250,10 @@ inst_simple() {
inst_dir "${target%/*}" inst_dir "${target%/*}"
fi fi
# install checksum files also # install checksum files also
if [[ -e "${src%/*}/.${src##*/}.hmac" ]]; then if [[ -e "${src%/*}/.${src##*/}.hmac" ]]; then
inst "${src%/*}/.${src##*/}.hmac" "${target%/*}/.${target##*/}.hmac" inst "${src%/*}/.${src##*/}.hmac" "${target%/*}/.${target##*/}.hmac"
fi fi
dinfo "Installing $src" dinfo "Installing $src"
cp -pfL "$src" "${initdir}$target" cp -pfL "$src" "${initdir}$target"
} }


@ -279,7 +279,7 @@ rev_lib_symlinks() {
[[ -L ${fn} && $(readlink -f "${fn}") == ${orig} ]] && links+=" ${fn}" [[ -L ${fn} && $(readlink -f "${fn}") == ${orig} ]] && links+=" ${fn}"
done done


echo ${links} echo "${links}"
} }


# Same as above, but specialized to handle dynamic libraries. # Same as above, but specialized to handle dynamic libraries.
@ -289,15 +289,15 @@ inst_library() {
local src=$1 dest=${2:-$1} lib reallib symlink local src=$1 dest=${2:-$1} lib reallib symlink
[[ -e $initdir$dest ]] && return 0 [[ -e $initdir$dest ]] && return 0
if [[ -L $src ]]; then if [[ -L $src ]]; then
# install checksum files also # install checksum files also
if [[ -e "${src%/*}/.${src##*/}.hmac" ]]; then if [[ -e "${src%/*}/.${src##*/}.hmac" ]]; then
inst "${src%/*}/.${src##*/}.hmac" "${dest%/*}/.${dest##*/}.hmac" inst "${src%/*}/.${src##*/}.hmac" "${dest%/*}/.${dest##*/}.hmac"
fi fi
reallib=$(readlink -f "$src") reallib=$(readlink -f "$src")
lib=${src##*/} lib=${src##*/}
inst_simple "$reallib" "$reallib" inst_simple "$reallib" "$reallib"
inst_dir "${dest%/*}" inst_dir "${dest%/*}"
(cd "${initdir}${dest%/*}" && ln -s "$reallib" "$lib") (cd "${initdir}${dest%/*}" && ln -s "$reallib" "$lib")
else else
inst_simple "$src" "$dest" inst_simple "$src" "$dest"
fi fi
@ -364,7 +364,7 @@ inst_binary() {
IF_dynamic=yes IF_dynamic=yes
continue continue
fi fi
inst_library "$FILE" inst_library "$FILE"
done done
inst_simple "$bin" "$target" inst_simple "$bin" "$target"
} }
@ -404,7 +404,7 @@ find_rule() {


# udev rules always get installed in the same place, so # udev rules always get installed in the same place, so
# create a function to install them to make life simpler. # create a function to install them to make life simpler.
inst_rules() { inst_rules() {
local target=/etc/udev/rules.d rule found local target=/etc/udev/rules.d rule found


inst_dir "/lib/udev/rules.d" inst_dir "/lib/udev/rules.d"
@ -433,7 +433,7 @@ inst() {
1) ;; 1) ;;
2) [[ ! $initdir && -d $2 ]] && export initdir=$2 2) [[ ! $initdir && -d $2 ]] && export initdir=$2
[[ $initdir = $2 ]] && set $1;; [[ $initdir = $2 ]] && set $1;;
3) [[ -z $initdir ]] && export initdir=$2 3) [[ -z $initdir ]] && export initdir=$2
set $1 $3;; set $1 $3;;
*) derror "inst only takes 1 or 2 or 3 arguments" *) derror "inst only takes 1 or 2 or 3 arguments"
exit 1;; exit 1;;
@ -459,14 +459,14 @@ inst_hook() {
derror "Aborting initrd creation." derror "Aborting initrd creation."
exit 1 exit 1
elif ! strstr "$hookdirs" "$1"; then elif ! strstr "$hookdirs" "$1"; then
derror "No such hook type $1. Aborting initrd creation." derror "No such hook type $1. Aborting initrd creation."
exit 1 exit 1
fi fi
inst_simple "$3" "/lib/dracut/hooks/${1}/${2}${3##*/}" inst_simple "$3" "/lib/dracut/hooks/${1}/${2}${3##*/}"
} }


dracut_install() { dracut_install() {
if [[ $1 = '-o' ]]; then if [[ $1 = '-o' ]]; then
local optional=yes local optional=yes
shift shift
fi fi
@ -671,9 +671,10 @@ install_kmod_with_fw() {
local modname=${1##*/} fwdir found local modname=${1##*/} fwdir found
modname=${modname%.ko*} modname=${modname%.ko*}
# no need to go further if the module is already installed # no need to go further if the module is already installed
[[ -e "${initdir}/lib/modules/$kernel/${1##*/lib/modules/$kernel/}" ]] && return 0 [[ -e "${initdir}/lib/modules/$kernel/${1##*/lib/modules/$kernel/}" ]] \
inst_simple "$1" "/lib/modules/$kernel/${1##*/lib/modules/$kernel/}" || \ && return 0
return $? inst_simple "$1" "/lib/modules/$kernel/${1##*/lib/modules/$kernel/}" \
|| return $?
for fw in $(modinfo -k $kernel -F firmware $1 2>/dev/null); do for fw in $(modinfo -k $kernel -F firmware $1 2>/dev/null); do
found='' found=''
for fwdir in $fw_dir; do for fwdir in $fw_dir; do
@ -691,20 +692,23 @@ install_kmod_with_fw() {


# Do something with all the dependencies of a kernel module. # Do something with all the dependencies of a kernel module.
# Note that kernel modules depend on themselves using the technique we use # Note that kernel modules depend on themselves using the technique we use
# $1 = function to call for each dependency we find # $1 = function to call for each dependency we find
# It will be passed the full path to the found kernel module # It will be passed the full path to the found kernel module
# $2 = module to get dependencies for # $2 = module to get dependencies for
# rest of args = arguments to modprobe # rest of args = arguments to modprobe
for_each_kmod_dep() { for_each_kmod_dep() {
local func=$1 kmod=$2 cmd modpapth options local func=$1 kmod=$2 cmd modpapth options
shift 2 shift 2
modprobe "$@" --ignore-install --show-depends $kmod 2>/dev/null | ( \ modprobe "$@" --ignore-install --show-depends $kmod 2>/dev/null | (
local found=0; local found=0
while read cmd modpath options; do while read cmd modpath options; do
[[ $cmd = insmod ]] || continue [[ $cmd = insmod ]] || continue
$func ${modpath} || exit $? $func ${modpath} || exit $?
found=1 found=1
done; [[ $found -eq 0 ]] && exit 1; exit 0;) done
[[ $found -eq 0 ]] && exit 1
exit 0
)
return $? return $?
} }


@ -718,16 +722,20 @@ for_each_kmod_dep() {
# This function returns the full filenames of modules that match $1 # This function returns the full filenames of modules that match $1
filter_kernel_modules () ( filter_kernel_modules () (
if ! [[ $hostonly ]]; then if ! [[ $hostonly ]]; then
filtercmd='find "$srcmods/kernel/drivers" "$srcmods/extra" "$srcmods/weak-updates" -name "*.ko" -o -name "*.ko.gz" 2>/dev/null' filtercmd='find "$srcmods/kernel/drivers" "$srcmods/extra"'
filtercmd+=' "$srcmods/weak-updates" -name "*.ko" -o -name "*.ko.gz"'
filtercmd+=' 2>/dev/null'
else else
filtercmd='cut -d " " -f 1 </proc/modules|xargs modinfo -F filename -k $kernel 2>/dev/null' filtercmd='cut -d " " -f 1 </proc/modules|xargs modinfo -F filename '
filtercmd+='-k $kernel 2>/dev/null'
fi fi
for modname in $(eval $filtercmd); do for modname in $(eval $filtercmd); do
case $modname in case $modname in
*.ko) "$1" "$modname" && echo "$modname";; *.ko) "$1" "$modname" && echo "$modname";;
*.ko.gz) gzip -dc "$modname" > $initdir/$$.ko *.ko.gz) gzip -dc "$modname" > $initdir/$$.ko
$1 $initdir/$$.ko && echo "$modname" $1 $initdir/$$.ko && echo "$modname"
rm -f $initdir/$$.ko;; rm -f $initdir/$$.ko
;;
esac esac
done done
) )
@ -740,18 +748,19 @@ instmods() {
while (($# > 0)); do while (($# > 0)); do
mod=${1%.ko*} mod=${1%.ko*}
case $mod in case $mod in
=*) =*)
# This introduces 2 incompatible meanings for =* arguments # This introduces 2 incompatible meanings for =* arguments
# to instmods. We need to decide which one to keep. # to instmods. We need to decide which one to keep.
if [[ $mod = =ata && -f $srcmods/modules.block ]] ; then if [[ $mod = =ata && -f $srcmods/modules.block ]]; then
instmods $mpargs $(egrep 'ata|ahci' "${srcmods}/modules.block") instmods $mpargs \
$(egrep 'ata|ahci' "${srcmods}/modules.block")
elif [ -f $srcmods/modules.${mod#=} ]; then elif [ -f $srcmods/modules.${mod#=} ]; then
instmods $mpargs $(cat ${srcmods}/modules.${mod#=} ) instmods $mpargs $(cat ${srcmods}/modules.${mod#=} )
else else
instmods $mpargs $(find "$srcmods" -path "*/${mod#=}/*") instmods $mpargs $(find "$srcmods" -path "*/${mod#=}/*")
fi fi
;; ;;
--*) --*)
mod=${mod##*/} mod=${mod##*/}
mpargs+=" $mod";; mpargs+=" $mod";;
i2o_scsi) shift; continue;; # Do not load this diagnostic-only module i2o_scsi) shift; continue;; # Do not load this diagnostic-only module
@ -761,25 +770,25 @@ instmods() {
[[ -f $initdir/$1 ]] && { shift; continue; } [[ -f $initdir/$1 ]] && { shift; continue; }
# If we are building a host-specific initramfs and this # If we are building a host-specific initramfs and this
# module is not already loaded, move on to the next one. # module is not already loaded, move on to the next one.
[[ $hostonly ]] && ! grep -qe "\<${mod//-/_}\>" /proc/modules && \ [[ $hostonly ]] && ! grep -qe "\<${mod//-/_}\>" /proc/modules \
! echo $add_drivers | grep -qe "\<${mod}\>" && { && ! echo $add_drivers | grep -qe "\<${mod}\>" && {
shift; continue; shift; continue
} }


# We use '-d' option in modprobe only if modules prefix path # We use '-d' option in modprobe only if modules prefix path
# differs from default '/'. This allows us to use Dracut with # differs from default '/'. This allows us to use Dracut with
# old version of modprobe which doesn't have '-d' option. # old version of modprobe which doesn't have '-d' option.
moddirname=${srcmods%%/lib/modules/*} moddirname=${srcmods%%/lib/modules/*}
[[ -n ${moddirname} ]] && moddirname="-d ${moddirname}/" [[ -n ${moddirname} ]] && moddirname="-d ${moddirname}/"

# ok, load the module, all its dependencies, and any firmware # ok, load the module, all its dependencies, and any firmware
# it may require # it may require
for_each_kmod_dep install_kmod_with_fw $mod \ for_each_kmod_dep install_kmod_with_fw $mod \
--set-version $kernel ${moddirname} --set-version $kernel ${moddirname}
ret=$((ret+$?)) ret=$((ret+$?))
;; ;;
esac esac
shift shift
done done
return $ret return $ret
} }