2
0
mirror of https://github.com/openvswitch/ovs synced 2025-08-23 10:28:00 +00:00

38 Commits

Author SHA1 Message Date
Ethan Jackson
97be153858 clang: Add annotations for thread safety check.
This commit adds annotations for thread safety check. And the
check can be conducted by using -Wthread-safety flag in clang.

Co-authored-by: Alex Wang <alexw@nicira.com>
Signed-off-by: Alex Wang <alexw@nicira.com>
Signed-off-by: Ethan Jackson <ethan@nicira.com>
Signed-off-by: Ben Pfaff <blp@nicira.com>
2013-07-30 21:30:45 -07:00
Ben Pfaff
0bd01224dc netlink-socket: Make thread-safe.
The uses of vlog in this module are not thread-safe, because vlog itself
is not yet thread-safe.

Signed-off-by: Ben Pfaff <blp@nicira.com>
2013-07-18 13:18:47 -07:00
Ben Pfaff
a88b4e0412 netlink-socket: Simplify use of transactions and dumps.
This disentangles "struct nl_dump" from "struct nl_sock", clearing the way
to make the use of either one thread-safe in an obviously correct manner.

Signed-off-by: Ben Pfaff <blp@nicira.com>
2013-07-18 13:18:46 -07:00
Ben Pfaff
bef3083859 stress: Remove essentially unused library.
The "stress" library was introduced years ago.  We intended at the time to
start using it to provoke errors in testing, to make sure that Open vSwitch
was resilient against those errors.  The intention was good, but there were
few actual implementations of stress options, and the testing never
materialized.

Rather than adapt the stress library for thread safety, this seems like a
good opportunity to remove it, so this commit does so.

Signed-off-by: Ben Pfaff <blp@nicira.com>
2013-07-15 11:07:25 -07:00
Ben Pfaff
10a89ef04d Replace all uses of strerror() by ovs_strerror(), for thread safety.
Signed-off-by: Ben Pfaff <blp@nicira.com>
2013-06-28 16:09:38 -07:00
Ben Pfaff
488232b7ec netlink-socket: Use xmalloc() instead of malloc().
This was the only obvious use of bare malloc() in the tree, other
than in the implementation of wrapper functions.

Signed-off-by: Ben Pfaff <blp@nicira.com>
2013-04-29 15:05:56 -07:00
Ben Pfaff
0d121c7350 netlink-socket: Minor style fix.
Signed-off-by: Ben Pfaff <blp@nicira.com>
2013-04-29 15:05:56 -07:00
Ansis Atteka
f28b6dd3f4 netlink-socket: Don't bother logging SO_RCVBUFFORCE failure
This patch fixes tests when they are run with "fakeroot debian/rules binary"
command.

The problem was that under fakeroot setsockopt() call could still return
EPERM and lead to a warning message being logged.

Signed-off-by: Ansis Atteka <aatteka@nicira.com>
2013-04-11 11:33:24 -07:00
Ben Pfaff
80af5ee5a5 netlink-socket: Don't bother logging SO_RCVBUFFORCE failure as non-root.
Some Open vSwitch utilities can do useful work when they are not run as
root.  Without this commit, these utilities will log a warning on failure
to use the SO_RCVBUFFORCE socket option if they open any Netlink sockets.
This will always happen, it does not report anything unexpected or
fixable as non-root, and sometimes it makes users wonder if something is
wrong, so there is no benefit to logging it.  This commit drops it in that
case.

Signed-off-by: Ben Pfaff <blp@nicira.com>
2013-02-01 10:33:50 -08:00
Ben Pfaff
cb22974d77 Replace most uses of assert by ovs_assert.
This is a straight search-and-replace, except that I also removed #include
<assert.h> from each file where there were no assert calls left.

Signed-off-by: Ben Pfaff <blp@nicira.com>
Acked-by: Ethan Jackson <ethan@nicira.com>
2013-01-16 16:03:37 -08:00
Ben Pfaff
ebc56baa41 util: New macro CONST_CAST.
Casts are sometimes necessary.  One common reason that they are necessary
is for discarding a "const" qualifier.  However, this can impede
maintenance: if the type of the expression being cast changes, then the
presence of the cast can hide a necessary change in the code that does the
cast.  Using CONST_CAST, instead of a bare cast, makes these changes
visible.

Inspired by my own work elsewhere:
http://git.savannah.gnu.org/cgit/pspp.git/tree/src/libpspp/cast.h#n80

