PRIORITY="${PRIORITY:--5}"
MEMLEAK_LOG="${MEMLEAK_LOG:-}"
+# --- Debugging startup options ---
+#
+# These should not generally be used since it requires vswitchd to run
+# in the foreground which is not really what you want in an init
+# script. Used by the restart-valgrind and restart-strace commands
+
+STRACE_LOG="${STRACE_LOG:-}"
+STRACE_OPT="${STRACE_OPT:-}"
+VALGRIND_LOG="${VALGRIND_LOG:-}"
+VALGRIND_OPT="${VALGRIND_OPT:-}"
+
VSWITCH_BASE=/root/vswitch/openflow/build
VSWITCHD_CONF=/etc/vswitchd.conf
VSWITCHD_LOG=/var/log/vswitchd.log
+function dp_list {
+ $VSWITCH_BASE/utilities/dpctl showdp | grep '^dp[0-9]\+:' | cut -d':' -f 1
+}
+
function dp_intf {
- $VSWITCH_BASE/utilities/dpctl show nl:$1 | grep '^ LOCAL(' | cut -d'(' -f2 | cut -d')' -f1
+ local dp=$1
+ # Currently port0 is hardcoded to be the local port.
+ $VSWITCH_BASE/utilities/dpctl showdp $dp | grep 'port 0:' | cut -d' ' -f 3
}
function clear_old_bridge_ports {
}
function start {
- if ! lsmod | grep -q "openflow_mod"; then
- action "Inserting openflow module" insmod $VSWITCH_BASE/datapath/linux-2.6/openflow_mod.ko
- fi
- if ! lsmod | grep -q "brcompat_mod"; then
- action "Inserting brcompat module" insmod $VSWITCH_BASE/datapath/linux-2.6/brcompat_mod.ko
- fi
+ if ! lsmod | grep -q "openflow_mod"; then
+ action "Inserting openflow module" insmod $VSWITCH_BASE/datapath/linux-2.6/openflow_mod.ko
+ fi
+ if ! lsmod | grep -q "brcompat_mod"; then
+ action "Inserting brcompat module" insmod $VSWITCH_BASE/datapath/linux-2.6/brcompat_mod.ko
+ fi
ulimit -c unlimited # Ensure core dump on crash. Will be in '/'.
local syslog_opt="-vANY:SYSLOG:${SYSLOG_LOGLEVEL}"
local logfile_file_opt=""
mv "$MEMLEAK_LOG" "$MEMLEAK_LOG.prev"
fi
fi
- [ "$1" = "restart" ] || clear_old_bridge_ports
- action "Starting vswitchd" nice -n "$PRIORITY" $VSWITCH_BASE/vswitchd/vswitchd -P/var/run/vswitchd.pid -D -vANY:CONSOLE:EMER $syslog_opt $logfile_level_opt $logfile_file_opt --brcompat $leak_opt "$VSWITCHD_CONF"
- if [ "$1" = "restart" ]; then
+ local strace_opt=""
+ local daemonize_opt="-D"
+ if [ -n "$STRACE_LOG" ] && [ -n "$VALGRIND_LOG" ]; then
+ printf "Can not start with both VALGRIND and STRACE\n"
+ exit 1
+ fi
+ if [ -n "$STRACE_LOG" ]; then
+ strace_opt="strace -o $STRACE_LOG $STRACE_OPT"
+ daemonize_opt=""
+ fi
+ if [ -n "$VALGRIND_LOG" ]; then
+ valgrind_opt="valgrind --log-file=$VALGRIND_LOG $VALGRIND_OPT"
+ daemonize_opt=""
+ fi
+ [ "$1" = "update-modules" ] || [ "$1" = "restart" ] || clear_old_bridge_ports
+ action "Starting vswitchd" nice -n "$PRIORITY" $strace_opt $valgrind_opt $VSWITCH_BASE/vswitchd/vswitchd -P/var/run/vswitchd.pid $daemonize_opt -vANY:CONSOLE:EMER $syslog_opt $logfile_level_opt $logfile_file_opt --brcompat $leak_opt "$VSWITCHD_CONF"
+ if [ "$1" = "update-modules" ]; then
sleep 2 # Give time for vswitch to get up and running.
- i=0
- while test $i -lt 256; do
- if $VSWITCH_BASE/utilities/dpctl show nl:$i >/dev/null 2>&1; then
- intf=$(dp_intf $i)
- if [ -e "/etc/sysconfig/network-scripts/ifcfg-$intf" ]; then
- action "Bringing up datapath interface: $intf" ifup "$intf"
- fi
+ for dp in $(dp_list); do
+ local intf=$(dp_intf $dp)
+ if [ -e "/etc/sysconfig/network-scripts/ifcfg-$intf" ]; then
+ action "Bringing up datapath interface: $intf" ifup "$intf"
fi
- i=$((i + 1))
done
fi
}
function stop {
if [ -f /var/run/vswitchd.pid ]; then
- action "Killing vswitchd" kill -TERM $(cat /var/run/vswitchd.pid)
+ local pid=$(cat /var/run/vswitchd.pid)
+ action "Killing vswitchd ($pid)" kill -TERM $pid
fi
if [ -e /var/run/vswitchd.pid ]; then
rm -f /var/run/vswitchd.pid
fi
- if [ "$1" = "restart" ]; then
- i=0
- while test $i -lt 256; do
- if $VSWITCH_BASE/utilities/dpctl show nl:$i >/dev/null 2>&1; then
- intf=$(dp_intf $i)
- if [ -e "/etc/sysconfig/network-scripts/ifcfg-$intf" ]; then
- action "Shutting down datapath interface: $intf" ifdown "$intf"
- fi
- action "Removing openflow datapath $i" $VSWITCH_BASE/utilities/dpctl deldp nl:$i
+ if [ "$1" = "update-modules" ]; then
+ for dp in $(dp_list); do
+ local intf=$(dp_intf $dp)
+ action "Removing datapath: $dp" $VSWITCH_BASE/utilities/dpctl deldp $dp
+ if [ -e "/etc/sysconfig/network-scripts/ifcfg-$intf" ]; then
+ action "Shutting down datapath interface: $intf" ifdown "$intf"
fi
- i=$((i + 1))
done
action "Removing brcompat module" rmmod brcompat_mod.ko
action "Removing openflow module" rmmod openflow_mod.ko
stop
;;
restart)
- stop restart
+ stop
start restart
;;
+ restart-strace)
+ shift
+ stop
+ STRACE_LOG="/var/log/vswitchd.strace" STRACE_OPT="$*" start restart
+ ;;
+ restart-valgrind)
+ shift
+ stop
+ VALGRIND_LOG="/var/log/vswitchd.valgrind" VALGRIND_OPT="$*" start restart
+ ;;
+ update-modules)
+ stop update-modules
+ start update-modules
+ ;;
reload)
if [ -f /var/run/vswitchd.pid ]; then
kill -HUP $(cat /var/run/vswitchd.pid)
fi
;;
+ strace)
+ shift
+ strace -p $(cat /var/run/vswitchd.pid) "$@"
+ ;;
unload)
- stop restart
+ stop update-modules
;;
status)
status -p vswitchd.pid vswitchd