add wait_for_dev() and wait_for_mount()
authorHarald Hoyer <harald@redhat.com>
Mon, 7 Nov 2011 07:46:36 +0000 (08:46 +0100)
committerHarald Hoyer <harald@redhat.com>
Tue, 15 Nov 2011 08:47:16 +0000 (09:47 +0100)
modules.d/90btrfs/btrfs_finished.sh
modules.d/90dmsquash-live/dmsquash-live-genrules.sh
modules.d/90dmsquash-live/dmsquash-liveiso-genrules.sh
modules.d/90lvm/parse-lvm.sh
modules.d/95iscsi/parse-iscsiroot.sh
modules.d/95nbd/parse-nbdroot.sh
modules.d/95resume/resume-genrules.sh
modules.d/95rootfs-block/block-genrules.sh
modules.d/99base/dracut-lib.sh

index 3601279..b01db69 100755 (executable)
@@ -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
index aa0654b..b27fccc 100755 (executable)
@@ -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
index c05fbb9..30ea180 100755 (executable)
@@ -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
index b85a1ac..c1d00c6 100755 (executable)
@@ -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
 
index 50341b2..3187632 100755 (executable)
@@ -76,5 +76,3 @@ rootok=1
 # Shut up init error check
 [ -z "$root" ] && root="iscsi"
 
-echo '[ -e /dev/root ]' > $hookdir/initqueue/finished/iscsi.sh
-
index 376681b..e237668 100755 (executable)
@@ -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
 
index e1afc26..16df877 100755 (executable)
@@ -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
     {
index a2310a0..1e6827a 100755 (executable)
@@ -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
index 8d294ee..4dbddb1 100755 (executable)
@@ -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"
+}