Skip to content

Commit 475f230

Browse files
committed
dlm: fix unlock balance warnings
The in_recovery rw_semaphore has always been acquired and released by different threads by design. To work around the "BUG: bad unlock balance detected!" messages, adjust things so the dlm_recoverd thread always does both down_write and up_write. Signed-off-by: David Teigland <teigland@redhat.com>
1 parent 6ad2291 commit 475f230

6 files changed

Lines changed: 78 additions & 30 deletions

File tree

‎fs/dlm/dlm_internal.h‎

Lines changed: 36 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -604,6 +604,7 @@ struct dlm_ls {
604604
struct idr ls_recover_idr;
605605
spinlock_t ls_recover_idr_lock;
606606
wait_queue_head_t ls_wait_general;
607+
wait_queue_head_t ls_recover_lock_wait;
607608
struct mutex ls_clear_proc_locks;
608609

609610
struct list_head ls_root_list; /* root resources */
@@ -616,15 +617,40 @@ struct dlm_ls {
616617
char ls_name[1];
617618
};
618619

619-
#define LSFL_WORK 0
620-
#define LSFL_RUNNING 1
621-
#define LSFL_RECOVERY_STOP 2
622-
#define LSFL_RCOM_READY 3
623-
#define LSFL_RCOM_WAIT 4
624-
#define LSFL_UEVENT_WAIT 5
625-
#define LSFL_TIMEWARN 6
626-
#define LSFL_CB_DELAY 7
627-
#define LSFL_NODIR 8
620+
/*
621+
* LSFL_RECOVER_STOP - dlm_ls_stop() sets this to tell dlm recovery routines
622+
* that they should abort what they're doing so new recovery can be started.
623+
*
624+
* LSFL_RECOVER_DOWN - dlm_ls_stop() sets this to tell dlm_recoverd that it
625+
* should do down_write() on the in_recovery rw_semaphore. (doing down_write
626+
* within dlm_ls_stop causes complaints about the lock acquired/released
627+
* in different contexts.)
628+
*
629+
* LSFL_RECOVER_LOCK - dlm_recoverd holds the in_recovery rw_semaphore.
630+
* It sets this after it is done with down_write() on the in_recovery
631+
* rw_semaphore and clears it after it has released the rw_semaphore.
632+
*
633+
* LSFL_RECOVER_WORK - dlm_ls_start() sets this to tell dlm_recoverd that it
634+
* should begin recovery of the lockspace.
635+
*
636+
* LSFL_RUNNING - set when normal locking activity is enabled.
637+
* dlm_ls_stop() clears this to tell dlm locking routines that they should
638+
* quit what they are doing so recovery can run. dlm_recoverd sets
639+
* this after recovery is finished.
640+
*/
641+
642+
#define LSFL_RECOVER_STOP 0
643+
#define LSFL_RECOVER_DOWN 1
644+
#define LSFL_RECOVER_LOCK 2
645+
#define LSFL_RECOVER_WORK 3
646+
#define LSFL_RUNNING 4
647+
648+
#define LSFL_RCOM_READY 5
649+
#define LSFL_RCOM_WAIT 6
650+
#define LSFL_UEVENT_WAIT 7
651+
#define LSFL_TIMEWARN 8
652+
#define LSFL_CB_DELAY 9
653+
#define LSFL_NODIR 10
628654

629655
/* much of this is just saving user space pointers associated with the
630656
lock that we pass back to the user lib with an ast */
@@ -667,7 +693,7 @@ static inline int dlm_locking_stopped(struct dlm_ls *ls)
667693

668694
static inline int dlm_recovery_stopped(struct dlm_ls *ls)
669695
{
670-
return test_bit(LSFL_RECOVERY_STOP, &ls->ls_flags);
696+
return test_bit(LSFL_RECOVER_STOP, &ls->ls_flags);
671697
}
672698

673699
static inline int dlm_no_directory(struct dlm_ls *ls)

‎fs/dlm/lockspace.c‎

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -582,8 +582,6 @@ static int new_lockspace(const char *name, const char *cluster,
582582
INIT_LIST_HEAD(&ls->ls_root_list);
583583
init_rwsem(&ls->ls_root_sem);
584584

585-
down_write(&ls->ls_in_recovery);
586-
587585
spin_lock(&lslist_lock);
588586
ls->ls_create_count = 1;
589587
list_add(&ls->ls_list, &lslist);
@@ -597,13 +595,24 @@ static int new_lockspace(const char *name, const char *cluster,
597595
}
598596
}
599597

600-
/* needs to find ls in lslist */
598+
init_waitqueue_head(&ls->ls_recover_lock_wait);
599+
600+
/*
601+
* Once started, dlm_recoverd first looks for ls in lslist, then
602+
* initializes ls_in_recovery as locked in "down" mode. We need
603+
* to wait for the wakeup from dlm_recoverd because in_recovery
604+
* has to start out in down mode.
605+
*/
606+
601607
error = dlm_recoverd_start(ls);
602608
if (error) {
603609
log_error(ls, "can't start dlm_recoverd %d", error);
604610
goto out_callback;
605611
}
606612

613+
wait_event(ls->ls_recover_lock_wait,
614+
test_bit(LSFL_RECOVER_LOCK, &ls->ls_flags));
615+
607616
ls->ls_kobj.kset = dlm_kset;
608617
error = kobject_init_and_add(&ls->ls_kobj, &dlm_ktype, NULL,
609618
"%s", ls->ls_name);

‎fs/dlm/member.c‎

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -616,13 +616,13 @@ int dlm_ls_stop(struct dlm_ls *ls)
616616
down_write(&ls->ls_recv_active);
617617

618618
/*
619-
* Abort any recovery that's in progress (see RECOVERY_STOP,
619+
* Abort any recovery that's in progress (see RECOVER_STOP,
620620
* dlm_recovery_stopped()) and tell any other threads running in the
621621
* dlm to quit any processing (see RUNNING, dlm_locking_stopped()).
622622
*/
623623

624624
spin_lock(&ls->ls_recover_lock);
625-
set_bit(LSFL_RECOVERY_STOP, &ls->ls_flags);
625+
set_bit(LSFL_RECOVER_STOP, &ls->ls_flags);
626626
new = test_and_clear_bit(LSFL_RUNNING, &ls->ls_flags);
627627
ls->ls_recover_seq++;
628628
spin_unlock(&ls->ls_recover_lock);
@@ -642,12 +642,16 @@ int dlm_ls_stop(struct dlm_ls *ls)
642642
* when recovery is complete.
643643
*/
644644

645-
if (new)
646-
down_write(&ls->ls_in_recovery);
645+
if (new) {
646+
set_bit(LSFL_RECOVER_DOWN, &ls->ls_flags);
647+
wake_up_process(ls->ls_recoverd_task);
648+
wait_event(ls->ls_recover_lock_wait,
649+
test_bit(LSFL_RECOVER_LOCK, &ls->ls_flags));
650+
}
647651

648652
/*
649653
* The recoverd suspend/resume makes sure that dlm_recoverd (if
650-
* running) has noticed RECOVERY_STOP above and quit processing the
654+
* running) has noticed RECOVER_STOP above and quit processing the
651655
* previous recovery.
652656
*/
653657

@@ -709,7 +713,8 @@ int dlm_ls_start(struct dlm_ls *ls)
709713
kfree(rv_old);
710714
}
711715

