Blob Blame History Raw
From 6c7c8d8a071694efd0c7e450fa78e71224a8ced4 Mon Sep 17 00:00:00 2001
From: Harald Hoyer <harald@redhat.com>
Date: Wed, 22 Jan 2014 17:05:22 +0100
Subject: [PATCH] iscsi: more iscsiroot fixes

handle iscsiroot with firmware more gracefully
---
 modules.d/95iscsi/iscsiroot.sh       | 68 +++++++++++++++++++++++++-----------
 modules.d/95iscsi/parse-iscsiroot.sh |  6 ++--
 2 files changed, 50 insertions(+), 24 deletions(-)

diff --git a/modules.d/95iscsi/iscsiroot.sh b/modules.d/95iscsi/iscsiroot.sh
index 156003c..6868710 100755
--- a/modules.d/95iscsi/iscsiroot.sh
+++ b/modules.d/95iscsi/iscsiroot.sh
@@ -31,36 +31,45 @@ iroot="$2"
 # If it's not iscsi we don't continue
 [ "${iroot%%:*}" = "iscsi" ] || exit 1
 
-iroot=${iroot#iscsi:}
+iroot=${iroot#iscsi}
+iroot=${iroot#:}
 
 # XXX modprobe crc32c should go in the cmdline parser, but I haven't yet
 # figured out a way how to check whether this is built-in or not
 modprobe crc32c 2>/dev/null
 
-[ -e /sys/module/bnx2i ] && iscsiuio
-
-if getargbool 0 rd.iscsi.firmware -d -y iscsi_firmware ; then
-    for p in $(getargs rd.iscsi.param -d iscsi_param); do
-	iscsi_param="$iscsi_param --param $p"
-    done
+if [ -e /sys/module/bnx2i ] && ! [ -e /tmp/iscsiuio-started ]; then
+        iscsiuio
+        > /tmp/iscsiuio-started
+fi
 
+handle_firmware()
+{
     if ! [ -e /tmp/iscsistarted-firmware ]; then
-        if ! iscsistart -f | vinfo; then
+        if ! iscsistart -f; then
             warn "iscistart: Could not get list of targets from firmware."
-            exit 1
+            return 1
         fi
 
-        if ! iscsistart -b $iscsi_param 2>&1 | vinfo; then
+        for p in $(getargs rd.iscsi.param -d iscsi_param); do
+	    iscsi_param="$iscsi_param --param $p"
+        done
+
+        if ! iscsistart -b $iscsi_param; then
             warn "\`iscsistart -b $iscsi_param\ยด failed"
-            exit 1
         fi
-        echo 'started' > "/tmp/iscsistarted-iscsi"
-        echo 'started' > "/tmp/iscsistarted-firmware"
+
+        if [ -d /sys/class/iscsi_session ]; then
+            echo 'started' > "/tmp/iscsistarted-iscsi"
+            echo 'started' > "/tmp/iscsistarted-firmware"
+        else
+            return 1
+        fi
+
         need_shutdown
     fi
-
-    [ "$netif" = dummy ] && exit 0
-fi
+    return 0
+}
 
 
 handle_netroot()
@@ -171,21 +180,38 @@ handle_netroot()
 
     netroot_enc=$(str_replace "$1" '/' '\2f')
     echo 'started' > "/tmp/iscsistarted-iscsi:${netroot_enc}"
-
 }
 
+ret=0
+
 # loop over all netroot parameter
 if getarg netroot; then
     for nroot in $(getargs netroot); do
-        [ "${netroot%%:*}" = "iscsi" ] || continue
-        handle_netroot ${nroot##iscsi:}
+        [ "${nroot%%:*}" = "iscsi" ] || continue
+        nroot="${nroot##iscsi:}"
+        if [ -n "$nroot" ]; then
+            handle_netroot "$nroot"
+            ret=$(($ret + $?))
+        fi
     done
+    if getargbool 0 rd.iscsi.firmware -d -y iscsi_firmware ; then
+        handle_firmware
+        ret=$(($ret + $?))
+    fi
 else
-    handle_netroot $iroot
+    if [ -n "$iroot" ]; then
+        handle_netroot "$iroot"
+        ret=$?
+    else
+        if getargbool 0 rd.iscsi.firmware -d -y iscsi_firmware ; then
+            handle_firmware
+            ret=$?
+        fi
+    fi
 fi
 
 need_shutdown
 
 # now we have a root filesystem somewhere in /dev/sda*
 # let the normal block handler handle root=
-exit 0
+exit $ret
diff --git a/modules.d/95iscsi/parse-iscsiroot.sh b/modules.d/95iscsi/parse-iscsiroot.sh
index e463add..4be9d56 100755
--- a/modules.d/95iscsi/parse-iscsiroot.sh
+++ b/modules.d/95iscsi/parse-iscsiroot.sh
@@ -61,10 +61,10 @@ fi
 
 # iscsi_firmware does not need argument checking
 if [ -n "$iscsi_firmware" ] ; then
-    netroot=${netroot:-iscsi}
+    netroot=${netroot:-iscsi:}
     modprobe -q iscsi_boot_sysfs 2>/dev/null
     modprobe -q iscsi_ibft
-    initqueue --settled /sbin/iscsiroot dummy "$netroot" "$NEWROOT"
+    initqueue --onetime --timeout "/sbin/iscsiroot dummy '$netroot' '$NEWROOT'"
 fi
 
 # If it's not iscsi we don't continue
@@ -88,7 +88,7 @@ fi
 
 if [ -n "$netroot" ] && [ "$root" != "/dev/root" ] && [ "$root" != "dhcp" ]; then
     if ! getargbool 1 rd.neednet >/dev/null || ! getarg "ip="; then
-        initqueue --onetime --settled /sbin/iscsiroot dummy "$netroot" "$NEWROOT"
+        initqueue --onetime --settled "/sbin/iscsiroot dummy '$netroot' '$NEWROOT'"
     fi
 fi