Browse Source

make host_fs_types a hashmap

This requires bash >= 4, but hash maps are so much more comfortable
master
Harald Hoyer 12 years ago
parent
commit
d351541ee6
  1. 14
      dracut-functions.sh
  2. 23
      dracut.sh
  3. 6
      modules.d/90btrfs/module-setup.sh
  4. 39
      modules.d/90crypt/module-setup.sh
  5. 34
      modules.d/90dmraid/module-setup.sh
  6. 36
      modules.d/90lvm/module-setup.sh
  7. 45
      modules.d/90mdraid/module-setup.sh
  8. 2
      modules.d/95cifs/module-setup.sh
  9. 6
      modules.d/95nfs/module-setup.sh
  10. 4
      modules.d/95virtfs/module-setup.sh

14
dracut-functions.sh

@ -450,23 +450,15 @@ find_mp_fstype() { @@ -450,23 +450,15 @@ find_mp_fstype() {
find_root_block_device() { find_block_device /; }

# for_each_host_dev_fs <func>
# Execute "<func> <dev> <filesystem>" for every "<dev>|<fs>" pair found
# Execute "<func> <dev> <filesystem>" for every "<dev> <fs>" pair found
# in ${host_fs_types[@]}
for_each_host_dev_fs()
{
local _func="$1"
local _dev
local _fs
local _ret=1
for f in ${host_fs_types[@]}; do
OLDIFS="$IFS"
IFS="|"
set -- $f
IFS="$OLDIFS"
_dev="$1"
[[ -b "$_dev" ]] || continue
_fs="$2"
$_func $_dev $_fs && _ret=0
for _dev in "${!host_fs_types[@]}"; do
$_func "$_dev" "${host_fs_types[$_dev]}" && _ret=0
done
return $_ret
}

23
dracut.sh

@ -750,11 +750,13 @@ fi @@ -750,11 +750,13 @@ fi
# Need to be able to have non-root users read stuff (rpcbind etc)
chmod 755 "$initdir"

declare -A host_fs_types

for line in "${fstab_lines[@]}"; do
set -- $line
#dev mp fs fsopts
push host_devs "$1"
push host_fs_types "$1|$3"
host_fs_types["$1"]="$3"
done

for f in $add_fstab; do
@ -797,28 +799,27 @@ fi @@ -797,28 +799,27 @@ fi
_get_fs_type() (
[[ $1 ]] || return
if [[ -b $1 ]] && get_fs_env $1; then
echo "$(readlink -f $1)|$ID_FS_TYPE"
echo "$(readlink -f $1) $ID_FS_TYPE"
return 1
fi
if [[ -b /dev/block/$1 ]] && get_fs_env /dev/block/$1; then
echo "$(readlink -f /dev/block/$1)|$ID_FS_TYPE"
echo "$(readlink -f /dev/block/$1) $ID_FS_TYPE"
return 1
fi
if fstype=$(find_dev_fstype $1); then
echo "$1|$fstype"
echo "$1 $fstype"
return 1
fi
return 1
)

for dev in "${host_devs[@]}"; do
unset fs_type
for fstype in $(_get_fs_type $dev) \
$(check_block_and_slaves _get_fs_type $(get_maj_min $dev)); do
if ! strstr " ${host_fs_types[*]} " " $fstype ";then
push host_fs_types "$fstype"
fi
done
while read key val; do
host_fs_types["$key"]="$val"
done < <(
_get_fs_type $dev
check_block_and_slaves_all _get_fs_type $(get_maj_min $dev)
)
done

[[ -d $udevdir ]] \

6
modules.d/90btrfs/module-setup.sh

@ -9,12 +9,10 @@ check() { @@ -9,12 +9,10 @@ check() {
type -P btrfs >/dev/null || return 1

[[ $hostonly ]] || [[ $mount_needs ]] && {
local _found
for fs in ${host_fs_types[@]}; do
strstr "$fs" "\|btrfs" && _found="1"
[[ "$fs" == "btrfs" ]] && return 0
done
[[ $_found ]] || return 1
unset _found
return 255
}

return 0

39
modules.d/90crypt/module-setup.sh

@ -7,8 +7,30 @@ check() { @@ -7,8 +7,30 @@ check() {
# if cryptsetup is not installed, then we cannot support encrypted devices.
type -P cryptsetup >/dev/null || return 1

[[ $hostonly ]] || [[ $mount_needs ]] && {
for fs in "${host_fs_types[@]}"; do
[[ $fs = "crypto_LUKS" ]] && return 0
done
return 255
}

return 0
}

depends() {
echo dm rootfs-block
return 0
}

installkernel() {
instmods dm_crypt =crypto
}

install() {

check_crypt() {
local dev=$1 fs=$2

[[ $fs = "crypto_LUKS" ]] || return 1
ID_FS_UUID=$(udevadm info --query=property --name=$dev \
| while read line; do
@ -24,23 +46,8 @@ check() { @@ -24,23 +46,8 @@ check() {
return 0
}

[[ $hostonly ]] || [[ $mount_needs ]] && {
for_each_host_dev_and_slaves_all check_crypt || return 1
}

return 0
}

depends() {
echo dm rootfs-block
return 0
}

installkernel() {
instmods dm_crypt =crypto
}
for_each_host_dev_fs check_crypt

install() {
dracut_install cryptsetup rmdir readlink umount
inst_script "$moddir"/cryptroot-ask.sh /sbin/cryptroot-ask
inst_script "$moddir"/probe-keydev.sh /sbin/probe-keydev

34
modules.d/90dmraid/module-setup.sh

@ -8,9 +8,27 @@ check() { @@ -8,9 +8,27 @@ check() {
# in trying to support it in the initramfs.
type -P dmraid >/dev/null || return 1

[[ $hostonly ]] || [[ $mount_needs ]] && {
for fs in "${host_fs_types[@]}"; do
[[ $fs = *_raid_member ]] && return 0
done
return 255
}

return 0
}

depends() {
echo dm rootfs-block
return 0
}

install() {
local _i

check_dmraid() {
local dev=$1 fs=$2 holder DEVPATH DM_NAME
[[ "$fs" = "${fs%%_raid_member}" ]] && return 1
[[ "$fs" != *_raid_member ]] && return 1

DEVPATH=$(udevadm info --query=property --name=$dev \
| while read line; do
@ -37,20 +55,8 @@ check() { @@ -37,20 +55,8 @@ check() {
return 0
}

[[ $hostonly ]] || [[ $mount_needs ]] && {
for_each_host_dev_and_slaves_all check_dmraid || return 1
}
for_each_host_dev_fs check_dmraid

return 0
}

depends() {
echo dm rootfs-block
return 0
}

install() {
local _i
dracut_install dmraid
dracut_install -o kpartx
inst $(command -v partx) /sbin/partx

36
modules.d/90lvm/module-setup.sh

@ -7,22 +7,11 @@ check() { @@ -7,22 +7,11 @@ check() {
# No point trying to support lvm if the binaries are missing
type -P lvm >/dev/null || return 1

check_lvm() {
local DM_VG_NAME DM_LV_NAME DM_UDEV_DISABLE_DISK_RULES_FLAG
eval $(udevadm info --query=property --name=/dev/block/$1|egrep '(DM_VG_NAME|DM_LV_NAME|DM_UDEV_DISABLE_DISK_RULES_FLAG)=')
[[ "$DM_UDEV_DISABLE_DISK_RULES_FLAG" = "1" ]] && return 1
[[ ${DM_VG_NAME} ]] && [[ ${DM_LV_NAME} ]] || return 1
if ! strstr " ${_activated[*]} " " ${DM_VG_NAME}/${DM_LV_NAME} "; then
if ! [[ $kernel_only ]]; then
echo " rd.lvm.lv=${DM_VG_NAME}/${DM_LV_NAME} " >> "${initdir}/etc/cmdline.d/90lvm.conf"
fi
push _activated "${DM_VG_NAME}/${DM_LV_NAME}"
fi
return 0
}

[[ $hostonly ]] || [[ $mount_needs ]] && {
for_each_host_dev_and_slaves_all check_lvm || return 1
for fs in "${host_fs_types[@]}"; do
[[ $fs = LVM*_member ]] && return 0
done
return 255
}

return 0
@ -38,6 +27,23 @@ install() { @@ -38,6 +27,23 @@ install() {
local _i
inst lvm

check_lvm() {
local DM_VG_NAME DM_LV_NAME DM_UDEV_DISABLE_DISK_RULES_FLAG

eval $(udevadm info --query=property --name=$1 | egrep '(DM_VG_NAME|DM_LV_NAME|DM_UDEV_DISABLE_DISK_RULES_FLAG)=')
[[ "$DM_UDEV_DISABLE_DISK_RULES_FLAG" = "1" ]] && return 1
[[ ${DM_VG_NAME} ]] && [[ ${DM_LV_NAME} ]] || return 1
if ! strstr " ${_activated[*]} " " ${DM_VG_NAME}/${DM_LV_NAME} "; then
if ! [[ $kernel_only ]]; then
echo " rd.lvm.lv=${DM_VG_NAME}/${DM_LV_NAME} " >> "${initdir}/etc/cmdline.d/90lvm.conf"
fi
push _activated "${DM_VG_NAME}/${DM_LV_NAME}"
fi
return 0
}

for_each_host_dev_fs check_lvm

inst_rules "$moddir/64-lvm.rules"

if [[ $hostonly ]] || [[ $lvmconf = "yes" ]]; then

45
modules.d/90mdraid/module-setup.sh

@ -7,27 +7,11 @@ check() { @@ -7,27 +7,11 @@ check() {
# No mdadm? No mdraid support.
type -P mdadm >/dev/null || return 1

check_mdraid() {
local dev=$1 fs=$2 holder DEVPATH MD_UUID
[[ "$fs" = "${fs%%_raid_member}" ]] && return 1

MD_UUID=$(/sbin/mdadm --examine --export $dev \
| while read line; do
[[ ${line#MD_UUID} = $line ]] && continue
eval "$line"
echo $MD_UUID
break
done)

[[ ${MD_UUID} ]] || return 1
if ! [[ $kernel_only ]]; then
echo " rd.md.uuid=${MD_UUID} " >> "${initdir}/etc/cmdline.d/90mdraid.conf"
fi
return 0
}

[[ $hostonly ]] || [[ $mount_needs ]] && {
for_each_host_dev_and_slaves_all check_mdraid || return 1
for fs in "${host_fs_types[@]}"; do
[[ "$fs" == *_raid_member ]] && return 0
done
return 255
}

return 0
@ -48,6 +32,27 @@ install() { @@ -48,6 +32,27 @@ install() {
inst $(command -v partx) /sbin/partx
inst $(command -v mdadm) /sbin/mdadm

check_mdraid() {
local dev=$1 fs=$2 holder DEVPATH MD_UUID
[[ "$fs" != *_raid_member ]] && return 1

MD_UUID=$(/sbin/mdadm --examine --export $dev \
| while read line; do
[[ ${line#MD_UUID} = $line ]] && continue
eval "$line"
echo $MD_UUID
break
done)

[[ ${MD_UUID} ]] || return 1
if ! [[ $kernel_only ]]; then
echo " rd.md.uuid=${MD_UUID} " >> "${initdir}/etc/cmdline.d/90mdraid.conf"
fi
return 0
}

for_each_host_dev_fs check_mdraid

inst_rules 64-md-raid.rules
# remove incremental assembly from stock rules, so they don't shadow
# 65-md-inc*.rules and its fine-grained controls, or cause other problems

2
modules.d/95cifs/module-setup.sh

@ -8,7 +8,7 @@ check() { @@ -8,7 +8,7 @@ check() {

[[ $hostonly ]] || [[ $mount_needs ]] && {
for fs in ${host_fs_types[@]}; do
strstr "$fs" "\|cifs" && return 0
[[ "$fs" == "cifs" ]] && return 0
done
return 255
}

6
modules.d/95nfs/module-setup.sh

@ -9,9 +9,9 @@ check() { @@ -9,9 +9,9 @@ check() {

[[ $hostonly ]] || [[ $mount_needs ]] && {
for fs in ${host_fs_types[@]}; do
strstr "$fs" "\|nfs" && return 0
strstr "$fs" "\|nfs3" && return 0
strstr "$fs" "\|nfs4" && return 0
[[ "$fs" == "nfs" ]] && return 0
[[ "$fs" == "nfs3" ]] && return 0
[[ "$fs" == "nfs4" ]] && return 0
done
return 255
}

4
modules.d/95virtfs/module-setup.sh

@ -5,9 +5,9 @@ @@ -5,9 +5,9 @@
check() {
[[ $hostonly ]] || [[ $mount_needs ]] && {
for fs in ${host_fs_types[@]}; do
strstr "$fs" "\|9p" && return 0
[[ "$fs" == "9p" ]] && return 0
done
return 1
return 255
}

if type -P systemd-detect-virt >/dev/null 2>&1; then

Loading…
Cancel
Save