Blame 0013-feat-znet-use-zdev-for-consolidated-device-configura.patch

218d2d
From 86b6e2979999cf5ecce8c76c6230d1f085b3a333 Mon Sep 17 00:00:00 2001
218d2d
From: Steffen Maier <maier@linux.ibm.com>
218d2d
Date: Tue, 25 Jul 2023 19:43:05 +0200
218d2d
Subject: [PATCH 13/23] feat(znet): use zdev for consolidated device
218d2d
 configuration
218d2d
218d2d
Remove any distribution-specifics from s390 channel-attached network device
218d2d
configuration.
218d2d
218d2d
Similar to 95qeth_rules, copy the existing persistent network configuration
218d2d
into the initrd. This needs to go via chzdev import so chzdev updates (adds
218d2d
to) the cio_ignore persistent config inside the initrd, because other
218d2d
dracut modules such as zdev from s390-tools also import
218d2d
persistent (non-network) config into initrd and the set union of devices
218d2d
needs to end up in the cio_ignore persistent config inside the initrd.
218d2d
218d2d
Additional debugging output can be generated with e.g. dracut option
218d2d
"--stdlog 5" (or short -L5). It shows the chzdev export result, the output
218d2d
of chzdev imports, and an overview of the resulting persistent config
218d2d
within the initrd. Typically combined with "--debug" to get a shell trace
218d2d
from building an initrd (Note: --debug does not increase the log levels).
218d2d
218d2d
Note that nm-initrd-generator also parses rd.znet and rd.znet_ifname
218d2d
to fill in s390 options of a NetworkManager connection definition.
218d2d
218d2d
Signed-off-by: Steffen Maier <maier@linux.ibm.com>
218d2d
---
218d2d
 modules.d/95znet/module-setup.sh | 37 +++++++++++++++++++++++--
218d2d
 modules.d/95znet/parse-ccw.sh    | 47 ++++++++++++++++++++++++++++++--
218d2d
 2 files changed, 78 insertions(+), 6 deletions(-)
218d2d
218d2d
diff --git a/modules.d/95znet/module-setup.sh b/modules.d/95znet/module-setup.sh
218d2d
index df37c660..95164bba 100755
218d2d
--- a/modules.d/95znet/module-setup.sh
218d2d
+++ b/modules.d/95znet/module-setup.sh
218d2d
@@ -5,7 +5,7 @@ check() {
218d2d
     arch=${DRACUT_ARCH:-$(uname -m)}
218d2d
     [ "$arch" = "s390" -o "$arch" = "s390x" ] || return 1
218d2d
 
218d2d
-    require_binaries znet_cio_free grep sed seq readlink || return 1
218d2d
+    require_binaries grep sed seq readlink chzdev || return 1
218d2d
 
218d2d
     return 0
218d2d
 }
