Justin Pettit [Fri, 9 Jan 2009 23:41:42 +0000 (15:41 -0800)]
Add datapath device name to printk's.
To aid debugging, this prints the datapath device name to printk
messages. Not doing this wasn't a big deal when only a single datapath
was running, but it's very confusing when there are multiple.
Ben Pfaff [Fri, 9 Jan 2009 23:18:36 +0000 (15:18 -0800)]
vswitchd: Delete 'ifaces' pointer to interface when deleting interface.
Otherwise we dereference a dangling pointer to the interface when we
look up the interface by datapath port index, causing a segfault.
Introduced in commit 150ac45, "vswitchd: Eliminate "can't forward to bad
port" when interfaces disappear," which deletes an interface that is known
to be in the datapath port index table.
Ben Pfaff [Fri, 9 Jan 2009 20:51:19 +0000 (12:51 -0800)]
vswitchd: Eliminate "can't forward to bad port" when interfaces disappear.
When an interface was deleted from a datapath by a process other than
vswitchd (which is not supposed to happen), vswitchd would not realize it
and would continue to set up flows for that interface (and leave in place
existing flows). This caused the kernel to complain "can't forward to bad
port" for each packet on these flows.
Xen triggered this by destroying vifs that were on vswitchd-controlled
datapaths (which removes them from any datapath that they are on).
This fixes the problem, by making vswitchd notice when interfaces
disappear and fixing up the flow table.
Justin Pettit [Fri, 9 Jan 2009 01:16:33 +0000 (17:16 -0800)]
Add support for sysfs and ethtool.
Add support for sysfs when the bridge compatibility module is running.
Currently, this only works for 2.6.18 kernels. Working on all kernels
should be fixed soon. Also, add ethtool support to the datapath device.
Ben Pfaff [Thu, 8 Jan 2009 22:58:35 +0000 (14:58 -0800)]
Remove 'wait' parameter from dpif_send_openflow().
The 'wait' parameter had no effect (it was not implemented) and it was
only ever set to false. It's easier to simply remove it than to
implement an unneeded feature.
Ben Pfaff [Thu, 8 Jan 2009 20:25:18 +0000 (12:25 -0800)]
datapath: Fix deadlock in switch port removal.
dp_del_switch_port() cancels the port_task and waits for
it to finish, but the port_task requires the RTNL lock
to complete, which dp_del_switch_port() holds, thus a
deadlock.
This commit fixes the problem, by deleting the port_task
entirely and moving its work into secchan.
Ben Pfaff [Thu, 8 Jan 2009 00:57:05 +0000 (16:57 -0800)]
datapath: Avoid deadlock on dp_mutex versus kthread_stop().
When a datapath is deleted, del_dp() acquires dp_mutex and uses
kthread_stop() to wait for the dp_task to die. Meanwhile, dp_task may
be waiting to acquire dp_mutex and won't die until it does so.
This commit fixes the problem by sending SIGKILL to dp_task before
call kthread_stop() and making dp_task give up if it receives a signal.
Ben Pfaff [Wed, 7 Jan 2009 23:19:09 +0000 (15:19 -0800)]
datapath: Fix deadlock in network device notifier.
When a network device that is part of a datapath is destroyed, the
notifier handler in dp_device_event() calls dp_del_switch_port() to
delete the switch port. dp_del_switch_port() then calls rtnl_lock()
to drop the device's promiscuous count. But the RTNL lock has already
been taken at this point, so taking it recursively deadlocks.
The obvious fix is for dp_del_switch_port()'s caller to take the RTNL
lock for it, if it is not already taken. This, however, causes a
different deadlock, as dp_del_switch_port() needs dp_mutex and that
means that we are nesting dp_mutex and the RTNL both ways.
The fix used here is to always nest dp_mutex inside the RTNL lock and
never vice versa.
=============================================
[ INFO: possible recursive locking detected ]
---------------------------------------------
tunctl/2934 is trying to acquire lock:
(rtnl_mutex){--..}, at: [<c029667d>] mutex_lock+0x1c/0x1f
but task is already holding lock:
(rtnl_mutex){--..}, at: [<c029667d>] mutex_lock+0x1c/0x1f
other info that might help us debug this:
1 lock held by tunctl/2934:
#0: (rtnl_mutex){--..}, at: [<c029667d>] mutex_lock+0x1c/0x1f
Problem identified with this script (in conjunction with the brcompat
module):
#! /bin/sh
brctl delbr a
brctl delbr b
brctl delbr c
set -x
stress () {
bridge=$1
shift
while true; do
brctl addbr $bridge; brctl show
for iface
do
case $iface in
tap*) tunctl -t $iface ;;
esac
brctl addif $bridge $iface
done
for iface
do
brctl delif $bridge $iface
case $iface in
tap*) tunctl -d $iface ;;
esac
done
brctl delbr $bridge; brctl show
done
}
stress a tap0 tap1 tap2 &
stress b tap3 tap4 tap5 &
trap 'killall stress-brctl' 0 SIGINT
wait
Ben Pfaff [Sat, 3 Jan 2009 01:26:26 +0000 (17:26 -0800)]
vswitchd: Improve log options passed down to secchan.
Previously, secchan as started by vswitchd would always log to the console.
Now, it logs to the console only if any logging to the console is enabled
for vswitchd.
Previously, secchan as started by vswitchd would never log to a file. Now,
it logs to a file if vswitchd is configured to do so.
Also, use the bridge name in the vlog log pattern, instead of the datapath
number, so that users can more easily relate log messages to bridges.
Ben Pfaff [Sat, 3 Jan 2009 00:10:19 +0000 (16:10 -0800)]
Improve compatibility fallbacks for allocating multicast groups.
The linux-2.6 compatibility code for allocating multicast groups only
allocated a single multicast group per Generic Netlink family. However,
OpenFlow performance is going to be better if we allocate one per OpenFlow
datapath (which are all in the same Generic Netlink family). This commit
implements that.
Ben Pfaff [Sat, 3 Jan 2009 00:13:07 +0000 (16:13 -0800)]
Use separate Netlink multicast groups for different datapaths.
Otherwise every socket that listens for OpenFlow multicast messages will
get them for every single datapath. Not only is that a waste of memory
and time, it also allows one congested bridge to effectively DoS other
bridges that have little traffic.
Ben Pfaff [Fri, 2 Jan 2009 21:58:08 +0000 (13:58 -0800)]
Discard OpenFlow messages not for us in dpif_recv_openflow().
Currently there is only a single Netlink multicast group that is shared
by all OpenFlow datapaths. This is undesirable and should be fixed, but
a solution in every case is impossible due to Linux kernel limitations.
This commit works around the problem by dropping OpenFlow messages that
are related to a datapath that we are not interested in.
This should fix vswitchd behavior when more than one bridge is configured.
Thanks to Keith and Justin for diagnosing the problem.
Justin Pettit [Wed, 31 Dec 2008 18:55:13 +0000 (10:55 -0800)]
Return meaningful errors for brctl modification commands.
When datapaths and interfaces are modified, we now do more thorough
checks to see whether they will succeed or not. When datapaths are
added, we now block until they are created, so that follow-on ioctl
calls to attach interfaces will immediately work.
Justin Pettit [Wed, 31 Dec 2008 06:31:38 +0000 (22:31 -0800)]
Add support for "brctl show".
This makes datapaths and their interfaces show up as you'd expect when
"brctl show" is run. To get this functionality, you must insmod the
brcompat kernel module.
Ben Pfaff [Tue, 30 Dec 2008 21:25:35 +0000 (13:25 -0800)]
brcompat: Write temporary file to same directory as config file.
Otherwise, we will write it in the current working directory, which will
be / if we're running as a daemon (see daemonize()). We shouldn't assume
that we can write to that directory, and it might not be in the same
file system as the output file anyhow.
Ben Pfaff [Tue, 30 Dec 2008 21:03:48 +0000 (13:03 -0800)]
Properly lock dp_mutex around changes to the datapath.
We weren't locking dp_mutex() here but it really is necessary. See the
comment on dp_mutex itself for details.
This actually restores some of the locking removed by commit 47b8652d
"Simplify use of dp_mutex." That commit is correct that we can take
dp_mutex at a high level in dp_genl_openflow(), but it removes locking
from functions that are not called through dp_genl_openflow(): in
particular any Netlink command other than DP_GENL_C_OPENFLOW does not
go through that function, so those commands need to acquire the mutex
themselves.
Ben Pfaff [Tue, 30 Dec 2008 19:40:22 +0000 (11:40 -0800)]
Fix GNU make warning about overriding commands for a target.
We would add a target to link a C file into datapath directories each
time that file was mentioned in a list of sources, so when we put a source
file into two different lists of sources it got two such targets. Fixed
by using the GNU make $(sort) function to eliminate duplicates.
Ben Pfaff [Tue, 30 Dec 2008 19:31:25 +0000 (11:31 -0800)]
Restore openflow-netlink.h ABI.
Inserting DP_GENL_A_DP_NAME above DP_GENL_A_PORTNAME in commit 660f6596ba31, "First cut at bridge compatibility for vswitchd" forces users
not to use any existing builds of userspace utilities, because the
numbering of all the netlink attributes for OpenFlow has changed. This
change restores the numbering and should make older dpctl, etc. still able
to work.