summaryrefslogtreecommitdiff
path: root/include/linux/mroute_base.h
diff options
context:
space:
mode:
authorYuval Mintz <yuvalm@mellanox.com>2018-03-26 15:01:36 +0300
committerDavid S. Miller <davem@davemloft.net>2018-03-26 13:14:43 -0400
commit8c13af2a219c6498071b30ea558438c74267ae4d (patch)
tree747dd0d7e4eb618fbacc0cbf27e7900d95618b75 /include/linux/mroute_base.h
parentd3c07e5b9939a055fa017f200e535ae947eb22ab (diff)
downloadlwn-8c13af2a219c6498071b30ea558438c74267ae4d.tar.gz
lwn-8c13af2a219c6498071b30ea558438c74267ae4d.zip
ip6mr: Add refcounting to mfc
Since ipmr and ip6mr are using the same mr_mfc struct at their core, we can now refactor the ipmr_cache_{hold,put} logic and apply refcounting to both ipmr and ip6mr. Signed-off-by: Yuval Mintz <yuvalm@mellanox.com> Signed-off-by: Ido Schimmel <idosch@mellanox.com> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'include/linux/mroute_base.h')
-rw-r--r--include/linux/mroute_base.h13
1 files changed, 13 insertions, 0 deletions
diff --git a/include/linux/mroute_base.h b/include/linux/mroute_base.h
index 289eb5aa7b5d..d617fe45543e 100644
--- a/include/linux/mroute_base.h
+++ b/include/linux/mroute_base.h
@@ -125,6 +125,7 @@ enum {
* @refcount: reference count for this entry
* @list: global entry list
* @rcu: used for entry destruction
+ * @free: Operation used for freeing an entry under RCU
*/
struct mr_mfc {
struct rhlist_head mnode;
@@ -150,8 +151,20 @@ struct mr_mfc {
} mfc_un;
struct list_head list;
struct rcu_head rcu;
+ void (*free)(struct rcu_head *head);
};
+static inline void mr_cache_put(struct mr_mfc *c)
+{
+ if (refcount_dec_and_test(&c->mfc_un.res.refcount))
+ call_rcu(&c->rcu, c->free);
+}
+
+static inline void mr_cache_hold(struct mr_mfc *c)
+{
+ refcount_inc(&c->mfc_un.res.refcount);
+}
+
struct mfc_entry_notifier_info {
struct fib_notifier_info info;
struct mr_mfc *mfc;