From bdeadfdd9559ca9fe6e63d3cfddc193a366390a7 Mon Sep 17 00:00:00 2001 From: Joe Stringer Date: Thu, 27 Feb 2014 14:13:10 -0800 Subject: [PATCH] dpif: New function flow_dump_next_may_destroy_keys(). This new function allows callers to determine whether previously returned keys will be modified or reallocated on the next call to dpif_flow_dump_next(). This will be used in a future commit to allow batched flow deletion by revalidator threads. Signed-off-by: Joe Stringer Signed-off-by: Ben Pfaff --- lib/dpif-linux.c | 9 +++++++++ lib/dpif-netdev.c | 1 + lib/dpif-provider.h | 13 +++++++++++++ lib/dpif.c | 21 +++++++++++++++++++++ lib/dpif.h | 2 ++ 5 files changed, 46 insertions(+) diff --git a/lib/dpif-linux.c b/lib/dpif-linux.c index 69b3e68c7..c2579f6bf 100644 --- a/lib/dpif-linux.c +++ b/lib/dpif-linux.c @@ -1104,6 +1104,14 @@ dpif_linux_flow_dump_next(const struct dpif *dpif_, void *iter_, void *state_, return error; } +static bool +dpif_linux_flow_dump_next_may_destroy_keys(void *state_) +{ + struct dpif_linux_flow_state *state = state_; + + return state->buffer.size ? false : true; +} + static int dpif_linux_flow_dump_done(const struct dpif *dpif OVS_UNUSED, void *iter_) { @@ -1669,6 +1677,7 @@ const struct dpif_class dpif_linux_class = { dpif_linux_flow_dump_state_init, dpif_linux_flow_dump_start, dpif_linux_flow_dump_next, + dpif_linux_flow_dump_next_may_destroy_keys, dpif_linux_flow_dump_done, dpif_linux_flow_dump_state_uninit, dpif_linux_execute, diff --git a/lib/dpif-netdev.c b/lib/dpif-netdev.c index de08c420d..d17fa0541 100644 --- a/lib/dpif-netdev.c +++ b/lib/dpif-netdev.c @@ -1892,6 +1892,7 @@ const struct dpif_class dpif_netdev_class = { dpif_netdev_flow_dump_state_init, dpif_netdev_flow_dump_start, dpif_netdev_flow_dump_next, + NULL, dpif_netdev_flow_dump_done, dpif_netdev_flow_dump_state_uninit, dpif_netdev_execute, diff --git a/lib/dpif-provider.h b/lib/dpif-provider.h index c85de5fa3..dd4f74ef7 100644 --- a/lib/dpif-provider.h +++ b/lib/dpif-provider.h @@ -312,6 +312,19 @@ struct dpif_class { const struct nlattr **actions, size_t *actions_len, const struct dpif_flow_stats **stats); + /* Determines whether the next call to 'flow_dump_next' with 'state' will + * modify or free the keys that it previously returned. 'state' must have + * been initialized by a call to 'flow_dump_state_init' for 'dpif'. + * + * 'dpif' guarantees that data returned by flow_dump_next() will remain + * accessible and unchanging until the next call. This function provides a + * way for callers to determine whether that guarantee extends beyond the + * next call. + * + * Returns true if the next call to flow_dump_next() is expected to be + * destructive to previously returned keys for 'state', false otherwise. */ + bool (*flow_dump_next_may_destroy_keys)(void *state); + /* Releases resources from 'dpif' for 'iter', which was initialized by a * successful call to the 'flow_dump_start' function for 'dpif'. Callers * must ensure that this function is called once within a given iteration, diff --git a/lib/dpif.c b/lib/dpif.c index 117d720ac..8cb2145ec 100644 --- a/lib/dpif.c +++ b/lib/dpif.c @@ -1056,6 +1056,27 @@ dpif_flow_dump_next(struct dpif_flow_dump *dump, void *state, return !error; } +/* Determines whether the next call to 'dpif_flow_dump_next' for 'dump' and + * 'state' will modify or free the keys that it previously returned. 'state' + * must have been initialized by a call to 'dpif_flow_dump_state_init' for + * 'dump'. + * + * 'dpif' guarantees that data returned by flow_dump_next() will remain + * accessible and unchanging until the next call. This function provides a way + * for callers to determine whether that guarantee extends beyond the next + * call. + * + * Returns true if the next call to flow_dump_next() is expected to be + * destructive to previously returned keys for 'state', false otherwise. */ +bool +dpif_flow_dump_next_may_destroy_keys(struct dpif_flow_dump *dump, void *state) +{ + const struct dpif *dpif = dump->dpif; + return (dpif->dpif_class->flow_dump_next_may_destroy_keys + ? dpif->dpif_class->flow_dump_next_may_destroy_keys(state) + : true); +} + /* Completes flow table dump operation 'dump', which must have been initialized * with a successful call to dpif_flow_dump_start(). Returns 0 if the dump * operation was error-free, otherwise a positive errno value describing the diff --git a/lib/dpif.h b/lib/dpif.h index 8e6e7d566..9cd8f6afa 100644 --- a/lib/dpif.h +++ b/lib/dpif.h @@ -523,6 +523,8 @@ bool dpif_flow_dump_next(struct dpif_flow_dump *, void *state, const struct nlattr **mask, size_t *mask_len, const struct nlattr **actions, size_t *actions_len, const struct dpif_flow_stats **); +bool dpif_flow_dump_next_may_destroy_keys(struct dpif_flow_dump *dump, + void *state); int dpif_flow_dump_done(struct dpif_flow_dump *); void dpif_flow_dump_state_uninit(const struct dpif *, void *state); -- 2.43.0