dracut-module-setup: consolidate s390 network device config (#1937048)

This is a preparation for consolidating s390 network device config with
https://github.com/dracutdevs/dracut/pull/2534
  ("feat(znet): use zdev for consolidated device configuration")
https://github.com/steffen-maier/s390utils/pull/1/commits
  ("znet: migrate to consolidated persistent device config with zdev
    (#1937046,#1937048))"
  ("znet: clean up old deprecated persistent device config
    (#1937046,#1937048)").
With above consolidation, s390-specific low-level configuration information
will no longer be in NetworkManager connections (nor ifcfg files), but in
the persistent configuration database of chzdev from s390-tools.

Since the kdump dracut module here depends on the "znet" dracut module [1]
and "znet" will copy all persistent configuration into initrd as of above
commit, all s390-specific information would already be in the kdump initrd.
[1] 08de712528 ("Move some dracut module dependencies checks to
module-setup.sh"), 7148c0a30d ("add s390x netdev setup")

However, it is more appropriate and also removes the copy dependency from
"znet" to introduce the consolidated zdev mechanism for importing just the
required network device config from the current active system
configuration. It does not depend on any of the pull requests above.
It does not depend on any existing persistent configuration
and can replace the old function code. This is similar to dracut block
device dependency handling in s390-tools zdev/dracut/95zdev-kdump.

The old code only seems to work if there is exactly one s390-specific
nmconnection (or ifcfg file). Related commits:
b5577c163a ("Simplify setup_znet by copying connection profile to initrd"),
7d47251568 ("Iterate /sys/bus/ccwgroup/devices to tell if we should set up rd.znet"),
8b08b4f17b ("Set up s390 znet cmdline by "nmcli --get-values""),
ce0305d4f9 ("Add a new option 'rd.znet_ifname' in order to use it in udev rules"),
7148c0a30d ("add s390x netdev setup").

A bonding or teaming setup would have multiple following network
interfaces, each of which would need a low-level config if they're s390
channel-attached network devices. The new code should be able to handle
that by iterating the involved network interfaces. Chzdev only exports
something if it's a device type it deems itself responsible for.

Additional debugging output can be generated with e.g. dracut option
"--stdlog 5" (or short -L5). It shows the chzdev export result, the output
of chzdev export and import, and an overview of the resulting persistent
config within the initrd. On systems, which default to using dracut option
"--quiet", you might need an additional "--verbose" to counter "--quiet" so
-L5 has effect. Typically combined with "--debug" to get a shell trace from
building an initrd (Note: --debug does not increase the log levels).

Signed-off-by: Steffen Maier <maier@linux.ibm.com>
Reviewed-by: Philipp Rudo <prudo@redhat.com>
Reviewed-by: Coiby Xu <coxu@redhat.com>
This commit is contained in:
Steffen Maier 2023-11-09 16:50:39 +01:00 committed by Coiby Xu
parent 38d9990389
commit 0d90d580b4

View File

@ -26,6 +26,9 @@ check() {
if [[ -z $IN_KDUMP ]] || [[ ! -f /etc/kdump.conf ]]; then if [[ -z $IN_KDUMP ]] || [[ ! -f /etc/kdump.conf ]]; then
return 1 return 1
fi fi
if [[ "$(uname -m)" == "s390x" ]]; then
require_binaries chzdev || return 1
fi
return 0 return 0
} }
@ -474,6 +477,8 @@ _find_znet_nmconnection() {
# #
# Note part of code is extracted from ccw_init provided by s390utils # Note part of code is extracted from ccw_init provided by s390utils
kdump_setup_znet() { kdump_setup_znet() {
local _netif
local _tempfile=$(mktemp --tmpdir="$_DRACUT_KDUMP_NM_TMP_DIR" kdump-dracut-zdev.XXXXXX)
local _config_file _unique_name _NM_conf_dir local _config_file _unique_name _NM_conf_dir
local __sed_discard_ignored_files='/\(~\|\.bak\|\.old\|\.orig\|\.rpmnew\|\.rpmorig\|\.rpmsave\)$/d' local __sed_discard_ignored_files='/\(~\|\.bak\|\.old\|\.orig\|\.rpmnew\|\.rpmorig\|\.rpmsave\)$/d'
@ -481,6 +486,18 @@ kdump_setup_znet() {
return return
fi fi
for _netif in $1; do
chzdev --export "$_tempfile" --active --by-interface "$_netif" \
2>&1 | ddebug
sed -i -e 's/^\[active /\[persistent /' "$_tempfile"
ddebug < "$_tempfile"
chzdev --import "$_tempfile" --persistent --base "/etc=$initdir/etc" \
--yes --no-root-update --force 2>&1 | ddebug
lszdev --configured --persistent --info --by-interface "$_netif" \
--base "/etc=$initdir/etc" 2>&1 | ddebug
done
rm -f "$_tempfile"
_NM_conf_dir="/etc/NetworkManager/system-connections" _NM_conf_dir="/etc/NetworkManager/system-connections"
_config_file=$(_find_znet_nmconnection "$initdir/$_NM_conf_dir" "$__sed_discard_ignored_files") _config_file=$(_find_znet_nmconnection "$initdir/$_NM_conf_dir" "$__sed_discard_ignored_files")
@ -599,7 +616,7 @@ kdump_install_net() {
if [[ -n "$_netifs" ]]; then if [[ -n "$_netifs" ]]; then
kdump_install_nmconnections kdump_install_nmconnections
apply_nm_initrd_generator_timeouts apply_nm_initrd_generator_timeouts
kdump_setup_znet kdump_setup_znet "$_netifs"
kdump_install_nm_netif_allowlist "$_netifs" kdump_install_nm_netif_allowlist "$_netifs"
kdump_install_nic_driver "$_netifs" kdump_install_nic_driver "$_netifs"
kdump_install_resolv_conf kdump_install_resolv_conf