Harald Hoyer d9da66
From 28a68f1f3ce15b40d45e6987ab0997584d4fa901 Mon Sep 17 00:00:00 2001
Harald Hoyer d9da66
From: Harald Hoyer <harald@redhat.com>
Harald Hoyer d9da66
Date: Fri, 12 Jan 2018 10:24:20 +0100
Harald Hoyer d9da66
Subject: [PATCH] iSCSI: no more iscsid
Harald Hoyer d9da66
Harald Hoyer d9da66
According to Cathy Zhou <Cathy.Zhou@Oracle.COM>:
Harald Hoyer d9da66
Harald Hoyer d9da66
"iscsistart is not designed to be working together with iscsid. When an
Harald Hoyer d9da66
interface gets the dhcp offer successfully, the iscsiroot script is run
Harald Hoyer d9da66
which starts the iscsistart service to establish the iSCSI session. With
Harald Hoyer d9da66
the existence of iscsid, the iscsistart service's attempt to setup its
Harald Hoyer d9da66
own mgmt ipc fails. Instead, the request to login to the iscsi target
Harald Hoyer d9da66
is handled by the mgmt ipc of iscsid. After iscsistart finishes its
Harald Hoyer d9da66
login attempt, it eventually sends a stop_event_loop request to stop
Harald Hoyer d9da66
the mgmt process. As the result, it terminates iscsid."
Harald Hoyer d9da66
Harald Hoyer d9da66
So, iscsid is kicked out again.
Harald Hoyer d9da66
Harald Hoyer d9da66
Additionally iscsistart-flocked is used to make sure iscsistart is not
Harald Hoyer d9da66
run in parallel.
Harald Hoyer d9da66
---
Harald Hoyer d9da66
 modules.d/95iscsi/cleanup-iscsi.sh      |  2 +-
Harald Hoyer d9da66
 modules.d/95iscsi/iscsiroot.sh          | 25 +++++--------------------
Harald Hoyer d9da66
 modules.d/95iscsi/iscsistart-flocked.sh |  5 +++++
Harald Hoyer d9da66
 modules.d/95iscsi/module-setup.sh       | 31 +------------------------------
Harald Hoyer d9da66
 modules.d/95iscsi/parse-iscsiroot.sh    | 10 ----------
Harald Hoyer d9da66
 test/TEST-31-ISCSI-MULTI/test.sh        | 32 ++++++++++++++++++++++++++++++++
Harald Hoyer d9da66
 6 files changed, 44 insertions(+), 61 deletions(-)
Harald Hoyer d9da66
Harald Hoyer d9da66
diff --git a/modules.d/95iscsi/cleanup-iscsi.sh b/modules.d/95iscsi/cleanup-iscsi.sh
Harald Hoyer d9da66
index bfc8aefc..e97d65ac 100755
Harald Hoyer d9da66
--- a/modules.d/95iscsi/cleanup-iscsi.sh
Harald Hoyer d9da66
+++ b/modules.d/95iscsi/cleanup-iscsi.sh
Harald Hoyer d9da66
@@ -1,4 +1,4 @@
Harald Hoyer d9da66
 #!/bin/sh
Harald Hoyer d9da66
 
Harald Hoyer d9da66
-[ -z "${DRACUT_SYSTEMD}" ] && [ -e /sys/module/bnx2i ] && killproc iscsiuio
Harald Hoyer d9da66
+[ -e /sys/module/bnx2i ] && killproc iscsiuio
Harald Hoyer d9da66
 
