This new function allows callers to determine whether the contents of the given buffer 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 <[email protected]> --- I was a little unsure on the longevity of an interface like this; I could pass the dpif and/or state and/or other pointers down to the dpif implementation, but these appear to be all unnecessary for dpif-linux. Furthermore, if another implementation wishes to provide this function, they can always put any relevant information at the start of their buffer for re-use. Willing to change it though. --- lib/dpif-linux.c | 7 +++++++ lib/dpif-netdev.c | 1 + lib/dpif-provider.h | 10 ++++++++++ lib/dpif.c | 17 +++++++++++++++++ lib/dpif.h | 2 ++ 5 files changed, 37 insertions(+) diff --git a/lib/dpif-linux.c b/lib/dpif-linux.c index babb9e7..568d5a0 100644 --- a/lib/dpif-linux.c +++ b/lib/dpif-linux.c @@ -1052,6 +1052,12 @@ dpif_linux_flow_dump_next(const struct dpif *dpif_ OVS_UNUSED, void *state_, return error; } +static bool +dpif_linux_flow_dump_next_may_overwrite(struct ofpbuf *buffer) +{ + return buffer->size ? false : true; +} + static int dpif_linux_flow_dump_done(const struct dpif *dpif OVS_UNUSED, void *state_) { @@ -1611,6 +1617,7 @@ const struct dpif_class dpif_linux_class = { dpif_linux_flow_flush, dpif_linux_flow_dump_start, dpif_linux_flow_dump_next, + dpif_linux_flow_dump_next_may_overwrite, dpif_linux_flow_dump_done, dpif_linux_execute, dpif_linux_operate, diff --git a/lib/dpif-netdev.c b/lib/dpif-netdev.c index f880ad0..815a56c 100644 --- a/lib/dpif-netdev.c +++ b/lib/dpif-netdev.c @@ -1845,6 +1845,7 @@ const struct dpif_class dpif_netdev_class = { dpif_netdev_flow_flush, dpif_netdev_flow_dump_start, dpif_netdev_flow_dump_next, + NULL, dpif_netdev_flow_dump_done, dpif_netdev_execute, NULL, /* operate */ diff --git a/lib/dpif-provider.h b/lib/dpif-provider.h index 3086893..c961a9c 100644 --- a/lib/dpif-provider.h +++ b/lib/dpif-provider.h @@ -304,6 +304,16 @@ struct dpif_class { const struct nlattr **mask, size_t *mask_len, struct dpif_flow_stats *stats); + /* Attempts to determine whether the contents of 'buffer' will be modified + * or reallocated the next time that 'flow_dump_next' is called. + * + * Returns true if the next call to flow_dump_next() may modify or free the + * contents of 'buffer', false otherwise. If this function returns false, + * then the 'dpif' guarantees that the contents of 'buffer' will remain + * accessible and unchanging after the next call to flow_dump_next(). + */ + bool (*flow_dump_next_may_overwrite)(struct ofpbuf *buffer); + /* Releases resources from 'dpif' for 'state', 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 850b4db..15eb794 100644 --- a/lib/dpif.c +++ b/lib/dpif.c @@ -1027,6 +1027,23 @@ dpif_flow_dump_next(struct dpif_flow_dump *dump, struct ofpbuf *buffer, return !error; } +/* Attempts to determine whether the contents of 'buffer' will be modified or + * reallocated the next time that 'flow_dump_next' is called. + * + * Returns true if the next call to dpif_flow_dump_next() may modify or free + * the contents of 'buffer', false otherwise. If this function returns false, + * then 'dpif' guarantees that the contents of 'buffer' will not be modified or + * freed until after the next call to dpif_flow_dump_next(). */ +bool +dpif_flow_dump_next_may_overwrite(struct dpif_flow_dump *dump, + struct ofpbuf *buffer) +{ + const struct dpif *dpif = dump->dpif; + return (dpif->dpif_class->flow_dump_next_may_overwrite + ? dpif->dpif_class->flow_dump_next_may_overwrite(buffer) + : true); +} + /* Completes flow table dump operation 'dump', which must have been initialized * with dpif_flow_dump_start(). Returns 0 if the dump operation was * error-free, otherwise a positive errno value describing the problem. */ diff --git a/lib/dpif.h b/lib/dpif.h index 2e8b7b8..100848c 100644 --- a/lib/dpif.h +++ b/lib/dpif.h @@ -514,6 +514,8 @@ bool dpif_flow_dump_next(struct dpif_flow_dump *, struct ofpbuf *buffer, const struct nlattr **key, size_t *key_len, const struct nlattr **mask, size_t *mask_len, struct dpif_flow_stats *); +bool dpif_flow_dump_next_may_overwrite(struct dpif_flow_dump *, + struct ofpbuf *); int dpif_flow_dump_done(struct dpif_flow_dump *); /* Operation batching interface. -- 1.7.9.5 _______________________________________________ dev mailing list [email protected] http://openvswitch.org/mailman/listinfo/dev
