18971c
From 20700e3dea3c10aa2c9d4a724ec3d671455d556f Mon Sep 17 00:00:00 2001
18971c
From: Harald Hoyer <harald@redhat.com>
18971c
Date: Mon, 12 Jan 2015 14:06:10 +0100
18971c
Subject: [PATCH] net-lib.sh:parse_iscsi_root() fix target parsing
18971c
18971c
For targets with colons in the iSCSI target name:
18971c
  "iqn.2000-09.com.foo:storage-system.e2000:00000001cm1p1"
18971c
18971c
the parser was confused with the optional iscsi_iface_name and
18971c
iscsi_netdev_name.
18971c
18971c
This patch reintroduces the old IQN, EUI and NAA parsing and enhances
18971c
the fallback parser by checking the LUN for a numerical value.
18971c
18971c
(cherry picked from commit 36e8ce4fb01824b49697bd0e7ad3ca3c4cfd4297)
18971c
---
18971c
 modules.d/40network/net-lib.sh | 50 ++++++++++++++++++++++++++--------
18971c
 1 file changed, 38 insertions(+), 12 deletions(-)
18971c
18971c
diff --git a/modules.d/40network/net-lib.sh b/modules.d/40network/net-lib.sh
18971c
index 337817e3..f0850207 100755
18971c
--- a/modules.d/40network/net-lib.sh
18971c
+++ b/modules.d/40network/net-lib.sh
18971c
@@ -310,6 +310,23 @@ parse_iscsi_root()
18971c
             ;;
18971c
     esac
18971c
 
18971c
+    unset iscsi_target_name
18971c
+    # extract target name
18971c
+    case "$v" in
18971c
+        *:iqn.*)
18971c
+            iscsi_target_name=iqn.${v##*:iqn.}
18971c
+            v=${v%:iqn.*}:
18971c
+            ;;
18971c
+        *:eui.*)
18971c
+            iscsi_target_name=iqn.${v##*:eui.}
18971c
+            v=${v%:iqn.*}:
18971c
+            ;;
18971c
+        *:naa.*)
18971c
+            iscsi_target_name=iqn.${v##*:naa.}
18971c
+            v=${v%:iqn.*}:
18971c
+            ;;
18971c
+    esac
18971c
+
18971c
     # parse the rest
18971c
     OLDIFS="$IFS"
18971c
     IFS=:
18971c
@@ -319,24 +336,33 @@ parse_iscsi_root()
18971c
     iscsi_protocol=$1; shift # ignored
18971c
     iscsi_target_port=$1; shift
18971c
 
18971c
-    if [ $# -gt 3 ] && [ -n "$1$2" ]; then
18971c
-        iscsi_iface_name=$1; shift
18971c
-        iscsi_netdev_name=$1; shift
18971c
+    if [ -n "$iscsi_target_name" ]; then
18971c
+        if [ $# -eq 3 ]; then
18971c
+            iscsi_iface_name=$1; shift
18971c
+        fi
18971c
+        if [ $# -eq 2 ]; then
18971c
+            iscsi_netdev_name=$1; shift
18971c
+        fi
18971c
+        iscsi_lun=$1; shift
18971c
+        if [ $# -ne 0 ]; then
18971c
+            warn "Invalid parameter in iscsi: parameter!"
18971c
+            return 1
18971c
+        fi
18971c
+        return 0
18971c
     fi
18971c
 
18971c
-    iscsi_lun=$1; shift
18971c
 
18971c
-    if [ $# -gt 2 ]; then
18971c
-        warn "Invalid parameter in iscsi: parameter!"
18971c
-        return 1
18971c
+    if [ $# -gt 3 ] && [ -n "$1$2" ]; then
18971c
+        if [ -z "$3" ] || [ "$3" -ge 0 ]  2>/dev/null ; then
18971c
+            iscsi_iface_name=$1; shift
18971c
+            iscsi_netdev_name=$1; shift
18971c
+        fi
18971c
     fi
18971c
 
18971c
-    if [ $# -eq 2 ]; then
18971c
-        iscsi_target_name="$1:$2"
18971c
-    else
18971c
-        iscsi_target_name="$1"
18971c
-    fi
18971c
+    iscsi_lun=$1; shift
18971c
 
18971c
+    iscsi_target_name=$(printf "%s:" "$@")
18971c
+    iscsi_target_name=${iscsi_target_name%:}
18971c
 }
18971c
 
18971c
 ip_to_var() {