1 /* -*- mode: c; c-basic-offset: 8; -*-
2 * vim: noexpandtab sw=8 ts=8 sts=0:
6 * Glue to the underlying cluster stack.
8 * Copyright (C) 2007 Oracle. All rights reserved.
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.
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.
24 #include <linux/types.h>
25 #include <linux/list.h>
26 #include <linux/dlmconstants.h>
28 #include "dlm/dlmapi.h"
31 * dlmconstants.h does not have a LOCAL flag. We hope to remove it
32 * some day, but right now we need it. Let's fake it. This value is larger
33 * than any flag in dlmconstants.h.
35 #define DLM_LKF_LOCAL 0x00100000
38 * This shadows DLM_LOCKSPACE_LEN in fs/dlm/dlm_internal.h. That probably
39 * wants to be in a public header.
41 #define GROUP_NAME_MAX 64
45 * ocfs2_protocol_version changes when ocfs2 does something different in
46 * its inter-node behavior. See dlmglue.c for more information.
48 struct ocfs2_protocol_version {
54 * The ocfs2_locking_protocol defines the handlers called on ocfs2's behalf.
56 struct ocfs2_locking_protocol {
57 struct ocfs2_protocol_version lp_max_version;
58 void (*lp_lock_ast)(void *astarg);
59 void (*lp_blocking_ast)(void *astarg, int level);
60 void (*lp_unlock_ast)(void *astarg, int error);
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
68 union ocfs2_dlm_lksb {
69 struct dlm_lockstatus lksb_o2dlm;
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.
77 struct ocfs2_cluster_connection {
78 char cc_name[GROUP_NAME_MAX];
80 struct ocfs2_protocol_version cc_version;
81 void (*cc_recovery_handler)(int node_num, void *recovery_data);
82 void *cc_recovery_data;
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.
92 struct ocfs2_stack_operations {
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
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
104 * ->connect() must not return until it is guaranteed that
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.
110 int (*connect)(struct ocfs2_cluster_connection *conn);
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.
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.
123 int (*disconnect)(struct ocfs2_cluster_connection *conn);
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.
131 void (*hangup)(const char *group, int grouplen);
134 * ->this_node() returns the cluster's unique identifier for the
137 int (*this_node)(unsigned int *node);
140 * Call the underlying dlm lock function. The ->dlm_lock()
141 * callback should convert the flags and mode as appropriate.
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.
147 int (*dlm_lock)(struct ocfs2_cluster_connection *conn,
149 union ocfs2_dlm_lksb *lksb,
152 unsigned int namelen,
156 * Call the underlying dlm unlock function. The ->dlm_unlock()
157 * function should convert the flags as appropriate.
159 * The unlock ast is not passed, as the stack will want to wrap
160 * it before calling stack->sp_proto->lp_unlock_ast().
162 int (*dlm_unlock)(struct ocfs2_cluster_connection *conn,
163 union ocfs2_dlm_lksb *lksb,
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.
173 int (*lock_status)(union ocfs2_dlm_lksb *lksb);
176 * Pull the lvb pointer off of the stack-specific lksb.
178 void *(*lock_lvb)(union ocfs2_dlm_lksb *lksb);
181 * This is an optoinal debugging hook. If provided, the
182 * stack can dump debugging information about this lock.
184 void (*dump_lksb)(union ocfs2_dlm_lksb *lksb);
187 int ocfs2_cluster_connect(const char *group,
189 void (*recovery_handler)(int node_num,
190 void *recovery_data),
192 struct ocfs2_cluster_connection **conn);
193 int ocfs2_cluster_disconnect(struct ocfs2_cluster_connection *conn);
194 void ocfs2_cluster_hangup(const char *group, int grouplen);
195 int ocfs2_cluster_this_node(unsigned int *node);
197 int ocfs2_dlm_lock(struct ocfs2_cluster_connection *conn,
199 union ocfs2_dlm_lksb *lksb,
202 unsigned int namelen,
204 int ocfs2_dlm_unlock(struct ocfs2_cluster_connection *conn,
205 union ocfs2_dlm_lksb *lksb,
209 int ocfs2_dlm_lock_status(union ocfs2_dlm_lksb *lksb);
210 void *ocfs2_dlm_lvb(union ocfs2_dlm_lksb *lksb);
211 void ocfs2_dlm_dump_lksb(union ocfs2_dlm_lksb *lksb);
213 void ocfs2_stack_glue_set_locking_protocol(struct ocfs2_locking_protocol *proto);
215 extern struct ocfs2_locking_protocol *stack_glue_lproto;
216 extern struct ocfs2_stack_operations o2cb_stack_ops;
217 #endif /* STACKGLUE_H */