mirror of
https://github.com/openvswitch/ovs
synced 2025-10-29 15:28:56 +00:00
netlink-socket: Simplify multithreaded dumping to match Linux reality.
Commit 0791315e4d (netlink-socket: Work around kernel Netlink dump thread
races.) introduced a simple workaround for Linux kernel races in Netlink
dumps. However, the code remained more complicated than needed. This
commit simplifies it.
The main reason for complication in the code was 'status_seq' in nl_dump.
This member was there to allow a thread to wait for some other thread to
refill the socket buffer with another dump message (although we did not
understand the reason at the time it was introduced). Now that we know
that Netlink dumps properly need to be serialized to work in existing
Linux kernels, there's no additional value in having 'status_seq',
because serialized recvmsg() calls always refill the socket buffer
properly.
This commit updates nl_msg_next() to clear its buffer argument on error.
This is a more convenient interface for the new version of the Netlink
dump code. nl_msg_next() doesn't have any other callers.
Signed-off-by: Ben Pfaff <blp@nicira.com>
This commit is contained in:
@@ -110,12 +110,15 @@ void nl_transact_multiple(int protocol, struct nl_transaction **, size_t n);
|
||||
#define NL_DUMP_BUFSIZE 4096
|
||||
|
||||
struct nl_dump {
|
||||
/* These members are immutable during the lifetime of the nl_dump. */
|
||||
struct nl_sock *sock; /* Socket being dumped. */
|
||||
uint32_t nl_seq; /* Expected nlmsg_seq for replies. */
|
||||
atomic_uint status; /* Low bit set if we read final message.
|
||||
* Other bits hold an errno (0 for success). */
|
||||
struct seq *status_seq; /* Tracks changes to the above 'status'. */
|
||||
struct ovs_mutex mutex;
|
||||
|
||||
/* 'mutex' protects 'status' and serializes access to 'sock'. */
|
||||
struct ovs_mutex mutex; /* Protects 'status', synchronizes recv(). */
|
||||
int status OVS_GUARDED; /* 0: dump in progress,
|
||||
* positive errno: dump completed with error,
|
||||
* EOF: dump completed successfully. */
|
||||
};
|
||||
|
||||
void nl_dump_start(struct nl_dump *, int protocol,
|
||||
|
||||
Reference in New Issue
Block a user