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

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