public inbox for initramfs@vger.kernel.org
 help / color / mirror / Atom feed
From: Thomas Renninger <trenn-l3A5Bk7waGM@public.gmane.org>
To: harald-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org
Cc: initramfs-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	trenn-l3A5Bk7waGM@public.gmane.org,
	Hannes Reinecke <hare-l3A5Bk7waGM@public.gmane.org>
Subject: [PATCH 12/42] 95iscsi: generate commandline for software iscsi
Date: Thu, 11 Dec 2014 15:46:03 +0100	[thread overview]
Message-ID: <1418309193-11208-13-git-send-email-trenn@suse.de> (raw)
In-Reply-To: <1418309193-11208-1-git-send-email-trenn-l3A5Bk7waGM@public.gmane.org>

From: Hannes Reinecke <hare-l3A5Bk7waGM@public.gmane.org>

When installing on an software iscsi root we need to generate
the correct commandline, otherwise the system cannot boot.

References: bnc#880108
Patch: 0093

When using software iscsi we should be using the existing
configuration from the system for the time being.

References: bnc#884768
Patch: 0095

Avoid bad ip route call on empty address
Patch: 0143

Signed-off-by: Hannes Reinecke <hare-l3A5Bk7waGM@public.gmane.org>
Signed-off-by: Thomas Renninger <trenn-l3A5Bk7waGM@public.gmane.org>
---
 modules.d/95iscsi/module-setup.sh | 91 +++++++++++++++++++++++++++++++++++++--
 1 file changed, 88 insertions(+), 3 deletions(-)

diff --git a/modules.d/95iscsi/module-setup.sh b/modules.d/95iscsi/module-setup.sh
index 29bba82..cd6cb4b 100755
--- a/modules.d/95iscsi/module-setup.sh
+++ b/modules.d/95iscsi/module-setup.sh
@@ -67,6 +67,84 @@ install_ibft() {
     done
 }
 
