Skip to content

Commit 6382675

Browse files
Matthew Wilcoxjgunthorpe
authored andcommitted
cma: Convert portspace IDRs to XArray
Signed-off-by: Matthew Wilcox <[email protected]> Signed-off-by: Jason Gunthorpe <[email protected]>
1 parent 81cc440 commit 6382675

File tree

1 file changed

+21
-20
lines changed
  • drivers/infiniband/core

1 file changed

+21
-20
lines changed

drivers/infiniband/core/cma.c

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
#include <linux/mutex.h>
4040
#include <linux/random.h>
4141
#include <linux/igmp.h>
42-
#include <linux/idr.h>
42+
#include <linux/xarray.h>
4343
#include <linux/inetdevice.h>
4444
#include <linux/slab.h>
4545
#include <linux/module.h>
@@ -191,18 +191,19 @@ static struct workqueue_struct *cma_wq;
191191
static unsigned int cma_pernet_id;
192192

193193
struct cma_pernet {
194-
struct idr tcp_ps;
195-
struct idr udp_ps;
196-
struct idr ipoib_ps;
197-
struct idr ib_ps;
194+
struct xarray tcp_ps;
195+
struct xarray udp_ps;
196+
struct xarray ipoib_ps;
197+
struct xarray ib_ps;
198198
};
199199

200200
static struct cma_pernet *cma_pernet(struct net *net)
201201
{
202202
return net_generic(net, cma_pernet_id);
203203
}
204204

205-
static struct idr *cma_pernet_idr(struct net *net, enum rdma_ucm_port_space ps)
205+
static
206+
struct xarray *cma_pernet_xa(struct net *net, enum rdma_ucm_port_space ps)
206207
{
207208
struct cma_pernet *pernet = cma_pernet(net);
208209

@@ -247,25 +248,25 @@ struct class_port_info_context {
247248
static int cma_ps_alloc(struct net *net, enum rdma_ucm_port_space ps,
248249
struct rdma_bind_list *bind_list, int snum)
249250
{
250-
struct idr *idr = cma_pernet_idr(net, ps);
251+
struct xarray *xa = cma_pernet_xa(net, ps);
251252

252-
return idr_alloc(idr, bind_list, snum, snum + 1, GFP_KERNEL);
253+
return xa_insert(xa, snum, bind_list, GFP_KERNEL);
253254
}
254255

255256
static struct rdma_bind_list *cma_ps_find(struct net *net,
256257
enum rdma_ucm_port_space ps, int snum)
257258
{
258-
struct idr *idr = cma_pernet_idr(net, ps);
259+
struct xarray *xa = cma_pernet_xa(net, ps);
259260

260-
return idr_find(idr, snum);
261+
return xa_load(xa, snum);
261262
}
262263

263264
static void cma_ps_remove(struct net *net, enum rdma_ucm_port_space ps,
264265
int snum)
265266
{
266-
struct idr *idr = cma_pernet_idr(net, ps);
267+
struct xarray *xa = cma_pernet_xa(net, ps);
267268

268-
idr_remove(idr, snum);
269+
xa_erase(xa, snum);
269270
}
270271

271272
enum {
@@ -4655,10 +4656,10 @@ static int cma_init_net(struct net *net)
46554656
{
46564657
struct cma_pernet *pernet = cma_pernet(net);
46574658

4658-
idr_init(&pernet->tcp_ps);
4659-
idr_init(&pernet->udp_ps);
4660-
idr_init(&pernet->ipoib_ps);
4661-
idr_init(&pernet->ib_ps);
4659+
xa_init(&pernet->tcp_ps);
4660+
xa_init(&pernet->udp_ps);
4661+
xa_init(&pernet->ipoib_ps);
4662+
xa_init(&pernet->ib_ps);
46624663

46634664
return 0;
46644665
}
@@ -4667,10 +4668,10 @@ static void cma_exit_net(struct net *net)
46674668
{
46684669
struct cma_pernet *pernet = cma_pernet(net);
46694670

4670-
idr_destroy(&pernet->tcp_ps);
4671-
idr_destroy(&pernet->udp_ps);
4672-
idr_destroy(&pernet->ipoib_ps);
4673-
idr_destroy(&pernet->ib_ps);
4671+
WARN_ON(!xa_empty(&pernet->tcp_ps));
4672+
WARN_ON(!xa_empty(&pernet->udp_ps));
4673+
WARN_ON(!xa_empty(&pernet->ipoib_ps));
4674+
WARN_ON(!xa_empty(&pernet->ib_ps));
46744675
}
46754676

46764677
static struct pernet_operations cma_pernet_operations = {

0 commit comments

Comments
 (0)