Skip to content

Commit c36258b

Browse files
teiglandswhiteho
authored andcommitted
[DLM] block dlm_recv in recovery transition
Introduce a per-lockspace rwsem that's held in read mode by dlm_recv threads while working in the dlm. This allows dlm_recv activity to be suspended when the lockspace transitions to, from and between recovery cycles. The specific bug prompting this change is one where an in-progress recovery cycle is aborted by a new recovery cycle. While dlm_recv was processing a recovery message, the recovery cycle was aborted and dlm_recoverd began cleaning up. dlm_recv decremented recover_locks_count on an rsb after dlm_recoverd had reset it to zero. This is fixed by suspending dlm_recv (taking write lock on the rwsem) before aborting the current recovery. The transitions to/from normal and recovery modes are simplified by using this new ability to block dlm_recv. The switch from normal to recovery mode means dlm_recv goes from processing locking messages, to saving them for later, and vice versa. Races are avoided by blocking dlm_recv when setting the flag that switches between modes. Signed-off-by: David Teigland <teigland@redhat.com> Signed-off-by: Steven Whitehouse <swhiteho@redhat.com>
1 parent b434eda commit c36258b

11 files changed

Lines changed: 161 additions & 152 deletions

File tree

‎fs/dlm/dlm_internal.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -491,6 +491,7 @@ struct dlm_ls {
491491
uint64_t ls_recover_seq;
492492
struct dlm_recover *ls_recover_args;
493493
struct rw_semaphore ls_in_recovery; /* block local requests */
494+
struct rw_semaphore ls_recv_active; /* block dlm_recv */
494495
struct list_head ls_requestqueue;/* queue remote requests */
495496
struct mutex ls_requestqueue_mutex;
496497
char *ls_recover_buf;

‎fs/dlm/lock.c‎

Lines changed: 81 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -3638,55 +3638,8 @@ static void receive_lookup_reply(struct dlm_ls *ls, struct dlm_message *ms)
36383638
dlm_put_lkb(lkb);
36393639
}
36403640

3641-
int dlm_receive_message(struct dlm_header *hd, int nodeid, int recovery)
3641+
static void _receive_message(struct dlm_ls *ls, struct dlm_message *ms)
36423642
{
3643-
struct dlm_message *ms = (struct dlm_message *) hd;
3644-
struct dlm_ls *ls;
3645-
int error = 0;
3646-
3647-
if (!recovery)
3648-
dlm_message_in(ms);
3649-
3650-
ls = dlm_find_lockspace_global(hd->h_lockspace);
3651-
if (!ls) {
3652-
log_print("drop message %d from %d for unknown lockspace %d",
3653-
ms->m_type, nodeid, hd->h_lockspace);
3654-
return -EINVAL;
3655-
}
3656-
3657-
/* recovery may have just ended leaving a bunch of backed-up requests
3658-
in the requestqueue; wait while dlm_recoverd clears them */
3659-
3660-
if (!recovery)
3661-
dlm_wait_requestqueue(ls);
3662-
3663-
/* recovery may have just started while there were a bunch of
3664-
in-flight requests -- save them in requestqueue to be processed
3665-
after recovery. we can't let dlm_recvd block on the recovery
3666-
lock. if dlm_recoverd is calling this function to clear the
3667-
requestqueue, it needs to be interrupted (-EINTR) if another
3668-
recovery operation is starting. */
3669-
3670-
while (1) {
3671-
if (dlm_locking_stopped(ls)) {
3672-
if (recovery) {
3673-
error = -EINTR;
3674-
goto out;
3675-
}
3676-
error = dlm_add_requestqueue(ls, nodeid, hd);
3677-
if (error == -EAGAIN)
3678-
continue;
3679-
else {
3680-
error = -EINTR;
3681-
goto out;
3682-
}
3683-
}
3684-
3685-
if (dlm_lock_recovery_try(ls))
3686-
break;
3687-
schedule();
3688-
}
3689-
36903643
switch (ms->m_type) {
36913644

36923645
/* messages sent to a master node */
@@ -3761,17 +3714,90 @@ int dlm_receive_message(struct dlm_header *hd, int nodeid, int recovery)
37613714
log_error(ls, "unknown message type %d", ms->m_type);
37623715
}
37633716

3764-
dlm_unlock_recovery(ls);
3765-
out:
3766-
dlm_put_lockspace(ls);
37673717
dlm_astd_wake();
3768-
return error;
37693718
}
37703719

3720+
/* If the lockspace is in recovery mode (locking stopped), then normal
3721+
messages are saved on the requestqueue for processing after recovery is
3722+
done. When not in recovery mode, we wait for dlm_recoverd to drain saved
3723+
messages off the requestqueue before we process new ones. This occurs right
3724+
after recovery completes when we transition from saving all messages on
3725+
requestqueue, to processing all the saved messages, to processing new
3726+
messages as they arrive. */
37713727