Signed-off-by: Ben Pfaff <blp@nicira.com>
2012-08-03 13:33:13 -07:00
Ben Pfaff
ff459dd649 ovs-brcompatd: Fix sending replies to kernel requests.
Commit 7d7447 (netlink: Postpone choosing sequence numbers until send
time.) broke ovs-brcompatd because it prevented userspace replies to
kernel requests from using the correct sequence numbers.  This commit fixes
it.

Atzm Watanabe found the root cause and provided an alternative patch to
avoid the problem.

Reported-by: André Ruß <andre.russ@hybris.com>
Reported-by: Atzm Watanabe <atzm@stratosphere.co.jp>
Tested-by: Atzm Watanabe <atzm@stratosphere.co.jp>
Signed-off-by: Ben Pfaff <blp@nicira.com>
2012-07-05 08:41:03 -07:00
Raju Subramanian
e0edde6fee Global replace of Nicira Networks.
Replaced all instances of Nicira Networks(, Inc) to Nicira, Inc.

Feature #10593
Signed-off-by: Raju Subramanian <rsubramanian@nicira.com>
Signed-off-by: Ben Pfaff <blp@nicira.com>
2012-05-02 17:08:02 -07:00
Ben Pfaff
72d32ac0b3 netlink-socket: Make caller provide message receive buffers.
Typically an nl_sock client can stack-allocate the buffer for receiving
a Netlink message, which provides a performance boost.

Signed-off-by: Ben Pfaff <blp@nicira.com>
2012-04-18 20:28:48 -07:00
Ben Pfaff
7d7447df77 netlink: Postpone choosing sequence numbers until send time.
Choosing sequence numbers at time of creating a packet means that
nl_sock_transact_multiple() has to search for the sequence number
of a reply, because the sequence numbers of the requests aren't
necessarily sequential.  This commit makes it possible to avoid
the search, by deferring choice of sequence numbers until the
time that we send the packets.  It doesn't actually modify
nl_sock_transact_multiple(), which will happen in a later commit.

Previously, I was concerned about a theoretical race condition
described in a comment in the old versino of this code:

    This implementation uses sequence numbers that are unique
    process-wide, to avoid a hypothetical race: send request, close
    socket, open new socket that reuses the old socket's PID value,
    send request on new socket, receive reply from kernel to old
    socket but with same PID and sequence number.  (This race could be
    avoided other ways, e.g. by preventing PIDs from being quickly
    reused).

However, I no longer believe that this can be a real problem,
because Netlink operates synchronously.  The reply to a request
will always arrive before the socket can be closed and a new
socket opened with the old socket's PID.

Signed-off-by: Ben Pfaff <blp@nicira.com>
2012-04-18 20:28:46 -07:00
Ben Pfaff
407556ac6c netlink-socket: Avoid forcing a reply for final message in a transaction.
Signed-off-by: Ben Pfaff <blp@nicira.com>
2012-04-18 20:28:41 -07:00
Ben Pfaff
d2b9f5b017 netlink-socket: Increase Netlink socket receive buffer size.
Open vSwitch userspace can set up flows at a high rate, but it is somewhat
"bursty" in opportunities to set up flows, by which I mean that OVS sets up
a batch of flows, then goes off and does some other work for a while, then
sets up another batch of flows, and so on.  The result is that, if a large
number of packets that need flow setups come in all at once, then some of
them can overflow the relatively small kernel-to-user buffers.

This commit increases the kernel-to-user buffers from the default of
approximately 120 kB each to 1 MB each.  In one somewhat synthetic test
case that I ran based on an "hping3" that generated a load of about 20,000
new flows per second (including both requests and replies), this reduced
the packets dropped at the kernel-to-user interface from about 30% to none.
I expect that it will similarly improve packet loss in workloads where
flow arrival is not easily predictable.

(This has little effect on workloads generated by "ovs-benchmark rate"
because that benchmark is effectively "self-clocking", that is, a new flow
is triggered only by a reply to a request made earlier, which means that
the number of buffered packets at any given has a known, constant upper
limit.)

Bug #10210.
Signed-off-by: Ben Pfaff <blp@nicira.com>
2012-03-15 21:15:38 -07:00
Ben Pfaff
2c5a683451 netlink-socket: Let the kernel choose Netlink pids for us.
The Netlink code in the Linux kernel has been willing to choose unique
Netlink pids for userspace sockets since at least 2.4.36 and probably
earlier.  There's no value in choosing them ourselves.

