Skip to content

Commit 4572ef5

Browse files
azhou-niciradavem330
authored andcommitted
openvswitch: Refactor recirc key allocation.
The logic of allocating and copy key for each 'exec_actions_level' was specific to execute_recirc(). However, future patches will reuse as well. Refactor the logic into its own function clone_key(). Signed-off-by: Andy Zhou <azhou@ovn.org> Acked-by: Pravin B Shelar <pshelar@ovn.org> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 47c697a commit 4572ef5

1 file changed

Lines changed: 40 additions & 26 deletions

File tree

‎net/openvswitch/actions.c‎

Lines changed: 40 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2007-2014 Nicira, Inc.
2+
* Copyright (c) 2007-2017 Nicira, Inc.
33
*
44
* This program is free software; you can redistribute it and/or
55
* modify it under the terms of version 2 of the GNU General Public
@@ -83,14 +83,31 @@ struct action_fifo {
8383
struct deferred_action fifo[DEFERRED_ACTION_FIFO_SIZE];
8484
};
8585

86-
struct recirc_keys {
86+
struct action_flow_keys {
8787
struct sw_flow_key key[OVS_DEFERRED_ACTION_THRESHOLD];
8888
};
8989

9090
static struct action_fifo __percpu *action_fifos;
91-
static struct recirc_keys __percpu *recirc_keys;
91+
static struct action_flow_keys __percpu *flow_keys;
9292
static DEFINE_PER_CPU(int, exec_actions_level);
9393

94+
/* Make a clone of the 'key', using the pre-allocated percpu 'flow_keys'
95+
* space. Return NULL if out of key spaces.
96+
*/
97+
static struct sw_flow_key *clone_key(const struct sw_flow_key *key_)
98+
{
99+
struct action_flow_keys *keys = this_cpu_ptr(flow_keys);
100+
int level = this_cpu_read(exec_actions_level);
101+
struct sw_flow_key *key = NULL;
102+
103+
if (level <= OVS_DEFERRED_ACTION_THRESHOLD) {
104+
key = &keys->key[level - 1];
105+
*key = *key_;
106+
}
107+
108+
return key;
109+
}
110+
94111
static void action_fifo_init(struct action_fifo *fifo)
95112
{
96113
fifo->head = 0;
@@ -1090,8 +1107,8 @@ static int execute_recirc(struct datapath *dp, struct sk_buff *skb,
10901107
struct sw_flow_key *key,
10911108
const struct nlattr *a, int rem)
10921109
{
1110+
struct sw_flow_key *recirc_key;
10931111
struct deferred_action *da;
1094-
int level;
10951112

10961113
if (!is_flow_key_valid(key)) {
10971114
int err;
@@ -1115,29 +1132,26 @@ static int execute_recirc(struct datapath *dp, struct sk_buff *skb,
11151132
return 0;
11161133
}
11171134

1118-
level = this_cpu_read(exec_actions_level);
1119-
if (level <= OVS_DEFERRED_ACTION_THRESHOLD) {
1120-
struct recirc_keys *rks = this_cpu_ptr(recirc_keys);
1121-
struct sw_flow_key *recirc_key = &rks->key[level - 1];
1122-
1123-
*recirc_key = *key;
1135+
/* If within the limit of 'OVS_DEFERRED_ACTION_THRESHOLD',
1136+
* recirc immediately, otherwise, defer it for later execution.
1137+
*/
1138+
recirc_key = clone_key(key);
1139+
if (recirc_key) {
11241140
recirc_key->recirc_id = nla_get_u32(a);
11251141
ovs_dp_process_packet(skb, recirc_key);
1126-
1127-
return 0;
1128-
}
1129-
1130-
da = add_deferred_actions(skb, key, NULL, 0);
1131-
if (da) {
1132-
da->pkt_key.recirc_id = nla_get_u32(a);
11331142
} else {
1134-
kfree_skb(skb);
1135-
1136-
if (net_ratelimit())
1137-
pr_warn("%s: deferred action limit reached, drop recirc action\n",
1138-
ovs_dp_name(dp));
1143+
da = add_deferred_actions(skb, key, NULL, 0);
1144+
if (da) {
1145+
recirc_key = &da->pkt_key;
1146+
recirc_key->recirc_id = nla_get_u32(a);
1147+
} else {
1148+
/* Log an error in case action fifo is full. */
1149+
kfree_skb(skb);
1150+
if (net_ratelimit())
1151+
pr_warn("%s: deferred action limit reached, drop recirc action\n",
1152+
ovs_dp_name(dp));
1153+
}
11391154
}
1140-
11411155
return 0;
11421156
}
11431157

@@ -1327,8 +1341,8 @@ int action_fifos_init(void)
13271341
if (!action_fifos)
13281342
return -ENOMEM;
13291343

1330-
recirc_keys = alloc_percpu(struct recirc_keys);
1331-
if (!recirc_keys) {
1344+
flow_keys = alloc_percpu(struct action_flow_keys);
1345+
if (!flow_keys) {
13321346
free_percpu(action_fifos);
13331347
return -ENOMEM;
13341348
}
@@ -1339,5 +1353,5 @@ int action_fifos_init(void)
13391353
void action_fifos_exit(void)
13401354
{
13411355
free_percpu(action_fifos);
1342-
free_percpu(recirc_keys);
1356+
free_percpu(flow_keys);
13431357
}

0 commit comments

Comments
 (0)