Harald Hoyer d9da66
diff --git a/modules.d/95iscsi/iscsiroot.sh b/modules.d/95iscsi/iscsiroot.sh
Harald Hoyer d9da66
index aefd263d..d6325f7d 100755
Harald Hoyer d9da66
--- a/modules.d/95iscsi/iscsiroot.sh
Harald Hoyer d9da66
+++ b/modules.d/95iscsi/iscsiroot.sh
Harald Hoyer d9da66
@@ -36,14 +36,14 @@ iroot=${iroot#:}
Harald Hoyer d9da66
 # figured out a way how to check whether this is built-in or not
Harald Hoyer d9da66
 modprobe crc32c 2>/dev/null
Harald Hoyer d9da66
 
Harald Hoyer d9da66
-if [ -z "${DRACUT_SYSTEMD}" ] && [ -e /sys/module/bnx2i ] && ! [ -e /tmp/iscsiuio-started ]; then
Harald Hoyer d9da66
+if [ -e /sys/module/bnx2i ] && ! [ -e /tmp/iscsiuio-started ]; then
Harald Hoyer d9da66
         iscsiuio
Harald Hoyer d9da66
         > /tmp/iscsiuio-started
Harald Hoyer d9da66
 fi
Harald Hoyer d9da66
 
Harald Hoyer d9da66
 handle_firmware()
Harald Hoyer d9da66
 {
Harald Hoyer d9da66
-    if ! iscsistart -f; then
Harald Hoyer d9da66
+    if ! iscsistart-flocked -f; then
Harald Hoyer d9da66
         warn "iscistart: Could not get list of targets from firmware. Skipping."
Harald Hoyer d9da66
         echo 'skipped' > "/tmp/iscsistarted-firmware"
Harald Hoyer d9da66
         return 0
Harald Hoyer d9da66
@@ -53,7 +53,7 @@ handle_firmware()
Harald Hoyer d9da66
 	iscsi_param="$iscsi_param --param $p"
Harald Hoyer d9da66
     done
Harald Hoyer d9da66
 
Harald Hoyer d9da66
-    if ! iscsistart -b $iscsi_param; then
Harald Hoyer d9da66
+    if ! iscsistart-flocked -b $iscsi_param; then
Harald Hoyer d9da66
         warn "'iscsistart -b $iscsi_param' failed with return code $?"
Harald Hoyer d9da66
     fi
Harald Hoyer d9da66
 
Harald Hoyer d9da66
@@ -117,11 +117,6 @@ handle_netroot()
Harald Hoyer d9da66
            mkdir -p /etc/iscsi
Harald Hoyer d9da66
            ln -fs /run/initiatorname.iscsi /etc/iscsi/initiatorname.iscsi
Harald Hoyer d9da66
            > /tmp/iscsi_set_initiator
Harald Hoyer d9da66
-           if [ -n "$DRACUT_SYSTEMD" ]; then
Harald Hoyer d9da66
-               systemctl try-restart iscsid
Harald Hoyer d9da66
-               # FIXME: iscsid is not yet ready, when the service is :-/
Harald Hoyer d9da66
-               sleep 1
Harald Hoyer d9da66
-           fi
Harald Hoyer d9da66
     fi
Harald Hoyer d9da66
 
Harald Hoyer d9da66
     if [ -z "$iscsi_initiator" ]; then
Harald Hoyer d9da66
@@ -138,11 +133,6 @@ handle_netroot()
Harald Hoyer d9da66
         mkdir -p /etc/iscsi
Harald Hoyer d9da66
         ln -fs /run/initiatorname.iscsi /etc/iscsi/initiatorname.iscsi
Harald Hoyer d9da66
         > /tmp/iscsi_set_initiator
Harald Hoyer d9da66
-        if [ -n "$DRACUT_SYSTEMD" ]; then
Harald Hoyer d9da66
-            systemctl try-restart iscsid
Harald Hoyer d9da66
-            # FIXME: iscsid is not yet ready, when the service is :-/
Harald Hoyer d9da66
-            sleep 1
Harald Hoyer d9da66
-        fi
Harald Hoyer d9da66
     fi
Harald Hoyer d9da66
 
Harald Hoyer d9da66
 
Harald Hoyer d9da66
@@ -163,11 +153,6 @@ handle_netroot()
Harald Hoyer d9da66
     if ! [ -e /etc/iscsi/initiatorname.iscsi ]; then
Harald Hoyer d9da66
         mkdir -p /etc/iscsi
Harald Hoyer d9da66
         ln -fs /run/initiatorname.iscsi /etc/iscsi/initiatorname.iscsi
Harald Hoyer d9da66
-        if [ -n "$DRACUT_SYSTEMD" ]; then
Harald Hoyer d9da66
-            systemctl try-restart iscsid
Harald Hoyer d9da66
-            # FIXME: iscsid is not yet ready, when the service is :-/
Harald Hoyer d9da66
-            sleep 1
Harald Hoyer d9da66
-        fi
Harald Hoyer d9da66
     fi
Harald Hoyer d9da66
 # FIXME $iscsi_protocol??
Harald Hoyer d9da66
 
Harald Hoyer d9da66
@@ -193,7 +178,7 @@ handle_netroot()
Harald Hoyer d9da66
                             --description="Login iSCSI Target $iscsi_target_name" \
Harald Hoyer d9da66
                             -p 'DefaultDependencies=no' \
Harald Hoyer d9da66
                             --unit="$netroot_enc" -- \
Harald Hoyer d9da66
-                            $(command -v iscsistart) \
Harald Hoyer d9da66
+                            $(command -v iscsistart-flocked) \
Harald Hoyer d9da66
                             -i "$iscsi_initiator" -t "$iscsi_target_name"        \
Harald Hoyer d9da66
                             -g "$iscsi_target_group" -a "$iscsi_target_ip"      \
Harald Hoyer d9da66
                             -p "$iscsi_target_port" \
Harald Hoyer d9da66
@@ -211,7 +196,7 @@ handle_netroot()
Harald Hoyer d9da66
             fi
Harald Hoyer d9da66
         fi
Harald Hoyer d9da66
     else
Harald Hoyer d9da66
-        iscsistart -i "$iscsi_initiator" -t "$iscsi_target_name"        \
Harald Hoyer d9da66
+        iscsistart-flocked -i "$iscsi_initiator" -t "$iscsi_target_name"        \
Harald Hoyer d9da66
                    -g "$iscsi_target_group" -a "$iscsi_target_ip"      \
Harald Hoyer d9da66
                    -p "$iscsi_target_port" \
Harald Hoyer d9da66
                    ${iscsi_username:+-u "$iscsi_username"} \
Harald Hoyer d9da66
diff --git a/modules.d/95iscsi/iscsistart-flocked.sh b/modules.d/95iscsi/iscsistart-flocked.sh
Harald Hoyer d9da66
new file mode 100755
Harald Hoyer d9da66
index 00000000..6366335d
Harald Hoyer d9da66
--- /dev/null
Harald Hoyer d9da66
+++ b/modules.d/95iscsi/iscsistart-flocked.sh
Harald Hoyer d9da66
@@ -0,0 +1,5 @@
Harald Hoyer d9da66
+#!/bin/sh
Harald Hoyer d9da66
+{
Harald Hoyer d9da66
+    flock -e 9
Harald Hoyer d9da66
+    iscsistart "$@"
Harald Hoyer d9da66
+} 9>/tmp/.iscsi_lock
Harald Hoyer d9da66
diff --git a/modules.d/95iscsi/module-setup.sh b/modules.d/95iscsi/module-setup.sh
Harald Hoyer d9da66
index 04937b5b..5c47750a 100755
Harald Hoyer d9da66
--- a/modules.d/95iscsi/module-setup.sh
Harald Hoyer d9da66
+++ b/modules.d/95iscsi/module-setup.sh
Harald Hoyer d9da66
@@ -194,41 +194,12 @@ install() {
Harald Hoyer d9da66
         [[ $_iscsiconf ]] && printf "%s\n" "$_iscsiconf" >> "${initdir}/etc/cmdline.d/95iscsi.conf"
Harald Hoyer d9da66
     fi
Harald Hoyer d9da66
 
Harald Hoyer d9da66
+    inst "$moddir/iscsistart-flocked.sh" "/bin/iscsistart-flocked"
Harald Hoyer d9da66
     inst_hook cmdline 90 "$moddir/parse-iscsiroot.sh"
Harald Hoyer d9da66
     inst_hook cleanup 90 "$moddir/cleanup-iscsi.sh"
Harald Hoyer d9da66
     inst "$moddir/iscsiroot.sh" "/sbin/iscsiroot"
Harald Hoyer d9da66
     if ! dracut_module_included "systemd"; then
Harald Hoyer d9da66
         inst "$moddir/mount-lun.sh" "/bin/mount-lun.sh"
Harald Hoyer d9da66
-    else
Harald Hoyer d9da66
-        inst_multiple -o \
Harald Hoyer d9da66
-                      $systemdsystemunitdir/iscsi.service \
Harald Hoyer d9da66
-                      $systemdsystemunitdir/iscsid.service \
Harald Hoyer d9da66
-                      $systemdsystemunitdir/iscsid.socket \
Harald Hoyer d9da66
-                      $systemdsystemunitdir/iscsiuio.service \
Harald Hoyer d9da66
-                      $systemdsystemunitdir/iscsiuio.socket \
Harald Hoyer d9da66
-                      iscsiadm iscsid
Harald Hoyer d9da66
-
Harald Hoyer d9da66
-        mkdir -p "${initdir}/$systemdsystemunitdir/sockets.target.wants"
Harald Hoyer d9da66
-        for i in \
Harald Hoyer d9da66
-                iscsiuio.socket \
Harald Hoyer d9da66
-            ; do
Harald Hoyer d9da66
-            ln_r "$systemdsystemunitdir/${i}" "$systemdsystemunitdir/sockets.target.wants/${i}"
Harald Hoyer d9da66
-        done
Harald Hoyer d9da66
-
Harald Hoyer d9da66
-        mkdir -p "${initdir}/$systemdsystemunitdir/basic.target.wants"
Harald Hoyer d9da66
-        for i in \
Harald Hoyer d9da66
-                iscsid.service \
Harald Hoyer d9da66
-            ; do
Harald Hoyer d9da66
-            ln_r "$systemdsystemunitdir/${i}" "$systemdsystemunitdir/basic.target.wants/${i}"
Harald Hoyer d9da66
-        done
Harald Hoyer d9da66
-
Harald Hoyer d9da66
-        # Make sure iscsid is started after dracut-cmdline and ready for the initqueue
Harald Hoyer d9da66
-        mkdir -p "${initdir}/$systemdsystemunitdir/iscsid.service.d"
Harald Hoyer d9da66
-        (
Harald Hoyer d9da66
-            echo "[Unit]"
Harald Hoyer d9da66
-            echo "After=dracut-cmdline.service"
Harald Hoyer d9da66
-            echo "Before=dracut-initqueue.service"
Harald Hoyer d9da66
-        ) > "${initdir}/$systemdsystemunitdir/iscsid.service.d/dracut.conf"
Harald Hoyer d9da66
     fi
Harald Hoyer d9da66
     inst_dir /var/lib/iscsi
Harald Hoyer d9da66
     dracut_need_initqueue
Harald Hoyer d9da66
diff --git a/modules.d/95iscsi/parse-iscsiroot.sh b/modules.d/95iscsi/parse-iscsiroot.sh
Harald Hoyer d9da66
index 43b2e088..c8c66ccf 100755
Harald Hoyer d9da66
--- a/modules.d/95iscsi/parse-iscsiroot.sh
Harald Hoyer d9da66
+++ b/modules.d/95iscsi/parse-iscsiroot.sh
Harald Hoyer d9da66
@@ -116,11 +116,6 @@ if arg=$(getarg rd.iscsi.initiator -d iscsi_initiator=) && [ -n "$arg" ] && ! [
Harald Hoyer d9da66
     if ! [ -e /etc/iscsi/initiatorname.iscsi ]; then
Harald Hoyer d9da66
         mkdir -p /etc/iscsi
Harald Hoyer d9da66
         ln -fs /run/initiatorname.iscsi /etc/iscsi/initiatorname.iscsi
Harald Hoyer d9da66
-        if [ -n "$DRACUT_SYSTEMD" ]; then
Harald Hoyer d9da66
-            systemctl try-restart iscsid
Harald Hoyer d9da66
-            # FIXME: iscsid is not yet ready, when the service is :-/
Harald Hoyer d9da66
-            sleep 1
Harald Hoyer d9da66
-        fi
Harald Hoyer d9da66
     fi
Harald Hoyer d9da66
 fi
Harald Hoyer d9da66
 
Harald Hoyer d9da66
@@ -133,11 +128,6 @@ if [ -z $iscsi_initiator ] && [ -f /sys/firmware/ibft/initiator/initiator-name ]
Harald Hoyer d9da66
         mkdir -p /etc/iscsi
Harald Hoyer d9da66
         ln -fs /run/initiatorname.iscsi /etc/iscsi/initiatorname.iscsi
Harald Hoyer d9da66
         > /tmp/iscsi_set_initiator
Harald Hoyer d9da66
-        if [ -n "$DRACUT_SYSTEMD" ]; then
Harald Hoyer d9da66
-            systemctl try-restart iscsid
Harald Hoyer d9da66
-            # FIXME: iscsid is not yet ready, when the service is :-/
Harald Hoyer d9da66
-            sleep 1
Harald Hoyer d9da66
-        fi
Harald Hoyer d9da66
     fi
Harald Hoyer d9da66
 fi
Harald Hoyer d9da66
 
Harald Hoyer d9da66
diff --git a/test/TEST-31-ISCSI-MULTI/test.sh b/test/TEST-31-ISCSI-MULTI/test.sh
Harald Hoyer d9da66
index 2b63ff46..2f2b6ed5 100755
Harald Hoyer d9da66
--- a/test/TEST-31-ISCSI-MULTI/test.sh
Harald Hoyer d9da66
+++ b/test/TEST-31-ISCSI-MULTI/test.sh
Harald Hoyer d9da66
@@ -73,6 +73,38 @@ do_test_run() {
Harald Hoyer d9da66
                "rd.iscsi.initiator=$initiator" \
Harald Hoyer d9da66
         || return 1
Harald Hoyer d9da66
 
Harald Hoyer d9da66
+    run_client "netroot=iscsi target1 target2 rd.iscsi.waitnet=0" \
Harald Hoyer d9da66
+               "root=LABEL=sysroot" \
Harald Hoyer d9da66
+               "ip=192.168.50.101:::255.255.255.0::ens3:off" \
Harald Hoyer d9da66
+               "ip=192.168.51.101:::255.255.255.0::ens4:off" \
Harald Hoyer d9da66
+               "netroot=iscsi:192.168.51.1::::iqn.2009-06.dracut:target1" \
Harald Hoyer d9da66
+               "netroot=iscsi:192.168.50.1::::iqn.2009-06.dracut:target2" \
Harald Hoyer d9da66
+               "rd.iscsi.firmware" \
Harald Hoyer d9da66
+               "rd.iscsi.initiator=$initiator" \
Harald Hoyer d9da66
+               "rd.iscsi.waitnet=0" \
Harald Hoyer d9da66
+        || return 1
Harald Hoyer d9da66
+
Harald Hoyer d9da66
+    run_client "netroot=iscsi target1 target2 rd.iscsi.waitnet=0 rd.iscsi.testroute=0" \
Harald Hoyer d9da66
+               "root=LABEL=sysroot" \
Harald Hoyer d9da66
+               "ip=192.168.50.101:::255.255.255.0::ens3:off" \
Harald Hoyer d9da66
+               "ip=192.168.51.101:::255.255.255.0::ens4:off" \
Harald Hoyer d9da66
+               "netroot=iscsi:192.168.51.1::::iqn.2009-06.dracut:target1" \
Harald Hoyer d9da66
+               "netroot=iscsi:192.168.50.1::::iqn.2009-06.dracut:target2" \
Harald Hoyer d9da66
+               "rd.iscsi.firmware" \
Harald Hoyer d9da66
+               "rd.iscsi.initiator=$initiator" \
Harald Hoyer d9da66
+               "rd.iscsi.waitnet=0 rd.iscsi.testroute=0" \
Harald Hoyer d9da66
+        || return 1
Harald Hoyer d9da66
+
Harald Hoyer d9da66
+    run_client "netroot=iscsi target1 target2 rd.iscsi.waitnet=0 rd.iscsi.testroute=0 default GW" \
Harald Hoyer d9da66
+               "root=LABEL=sysroot" \
Harald Hoyer d9da66
+               "ip=192.168.50.101::192.168.50.1:255.255.255.0::ens3:off" \
Harald Hoyer d9da66
+               "ip=192.168.51.101::192.168.51.1:255.255.255.0::ens4:off" \
Harald Hoyer d9da66
+               "netroot=iscsi:192.168.51.1::::iqn.2009-06.dracut:target1" \
Harald Hoyer d9da66
+               "netroot=iscsi:192.168.50.1::::iqn.2009-06.dracut:target2" \
Harald Hoyer d9da66
+               "rd.iscsi.firmware" \
Harald Hoyer d9da66
+               "rd.iscsi.initiator=$initiator" \
Harald Hoyer d9da66
+               "rd.iscsi.waitnet=0 rd.iscsi.testroute=0" \
Harald Hoyer d9da66
+        || return 1
Harald Hoyer d9da66
 
Harald Hoyer d9da66
     echo "All tests passed [OK]"
Harald Hoyer d9da66
     return 0
Harald Hoyer d9da66