218d2d
@@ -24,6 +24,37 @@ installkernel() {
218d2d
 # called by dracut
218d2d
 install() {
218d2d
     inst_hook cmdline 30 "$moddir/parse-ccw.sh"
218d2d
-    inst_rules 81-ccw.rules
218d2d
-    inst_multiple znet_cio_free grep sed seq readlink /lib/udev/ccw_init
218d2d
+    inst_multiple grep sed seq readlink chzdev
218d2d
+    if [[ $hostonly ]]; then
218d2d
+        local _tempfile
218d2d
+        _tempfile=$(mktemp --tmpdir="${DRACUT_TMPDIR}" dracut-zdev.XXXXXX)
218d2d
+        {
218d2d
+            chzdev qeth --export - --configured --persistent --quiet --type
218d2d
+            chzdev lcs --export - --configured --persistent --quiet --type
218d2d
+            chzdev ctc --export - --configured --persistent --quiet --type
218d2d
+        } 2> /dev/null > "$_tempfile"
218d2d
+        ddebug < "$_tempfile"
218d2d
+        chzdev --import "$_tempfile" --persistent --base "/etc=$initdir/etc" \
218d2d
+            --yes --no-root-update --force 2>&1 | ddebug
218d2d
+        lszdev --configured --persistent --info \
218d2d
+            --base "/etc=$initdir/etc" 2>&1 | ddebug
218d2d
+        rm -f "$_tempfile"
218d2d
+        # these are purely generated udev rules so we have to glob expand
218d2d
+        # within $initdir and strip the $initdir prefix for mark_hostonly
218d2d
+        local -a _array
218d2d
+        # shellcheck disable=SC2155
218d2d
+        local _nullglob=$(shopt -p nullglob)
218d2d
+        shopt -u nullglob
218d2d
+        # shellcheck disable=SC2086
218d2d
+        readarray -t _array < <(
218d2d
+            ls -1 $initdir/etc/udev/rules.d/41-*.rules 2> /dev/null
218d2d
+        )
218d2d
+        [[ ${#_array[@]} -gt 0 ]] && mark_hostonly "${_array[@]#$initdir}"
218d2d
+        # shellcheck disable=SC2086
218d2d
+        readarray -t _array < <(
218d2d
+            ls -1 $initdir/etc/modprobe.d/s390x-*.conf 2> /dev/null
218d2d
+        )
218d2d
+        [[ ${#_array[@]} -gt 0 ]] && mark_hostonly "${_array[@]#$initdir}"
218d2d
+        $_nullglob
218d2d
+    fi
218d2d
 }
218d2d
diff --git a/modules.d/95znet/parse-ccw.sh b/modules.d/95znet/parse-ccw.sh
218d2d
index d8953605..aacc988e 100755
218d2d
--- a/modules.d/95znet/parse-ccw.sh
218d2d
+++ b/modules.d/95znet/parse-ccw.sh
218d2d
@@ -1,7 +1,50 @@
218d2d
 #!/bin/bash
218d2d
 
218d2d
+znet_base_args="--no-settle --yes --no-root-update --force"
218d2d
+
218d2d
+# at this point in time dracut's vinfo() only logs to journal which is hard for
218d2d
+# s390 users to find and access on a line mode console such as 3215 mode
218d2d
+# so use a vinfo alternative that still prints to the console via kmsg
218d2d
+znet_vinfo() {
218d2d
+    while read -r _znet_vinfo_line || [ -n "$_znet_vinfo_line" ]; do
218d2d
+        # Prefix "<30>" represents facility LOG_DAEMON 3 and loglevel INFO 6:
218d2d
+        # (facility << 3) | level.
218d2d
+        echo "<30>dracut: $_znet_vinfo_line" > /dev/kmsg
218d2d
+    done
218d2d
+}
218d2d
+
218d2d
 for ccw_arg in $(getargs rd.ccw -d 'rd_CCW=') $(getargs rd.znet -d 'rd_ZNET='); do
218d2d
-    echo "$ccw_arg" >> /etc/ccw.conf
218d2d
+    (
218d2d
+        SAVED_IFS="$IFS"
218d2d
+        IFS=","
218d2d
+        # shellcheck disable=SC2086
218d2d
+        set -- $ccw_arg
218d2d
+        IFS="$SAVED_IFS"
218d2d
+        type="$1"
218d2d
+        subchannel1="$2"
218d2d
+        subchannel2="$3"
218d2d
+        subchannel3="$4"
218d2d
+        echo "rd.znet ${ccw_arg} :" | znet_vinfo
218d2d
+        if [ "$#" -lt 3 ]; then
218d2d
+            echo "rd.znet needs at least 3 list items: type,subchannel1,subchannel2" | znet_vinfo
218d2d
+        fi
218d2d
+        if [ "$1" = "qeth" ]; then
218d2d
+            if [ "$#" -lt 4 ]; then
218d2d
+                echo "rd.znet for type qeth needs at least 4 list items: qeth,subchannel1,subchannel2,subchannel3" | znet_vinfo
218d2d
+            fi
218d2d
+            subchannels="$subchannel1:$subchannel2:$subchannel3"
218d2d
+            shift 4
218d2d
+            # shellcheck disable=SC2086
218d2d
+            chzdev --enable --persistent $znet_base_args \
218d2d
+                "$type" "$subchannels" "$@" 2>&1 | znet_vinfo
218d2d
+        else
218d2d
+            subchannels="$subchannel1:$subchannel2"
218d2d
+            shift 3
218d2d
+            # shellcheck disable=SC2086
218d2d
+            chzdev --enable --persistent $znet_base_args \
218d2d
+                "$type" "$subchannels" "$@" 2>&1 | znet_vinfo
218d2d
+        fi
218d2d
+    )
218d2d
 done
218d2d
 
218d2d
 for ifname in $(getargs rd.znet_ifname); do
218d2d
@@ -21,5 +64,3 @@ for ifname in $(getargs rd.znet_ifname); do
218d2d
         } > /etc/udev/rules.d/81-ccw-ifname.rules
218d2d
     fi
218d2d
 done
218d2d
-
218d2d
-znet_cio_free
218d2d
-- 
218d2d
2.42.0
218d2d