712-
dlm_recoverd_kick(ls);
716+
set_bit(LSFL_RECOVER_WORK, &ls->ls_flags);
717+
wake_up_process(ls->ls_recoverd_task);
713718
return 0;
714719

715720
fail:

‎fs/dlm/rcom.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -581,7 +581,7 @@ void dlm_receive_rcom(struct dlm_ls *ls, struct dlm_rcom *rc, int nodeid)
581581

582582
spin_lock(&ls->ls_recover_lock);
583583
status = ls->ls_recover_status;
584-
stop = test_bit(LSFL_RECOVERY_STOP, &ls->ls_flags);
584+
stop = test_bit(LSFL_RECOVER_STOP, &ls->ls_flags);
585585
seq = ls->ls_recover_seq;
586586
spin_unlock(&ls->ls_recover_lock);
587587

‎fs/dlm/recoverd.c‎

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ static int enable_locking(struct dlm_ls *ls, uint64_t seq)
4141
set_bit(LSFL_RUNNING, &ls->ls_flags);
4242
/* unblocks processes waiting to enter the dlm */
4343
up_write(&ls->ls_in_recovery);
44+
clear_bit(LSFL_RECOVER_LOCK, &ls->ls_flags);
4445
error = 0;
4546
}
4647
spin_unlock(&ls->ls_recover_lock);
@@ -262,7 +263,7 @@ static void do_ls_recovery(struct dlm_ls *ls)
262263
rv = ls->ls_recover_args;
263264
ls->ls_recover_args = NULL;
264265
if (rv && ls->ls_recover_seq == rv->seq)
265-
clear_bit(LSFL_RECOVERY_STOP, &ls->ls_flags);
266+
clear_bit(LSFL_RECOVER_STOP, &ls->ls_flags);
266267
spin_unlock(&ls->ls_recover_lock);
267268

