Iterate /sys/bus/ccwgroup/devices to tell if we should set up rd.znet

This patch fixes bz1941106 and bz1941905 which passed empty rd.znet to the
kernel command line in the following cases,
 - The IBM (Z15) KVM guest uses virtio for all devices including network
   device, so there is no znet device for IBM KVM guest. So we can't
   assume a s390x machine always has a znet device.
 - When a bridged network is used, kexec-tools tries to obtain the znet
   configuration from the ifcfg script of the bridged network rather than
   from the ifcfg script of znet device.

We can iterate /sys/bus/ccwgroup/devices to tell if there if there is
a znet network device. By getting an ifname from znet, we can also avoid
mistaking the slave netdev as a znet network device in a bridged network
or bonded network.

Note: This patch also assumes there is only one znet device as commit
7148c0a30d ("add s390x netdev setup")
which greatly simplifies the code. According to IBM [1], there could be
more than znet devices for a z/VM system and a z/VM system may have a
non-znet network device like ConnectX. Since kdump_setup_znet was
introduced in 2012 and so far there is no known customer complaint that
invalidates this assumption I think it's safe to assume an IBM z/VM
system only has one znet device. Besides, there is no z/VM system found
on beaker to test the alternative scenarios.

[1] https://bugzilla.redhat.com/show_bug.cgi?id=1941905#c13

Signed-off-by: Coiby Xu <coxu@redhat.com>
Acked-by: Kairui Song <kasong@redhat.com>
This commit is contained in:
Coiby Xu 2021-06-07 07:26:03 +08:00 committed by Kairui Song
parent 41980f30d9
commit 7d47251568

View File

@ -460,6 +460,34 @@ kdump_setup_vlan() {
fi
}
# find online znet device
# return ifname (_netdev)
# code reaped from the list_configured function of
# https://github.com/hreinecke/s390-tools/blob/master/zconf/znetconf
find_online_znet_device() {
local CCWGROUPBUS_DEVICEDIR="/sys/bus/ccwgroup/devices"
local NETWORK_DEVICES d ifname ONLINE
NETWORK_DEVICES=$(find $CCWGROUPBUS_DEVICEDIR -type l)
for d in $NETWORK_DEVICES
do
read ONLINE < $d/online
if [ $ONLINE -ne 1 ]; then
continue
fi
# determine interface name, if there (only for qeth and if
# device is online)
if [ -f $d/if_name ]
then
read ifname < $d/if_name
elif [ -d $d/net ]
then
ifname=$(ls $d/net/)
fi
[ -n "$ifname" ] && break
done
echo -n "$ifname"
}
# setup s390 znet cmdline
# $1: netdev (ifname)
# $2: nmcli connection show output
@ -526,6 +554,7 @@ kdump_get_remote_ip()
kdump_install_net() {
local _destaddr _srcaddr _route _netdev _nm_show_cmd kdumpnic
local _static _proto _ip_conf _ip_opts _ifname_opts
local _znet_netdev _nm_show_cmd_znet
_destaddr=$(kdump_get_remote_ip $1)
_route=$(kdump_get_ip_route $_destaddr)
@ -535,8 +564,10 @@ kdump_install_net() {
_netmac=$(kdump_get_mac_addr $_netdev)
kdumpnic=$(kdump_setup_ifname $_netdev)
if [ "$(uname -m)" = "s390x" ]; then
$(kdump_setup_znet "$_netdev" "$_nm_show_cmd")
_znet_netdev=$(find_online_znet_device)
if [[ -n "$_znet_netdev" ]]; then
_nm_show_cmd_znet=$(get_nmcli_connection_show_cmd_by_ifname "$_znet_netdev")
$(kdump_setup_znet "$_znet_netdev" "$_nm_show_cmd_znet")
if [[ $? != 0 ]]; then
derror "Failed to set up znet"
exit 1