3888c9
From 261d278332e0af85a0311a75d7b81c6cf35e4816 Mon Sep 17 00:00:00 2001
3888c9
From: Martin Wilck <mwilck@suse.de>
3888c9
Date: Thu, 4 Apr 2019 16:16:40 +0200
3888c9
Subject: [PATCH] iscsiroot: try targets only once
3888c9
3888c9
In multipath scenarios, "iscsiadm -m node" may contain
3888c9
several records with the same target.
3888c9
There's no point in trying "iscsiadm --login" multiple
3888c9
time for the same target, through the same portal.
3888c9
3888c9
Moreover, warn if the desired target is not on the node
3888c9
list.
3888c9
---
3888c9
 modules.d/95iscsi/iscsiroot.sh | 8 +++++++-
3888c9
 1 file changed, 7 insertions(+), 1 deletion(-)
3888c9
3888c9
diff --git a/modules.d/95iscsi/iscsiroot.sh b/modules.d/95iscsi/iscsiroot.sh
3888c9
index a334b76e..e8e0b4b8 100755
3888c9
--- a/modules.d/95iscsi/iscsiroot.sh
3888c9
+++ b/modules.d/95iscsi/iscsiroot.sh
3888c9
@@ -87,7 +87,7 @@ handle_netroot()
3888c9
     local iscsi_in_username iscsi_in_password
3888c9
     local iscsi_iface_name iscsi_netdev_name
3888c9
     local iscsi_param param
3888c9
-    local p
3888c9
+    local p found
3888c9
 
3888c9
     # override conf settings by command line options
3888c9
     arg=$(getarg rd.iscsi.initiator -d iscsi_initiator=)
3888c9
@@ -213,6 +213,7 @@ handle_netroot()
3888c9
     targets=$(iscsiadm -m discovery -t st -p $iscsi_target_ip:${iscsi_target_port:+$iscsi_target_port} | sed 's/^.*iqn/iqn/')
3888c9
     [ -z "$targets" ] && echo "Target discovery to $iscsi_target_ip:${iscsi_target_port:+$iscsi_target_port} failed with status $?" && exit 1
3888c9
 
3888c9
+    found=
3888c9
     for target in $targets; do
3888c9
         if [ "$target" = "$iscsi_target_name" ]; then
3888c9
             if [ -n "$iscsi_iface_name" ]; then
3888c9
@@ -237,11 +238,16 @@ handle_netroot()
3888c9
             if [ "$netif" != "timeout" ]; then
3888c9
                 $CMD --login
3888c9
             fi
3888c9
+            found=yes
3888c9
+            break
3888c9
         fi
3888c9
     done
3888c9
 
3888c9
     if [ "$netif" = "timeout" ]; then
3888c9
         iscsiadm -m node -L onboot || :
3888c9
+    elif [ "$found" != yes ]; then
3888c9
+        warn "iSCSI target \"$iscsi_target_name\" not found on portal $iscsi_target_ip:$iscsi_target_port"
3888c9
+        return 1
3888c9
     fi
3888c9
     > $hookdir/initqueue/work
3888c9
 
3888c9