Blame 0042-95iscsi-generate-commandline-for-software-iscsi.patch

Harald Hoyer b94732
From c4d8793c67cb75804dfb8b14985e125a22f212eb Mon Sep 17 00:00:00 2001
Harald Hoyer b94732
From: Hannes Reinecke <hare@suse.de>
Harald Hoyer b94732
Date: Thu, 11 Dec 2014 15:46:03 +0100
Harald Hoyer b94732
Subject: [PATCH] 95iscsi: generate commandline for software iscsi
Harald Hoyer b94732
Harald Hoyer b94732
When installing on an software iscsi root we need to generate
Harald Hoyer b94732
the correct commandline, otherwise the system cannot boot.
Harald Hoyer b94732
Harald Hoyer b94732
References: bnc#880108
Harald Hoyer b94732
Patch: 0093
Harald Hoyer b94732
Harald Hoyer b94732
When using software iscsi we should be using the existing
Harald Hoyer b94732
configuration from the system for the time being.
Harald Hoyer b94732
Harald Hoyer b94732
References: bnc#884768
Harald Hoyer b94732
Patch: 0095
Harald Hoyer b94732
Harald Hoyer b94732
Avoid bad ip route call on empty address
Harald Hoyer b94732
Patch: 0143
Harald Hoyer b94732
Harald Hoyer b94732
Signed-off-by: Hannes Reinecke <hare@suse.de>
Harald Hoyer b94732
Signed-off-by: Thomas Renninger <trenn@suse.de>
Harald Hoyer b94732
---
Harald Hoyer b94732
 modules.d/95iscsi/module-setup.sh | 91 +++++++++++++++++++++++++++++++++++++--
Harald Hoyer b94732
 1 file changed, 88 insertions(+), 3 deletions(-)
Harald Hoyer b94732
Harald Hoyer b94732
diff --git a/modules.d/95iscsi/module-setup.sh b/modules.d/95iscsi/module-setup.sh
Harald Hoyer b94732
index 29bba82..cd6cb4b 100755
Harald Hoyer b94732
--- a/modules.d/95iscsi/module-setup.sh
Harald Hoyer b94732
+++ b/modules.d/95iscsi/module-setup.sh
Harald Hoyer b94732
@@ -67,6 +67,84 @@ install_ibft() {
Harald Hoyer b94732
     done
Harald Hoyer b94732
 }
Harald Hoyer b94732
 