This simplifies the code and eliminates the possibility of exhausting our
supply of Netlink PIDs.
2011-11-28 12:16:48 -08:00
Ben Pfaff
8522ba0996 dpif-linux: Use poll() internally in dpif_linux_recv().
Using poll() internally in dpif_linux_recv(), instead of relying
on the results of the main loop poll() call, brings netperf CRR
performance back within 1% of par versus the code base before the
poll_fd_woke() optimizations were introduced.  It also increases
the ovs-benchmark results by about 5% versus that baseline, too.

My theory is that this is because the main loop takes long enough
that a significant number of packets can arrive during the main
loop itself, so this reduces the time before OVS gets to those
packets.
2011-11-28 09:29:18 -08:00
Ben Pfaff
3907401ce6 Revert "poll-loop: Enable checking whether a FD caused a wakeup."
This reverts commit 1e276d1a10539a8cd97d2ad63c073a9a43f0f1ef.
The poll_fd_woke() and nl_sock_woke() function added in that commit are
no longer used, so there is no reason to keep them in the tree.
2011-11-28 09:19:48 -08:00
Ben Pfaff
cc75061af7 netlink-socket: New function nl_sock_transact_multiple().
This will be used in an upcoming commit.
2011-10-14 14:08:44 -07:00
Ben Pfaff
6d23c6f422 netlink: New macros NL_NESTED_FOR_EACH, NL_NESTED_FOR_EACH_UNSAFE.
Upcoming commits will introduce more users.
2011-10-11 10:37:25 -07:00
Jesse Gross
1e276d1a10 poll-loop: Enable checking whether a FD caused a wakeup.
Each time we run through the poll loop, we check all file descriptors
that we were waiting on to see if there is data available.  However,
this requires a system call and poll already provides information on
which FDs caused the wakeup so it is inefficient as the number of
active FDs grows.  This provides a way to check whether a given FD
has data.
2011-09-23 15:27:49 -07:00
Jesse Gross
50802adb0e netlink: Expose method to get Netlink pid of a socket.
In the future, the kernel will use unicast messages instead of
multicast to send upcalls.  As a result, we need to be able to
tell it where to direct the traffic.  This adds a function to expose
the Netlink pid of a socket so it can be included in messages to the
kernel.
2011-09-23 15:27:48 -07:00
Ben Pfaff
a838c4fe1d netlink-socket: Async notifications are incompatible with other operations.
A Netlink socket that receives asynchronous notifications (e.g. from a
multicast group) cannot be used for transactions or dumps, because those
operations would discard asynchronous messages that arrive while waiting
for replies.

This commit documents this issue in a comment on nl_sock_join_mcgroup().
It also removes an internal attempt to avoid mixing multicast reception
with other operations.  The attempt was incomplete, because it only
handled dumps even though ordinary transactions are also problematic.  It
seems better to remove it than to fix it because, first, all of the
existing users in OVS already separate multicast reception from other
operations and, second, an upcoming commit will start using unicast
Netlink for asynchronous notifications, which has the same issues but
doesn't use nl_sock_join_mcgroup().
2011-09-22 11:36:39 -07:00
Ben Pfaff
0428ae5f7b netlink-socket: Fix typo in comment. 2011-09-21 21:38:44 -07:00
Ethan Jackson
213a13ed77 dpif-linux: Handle nl_lookup_genl_mcgroup() failures.
The nl_lookup_genl_mcgroup() function can fail on older kernels
which do not support the required netlink interface.  Before this
patch, dpif-linux would refuse to create a datapath when this
happened.  With this patch, it attempts to use a workaround.  If
the workaround fails it simply disables the affected features
without completely disabling the dpif.
2011-09-16 11:22:30 -07:00
Ben Pfaff
2a477244f7 netlink-socket: Avoid use-after-free in nl_lookup_genl_mcgroup().
Commit e408762f "netlink-socket: New function nl_lookup_genl_mcgroup()"
modified do_lookup_genl_family() to return the Netlink attributes to the
caller, but it still freed the Netlink message itself, which meant that
the attributes pointed into freed memory.  This commit fixes the problem.

This commit is not a minimal fix.  It refactors do_lookup_genl_family(),
changing the return value from "negative errno value or positive genl
family id" to the more common "zero or positive errno value".

