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