From c4a0ad47dd7aed257d563fbbb90e086148faf169 Mon Sep 17 00:00:00 2001 From: Coiby Xu Date: Thu, 25 May 2023 16:56:12 +0800 Subject: [PATCH] Only rename the virtual Azure Hyper-V network interface Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1964822 Upstream: RHEL-only Currently, vmcore dumping to remote fs gives a warning "eth0: Failed to rename network interface 3 from 'eth0' to 'kdump-eth0': File exists" on Azure Hyper-V VM with accelerated networking because it uses a physical NIC for accelerated networking [1] and the backing physical NIC has the same MAC address as the virtual NIC. In the kdump initrd, an udev rule will try renaming NICs with the given MAC address and fails as expected since there are two NICs having the same MAC address. This udev rule is created automatically when specifying the dracut cmdline "ifname=:". For the case of Azure Hyper-V VM with accelerated networking, only the virtual network interface need to be renamed. So create an udev rule manually. [1] https://learn.microsoft.com/en-us/azure/virtual-network/accelerated-networking-overview Signed-off-by: Coiby Xu --- dracut-module-setup.sh | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/dracut-module-setup.sh b/dracut-module-setup.sh index e250703..27be84b 100755 --- a/dracut-module-setup.sh +++ b/dracut-module-setup.sh @@ -303,10 +303,6 @@ kdump_get_perm_addr() { fi } -_get_nic_driver() { - ethtool -i "$1" | sed -n -E "s/driver: (.*)/\1/p" -} - # Prefix kernel assigned names with "kdump-". EX: eth0 -> kdump-eth0 # Because kernel assigned names are not persistent between 1st and 2nd # kernel. We could probably end up with eth0 being eth1, eth0 being @@ -318,7 +314,7 @@ kdump_setup_ifname() { # fadump to kdump. Skip prefixing 'kdump-' in this case as adding # another prefix may truncate the ifname. Since an ifname with # 'kdump-' is already persistent, this should be fine. - if [[ $1 =~ eth* ]] && [[ ! $1 =~ ^kdump-* ]] && [[ $(_get_nic_driver "$1") != hv_netvsc ]]; then + if [[ $1 =~ eth* ]] && [[ ! $1 =~ ^kdump-* ]]; then _ifname="kdump-$1" else _ifname="$1" @@ -485,6 +481,18 @@ kdump_setup_znet() { echo rd.znet=${NETTYPE},${SUBCHANNELS}${_options} rd.znet_ifname=$(kdump_setup_ifname $_netdev):${SUBCHANNELS} > ${initdir}/etc/cmdline.d/30znet.conf } +_get_nic_driver() { + ethtool -i "$1" | sed -n -E "s/driver: (.*)/\1/p" +} + +_rename_hypver_netdev() { + local _udev_rule_dir + + _udev_rule_dir=${initdir}/etc/udev/rules.d + mkdir -p "$_udev_rule_dir" + printf 'SUBSYSTEM=="net", ACTION=="add", DRIVERS=="hv_netvsc", ATTR{address}=="%s", ATTR{type}=="1", NAME="%s"\n' "$2" "$1" > "${_udev_rule_dir}/80-hv_netvsc-ifname.rules" +} + # Setup dracut to bringup a given network interface kdump_setup_netdev() { local _netdev=$1 _srcaddr=$2 @@ -533,8 +541,12 @@ kdump_setup_netdev() { elif kdump_is_vlan "$_netdev"; then kdump_setup_vlan "$_netdev" else - _ifname_opts=" ifname=$kdumpnic:$_netmac" - echo "$_ifname_opts" >> $_ip_conf + if [[ $(_get_nic_driver "$1") != hv_netvsc ]]; then + _ifname_opts=" ifname=$kdumpnic:$_netmac" + echo "$_ifname_opts" >> $_ip_conf + else + _rename_hypver_netdev "$kdumpnic" "$_netmac" + fi fi _save_kdump_netifs "$_netdev" "$_kdumpdev"