Change in vdsm[ovirt-3.5]: init: wait for network service

danken at redhat.com danken at redhat.com
Thu Jan 8 16:18:08 UTC 2015


Hello Douglas Schilling Landgraf, Ido Barkan, Petr Horáček,

I'd like you to do a code review.  Please visit

    http://gerrit.ovirt.org/36703

to review the following change.

Change subject: init: wait for network service
......................................................................

init: wait for network service

The network service is not synchronous. It returns before all of the
interfaces that it started are actually up.

This is particularly problematic when upgrading from ovirt-3.4 to
ovirt-3.5, as one of the first pre-run tasks is to upgrade network
configuration to the "unified persistence" model.

This patch waits up to 10 seconds for vdsm-controlled interfaces to
obtain their IPv4 address. It's a hack, an ugly hack, that does not solve
the inherent race. The race would be solved only when we tap into
netlink's event monitor and stall ifup until the interface is actually
up.

Change-Id: I89abe7a83673c2232f8b249f23a39e27e01e50be
Bug-Url: https://bugzilla.redhat.com/1174611
Signed-off-by: Dan Kenigsberg <danken at redhat.com>
Reviewed-on: http://gerrit.ovirt.org/36647
Reviewed-by: Ido Barkan <ibarkan at redhat.com>
Reviewed-by: Petr Horáček <phoracek at redhat.com>
Reviewed-by: Douglas Schilling Landgraf <dougsland at redhat.com>
Tested-by: Douglas Schilling Landgraf <dougsland at redhat.com>
---
M init/vdsmd_init_common.sh.in
1 file changed, 61 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/03/36703/1

diff --git a/init/vdsmd_init_common.sh.in b/init/vdsmd_init_common.sh.in
index e637b59..c94639b 100644
--- a/init/vdsmd_init_common.sh.in
+++ b/init/vdsmd_init_common.sh.in
@@ -23,6 +23,66 @@
 prog=vdsm
 
 #### pre-start tasks ####
+_dev_has_ipv4() {
+    local dev="$1"
+    ip -o address show "$dev" | grep -q ' inet '
+}
+
+_all_devs_have_ipv4(){
+    local dev
+
+    for dev in $1
+    do
+        _dev_has_ipv4 "$dev" || return 1
+    done
+    return 0
+}
+
+_wait_for_ipv4() {
+    # wait up to a timeout for all specified devices to have an ipv4 address
+    local i
+
+    for i in `seq 10`
+    do
+        _all_devs_have_ipv4 "$1" && return 0
+        sleep 1
+    done
+    echo "timeout waiting for ipv4 addresses"
+    return 1
+}
+
+task_wait_for_network() {
+    # interfaces that we depend upon may not have their IP address ready yet
+    # see https://bugzilla.redhat.com/show_bug.cgi?id=1174611#c34
+    local interfaces dev static_devs
+
+    pushd /etc/sysconfig/network-scripts/ > /dev/null
+
+    # copied from /etc/init.d/network
+    interfaces=$(ls ifcfg-* | \
+            LC_ALL=C sed -e "$__sed_discard_ignored_files" \
+                   -e '/\(ifcfg-lo$\|:\|ifcfg-.*-range\)/d' \
+                   -e '{ s/^ifcfg-//g;s/[0-9]/ &/}' | \
+            LC_ALL=C sort -k 1,1 -k 2n | \
+            LC_ALL=C sed 's/ //')
+
+    for dev in $interfaces
+    do
+        ifcfg="ifcfg-$dev"
+        grep -q '# Generated by VDSM version' "$ifcfg" || continue
+        grep -q 'ONBOOT=yes' "$ifcfg" || continue
+        grep -q 'IPADDR=' "$ifcfg" || continue
+        static_devs="$static_devs $dev"
+    done
+    popd > /dev/null
+
+    _wait_for_ipv4 "$static_devs"
+
+    # never fail, in order to allow intentionally-downed vdsm-controlled
+    # interfaces
+    return 0
+}
+
 task_configure_coredump() {
     local conf_file="@CONFDIR@/vdsm.conf"
     local getconfitem="@VDSMDIR@/get-conf-item"
@@ -255,6 +315,7 @@
             mkdirs \
             configure_coredump \
             configure_vdsm_logs \
+            wait_for_network \
             run_init_hooks \
             upgraded_version_check \
             check_is_configured \


-- 
To view, visit http://gerrit.ovirt.org/36703
To unsubscribe, visit http://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I89abe7a83673c2232f8b249f23a39e27e01e50be
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: ovirt-3.5
Gerrit-Owner: Dan Kenigsberg <danken at redhat.com>
Gerrit-Reviewer: Douglas Schilling Landgraf <dougsland at redhat.com>
Gerrit-Reviewer: Ido Barkan <ibarkan at redhat.com>
Gerrit-Reviewer: Petr Horáček <phoracek at redhat.com>


More information about the vdsm-patches mailing list