Skip to content

Commit e7fd417

Browse files
teiglandswhiteho
authored andcommitted
[DLM] The core of the DLM for GFS2/CLVM
This is the core of the distributed lock manager which is required to use GFS2 as a cluster filesystem. It is also used by CLVM and can be used as a standalone lock manager independantly of either of these two projects. It implements VAX-style locking modes. Signed-off-by: David Teigland <teigland@redhat.com> Signed-off-by: Steve Whitehouse <swhiteho@redhat.com>
1 parent e473142 commit e7fd417

39 files changed

Lines changed: 12178 additions & 0 deletions

‎fs/Kconfig‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1831,6 +1831,7 @@ source "fs/partitions/Kconfig"
18311831
endmenu
18321832

18331833
source "fs/nls/Kconfig"
1834+
source "fs/dlm/Kconfig"
18341835

18351836
endmenu
18361837

‎fs/Makefile‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ obj-$(CONFIG_SYSFS) += sysfs/
4848
obj-y += devpts/
4949

5050
obj-$(CONFIG_PROFILING) += dcookies.o
51+
obj-$(CONFIG_DLM) += dlm/
5152

5253
# Do not add any filesystems before this line
5354
obj-$(CONFIG_REISERFS_FS) += reiserfs/

‎fs/dlm/Kconfig‎

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
menu "Distributed Lock Manager"
2+
depends on INET && EXPERIMENTAL
3+
4+
config DLM
5+
tristate "Distributed Lock Manager (DLM)"
6+
depends on SYSFS
7+
depends on IPV6 || IPV6=n
8+
select IP_SCTP
9+
select CONFIGFS_FS
10+
help
11+
A general purpose distributed lock manager for kernel or userspace
12+
applications.
13+
14+
config DLM_DEVICE
15+
tristate "DLM device for userspace access"
16+
depends on DLM
17+
help
18+
This module creates a misc device through which the dlm lockspace
19+
and locking functions become available to userspace applications
20+
(usually through the libdlm library).
21+
22+
config DLM_DEBUG
23+
bool "DLM debugging"
24+
depends on DLM
25+
help
26+
Under the debugfs mount point, the name of each lockspace will
27+
appear as a file in the "dlm" directory. The output is the
28+
list of resource and locks the local node knows about.
29+
30+
endmenu

‎fs/dlm/Makefile‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
obj-$(CONFIG_DLM) += dlm.o
2+
obj-$(CONFIG_DLM_DEVICE) += dlm_device.o
3+
4+
dlm-y := ast.o \
5+
config.o \
6+
dir.o \
7+
lock.o \
8+
lockspace.o \
9+
lowcomms.o \
10+
main.o \
11+
member.o \
12+
memory.o \
13+
midcomms.o \
14+
rcom.o \
15+
recover.o \
16+
recoverd.o \
17+
requestqueue.o \
18+
util.o
19+
dlm-$(CONFIG_DLM_DEBUG) += debug_fs.o
20+
21+
dlm_device-y := device.o

‎fs/dlm/ast.c‎

