]> git.ipfire.org Git - thirdparty/dracut.git/commitdiff
Wait for link ready before use the interface
authordyoung@redhat.com <dyoung@redhat.com>
Wed, 12 Dec 2012 04:23:24 +0000 (12:23 +0800)
committerHarald Hoyer <harald@redhat.com>
Fri, 14 Dec 2012 08:08:59 +0000 (09:08 +0100)
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 <dev> 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 <dyoung@redhat.com>
modules.d/40network/net-lib.sh

index 142aa687bc8465e14e3dc8a24bccacd0ba6b1624..d9a241b487c49961f1b3e2fe12695d1852ac4303 100644 (file)
@@ -323,6 +323,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
@@ -347,6 +360,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
 }