Merge commit 'b5d57fc87925cb3c029de19d0a94de5ca07ae28e'
[sliver-openvswitch.git] / utilities / ovs-ctl.in
index dd958a2..1f10491 100755 (executable)
@@ -30,7 +30,7 @@ done
 ## start ##
 ## ----- ##
 
-insert_openvswitch_mod_if_required () {
+insert_mod_if_required () {
     # If openvswitch is already loaded then we're done.
     test -e /sys/module/openvswitch -o -e /sys/module/openvswitch_mod && \
      return 0
@@ -52,12 +52,8 @@ insert_openvswitch_mod_if_required () {
     action "Inserting openvswitch module" modprobe openvswitch
 }
 
-insert_mod_if_required () {
-    insert_openvswitch_mod_if_required || return 1
-}
-
 ovs_vsctl () {
-    ovs-vsctl --no-wait --timeout=5 "$@"
+    ovs-vsctl --no-wait "$@"
 }
 
 ovsdb_tool () {
@@ -157,7 +153,7 @@ set_system_ids () {
 
 check_force_cores () {
     if test X"$FORCE_COREFILES" = Xyes; then
-        ulimit -Sc 67108864
+        ulimit -c 67108864
     fi
 }
 
@@ -188,7 +184,6 @@ start_ovsdb () {
         done
         set "$@" -vconsole:emer -vsyslog:err -vfile:info
         set "$@" --remote=punix:"$DB_SOCK"
-        set "$@" --remote=db:Open_vSwitch,Open_vSwitch,manager_options
         set "$@" --private-key=db:Open_vSwitch,SSL,private_key
         set "$@" --certificate=db:Open_vSwitch,SSL,certificate
         set "$@" --bootstrap-ca-cert=db:Open_vSwitch,SSL,ca_cert
@@ -229,6 +224,17 @@ start_forwarding () {
            fi
            start_daemon "$OVS_VSWITCHD_PRIORITY" "$OVS_VSWITCHD_WRAPPER" "$@"
     fi
+
+    # Now that ovs-vswitchd has started and completed its initial
+    # configuration, tell ovsdb-server to conenct to the remote managers.  We
+    # used to do this at ovsdb-server startup time, but waiting for
+    # ovs-vswitchd to finish configuring means that remote managers see less
+    # churn in the database at startup or restart.  (For example, managers
+    # won't briefly see empty datapath-id or ofport columns for records that
+    # exist at startup.)
+    action "Enabling remote OVSDB managers" \
+       ovs-appctl -t ovsdb-server ovsdb-server/add-remote \
+           db:Open_vSwitch,Open_vSwitch,manager_options
 }
 
 ## ---- ##
@@ -285,8 +291,6 @@ save_ofports_if_required () {
             action "Saving ofport values" ovs_save save-ofports \
                 "${script_ofports}"
             ;;
-        *)
-            ;;
     esac
 }
 
@@ -315,7 +319,7 @@ restore_interfaces () {
         level=err
     fi
     log="logger -p daemon.$level -t ovs-save"
-    $log "force-reload-kmod interface restore script exited with status $rc:"
+    $log "interface restore script exited with status $rc:"
     $log -f "$script_interfaces"
 }
 
@@ -379,13 +383,25 @@ force_reload_kmod () {
 ## restart ##
 ## ------- ##
 
+save_interfaces_if_required () {
+    # Save interfaces if we are upgrading from a pre-1.10 branch.
+    case `ovs-appctl version | sed 1q` in
+        "ovs-vswitchd (Open vSwitch) 1."[0-9].*)
+            ifaces=`internal_interfaces`
+            action "Detected internal interfaces: $ifaces" true
+            if action "Saving interface configuration" save_interfaces; then
+                chmod +x "$script_interfaces"
+            fi
+            ;;
+    esac
+}
+
 restart () {
     if daemon_is_running ovsdb-server && daemon_is_running ovs-vswitchd; then
-        script_flows=`mktemp`
-        trap 'rm -f "${script_flows}"' 0
-
-        action "Saving flows" ovs_save save-flows "${script_flows}" \
-            script_flows
+        init_restore_scripts
+        save_interfaces_if_required
+        action "Saving flows" ovs_save save-flows "${script_flows}"
+        save_ofports_if_required
     fi
 
     # Restart the database first, since a large database may take a
@@ -393,11 +409,18 @@ restart () {
     stop_ovsdb
     start_ovsdb
 
+    # Restore of ofports, if required, should happen before vswitchd is
+    # restarted.
+    restore_ofports
+
     stop_forwarding
     start_forwarding
 
-    # Restore the saved flows. Do not return error if restore fails.
-    restore_flows || true
+    # Restore the saved flows.
+    restore_flows
+
+    # Restore the interfaces if required. Return true even if restore fails.
+    restore_interfaces || true
 }
 
 ## --------------- ##