mirror of
https://github.com/openvswitch/ovs
synced 2025-08-31 06:15:47 +00:00
netlink: Remove buffer from 'struct nl_dump'.
This patch makes all of the users of 'struct nl_dump' allocate their own buffers to pass down to nl_dump_next(). This paves the way for allowing multithreaded flow dumping. Signed-off-by: Joe Stringer <joestringer@nicira.com> Signed-off-by: Ben Pfaff <blp@nicira.com>
This commit is contained in:
@@ -190,7 +190,8 @@ static int
|
||||
dpif_linux_enumerate(struct sset *all_dps)
|
||||
{
|
||||
struct nl_dump dump;
|
||||
struct ofpbuf msg;
|
||||
uint64_t reply_stub[NL_DUMP_BUFSIZE / 8];
|
||||
struct ofpbuf msg, buf;
|
||||
int error;
|
||||
|
||||
error = dpif_linux_init();
|
||||
@@ -198,14 +199,16 @@ dpif_linux_enumerate(struct sset *all_dps)
|
||||
return error;
|
||||
}
|
||||
|
||||
ofpbuf_use_stub(&buf, reply_stub, sizeof reply_stub);
|
||||
dpif_linux_dp_dump_start(&dump);
|
||||
while (nl_dump_next(&dump, &msg)) {
|
||||
while (nl_dump_next(&dump, &msg, &buf)) {
|
||||
struct dpif_linux_dp dp;
|
||||
|
||||
if (!dpif_linux_dp_from_ofpbuf(&dp, &msg)) {
|
||||
sset_add(all_dps, dp.name);
|
||||
}
|
||||
}
|
||||
ofpbuf_uninit(&buf);
|
||||
return nl_dump_done(&dump);
|
||||
}
|
||||
|
||||
@@ -708,6 +711,7 @@ dpif_linux_flow_flush(struct dpif *dpif_)
|
||||
|
||||
struct dpif_linux_port_state {
|
||||
struct nl_dump dump;
|
||||
struct ofpbuf buf;
|
||||
};
|
||||
|
||||
static void
|
||||
@@ -735,18 +739,20 @@ dpif_linux_port_dump_start(const struct dpif *dpif, void **statep)
|
||||
*statep = state = xmalloc(sizeof *state);
|
||||
dpif_linux_port_dump_start__(dpif, &state->dump);
|
||||
|
||||
ofpbuf_init(&state->buf, NL_DUMP_BUFSIZE);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
dpif_linux_port_dump_next__(const struct dpif *dpif_, struct nl_dump *dump,
|
||||
struct dpif_linux_vport *vport)
|
||||
struct dpif_linux_vport *vport,
|
||||
struct ofpbuf *buffer)
|
||||
{
|
||||
struct dpif_linux *dpif = dpif_linux_cast(dpif_);
|
||||
struct ofpbuf buf;
|
||||
int error;
|
||||
|
||||
if (!nl_dump_next(dump, &buf)) {
|
||||
if (!nl_dump_next(dump, &buf, buffer)) {
|
||||
return EOF;
|
||||
}
|
||||
|
||||
@@ -766,7 +772,8 @@ dpif_linux_port_dump_next(const struct dpif *dpif OVS_UNUSED, void *state_,
|
||||
struct dpif_linux_vport vport;
|
||||
int error;
|
||||
|
||||
error = dpif_linux_port_dump_next__(dpif, &state->dump, &vport);
|
||||
error = dpif_linux_port_dump_next__(dpif, &state->dump, &vport,
|
||||
&state->buf);
|
||||
if (error) {
|
||||
return error;
|
||||
}
|
||||
@@ -782,6 +789,7 @@ dpif_linux_port_dump_done(const struct dpif *dpif_ OVS_UNUSED, void *state_)
|
||||
struct dpif_linux_port_state *state = state_;
|
||||
int error = nl_dump_done(&state->dump);
|
||||
|
||||
ofpbuf_uninit(&state->buf);
|
||||
free(state);
|
||||
return error;
|
||||
}
|
||||
@@ -987,7 +995,8 @@ struct dpif_linux_flow_state {
|
||||
struct nl_dump dump;
|
||||
struct dpif_linux_flow flow;
|
||||
struct dpif_flow_stats stats;
|
||||
struct ofpbuf *buf;
|
||||
struct ofpbuf buffer; /* Always used to store flows. */
|
||||
struct ofpbuf *tmp; /* Used if kernel does not supply actions. */
|
||||
};
|
||||
|
||||
static int
|
||||
@@ -1009,7 +1018,8 @@ dpif_linux_flow_dump_start(const struct dpif *dpif_, void **statep)
|
||||
nl_dump_start(&state->dump, NETLINK_GENERIC, buf);
|
||||
ofpbuf_delete(buf);
|
||||
|
||||
state->buf = NULL;
|
||||
ofpbuf_init(&state->buffer, NL_DUMP_BUFSIZE);
|
||||
state->tmp = NULL;
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -1026,10 +1036,10 @@ dpif_linux_flow_dump_next(const struct dpif *dpif_, void *state_,
|
||||
int error;
|
||||
|
||||
do {
|
||||
ofpbuf_delete(state->buf);
|
||||
state->buf = NULL;
|
||||
ofpbuf_delete(state->tmp);
|
||||
state->tmp = NULL;
|
||||
|
||||
if (!nl_dump_next(&state->dump, &buf)) {
|
||||
if (!nl_dump_next(&state->dump, &buf, &state->buffer)) {
|
||||
return EOF;
|
||||
}
|
||||
|
||||
@@ -1041,7 +1051,7 @@ dpif_linux_flow_dump_next(const struct dpif *dpif_, void *state_,
|
||||
if (actions && !state->flow.actions) {
|
||||
error = dpif_linux_flow_get__(dpif_, state->flow.key,
|
||||
state->flow.key_len,
|
||||
&state->flow, &state->buf);
|
||||
&state->flow, &state->tmp);
|
||||
if (error == ENOENT) {
|
||||
VLOG_DBG("dumped flow disappeared on get");
|
||||
} else if (error) {
|
||||
@@ -1075,7 +1085,8 @@ dpif_linux_flow_dump_done(const struct dpif *dpif OVS_UNUSED, void *state_)
|
||||
{
|
||||
struct dpif_linux_flow_state *state = state_;
|
||||
int error = nl_dump_done(&state->dump);
|
||||
ofpbuf_delete(state->buf);
|
||||
ofpbuf_uninit(&state->buffer);
|
||||
ofpbuf_delete(state->tmp);
|
||||
free(state);
|
||||
return error;
|
||||
}
|
||||
@@ -1287,6 +1298,8 @@ dpif_linux_refresh_channels(struct dpif *dpif_)
|
||||
struct dpif_linux_vport vport;
|
||||
size_t keep_channels_nbits;
|
||||
struct nl_dump dump;
|
||||
uint64_t reply_stub[NL_DUMP_BUFSIZE / 8];
|
||||
struct ofpbuf buf;
|
||||
int retval = 0;
|
||||
size_t i;
|
||||
|
||||
@@ -1303,8 +1316,9 @@ dpif_linux_refresh_channels(struct dpif *dpif_)
|
||||
|
||||
dpif->n_events = dpif->event_offset = 0;
|
||||
|
||||
ofpbuf_use_stub(&buf, reply_stub, sizeof reply_stub);
|
||||
dpif_linux_port_dump_start__(dpif_, &dump);
|
||||
while (!dpif_linux_port_dump_next__(dpif_, &dump, &vport)) {
|
||||
while (!dpif_linux_port_dump_next__(dpif_, &dump, &vport, &buf)) {
|
||||
uint32_t port_no = odp_to_u32(vport.port_no);
|
||||
struct nl_sock *sock = (port_no < dpif->uc_array_size
|
||||
? dpif->channels[port_no].sock
|
||||
@@ -1370,6 +1384,7 @@ dpif_linux_refresh_channels(struct dpif *dpif_)
|
||||
nl_sock_destroy(sock);
|
||||
}
|
||||
nl_dump_done(&dump);
|
||||
ofpbuf_uninit(&buf);
|
||||
|
||||
/* Discard any saved channels that we didn't reuse. */
|
||||
for (i = 0; i < keep_channels_nbits; i++) {
|
||||
|
Reference in New Issue
Block a user