diff options
author | Joel Becker <joel.becker@oracle.com> | 2008-02-01 18:02:36 -0500 |
---|---|---|
committer | Mark Fasheh <mfasheh@suse.com> | 2008-04-18 11:56:05 -0400 |
commit | e3dad42bf993a0f24eb6e46152356c9b119c15e8 (patch) | |
tree | df0419dc5e4387db7e6a6e0118bb5b9d01d8c0b2 | |
parent | 553aa7e408eac402c00b67ddfa7aec13fe1f3a33 (diff) |
ocfs2: Create ocfs2_stack_operations and split out the o2cb stack.
Define the ocfs2_stack_operations structure. Build o2cb_stack_ops from
all of the o2cb-specific stack functions. Change the generic stack glue
functions to call the stack_ops instead of the o2cb functions directly.
The o2cb functions are moved to stack_o2cb.c. The headers are cleaned up
to where only needed headers are included.
In this code, stackglue.c and stack_o2cb.c refer to some shared
extern variables. When they become modules, that will change.
Signed-off-by: Joel Becker <joel.becker@oracle.com>
Signed-off-by: Mark Fasheh <mfasheh@suse.com>
-rw-r--r-- | fs/ocfs2/Makefile | 1 | ||||
-rw-r--r-- | fs/ocfs2/stack_o2cb.c | 395 | ||||
-rw-r--r-- | fs/ocfs2/stackglue.c | 385 | ||||
-rw-r--r-- | fs/ocfs2/stackglue.h | 123 |
4 files changed, 532 insertions, 372 deletions
diff --git a/fs/ocfs2/Makefile b/fs/ocfs2/Makefile index 3ba64af26951..8e86195fedbf 100644 --- a/fs/ocfs2/Makefile +++ b/fs/ocfs2/Makefile | |||
@@ -25,6 +25,7 @@ ocfs2-objs := \ | |||
25 | resize.o \ | 25 | resize.o \ |
26 | slot_map.o \ | 26 | slot_map.o \ |
27 | stackglue.o \ | 27 | stackglue.o \ |
28 | stack_o2cb.o \ | ||
28 | suballoc.o \ | 29 | suballoc.o \ |
29 | super.o \ | 30 | super.o \ |
30 | symlink.o \ | 31 | symlink.o \ |
diff --git a/fs/ocfs2/stack_o2cb.c b/fs/ocfs2/stack_o2cb.c new file mode 100644 index 000000000000..c9bc3541a33f --- /dev/null +++ b/fs/ocfs2/stack_o2cb.c | |||
@@ -0,0 +1,395 @@ | |||
1 | /* -*- mode: c; c-basic-offset: 8; -*- | ||
2 | * vim: noexpandtab sw=8 ts=8 sts=0: | ||
3 | * | ||
4 | * stack_o2cb.c | ||
5 | * | ||
6 | * Code which interfaces ocfs2 with the o2cb stack. | ||
7 | * | ||
8 | * Copyright (C) 2007 Oracle. All rights reserved. | ||
9 | * | ||
10 | * This program is free software; you can redistribute it and/or | ||
11 | * modify it under the terms of the GNU General Public | ||
12 | * License as published by the Free Software Foundation, version 2. | ||
13 | * | ||
14 | * This program is distributed in the hope that it will be useful, | ||
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
17 | * General Public License for more details. | ||
18 | */ | ||
19 | |||
20 | #include <linux/crc32.h> | ||
21 | #include <linux/kmod.h> | ||
22 | |||
23 | /* Needed for AOP_TRUNCATED_PAGE in mlog_errno() */ | ||
24 | #include <linux/fs.h> | ||
25 | |||
26 | #include "cluster/masklog.h" | ||
27 | #include "cluster/nodemanager.h" | ||
28 | #include "cluster/heartbeat.h" | ||
29 | |||
30 | #include "stackglue.h" | ||
31 | |||
32 | struct o2dlm_private { | ||
33 | struct dlm_eviction_cb op_eviction_cb; | ||
34 | }; | ||
35 | |||
36 | /* These should be identical */ | ||
37 | #if (DLM_LOCK_IV != LKM_IVMODE) | ||
38 | # error Lock modes do not match | ||
39 | #endif | ||
40 | #if (DLM_LOCK_NL != LKM_NLMODE) | ||
41 | # error Lock modes do not match | ||
42 | #endif | ||
43 | #if (DLM_LOCK_CR != LKM_CRMODE) | ||
44 | # error Lock modes do not match | ||
45 | #endif | ||
46 | #if (DLM_LOCK_CW != LKM_CWMODE) | ||
47 | # error Lock modes do not match | ||
48 | #endif | ||
49 | #if (DLM_LOCK_PR != LKM_PRMODE) | ||
50 | # error Lock modes do not match | ||
51 | #endif | ||
52 | #if (DLM_LOCK_PW != LKM_PWMODE) | ||
53 | # error Lock modes do not match | ||
54 | #endif | ||
55 | #if (DLM_LOCK_EX != LKM_EXMODE) | ||
56 | # error Lock modes do not match | ||
57 | #endif | ||
58 | static inline int mode_to_o2dlm(int mode) | ||
59 | { | ||
60 | BUG_ON(mode > LKM_MAXMODE); | ||
61 | |||
62 | return mode; | ||
63 | } | ||
64 | |||
65 | #define map_flag(_generic, _o2dlm) \ | ||
66 | if (flags & (_generic)) { \ | ||
67 | flags &= ~(_generic); \ | ||
68 | o2dlm_flags |= (_o2dlm); \ | ||
69 | } | ||
70 | static int flags_to_o2dlm(u32 flags) | ||
71 | { | ||
72 | int o2dlm_flags = 0; | ||
73 | |||
74 | map_flag(DLM_LKF_NOQUEUE, LKM_NOQUEUE); | ||
75 | map_flag(DLM_LKF_CANCEL, LKM_CANCEL); | ||
76 | map_flag(DLM_LKF_CONVERT, LKM_CONVERT); | ||
77 | map_flag(DLM_LKF_VALBLK, LKM_VALBLK); | ||
78 | map_flag(DLM_LKF_IVVALBLK, LKM_INVVALBLK); | ||
79 | map_flag(DLM_LKF_ORPHAN, LKM_ORPHAN); | ||
80 | map_flag(DLM_LKF_FORCEUNLOCK, LKM_FORCE); | ||
81 | map_flag(DLM_LKF_TIMEOUT, LKM_TIMEOUT); | ||
82 | map_flag(DLM_LKF_LOCAL, LKM_LOCAL); | ||
83 | |||
84 | /* map_flag() should have cleared every flag passed in */ | ||
85 | BUG_ON(flags != 0); | ||
86 | |||
87 | return o2dlm_flags; | ||
88 | } | ||
89 | #undef map_flag | ||
90 | |||
91 | /* | ||
92 | * Map an o2dlm status to standard errno values. | ||
93 | * | ||
94 | * o2dlm only uses a handful of these, and returns even fewer to the | ||
95 | * caller. Still, we try to assign sane values to each error. | ||
96 | * | ||
97 | * The following value pairs have special meanings to dlmglue, thus | ||
98 | * the right hand side needs to stay unique - never duplicate the | ||
99 | * mapping elsewhere in the table! | ||
100 | * | ||
101 | * DLM_NORMAL: 0 | ||
102 | * DLM_NOTQUEUED: -EAGAIN | ||
103 | * DLM_CANCELGRANT: -EBUSY | ||
104 | * DLM_CANCEL: -DLM_ECANCEL | ||
105 | */ | ||
106 | /* Keep in sync with dlmapi.h */ | ||
107 | static int status_map[] = { | ||
108 | [DLM_NORMAL] = 0, /* Success */ | ||
109 | [DLM_GRANTED] = -EINVAL, | ||
110 | [DLM_DENIED] = -EACCES, | ||
111 | [DLM_DENIED_NOLOCKS] = -EACCES, | ||
112 | [DLM_WORKING] = -EACCES, | ||
113 | [DLM_BLOCKED] = -EINVAL, | ||
114 | [DLM_BLOCKED_ORPHAN] = -EINVAL, | ||
115 | [DLM_DENIED_GRACE_PERIOD] = -EACCES, | ||
116 | [DLM_SYSERR] = -ENOMEM, /* It is what it is */ | ||
117 | [DLM_NOSUPPORT] = -EPROTO, | ||
118 | [DLM_CANCELGRANT] = -EBUSY, /* Cancel after grant */ | ||
119 | [DLM_IVLOCKID] = -EINVAL, | ||
120 | [DLM_SYNC] = -EINVAL, | ||
121 | [DLM_BADTYPE] = -EINVAL, | ||
122 | [DLM_BADRESOURCE] = -EINVAL, | ||
123 | [DLM_MAXHANDLES] = -ENOMEM, | ||
124 | [DLM_NOCLINFO] = -EINVAL, | ||
125 | [DLM_NOLOCKMGR] = -EINVAL, | ||
126 | [DLM_NOPURGED] = -EINVAL, | ||
127 | [DLM_BADARGS] = -EINVAL, | ||
128 | [DLM_VOID] = -EINVAL, | ||
129 | [DLM_NOTQUEUED] = -EAGAIN, /* Trylock failed */ | ||
130 | [DLM_IVBUFLEN] = -EINVAL, | ||
131 | [DLM_CVTUNGRANT] = -EPERM, | ||
132 | [DLM_BADPARAM] = -EINVAL, | ||
133 | [DLM_VALNOTVALID] = -EINVAL, | ||
134 | [DLM_REJECTED] = -EPERM, | ||
135 | [DLM_ABORT] = -EINVAL, | ||
136 | [DLM_CANCEL] = -DLM_ECANCEL, /* Successful cancel */ | ||
137 | [DLM_IVRESHANDLE] = -EINVAL, | ||
138 | [DLM_DEADLOCK] = -EDEADLK, | ||
139 | [DLM_DENIED_NOASTS] = -EINVAL, | ||
140 | [DLM_FORWARD] = -EINVAL, | ||
141 | [DLM_TIMEOUT] = -ETIMEDOUT, | ||
142 | [DLM_IVGROUPID] = -EINVAL, | ||
143 | [DLM_VERS_CONFLICT] = -EOPNOTSUPP, | ||
144 | [DLM_BAD_DEVICE_PATH] = -ENOENT, | ||
145 | [DLM_NO_DEVICE_PERMISSION] = -EPERM, | ||
146 | [DLM_NO_CONTROL_DEVICE] = -ENOENT, | ||
147 | [DLM_RECOVERING] = -ENOTCONN, | ||
148 | [DLM_MIGRATING] = -ERESTART, | ||
149 | [DLM_MAXSTATS] = -EINVAL, | ||
150 | }; | ||
151 | |||
152 | static int dlm_status_to_errno(enum dlm_status status) | ||
153 | { | ||
154 | BUG_ON(status > (sizeof(status_map) / sizeof(status_map[0]))); | ||
155 | |||
156 | return status_map[status]; | ||
157 | } | ||
158 | |||
159 | static void o2dlm_lock_ast_wrapper(void *astarg) | ||
160 | { | ||
161 | BUG_ON(stack_glue_lproto == NULL); | ||
162 | |||
163 | stack_glue_lproto->lp_lock_ast(astarg); | ||
164 | } | ||
165 | |||
166 | static void o2dlm_blocking_ast_wrapper(void *astarg, int level) | ||
167 | { | ||
168 | BUG_ON(stack_glue_lproto == NULL); | ||
169 | |||
170 | stack_glue_lproto->lp_blocking_ast(astarg, level); | ||
171 | } | ||
172 | |||
173 | static void o2dlm_unlock_ast_wrapper(void *astarg, enum dlm_status status) | ||
174 | { | ||
175 | int error = dlm_status_to_errno(status); | ||
176 | |||
177 | BUG_ON(stack_glue_lproto == NULL); | ||
178 | |||
179 | /* | ||
180 | * In o2dlm, you can get both the lock_ast() for the lock being | ||
181 | * granted and the unlock_ast() for the CANCEL failing. A | ||
182 | * successful cancel sends DLM_NORMAL here. If the | ||
183 | * lock grant happened before the cancel arrived, you get | ||
184 | * DLM_CANCELGRANT. | ||
185 | * | ||
186 | * There's no need for the double-ast. If we see DLM_CANCELGRANT, | ||
187 | * we just ignore it. We expect the lock_ast() to handle the | ||
188 | * granted lock. | ||
189 | */ | ||
190 | if (status == DLM_CANCELGRANT) | ||
191 | return; | ||
192 | |||
193 | stack_glue_lproto->lp_unlock_ast(astarg, error); | ||
194 | } | ||
195 | |||
196 | static int o2cb_dlm_lock(struct ocfs2_cluster_connection *conn, | ||
197 | int mode, | ||
198 | union ocfs2_dlm_lksb *lksb, | ||
199 | u32 flags, | ||
200 | void *name, | ||
201 | unsigned int namelen, | ||
202 | void *astarg) | ||
203 | { | ||
204 | enum dlm_status status; | ||
205 | int o2dlm_mode = mode_to_o2dlm(mode); | ||
206 | int o2dlm_flags = flags_to_o2dlm(flags); | ||
207 | int ret; | ||
208 | |||
209 | status = dlmlock(conn->cc_lockspace, o2dlm_mode, &lksb->lksb_o2dlm, | ||
210 | o2dlm_flags, name, namelen, | ||
211 | o2dlm_lock_ast_wrapper, astarg, | ||
212 | o2dlm_blocking_ast_wrapper); | ||
213 | ret = dlm_status_to_errno(status); | ||
214 | return ret; | ||
215 | } | ||
216 | |||
217 | static int o2cb_dlm_unlock(struct ocfs2_cluster_connection *conn, | ||
218 | union ocfs2_dlm_lksb *lksb, | ||
219 | u32 flags, | ||
220 | void *astarg) | ||
221 | { | ||
222 | enum dlm_status status; | ||
223 | int o2dlm_flags = flags_to_o2dlm(flags); | ||
224 | int ret; | ||
225 | |||
226 | status = dlmunlock(conn->cc_lockspace, &lksb->lksb_o2dlm, | ||
227 | o2dlm_flags, o2dlm_unlock_ast_wrapper, astarg); | ||
228 | ret = dlm_status_to_errno(status); | ||
229 | return ret; | ||
230 | } | ||
231 | |||
232 | static int o2cb_dlm_lock_status(union ocfs2_dlm_lksb *lksb) | ||
233 | { | ||
234 | return dlm_status_to_errno(lksb->lksb_o2dlm.status); | ||
235 | } | ||
236 | |||
237 | static void *o2cb_dlm_lvb(union ocfs2_dlm_lksb *lksb) | ||
238 | { | ||
239 | return (void *)(lksb->lksb_o2dlm.lvb); | ||
240 | } | ||
241 | |||
242 | static void o2cb_dump_lksb(union ocfs2_dlm_lksb *lksb) | ||
243 | { | ||
244 | dlm_print_one_lock(lksb->lksb_o2dlm.lockid); | ||
245 | } | ||
246 | |||
247 | /* | ||
248 | * Called from the dlm when it's about to evict a node. This is how the | ||
249 | * classic stack signals node death. | ||
250 | */ | ||
251 | static void o2dlm_eviction_cb(int node_num, void *data) | ||
252 | { | ||
253 | struct ocfs2_cluster_connection *conn = data; | ||
254 | |||
255 | mlog(ML_NOTICE, "o2dlm has evicted node %d from group %.*s\n", | ||
256 | node_num, conn->cc_namelen, conn->cc_name); | ||
257 | |||
258 | conn->cc_recovery_handler(node_num, conn->cc_recovery_data); | ||
259 | } | ||
260 | |||
261 | static int o2cb_cluster_connect(struct ocfs2_cluster_connection *conn) | ||
262 | { | ||
263 | int rc = 0; | ||
264 | u32 dlm_key; | ||
265 | struct dlm_ctxt *dlm; | ||
266 | struct o2dlm_private *priv; | ||
267 | struct dlm_protocol_version dlm_version; | ||
268 | |||
269 | BUG_ON(conn == NULL); | ||
270 | |||
271 | /* for now we only have one cluster/node, make sure we see it | ||
272 | * in the heartbeat universe */ | ||
273 | if (!o2hb_check_local_node_heartbeating()) { | ||
274 | rc = -EINVAL; | ||
275 | goto out; | ||
276 | } | ||
277 | |||
278 | priv = kzalloc(sizeof(struct o2dlm_private), GFP_KERNEL); | ||
279 | if (!priv) { | ||
280 | rc = -ENOMEM; | ||
281 | goto out_free; | ||
282 | } | ||
283 | |||
284 | /* This just fills the structure in. It is safe to pass conn. */ | ||
285 | dlm_setup_eviction_cb(&priv->op_eviction_cb, o2dlm_eviction_cb, | ||
286 | conn); | ||
287 | |||
288 | conn->cc_private = priv; | ||
289 | |||
290 | /* used by the dlm code to make message headers unique, each | ||
291 | * node in this domain must agree on this. */ | ||
292 | dlm_key = crc32_le(0, conn->cc_name, conn->cc_namelen); | ||
293 | dlm_version.pv_major = conn->cc_version.pv_major; | ||
294 | dlm_version.pv_minor = conn->cc_version.pv_minor; | ||
295 | |||
296 | dlm = dlm_register_domain(conn->cc_name, dlm_key, &dlm_version); | ||
297 | if (IS_ERR(dlm)) { | ||
298 | rc = PTR_ERR(dlm); | ||
299 | mlog_errno(rc); | ||
300 | goto out_free; | ||
301 | } | ||
302 | |||
303 | conn->cc_version.pv_major = dlm_version.pv_major; | ||
304 | conn->cc_version.pv_minor = dlm_version.pv_minor; | ||
305 | conn->cc_lockspace = dlm; | ||
306 | |||
307 | dlm_register_eviction_cb(dlm, &priv->op_eviction_cb); | ||
308 | |||
309 | out_free: | ||
310 | if (rc && conn->cc_private) | ||
311 | kfree(conn->cc_private); | ||
312 | |||
313 | out: | ||
314 | return rc; | ||
315 | } | ||
316 | |||
317 | static int o2cb_cluster_disconnect(struct ocfs2_cluster_connection *conn) | ||
318 | { | ||
319 | struct dlm_ctxt *dlm = conn->cc_lockspace; | ||
320 | struct o2dlm_private *priv = conn->cc_private; | ||
321 | |||
322 | dlm_unregister_eviction_cb(&priv->op_eviction_cb); | ||
323 | conn->cc_private = NULL; | ||
324 | kfree(priv); | ||
325 | |||
326 | dlm_unregister_domain(dlm); | ||
327 | conn->cc_lockspace = NULL; | ||
328 | |||
329 | return 0; | ||
330 | } | ||
331 | |||
332 | static void o2hb_stop(const char *group) | ||
333 | { | ||
334 | int ret; | ||
335 | char *argv[5], *envp[3]; | ||
336 | |||
337 | argv[0] = (char *)o2nm_get_hb_ctl_path(); | ||
338 | argv[1] = "-K"; | ||
339 | argv[2] = "-u"; | ||
340 | argv[3] = (char *)group; | ||
341 | argv[4] = NULL; | ||
342 | |||
343 | mlog(0, "Run: %s %s %s %s\n", argv[0], argv[1], argv[2], argv[3]); | ||
344 | |||
345 | /* minimal command environment taken from cpu_run_sbin_hotplug */ | ||
346 | envp[0] = "HOME=/"; | ||
347 | envp[1] = "PATH=/sbin:/bin:/usr/sbin:/usr/bin"; | ||
348 | envp[2] = NULL; | ||
349 | |||
350 | ret = call_usermodehelper(argv[0], argv, envp, UMH_WAIT_PROC); | ||
351 | if (ret < 0) | ||
352 | mlog_errno(ret); | ||
353 | } | ||
354 | |||
355 | /* | ||
356 | * Hangup is a hack for tools compatibility. Older ocfs2-tools software | ||
357 | * expects the filesystem to call "ocfs2_hb_ctl" during unmount. This | ||
358 | * happens regardless of whether the DLM got started, so we can't do it | ||
359 | * in ocfs2_cluster_disconnect(). We bring the o2hb_stop() function into | ||
360 | * the glue and provide a "hangup" API for super.c to call. | ||
361 | * | ||
362 | * Other stacks will eventually provide a NULL ->hangup() pointer. | ||
363 | */ | ||
364 | static void o2cb_cluster_hangup(const char *group, int grouplen) | ||
365 | { | ||
366 | o2hb_stop(group); | ||
367 | } | ||
368 | |||
369 | static int o2cb_cluster_this_node(unsigned int *node) | ||
370 | { | ||
371 | int node_num; | ||
372 | |||
373 | node_num = o2nm_this_node(); | ||
374 | if (node_num == O2NM_INVALID_NODE_NUM) | ||
375 | return -ENOENT; | ||
376 | |||
377 | if (node_num >= O2NM_MAX_NODES) | ||
378 | return -EOVERFLOW; | ||
379 | |||
380 | *node = node_num; | ||
381 | return 0; | ||
382 | } | ||
383 | |||
384 | struct ocfs2_stack_operations o2cb_stack_ops = { | ||
385 | .connect = o2cb_cluster_connect, | ||
386 | .disconnect = o2cb_cluster_disconnect, | ||
387 | .hangup = o2cb_cluster_hangup, | ||
388 | .this_node = o2cb_cluster_this_node, | ||
389 | .dlm_lock = o2cb_dlm_lock, | ||
390 | .dlm_unlock = o2cb_dlm_unlock, | ||
391 | .lock_status = o2cb_dlm_lock_status, | ||
392 | .lock_lvb = o2cb_dlm_lvb, | ||
393 | .dump_lksb = o2cb_dump_lksb, | ||
394 | }; | ||
395 | |||
diff --git a/fs/ocfs2/stackglue.c b/fs/ocfs2/stackglue.c index e35dde6217f5..e197367b6bd6 100644 --- a/fs/ocfs2/stackglue.c +++ b/fs/ocfs2/stackglue.c | |||
@@ -19,204 +19,17 @@ | |||
19 | */ | 19 | */ |
20 | 20 | ||
21 | #include <linux/slab.h> | 21 | #include <linux/slab.h> |
22 | #include <linux/crc32.h> | ||
23 | #include <linux/kmod.h> | 22 | #include <linux/kmod.h> |
24 | 23 | ||
25 | /* Needed for AOP_TRUNCATED_PAGE in mlog_errno() */ | 24 | /* Needed for AOP_TRUNCATED_PAGE in mlog_errno() */ |
26 | #include <linux/fs.h> | 25 | #include <linux/fs.h> |
27 | 26 | ||
28 | #include "cluster/masklog.h" | 27 | #include "cluster/masklog.h" |
29 | #include "cluster/nodemanager.h" | ||
30 | #include "cluster/heartbeat.h" | ||
31 | 28 | ||
32 | #include "stackglue.h" | 29 | #include "stackglue.h" |
33 | 30 | ||
34 | static struct ocfs2_locking_protocol *lproto; | 31 | struct ocfs2_locking_protocol *stack_glue_lproto; |
35 | |||
36 | struct o2dlm_private { | ||
37 | struct dlm_eviction_cb op_eviction_cb; | ||
38 | }; | ||
39 | |||
40 | /* These should be identical */ | ||
41 | #if (DLM_LOCK_IV != LKM_IVMODE) | ||
42 | # error Lock modes do not match | ||
43 | #endif | ||
44 | #if (DLM_LOCK_NL != LKM_NLMODE) | ||
45 | # error Lock modes do not match | ||
46 | #endif | ||
47 | #if (DLM_LOCK_CR != LKM_CRMODE) | ||
48 | # error Lock modes do not match | ||
49 | #endif | ||
50 | #if (DLM_LOCK_CW != LKM_CWMODE) | ||
51 | # error Lock modes do not match | ||
52 | #endif | ||
53 | #if (DLM_LOCK_PR != LKM_PRMODE) | ||
54 | # error Lock modes do not match | ||
55 | #endif | ||
56 | #if (DLM_LOCK_PW != LKM_PWMODE) | ||
57 | # error Lock modes do not match | ||
58 | #endif | ||
59 | #if (DLM_LOCK_EX != LKM_EXMODE) | ||
60 | # error Lock modes do not match | ||
61 | #endif | ||
62 | static inline int mode_to_o2dlm(int mode) | ||
63 | { | ||
64 | BUG_ON(mode > LKM_MAXMODE); | ||
65 | |||
66 | return mode; | ||
67 | } | ||
68 | |||
69 | #define map_flag(_generic, _o2dlm) \ | ||
70 | if (flags & (_generic)) { \ | ||
71 | flags &= ~(_generic); \ | ||
72 | o2dlm_flags |= (_o2dlm); \ | ||
73 | } | ||
74 | static int flags_to_o2dlm(u32 flags) | ||
75 | { | ||
76 | int o2dlm_flags = 0; | ||
77 | |||
78 | map_flag(DLM_LKF_NOQUEUE, LKM_NOQUEUE); | ||
79 | map_flag(DLM_LKF_CANCEL, LKM_CANCEL); | ||
80 | map_flag(DLM_LKF_CONVERT, LKM_CONVERT); | ||
81 | map_flag(DLM_LKF_VALBLK, LKM_VALBLK); | ||
82 | map_flag(DLM_LKF_IVVALBLK, LKM_INVVALBLK); | ||
83 | map_flag(DLM_LKF_ORPHAN, LKM_ORPHAN); | ||
84 | map_flag(DLM_LKF_FORCEUNLOCK, LKM_FORCE); | ||
85 | map_flag(DLM_LKF_TIMEOUT, LKM_TIMEOUT); | ||
86 | map_flag(DLM_LKF_LOCAL, LKM_LOCAL); | ||
87 | |||
88 | /* map_flag() should have cleared every flag passed in */ | ||
89 | BUG_ON(flags != 0); | ||
90 | |||
91 | return o2dlm_flags; | ||
92 | } | ||
93 | #undef map_flag | ||
94 | |||
95 | /* | ||
96 | * Map an o2dlm status to standard errno values. | ||
97 | * | ||
98 | * o2dlm only uses a handful of these, and returns even fewer to the | ||
99 | * caller. Still, we try to assign sane values to each error. | ||
100 | * | ||
101 | * The following value pairs have special meanings to dlmglue, thus | ||
102 | * the right hand side needs to stay unique - never duplicate the | ||
103 | * mapping elsewhere in the table! | ||
104 | * | ||
105 | * DLM_NORMAL: 0 | ||
106 | * DLM_NOTQUEUED: -EAGAIN | ||
107 | * DLM_CANCELGRANT: -EBUSY | ||
108 | * DLM_CANCEL: -DLM_ECANCEL | ||
109 | */ | ||
110 | /* Keep in sync with dlmapi.h */ | ||
111 | static int status_map[] = { | ||
112 | [DLM_NORMAL] = 0, /* Success */ | ||
113 | [DLM_GRANTED] = -EINVAL, | ||
114 | [DLM_DENIED] = -EACCES, | ||
115 | [DLM_DENIED_NOLOCKS] = -EACCES, | ||
116 | [DLM_WORKING] = -EACCES, | ||
117 | [DLM_BLOCKED] = -EINVAL, | ||
118 | [DLM_BLOCKED_ORPHAN] = -EINVAL, | ||
119 | [DLM_DENIED_GRACE_PERIOD] = -EACCES, | ||
120 | [DLM_SYSERR] = -ENOMEM, /* It is what it is */ | ||
121 | [DLM_NOSUPPORT] = -EPROTO, | ||
122 | [DLM_CANCELGRANT] = -EBUSY, /* Cancel after grant */ | ||
123 | [DLM_IVLOCKID] = -EINVAL, | ||
124 | [DLM_SYNC] = -EINVAL, | ||
125 | [DLM_BADTYPE] = -EINVAL, | ||
126 | [DLM_BADRESOURCE] = -EINVAL, | ||
127 | [DLM_MAXHANDLES] = -ENOMEM, | ||
128 | [DLM_NOCLINFO] = -EINVAL, | ||
129 | [DLM_NOLOCKMGR] = -EINVAL, | ||
130 | [DLM_NOPURGED] = -EINVAL, | ||
131 | [DLM_BADARGS] = -EINVAL, | ||
132 | [DLM_VOID] = -EINVAL, | ||
133 | [DLM_NOTQUEUED] = -EAGAIN, /* Trylock failed */ | ||
134 | [DLM_IVBUFLEN] = -EINVAL, | ||
135 | [DLM_CVTUNGRANT] = -EPERM, | ||
136 | [DLM_BADPARAM] = -EINVAL, | ||
137 | [DLM_VALNOTVALID] = -EINVAL, | ||
138 | [DLM_REJECTED] = -EPERM, | ||
139 | [DLM_ABORT] = -EINVAL, | ||
140 | [DLM_CANCEL] = -DLM_ECANCEL, /* Successful cancel */ | ||
141 | [DLM_IVRESHANDLE] = -EINVAL, | ||
142 | [DLM_DEADLOCK] = -EDEADLK, | ||
143 | [DLM_DENIED_NOASTS] = -EINVAL, | ||
144 | [DLM_FORWARD] = -EINVAL, | ||
145 | [DLM_TIMEOUT] = -ETIMEDOUT, | ||
146 | [DLM_IVGROUPID] = -EINVAL, | ||
147 | [DLM_VERS_CONFLICT] = -EOPNOTSUPP, | ||
148 | [DLM_BAD_DEVICE_PATH] = -ENOENT, | ||
149 | [DLM_NO_DEVICE_PERMISSION] = -EPERM, | ||
150 | [DLM_NO_CONTROL_DEVICE] = -ENOENT, | ||
151 | [DLM_RECOVERING] = -ENOTCONN, | ||
152 | [DLM_MIGRATING] = -ERESTART, | ||
153 | [DLM_MAXSTATS] = -EINVAL, | ||
154 | }; | ||
155 | |||
156 | static int dlm_status_to_errno(enum dlm_status status) | ||
157 | { | ||
158 | BUG_ON(status > (sizeof(status_map) / sizeof(status_map[0]))); | ||
159 | 32 | ||
160 | return status_map[status]; | ||
161 | } | ||
162 | |||
163 | static void o2dlm_lock_ast_wrapper(void *astarg) | ||
164 | { | ||
165 | BUG_ON(lproto == NULL); | ||
166 | |||
167 | lproto->lp_lock_ast(astarg); | ||
168 | } | ||
169 | |||
170 | static void o2dlm_blocking_ast_wrapper(void *astarg, int level) | ||
171 | { | ||
172 | BUG_ON(lproto == NULL); | ||
173 | |||
174 | lproto->lp_blocking_ast(astarg, level); | ||
175 | } | ||
176 | |||
177 | static void o2dlm_unlock_ast_wrapper(void *astarg, enum dlm_status status) | ||
178 | { | ||
179 | int error = dlm_status_to_errno(status); | ||
180 | |||
181 | BUG_ON(lproto == NULL); | ||
182 | |||
183 | /* | ||
184 | * In o2dlm, you can get both the lock_ast() for the lock being | ||
185 | * granted and the unlock_ast() for the CANCEL failing. A | ||
186 | * successful cancel sends DLM_NORMAL here. If the | ||
187 | * lock grant happened before the cancel arrived, you get | ||
188 | * DLM_CANCELGRANT. | ||
189 | * | ||
190 | * There's no need for the double-ast. If we see DLM_CANCELGRANT, | ||
191 | * we just ignore it. We expect the lock_ast() to handle the | ||
192 | * granted lock. | ||
193 | */ | ||
194 | if (status == DLM_CANCELGRANT) | ||
195 | return; | ||
196 | |||
197 | lproto->lp_unlock_ast(astarg, error); | ||
198 | } | ||
199 | |||
200 | static int o2cb_dlm_lock(struct ocfs2_cluster_connection *conn, | ||
201 | int mode, | ||
202 | union ocfs2_dlm_lksb *lksb, | ||
203 | u32 flags, | ||
204 | void *name, | ||
205 | unsigned int namelen, | ||
206 | void *astarg) | ||
207 | { | ||
208 | enum dlm_status status; | ||
209 | int o2dlm_mode = mode_to_o2dlm(mode); | ||
210 | int o2dlm_flags = flags_to_o2dlm(flags); | ||
211 | int ret; | ||
212 | |||
213 | status = dlmlock(conn->cc_lockspace, o2dlm_mode, &lksb->lksb_o2dlm, | ||
214 | o2dlm_flags, name, namelen, | ||
215 | o2dlm_lock_ast_wrapper, astarg, | ||
216 | o2dlm_blocking_ast_wrapper); | ||
217 | ret = dlm_status_to_errno(status); | ||
218 | return ret; | ||
219 | } | ||
220 | 33 | ||
221 | int ocfs2_dlm_lock(struct ocfs2_cluster_connection *conn, | 34 | int ocfs2_dlm_lock(struct ocfs2_cluster_connection *conn, |
222 | int mode, | 35 | int mode, |
@@ -226,25 +39,10 @@ int ocfs2_dlm_lock(struct ocfs2_cluster_connection *conn, | |||
226 | unsigned int namelen, | 39 | unsigned int namelen, |
227 | void *astarg) | 40 | void *astarg) |
228 | { | 41 | { |
229 | BUG_ON(lproto == NULL); | 42 | BUG_ON(stack_glue_lproto == NULL); |
230 | |||
231 | return o2cb_dlm_lock(conn, mode, lksb, flags, | ||
232 | name, namelen, astarg); | ||
233 | } | ||
234 | |||
235 | static int o2cb_dlm_unlock(struct ocfs2_cluster_connection *conn, | ||
236 | union ocfs2_dlm_lksb *lksb, | ||
237 | u32 flags, | ||
238 | void *astarg) | ||
239 | { | ||
240 | enum dlm_status status; | ||
241 | int o2dlm_flags = flags_to_o2dlm(flags); | ||
242 | int ret; | ||
243 | 43 | ||
244 | status = dlmunlock(conn->cc_lockspace, &lksb->lksb_o2dlm, | 44 | return o2cb_stack_ops.dlm_lock(conn, mode, lksb, flags, |
245 | o2dlm_flags, o2dlm_unlock_ast_wrapper, astarg); | 45 | name, namelen, astarg); |
246 | ret = dlm_status_to_errno(status); | ||
247 | return ret; | ||
248 | } | 46 | } |
249 | 47 | ||
250 | int ocfs2_dlm_unlock(struct ocfs2_cluster_connection *conn, | 48 | int ocfs2_dlm_unlock(struct ocfs2_cluster_connection *conn, |
@@ -252,19 +50,14 @@ int ocfs2_dlm_unlock(struct ocfs2_cluster_connection *conn, | |||
252 | u32 flags, | 50 | u32 flags, |
253 | void *astarg) | 51 | void *astarg) |
254 | { | 52 | { |
255 | BUG_ON(lproto == NULL); | 53 | BUG_ON(stack_glue_lproto == NULL); |
256 | 54 | ||
257 | return o2cb_dlm_unlock(conn, lksb, flags, astarg); | 55 | return o2cb_stack_ops.dlm_unlock(conn, lksb, flags, astarg); |
258 | } | ||
259 | |||
260 | static int o2cb_dlm_lock_status(union ocfs2_dlm_lksb *lksb) | ||
261 | { | ||
262 | return dlm_status_to_errno(lksb->lksb_o2dlm.status); | ||
263 | } | 56 | } |
264 | 57 | ||
265 | int ocfs2_dlm_lock_status(union ocfs2_dlm_lksb *lksb) | 58 | int ocfs2_dlm_lock_status(union ocfs2_dlm_lksb *lksb) |
266 | { | 59 | { |
267 | return o2cb_dlm_lock_status(lksb); | 60 | return o2cb_stack_ops.lock_status(lksb); |
268 | } | 61 | } |
269 | 62 | ||
270 | /* | 63 | /* |
@@ -272,94 +65,14 @@ int ocfs2_dlm_lock_status(union ocfs2_dlm_lksb *lksb) | |||
272 | * don't cast at the glue level. The real answer is that the header | 65 | * don't cast at the glue level. The real answer is that the header |
273 | * ordering is nigh impossible. | 66 | * ordering is nigh impossible. |
274 | */ | 67 | */ |
275 | static void *o2cb_dlm_lvb(union ocfs2_dlm_lksb *lksb) | ||
276 | { | ||
277 | return (void *)(lksb->lksb_o2dlm.lvb); | ||
278 | } | ||
279 | |||
280 | void *ocfs2_dlm_lvb(union ocfs2_dlm_lksb *lksb) | 68 | void *ocfs2_dlm_lvb(union ocfs2_dlm_lksb *lksb) |
281 | { | 69 | { |
282 | return o2cb_dlm_lvb(lksb); | 70 | return o2cb_stack_ops.lock_lvb(lksb); |
283 | } | ||
284 | |||
285 | static void o2cb_dlm_dump_lksb(union ocfs2_dlm_lksb *lksb) | ||
286 | { | ||
287 | dlm_print_one_lock(lksb->lksb_o2dlm.lockid); | ||
288 | } | 71 | } |
289 | 72 | ||
290 | void ocfs2_dlm_dump_lksb(union ocfs2_dlm_lksb *lksb) | 73 | void ocfs2_dlm_dump_lksb(union ocfs2_dlm_lksb *lksb) |
291 | { | 74 | { |
292 | o2cb_dlm_dump_lksb(lksb); | 75 | o2cb_stack_ops.dump_lksb(lksb); |
293 | } | ||
294 | |||
295 | /* | ||
296 | * Called from the dlm when it's about to evict a node. This is how the | ||
297 | * classic stack signals node death. | ||
298 | */ | ||
299 | static void o2dlm_eviction_cb(int node_num, void *data) | ||
300 | { | ||
301 | struct ocfs2_cluster_connection *conn = data; | ||
302 | |||
303 | mlog(ML_NOTICE, "o2dlm has evicted node %d from group %.*s\n", | ||
304 | node_num, conn->cc_namelen, conn->cc_name); | ||
305 | |||
306 | conn->cc_recovery_handler(node_num, conn->cc_recovery_data); | ||
307 | } | ||
308 | |||
309 | static int o2cb_cluster_connect(struct ocfs2_cluster_connection *conn) | ||
310 | { | ||
311 | int rc = 0; | ||
312 | u32 dlm_key; | ||
313 | struct dlm_ctxt *dlm; | ||
314 | struct o2dlm_private *priv; | ||
315 | struct dlm_protocol_version dlm_version; | ||
316 | |||
317 | BUG_ON(conn == NULL); | ||
318 | |||
319 | /* for now we only have one cluster/node, make sure we see it | ||
320 | * in the heartbeat universe */ | ||
321 | if (!o2hb_check_local_node_heartbeating()) { | ||
322 | rc = -EINVAL; | ||
323 | goto out; | ||
324 | } | ||
325 | |||
326 | priv = kzalloc(sizeof(struct o2dlm_private), GFP_KERNEL); | ||
327 | if (!priv) { | ||
328 | rc = -ENOMEM; | ||
329 | goto out_free; | ||
330 | } | ||
331 | |||
332 | /* This just fills the structure in. It is safe to pass conn. */ | ||
333 | dlm_setup_eviction_cb(&priv->op_eviction_cb, o2dlm_eviction_cb, | ||
334 | conn); | ||
335 | |||
336 | conn->cc_private = priv; | ||
337 | |||
338 | /* used by the dlm code to make message headers unique, each | ||
339 | * node in this domain must agree on this. */ | ||
340 | dlm_key = crc32_le(0, conn->cc_name, conn->cc_namelen); | ||
341 | dlm_version.pv_major = conn->cc_version.pv_major; | ||
342 | dlm_version.pv_minor = conn->cc_version.pv_minor; | ||
343 | |||
344 | dlm = dlm_register_domain(conn->cc_name, dlm_key, &dlm_version); | ||
345 | if (IS_ERR(dlm)) { | ||
346 | rc = PTR_ERR(dlm); | ||
347 | mlog_errno(rc); | ||
348 | goto out_free; | ||
349 | } | ||
350 | |||
351 | conn->cc_version.pv_major = dlm_version.pv_major; | ||
352 | conn->cc_version.pv_minor = dlm_version.pv_minor; | ||
353 | conn->cc_lockspace = dlm; | ||
354 | |||
355 | dlm_register_eviction_cb(dlm, &priv->op_eviction_cb); | ||
356 | |||
357 | out_free: | ||
358 | if (rc && conn->cc_private) | ||
359 | kfree(conn->cc_private); | ||
360 | |||
361 | out: | ||
362 | return rc; | ||
363 | } | 76 | } |
364 | 77 | ||
365 | int ocfs2_cluster_connect(const char *group, | 78 | int ocfs2_cluster_connect(const char *group, |
@@ -394,9 +107,9 @@ int ocfs2_cluster_connect(const char *group, | |||
394 | new_conn->cc_recovery_data = recovery_data; | 107 | new_conn->cc_recovery_data = recovery_data; |
395 | 108 | ||
396 | /* Start the new connection at our maximum compatibility level */ | 109 | /* Start the new connection at our maximum compatibility level */ |
397 | new_conn->cc_version = lproto->lp_max_version; | 110 | new_conn->cc_version = stack_glue_lproto->lp_max_version; |
398 | 111 | ||
399 | rc = o2cb_cluster_connect(new_conn); | 112 | rc = o2cb_stack_ops.connect(new_conn); |
400 | if (rc) { | 113 | if (rc) { |
401 | mlog_errno(rc); | 114 | mlog_errno(rc); |
402 | goto out_free; | 115 | goto out_free; |
@@ -412,29 +125,13 @@ out: | |||
412 | return rc; | 125 | return rc; |
413 | } | 126 | } |
414 | 127 | ||
415 | |||
416 | static int o2cb_cluster_disconnect(struct ocfs2_cluster_connection *conn) | ||
417 | { | ||
418 | struct dlm_ctxt *dlm = conn->cc_lockspace; | ||
419 | struct o2dlm_private *priv = conn->cc_private; | ||
420 | |||
421 | dlm_unregister_eviction_cb(&priv->op_eviction_cb); | ||
422 | conn->cc_private = NULL; | ||
423 | kfree(priv); | ||
424 | |||
425 | dlm_unregister_domain(dlm); | ||
426 | conn->cc_lockspace = NULL; | ||
427 | |||
428 | return 0; | ||
429 | } | ||
430 | |||
431 | int ocfs2_cluster_disconnect(struct ocfs2_cluster_connection *conn) | 128 | int ocfs2_cluster_disconnect(struct ocfs2_cluster_connection *conn) |
432 | { | 129 | { |
433 | int ret; | 130 | int ret; |
434 | 131 | ||
435 | BUG_ON(conn == NULL); | 132 | BUG_ON(conn == NULL); |
436 | 133 | ||
437 | ret = o2cb_cluster_disconnect(conn); | 134 | ret = o2cb_stack_ops.disconnect(conn); |
438 | 135 | ||
439 | /* XXX Should we free it anyway? */ | 136 | /* XXX Should we free it anyway? */ |
440 | if (!ret) | 137 | if (!ret) |
@@ -443,75 +140,23 @@ int ocfs2_cluster_disconnect(struct ocfs2_cluster_connection *conn) | |||
443 | return ret; | 140 | return ret; |
444 | } | 141 | } |
445 | 142 | ||
446 | static void o2hb_stop(const char *group) | ||
447 | { | ||
448 | int ret; | ||
449 | char *argv[5], *envp[3]; | ||
450 | |||
451 | argv[0] = (char *)o2nm_get_hb_ctl_path(); | ||
452 | argv[1] = "-K"; | ||
453 | argv[2] = "-u"; | ||
454 | argv[3] = (char *)group; | ||
455 | argv[4] = NULL; | ||
456 | |||
457 | mlog(0, "Run: %s %s %s %s\n", argv[0], argv[1], argv[2], argv[3]); | ||
458 | |||
459 | /* minimal command environment taken from cpu_run_sbin_hotplug */ | ||
460 | envp[0] = "HOME=/"; | ||
461 | envp[1] = "PATH=/sbin:/bin:/usr/sbin:/usr/bin"; | ||
462 | envp[2] = NULL; | ||
463 | |||
464 | ret = call_usermodehelper(argv[0], argv, envp, UMH_WAIT_PROC); | ||
465 | if (ret < 0) | ||
466 | mlog_errno(ret); | ||
467 | } | ||
468 | |||
469 | /* | ||
470 | * Hangup is a hack for tools compatibility. Older ocfs2-tools software | ||
471 | * expects the filesystem to call "ocfs2_hb_ctl" during unmount. This | ||
472 | * happens regardless of whether the DLM got started, so we can't do it | ||
473 | * in ocfs2_cluster_disconnect(). We bring the o2hb_stop() function into | ||
474 | * the glue and provide a "hangup" API for super.c to call. | ||
475 | * | ||
476 | * Other stacks will eventually provide a NULL ->hangup() pointer. | ||
477 | */ | ||
478 | static void o2cb_cluster_hangup(const char *group, int grouplen) | ||
479 | { | ||
480 | o2hb_stop(group); | ||
481 | } | ||
482 | |||
483 | void ocfs2_cluster_hangup(const char *group, int grouplen) | 143 | void ocfs2_cluster_hangup(const char *group, int grouplen) |
484 | { | 144 | { |
485 | BUG_ON(group == NULL); | 145 | BUG_ON(group == NULL); |
486 | BUG_ON(group[grouplen] != '\0'); | 146 | BUG_ON(group[grouplen] != '\0'); |
487 | 147 | ||
488 | o2cb_cluster_hangup(group, grouplen); | 148 | o2cb_stack_ops.hangup(group, grouplen); |
489 | } | ||
490 | |||
491 | static int o2cb_cluster_this_node(unsigned int *node) | ||
492 | { | ||
493 | int node_num; | ||
494 | |||
495 | node_num = o2nm_this_node(); | ||
496 | if (node_num == O2NM_INVALID_NODE_NUM) | ||
497 | return -ENOENT; | ||
498 | |||
499 | if (node_num >= O2NM_MAX_NODES) | ||
500 | return -EOVERFLOW; | ||
501 | |||
502 | *node = node_num; | ||
503 | return 0; | ||
504 | } | 149 | } |
505 | 150 | ||
506 | int ocfs2_cluster_this_node(unsigned int *node) | 151 | int ocfs2_cluster_this_node(unsigned int *node) |
507 | { | 152 | { |
508 | return o2cb_cluster_this_node(node); | 153 | return o2cb_stack_ops.this_node(node); |
509 | } | 154 | } |
510 | 155 | ||
511 | void ocfs2_stack_glue_set_locking_protocol(struct ocfs2_locking_protocol *proto) | 156 | void ocfs2_stack_glue_set_locking_protocol(struct ocfs2_locking_protocol *proto) |
512 | { | 157 | { |
513 | BUG_ON(proto != NULL); | 158 | BUG_ON(proto != NULL); |
514 | 159 | ||
515 | lproto = proto; | 160 | stack_glue_lproto = proto; |
516 | } | 161 | } |
517 | 162 | ||
diff --git a/fs/ocfs2/stackglue.h b/fs/ocfs2/stackglue.h index decb147106fd..083632215dc5 100644 --- a/fs/ocfs2/stackglue.h +++ b/fs/ocfs2/stackglue.h | |||
@@ -25,6 +25,8 @@ | |||
25 | #include <linux/list.h> | 25 | #include <linux/list.h> |
26 | #include <linux/dlmconstants.h> | 26 | #include <linux/dlmconstants.h> |
27 | 27 | ||
28 | #include "dlm/dlmapi.h" | ||
29 | |||
28 | /* | 30 | /* |
29 | * dlmconstants.h does not have a LOCAL flag. We hope to remove it | 31 | * dlmconstants.h does not have a LOCAL flag. We hope to remove it |
30 | * some day, but right now we need it. Let's fake it. This value is larger | 32 | * some day, but right now we need it. Let's fake it. This value is larger |
@@ -39,13 +41,18 @@ | |||
39 | #define GROUP_NAME_MAX 64 | 41 | #define GROUP_NAME_MAX 64 |
40 | 42 | ||
41 | 43 | ||
42 | #include "dlm/dlmapi.h" | 44 | /* |
43 | 45 | * ocfs2_protocol_version changes when ocfs2 does something different in | |
46 | * its inter-node behavior. See dlmglue.c for more information. | ||
47 | */ | ||
44 | struct ocfs2_protocol_version { | 48 | struct ocfs2_protocol_version { |
45 | u8 pv_major; | 49 | u8 pv_major; |
46 | u8 pv_minor; | 50 | u8 pv_minor; |
47 | }; | 51 | }; |
48 | 52 | ||
53 | /* | ||
54 | * The ocfs2_locking_protocol defines the handlers called on ocfs2's behalf. | ||
55 | */ | ||
49 | struct ocfs2_locking_protocol { | 56 | struct ocfs2_locking_protocol { |
50 | struct ocfs2_protocol_version lp_max_version; | 57 | struct ocfs2_protocol_version lp_max_version; |
51 | void (*lp_lock_ast)(void *astarg); | 58 | void (*lp_lock_ast)(void *astarg); |
@@ -53,10 +60,20 @@ struct ocfs2_locking_protocol { | |||
53 | void (*lp_unlock_ast)(void *astarg, int error); | 60 | void (*lp_unlock_ast)(void *astarg, int error); |
54 | }; | 61 | }; |
55 | 62 | ||
63 | /* | ||
64 | * A union of all lock status structures. We define it here so that the | ||
65 | * size of the union is known. Lock status structures are embedded in | ||
66 | * ocfs2 inodes. | ||
67 | */ | ||
56 | union ocfs2_dlm_lksb { | 68 | union ocfs2_dlm_lksb { |
57 | struct dlm_lockstatus lksb_o2dlm; | 69 | struct dlm_lockstatus lksb_o2dlm; |
58 | }; | 70 | }; |
59 | 71 | ||
72 | /* | ||
73 | * A cluster connection. Mostly opaque to ocfs2, the connection holds | ||
74 | * state for the underlying stack. ocfs2 does use cc_version to determine | ||
75 | * locking compatibility. | ||
76 | */ | ||
60 | struct ocfs2_cluster_connection { | 77 | struct ocfs2_cluster_connection { |
61 | char cc_name[GROUP_NAME_MAX]; | 78 | char cc_name[GROUP_NAME_MAX]; |
62 | int cc_namelen; | 79 | int cc_namelen; |
@@ -67,6 +84,106 @@ struct ocfs2_cluster_connection { | |||
67 | void *cc_private; | 84 | void *cc_private; |
68 | }; | 85 | }; |
69 | 86 | ||
87 | /* | ||
88 | * Each cluster stack implements the stack operations structure. Not used | ||
89 | * in the ocfs2 code, the stackglue code translates generic cluster calls | ||
90 | * into stack operations. | ||
91 | */ | ||
92 | struct ocfs2_stack_operations { | ||
93 | /* | ||
94 | * The fs code calls ocfs2_cluster_connect() to attach a new | ||
95 | * filesystem to the cluster stack. The ->connect() op is passed | ||
96 | * an ocfs2_cluster_connection with the name and recovery field | ||
97 | * filled in. | ||
98 | * | ||
99 | * The stack must set up any notification mechanisms and create | ||
100 | * the filesystem lockspace in the DLM. The lockspace should be | ||
101 | * stored on cc_lockspace. Any other information can be stored on | ||
102 | * cc_private. | ||
103 | * | ||
104 | * ->connect() must not return until it is guaranteed that | ||
105 | * | ||
106 | * - Node down notifications for the filesystem will be recieved | ||
107 | * and passed to conn->cc_recovery_handler(). | ||
108 | * - Locking requests for the filesystem will be processed. | ||
109 | */ | ||
110 | int (*connect)(struct ocfs2_cluster_connection *conn); | ||
111 | |||
112 | /* | ||
113 | * The fs code calls ocfs2_cluster_disconnect() when a filesystem | ||
114 | * no longer needs cluster services. All DLM locks have been | ||
115 | * dropped, and recovery notification is being ignored by the | ||
116 | * fs code. The stack must disengage from the DLM and discontinue | ||
117 | * recovery notification. | ||
118 | * | ||
119 | * Once ->disconnect() has returned, the connection structure will | ||
120 | * be freed. Thus, a stack must not return from ->disconnect() | ||
121 | * until it will no longer reference the conn pointer. | ||
122 | */ | ||
123 | int (*disconnect)(struct ocfs2_cluster_connection *conn); | ||
124 | |||
125 | /* | ||
126 | * ocfs2_cluster_hangup() exists for compatibility with older | ||
127 | * ocfs2 tools. Only the classic stack really needs it. As such | ||
128 | * ->hangup() is not required of all stacks. See the comment by | ||
129 | * ocfs2_cluster_hangup() for more details. | ||
130 | */ | ||
131 | void (*hangup)(const char *group, int grouplen); | ||
132 | |||
133 | /* | ||
134 | * ->this_node() returns the cluster's unique identifier for the | ||
135 | * local node. | ||
136 | */ | ||
137 | int (*this_node)(unsigned int *node); | ||
138 | |||
139 | /* | ||
140 | * Call the underlying dlm lock function. The ->dlm_lock() | ||
141 | * callback should convert the flags and mode as appropriate. | ||
142 | * | ||
143 | * ast and bast functions are not part of the call because the | ||
144 | * stack will likely want to wrap ast and bast calls before passing | ||
145 | * them to stack->sp_proto. | ||
146 | */ | ||
147 | int (*dlm_lock)(struct ocfs2_cluster_connection *conn, | ||
148 | int mode, | ||
149 | union ocfs2_dlm_lksb *lksb, | ||
150 | u32 flags, | ||
151 | void *name, | ||
152 | unsigned int namelen, | ||
153 | void *astarg); | ||
154 | |||
155 | /* | ||
156 | * Call the underlying dlm unlock function. The ->dlm_unlock() | ||
157 | * function should convert the flags as appropriate. | ||
158 | * | ||
159 | * The unlock ast is not passed, as the stack will want to wrap | ||
160 | * it before calling stack->sp_proto->lp_unlock_ast(). | ||
161 | */ | ||
162 | int (*dlm_unlock)(struct ocfs2_cluster_connection *conn, | ||
163 | union ocfs2_dlm_lksb *lksb, | ||
164 | u32 flags, | ||
165 | void *astarg); | ||
166 | |||
167 | /* | ||
168 | * Return the status of the current lock status block. The fs | ||
169 | * code should never dereference the union. The ->lock_status() | ||
170 | * callback pulls out the stack-specific lksb, converts the status | ||
171 | * to a proper errno, and returns it. | ||
172 | */ | ||
173 | int (*lock_status)(union ocfs2_dlm_lksb *lksb); | ||
174 | |||
175 | /* | ||
176 | * Pull the lvb pointer off of the stack-specific lksb. | ||
177 | */ | ||
178 | void *(*lock_lvb)(union ocfs2_dlm_lksb *lksb); | ||
179 | |||
180 | /* | ||
181 | * This is an optoinal debugging hook. If provided, the | ||
182 | * stack can dump debugging information about this lock. | ||
183 | */ | ||
184 | void (*dump_lksb)(union ocfs2_dlm_lksb *lksb); | ||
185 | }; | ||
186 | |||
70 | int ocfs2_cluster_connect(const char *group, | 187 | int ocfs2_cluster_connect(const char *group, |
71 | int grouplen, | 188 | int grouplen, |
72 | void (*recovery_handler)(int node_num, | 189 | void (*recovery_handler)(int node_num, |
@@ -95,4 +212,6 @@ void ocfs2_dlm_dump_lksb(union ocfs2_dlm_lksb *lksb); | |||
95 | 212 | ||
96 | void ocfs2_stack_glue_set_locking_protocol(struct ocfs2_locking_protocol *proto); | 213 | void ocfs2_stack_glue_set_locking_protocol(struct ocfs2_locking_protocol *proto); |
97 | 214 | ||
215 | extern struct ocfs2_locking_protocol *stack_glue_lproto; | ||
216 | extern struct ocfs2_stack_operations o2cb_stack_ops; | ||
98 | #endif /* STACKGLUE_H */ | 217 | #endif /* STACKGLUE_H */ |