From 9792994f2f13dd7d6561140fe4b590114a8571c1 Mon Sep 17 00:00:00 2001 From: Coiby Xu Date: Thu, 22 Sep 2022 22:31:47 +0800 Subject: [PATCH] Wait for the network to be truly ready before dumping vmcore nm-wait-online-initrd.service installed by dracut's 35-networkmanager module calls nm-online with "-s" which means it returns immediately when NetworkManager logs "startup complete". Thus it doesn't truly wait for network connectivity to be established [1]. Wait for the network to be truly ready before dumping vmcore. There are two benefits brought by this approach, - ssh/nfs dumping won't fail because of that the network is not ready e.g. [2][3] - users don't need to use workarounds like rd.net.carrier.timeout to make sure the network is ready [1] https://bugzilla.redhat.com/show_bug.cgi?id=1485712 [2] https://bugzilla.redhat.com/show_bug.cgi?id=1909014 [3] https://bugzilla.redhat.com/show_bug.cgi?id=2035451 Signed-off-by: Coiby Xu Reviewed-by: Thomas Haller Reviewed-by: Philipp Rudo --- dracut-kdump.sh | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/dracut-kdump.sh b/dracut-kdump.sh index 357c14c..4eec70b 100755 --- a/dracut-kdump.sh +++ b/dracut-kdump.sh @@ -482,6 +482,26 @@ save_vmcore_dmesg_ssh() fi } +wait_online_network() +{ + # In some cases, network may still not be ready because nm-online is called + # with "-s" which means to wait for NetworkManager startup to complete, rather + # than waiting for network connectivity specifically. Wait 10mins more for the + # network to be truely ready in these cases. + _loop=0 + while [ $_loop -lt 600 ]; do + sleep 1 + _loop=$((_loop + 1)) + if _route=$(kdump_get_ip_route "$1" 2> /dev/null); then + printf "%s" "$_route" + return + fi + done + + derror "Oops. The network still isn't ready after waiting 10mins." + exit 1 +} + get_host_ip() { @@ -495,7 +515,11 @@ get_host_ip() derror "failed to get remote IP address!" return 1 fi - _route=$(kdump_get_ip_route "$_kdump_remote_ip") + + if ! _route=$(wait_online_network "$_kdump_remote_ip"); then + return 1 + fi + _netdev=$(kdump_get_ip_route_field "$_route" "dev") if ! _kdumpip=$(ip addr show dev "$_netdev" | grep '[ ]*inet'); then