From: Daniele Di Proietto Date: Wed, 22 Jun 2016 02:27:30 +0000 (-0700) Subject: ovs-lib: Keep internal interface ip during upgrade. X-Git-Url: http://git.cascardo.eti.br/?p=cascardo%2Fovs.git;a=commitdiff_plain;h=a4d04282f12ed20d89edee329c79c84176ad5598 ovs-lib: Keep internal interface ip during upgrade. Commit 9b5422a98f81("ovs-lib: Try to call exit before killing.") introduced a problem where internal interfaces are destroyed and recreated, losing their IP address. Commit 9aad5a5a96ba("ovs-vswitchd: Preserve datapath ports across graceful shutdown.") fixed the problem by changing ovs-vswitchd to preserve the ports on `ovs-appctl exit`. Unfortunately, this fix is not enough during upgrade from <= 2.5.0, where an old ovs-vswitchd is running (without the fix) and a new ovs-lib script is performing the restart. The problem seem to affect both RHEL and ubuntu. This commit fixes the upgrade by looking at the running daemon version and avoid using `ovs-appctl exit` if it's < 2.5.90. Suggested-by: Gurucharan Shetty Signed-off-by: Daniele Di Proietto Acked-by: Gurucharan Shetty Acked-by: Ben Pfaff --- diff --git a/utilities/ovs-lib.in b/utilities/ovs-lib.in index 773efb32c..7fcd73422 100644 --- a/utilities/ovs-lib.in +++ b/utilities/ovs-lib.in @@ -132,6 +132,22 @@ pid_comm_check () { [ "$1" = "`cat /proc/$2/comm`" ] } +# version_geq version_a version_b +# +# Compare (dot separated) version numbers. Returns true (exit code 0) if +# version_a is greater or equal than version_b, otherwise false (exit code 1). +version_geq() { + echo $1 $2 | awk '{ + n1 = split($1, a, "."); + n2 = split($2, b, "."); + n = (n1 > n2) ? n1 : n2; + for (i = 1; i <= n; i++) { + if (a[i]+0 < b[i]+0) exit 1 + if (a[i]+0 > b[i]+0) exit 0 + } + }' +} + start_daemon () { priority=$1 wrapper=$2 @@ -202,10 +218,23 @@ start_daemon () { stop_daemon () { if test -e "$rundir/$1.pid"; then if pid=`cat "$rundir/$1.pid"`; then - for action in EXIT .1 .25 .65 1 \ - TERM .1 .25 .65 1 1 1 1 \ - KILL 1 1 1 2 10 15 30 \ - FAIL; do + + graceful="EXIT .1 .25 .65 1" + actions="TERM .1 .25 .65 1 1 1 1 \ + KILL 1 1 1 2 10 15 30 \ + FAIL" + version=`ovs-appctl -T 1 -t $rundir/$1.$pid.ctl version \ + | awk 'NR==1{print $NF}'` + + # Use `ovs-appctl exit` only if the running daemon version + # is >= 2.5.90. This script might be used during upgrade to + # stop older versions of daemons which do not behave correctly + # with `ovs-appctl exit` (e.g. ovs-vswitchd <= 2.5.0 deletes + # internal ports). + if version_geq "$version" "2.5.90"; then + actions="$graceful $actions" + fi + for action in $actions; do if pid_exists "$pid" >/dev/null 2>&1; then :; else return 0 fi