Skip to content

Commit df68d64

Browse files
hao022davem330
authored andcommitted
net: openvswitch: refactor flow free function
Decrease table->count and ufid_count unconditionally, because we only don't use count or ufid_count to count when flushing the flows. To simplify the codes, we remove the "count" argument of table_instance_flow_free. To avoid a bug when deleting flows in the future, add WARN_ON in flush flows function. Cc: Pravin B Shelar <pshelar@ovn.org> Signed-off-by: Tonghao Zhang <xiangxia.m.yue@gmail.com> Acked-by: Pravin B Shelar <pshelar@ovn.org> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent cf3266a commit df68d64

1 file changed

Lines changed: 11 additions & 11 deletions

File tree

‎net/openvswitch/flow_table.c‎

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -461,18 +461,14 @@ static void flow_tbl_destroy_rcu_cb(struct rcu_head *rcu)
461461
static void table_instance_flow_free(struct flow_table *table,
462462
struct table_instance *ti,
463463
struct table_instance *ufid_ti,
464-
struct sw_flow *flow,
465-
bool count)
464+
struct sw_flow *flow)
466465
{
467466
hlist_del_rcu(&flow->flow_table.node[ti->node_ver]);
468-
if (count)
469-
table->count--;
467+
table->count--;
470468

471469
if (ovs_identifier_is_ufid(&flow->id)) {
472470
hlist_del_rcu(&flow->ufid_table.node[ufid_ti->node_ver]);
473-
474-
if (count)
475-
table->ufid_count--;
471+
table->ufid_count--;
476472
}
477473

478474
flow_mask_remove(table, flow->mask);
@@ -497,10 +493,16 @@ void table_instance_flow_flush(struct flow_table *table,
497493
flow_table.node[ti->node_ver]) {
498494

499495
table_instance_flow_free(table, ti, ufid_ti,
500-
flow, false);
496+
flow);
501497
ovs_flow_free(flow, true);
502498
}
503499
}
500+
501+
if (WARN_ON(table->count != 0 ||
502+
table->ufid_count != 0)) {
503+
table->count = 0;
504+
table->ufid_count = 0;
505+
}
504506
}
505507

506508
static void table_instance_destroy(struct table_instance *ti,
@@ -637,8 +639,6 @@ int ovs_flow_tbl_flush(struct flow_table *flow_table)
637639
rcu_assign_pointer(flow_table->ti, new_ti);
638640
rcu_assign_pointer(flow_table->ufid_ti, new_ufid_ti);
639641
flow_table->last_rehash = jiffies;
640-
flow_table->count = 0;
641-
flow_table->ufid_count = 0;
642642

643643
table_instance_flow_flush(flow_table, old_ti, old_ufid_ti);
644644
table_instance_destroy(old_ti, old_ufid_ti);
@@ -956,7 +956,7 @@ void ovs_flow_tbl_remove(struct flow_table *table, struct sw_flow *flow)
956956
struct table_instance *ufid_ti = ovsl_dereference(table->ufid_ti);
957957

958958
BUG_ON(table->count == 0);
959-
table_instance_flow_free(table, ti, ufid_ti, flow, true);
959+
table_instance_flow_free(table, ti, ufid_ti, flow);
960960
}
961961

962962
static struct sw_flow_mask *mask_alloc(void)

0 commit comments

Comments
 (0)