Harald Hoyer b94732
+install_iscsiroot() {
Harald Hoyer b94732
+    local devpath=$1
Harald Hoyer b94732
+    local scsi_path iscsi_lun session c d conn
Harald Hoyer b94732
+    local iscsi_session iscsi_address iscsi_port iscsi_targetname iscsi_tpgt
Harald Hoyer b94732
+
Harald Hoyer b94732
+    scsi_path=${devpath%%/block*}
Harald Hoyer b94732
+    [ "$scsi_path" = "$devpath" ] && return 1
Harald Hoyer b94732
+    iscsi_lun=${scsi_path##*:}
Harald Hoyer b94732
+    [ "$iscsi_lun" = "$scsi_path" ] && return 1
Harald Hoyer b94732
+    session=${devpath%%/target*}
Harald Hoyer b94732
+    [ "$session" = "$devpath" ] && return 1
Harald Hoyer b94732
+    iscsi_session=${session##*/}
Harald Hoyer b94732
+    [ "$iscsi_session" = "$session" ] && return 1
Harald Hoyer b94732
+
Harald Hoyer b94732
+    for d in ${session}/* ; do
Harald Hoyer b94732
+        case $d in
Harald Hoyer b94732
+	    *connection*)
Harald Hoyer b94732
+	        c=${d##*/}
Harald Hoyer b94732
+	        conn=${d}/iscsi_connection/${c}
Harald Hoyer b94732
+	        if [ -d ${conn} ] ; then
Harald Hoyer b94732
+		    iscsi_address=$(cat ${conn}/persistent_address)
Harald Hoyer b94732
+		    iscsi_port=$(cat ${conn}/persistent_port)
Harald Hoyer b94732
+	        fi
Harald Hoyer b94732
+	        ;;
Harald Hoyer b94732
+	    *session)
Harald Hoyer b94732
+	        if [ -d ${d}/${iscsi_session} ] ; then
Harald Hoyer b94732
+                    iscsi_initiator=$(cat ${d}/${iscsi_session}/initiatorname)
Harald Hoyer b94732
+		    iscsi_targetname=$(cat ${d}/${iscsi_session}/targetname)
Harald Hoyer b94732
+	        fi
Harald Hoyer b94732
+	        ;;
Harald Hoyer b94732
+        esac
Harald Hoyer b94732
+    done
Harald Hoyer b94732
+
Harald Hoyer b94732
+    [ -z "$iscsi_address" ] && return
Harald Hoyer b94732
+    local_address=$(ip -o route get to $iscsi_address | sed -n 's/.*src \([0-9a-f.:]*\).*/\1/p')
Harald Hoyer b94732
+    ifname=$(ip -o route get to $iscsi_address | sed -n 's/.*dev \([^ ]*\).*/\1/p')
Harald Hoyer b94732
+    printf 'ip=%s:static ' ${ifname}
Harald Hoyer b94732
+
Harald Hoyer b94732
+    if [ -e /sys/class/net/$ifname/address ] ; then
Harald Hoyer b94732
+        ifmac=$(cat /sys/class/net/$ifname/address)
Harald Hoyer b94732
+        printf 'ifname=%s:%s ' ${ifname} ${ifmac}
Harald Hoyer b94732
+    fi
Harald Hoyer b94732
+
Harald Hoyer b94732
+    if [ -n "$iscsi_address" -a -n "$iscsi_targetname" ] ; then
Harald Hoyer b94732
+        if [ -n "$iscsi_port" -a "$iscsi_port" -eq 3260 ] ; then
Harald Hoyer b94732
+            iscsi_port=
Harald Hoyer b94732
+        fi
Harald Hoyer b94732
+        if [ -n "$iscsi_lun" -a "$iscsi_lun" -eq 0 ] ; then
Harald Hoyer b94732
+            iscsi_lun=
Harald Hoyer b94732
+        fi
Harald Hoyer b94732
+        # In IPv6 case rd.iscsi.initatior= must pass address in [] brackets
Harald Hoyer b94732
+        case "$iscsi_address" in
Harald Hoyer b94732
+            *:*)
Harald Hoyer b94732
+                iscsi_address="[$iscsi_address]"
Harald Hoyer b94732
+                ;;
Harald Hoyer b94732
+        esac
Harald Hoyer b94732
+        echo "rd.iscsi.initiator=${iscsi_initiator} netroot=iscsi:${iscsi_address}::${iscsi_port}:${iscsi_lun}:${iscsi_targetname}"
Harald Hoyer b94732
+    fi
Harald Hoyer b94732
+    return 0
Harald Hoyer b94732
+}
Harald Hoyer b94732
+
Harald Hoyer b94732
+
Harald Hoyer b94732
+install_softiscsi() {
Harald Hoyer b94732
+    [ -d /sys/firmware/ibft ] && return 0
Harald Hoyer b94732
+
Harald Hoyer b94732
+    is_softiscsi() {
Harald Hoyer b94732
+        local _dev=$1
Harald Hoyer b94732
+        local iscsi_dev
Harald Hoyer b94732
+
Harald Hoyer b94732
+        [[ -L "/sys/dev/block/$_dev" ]] || return
Harald Hoyer b94732
+        iscsi_dev=$(cd -P /sys/dev/block/$_dev; echo $PWD)
Harald Hoyer b94732
+        install_iscsiroot $iscsi_dev
Harald Hoyer b94732
+    }
Harald Hoyer b94732
+
Harald Hoyer b94732
+    for_each_host_dev_and_slaves_all is_softiscsi || return 255
Harald Hoyer b94732
+    return 0
Harald Hoyer b94732
+}
Harald Hoyer b94732
+
Harald Hoyer b94732
 # called by dracut
Harald Hoyer b94732
 depends() {
Harald Hoyer b94732
     echo network rootfs-block
Harald Hoyer b94732
@@ -117,7 +195,14 @@ installkernel() {
Harald Hoyer b94732
 
Harald Hoyer b94732
 # called by dracut
Harald Hoyer b94732
 cmdline() {
Harald Hoyer b94732
-    install_ibft
Harald Hoyer b94732
+    local _iscsiconf=$(install_ibft)
Harald Hoyer b94732
+    {
Harald Hoyer b94732
+        if [ "$_iscsiconf" ] ; then
Harald Hoyer b94732
+            echo ${_iscsiconf}
Harald Hoyer b94732
+        else
Harald Hoyer b94732
+            install_softiscsi
Harald Hoyer b94732
+        fi
Harald Hoyer b94732
+    } | sort | uniq
Harald Hoyer b94732
 }
Harald Hoyer b94732
 
Harald Hoyer b94732
 # called by dracut
Harald Hoyer b94732
@@ -128,8 +213,8 @@ install() {
Harald Hoyer b94732
 
Harald Hoyer b94732
     # Detect iBFT and perform mandatory steps
Harald Hoyer b94732
     if [[ $hostonly_cmdline == "yes" ]] ; then
Harald Hoyer b94732
-        local _ibftconf=$(install_ibft)
Harald Hoyer b94732
-        [[ $_ibftconf ]] && printf "%s\n" "$_ibftconf" >> "${initdir}/etc/cmdline.d/95iscsi.conf"
Harald Hoyer b94732
+        local _iscsiconf=$(cmdline)
Harald Hoyer b94732
+        [[ $_iscsiconf ]] && printf "%s\n" "$_iscsiconf" >> "${initdir}/etc/cmdline.d/95iscsi.conf"
Harald Hoyer b94732
     fi
Harald Hoyer b94732
 
Harald Hoyer b94732
     inst_hook cmdline 90 "$moddir/parse-iscsiroot.sh"