Merge branch 'mainstream'
[sliver-openvswitch.git] / utilities / ovs-ctl.in
index bce74a6..e186e71 100755 (executable)
@@ -1,5 +1,5 @@
 #! /bin/sh
-# Copyright (C) 2009, 2010, 2011, 2012 Nicira, Inc.
+# Copyright (C) 2009, 2010, 2011, 2012, 2013 Nicira, Inc.
 #
 # Licensed under the Apache License, Version 2.0 (the "License");
 # you may not use this file except in compliance with the License.
@@ -216,8 +216,9 @@ start_forwarding () {
         log_success_msg "ovs-vswitchd is already running"
     else
         # Increase the limit on the number of open file descriptors.
-        # ovs-vswitchd needs 16 per datapath, plus a few extra, so this
-        # should allow for 256 (or more) bridges.
+        # On Linux, ovs-vswitchd needs about one file descriptor per
+        # switch port, so this allows a very large number of switch
+        # ports.
         ulimit -n 5000
 
            # Start ovs-vswitchd.
@@ -267,16 +268,28 @@ internal_interfaces () {
     done
 }
 
-save_flows () {
-   if set X `ovs_vsctl -- --real list-br`; then
-        shift
-        if "$datadir/scripts/ovs-save" save-flows "$@" > "$script_flows"; then
-            chmod +x "$script_flows"
-            return 0
-        fi
+ovs_save () {
+    bridges=`ovs_vsctl -- --real list-br`
+    if [ -n "${bridges}" ] && \
+        "$datadir/scripts/ovs-save" "$1" ${bridges} > "$2"; then
+        chmod +x "$2"
+        return 0
     fi
-    script_flows=
-    return 1
+    eval $3=""
+    [ -z "${bridges}" ] && return 0
+}
+
+save_ofports_if_required () {
+    # Save ofports if we are upgrading from a pre-1.10 branch.
+    case `ovs-appctl version | sed 1q` in
+        "ovs-vswitchd (Open vSwitch) 1."[0-9].*)
+            action "Saving ofport values" ovs_save save-ofports \
+                "${script_ofports}" script_ofports
+            ;;
+        *)
+            script_ofports=""
+            ;;
+    esac
 }
 
 save_interfaces () {
@@ -284,6 +297,11 @@ save_interfaces () {
         > "${script_interfaces}"
 }
 
+restore_ofports () {
+    [ -n "${script_ofports}" ] && \
+        action "Restoring ofport values" "${script_ofports}"
+}
+
 restore_flows () {
     [ -n "${script_flows}" ] && \
         action "Restoring saved flows" "${script_flows}"
@@ -295,15 +313,21 @@ force_reload_kmod () {
 
     script_interfaces=`mktemp`
     script_flows=`mktemp`
-    trap 'rm -f "${script_interfaces}" "${script_flows}" ' 0
+    script_ofports=`mktemp`
+    trap 'rm -f "${script_interfaces}" "${script_flows}" "${script_ofports}"' 0
 
-    action "Saving flows" save_flows
+    action "Saving flows" ovs_save save-flows "${script_flows}" script_flows
+
+    save_ofports_if_required
 
     # Restart the database first, since a large database may take a
     # while to load, and we want to minimize forwarding disruption.
     stop_ovsdb
     start_ovsdb
 
+    # Restore of ofports should happen before vswitchd is restarted.
+    restore_ofports
+
     stop_forwarding
 
     if action "Saving interface configuration" save_interfaces; then
@@ -353,7 +377,8 @@ restart () {
         script_flows=`mktemp`
         trap 'rm -f "${script_flows}"' 0
 
-        action "Saving flows" save_flows
+        action "Saving flows" ovs_save save-flows "${script_flows}" \
+            script_flows
     fi
 
     # Restart the database first, since a large database may take a