From b0692d03112c208cd414d6c108c79e10c8ef5b8c Mon Sep 17 00:00:00 2001 From: Harald Hoyer Date: Mon, 7 Nov 2011 08:46:36 +0100 Subject: [PATCH] add wait_for_dev() and wait_for_mount() --- modules.d/90btrfs/btrfs_finished.sh | 10 +++++--- .../90dmsquash-live/dmsquash-live-genrules.sh | 3 +-- .../90dmsquash-live/dmsquash-liveiso-genrules.sh | 1 - modules.d/90lvm/parse-lvm.sh | 7 +----- modules.d/95iscsi/parse-iscsiroot.sh | 2 -- modules.d/95nbd/parse-nbdroot.sh | 8 +++--- modules.d/95resume/resume-genrules.sh | 8 +----- modules.d/95rootfs-block/block-genrules.sh | 2 +- modules.d/99base/dracut-lib.sh | 29 +++++++++++++++++++++- 9 files changed, 43 insertions(+), 27 deletions(-) diff --git a/modules.d/90btrfs/btrfs_finished.sh b/modules.d/90btrfs/btrfs_finished.sh index 3601279..b01db69 100755 --- a/modules.d/90btrfs/btrfs_finished.sh +++ b/modules.d/90btrfs/btrfs_finished.sh @@ -4,13 +4,15 @@ type getarg >/dev/null 2>&1 || . /lib/dracut-lib.sh -if [ -e /dev/root ]; then - if strstr "$(udevadm info --query=env --name=/dev/root)" "ID_FS_TYPE=btrfs"; then +dev="${1:-/dev/root}" + +if [ -e "$dev" ]; then + if strstr "$(udevadm info --query=env \"--name=$dev\")" "ID_FS_TYPE=btrfs"; then info "Checking, if btrfs device complete" unset __btrfs_mount - mount -o ro /dev/root /tmp >/dev/null 2>&1 + mount -o ro "$dev" /tmp >/dev/null 2>&1 __btrfs_mount=$? - [ $__btrfs_mount -eq 0 ] && umount /dev/root >/dev/null 2>&1 + [ $__btrfs_mount -eq 0 ] && umount "$dev" >/dev/null 2>&1 exit $__btrfs_mount fi fi diff --git a/modules.d/90dmsquash-live/dmsquash-live-genrules.sh b/modules.d/90dmsquash-live/dmsquash-live-genrules.sh index aa0654b..b27fccc 100755 --- a/modules.d/90dmsquash-live/dmsquash-live-genrules.sh +++ b/modules.d/90dmsquash-live/dmsquash-live-genrules.sh @@ -9,12 +9,11 @@ case "$root" in printf 'SYMLINK=="%s", RUN+="/sbin/initqueue --settled --onetime --unique /sbin/dmsquash-live-root $env{DEVNAME}"\n' \ ${root#live:/dev/} } >> /etc/udev/rules.d/99-live-squash.rules - echo '[ -e /dev/root ]' > $hookdir/initqueue/finished/dmsquash.sh + wait_for_dev "${root#live:}" ;; live:*) if [ -f "${root#live:}" ]; then /sbin/initqueue --settled --onetime --unique /sbin/dmsquash-live-root "${root#live:}" - echo '[ -e /dev/root ]' > $hookdir/initqueue/finished/dmsquash.sh fi ;; esac diff --git a/modules.d/90dmsquash-live/dmsquash-liveiso-genrules.sh b/modules.d/90dmsquash-live/dmsquash-liveiso-genrules.sh index c05fbb9..30ea180 100755 --- a/modules.d/90dmsquash-live/dmsquash-liveiso-genrules.sh +++ b/modules.d/90dmsquash-live/dmsquash-liveiso-genrules.sh @@ -6,5 +6,4 @@ if [ "${root%%:*}" = "liveiso" ]; then printf 'KERNEL=="loop0", RUN+="/sbin/initqueue --settled --onetime --unique /sbin/dmsquash-live-root `/sbin/losetup -f --show %s`"\n' \ ${root#liveiso:} } >> /etc/udev/rules.d/99-liveiso-mount.rules - echo '[ -e /dev/root ]' > $hookdir/initqueue/finished/dmsquash.sh fi diff --git a/modules.d/90lvm/parse-lvm.sh b/modules.d/90lvm/parse-lvm.sh index b85a1ac..c1d00c6 100755 --- a/modules.d/90lvm/parse-lvm.sh +++ b/modules.d/90lvm/parse-lvm.sh @@ -10,12 +10,7 @@ if ! getargbool 1 rd.lvm -n rd_NO_LVM; then rm -f /etc/udev/rules.d/64-lvm*.rules else for dev in $(getargs rd.lvm.vg rd_LVM_VG=) $(getargs rd.lvm.lv rd_LVM_LV=); do - printf '[ -e "/dev/%s" ] || return 1\n' $dev \ - >> $hookdir/initqueue/finished/lvm.sh - { - printf '[ -e "/dev/%s" ] || ' $dev - printf 'warn "LVM "%s" not found"\n' $dev - } >> $hookdir/emergency/90-lvm.sh + wait_for_dev "/dev/$dev" done fi diff --git a/modules.d/95iscsi/parse-iscsiroot.sh b/modules.d/95iscsi/parse-iscsiroot.sh index 50341b2..3187632 100755 --- a/modules.d/95iscsi/parse-iscsiroot.sh +++ b/modules.d/95iscsi/parse-iscsiroot.sh @@ -76,5 +76,3 @@ rootok=1 # Shut up init error check [ -z "$root" ] && root="iscsi" -echo '[ -e /dev/root ]' > $hookdir/initqueue/finished/iscsi.sh - diff --git a/modules.d/95nbd/parse-nbdroot.sh b/modules.d/95nbd/parse-nbdroot.sh index 376681b..e237668 100755 --- a/modules.d/95nbd/parse-nbdroot.sh +++ b/modules.d/95nbd/parse-nbdroot.sh @@ -38,6 +38,7 @@ if [ "${root%%:*}" = "nbd" ] ; then fi netroot=$root + unset root fi # If it's not nbd we don't continue @@ -55,7 +56,8 @@ incol2 /proc/devices nbd || modprobe nbd || die "nbdroot requested but kernel/in rootok=1 # Shut up init error check -[ -z "$root" ] && root="nbd" - -echo '[ -e /dev/root ]' > $hookdir/initqueue/finished/nbd.sh +if [ -z "$root" ]; then + root=block:/dev/root + wait_for_dev /dev/root +fi diff --git a/modules.d/95resume/resume-genrules.sh b/modules.d/95resume/resume-genrules.sh index e1afc26..16df877 100755 --- a/modules.d/95resume/resume-genrules.sh +++ b/modules.d/95resume/resume-genrules.sh @@ -35,13 +35,7 @@ if [ -n "$resume" ]; then printf '[ -e "%s" ] && { ln -s "%s" /dev/resume; rm "$job"; }\n' \ "$resume" "$resume" >> $hookdir/initqueue/settled/resume.sh - echo '[ -e /dev/resume ]' > $hookdir/initqueue/finished/resume.sh - - { - printf '[ -e /dev/resume ] || ' - printf 'warn "resume device "%s" not found"\n' "$resume" - } >> $hookdir/emergency/00-resume.sh - + wait_for_dev "/dev/resume" elif ! getarg noresume; then { diff --git a/modules.d/95rootfs-block/block-genrules.sh b/modules.d/95rootfs-block/block-genrules.sh index a2310a0..1e6827a 100755 --- a/modules.d/95rootfs-block/block-genrules.sh +++ b/modules.d/95rootfs-block/block-genrules.sh @@ -13,5 +13,5 @@ if [ "${root%%:*}" = "block" ]; then printf '[ -e "%s" ] && { ln -s "%s" /dev/root 2>/dev/null; rm "$job"; }\n' \ "${root#block:}" "${root#block:}" > $hookdir/initqueue/settled/blocksymlink.sh - echo '[ -e /dev/root ]' > $hookdir/initqueue/finished/block.sh + wait_for_dev "${root#block:}" fi diff --git a/modules.d/99base/dracut-lib.sh b/modules.d/99base/dracut-lib.sh index 8d294ee..4dbddb1 100755 --- a/modules.d/99base/dracut-lib.sh +++ b/modules.d/99base/dracut-lib.sh @@ -261,7 +261,10 @@ source_hook() { check_finished() { local f - for f in $hookdir/initqueue/finished/*.sh; do { [ -e "$f" ] && ( . "$f" ) ; } || return 1 ; done + for f in $hookdir/initqueue/finished/*.sh; do + [ "$f" = "$hookdir/initqueue/finished/*.sh" ] && return 0 + { [ -e "$f" ] && ( . "$f" ) ; } || return 1 + done return 0 } @@ -560,3 +563,27 @@ usable_root() { done return 0 } + +wait_for_mount() +{ + local _name + _name="$(str_replace "$1" '/' '\\x2f')" + printf '. /lib/dracut-lib.sh\nismounted "%s"\n' $1 \ + >> "$hookdir/initqueue/finished/ismounted-${_name}.sh" + { + printf 'ismounted "%s" || ' $1 + printf 'warn "\"%s\" is not mounted"\n' $1 + } >> "$hookdir/emergency/90-${_name}.sh" +} + +wait_for_dev() +{ + local _name + _name="$(str_replace "$1" '/' '\\x2f')" + printf '[ -e "%s" ]\n' $1 \ + >> "$hookdir/initqueue/finished/devexists-${_name}.sh" + { + printf '[ -e "%s" ] || ' $1 + printf 'warn "\"%s\" does not exist"\n' $1 + } >> "$hookdir/emergency/80-${_name}.sh" +} -- 2.7.4