Blame 0104-network-add-options-to-tweak-timeouts.patch

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