Found by valgrind.
2011-09-09 16:40:16 -07:00
Ethan Jackson
e408762f5d netlink-socket: New function nl_lookup_genl_mcgroup(). 2011-09-01 17:18:52 -07:00
Ben Pfaff
fc999dda6a netlink-socket: Reduce nl_sock_recv() from 2 (or more) system calls to 1.
Until now, each attempt to receive a message from a Netlink socket has
taken at least two system calls, one to check the size of the message to
be received and a second one to delete the message from the socket buffer.
This commit switches to a new strategy that requires only one system call
per message received.

In my testing this increases the maximum flow setups per second by a little
over 10%.
2011-07-27 14:56:03 -07:00
Ben Pfaff
5e9fd01b6e netlink-socket: Remove unused nl_sock_sendv() function.
This function hasn't been used for ages.
2011-07-27 14:50:23 -07:00
Ben Pfaff
2ad204c863 netlink-socket: Log Generic Netlink family names.
The ids for Generic Netlink family names aren't very helpful because they
can vary from machine to machine and even from one boot to the next.  So
this change logs their names too.

This only affects logging at DBG level.

Reviewed by Ethan Jackson <ethan@nicira.com>.
2011-01-27 09:26:06 -08:00
Ben Pfaff
727ef33f12 netlink-socket: Consistently log sequence numbers in hexadecimal.
nlmsghdr_to_string() wrote sequence numbers in hex, but nl_sock_transact()
wrote them in decimal.  This consistently switches to hexadecimal.

Reviewed by Ethan Jackson <ethan@nicira.com>.
2011-01-27 09:26:06 -08:00
Ben Pfaff
c6eab56db4 netlink-socket: Make dumping and doing transactions on same nl_sock safe.
It's not safe to use a single Netlink fd to do multiple operations in an
synchronous way.  Some of the limitations are fundamental; for example, the
kernel only supports a single "dump" operation at a time.  Others are
limitations imposed by the OVS coding style; for example, our Netlink
library is not callback based, so nothing can be done about incoming
messages that can't be handled immediately.  Regardless, in OVS multicast
groups, transactions, and dumps cannot coexist on a single nl_sock.

This is only mildly irritating at the moment, but it will become much worse
later on, when dpif-linux shifts to using Netlink dumps for listing various
kinds of datapath entities.  When that happens, a dump will be in progress
in situations where the dpif-linux client might want to do other
operations.  For example, it is reasonable for the client to list flows
and, in the middle, look up information on vports mentioned in those flows.
It might be possible to simply ban and avoid such nested operations--I have
not even audited the source tree to find out whether we do anything like
that already--but that seems like an unnecessary cramp on our coding style.
Furthermore, it's difficult to explain and justify without understanding
the implementation.

This patch takes another approach, by improving the Netlink socket library
to avoid artificial constraints.  When an operation, or a dump, or joining
a multicast group would cause a problem, this patch makes the library
transparently create a separate Netlink socket.  This solves the problem
without putting any onerous restrictions on use.

This commit also slightly simplifies netdev_vport_reset_names().  It had
been written to destroy the dump object before the Netlink socket that it
used, but this is no longer necessary and doing it in the opposite order
saved a few lines of code.

Reviewed by Ethan Jackson <ethan@nicira.com>.
2011-01-27 09:26:06 -08:00
Ben Pfaff
7041c3a9b0 netlink-socket: Slightly improve logging of Generic Netlink messages.
This makes the stream of requests and replies very slightly easier to
understand.

Reviewed by Justin Pettit.
2011-01-27 09:26:05 -08:00
Ben Pfaff
6b7c12fdc1 netlink-socket: New function for draining the receive buffer.
This will be used in an upcoming patch.

Reviewed by Justin Pettit.
2011-01-27 09:26:05 -08:00
Ben Pfaff
cceb11f5b1 netlink-socket: Add functions for joining and leaving multicast groups.
When this library was originally implemented, support for Linux 2.4 was
important.  The Netlink implementation in Linux only added support for
joining and leaving multicast groups after a socket is bound as of Linux
2.6.14, so the library did not support it either.  But the current version
of Open vSwitch targets Linux 2.6.18 and over, so it's fine to add this
support now, and this commit does so.

This will be used more extensively in upcoming commits.

Reviewed by Justin Pettit.
2011-01-27 09:26:05 -08:00
Ben Pfaff
2fe27d5ad2 netlink: Split into generic and Linux-specific parts.
The parts of the netlink module that are related to sockets are
Linux-specific, since only Linux has AF_NETLINK sockets.  The rest can be
built anywhere.  This commit breaks them into two modules, and builds the
generic one on all platforms.

Acked-by: Jesse Gross <jesse@nicira.com>
2010-12-10 11:13:27 -08:00