[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20190820223259.22348-24-willy@infradead.org>
Date: Tue, 20 Aug 2019 15:32:44 -0700
From: Matthew Wilcox <willy@...radead.org>
To: netdev@...r.kernel.org
Cc: "Matthew Wilcox (Oracle)" <willy@...radead.org>
Subject: [PATCH 23/38] cls_api: Convert tcf_net to XArray
From: "Matthew Wilcox (Oracle)" <willy@...radead.org>
This module doesn't use the allocating functionality; convert it to a
plain XArray instead of an allocating one. I've left struct tcf_net
in place in case more objects are added to it in future, although
it now only contains an XArray. We don't need to call xa_destroy()
if the array is empty, so I've removed the contents of tcf_net_exit()
-- if it can be called with entries still in place, then it shoud call
xa_destroy() instead.
Signed-off-by: Matthew Wilcox (Oracle) <willy@...radead.org>
---
net/sched/cls_api.c | 27 ++++++---------------------
1 file changed, 6 insertions(+), 21 deletions(-)
diff --git a/net/sched/cls_api.c b/net/sched/cls_api.c
index e0d8b456e9f5..8392a7ef0ed4 100644
--- a/net/sched/cls_api.c
+++ b/net/sched/cls_api.c
@@ -19,7 +19,7 @@
#include <linux/init.h>
#include <linux/kmod.h>
#include <linux/slab.h>
-#include <linux/idr.h>
+#include <linux/xarray.h>
#include <linux/rhashtable.h>
#include <net/net_namespace.h>
#include <net/sock.h>
@@ -777,8 +777,7 @@ tcf_chain0_head_change_cb_del(struct tcf_block *block,
}
struct tcf_net {
- spinlock_t idr_lock; /* Protects idr */
- struct idr idr;
+ struct xarray blocks;
};
static unsigned int tcf_net_id;
@@ -787,25 +786,15 @@ static int tcf_block_insert(struct tcf_block *block, struct net *net,
struct netlink_ext_ack *extack)
{
struct tcf_net *tn = net_generic(net, tcf_net_id);
- int err;
-
- idr_preload(GFP_KERNEL);
- spin_lock(&tn->idr_lock);
- err = idr_alloc_u32(&tn->idr, block, &block->index, block->index,
- GFP_NOWAIT);
- spin_unlock(&tn->idr_lock);
- idr_preload_end();
- return err;
+ return xa_insert(&tn->blocks, block->index, block, GFP_KERNEL);
}
static void tcf_block_remove(struct tcf_block *block, struct net *net)
{
struct tcf_net *tn = net_generic(net, tcf_net_id);
- spin_lock(&tn->idr_lock);
- idr_remove(&tn->idr, block->index);
- spin_unlock(&tn->idr_lock);
+ xa_erase(&tn->blocks, block->index);
}
static struct tcf_block *tcf_block_create(struct net *net, struct Qdisc *q,
@@ -839,7 +828,7 @@ static struct tcf_block *tcf_block_lookup(struct net *net, u32 block_index)
{
struct tcf_net *tn = net_generic(net, tcf_net_id);
- return idr_find(&tn->idr, block_index);
+ return xa_load(&tn->blocks, block_index);
}
static struct tcf_block *tcf_block_refcnt_get(struct net *net, u32 block_index)
@@ -3164,16 +3153,12 @@ static __net_init int tcf_net_init(struct net *net)
{
struct tcf_net *tn = net_generic(net, tcf_net_id);
- spin_lock_init(&tn->idr_lock);
- idr_init(&tn->idr);
+ xa_init(&tn->blocks);
return 0;
}
static void __net_exit tcf_net_exit(struct net *net)
{
- struct tcf_net *tn = net_generic(net, tcf_net_id);
-
- idr_destroy(&tn->idr);
}
static struct pernet_operations tcf_net_ops = {
--
2.23.0.rc1
Powered by blists - more mailing lists