Blame 0054-dracut.sh-Avoid-duplicate-devices-in-host_devs.patch

Harald Hoyer b94732
From 118ca9ecfcc8cec0a428352355592717d0a44109 Mon Sep 17 00:00:00 2001
Harald Hoyer b94732
From: Thomas Renninger <trenn@suse.de>
Harald Hoyer b94732
Date: Thu, 11 Dec 2014 15:46:15 +0100
Harald Hoyer b94732
Subject: [PATCH] dracut.sh: Avoid duplicate devices in host_devs
Harald Hoyer b94732
Harald Hoyer b94732
Signed-off-by: Thomas Renninger <trenn@suse.de>
Harald Hoyer b94732
---
Harald Hoyer b94732
 dracut.sh | 26 ++++++++++++++++++--------
Harald Hoyer b94732
 1 file changed, 18 insertions(+), 8 deletions(-)
Harald Hoyer b94732
Harald Hoyer b94732
diff --git a/dracut.sh b/dracut.sh
Harald Hoyer b94732
index 79f36b6..a4c7ce5 100755
Harald Hoyer b94732
--- a/dracut.sh
Harald Hoyer b94732
+++ b/dracut.sh
Harald Hoyer b94732
@@ -219,6 +219,16 @@ push() {
Harald Hoyer b94732
     done
Harald Hoyer b94732
 }
Harald Hoyer b94732
 
Harald Hoyer b94732
+# Fills up host_devs stack variable and makes sure there are no duplicates
Harald Hoyer b94732
+push_host_devs() {
Harald Hoyer b94732
+    local _dev
Harald Hoyer b94732
+    for _dev in ${host_devs[@]}; do
Harald Hoyer b94732
+        [ "$_dev" = "$1" ] && return
Harald Hoyer b94732
+    done
Harald Hoyer b94732
+    push host_devs "$1"
Harald Hoyer b94732
+}
Harald Hoyer b94732
+
Harald Hoyer b94732
+
Harald Hoyer b94732
 # function pop()
Harald Hoyer b94732
 # pops the last value from a stack
Harald Hoyer b94732
 # assigns value to second argument variable
Harald Hoyer b94732
@@ -1062,25 +1072,25 @@ declare -A host_fs_types
Harald Hoyer b94732
 for line in "${fstab_lines[@]}"; do
Harald Hoyer b94732
     set -- $line
Harald Hoyer b94732
     #dev mp fs fsopts
Harald Hoyer b94732
-    push host_devs "$1"
Harald Hoyer b94732
+    push_host_devs "$1"
Harald Hoyer b94732
     host_fs_types["$1"]="$3"
Harald Hoyer b94732
 done
Harald Hoyer b94732
 
Harald Hoyer b94732
 for f in $add_fstab; do
Harald Hoyer b94732
     [[ -e $f ]] || continue
Harald Hoyer b94732
     while read dev rest; do
Harald Hoyer b94732
-        push host_devs "$dev"
Harald Hoyer b94732
+        push_host_devs "$dev"
Harald Hoyer b94732
     done < "$f"
Harald Hoyer b94732
 done
Harald Hoyer b94732
 
Harald Hoyer b94732
 for dev in $add_device; do
Harald Hoyer b94732
-    push host_devs "$dev"
Harald Hoyer b94732
+    push_host_devs "$dev"
Harald Hoyer b94732
 done
Harald Hoyer b94732
 
Harald Hoyer b94732
 if (( ${#add_device_l[@]} )); then
Harald Hoyer b94732
     while pop add_device_l val; do
Harald Hoyer b94732
         add_device+=" $val "
Harald Hoyer b94732
-        push host_devs "$val"
Harald Hoyer b94732
+        push_host_devs "$val"
Harald Hoyer b94732
     done
Harald Hoyer b94732
 fi
Harald Hoyer b94732
 
Harald Hoyer b94732
@@ -1109,9 +1119,9 @@ if [[ $hostonly ]]; then
Harald Hoyer b94732
         _dev=$(find_block_device "$mp")
Harald Hoyer b94732
         _bdev=$(readlink -f "/dev/block/$_dev")
Harald Hoyer b94732
         [[ -b $_bdev ]] && _dev=$_bdev
Harald Hoyer b94732
-        push host_devs $_dev
Harald Hoyer b94732
+        push_host_devs $_dev
Harald Hoyer b94732
         [[ "$mp" == "/" ]] && root_dev="$_dev"
Harald Hoyer b94732
-        push host_devs "$_dev"
Harald Hoyer b94732
+        push_host_devs "$_dev"
Harald Hoyer b94732
     done
Harald Hoyer b94732
 
Harald Hoyer b94732
     if [[ -f /proc/swaps ]] && [[ -f /etc/fstab ]]; then
Harald Hoyer b94732
@@ -1140,7 +1150,7 @@ if [[ $hostonly ]]; then
Harald Hoyer b94732
                     done < /etc/crypttab
Harald Hoyer b94732
                 fi
Harald Hoyer b94732
 
Harald Hoyer b94732
-                push host_devs "$(readlink -f "$dev")"
Harald Hoyer b94732
+                push_host_devs "$(readlink -f "$dev")"
Harald Hoyer b94732
                 break
Harald Hoyer b94732
             done < /etc/fstab
Harald Hoyer b94732
         done < /proc/swaps
Harald Hoyer b94732
@@ -1205,7 +1215,7 @@ for dev in "${!host_fs_types[@]}"; do
Harald Hoyer b94732
     fi
Harald Hoyer b94732
     if [[ $journaldev ]]; then
Harald Hoyer b94732
         dev="$(readlink -f "$dev")"
Harald Hoyer b94732
-        push host_devs "$dev"
Harald Hoyer b94732
+        push_host_devs "$dev"
Harald Hoyer b94732
         _get_fs_type "$dev"
Harald Hoyer b94732
         check_block_and_slaves_all _get_fs_type "$(get_maj_min "$dev")"
Harald Hoyer b94732
     fi