3772-
/*
3773-
* Recovery related
3774-
*/
3728+
static void dlm_receive_message(struct dlm_ls *ls, struct dlm_message *ms,
3729+
int nodeid)
3730+
{
3731+
if (dlm_locking_stopped(ls)) {
3732+
dlm_add_requestqueue(ls, nodeid, (struct dlm_header *) ms);
3733+
} else {
3734+
dlm_wait_requestqueue(ls);
3735+
_receive_message(ls, ms);
3736+
}
3737+
}
3738+
3739+
/* This is called by dlm_recoverd to process messages that were saved on
3740+
the requestqueue. */
3741+
3742+
void dlm_receive_message_saved(struct dlm_ls *ls, struct dlm_message *ms)
3743+
{
3744+
_receive_message(ls, ms);
3745+
}
3746+
3747+
/* This is called by the midcomms layer when something is received for
3748+
the lockspace. It could be either a MSG (normal message sent as part of
3749+
standard locking activity) or an RCOM (recovery message sent as part of
3750+
lockspace recovery). */
3751+
3752+
void dlm_receive_buffer(struct dlm_header *hd, int nodeid)
3753+
{
3754+
struct dlm_message *ms = (struct dlm_message *) hd;
3755+
struct dlm_rcom *rc = (struct dlm_rcom *) hd;
3756+
struct dlm_ls *ls;
3757+
int type = 0;
3758+
3759+
switch (hd->h_cmd) {
3760+
case DLM_MSG:
3761+
dlm_message_in(ms);
3762+
type = ms->m_type;
3763+
break;
3764+
case DLM_RCOM:
3765+
dlm_rcom_in(rc);
3766+
type = rc->rc_type;
3767+
break;
3768+
default:
3769+
log_print("invalid h_cmd %d from %u", hd->h_cmd, nodeid);
3770+
return;
3771+
}
3772+
3773+
if (hd->h_nodeid != nodeid) {
3774+
log_print("invalid h_nodeid %d from %d lockspace %x",
3775+
hd->h_nodeid, nodeid, hd->h_lockspace);
3776+
return;
3777+
}
3778+
3779+
ls = dlm_find_lockspace_global(hd->h_lockspace);
3780+
if (!ls) {
3781+
log_print("invalid h_lockspace %x from %d cmd %d type %d",
3782+
hd->h_lockspace, nodeid, hd->h_cmd, type);
3783+
3784+
if (hd->h_cmd == DLM_RCOM && type == DLM_RCOM_STATUS)
3785+
dlm_send_ls_not_ready(nodeid, rc);
3786+
return;
3787+
}
3788+
3789+
/* this rwsem allows dlm_ls_stop() to wait for all dlm_recv threads to
3790+
be inactive (in this ls) before transitioning to recovery mode */
3791+
3792+
down_read(&ls->ls_recv_active);
3793+
if (hd->h_cmd == DLM_MSG)
3794+
dlm_receive_message(ls, ms, nodeid);
3795+
else
3796+
dlm_receive_rcom(ls, rc, nodeid);
3797+
up_read(&ls->ls_recv_active);
3798+
3799+
dlm_put_lockspace(ls);
3800+
}
37753801

