Skip to content

Commit fa0b54f

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

File tree

3 files changed

+40
-36
lines changed

3 files changed

+40
-36
lines changed

fs/dlm/dlm_internal.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
#include <linux/miscdevice.h>
3737
#include <linux/rhashtable.h>
3838
#include <linux/mutex.h>
39-
#include <linux/idr.h>
4039
#include <linux/xarray.h>
4140
#include <linux/ratelimit.h>
4241
#include <linux/uaccess.h>
@@ -317,7 +316,7 @@ struct dlm_rsb {
317316
int res_nodeid;
318317
int res_master_nodeid;
319318
int res_dir_nodeid;
320-
int res_id; /* for ls_recover_idr */
319+
unsigned long res_id; /* for ls_recover_xa */
321320
uint32_t res_lvbseq;
322321
uint32_t res_hash;
323322
unsigned long res_toss_time;
@@ -649,8 +648,8 @@ struct dlm_ls {
649648
struct list_head ls_recover_list;
650649
spinlock_t ls_recover_list_lock;
651650
int ls_recover_list_count;
652-
struct idr ls_recover_idr;
653-
spinlock_t ls_recover_idr_lock;
651+
struct xarray ls_recover_xa;
652+
spinlock_t ls_recover_xa_lock;
654653
wait_queue_head_t ls_wait_general;
655654
wait_queue_head_t ls_recover_lock_wait;
656655
spinlock_t ls_clear_proc_locks;

fs/dlm/lockspace.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -481,8 +481,8 @@ static int new_lockspace(const char *name, const char *cluster,
481481

482482
INIT_LIST_HEAD(&ls->ls_recover_list);
483483
spin_lock_init(&ls->ls_recover_list_lock);
484-
idr_init(&ls->ls_recover_idr);
485-
spin_lock_init(&ls->ls_recover_idr_lock);
484+
xa_init_flags(&ls->ls_recover_xa, XA_FLAGS_ALLOC | XA_FLAGS_LOCK_BH);
485+
spin_lock_init(&ls->ls_recover_xa_lock);
486486
ls->ls_recover_list_count = 0;
487487
init_waitqueue_head(&ls->ls_wait_general);
488488
INIT_LIST_HEAD(&ls->ls_masters_list);
@@ -570,7 +570,7 @@ static int new_lockspace(const char *name, const char *cluster,
570570
spin_lock_bh(&lslist_lock);
571571
list_del(&ls->ls_list);
572572
spin_unlock_bh(&lslist_lock);
573-
idr_destroy(&ls->ls_recover_idr);
573+
xa_destroy(&ls->ls_recover_xa);
574574
kfree(ls->ls_recover_buf);
575575
out_lkbxa:
576576
xa_destroy(&ls->ls_lkbxa);
@@ -736,7 +736,7 @@ static int release_lockspace(struct dlm_ls *ls, int force)
736736

737737
dlm_delete_debug_file(ls);
738738

739-
idr_destroy(&ls->ls_recover_idr);
739+
xa_destroy(&ls->ls_recover_xa);
740740
kfree(ls->ls_recover_buf);
741741

742742
/*

fs/dlm/recover.c

Lines changed: 33 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -293,73 +293,78 @@ static void recover_list_clear(struct dlm_ls *ls)
293293
spin_unlock_bh(&ls->ls_recover_list_lock);
294294
}
295295

296-
static int recover_idr_empty(struct dlm_ls *ls)
296+
static int recover_xa_empty(struct dlm_ls *ls)
297297
{
298298
int empty = 1;
299299

300-
spin_lock_bh(&ls->ls_recover_idr_lock);
300+
spin_lock_bh(&ls->ls_recover_xa_lock);
301301
if (ls->ls_recover_list_count)
302302
empty = 0;
303-
spin_unlock_bh(&ls->ls_recover_idr_lock);
303+
spin_unlock_bh(&ls->ls_recover_xa_lock);
304304

305305
return empty;
306306
}
307307

308-
static int recover_idr_add(struct dlm_rsb *r)
308+
static int recover_xa_add(struct dlm_rsb *r)
309309
{
310310
struct dlm_ls *ls = r->res_ls;
311+
struct xa_limit limit = {
312+
.min = 1,
313+
.max = UINT_MAX,
314+
};
315+
uint32_t id;
311316
int rv;
312317

313-
spin_lock_bh(&ls->ls_recover_idr_lock);
318+
spin_lock_bh(&ls->ls_recover_xa_lock);
314319
if (r->res_id) {
315320
rv = -1;
316321
goto out_unlock;
317322
}
318-
rv = idr_alloc(&ls->ls_recover_idr, r, 1, 0, GFP_NOWAIT);
323+
rv = xa_alloc(&ls->ls_recover_xa, &id, r, limit, GFP_ATOMIC);
319324
if (rv < 0)
320325
goto out_unlock;
321326

322-
r->res_id = rv;
327+
r->res_id = id;
323328
ls->ls_recover_list_count++;
324329
dlm_hold_rsb(r);
325330
rv = 0;
326331
out_unlock:
327-
spin_unlock_bh(&ls->ls_recover_idr_lock);
332+
spin_unlock_bh(&ls->ls_recover_xa_lock);
328333
return rv;
329334
}
330335

331-
static void recover_idr_del(struct dlm_rsb *r)
336+
static void recover_xa_del(struct dlm_rsb *r)
332337
{
333338
struct dlm_ls *ls = r->res_ls;
334339

335-
spin_lock_bh(&ls->ls_recover_idr_lock);
336-
idr_remove(&ls->ls_recover_idr, r->res_id);
340+
spin_lock_bh(&ls->ls_recover_xa_lock);
341+
xa_erase_bh(&ls->ls_recover_xa, r->res_id);
337342
r->res_id = 0;
338343
ls->ls_recover_list_count--;
339-
spin_unlock_bh(&ls->ls_recover_idr_lock);
344+
spin_unlock_bh(&ls->ls_recover_xa_lock);
340345

341346
dlm_put_rsb(r);
342347
}
343348

344-
static struct dlm_rsb *recover_idr_find(struct dlm_ls *ls, uint64_t id)
349+
static struct dlm_rsb *recover_xa_find(struct dlm_ls *ls, uint64_t id)
345350
{
346351
struct dlm_rsb *r;
347352

348-
spin_lock_bh(&ls->ls_recover_idr_lock);
349-
r = idr_find(&ls->ls_recover_idr, (int)id);
350-
spin_unlock_bh(&ls->ls_recover_idr_lock);
353+
spin_lock_bh(&ls->ls_recover_xa_lock);
354+
r = xa_load(&ls->ls_recover_xa, (int)id);
355+
spin_unlock_bh(&ls->ls_recover_xa_lock);
351356
return r;
352357
}
353358

354-
static void recover_idr_clear(struct dlm_ls *ls)
359+
static void recover_xa_clear(struct dlm_ls *ls)
355360
{
356361
struct dlm_rsb *r;
357-
int id;
362+
unsigned long id;
358363

359-
spin_lock_bh(&ls->ls_recover_idr_lock);
364+
spin_lock_bh(&ls->ls_recover_xa_lock);
360365

361-
idr_for_each_entry(&ls->ls_recover_idr, r, id) {
362-
idr_remove(&ls->ls_recover_idr, id);
366+
xa_for_each(&ls->ls_recover_xa, id, r) {
367+
xa_erase_bh(&ls->ls_recover_xa, id);
363368
r->res_id = 0;
364369
r->res_recover_locks_count = 0;
365370
ls->ls_recover_list_count--;
@@ -372,7 +377,7 @@ static void recover_idr_clear(struct dlm_ls *ls)
372377
ls->ls_recover_list_count);
373378
ls->ls_recover_list_count = 0;
374379
}
375-
spin_unlock_bh(&ls->ls_recover_idr_lock);
380+
spin_unlock_bh(&ls->ls_recover_xa_lock);
376381
}
377382

378383

@@ -470,7 +475,7 @@ static int recover_master(struct dlm_rsb *r, unsigned int *count, uint64_t seq)
470475
set_new_master(r);
471476
error = 0;
472477
} else {
473-
recover_idr_add(r);
478+
recover_xa_add(r);
474479
error = dlm_send_rcom_lookup(r, dir_nodeid, seq);
475480
}
476481

@@ -551,10 +556,10 @@ int dlm_recover_masters(struct dlm_ls *ls, uint64_t seq,
551556

552557
log_rinfo(ls, "dlm_recover_masters %u of %u", count, total);
553558

554-
error = dlm_wait_function(ls, &recover_idr_empty);
559+
error = dlm_wait_function(ls, &recover_xa_empty);
555560
out:
556561
if (error)
557-
recover_idr_clear(ls);
562+
recover_xa_clear(ls);
558563
return error;
559564
}
560565

@@ -563,7 +568,7 @@ int dlm_recover_master_reply(struct dlm_ls *ls, const struct dlm_rcom *rc)
563568
struct dlm_rsb *r;
564569
int ret_nodeid, new_master;
565570

566-
r = recover_idr_find(ls, le64_to_cpu(rc->rc_id));
571+
r = recover_xa_find(ls, le64_to_cpu(rc->rc_id));
567572
if (!r) {
568573
log_error(ls, "dlm_recover_master_reply no id %llx",
569574
(unsigned long long)le64_to_cpu(rc->rc_id));
@@ -582,9 +587,9 @@ int dlm_recover_master_reply(struct dlm_ls *ls, const struct dlm_rcom *rc)
582587
r->res_nodeid = new_master;
583588
set_new_master(r);
584589
unlock_rsb(r);
585-
recover_idr_del(r);
590+
recover_xa_del(r);
586591

587-
if (recover_idr_empty(ls))
592+
if (recover_xa_empty(ls))
588593
wake_up(&ls->ls_wait_general);
589594
out:
590595
return 0;

0 commit comments

Comments
 (0)