268269
if (rv) {
@@ -282,26 +283,34 @@ static int dlm_recoverd(void *arg)
282283
return -1;
283284
}
284285

286+
down_write(&ls->ls_in_recovery);
287+
set_bit(LSFL_RECOVER_LOCK, &ls->ls_flags);
288+
wake_up(&ls->ls_recover_lock_wait);
289+
285290
while (!kthread_should_stop()) {
286291
set_current_state(TASK_INTERRUPTIBLE);
287-
if (!test_bit(LSFL_WORK, &ls->ls_flags))
292+
if (!test_bit(LSFL_RECOVER_WORK, &ls->ls_flags) &&
293+
!test_bit(LSFL_RECOVER_DOWN, &ls->ls_flags))
288294
schedule();
289295
set_current_state(TASK_RUNNING);
290296

291-
if (test_and_clear_bit(LSFL_WORK, &ls->ls_flags))
297+
if (test_and_clear_bit(LSFL_RECOVER_DOWN, &ls->ls_flags)) {
298+
down_write(&ls->ls_in_recovery);
299+
set_bit(LSFL_RECOVER_LOCK, &ls->ls_flags);
300+
wake_up(&ls->ls_recover_lock_wait);
301+
}
302+
303+
if (test_and_clear_bit(LSFL_RECOVER_WORK, &ls->ls_flags))
292304
do_ls_recovery(ls);
293305
}
294306

307+
if (test_bit(LSFL_RECOVER_LOCK, &ls->ls_flags))
308+
up_write(&ls->ls_in_recovery);
309+
295310
dlm_put_lockspace(ls);
296311
return 0;
297312
}
298313

299-
void dlm_recoverd_kick(struct dlm_ls *ls)
300-
{
301-
set_bit(LSFL_WORK, &ls->ls_flags);
302-
wake_up_process(ls->ls_recoverd_task);
303-
}
304-
305314
int dlm_recoverd_start(struct dlm_ls *ls)
306315
{
307316
struct task_struct *p;

‎fs/dlm/recoverd.h‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
#ifndef __RECOVERD_DOT_H__
1515
#define __RECOVERD_DOT_H__
1616

17-
void dlm_recoverd_kick(struct dlm_ls *ls);
1817
void dlm_recoverd_stop(struct dlm_ls *ls);
1918
int dlm_recoverd_start(struct dlm_ls *ls);
2019
void dlm_recoverd_suspend(struct dlm_ls *ls);

0 commit comments

Comments
 (0)