37763802
static void recover_convert_waiter(struct dlm_ls *ls, struct dlm_lkb *lkb)
37773803
{

‎fs/dlm/lock.h‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616
void dlm_print_rsb(struct dlm_rsb *r);
1717
void dlm_dump_rsb(struct dlm_rsb *r);
1818
void dlm_print_lkb(struct dlm_lkb *lkb);
19-
int dlm_receive_message(struct dlm_header *hd, int nodeid, int recovery);
19+
void dlm_receive_message_saved(struct dlm_ls *ls, struct dlm_message *ms);
20+
void dlm_receive_buffer(struct dlm_header *hd, int nodeid);
2021
int dlm_modes_compat(int mode1, int mode2);
2122
int dlm_find_rsb(struct dlm_ls *ls, char *name, int namelen,
2223
unsigned int flags, struct dlm_rsb **r_ret);

‎fs/dlm/lockspace.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -519,6 +519,7 @@ static int new_lockspace(char *name, int namelen, void **lockspace,
519519
ls->ls_recover_seq = 0;
520520
ls->ls_recover_args = NULL;
521521
init_rwsem(&ls->ls_in_recovery);
522+
init_rwsem(&ls->ls_recv_active);
522523
INIT_LIST_HEAD(&ls->ls_requestqueue);
523524
mutex_init(&ls->ls_requestqueue_mutex);
524525
mutex_init(&ls->ls_clear_proc_locks);

‎fs/dlm/member.c‎

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,6 @@
1818
#include "rcom.h"
1919
#include "config.h"
2020

21-
/*
22-
* Following called by dlm_recoverd thread
23-
*/
24-
2521
static void add_ordered_member(struct dlm_ls *ls, struct dlm_member *new)
2622
{
2723
struct dlm_member *memb = NULL;
@@ -250,18 +246,30 @@ int dlm_recover_members(struct dlm_ls *ls, struct dlm_recover *rv, int *neg_out)
250246
return error;
251247
}
252248

253-
/*
254-
* Following called from lockspace.c
255-
*/
249+
/* Userspace guarantees that dlm_ls_stop() has completed on all nodes before
250+
dlm_ls_start() is called on any of them to start the new recovery. */
256251

257252
int dlm_ls_stop(struct dlm_ls *ls)
258253
{
259254
int new;
260255

261256
/*
262-
* A stop cancels any recovery that's in progress (see RECOVERY_STOP,
263-
* dlm_recovery_stopped()) and prevents any new locks from being
264-
* processed (see RUNNING, dlm_locking_stopped()).
257+
* Prevent dlm_recv from being in the middle of something when we do
258+
* the stop. This includes ensuring dlm_recv isn't processing a
259+
* recovery message (rcom), while dlm_recoverd is aborting and
260+
* resetting things from an in-progress recovery. i.e. we want
261+
* dlm_recoverd to abort its recovery without worrying about dlm_recv
262+
* processing an rcom at the same time. Stopping dlm_recv also makes
263+
* it easy for dlm_receive_message() to check locking stopped and add a
264+
* message to the requestqueue without races.
265+
*/
266+
267+
down_write(&ls->ls_recv_active);
268+
269+
/*
270+
* Abort any recovery that's in progress (see RECOVERY_STOP,
271+
* dlm_recovery_stopped()) and tell any other threads running in the
272+
* dlm to quit any processing (see RUNNING, dlm_locking_stopped()).
265273
*/
266274

267275
spin_lock(&ls->ls_recover_lock);
@@ -270,9 +278,15 @@ int dlm_ls_stop(struct dlm_ls *ls)
270278
ls->ls_recover_seq++;
271279
spin_unlock(&ls->ls_recover_lock);
272280

281+
/*
282+
* Let dlm_recv run again, now any normal messages will be saved on the
283+
* requestqueue for later.
284+
*/
285+
286+
up_write(&ls->ls_recv_active);
287+
273288
/*
274289
* This in_recovery lock does two things:
275-
*
276290
* 1) Keeps this function from returning until all threads are out
277291
* of locking routines and locking is truely stopped.
278292
* 2) Keeps any new requests from being processed until it's unlocked
@@ -284,9 +298,8 @@ int dlm_ls_stop(struct dlm_ls *ls)
284298

285299
/*
286300
* The recoverd suspend/resume makes sure that dlm_recoverd (if
287-
* running) has noticed the clearing of RUNNING above and quit
288-
* processing the previous recovery. This will be true for all nodes
289-
* before any nodes start the new recovery.
301+
* running) has noticed RECOVERY_STOP above and quit processing the
302+
* previous recovery.
290303
*/
291304

292305
dlm_recoverd_suspend(ls);

‎fs/dlm/midcomms.c‎

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
*******************************************************************************
33
**
44
** Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved.
5-
** Copyright (C) 2004-2005 Red Hat, Inc. All rights reserved.
5+
** Copyright (C) 2004-2007 Red Hat, Inc. All rights reserved.
66
**
77
** This copyrighted material is made available to anyone wishing to use,
88
** modify, copy, or redistribute it subject to the terms and conditions
@@ -27,7 +27,6 @@
2727
#include "dlm_internal.h"
2828
#include "lowcomms.h"
2929
#include "config.h"
30-
#include "rcom.h"
3130
#include "lock.h"
3231
#include "midcomms.h"
3332

@@ -117,19 +116,7 @@ int dlm_process_incoming_buffer(int nodeid, const void *base,
117116
offset &= (limit - 1);
118117
len -= msglen;
119118

120-
switch (msg->h_cmd) {
121-
case DLM_MSG:
122-
dlm_receive_message(msg, nodeid, 0);
123-
break;
124-
125-
case DLM_RCOM:
126-
dlm_receive_rcom(msg, nodeid);
127-
break;
128-
129-
default:
130-
log_print("unknown msg type %x from %u: %u %u %u %u",
131-
msg->h_cmd, nodeid, msglen, len, offset, ret);
132-
}
119+
dlm_receive_buffer(msg, nodeid);
133120
}
134121

135122
if (msg != (struct dlm_header *) __tmp)

‎fs/dlm/rcom.c‎

Lines changed: 8 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
*******************************************************************************
33
**
44
** Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved.
5-
** Copyright (C) 2005 Red Hat, Inc. All rights reserved.
5+
** Copyright (C) 2005-2007 Red Hat, Inc. All rights reserved.
66
**
77
** This copyrighted material is made available to anyone wishing to use,
88
** modify, copy, or redistribute it subject to the terms and conditions
@@ -386,7 +386,10 @@ static void receive_rcom_lock_reply(struct dlm_ls *ls, struct dlm_rcom *rc_in)
386386
dlm_recover_process_copy(ls, rc_in);
387387
}
388388

389-
static int send_ls_not_ready(int nodeid, struct dlm_rcom *rc_in)
389+
/* If the lockspace doesn't exist then still send a status message
390+
back; it's possible that it just doesn't have its global_id yet. */
391+
392+
int dlm_send_ls_not_ready(int nodeid, struct dlm_rcom *rc_in)
390393
{
391394
struct dlm_rcom *rc;
392395
struct rcom_config *rf;
@@ -446,28 +449,11 @@ static int is_old_reply(struct dlm_ls *ls, struct dlm_rcom *rc)
446449
return rv;
447450
}
448451

449-
/* Called by dlm_recvd; corresponds to dlm_receive_message() but special
452+
/* Called by dlm_recv; corresponds to dlm_receive_message() but special
450453
recovery-only comms are sent through here. */
451454

452-
void dlm_receive_rcom(struct dlm_header *hd, int nodeid)
455+
void dlm_receive_rcom(struct dlm_ls *ls, struct dlm_rcom *rc, int nodeid)
453456
{
454-
struct dlm_rcom *rc = (struct dlm_rcom *) hd;
455-
struct dlm_ls *ls;
456-
457-
dlm_rcom_in(rc);
458-
459-
/* If the lockspace doesn't exist then still send a status message
460-
back; it's possible that it just doesn't have its global_id yet. */
461-
462-
ls = dlm_find_lockspace_global(hd->h_lockspace);
463-
if (!ls) {
464-
log_print("lockspace %x from %d type %x not found",
465-
hd->h_lockspace, nodeid, rc->rc_type);
466-
if (rc->rc_type == DLM_RCOM_STATUS)
467-
send_ls_not_ready(nodeid, rc);
468-
return;
469-
}
470-
471457
if (dlm_recovery_stopped(ls) && (rc->rc_type != DLM_RCOM_STATUS)) {
472458
log_debug(ls, "ignoring recovery message %x from %d",
473459
rc->rc_type, nodeid);
@@ -477,12 +463,6 @@ void dlm_receive_rcom(struct dlm_header *hd, int nodeid)
477463
if (is_old_reply(ls, rc))
478464
goto out;
479465

480-
if (nodeid != rc->rc_header.h_nodeid) {
481-
log_error(ls, "bad rcom nodeid %d from %d",
482-
rc->rc_header.h_nodeid, nodeid);
483-
goto out;
484-
}
485-
486466
switch (rc->rc_type) {
487467
case DLM_RCOM_STATUS:
488468
receive_rcom_status(ls, rc);
@@ -520,6 +500,6 @@ void dlm_receive_rcom(struct dlm_header *hd, int nodeid)
520500
DLM_ASSERT(0, printk("rc_type=%x\n", rc->rc_type););
521501
}
522502
out:
523-
dlm_put_lockspace(ls);
503+
return;
524504
}
525505

‎fs/dlm/rcom.h‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
*******************************************************************************
33
**
44
** Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved.
5-
** Copyright (C) 2005 Red Hat, Inc. All rights reserved.
5+
** Copyright (C) 2005-2007 Red Hat, Inc. All rights reserved.
66
**
77
** This copyrighted material is made available to anyone wishing to use,
88
** modify, copy, or redistribute it subject to the terms and conditions
@@ -18,7 +18,8 @@ int dlm_rcom_status(struct dlm_ls *ls, int nodeid);
1818
int dlm_rcom_names(struct dlm_ls *ls, int nodeid, char *last_name,int last_len);
1919
int dlm_send_rcom_lookup(struct dlm_rsb *r, int dir_nodeid);
2020
int dlm_send_rcom_lock(struct dlm_rsb *r, struct dlm_lkb *lkb);
21-
void dlm_receive_rcom(struct dlm_header *hd, int nodeid);
21+
void dlm_receive_rcom(struct dlm_ls *ls, struct dlm_rcom *rc, int nodeid);
22+
int dlm_send_ls_not_ready(int nodeid, struct dlm_rcom *rc_in);
2223

2324
#endif
2425

0 commit comments

Comments
 (0)