Skip to content

Commit 2a2ea34

Browse files
w1ldptrdavem330
authored andcommitted
net: sched: implement action API that deletes action by index
Implement new action API function that atomically finds and deletes action from idr by index. Intended to be used by lockless actions that do not rely on rtnl lock. 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 3f7c72b commit 2a2ea34

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

include/net/act_api.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ int tcf_idr_create(struct tc_action_net *tn, u32 index, struct nlattr *est,
153153
int bind, bool cpustats);
154154
void tcf_idr_insert(struct tc_action_net *tn, struct tc_action *a);
155155

156+
int tcf_idr_delete_index(struct tc_action_net *tn, u32 index);
156157
int __tcf_idr_release(struct tc_action *a, bool bind, bool strict);
157158

158159
static inline int tcf_idr_release(struct tc_action *a, bool bind)

net/sched/act_api.c

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,45 @@ bool tcf_idr_check(struct tc_action_net *tn, u32 index, struct tc_action **a,
319319
}
320320
EXPORT_SYMBOL(tcf_idr_check);
321321

322+
int tcf_idr_delete_index(struct tc_action_net *tn, u32 index)
323+
{
324+
struct tcf_idrinfo *idrinfo = tn->idrinfo;
325+
struct tc_action *p;
326+
int ret = 0;
327+
328+
spin_lock(&idrinfo->lock);
329+
p = idr_find(&idrinfo->action_idr, index);
330+
if (!p) {
331+
spin_unlock(&idrinfo->lock);
332+
return -ENOENT;
333+
}
334+
335+
if (!atomic_read(&p->tcfa_bindcnt)) {
336+
if (refcount_dec_and_test(&p->tcfa_refcnt)) {
337+
struct module *owner = p->ops->owner;
338+
339+
WARN_ON(p != idr_remove(&idrinfo->action_idr,
340+
p->tcfa_index));
341+
spin_unlock(&idrinfo->lock);
342+
343+
if (p->ops->cleanup)
344+
p->ops->cleanup(p);
345+
346+
gen_kill_estimator(&p->tcfa_rate_est);
347+
free_tcf(p);
348+
module_put(owner);
349+
return 0;
350+
}
351+
ret = 0;
352+
} else {
353+
ret = -EPERM;
354+
}
355+
356+
spin_unlock(&idrinfo->lock);
357+
return ret;
358+
}
359+
EXPORT_SYMBOL(tcf_idr_delete_index);
360+
322361
int tcf_idr_create(struct tc_action_net *tn, u32 index, struct nlattr *est,
323362
struct tc_action **a, const struct tc_action_ops *ops,
324363
int bind, bool cpustats)

0 commit comments

Comments
 (0)