mirror of
https://github.com/openvswitch/ovs
synced 2025-08-31 14:25:26 +00:00
datapath: Change listing flows to use an iterator concept.
One of the goals for Open vSwitch is to decouple kernel and userspace software, so that either one can be upgraded or rolled back independent of the other. To do this in full generality, it must be possible to change the kernel's idea of the flow key separately from the userspace version. In turn, that means that flow keys must become variable-length. This does not, however, fit in well with the ODP_FLOW_LIST ioctl in its current form, because that would require userspace to know how much space to allocate for each flow's key in advance, or to allocate as much space as could possibly be needed. Neither choice is very attractive. This commit prepares for a different solution, by replacing ODP_FLOW_LIST by a new ioctl ODP_FLOW_DUMP that retrieves a single flow from the datapath on each call. It is much cleaner to allocate the maximum amount of space for a single flow key than to do so for possibly a very large number of flow keys. As a side effect, this patch also fixes a race condition that sometimes made "ovs-dpctl dump-flows" print an error: previously, flows were listed and then their actions were retrieved, which left a window in which ovs-vswitchd could delete the flow. Now dumping a flow and its actions is a single step, closing that window. Dumping all of the flows in a datapath is no longer an atomic step, so now it is possible to miss some flows or see a single flow twice during iteration, if the flow table is modified by another process. It doesn't look like this should be a problem for ovs-vswitchd. It would be faster to retrieve a number of flows in batch instead of just one at a time, but that will naturally happen later when the kernel datapath interface is changed to use Netlink, so this patch does not bother with it. Signed-off-by: Ben Pfaff <blp@nicira.com> Acked-by: Jesse Gross <jesse@nicira.com>
This commit is contained in:
@@ -394,15 +394,29 @@ dpif_linux_flow_del(struct dpif *dpif_, struct odp_flow *flow)
|
||||
}
|
||||
|
||||
static int
|
||||
dpif_linux_flow_list(const struct dpif *dpif_, struct odp_flow flows[], int n)
|
||||
dpif_linux_flow_dump_start(const struct dpif *dpif OVS_UNUSED, void **statep)
|
||||
{
|
||||
struct odp_flowvec fv;
|
||||
*statep = xzalloc(sizeof(struct odp_flow_dump));
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
dpif_linux_flow_dump_next(const struct dpif *dpif, void *state,
|
||||
struct odp_flow *flow)
|
||||
{
|
||||
struct odp_flow_dump *dump = state;
|
||||
int error;
|
||||
|
||||
fv.flows = flows;
|
||||
fv.n_flows = n;
|
||||
error = do_ioctl(dpif_, ODP_FLOW_LIST, &fv);
|
||||
return error ? -error : fv.n_flows;
|
||||
dump->flow = flow;
|
||||
error = do_ioctl(dpif, ODP_FLOW_DUMP, dump);
|
||||
return error ? error : flow->flags & ODPFF_EOF ? EOF : 0;
|
||||
}
|
||||
|
||||
static int
|
||||
dpif_linux_flow_dump_done(const struct dpif *dpif OVS_UNUSED, void *state)
|
||||
{
|
||||
free(state);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
@@ -529,7 +543,9 @@ const struct dpif_class dpif_linux_class = {
|
||||
dpif_linux_flow_put,
|
||||
dpif_linux_flow_del,
|
||||
dpif_linux_flow_flush,
|
||||
dpif_linux_flow_list,
|
||||
dpif_linux_flow_dump_start,
|
||||
dpif_linux_flow_dump_next,
|
||||
dpif_linux_flow_dump_done,
|
||||
dpif_linux_execute,
|
||||
dpif_linux_recv_get_mask,
|
||||
dpif_linux_recv_set_mask,
|
||||
|
Reference in New Issue
Block a user