Skip to content

Commit f455eb8

Browse files
Alexander Aringteigland
authored andcommitted
dlm: move lkb idr to xarray datastructure
According to kernel doc idr is deprecated and xarrays should be used nowadays. This patch is moving the lkb idr implementation to xarrays. Signed-off-by: Alexander Aring <[email protected]> Signed-off-by: David Teigland <[email protected]>
1 parent 1ffefc1 commit f455eb8

File tree

3 files changed

+49
-46
lines changed

3 files changed

+49
-46
lines changed

fs/dlm/dlm_internal.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
#include <linux/rhashtable.h>
3838
#include <linux/mutex.h>
3939
#include <linux/idr.h>
40+
#include <linux/xarray.h>
4041
#include <linux/ratelimit.h>
4142
#include <linux/uaccess.h>
4243

@@ -569,8 +570,8 @@ struct dlm_ls {
569570
unsigned long ls_flags; /* LSFL_ */
570571
struct kobject ls_kobj;
571572

572-
struct idr ls_lkbidr;
573-
rwlock_t ls_lkbidr_lock;
573+
struct xarray ls_lkbxa;
574+
rwlock_t ls_lkbxa_lock;
574575

575576
struct rhashtable ls_rsbtbl;
576577
rwlock_t ls_rsbtbl_lock;

fs/dlm/lock.c

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1435,11 +1435,15 @@ static void detach_lkb(struct dlm_lkb *lkb)
14351435
}
14361436