Lines changed: 167 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,167 @@
1+
/******************************************************************************
2+
*******************************************************************************
3+
**
4+
** Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved.
5+
** Copyright (C) 2004-2005 Red Hat, Inc. All rights reserved.
6+
**
7+
** This copyrighted material is made available to anyone wishing to use,
8+
** modify, copy, or redistribute it subject to the terms and conditions
9+
** of the GNU General Public License v.2.
10+
**
11+
*******************************************************************************
12+
******************************************************************************/
13+
14+
#include "dlm_internal.h"
15+
#include "lock.h"
16+
#include "ast.h"
17+
18+
#define WAKE_ASTS 0
19+
20+
static struct list_head ast_queue;
21+
static spinlock_t ast_queue_lock;
22+
static struct task_struct * astd_task;
23+
static unsigned long astd_wakeflags;
24+
static struct semaphore astd_running;
25+
26+
27+
void dlm_del_ast(struct dlm_lkb *lkb)
28+
{
29+
spin_lock(&ast_queue_lock);
30+
if (lkb->lkb_ast_type & (AST_COMP | AST_BAST))
31+
list_del(&lkb->lkb_astqueue);
32+
spin_unlock(&ast_queue_lock);
33+
}
34+
35+
void dlm_add_ast(struct dlm_lkb *lkb, int type)
36+
{
37+
spin_lock(&ast_queue_lock);
38+
if (!(lkb->lkb_ast_type & (AST_COMP | AST_BAST))) {
39+
kref_get(&lkb->lkb_ref);
40+
list_add_tail(&lkb->lkb_astqueue, &ast_queue);
41+
}
42+
lkb->lkb_ast_type |= type;
43+
spin_unlock(&ast_queue_lock);
44+
45+
set_bit(WAKE_ASTS, &astd_wakeflags);
46+
wake_up_process(astd_task);
47+
}
48+
49+
static void process_asts(void)
50+
{
51+
struct dlm_ls *ls = NULL;
52+
struct dlm_rsb *r = NULL;
53+
struct dlm_lkb *lkb;
54+
void (*cast) (long param);
55+
void (*bast) (long param, int mode);
56+
int type = 0, found, bmode;
57+
58+
for (;;) {
59+
found = FALSE;
60+
spin_lock(&ast_queue_lock);
61+
list_for_each_entry(lkb, &ast_queue, lkb_astqueue) {
62+
r = lkb->lkb_resource;
63+
ls = r->res_ls;
64+
65+
if (dlm_locking_stopped(ls))
66+
continue;
67+
68+
list_del(&lkb->lkb_astqueue);
69+
type = lkb->lkb_ast_type;
70+
lkb->lkb_ast_type = 0;
71+
found = TRUE;
72+
break;
73+
}
74+
spin_unlock(&ast_queue_lock);
75+
76+
if (!found)
77+
break;
78+
79+
cast = lkb->lkb_astaddr;
80+
bast = lkb->lkb_bastaddr;
81+
bmode = lkb->lkb_bastmode;
82+
83+
if ((type & AST_COMP) && cast)
84+
cast(lkb->lkb_astparam);
85+
86+
/* FIXME: Is it safe to look at lkb_grmode here
87+
without doing a lock_rsb() ?
88+
Look at other checks in v1 to avoid basts. */
89+
90+
if ((type & AST_BAST) && bast)
91+
if (!dlm_modes_compat(lkb->lkb_grmode, bmode))
92+
bast(lkb->lkb_astparam, bmode);
93+
94+
/* this removes the reference added by dlm_add_ast
95+
and may result in the lkb being freed */
96+
dlm_put_lkb(lkb);
97+
98+
schedule();
99+
}
100+
}
101+
102+
static inline int no_asts(void)
103+
{
104+
int ret;
105+
106+
spin_lock(&ast_queue_lock);
107+
ret = list_empty(&ast_queue);
108+
spin_unlock(&ast_queue_lock);
109+
return ret;
110+
}
111+
112+
static int dlm_astd(void *data)
113+
{
114+
while (!kthread_should_stop()) {
115+
set_current_state(TASK_INTERRUPTIBLE);
116+
if (!test_bit(WAKE_ASTS, &astd_wakeflags))
117+
schedule();
118+
set_current_state(TASK_RUNNING);
119+
120+
down(&astd_running);
121+
if (test_and_clear_bit(WAKE_ASTS, &astd_wakeflags))
122+
process_asts();
123+
up(&astd_running);
124+
}
125+
return 0;
126+
}
127+
128+
void dlm_astd_wake(void)
129+
{
130+
if (!no_asts()) {
131+
set_bit(WAKE_ASTS, &astd_wakeflags);
132+
wake_up_process(astd_task);
133+
}
134+
}
135+
136+
int dlm_astd_start(void)
137+
{
138+
struct task_struct *p;
139+
int error = 0;
140+
141+
INIT_LIST_HEAD(&ast_queue);
142+
spin_lock_init(&ast_queue_lock);
143+
init_MUTEX(&astd_running);
144+
145+
p = kthread_run(dlm_astd, NULL, "dlm_astd");
146+
if (IS_ERR(p))
147+
error = PTR_ERR(p);
148+
else
149+
astd_task = p;
150+
return error;
151+
}
152+
153+
void dlm_astd_stop(void)
154+
{
155+
kthread_stop(astd_task);
156+
}
157+
158+
void dlm_astd_suspend(void)
159+
{
160+
down(&astd_running);
161+
}
162+
163+
void dlm_astd_resume(void)
164+
{
165+
up(&astd_running);
166+
}
167+

‎fs/dlm/ast.h‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/******************************************************************************
2+
*******************************************************************************
3+
**
4+
** Copyright (C) 2005 Red Hat, Inc. All rights reserved.
5+
**
6+
** This copyrighted material is made available to anyone wishing to use,
7+
** modify, copy, or redistribute it subject to the terms and conditions
8+
** of the GNU General Public License v.2.
9+
**
10+
*******************************************************************************
11+
******************************************************************************/
12+
13+
#ifndef __ASTD_DOT_H__
14+
#define __ASTD_DOT_H__
15+
16+
void dlm_add_ast(struct dlm_lkb *lkb, int type);
17+
void dlm_del_ast(struct dlm_lkb *lkb);
18+
19+
void dlm_astd_wake(void);
20+
int dlm_astd_start(void);
21+
void dlm_astd_stop(void);
22+
void dlm_astd_suspend(void);
23+
void dlm_astd_resume(void);
24+
25+
#endif
26+

0 commit comments

Comments
 (0)