This is needed to add flow dump batching to dpif-netdev, specifically for malloc-ing 'max_flows' key and mask buffers.
Signed-off-by: Ryan Wilson <wr...@nicira.com> --- v2: Addressed Joe's comments, split into 2 patches --- lib/dpif-linux.c | 4 ++-- lib/dpif-netdev.c | 4 ++-- lib/dpif-provider.h | 7 +++++-- lib/dpif.c | 7 ++++--- lib/dpif.h | 2 +- ofproto/ofproto-dpif-upcall.c | 3 ++- ofproto/ofproto-dpif.c | 2 +- utilities/ovs-dpctl.c | 2 +- 8 files changed, 18 insertions(+), 13 deletions(-) diff --git a/lib/dpif-linux.c b/lib/dpif-linux.c index afe9340..e0e4293 100644 --- a/lib/dpif-linux.c +++ b/lib/dpif-linux.c @@ -1203,13 +1203,13 @@ dpif_linux_flow_dump_thread_cast(struct dpif_flow_dump_thread *thread) } static struct dpif_flow_dump_thread * -dpif_linux_flow_dump_thread_create(struct dpif_flow_dump *dump_) +dpif_linux_flow_dump_thread_create(struct dpif_flow_dump *dump_, int max_flows) { struct dpif_linux_flow_dump *dump = dpif_linux_flow_dump_cast(dump_); struct dpif_linux_flow_dump_thread *thread; thread = xmalloc(sizeof *thread); - dpif_flow_dump_thread_init(&thread->up, &dump->up); + dpif_flow_dump_thread_init(&thread->up, &dump->up, max_flows); thread->dump = dump; ofpbuf_init(&thread->nl_flows, NL_DUMP_BUFSIZE); thread->nl_actions = NULL; diff --git a/lib/dpif-netdev.c b/lib/dpif-netdev.c index 6c281fe..805af9a 100644 --- a/lib/dpif-netdev.c +++ b/lib/dpif-netdev.c @@ -1434,13 +1434,13 @@ dpif_netdev_flow_dump_thread_cast(struct dpif_flow_dump_thread *thread) } static struct dpif_flow_dump_thread * -dpif_netdev_flow_dump_thread_create(struct dpif_flow_dump *dump_) +dpif_netdev_flow_dump_thread_create(struct dpif_flow_dump *dump_, int max_flows) { struct dpif_netdev_flow_dump *dump = dpif_netdev_flow_dump_cast(dump_); struct dpif_netdev_flow_dump_thread *thread; thread = xmalloc(sizeof *thread); - dpif_flow_dump_thread_init(&thread->up, &dump->up); + dpif_flow_dump_thread_init(&thread->up, &dump->up, max_flows); thread->dump = dump; return &thread->up; } diff --git a/lib/dpif-provider.h b/lib/dpif-provider.h index b762ac0..70d1ea2 100644 --- a/lib/dpif-provider.h +++ b/lib/dpif-provider.h @@ -63,13 +63,16 @@ dpif_flow_dump_init(struct dpif_flow_dump *dump, const struct dpif *dpif) struct dpif_flow_dump_thread { struct dpif *dpif; + int max_flows; }; static inline void dpif_flow_dump_thread_init(struct dpif_flow_dump_thread *thread, - struct dpif_flow_dump *dump) + struct dpif_flow_dump *dump, + int max_flows) { thread->dpif = dump->dpif; + thread->max_flows = max_flows; } /* Datapath interface class structure, to be defined by each implementation of @@ -312,7 +315,7 @@ struct dpif_class { int (*flow_dump_destroy)(struct dpif_flow_dump *dump); struct dpif_flow_dump_thread *(*flow_dump_thread_create)( - struct dpif_flow_dump *dump); + struct dpif_flow_dump *dump, int max_flows); void (*flow_dump_thread_destroy)(struct dpif_flow_dump_thread *thread); int (*flow_dump_next)(struct dpif_flow_dump_thread *thread, diff --git a/lib/dpif.c b/lib/dpif.c index cace47b..3349933 100644 --- a/lib/dpif.c +++ b/lib/dpif.c @@ -1000,9 +1000,10 @@ dpif_flow_dump_destroy(struct dpif_flow_dump *dump) /* Returns new thread-local state for use with dpif_flow_dump_next(). */ struct dpif_flow_dump_thread * -dpif_flow_dump_thread_create(struct dpif_flow_dump *dump) +dpif_flow_dump_thread_create(struct dpif_flow_dump *dump, int max_flows) { - return dump->dpif->dpif_class->flow_dump_thread_create(dump); + ovs_assert(max_flows > 0); + return dump->dpif->dpif_class->flow_dump_thread_create(dump, max_flows); } /* Releases 'thread'. */ @@ -1036,7 +1037,7 @@ dpif_flow_dump_next(struct dpif_flow_dump_thread *thread, struct dpif *dpif = thread->dpif; int n; - ovs_assert(max_flows > 0); + ovs_assert(max_flows <= thread->max_flows); n = dpif->dpif_class->flow_dump_next(thread, flows, max_flows); if (n > 0) { struct dpif_flow *f; diff --git a/lib/dpif.h b/lib/dpif.h index f080cde..5c060e4 100644 --- a/lib/dpif.h +++ b/lib/dpif.h @@ -558,7 +558,7 @@ struct dpif_flow_dump *dpif_flow_dump_create(const struct dpif *); int dpif_flow_dump_destroy(struct dpif_flow_dump *); struct dpif_flow_dump_thread *dpif_flow_dump_thread_create( - struct dpif_flow_dump *); + struct dpif_flow_dump *, int max_flows); void dpif_flow_dump_thread_destroy(struct dpif_flow_dump_thread *); /* A datapath flow as dumped by dpif_flow_dump_next(). */ diff --git a/ofproto/ofproto-dpif-upcall.c b/ofproto/ofproto-dpif-upcall.c index b38f226..b12d43d 100644 --- a/ofproto/ofproto-dpif-upcall.c +++ b/ofproto/ofproto-dpif-upcall.c @@ -1332,7 +1332,8 @@ revalidate(struct revalidator *revalidator) dump_seq = seq_read(udpif->dump_seq); atomic_read(&udpif->flow_limit, &flow_limit); - dump_thread = dpif_flow_dump_thread_create(udpif->dump); + dump_thread = dpif_flow_dump_thread_create(udpif->dump, + REVALIDATE_MAX_BATCH); for (;;) { struct dump_op ops[REVALIDATE_MAX_BATCH]; int n_ops = 0; diff --git a/ofproto/ofproto-dpif.c b/ofproto/ofproto-dpif.c index 9e4a455..965342a 100644 --- a/ofproto/ofproto-dpif.c +++ b/ofproto/ofproto-dpif.c @@ -4486,7 +4486,7 @@ ofproto_unixctl_dpif_dump_flows(struct unixctl_conn *conn, ds_init(&ds); flow_dump = dpif_flow_dump_create(ofproto->backer->dpif); - flow_dump_thread = dpif_flow_dump_thread_create(flow_dump); + flow_dump_thread = dpif_flow_dump_thread_create(flow_dump, 1); while (dpif_flow_dump_next(flow_dump_thread, &f, 1)) { if (!ofproto_dpif_contains_flow(ofproto, f.key, f.key_len)) { continue; diff --git a/utilities/ovs-dpctl.c b/utilities/ovs-dpctl.c index 62fc1dd..2f0cdb1 100644 --- a/utilities/ovs-dpctl.c +++ b/utilities/ovs-dpctl.c @@ -792,7 +792,7 @@ dpctl_dump_flows(int argc, char *argv[]) ds_init(&ds); flow_dump = dpif_flow_dump_create(dpif); - flow_dump_thread = dpif_flow_dump_thread_create(flow_dump); + flow_dump_thread = dpif_flow_dump_thread_create(flow_dump, 1); while (dpif_flow_dump_next(flow_dump_thread, &f, 1)) { if (filter) { struct flow flow; -- 1.7.9.5 _______________________________________________ dev mailing list dev@openvswitch.org http://openvswitch.org/mailman/listinfo/dev