14371437
static int _create_lkb(struct dlm_ls *ls, struct dlm_lkb **lkb_ret,
1438-
int start, int end)
1438+
unsigned long start, unsigned long end)
14391439
{
1440+
struct xa_limit limit;
14401441
struct dlm_lkb *lkb;
14411442
int rv;
14421443

1444+
limit.max = end;
1445+
limit.min = start;
1446+
14431447
lkb = dlm_allocate_lkb(ls);
14441448
if (!lkb)
14451449
return -ENOMEM;
@@ -1453,14 +1457,12 @@ static int _create_lkb(struct dlm_ls *ls, struct dlm_lkb **lkb_ret,
14531457
INIT_LIST_HEAD(&lkb->lkb_ownqueue);
14541458
INIT_LIST_HEAD(&lkb->lkb_rsb_lookup);
14551459

1456-
write_lock_bh(&ls->ls_lkbidr_lock);
1457-
rv = idr_alloc(&ls->ls_lkbidr, lkb, start, end, GFP_NOWAIT);
1458-
if (rv >= 0)
1459-
lkb->lkb_id = rv;
1460-
write_unlock_bh(&ls->ls_lkbidr_lock);
1460+
write_lock_bh(&ls->ls_lkbxa_lock);
1461+
rv = xa_alloc(&ls->ls_lkbxa, &lkb->lkb_id, lkb, limit, GFP_ATOMIC);
1462+
write_unlock_bh(&ls->ls_lkbxa_lock);
14611463

14621464
if (rv < 0) {
1463-
log_error(ls, "create_lkb idr error %d", rv);
1465+
log_error(ls, "create_lkb xa error %d", rv);
14641466
dlm_free_lkb(lkb);
14651467
return rv;
14661468
}
@@ -1471,18 +1473,18 @@ static int _create_lkb(struct dlm_ls *ls, struct dlm_lkb **lkb_ret,
14711473

14721474
static int create_lkb(struct dlm_ls *ls, struct dlm_lkb **lkb_ret)
14731475
{
1474-
return _create_lkb(ls, lkb_ret, 1, 0);
1476+
return _create_lkb(ls, lkb_ret, 1, ULONG_MAX);
14751477
}
14761478

14771479
static int find_lkb(struct dlm_ls *ls, uint32_t lkid, struct dlm_lkb **lkb_ret)
14781480
{
14791481
struct dlm_lkb *lkb;
14801482

1481-
read_lock_bh(&ls->ls_lkbidr_lock);
1482-
lkb = idr_find(&ls->ls_lkbidr, lkid);
1483+
read_lock_bh(&ls->ls_lkbxa_lock);
1484+
lkb = xa_load(&ls->ls_lkbxa, lkid);
14831485
if (lkb)
14841486
kref_get(&lkb->lkb_ref);
1485-
read_unlock_bh(&ls->ls_lkbidr_lock);
1487+
read_unlock_bh(&ls->ls_lkbxa_lock);
14861488

14871489
*lkb_ret = lkb;
14881490
return lkb ? 0 : -ENOENT;
@@ -1507,10 +1509,10 @@ static int __put_lkb(struct dlm_ls *ls, struct dlm_lkb *lkb)
15071509
int rv;
15081510

15091511
rv = dlm_kref_put_write_lock_bh(&lkb->lkb_ref, kill_lkb,
1510-
&ls->ls_lkbidr_lock);
1512+
&ls->ls_lkbxa_lock);
15111513
if (rv) {
1512-
idr_remove(&ls->ls_lkbidr, lkid);
1513-
write_unlock_bh(&ls->ls_lkbidr_lock);
1514+
xa_erase(&ls->ls_lkbxa, lkid);
1515+
write_unlock_bh(&ls->ls_lkbxa_lock);
15141516

15151517
detach_lkb(lkb);
15161518

fs/dlm/lockspace.c

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -420,8 +420,8 @@ static int new_lockspace(const char *name, const char *cluster,
420420
if (error)
421421
goto out_lsfree;
422422

423-
idr_init(&ls->ls_lkbidr);
424-
rwlock_init(&ls->ls_lkbidr_lock);
423+
xa_init_flags(&ls->ls_lkbxa, XA_FLAGS_ALLOC | XA_FLAGS_LOCK_BH);
424+
rwlock_init(&ls->ls_lkbxa_lock);
425425

426426
INIT_LIST_HEAD(&ls->ls_waiters);
427427
spin_lock_init(&ls->ls_waiters_lock);
@@ -471,7 +471,7 @@ static int new_lockspace(const char *name, const char *cluster,
471471
ls->ls_recover_buf = kmalloc(DLM_MAX_SOCKET_BUFSIZE, GFP_NOFS);
472472
if (!ls->ls_recover_buf) {
473473
error = -ENOMEM;
474-
goto out_lkbidr;
474+
goto out_lkbxa;
475475
}
476476

477477
ls->ls_slot = 0;
@@ -572,8 +572,8 @@ static int new_lockspace(const char *name, const char *cluster,
572572
spin_unlock_bh(&lslist_lock);
573573
idr_destroy(&ls->ls_recover_idr);
574574
kfree(ls->ls_recover_buf);
575-
out_lkbidr:
576-
idr_destroy(&ls->ls_lkbidr);
575+
out_lkbxa:
576+
xa_destroy(&ls->ls_lkbxa);
577577
rhashtable_destroy(&ls->ls_rsbtbl);
578578
out_lsfree:
579579
if (do_unreg)
@@ -633,46 +633,43 @@ int dlm_new_user_lockspace(const char *name, const char *cluster,
633633
ops_arg, ops_result, lockspace);
634634
}
635635

636-
static int lkb_idr_is_local(int id, void *p, void *data)
636+
static int lkb_idr_free(struct dlm_lkb *lkb)
637637
{
638-
struct dlm_lkb *lkb = p;
639-
640-
return lkb->lkb_nodeid == 0 && lkb->lkb_grmode != DLM_LOCK_IV;
641-
}
642-
643-
static int lkb_idr_is_any(int id, void *p, void *data)
644-
{
645-
return 1;
646-
}
647-
648-
static int lkb_idr_free(int id, void *p, void *data)
649-
{
650-
struct dlm_lkb *lkb = p;
651-
652638
if (lkb->lkb_lvbptr && test_bit(DLM_IFL_MSTCPY_BIT, &lkb->lkb_iflags))
653639
dlm_free_lvb(lkb->lkb_lvbptr);
654640

655641
dlm_free_lkb(lkb);
656642
return 0;
657643
}
658644

659-
/* NOTE: We check the lkbidr here rather than the resource table.
645+
/* NOTE: We check the lkbxa here rather than the resource table.
660646
This is because there may be LKBs queued as ASTs that have been unlinked
661647
from their RSBs and are pending deletion once the AST has been delivered */
662648

663649
static int lockspace_busy(struct dlm_ls *ls, int force)
664650
{
665-
int rv;
651+
struct dlm_lkb *lkb;
652+
unsigned long id;
653+
int rv = 0;
666654

667-
read_lock_bh(&ls->ls_lkbidr_lock);
655+
read_lock_bh(&ls->ls_lkbxa_lock);
668656
if (force == 0) {
669-
rv = idr_for_each(&ls->ls_lkbidr, lkb_idr_is_any, ls);
657+
xa_for_each(&ls->ls_lkbxa, id, lkb) {
658+
rv = 1;
659+
break;
660+
}
670661
} else if (force == 1) {
671-
rv = idr_for_each(&ls->ls_lkbidr, lkb_idr_is_local, ls);
662+
xa_for_each(&ls->ls_lkbxa, id, lkb) {
663+
if (lkb->lkb_nodeid == 0 &&
664+
lkb->lkb_grmode != DLM_LOCK_IV) {
665+
rv = 1;
666+
break;
667+
}
668+
}
672669
} else {
673670
rv = 0;
674671
}
675-
read_unlock_bh(&ls->ls_lkbidr_lock);
672+
read_unlock_bh(&ls->ls_lkbxa_lock);
676673
return rv;
677674
}
678675

@@ -685,6 +682,8 @@ static void rhash_free_rsb(void *ptr, void *arg)
685682

686683
static int release_lockspace(struct dlm_ls *ls, int force)
687684
{
685+
struct dlm_lkb *lkb;
686+
unsigned long id;
688687
int busy, rv;
689688

690689
busy = lockspace_busy(ls, force);
@@ -741,11 +740,12 @@ static int release_lockspace(struct dlm_ls *ls, int force)
741740
kfree(ls->ls_recover_buf);
742741

743742
/*
744-
* Free all lkb's in idr
743+
* Free all lkb's in xa
745744
*/
746-
747-
idr_for_each(&ls->ls_lkbidr, lkb_idr_free, ls);
748-
idr_destroy(&ls->ls_lkbidr);
745+
xa_for_each(&ls->ls_lkbxa, id, lkb) {
746+
lkb_idr_free(lkb);
747+
}
748+
xa_destroy(&ls->ls_lkbxa);
749749

750750
/*
751751
* Free all rsb's on rsbtbl

0 commit comments

Comments
 (0)