Skip to content

Commit b409074

Browse files
w1ldptrdavem330
authored andcommitted
net: sched: add 'delete' function to action ops
Extend action ops with 'delete' function. Each action type to implements its own delete function that doesn't depend on rtnl lock. Implement delete function that is required to delete actions without holding rtnl lock. Use action API function that atomically deletes action only if it is still in action idr. This implementation prevents concurrent threads from deleting same action twice. Reviewed-by: Marcelo Ricardo Leitner <marcelo.leitner@gmail.com> Signed-off-by: Vlad Buslov <vladbu@mellanox.com> Signed-off-by: Jiri Pirko <jiri@mellanox.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 2a2ea34 commit b409074

File tree

17 files changed

+137
-0
lines changed

17 files changed

+137
-0
lines changed

include/net/act_api.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ struct tc_action_ops {
101101
void (*stats_update)(struct tc_action *, u64, u32, u64);
102102
size_t (*get_fill_size)(const struct tc_action *act);
103103
struct net_device *(*get_dev)(const struct tc_action *a);
104+
int (*delete)(struct net *net, u32 index);
104105
};
105106

106107
struct tc_action_net {

net/sched/act_bpf.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,13 @@ static int tcf_bpf_search(struct net *net, struct tc_action **a, u32 index,
388388
return tcf_idr_search(tn, a, index);
389389
}
390390

391+
static int tcf_bpf_delete(struct net *net, u32 index)
392+
{
393+
struct tc_action_net *tn = net_generic(net, bpf_net_id);
394+
395+
return tcf_idr_delete_index(tn, index);
396+
}
397+
391398
static struct tc_action_ops act_bpf_ops __read_mostly = {
392399
.kind = "bpf",
393400
.type = TCA_ACT_BPF,
@@ -398,6 +405,7 @@ static struct tc_action_ops act_bpf_ops __read_mostly = {
398405
.init = tcf_bpf_init,
399406
.walk = tcf_bpf_walker,
400407
.lookup = tcf_bpf_search,
408+
.delete = tcf_bpf_delete,
401409
.size = sizeof(struct tcf_bpf),
402410
};
403411

net/sched/act_connmark.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,13 @@ static int tcf_connmark_search(struct net *net, struct tc_action **a, u32 index,
193193
return tcf_idr_search(tn, a, index);
194194
}
195195

196+
static int tcf_connmark_delete(struct net *net, u32 index)
197+
{
198+
struct tc_action_net *tn = net_generic(net, connmark_net_id);
199+
200+
return tcf_idr_delete_index(tn, index);
201+
}
202+
196203
static struct tc_action_ops act_connmark_ops = {
197204
.kind = "connmark",
198205
.type = TCA_ACT_CONNMARK,
@@ -202,6 +209,7 @@ static struct tc_action_ops act_connmark_ops = {
202209
.init = tcf_connmark_init,
203210
.walk = tcf_connmark_walker,
204211
.lookup = tcf_connmark_search,
212+
.delete = tcf_connmark_delete,
205213
.size = sizeof(struct tcf_connmark_info),
206214
};
207215

net/sched/act_csum.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -654,6 +654,13 @@ static size_t tcf_csum_get_fill_size(const struct tc_action *act)
654654
return nla_total_size(sizeof(struct tc_csum));
655655
}
656656

657+
static int tcf_csum_delete(struct net *net, u32 index)
658+
{
659+
struct tc_action_net *tn = net_generic(net, csum_net_id);
660+
661+
return tcf_idr_delete_index(tn, index);
662+
}
663+
657664
static struct tc_action_ops act_csum_ops = {
658665
.kind = "csum",
659666
.type = TCA_ACT_CSUM,
@@ -665,6 +672,7 @@ static struct tc_action_ops act_csum_ops = {
665672
.walk = tcf_csum_walker,
666673
.lookup = tcf_csum_search,
667674
.get_fill_size = tcf_csum_get_fill_size,
675+
.delete = tcf_csum_delete,
668676
.size = sizeof(struct tcf_csum),
669677
};
670678

net/sched/act_gact.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,13 @@ static size_t tcf_gact_get_fill_size(const struct tc_action *act)
231231
return sz;
232232
}
233233

234+
static int tcf_gact_delete(struct net *net, u32 index)
235+
{
236+
struct tc_action_net *tn = net_generic(net, gact_net_id);
237+
238+
return tcf_idr_delete_index(tn, index);
239+
}
240+
234241
static struct tc_action_ops act_gact_ops = {
235242
.kind = "gact",
236243
.type = TCA_ACT_GACT,
@@ -242,6 +249,7 @@ static struct tc_action_ops act_gact_ops = {
242249
.walk = tcf_gact_walker,
243250
.lookup = tcf_gact_search,
244251
.get_fill_size = tcf_gact_get_fill_size,
252+
.delete = tcf_gact_delete,
245253
.size = sizeof(struct tcf_gact),
246254
};
247255

net/sched/act_ife.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -844,6 +844,13 @@ static int tcf_ife_search(struct net *net, struct tc_action **a, u32 index,
844844
return tcf_idr_search(tn, a, index);
845845
}
846846

847+
static int tcf_ife_delete(struct net *net, u32 index)
848+
{
849+
struct tc_action_net *tn = net_generic(net, ife_net_id);
850+
851+
return tcf_idr_delete_index(tn, index);
852+
}
853+
847854
static struct tc_action_ops act_ife_ops = {
848855
.kind = "ife",
849856
.type = TCA_ACT_IFE,
@@ -854,6 +861,7 @@ static struct tc_action_ops act_ife_ops = {
854861
.init = tcf_ife_init,
855862
.walk = tcf_ife_walker,
856863
.lookup = tcf_ife_search,
864+
.delete = tcf_ife_delete,
857865
.size = sizeof(struct tcf_ife_info),
858866
};
859867

net/sched/act_ipt.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,13 @@ static int tcf_ipt_search(struct net *net, struct tc_action **a, u32 index,
324324
return tcf_idr_search(tn, a, index);
325325
}
326326

327+
static int tcf_ipt_delete(struct net *net, u32 index)
328+
{
329+
struct tc_action_net *tn = net_generic(net, ipt_net_id);
330+
331+
return tcf_idr_delete_index(tn, index);
332+
}
333+
327334
static struct tc_action_ops act_ipt_ops = {
328335
.kind = "ipt",
329336
.type = TCA_ACT_IPT,
@@ -334,6 +341,7 @@ static struct tc_action_ops act_ipt_ops = {
334341
.init = tcf_ipt_init,
335342
.walk = tcf_ipt_walker,
336343
.lookup = tcf_ipt_search,
344+
.delete = tcf_ipt_delete,
337345
.size = sizeof(struct tcf_ipt),
338346
};
339347

@@ -374,6 +382,13 @@ static int tcf_xt_search(struct net *net, struct tc_action **a, u32 index,
374382
return tcf_idr_search(tn, a, index);
375383
}
376384

385+
static int tcf_xt_delete(struct net *net, u32 index)
386+
{
387+
struct tc_action_net *tn = net_generic(net, xt_net_id);
388+
389+
return tcf_idr_delete_index(tn, index);
390+
}
391+
377392
static struct tc_action_ops act_xt_ops = {
378393
.kind = "xt",
379394
.type = TCA_ACT_XT,
@@ -384,6 +399,7 @@ static struct tc_action_ops act_xt_ops = {
384399
.init = tcf_xt_init,
385400
.walk = tcf_xt_walker,
386401
.lookup = tcf_xt_search,
402+
.delete = tcf_xt_delete,
387403
.size = sizeof(struct tcf_ipt),
388404
};
389405

net/sched/act_mirred.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,13 @@ static struct net_device *tcf_mirred_get_dev(const struct tc_action *a)
322322
return rtnl_dereference(m->tcfm_dev);
323323
}
324324

325+
static int tcf_mirred_delete(struct net *net, u32 index)
326+
{
327+
struct tc_action_net *tn = net_generic(net, mirred_net_id);
328+
329+
return tcf_idr_delete_index(tn, index);
330+
}
331+
325332
static struct tc_action_ops act_mirred_ops = {
326333
.kind = "mirred",
327334
.type = TCA_ACT_MIRRED,
@@ -335,6 +342,7 @@ static struct tc_action_ops act_mirred_ops = {
335342
.lookup = tcf_mirred_search,
336343
.size = sizeof(struct tcf_mirred),
337344
.get_dev = tcf_mirred_get_dev,
345+
.delete = tcf_mirred_delete,
338346
};
339347

340348
static __net_init int mirred_init_net(struct net *net)

net/sched/act_nat.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,13 @@ static int tcf_nat_search(struct net *net, struct tc_action **a, u32 index,
294294
return tcf_idr_search(tn, a, index);
295295
}
296296

297+
static int tcf_nat_delete(struct net *net, u32 index)
298+
{
299+
struct tc_action_net *tn = net_generic(net, nat_net_id);
300+
301+
return tcf_idr_delete_index(tn, index);
302+
}
303+
297304
static struct tc_action_ops act_nat_ops = {
298305
.kind = "nat",
299306
.type = TCA_ACT_NAT,
@@ -303,6 +310,7 @@ static struct tc_action_ops act_nat_ops = {
303310
.init = tcf_nat_init,
304311
.walk = tcf_nat_walker,
305312
.lookup = tcf_nat_search,
313+
.delete = tcf_nat_delete,
306314
.size = sizeof(struct tcf_nat),
307315
};
308316

net/sched/act_pedit.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -454,6 +454,13 @@ static int tcf_pedit_search(struct net *net, struct tc_action **a, u32 index,
454454
return tcf_idr_search(tn, a, index);
455455
}
456456

457+
static int tcf_pedit_delete(struct net *net, u32 index)
458+
{
459+
struct tc_action_net *tn = net_generic(net, pedit_net_id);
460+
461+
return tcf_idr_delete_index(tn, index);
462+
}
463+
457464
static struct tc_action_ops act_pedit_ops = {
458465
.kind = "pedit",
459466
.type = TCA_ACT_PEDIT,
@@ -464,6 +471,7 @@ static struct tc_action_ops act_pedit_ops = {
464471
.init = tcf_pedit_init,
465472
.walk = tcf_pedit_walker,
466473
.lookup = tcf_pedit_search,
474+
.delete = tcf_pedit_delete,
467475
.size = sizeof(struct tcf_pedit),
468476
};
469477

0 commit comments

Comments
 (0)