]> git.baikalelectronics.ru Git - kernel.git/commitdiff
net: sched: add helper function to take reference to Qdisc
authorVlad Buslov <vladbu@mellanox.com>
Mon, 24 Sep 2018 16:22:52 +0000 (19:22 +0300)
committerDavid S. Miller <davem@davemloft.net>
Wed, 26 Sep 2018 03:17:35 +0000 (20:17 -0700)
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 <vladbu@mellanox.com>
Acked-by: Jiri Pirko <jiri@mellanox.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
include/net/sch_generic.h

index 091b40c198ff8a7d80bc6178fce60bb64a16d9e8..43b17f82d8eebad5239a9b86a145aa9d556ef29c 100644 (file)
@@ -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)