X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=utilities%2Fovs-ctl.in;h=0735160ae33fbb6a04f4d00b263bf0b05b55f520;hb=cfc50ae514f805dcd9c14589f21158185424daf6;hp=bce74a69345863d6d5ece4e16ed1e6df50361e1c;hpb=5ca1ba484bd9ade5116a49cf241cb98219d7d696;p=sliver-openvswitch.git diff --git a/utilities/ovs-ctl.in b/utilities/ovs-ctl.in index bce74a693..0735160ae 100755 --- a/utilities/ovs-ctl.in +++ b/utilities/ovs-ctl.in @@ -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. @@ -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 @@ -207,6 +202,19 @@ start_ovsdb () { fi } +add_managers () { + # 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 +} + start_forwarding () { check_force_cores @@ -216,9 +224,10 @@ 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. - ulimit -n 5000 + # On Linux, ovs-vswitchd needs about three file descriptors + # per bridge and one file descriptor per bridge port, so this + # allows a very large number of bridges and ports. + ulimit -n 7500 # Start ovs-vswitchd. set ovs-vswitchd unix:"$DB_SOCK" @@ -267,16 +276,24 @@ 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 + [ -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}" + ;; + esac } save_interfaces () { @@ -284,26 +301,64 @@ save_interfaces () { > "${script_interfaces}" } +restore_ofports () { + [ -x "${script_ofports}" ] && \ + action "Restoring ofport values" "${script_ofports}" +} + +flow_restore_wait () { + ovs_vsctl set open_vswitch . other_config:flow-restore-wait="true" +} + +flow_restore_complete () { + ovs_vsctl --if-exists remove open_vswitch . other_config \ + flow-restore-wait="true" +} + restore_flows () { - [ -n "${script_flows}" ] && \ + [ -x "${script_flows}" ] && \ action "Restoring saved flows" "${script_flows}" } +restore_interfaces () { + [ ! -x "${script_interfaces}" ] && return 0 + action "Restoring interface configuration" "${script_interfaces}" + rc=$? + if test $rc = 0; then + level=debug + else + level=err + fi + log="logger -p daemon.$level -t ovs-save" + $log "interface restore script exited with status $rc:" + $log -f "$script_interfaces" +} + +init_restore_scripts () { + script_interfaces=`mktemp` + script_flows=`mktemp` + script_ofports=`mktemp` + trap 'rm -f "${script_interfaces}" "${script_flows}" "${script_ofports}"' 0 +} + force_reload_kmod () { ifaces=`internal_interfaces` action "Detected internal interfaces: $ifaces" true - script_interfaces=`mktemp` - script_flows=`mktemp` - trap 'rm -f "${script_interfaces}" "${script_flows}" ' 0 + init_restore_scripts + + action "Saving flows" ovs_save save-flows "${script_flows}" - action "Saving flows" save_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 @@ -311,6 +366,7 @@ force_reload_kmod () { else log_warning_msg "Failed to save configuration, not replacing kernel module" start_forwarding + add_managers exit 1 fi chmod +x "$script_interfaces" @@ -326,20 +382,16 @@ force_reload_kmod () { action "Removing openvswitch module" rmmod openvswitch fi + # Start vswitchd by asking it to wait till flow restore is finished. + flow_restore_wait start_forwarding + # Restore saved flows and inform vswitchd that we are done. restore_flows + flow_restore_complete + add_managers - action "Restoring interface configuration" "$script_interfaces" - rc=$? - if test $rc = 0; then - level=debug - else - level=err - fi - log="logger -p daemon.$level -t ovs-save" - $log "force-reload-kmod interface restore script exited with status $rc:" - $log -f "$script_interfaces" + restore_interfaces "$datadir/scripts/ovs-check-dead-ifs" } @@ -348,12 +400,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" save_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 @@ -361,11 +426,23 @@ restart () { stop_ovsdb start_ovsdb + # Restore of ofports, if required, should happen before vswitchd is + # restarted. + restore_ofports + stop_forwarding + + # Start vswitchd by asking it to wait till flow restore is finished. + flow_restore_wait start_forwarding - # Restore the saved flows. Do not return error if restore fails. - restore_flows || true + # Restore saved flows and inform vswitchd that we are done. + restore_flows + flow_restore_complete + add_managers + + # Restore the interfaces if required. Return true even if restore fails. + restore_interfaces || true } ## --------------- ## @@ -609,6 +686,7 @@ case $command in start) start_ovsdb start_forwarding + add_managers ;; stop) stop_forwarding