diff mbox series

[23/38] cls_api: Convert tcf_net to XArray

Message ID 20190820223259.22348-24-willy@infradead.org
State Changes Requested
Delegated to: David Miller
Headers show
Series Convert networking to use the XArray | expand

Commit Message

Matthew Wilcox Aug. 20, 2019, 10:32 p.m. UTC
From: "Matthew Wilcox (Oracle)" <willy@infradead.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@infradead.org>
---
 net/sched/cls_api.c | 27 ++++++---------------------
 1 file changed, 6 insertions(+), 21 deletions(-)

Comments

David Miller Aug. 20, 2019, 11:57 p.m. UTC | #1
From: Matthew Wilcox <willy@infradead.org>
Date: Tue, 20 Aug 2019 15:32:44 -0700

> From: "Matthew Wilcox (Oracle)" <willy@infradead.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@infradead.org>

I don't know if the net exit can be invoked with entires still in place,
however if the tcf_net_exit() function is made empty it should be removed
along with the assignment to the per-netns ops.
Matthew Wilcox Aug. 21, 2019, 12:52 a.m. UTC | #2
On Tue, Aug 20, 2019 at 04:57:28PM -0700, David Miller wrote:
> > From: "Matthew Wilcox (Oracle)" <willy@infradead.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@infradead.org>
> 
> I don't know if the net exit can be invoked with entires still in place,
> however if the tcf_net_exit() function is made empty it should be removed
> along with the assignment to the per-netns ops.

Thanks!  I wasn't sure what the rule was for these ops.  I'll fix that up.
diff mbox series

Patch

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 = {