2 * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved.
3 * Copyright (C) 2004-2006 Red Hat, Inc. All rights reserved.
5 * This copyrighted material is made available to anyone wishing to use,
6 * modify, copy, or redistribute it subject to the terms and conditions
7 * of the GNU General Public License version 2.
10 #ifndef __LM_INTERFACE_DOT_H__
11 #define __LM_INTERFACE_DOT_H__
14 * Opaque handles represent the lock module's lockspace structure, the lock
15 * module's lock structures, and GFS's file system (superblock) structure.
18 typedef void lm_lockspace_t;
19 typedef void lm_lock_t;
22 typedef void (*lm_callback_t) (struct gfs2_sbd *sdp, unsigned int type, void *data);
28 * GFS is asking to join the filesystem's lockspace, but it doesn't want to
29 * modify the filesystem. The lock module shouldn't assign a journal to the FS
30 * mount. It shouldn't send recovery callbacks to the FS mount. If the node
31 * dies or withdraws, all locks can be wiped immediately.
34 #define LM_MFLAG_SPECTATOR 0x00000001
40 * The lock_nolock module returns LM_LSFLAG_LOCAL to GFS, indicating that GFS
41 * can make single-node optimizations.
44 #define LM_LSFLAG_LOCAL 0x00000001
50 #define LM_TYPE_RESERVED 0x00
51 #define LM_TYPE_NONDISK 0x01
52 #define LM_TYPE_INODE 0x02
53 #define LM_TYPE_RGRP 0x03
54 #define LM_TYPE_META 0x04
55 #define LM_TYPE_IOPEN 0x05
56 #define LM_TYPE_FLOCK 0x06
57 #define LM_TYPE_PLOCK 0x07
58 #define LM_TYPE_QUOTA 0x08
59 #define LM_TYPE_JOURNAL 0x09
64 * SHARED is compatible with SHARED, not with DEFERRED or EX.
65 * DEFERRED is compatible with DEFERRED, not with SHARED or EX.
68 #define LM_ST_UNLOCKED 0
69 #define LM_ST_EXCLUSIVE 1
70 #define LM_ST_DEFERRED 2
71 #define LM_ST_SHARED 3
77 * Don't wait to acquire the lock if it can't be granted immediately.
80 * Send one blocking callback if TRY is set and the lock is not granted.
83 * GFS sets this flag on lock requests it makes while doing journal recovery.
84 * These special requests should not be blocked due to the recovery like
85 * ordinary locks would be.
88 * A SHARED request may also be granted in DEFERRED, or a DEFERRED request may
89 * also be granted in SHARED. The preferred state is whichever is compatible
90 * with other granted locks, or the specified state if no other locks exist.
93 * Override fairness considerations. Suppose a lock is held in a shared state
94 * and there is a pending request for the deferred state. A shared lock
95 * request with the priority flag would be allowed to bypass the deferred
96 * request and directly join the other shared lock. A shared lock request
97 * without the priority flag might be forced to wait until the deferred
98 * requested had acquired and released the lock.
101 #define LM_FLAG_TRY 0x00000001
102 #define LM_FLAG_TRY_1CB 0x00000002
103 #define LM_FLAG_NOEXP 0x00000004
104 #define LM_FLAG_ANY 0x00000008
105 #define LM_FLAG_PRIORITY 0x00000010
108 * lm_lock() and lm_async_cb return flags
111 * Masks the lower two bits of lock state in the returned value.
114 * The lock hasn't been released so GFS can continue to cache data for it.
117 * The lock request was canceled.
120 * The result of the request will be returned in an LM_CB_ASYNC callback.
123 #define LM_OUT_ST_MASK 0x00000003
124 #define LM_OUT_CACHEABLE 0x00000004
125 #define LM_OUT_CANCELED 0x00000008
126 #define LM_OUT_ASYNC 0x00000080
127 #define LM_OUT_ERROR 0x00000100
130 * lm_callback_t types
132 * LM_CB_NEED_E LM_CB_NEED_D LM_CB_NEED_S
133 * Blocking callback, a remote node is requesting the given lock in
134 * EXCLUSIVE, DEFERRED, or SHARED.
136 * LM_CB_NEED_RECOVERY
137 * The given journal needs to be recovered.
140 * Reduce the number of cached locks.
143 * The given lock has been granted.
146 #define LM_CB_NEED_E 257
147 #define LM_CB_NEED_D 258
148 #define LM_CB_NEED_S 259
149 #define LM_CB_NEED_RECOVERY 260
150 #define LM_CB_DROPLOCKS 261
151 #define LM_CB_ASYNC 262
154 * lm_recovery_done() messages
157 #define LM_RD_GAVEUP 308
158 #define LM_RD_SUCCESS 309
163 unsigned int ln_type;
166 #define lm_name_equal(name1, name2) \
167 (((name1)->ln_number == (name2)->ln_number) && \
168 ((name1)->ln_type == (name2)->ln_type)) \
171 struct lm_lockname lc_name;
175 struct lm_lockstruct;
178 char lm_proto_name[256];
184 int (*lm_mount) (char *table_name, char *host_data,
185 lm_callback_t cb, struct gfs2_sbd *sdp,
186 unsigned int min_lvb_size, int flags,
187 struct lm_lockstruct *lockstruct,
188 struct kobject *fskobj);
190 void (*lm_others_may_mount) (lm_lockspace_t *lockspace);
192 void (*lm_unmount) (lm_lockspace_t *lockspace);
194 void (*lm_withdraw) (lm_lockspace_t *lockspace);
197 * Lock oriented operations
200 int (*lm_get_lock) (lm_lockspace_t *lockspace,
201 struct lm_lockname *name, lm_lock_t **lockp);
203 void (*lm_put_lock) (lm_lock_t *lock);
205 unsigned int (*lm_lock) (lm_lock_t *lock, unsigned int cur_state,
206 unsigned int req_state, unsigned int flags);
208 unsigned int (*lm_unlock) (lm_lock_t *lock, unsigned int cur_state);
210 void (*lm_cancel) (lm_lock_t *lock);
212 int (*lm_hold_lvb) (lm_lock_t *lock, char **lvbp);
213 void (*lm_unhold_lvb) (lm_lock_t *lock, char *lvb);
216 * Posix Lock oriented operations
219 int (*lm_plock_get) (lm_lockspace_t *lockspace,
220 struct lm_lockname *name,
221 struct file *file, struct file_lock *fl);
223 int (*lm_plock) (lm_lockspace_t *lockspace,
224 struct lm_lockname *name,
225 struct file *file, int cmd, struct file_lock *fl);
227 int (*lm_punlock) (lm_lockspace_t *lockspace,
228 struct lm_lockname *name,
229 struct file *file, struct file_lock *fl);
232 * Client oriented operations
235 void (*lm_recovery_done) (lm_lockspace_t *lockspace, unsigned int jid,
236 unsigned int message);
238 struct module *lm_owner;
242 * lm_mount() return values
244 * ls_jid - the journal ID this node should use
245 * ls_first - this node is the first to mount the file system
246 * ls_lvb_size - size in bytes of lock value blocks
247 * ls_lockspace - lock module's context for this file system
248 * ls_ops - lock module's functions
249 * ls_flags - lock module features
252 struct lm_lockstruct {
254 unsigned int ls_first;
255 unsigned int ls_lvb_size;
256 lm_lockspace_t *ls_lockspace;
257 struct lm_lockops *ls_ops;
262 * Lock module bottom interface. A lock module makes itself available to GFS
263 * with these functions.
266 int gfs2_register_lockproto(struct lm_lockops *proto);
268 void gfs2_unregister_lockproto(struct lm_lockops *proto);
271 * Lock module top interface. GFS calls these functions when mounting or
272 * unmounting a file system.
275 int gfs2_mount_lockproto(char *proto_name, char *table_name, char *host_data,
276 lm_callback_t cb, struct gfs2_sbd *sdp,
277 unsigned int min_lvb_size, int flags,
278 struct lm_lockstruct *lockstruct,
279 struct kobject *fskobj);
281 void gfs2_unmount_lockproto(struct lm_lockstruct *lockstruct);
283 void gfs2_withdraw_lockproto(struct lm_lockstruct *lockstruct);
285 #endif /* __LM_INTERFACE_DOT_H__ */