diff options
author | David Teigland <teigland@redhat.com> | 2006-01-18 04:30:29 -0500 |
---|---|---|
committer | Steven Whitehouse <swhiteho@redhat.com> | 2006-01-18 04:30:29 -0500 |
commit | e7fd41792fc0ee52a05fcaac87511f118328d147 (patch) | |
tree | eee5227088ba97daef795e385b7548d2a1cc4cb6 /include/linux | |
parent | e47314207032cfd1157b8c377df162839b32ea6f (diff) |
[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>
Diffstat (limited to 'include/linux')
-rw-r--r-- | include/linux/dlm.h | 312 | ||||
-rw-r--r-- | include/linux/dlm_device.h | 84 |
2 files changed, 396 insertions, 0 deletions
diff --git a/include/linux/dlm.h b/include/linux/dlm.h new file mode 100644 index 000000000000..dd324ba44d80 --- /dev/null +++ b/include/linux/dlm.h | |||
@@ -0,0 +1,312 @@ | |||
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 | #ifndef __DLM_DOT_H__ | ||
15 | #define __DLM_DOT_H__ | ||
16 | |||
17 | /* | ||
18 | * Interface to Distributed Lock Manager (DLM) | ||
19 | * routines and structures to use DLM lockspaces | ||
20 | */ | ||
21 | |||
22 | /* | ||
23 | * Lock Modes | ||
24 | */ | ||
25 | |||
26 | #define DLM_LOCK_IV -1 /* invalid */ | ||
27 | #define DLM_LOCK_NL 0 /* null */ | ||
28 | #define DLM_LOCK_CR 1 /* concurrent read */ | ||
29 | #define DLM_LOCK_CW 2 /* concurrent write */ | ||
30 | #define DLM_LOCK_PR 3 /* protected read */ | ||
31 | #define DLM_LOCK_PW 4 /* protected write */ | ||
32 | #define DLM_LOCK_EX 5 /* exclusive */ | ||
33 | |||
34 | /* | ||
35 | * Maximum size in bytes of a dlm_lock name | ||
36 | */ | ||
37 | |||
38 | #define DLM_RESNAME_MAXLEN 64 | ||
39 | |||
40 | /* | ||
41 | * Flags to dlm_lock | ||
42 | * | ||
43 | * DLM_LKF_NOQUEUE | ||
44 | * | ||
45 | * Do not queue the lock request on the wait queue if it cannot be granted | ||
46 | * immediately. If the lock cannot be granted because of this flag, DLM will | ||
47 | * either return -EAGAIN from the dlm_lock call or will return 0 from | ||
48 | * dlm_lock and -EAGAIN in the lock status block when the AST is executed. | ||
49 | * | ||
50 | * DLM_LKF_CANCEL | ||
51 | * | ||
52 | * Used to cancel a pending lock request or conversion. A converting lock is | ||
53 | * returned to its previously granted mode. | ||
54 | * | ||
55 | * DLM_LKF_CONVERT | ||
56 | * | ||
57 | * Indicates a lock conversion request. For conversions the name and namelen | ||
58 | * are ignored and the lock ID in the LKSB is used to identify the lock. | ||
59 | * | ||
60 | * DLM_LKF_VALBLK | ||
61 | * | ||
62 | * Requests DLM to return the current contents of the lock value block in the | ||
63 | * lock status block. When this flag is set in a lock conversion from PW or EX | ||
64 | * modes, DLM assigns the value specified in the lock status block to the lock | ||
65 | * value block of the lock resource. The LVB is a DLM_LVB_LEN size array | ||
66 | * containing application-specific information. | ||
67 | * | ||
68 | * DLM_LKF_QUECVT | ||
69 | * | ||
70 | * Force a conversion request to be queued, even if it is compatible with | ||
71 | * the granted modes of other locks on the same resource. | ||
72 | * | ||
73 | * DLM_LKF_IVVALBLK | ||
74 | * | ||
75 | * Invalidate the lock value block. | ||
76 | * | ||
77 | * DLM_LKF_CONVDEADLK | ||
78 | * | ||
79 | * Allows the dlm to resolve conversion deadlocks internally by demoting the | ||
80 | * granted mode of a converting lock to NL. The DLM_SBF_DEMOTED flag is | ||
81 | * returned for a conversion that's been effected by this. | ||
82 | * | ||
83 | * DLM_LKF_PERSISTENT | ||
84 | * | ||
85 | * Only relevant to locks originating in userspace. A persistent lock will not | ||
86 | * be removed if the process holding the lock exits. | ||
87 | * | ||
88 | * DLM_LKF_NODLKWT | ||
89 | * DLM_LKF_NODLCKBLK | ||
90 | * | ||
91 | * net yet implemented | ||
92 | * | ||
93 | * DLM_LKF_EXPEDITE | ||
94 | * | ||
95 | * Used only with new requests for NL mode locks. Tells the lock manager | ||
96 | * to grant the lock, ignoring other locks in convert and wait queues. | ||
97 | * | ||
98 | * DLM_LKF_NOQUEUEBAST | ||
99 | * | ||
100 | * Send blocking AST's before returning -EAGAIN to the caller. It is only | ||
101 | * used along with the NOQUEUE flag. Blocking AST's are not sent for failed | ||
102 | * NOQUEUE requests otherwise. | ||
103 | * | ||
104 | * DLM_LKF_HEADQUE | ||
105 | * | ||
106 | * Add a lock to the head of the convert or wait queue rather than the tail. | ||
107 | * | ||
108 | * DLM_LKF_NOORDER | ||
109 | * | ||
110 | * Disregard the standard grant order rules and grant a lock as soon as it | ||
111 | * is compatible with other granted locks. | ||
112 | * | ||
113 | * DLM_LKF_ORPHAN | ||
114 | * | ||
115 | * not yet implemented | ||
116 | * | ||
117 | * DLM_LKF_ALTPR | ||
118 | * | ||
119 | * If the requested mode cannot be granted immediately, try to grant the lock | ||
120 | * in PR mode instead. If this alternate mode is granted instead of the | ||
121 | * requested mode, DLM_SBF_ALTMODE is returned in the lksb. | ||
122 | * | ||
123 | * DLM_LKF_ALTCW | ||
124 | * | ||
125 | * The same as ALTPR, but the alternate mode is CW. | ||
126 | * | ||
127 | * DLM_LKF_FORCEUNLOCK | ||
128 | * | ||
129 | * Unlock the lock even if it is converting or waiting or has sublocks. | ||
130 | * Only really for use by the userland device.c code. | ||
131 | * | ||
132 | */ | ||
133 | |||
134 | #define DLM_LKF_NOQUEUE 0x00000001 | ||
135 | #define DLM_LKF_CANCEL 0x00000002 | ||
136 | #define DLM_LKF_CONVERT 0x00000004 | ||
137 | #define DLM_LKF_VALBLK 0x00000008 | ||
138 | #define DLM_LKF_QUECVT 0x00000010 | ||
139 | #define DLM_LKF_IVVALBLK 0x00000020 | ||
140 | #define DLM_LKF_CONVDEADLK 0x00000040 | ||
141 | #define DLM_LKF_PERSISTENT 0x00000080 | ||
142 | #define DLM_LKF_NODLCKWT 0x00000100 | ||
143 | #define DLM_LKF_NODLCKBLK 0x00000200 | ||
144 | #define DLM_LKF_EXPEDITE 0x00000400 | ||
145 | #define DLM_LKF_NOQUEUEBAST 0x00000800 | ||
146 | #define DLM_LKF_HEADQUE 0x00001000 | ||
147 | #define DLM_LKF_NOORDER 0x00002000 | ||
148 | #define DLM_LKF_ORPHAN 0x00004000 | ||
149 | #define DLM_LKF_ALTPR 0x00008000 | ||
150 | #define DLM_LKF_ALTCW 0x00010000 | ||
151 | #define DLM_LKF_FORCEUNLOCK 0x00020000 | ||
152 | |||
153 | /* | ||
154 | * Some return codes that are not in errno.h | ||
155 | */ | ||
156 | |||
157 | #define DLM_ECANCEL 0x10001 | ||
158 | #define DLM_EUNLOCK 0x10002 | ||
159 | |||
160 | typedef void dlm_lockspace_t; | ||
161 | |||
162 | /* | ||
163 | * Lock range structure | ||
164 | */ | ||
165 | |||
166 | struct dlm_range { | ||
167 | uint64_t ra_start; | ||
168 | uint64_t ra_end; | ||
169 | }; | ||
170 | |||
171 | /* | ||
172 | * Lock status block | ||
173 | * | ||
174 | * Use this structure to specify the contents of the lock value block. For a | ||
175 | * conversion request, this structure is used to specify the lock ID of the | ||
176 | * lock. DLM writes the status of the lock request and the lock ID assigned | ||
177 | * to the request in the lock status block. | ||
178 | * | ||
179 | * sb_lkid: the returned lock ID. It is set on new (non-conversion) requests. | ||
180 | * It is available when dlm_lock returns. | ||
181 | * | ||
182 | * sb_lvbptr: saves or returns the contents of the lock's LVB according to rules | ||
183 | * shown for the DLM_LKF_VALBLK flag. | ||
184 | * | ||
185 | * sb_flags: DLM_SBF_DEMOTED is returned if in the process of promoting a lock, | ||
186 | * it was first demoted to NL to avoid conversion deadlock. | ||
187 | * DLM_SBF_VALNOTVALID is returned if the resource's LVB is marked invalid. | ||
188 | * | ||
189 | * sb_status: the returned status of the lock request set prior to AST | ||
190 | * execution. Possible return values: | ||
191 | * | ||
192 | * 0 if lock request was successful | ||
193 | * -EAGAIN if request would block and is flagged DLM_LKF_NOQUEUE | ||
194 | * -ENOMEM if there is no memory to process request | ||
195 | * -EINVAL if there are invalid parameters | ||
196 | * -DLM_EUNLOCK if unlock request was successful | ||
197 | * -DLM_ECANCEL if a cancel completed successfully | ||
198 | */ | ||
199 | |||
200 | #define DLM_SBF_DEMOTED 0x01 | ||
201 | #define DLM_SBF_VALNOTVALID 0x02 | ||
202 | #define DLM_SBF_ALTMODE 0x04 | ||
203 | |||
204 | struct dlm_lksb { | ||
205 | int sb_status; | ||
206 | uint32_t sb_lkid; | ||
207 | char sb_flags; | ||
208 | char * sb_lvbptr; | ||
209 | }; | ||
210 | |||
211 | |||
212 | #ifdef __KERNEL__ | ||
213 | |||
214 | #define DLM_LSFL_NODIR 0x00000001 | ||
215 | |||
216 | /* | ||
217 | * dlm_new_lockspace | ||
218 | * | ||
219 | * Starts a lockspace with the given name. If the named lockspace exists in | ||
220 | * the cluster, the calling node joins it. | ||
221 | */ | ||
222 | |||
223 | int dlm_new_lockspace(char *name, int namelen, dlm_lockspace_t **lockspace, | ||
224 | uint32_t flags, int lvblen); | ||
225 | |||
226 | /* | ||
227 | * dlm_release_lockspace | ||
228 | * | ||
229 | * Stop a lockspace. | ||
230 | */ | ||
231 | |||
232 | int dlm_release_lockspace(dlm_lockspace_t *lockspace, int force); | ||
233 | |||
234 | /* | ||
235 | * dlm_lock | ||
236 | * | ||
237 | * Make an asyncronous request to acquire or convert a lock on a named | ||
238 | * resource. | ||
239 | * | ||
240 | * lockspace: context for the request | ||
241 | * mode: the requested mode of the lock (DLM_LOCK_) | ||
242 | * lksb: lock status block for input and async return values | ||
243 | * flags: input flags (DLM_LKF_) | ||
244 | * name: name of the resource to lock, can be binary | ||
245 | * namelen: the length in bytes of the resource name (MAX_RESNAME_LEN) | ||
246 | * parent: the lock ID of a parent lock or 0 if none | ||
247 | * lockast: function DLM executes when it completes processing the request | ||
248 | * astarg: argument passed to lockast and bast functions | ||
249 | * bast: function DLM executes when this lock later blocks another request | ||
250 | * | ||
251 | * Returns: | ||
252 | * 0 if request is successfully queued for processing | ||
253 | * -EINVAL if any input parameters are invalid | ||
254 | * -EAGAIN if request would block and is flagged DLM_LKF_NOQUEUE | ||
255 | * -ENOMEM if there is no memory to process request | ||
256 | * -ENOTCONN if there is a communication error | ||
257 | * | ||
258 | * If the call to dlm_lock returns an error then the operation has failed and | ||
259 | * the AST routine will not be called. If dlm_lock returns 0 it is still | ||
260 | * possible that the lock operation will fail. The AST routine will be called | ||
261 | * when the locking is complete and the status is returned in the lksb. | ||
262 | * | ||
263 | * If the AST routines or parameter are passed to a conversion operation then | ||
264 | * they will overwrite those values that were passed to a previous dlm_lock | ||
265 | * call. | ||
266 | * | ||
267 | * AST routines should not block (at least not for long), but may make | ||
268 | * any locking calls they please. | ||
269 | */ | ||
270 | |||
271 | int dlm_lock(dlm_lockspace_t *lockspace, | ||
272 | int mode, | ||
273 | struct dlm_lksb *lksb, | ||
274 | uint32_t flags, | ||
275 | void *name, | ||
276 | unsigned int namelen, | ||
277 | uint32_t parent_lkid, | ||
278 | void (*lockast) (void *astarg), | ||
279 | void *astarg, | ||
280 | void (*bast) (void *astarg, int mode), | ||
281 | struct dlm_range *range); | ||
282 | |||
283 | /* | ||
284 | * dlm_unlock | ||
285 | * | ||
286 | * Asynchronously release a lock on a resource. The AST routine is called | ||
287 | * when the resource is successfully unlocked. | ||
288 | * | ||
289 | * lockspace: context for the request | ||
290 | * lkid: the lock ID as returned in the lksb | ||
291 | * flags: input flags (DLM_LKF_) | ||
292 | * lksb: if NULL the lksb parameter passed to last lock request is used | ||
293 | * astarg: the arg used with the completion ast for the unlock | ||
294 | * | ||
295 | * Returns: | ||
296 | * 0 if request is successfully queued for processing | ||
297 | * -EINVAL if any input parameters are invalid | ||
298 | * -ENOTEMPTY if the lock still has sublocks | ||
299 | * -EBUSY if the lock is waiting for a remote lock operation | ||
300 | * -ENOTCONN if there is a communication error | ||
301 | */ | ||
302 | |||
303 | int dlm_unlock(dlm_lockspace_t *lockspace, | ||
304 | uint32_t lkid, | ||
305 | uint32_t flags, | ||
306 | struct dlm_lksb *lksb, | ||
307 | void *astarg); | ||
308 | |||
309 | #endif /* __KERNEL__ */ | ||
310 | |||
311 | #endif /* __DLM_DOT_H__ */ | ||
312 | |||
diff --git a/include/linux/dlm_device.h b/include/linux/dlm_device.h new file mode 100644 index 000000000000..5e17d295544b --- /dev/null +++ b/include/linux/dlm_device.h | |||
@@ -0,0 +1,84 @@ | |||
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 | /* This is the device interface for dlm, most users will use a library | ||
15 | * interface. | ||
16 | */ | ||
17 | |||
18 | #define DLM_USER_LVB_LEN 32 | ||
19 | |||
20 | /* Version of the device interface */ | ||
21 | #define DLM_DEVICE_VERSION_MAJOR 3 | ||
22 | #define DLM_DEVICE_VERSION_MINOR 0 | ||
23 | #define DLM_DEVICE_VERSION_PATCH 0 | ||
24 | |||
25 | /* struct passed to the lock write */ | ||
26 | struct dlm_lock_params { | ||
27 | __u8 mode; | ||
28 | __u16 flags; | ||
29 | __u32 lkid; | ||
30 | __u32 parent; | ||
31 | struct dlm_range range; | ||
32 | __u8 namelen; | ||
33 | void __user *castparam; | ||
34 | void __user *castaddr; | ||
35 | void __user *bastparam; | ||
36 | void __user *bastaddr; | ||
37 | struct dlm_lksb __user *lksb; | ||
38 | char lvb[DLM_USER_LVB_LEN]; | ||
39 | char name[1]; | ||
40 | }; | ||
41 | |||
42 | struct dlm_lspace_params { | ||
43 | __u32 flags; | ||
44 | __u32 minor; | ||
45 | char name[1]; | ||
46 | }; | ||
47 | |||
48 | struct dlm_write_request { | ||
49 | __u32 version[3]; | ||
50 | __u8 cmd; | ||
51 | |||
52 | union { | ||
53 | struct dlm_lock_params lock; | ||
54 | struct dlm_lspace_params lspace; | ||
55 | } i; | ||
56 | }; | ||
57 | |||
58 | /* struct read from the "device" fd, | ||
59 | consists mainly of userspace pointers for the library to use */ | ||
60 | struct dlm_lock_result { | ||
61 | __u32 length; | ||
62 | void __user * user_astaddr; | ||
63 | void __user * user_astparam; | ||
64 | struct dlm_lksb __user * user_lksb; | ||
65 | struct dlm_lksb lksb; | ||
66 | __u8 bast_mode; | ||
67 | /* Offsets may be zero if no data is present */ | ||
68 | __u32 lvb_offset; | ||
69 | }; | ||
70 | |||
71 | /* Commands passed to the device */ | ||
72 | #define DLM_USER_LOCK 1 | ||
73 | #define DLM_USER_UNLOCK 2 | ||
74 | #define DLM_USER_QUERY 3 | ||
75 | #define DLM_USER_CREATE_LOCKSPACE 4 | ||
76 | #define DLM_USER_REMOVE_LOCKSPACE 5 | ||
77 | |||
78 | /* Arbitrary length restriction */ | ||
79 | #define MAX_LS_NAME_LEN 64 | ||
80 | |||
81 | /* Lockspace flags */ | ||
82 | #define DLM_USER_LSFLG_AUTOFREE 1 | ||
83 | #define DLM_USER_LSFLG_FORCEFREE 2 | ||
84 | |||