From: Vlad Buslov Date: Mon, 24 Sep 2018 16:22:52 +0000 (+0300) Subject: net: sched: add helper function to take reference to Qdisc X-Git-Url: http://git.maquefel.me/?a=commitdiff_plain;h=9d7e82cec35c027756ec97e274f878251f271181;p=linux.git net: sched: add helper function to take reference to Qdisc Implement function to take reference to Qdisc that relies on rcu read lock instead of rtnl mutex. Function only takes reference to Qdisc if reference counter isn't zero. Intended to be used by unlocked cls API. Signed-off-by: Vlad Buslov Acked-by: Jiri Pirko Signed-off-by: David S. Miller --- diff --git a/include/net/sch_generic.h b/include/net/sch_generic.h index 091b40c198ff8..43b17f82d8eeb 100644 --- a/include/net/sch_generic.h +++ b/include/net/sch_generic.h @@ -115,6 +115,19 @@ static inline void qdisc_refcount_inc(struct Qdisc *qdisc) refcount_inc(&qdisc->refcnt); } +/* Intended to be used by unlocked users, when concurrent qdisc release is + * possible. + */ + +static inline struct Qdisc *qdisc_refcount_inc_nz(struct Qdisc *qdisc) +{ + if (qdisc->flags & TCQ_F_BUILTIN) + return qdisc; + if (refcount_inc_not_zero(&qdisc->refcnt)) + return qdisc; + return NULL; +} + static inline bool qdisc_is_running(struct Qdisc *qdisc) { if (qdisc->flags & TCQ_F_NOLOCK)