Blame SOURCES/0266-network-add-options-to-tweak-timeouts.patch

64b87c
From d8ad687e1a4c0343eb076902b11aff2b2b2c4b85 Mon Sep 17 00:00:00 2001
64b87c
From: Harald Hoyer <harald@redhat.com>
64b87c
Date: Fri, 3 Jul 2015 13:30:40 +0200
64b87c
Subject: [PATCH] network: add options to tweak timeouts
64b87c
64b87c
 rd.net.dhcp.retry=<cnt>
64b87c
     If this option is set, dracut will try to connect via dhcp
64b87c
     <cnt> times before failing. Default is 1.
64b87c
64b87c
 rd.net.timeout.dhcp=<arg>
64b87c
     If this option is set, dhclient is called with "-timeout <arg>".
64b87c
64b87c
 rd.net.timeout.iflink=<seconds>
64b87c
     Wait <seconds> until link shows up. Default is 60 seconds.
64b87c
64b87c
 rd.net.timeout.ifup=<seconds>
64b87c
     Wait <seconds> until link has state "UP". Default is 20 seconds.
64b87c
64b87c
 rd.net.timeout.route=<seconds>
64b87c
     Wait <seconds> until route shows up. Default is 20 seconds.
64b87c
64b87c
 rd.net.timeout.ipv6dad=<seconds>
64b87c
     Wait <seconds> until IPv6 DAD is finished. Default is 50 seconds.
64b87c
64b87c
 rd.net.timeout.ipv6auto=<seconds>
64b87c
     Wait <seconds> until IPv6 automatic addresses are assigned.
64b87c
     Default is 40 seconds.
64b87c
64b87c
 rd.net.timeout.carrier=<seconds>
64b87c
     Wait <seconds> until carrier is recognized. Default is 5 seconds.
64b87c
---
64b87c
 dracut.cmdline.7.asc           | 25 +++++++++++++++++++++++++
64b87c
 modules.d/40network/ifup.sh    | 26 ++++++++++++++++++++++----
64b87c
 modules.d/40network/net-lib.sh | 36 ++++++++++++++++++++++++++++++------
64b87c
 3 files changed, 77 insertions(+), 10 deletions(-)
64b87c
64b87c
diff --git a/dracut.cmdline.7.asc b/dracut.cmdline.7.asc
1755ca
index c7e3bd40..5f3dead1 100644
64b87c
--- a/dracut.cmdline.7.asc
64b87c
+++ b/dracut.cmdline.7.asc
64b87c
@@ -572,6 +572,31 @@ NFS
64b87c
 **rd.nfs.domain=**__<NFSv4 domain name>__::
64b87c
     Set the NFSv4 domain name. Will overwrite the settings in _/etc/idmap.conf_.
64b87c
 
64b87c
+**rd.net.dhcp.retry=**__<cnt>__::
64b87c
+    If this option is set, dracut will try to connect via dhcp <cnt> times before failing.
64b87c
+    Default is 1.
64b87c
+
64b87c
+**rd.net.timeout.dhcp=**__<arg>__::
64b87c
+    If this option is set, dhclient is called with "-timeout <arg>".
64b87c
+
64b87c
+**rd.net.timeout.iflink=**__<seconds>__::
64b87c
+    Wait <seconds> until link shows up. Default is 60 seconds.
64b87c
+
64b87c
+**rd.net.timeout.ifup=**__<seconds>__::
64b87c
+    Wait <seconds> until link has state "UP". Default is 20 seconds.
64b87c
+
64b87c
+**rd.net.timeout.route=**__<seconds>__::
64b87c
+    Wait <seconds> until route shows up. Default is 20 seconds.
64b87c
+
64b87c
+**rd.net.timeout.ipv6dad=**__<seconds>__::
64b87c
+    Wait <seconds> until IPv6 DAD is finished. Default is 50 seconds.
64b87c
+
64b87c
+**rd.net.timeout.ipv6auto=**__<seconds>__::
64b87c
+    Wait <seconds> until IPv6 automatic addresses are assigned. Default is 40 seconds.
64b87c
+
64b87c
+**rd.net.timeout.carrier=**__<seconds>__::
64b87c
+    Wait <seconds> until carrier is recognized. Default is 5 seconds.
64b87c
+
64b87c
 CIFS
64b87c
 ~~~
64b87c
 **root=**cifs://[__<username>__[:__<password>__]@]__<server-ip>__:__<root-dir>__::
64b87c
diff --git a/modules.d/40network/ifup.sh b/modules.d/40network/ifup.sh
1755ca
index 3cff725c..2f51e6d5 100755
64b87c
--- a/modules.d/40network/ifup.sh
64b87c
+++ b/modules.d/40network/ifup.sh
64b87c
@@ -98,15 +98,33 @@ do_dhcp() {
64b87c
     # event for nfsroot
64b87c
     # XXX add -V vendor class and option parsing per kernel
64b87c
 
64b87c
+    local _COUNT=0
64b87c
+    local _timeout=$(getargs rd.net.timeout.dhcp=)
64b87c
+    local _DHCPRETRY=$(getargs rd.net.dhcp.retry=)
64b87c
+    _DHCPRETRY=${_DHCPRETRY:-1}
64b87c
+
64b87c
     [ -e /tmp/dhclient.$netif.pid ] && return 0
64b87c
 
64b87c
     if ! iface_has_link $netif; then
64b87c
-        echo "No carrier detected"
64b87c
+        warn "No carrier detected on interface $netif"
64b87c
         return 1
64b87c
     fi
64b87c
-    echo "Starting dhcp for interface $netif"
64b87c
-    dhclient "$@" -1 -q -cf /etc/dhclient.conf -pf /tmp/dhclient.$netif.pid -lf /tmp/dhclient.$netif.lease $netif \
64b87c
-        || echo "dhcp failed"
64b87c
+
64b87c
+    while [ $_COUNT -lt $_DHCPRETRY ]; do
64b87c
+        info "Starting dhcp for interface $netif"
64b87c
+        dhclient "$@" \
64b87c
+                 ${_timeout:+-timeout $_timeout} \
64b87c
+                 -1 -q \
64b87c
+                 -cf /etc/dhclient.conf \
64b87c
+                 -pf /tmp/dhclient.$netif.pid \
64b87c
+                 -lf /tmp/dhclient.$netif.lease \
64b87c
+                 $netif \
64b87c
+            && return 0
64b87c
+        _COUNT=$(($_COUNT+1))
64b87c
+        [ $_COUNT -lt $_DHCPRETRY ] && sleep 1
64b87c
+    done
64b87c
+    warn "dhcp for interface $netif failed"
64b87c
+    return 1
64b87c
 }
