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