1 /******************************************************************************
2 *******************************************************************************
4 ** Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved.
5 ** Copyright (C) 2004-2005 Red Hat, Inc. All rights reserved.
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.
11 *******************************************************************************
12 ******************************************************************************/
14 #include <linux/module.h>
15 #include <linux/slab.h>
16 #include <linux/module.h>
17 #include <linux/init.h>
18 #include <linux/types.h>
20 #include <linux/smp_lock.h>
22 #include "../../lm_interface.h"
24 struct nolock_lockspace {
25 unsigned int nl_lvb_size;
28 struct lm_lockops nolock_ops;
31 * nolock_mount - mount a nolock lockspace
32 * @table_name: the name of the space to mount
33 * @host_data: host specific data
38 * @lockstruct: the structure of crap to fill in
40 * Returns: 0 on success, -EXXX on failure
43 static int nolock_mount(char *table_name, char *host_data,
44 lm_callback_t cb, lm_fsdata_t *fsdata,
45 unsigned int min_lvb_size, int flags,
46 struct lm_lockstruct *lockstruct)
50 struct nolock_lockspace *nl;
52 /* If there is a "jid=" in the hostdata, return that jid.
53 Otherwise, return zero. */
55 c = strstr(host_data, "jid=");
60 sscanf(c, "%u", &jid);
63 nl = kmalloc(sizeof(struct nolock_lockspace), GFP_KERNEL);
67 memset(nl, 0, sizeof(struct nolock_lockspace));
68 nl->nl_lvb_size = min_lvb_size;
70 lockstruct->ls_jid = jid;
71 lockstruct->ls_first = 1;
72 lockstruct->ls_lvb_size = min_lvb_size;
73 lockstruct->ls_lockspace = (lm_lockspace_t *)nl;
74 lockstruct->ls_ops = &nolock_ops;
75 lockstruct->ls_flags = LM_LSFLAG_LOCAL;
81 * nolock_others_may_mount - unmount a lock space
82 * @lockspace: the lockspace to unmount
86 static void nolock_others_may_mount(lm_lockspace_t *lockspace)
91 * nolock_unmount - unmount a lock space
92 * @lockspace: the lockspace to unmount
96 static void nolock_unmount(lm_lockspace_t *lockspace)
98 struct nolock_lockspace *nl = (struct nolock_lockspace *)lockspace;
103 * nolock_withdraw - withdraw from a lock space
104 * @lockspace: the lockspace
108 static void nolock_withdraw(lm_lockspace_t *lockspace)
113 * nolock_get_lock - get a lm_lock_t given a descripton of the lock
114 * @lockspace: the lockspace the lock lives in
115 * @name: the name of the lock
116 * @lockp: return the lm_lock_t here
118 * Returns: 0 on success, -EXXX on failure
121 static int nolock_get_lock(lm_lockspace_t *lockspace, struct lm_lockname *name,
124 *lockp = (lm_lock_t *)lockspace;
129 * nolock_put_lock - get rid of a lock structure
130 * @lock: the lock to throw away
134 static void nolock_put_lock(lm_lock_t *lock)
139 * nolock_lock - acquire a lock
140 * @lock: the lock to manipulate
141 * @cur_state: the current state
142 * @req_state: the requested state
143 * @flags: modifier flags
145 * Returns: A bitmap of LM_OUT_*
148 static unsigned int nolock_lock(lm_lock_t *lock, unsigned int cur_state,
149 unsigned int req_state, unsigned int flags)
151 return req_state | LM_OUT_CACHEABLE;
155 * nolock_unlock - unlock a lock
156 * @lock: the lock to manipulate
157 * @cur_state: the current state
162 static unsigned int nolock_unlock(lm_lock_t *lock, unsigned int cur_state)
168 * nolock_cancel - cancel a request on a lock
169 * @lock: the lock to cancel request for
173 static void nolock_cancel(lm_lock_t *lock)
178 * nolock_hold_lvb - hold on to a lock value block
179 * @lock: the lock the LVB is associated with
180 * @lvbp: return the lm_lvb_t here
182 * Returns: 0 on success, -EXXX on failure
185 static int nolock_hold_lvb(lm_lock_t *lock, char **lvbp)
187 struct nolock_lockspace *nl = (struct nolock_lockspace *)lock;
190 *lvbp = kmalloc(nl->nl_lvb_size, GFP_KERNEL);
192 memset(*lvbp, 0, nl->nl_lvb_size);
200 * nolock_unhold_lvb - release a LVB
201 * @lock: the lock the LVB is associated with
202 * @lvb: the lock value block
206 static void nolock_unhold_lvb(lm_lock_t *lock, char *lvb)
212 * nolock_sync_lvb - sync out the value of a lvb
213 * @lock: the lock the LVB is associated with
214 * @lvb: the lock value block
218 static void nolock_sync_lvb(lm_lock_t *lock, char *lvb)
224 * @lockspace: the lockspace
232 static int nolock_plock_get(lm_lockspace_t *lockspace, struct lm_lockname *name,
233 struct file *file, struct file_lock *fl)
235 struct file_lock *tmp;
238 tmp = posix_test_lock(file, fl);
239 fl->fl_type = F_UNLCK;
241 memcpy(fl, tmp, sizeof(struct file_lock));
249 * @lockspace: the lockspace
258 static int nolock_plock(lm_lockspace_t *lockspace, struct lm_lockname *name,
259 struct file *file, int cmd, struct file_lock *fl)
263 error = posix_lock_file_wait(file, fl);
270 * @lockspace: the lockspace
278 static int nolock_punlock(lm_lockspace_t *lockspace, struct lm_lockname *name,
279 struct file *file, struct file_lock *fl)
283 error = posix_lock_file_wait(file, fl);
289 * nolock_recovery_done - reset the expired locks for a given jid
290 * @lockspace: the lockspace
295 static void nolock_recovery_done(lm_lockspace_t *lockspace, unsigned int jid,
296 unsigned int message)
300 struct lm_lockops nolock_ops = {
301 .lm_proto_name = "lock_nolock",
302 .lm_mount = nolock_mount,
303 .lm_others_may_mount = nolock_others_may_mount,
304 .lm_unmount = nolock_unmount,
305 .lm_withdraw = nolock_withdraw,
306 .lm_get_lock = nolock_get_lock,
307 .lm_put_lock = nolock_put_lock,
308 .lm_lock = nolock_lock,
309 .lm_unlock = nolock_unlock,
310 .lm_cancel = nolock_cancel,
311 .lm_hold_lvb = nolock_hold_lvb,
312 .lm_unhold_lvb = nolock_unhold_lvb,
313 .lm_sync_lvb = nolock_sync_lvb,
314 .lm_plock_get = nolock_plock_get,
315 .lm_plock = nolock_plock,
316 .lm_punlock = nolock_punlock,
317 .lm_recovery_done = nolock_recovery_done,
318 .lm_owner = THIS_MODULE,
322 * init_nolock - Initialize the nolock module
324 * Returns: 0 on success, -EXXX on failure
327 int __init init_nolock(void)
331 error = lm_register_proto(&nolock_ops);
333 printk("lock_nolock: can't register protocol: %d\n", error);
337 printk("Lock_Nolock (built %s %s) installed\n", __DATE__, __TIME__);
342 * exit_nolock - cleanup the nolock module
346 void __exit exit_nolock(void)
348 lm_unregister_proto(&nolock_ops);
351 module_init(init_nolock);
352 module_exit(exit_nolock);
354 MODULE_DESCRIPTION("GFS Nolock Locking Module");
355 MODULE_AUTHOR("Red Hat, Inc.");
356 MODULE_LICENSE("GPL");