64b87c
 
64b87c
 load_ipv6() {
64b87c
diff --git a/modules.d/40network/net-lib.sh b/modules.d/40network/net-lib.sh
1755ca
index 1f77a154..de5273ca 100755
64b87c
--- a/modules.d/40network/net-lib.sh
64b87c
+++ b/modules.d/40network/net-lib.sh
64b87c
@@ -486,7 +486,11 @@ parse_ifname_opts() {
64b87c
 wait_for_if_link() {
64b87c
     local cnt=0
64b87c
     local li
64b87c
-    while [ $cnt -lt 600 ]; do
64b87c
+    local timeout="$(getargs rd.net.timeout.iflink=)"
64b87c
+    timeout=${timeout:-60}
64b87c
+    timeout=$(($timeout*10))
64b87c
+
64b87c
+    while [ $cnt -lt $timeout ]; do
64b87c
         li=$(ip -o link show dev $1 2>/dev/null)
64b87c
         [ -n "$li" ] && return 0
64b87c
         sleep 0.1
64b87c
@@ -498,7 +502,11 @@ wait_for_if_link() {
64b87c
 wait_for_if_up() {
64b87c
     local cnt=0
64b87c
     local li
64b87c
-    while [ $cnt -lt 200 ]; do
64b87c
+    local timeout="$(getargs rd.net.timeout.ifup=)"
64b87c
+    timeout=${timeout:-20}
64b87c
+    timeout=$(($timeout*10))
64b87c
+
64b87c
+    while [ $cnt -lt $timeout ]; do
64b87c
         li=$(ip -o link show up dev $1)
64b87c
         [ -n "$li" ] && [ -z "${li##*state UP*}" ] && return 0
64b87c
         sleep 0.1
64b87c
@@ -509,7 +517,11 @@ wait_for_if_up() {
64b87c
 
64b87c
 wait_for_route_ok() {
64b87c
     local cnt=0
64b87c
-    while [ $cnt -lt 200 ]; do
64b87c
+    local timeout="$(getargs rd.net.timeout.route=)"
64b87c
+    timeout=${timeout:-20}
64b87c
+    timeout=$(($timeout*10))
64b87c
+
64b87c
+    while [ $cnt -lt $timeout ]; do
64b87c
         li=$(ip route show)
64b87c
         [ -n "$li" ] && [ -z "${li##*$1*}" ] && return 0
64b87c
         sleep 0.1
64b87c
@@ -521,7 +533,11 @@ wait_for_route_ok() {
64b87c
 wait_for_ipv6_dad() {
64b87c
     local cnt=0
64b87c
     local li
64b87c
-    while [ $cnt -lt 500 ]; do
64b87c
+    local timeout="$(getargs rd.net.timeout.ipv6dad=)"
64b87c
+    timeout=${timeout:-50}
64b87c
+    timeout=$(($timeout*10))
64b87c
+
64b87c
+    while [ $cnt -lt $timeout ]; do
64b87c
         li=$(ip -6 addr show dev $1 scope link)
64b87c
         strstr "$li" "tentative" || return 0
64b87c
         sleep 0.1
64b87c
@@ -533,7 +549,11 @@ wait_for_ipv6_dad() {
64b87c
 wait_for_ipv6_auto() {
64b87c
     local cnt=0
64b87c
     local li
64b87c
-    while [ $cnt -lt 400 ]; do
64b87c
+    local timeout="$(getargs rd.net.timeout.ipv6auto=)"
64b87c
+    timeout=${timeout:-40}
64b87c
+    timeout=$(($timeout*10))
64b87c
+
64b87c
+    while [ $cnt -lt $timeout ]; do
64b87c
         li=$(ip -6 addr show dev $1)
64b87c
         if ! strstr "$li" "tentative"; then
64b87c
             strstr "$li" "dynamic" && return 0
64b87c
@@ -561,8 +581,12 @@ iface_has_link() {
64b87c
     [ -n "$interface" ] || return 2
64b87c
     interface="/sys/class/net/$interface"
64b87c
     [ -d "$interface" ] || return 2
64b87c
+    local timeout="$(getargs rd.net.timeout.carrier=)"
64b87c
+    timeout=${timeout:-5}
64b87c
+    timeout=$(($timeout*10))
64b87c
+
64b87c
     linkup "$1"
64b87c
-    while [ $cnt -lt 50 ]; do
64b87c
+    while [ $cnt -lt $timeout ]; do
64b87c
         [ "$(cat $interface/carrier)" = 1 ] && return 0
64b87c
         sleep 0.1
64b87c
         cnt=$(($cnt+1))