Skip to content

Commit 56c1986

Browse files
Jarno RajahalmePravin B Shelar
authored andcommitted
openvswitch: Make flow mask removal symmetric.
Masks are inserted when flows are inserted to the table, so it is logical to correspondingly remove masks when flows are removed from the table, in ovs_flow_table_remove(). This allows ovs_flow_free() to be called without locking, which will be used by later patches. Signed-off-by: Jarno Rajahalme <jrajahalme@nicira.com> Signed-off-by: Pravin B Shelar <pshelar@nicira.com>
1 parent fb5d1e9 commit 56c1986

1 file changed

Lines changed: 25 additions & 19 deletions

File tree

‎net/openvswitch/flow_table.c‎

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -159,25 +159,6 @@ void ovs_flow_free(struct sw_flow *flow, bool deferred)
159159
if (!flow)
160160
return;
161161

162-
if (flow->mask) {
163-
struct sw_flow_mask *mask = flow->mask;
164-
165-
/* ovs-lock is required to protect mask-refcount and
166-
* mask list.
167-
*/
168-
ASSERT_OVSL();
169-
BUG_ON(!mask->ref_count);
170-
mask->ref_count--;
171-
172-
if (!mask->ref_count) {
173-
list_del_rcu(&mask->list);
174-
if (deferred)
175-
kfree_rcu(mask, rcu);
176-
else
177-
kfree(mask);
178-
}
179-
}
180-
181162
if (deferred)
182163
call_rcu(&flow->rcu, rcu_free_flow_callback);
183164
else
@@ -491,13 +472,37 @@ static struct table_instance *table_instance_expand(struct table_instance *ti)
491472
return table_instance_rehash(ti, ti->n_buckets * 2);
492473
}
493474

475+
/* Remove 'mask' from the mask list, if it is not needed any more. */
476+
static void flow_mask_remove(struct flow_table *tbl, struct sw_flow_mask *mask)
477+
{
478+
if (mask) {
479+
/* ovs-lock is required to protect mask-refcount and
480+
* mask list.
481+
*/
482+
ASSERT_OVSL();
483+
BUG_ON(!mask->ref_count);
484+
mask->ref_count--;
485+
486+
if (!mask->ref_count) {
487+
list_del_rcu(&mask->list);
488+
kfree_rcu(mask, rcu);
489+
}
490+
}
491+
}
492+
493+
/* Must be called with OVS mutex held. */
494494
void ovs_flow_tbl_remove(struct flow_table *table, struct sw_flow *flow)
495495
{
496496
struct table_instance *ti = ovsl_dereference(table->ti);
497497

498498
BUG_ON(table->count == 0);
499499
hlist_del_rcu(&flow->hash_node[ti->node_ver]);
500500
table->count--;
501+
502+
/* RCU delete the mask. 'flow->mask' is not NULLed, as it should be
503+
* accessible as long as the RCU read lock is held.
504+
*/
505+
flow_mask_remove(table, flow->mask);
501506
}
502507

503508
static struct sw_flow_mask *mask_alloc(void)
@@ -560,6 +565,7 @@ static int flow_mask_insert(struct flow_table *tbl, struct sw_flow *flow,
560565
return 0;
561566
}
562567

568+
/* Must be called with OVS mutex held. */
563569
int ovs_flow_tbl_insert(struct flow_table *table, struct sw_flow *flow,
564570
struct sw_flow_mask *mask)
565571
{

0 commit comments

Comments
 (0)