+install_iscsiroot() {
+    local devpath=$1
+    local scsi_path iscsi_lun session c d conn
+    local iscsi_session iscsi_address iscsi_port iscsi_targetname iscsi_tpgt
+
+    scsi_path=${devpath%%/block*}
+    [ "$scsi_path" = "$devpath" ] && return 1
+    iscsi_lun=${scsi_path##*:}
+    [ "$iscsi_lun" = "$scsi_path" ] && return 1
+    session=${devpath%%/target*}
+    [ "$session" = "$devpath" ] && return 1
+    iscsi_session=${session##*/}
+    [ "$iscsi_session" = "$session" ] && return 1
+
+    for d in ${session}/* ; do
+        case $d in
+	    *connection*)
+	        c=${d##*/}
+	        conn=${d}/iscsi_connection/${c}
+	        if [ -d ${conn} ] ; then
+		    iscsi_address=$(cat ${conn}/persistent_address)
+		    iscsi_port=$(cat ${conn}/persistent_port)
+	        fi
+	        ;;
+	    *session)
+	        if [ -d ${d}/${iscsi_session} ] ; then
+                    iscsi_initiator=$(cat ${d}/${iscsi_session}/initiatorname)
+		    iscsi_targetname=$(cat ${d}/${iscsi_session}/targetname)
+	        fi
+	        ;;
+        esac
+    done
+
+    [ -z "$iscsi_address" ] && return
+    local_address=$(ip -o route get to $iscsi_address | sed -n 's/.*src \([0-9a-f.:]*\).*/\1/p')
+    ifname=$(ip -o route get to $iscsi_address | sed -n 's/.*dev \([^ ]*\).*/\1/p')
+    printf 'ip=%s:static ' ${ifname}
+
+    if [ -e /sys/class/net/$ifname/address ] ; then
+        ifmac=$(cat /sys/class/net/$ifname/address)
+        printf 'ifname=%s:%s ' ${ifname} ${ifmac}
+    fi
+
+    if [ -n "$iscsi_address" -a -n "$iscsi_targetname" ] ; then
+        if [ -n "$iscsi_port" -a "$iscsi_port" -eq 3260 ] ; then
+            iscsi_port=
+        fi
+        if [ -n "$iscsi_lun" -a "$iscsi_lun" -eq 0 ] ; then
+            iscsi_lun=
+        fi
+        # In IPv6 case rd.iscsi.initatior= must pass address in [] brackets
+        case "$iscsi_address" in
+            *:*)
+                iscsi_address="[$iscsi_address]"
+                ;;
+        esac
+        echo "rd.iscsi.initiator=${iscsi_initiator} netroot=iscsi:${iscsi_address}::${iscsi_port}:${iscsi_lun}:${iscsi_targetname}"
+    fi
+    return 0
+}
+
+
+install_softiscsi() {
+    [ -d /sys/firmware/ibft ] && return 0
+
+    is_softiscsi() {
+        local _dev=$1
+        local iscsi_dev
+
+        [[ -L "/sys/dev/block/$_dev" ]] || return
+        iscsi_dev=$(cd -P /sys/dev/block/$_dev; echo $PWD)
+        install_iscsiroot $iscsi_dev
+    }
+
+    for_each_host_dev_and_slaves_all is_softiscsi || return 255
+    return 0
+}
+
 # called by dracut
 depends() {
     echo network rootfs-block
@@ -117,7 +195,14 @@ installkernel() {
 
 # called by dracut
 cmdline() {
-    install_ibft
+    local _iscsiconf=$(install_ibft)
+    {
+        if [ "$_iscsiconf" ] ; then
+            echo ${_iscsiconf}
+        else
+            install_softiscsi
+        fi
+    } | sort | uniq
 }
 
 # called by dracut
@@ -128,8 +213,8 @@ install() {
 
     # Detect iBFT and perform mandatory steps
     if [[ $hostonly_cmdline == "yes" ]] ; then
-        local _ibftconf=$(install_ibft)
-        [[ $_ibftconf ]] && printf "%s\n" "$_ibftconf" >> "${initdir}/etc/cmdline.d/95iscsi.conf"
+        local _iscsiconf=$(cmdline)
+        [[ $_iscsiconf ]] && printf "%s\n" "$_iscsiconf" >> "${initdir}/etc/cmdline.d/95iscsi.conf"
     fi
 
     inst_hook cmdline 90 "$moddir/parse-iscsiroot.sh"
-- 
1.8.5.2

  parent reply	other threads:[~2014-12-11 14:46 UTC|newest]

Thread overview: 52+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-12-11 14:45 [RESEND] SUSE patches which should show up mainline Thomas Renninger
     [not found] ` <1418309193-11208-1-git-send-email-trenn-l3A5Bk7waGM@public.gmane.org>
2014-12-11 14:45   ` [PATCH 01/42] mkinitrd-suse: Update to sles12 SUSE state Thomas Renninger
2014-12-11 14:45   ` [PATCH 02/42] systemd always tries to load autofs4 Thomas Renninger
2014-12-11 14:45   ` [PATCH 03/42] Fixup mdraid setup Thomas Renninger
2014-12-11 14:45   ` [PATCH 04/42] 95udev-rules: Include correct sg3_utils rules Thomas Renninger
     [not found]     ` <1418309193-11208-5-git-send-email-trenn-l3A5Bk7waGM@public.gmane.org>
2014-12-17 10:00       ` Harald Hoyer
2014-12-11 14:45   ` [PATCH 05/42] 90multipath: install correct multipath rules Thomas Renninger
2014-12-11 14:45   ` [PATCH 06/42] 95iscsi: Autodetect iSCSI firmware Thomas Renninger
2014-12-11 14:45   ` [PATCH 07/42] 95iscsi: Install libgcc_s library Thomas Renninger
2014-12-11 14:45   ` [PATCH 08/42] 95iscsi: Set correct iscsi_started value for iSCSI firmware Thomas Renninger
2014-12-11 14:46   ` [PATCH 09/42] 95iscsi: strip one set of quotes when calling initqueue Thomas Renninger
2014-12-11 14:46   ` [PATCH 10/42] 95iscsi: Fixup bnx2i offload booting Thomas Renninger
2014-12-11 14:46   ` [PATCH 11/42] 95iscsi: More empty cmdline fixes Thomas Renninger
2014-12-11 14:46   ` Thomas Renninger [this message]
2014-12-11 14:46   ` [PATCH 13/42] iscsi: iscsi.initiator and others can and must only show up once Thomas Renninger
2014-12-11 14:46   ` [PATCH 14/42] Implement 'rd.timeout' to modify the device timeout Thomas Renninger
2014-12-11 14:46   ` [PATCH 15/42] Do not call 'lvm' for non-LVM device-mapper devices Thomas Renninger
2014-12-11 14:46   ` [PATCH 16/42] Print stored dracut commandline during initramfs build Thomas Renninger
2014-12-11 14:46   ` [PATCH 17/42] Align dev_unit_name() with systemd's function Thomas Renninger
     [not found]     ` <1418309193-11208-18-git-send-email-trenn-l3A5Bk7waGM@public.gmane.org>
2015-02-24  9:37       ` Alexander Tsoy
2014-12-11 14:46   ` [PATCH 18/42] Generate fallback mount unit for root filesystem Thomas Renninger
2014-12-11 14:46   ` [PATCH 19/42] 99base: warn on invalid command for initqueue Thomas Renninger
2014-12-11 14:46   ` [PATCH 20/42] Handle module alias properly Thomas Renninger
2014-12-11 14:46   ` [PATCH 21/42] 99base: Increase initqueue timeout in non systemd case Thomas Renninger
2014-12-11 14:46   ` [PATCH 22/42] 90lvm: Install dm-snapshot module Thomas Renninger
2014-12-11 14:46   ` [PATCH 23/42] Check for logfile (--logfile option) and create it if necessary Thomas Renninger
2014-12-11 14:46   ` [PATCH 24/42] dracut.sh: Avoid duplicate devices in host_devs Thomas Renninger
2014-12-11 14:46   ` [PATCH 25/42] dracut.sh: Fix UUID= fstab parsing in case --mount option is passed Thomas Renninger
2014-12-11 14:46   ` [PATCH 26/42] dracut.usage.asc: Remove distro specific help from manpage Thomas Renninger
2014-12-11 14:46   ` [PATCH 27/42] nfs: Add ip=... and root=nfs... parameters to internal dracut Thomas Renninger
2014-12-11 14:46   ` [PATCH 28/42] 95iscsi: parse output from iscsiadm correctly Thomas Renninger
2014-12-11 14:46   ` [PATCH 29/42] dracut: Do not stop installing drivers if one fails Thomas Renninger
2014-12-11 14:46   ` [PATCH 30/42] 95fcoe: update fcoe interface check Thomas Renninger
2014-12-11 14:46   ` [PATCH 31/42] 95fcoe: Store current configuration in dracut cmdline Thomas Renninger
     [not found]     ` <1418309193-11208-32-git-send-email-trenn-l3A5Bk7waGM@public.gmane.org>
2014-12-12  3:02       ` Baoquan He
     [not found]         ` <20141212030201.GD1678-je1gSBvt1Tcx0jIIkfS+Ph/sF2h8X+2i0E9HWUfgJXw@public.gmane.org>
2014-12-12 14:05           ` Hannes Reinecke
2014-12-11 14:46   ` [PATCH 32/42] 95fcoe: skip VLAN devices in fcoe-up Thomas Renninger
2014-12-11 14:46   ` [PATCH 33/42] 95fcoe: start lldpad separately Thomas Renninger
2014-12-11 14:46   ` [PATCH 34/42] Enhance suse.conf and debug module example with SUSE-specific settings Thomas Renninger
2014-12-11 14:46   ` [PATCH 35/42] 40network: add missing _arch variable declaration Thomas Renninger
2014-12-11 14:46   ` [PATCH 36/42] 99base: Add chown binary Thomas Renninger
2014-12-11 14:46   ` [PATCH 37/42] 90kernel-modules: install scsi_dh_alua Thomas Renninger
2014-12-11 14:46   ` [PATCH 38/42] Fix non-export of journal dev boot options Thomas Renninger
2014-12-11 14:46   ` [PATCH 39/42] Also export root= boot param for hostonly-cmdline case Thomas Renninger
2014-12-11 14:46   ` [PATCH 40/42] Don't create lots of empty cmdline files " Thomas Renninger
2014-12-11 14:46   ` [PATCH 41/42] 95rootfs-block: Correctly terminate commandline parameter Thomas Renninger
     [not found]     ` <1418309193-11208-42-git-send-email-trenn-l3A5Bk7waGM@public.gmane.org>
2014-12-17 10:44       ` Harald Hoyer
     [not found]         ` <54915E9C.2050306-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2014-12-17 10:57           ` Hannes Reinecke
     [not found]             ` <54916198.1060206-l3A5Bk7waGM@public.gmane.org>
2014-12-17 12:21               ` Harald Hoyer
2014-12-11 14:46   ` [PATCH 42/42] dracut: nbd: Only complain of missing binary in hostonly mode if Thomas Renninger
2014-12-17 10:26   ` [RESEND] SUSE patches which should show up mainline Harald Hoyer
     [not found]     ` <54915A3C.9050409-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2014-12-17 11:34       ` Thomas Renninger

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1418309193-11208-13-git-send-email-trenn@suse.de \
    --to=trenn-l3a5bk7wagm@public.gmane.org \
    --cc=harald-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org \
    --cc=hare-l3A5Bk7waGM@public.gmane.org \
    --cc=initramfs-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox