From mboxrd@z Thu Jan 1 00:00:00 1970 From: dyoung-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org Subject: [patch 4/6 v2] Wait for link ready before use the interface Date: Fri, 30 Nov 2012 11:20:25 +0800 Message-ID: <20121130032700.756418200@redhat.com> References: <20121130032021.140175185@redhat.com> Return-path: Content-Disposition: inline; filename=patch4 Sender: initramfs-owner-u79uwXL29TY76Z2rM5mHXA@public.gmane.org List-ID: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: harald-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org, initramfs-u79uwXL29TY76Z2rM5mHXA@public.gmane.org Cc: Dave Young Some network driver will take long time to initialize. We have an example in a HP machine which take about one minute for this. The callback such as "ip link set up" will fail, afterwards setup for network will also fail. Fix this by add a new function wait_for_if_link, wait the link ready before use it. Signed-off-by: Dave Young --- modules.d/40network/net-lib.sh | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) --- dracut.orig/modules.d/40network/net-lib.sh +++ dracut/modules.d/40network/net-lib.sh @@ -316,6 +316,19 @@ parse_ifname_opts() { } +# some network driver need long time to initialize, wait before it's ready. +wait_for_if_link() { + local cnt=0 + local li + while [ $cnt -lt 600 ]; do + li=$(ip -o link show dev $1 2>/dev/null) + [ -n "$li" ] && return 0 + sleep 0.1 + cnt=$(($cnt+1)) + done + return 1 +} + wait_for_if_up() { local cnt=0 local li @@ -340,6 +353,8 @@ wait_for_route_ok() { } linkup() { - ip link set $1 up 2>/dev/null && wait_for_if_up $1 2>/dev/null + wait_for_if_link $1 2>/dev/null\ + && ip link set $1 up 2>/dev/null\ + && wait_for_if_up $1 2>/dev/null }