aboutsummaryrefslogtreecommitdiffstats
path: root/fs/ocfs2/stackglue.c
diff options
context:
space:
mode:
authorJoel Becker <joel.becker@oracle.com>2008-02-01 18:02:36 -0500
committerMark Fasheh <mfasheh@suse.com>2008-04-18 11:56:05 -0400
commite3dad42bf993a0f24eb6e46152356c9b119c15e8 (patch)
treedf0419dc5e4387db7e6a6e0118bb5b9d01d8c0b2 /fs/ocfs2/stackglue.c
parent553aa7e408eac402c00b67ddfa7aec13fe1f3a33 (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>
Diffstat (limited to 'fs/ocfs2/stackglue.c')
-rw-r--r--fs/ocfs2/stackglue.c385
1 files changed, 15 insertions, 370 deletions
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
34static struct ocfs2_locking_protocol *lproto; 31struct ocfs2_locking_protocol *stack_glue_lproto;
35
36struct 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
62static 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 }
74static 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 */
111static 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
156static 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
163static void o2dlm_lock_ast_wrapper(void *astarg)
164{
165 BUG_ON(lproto == NULL);
166
167 lproto->lp_lock_ast(astarg);
168}
169
170static 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
177static 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
200static 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
221int ocfs2_dlm_lock(struct ocfs2_cluster_connection *conn, 34int 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
235static 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
250int ocfs2_dlm_unlock(struct ocfs2_cluster_connection *conn, 48int 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
260static 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
265int ocfs2_dlm_lock_status(union ocfs2_dlm_lksb *lksb) 58int 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 */
275static void *o2cb_dlm_lvb(union ocfs2_dlm_lksb *lksb)
276{
277 return (void *)(lksb->lksb_o2dlm.lvb);
278}
279
280void *ocfs2_dlm_lvb(union ocfs2_dlm_lksb *lksb) 68void *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
285static void o2cb_dlm_dump_lksb(union ocfs2_dlm_lksb *lksb)
286{
287 dlm_print_one_lock(lksb->lksb_o2dlm.lockid);
288} 71}
289 72
290void ocfs2_dlm_dump_lksb(union ocfs2_dlm_lksb *lksb) 73void 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 */
299static 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
309static 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
357out_free:
358 if (rc && conn->cc_private)
359 kfree(conn->cc_private);
360
361out:
362 return rc;
363} 76}
364 77
365int ocfs2_cluster_connect(const char *group, 78int 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
416static 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
431int ocfs2_cluster_disconnect(struct ocfs2_cluster_connection *conn) 128int 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
446static 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 */
478static void o2cb_cluster_hangup(const char *group, int grouplen)
479{
480 o2hb_stop(group);
481}
482
483void ocfs2_cluster_hangup(const char *group, int grouplen) 143void 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
491static 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
506int ocfs2_cluster_this_node(unsigned int *node) 151int 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
511void ocfs2_stack_glue_set_locking_protocol(struct ocfs2_locking_protocol *proto) 156void 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