blob: 0d149c8c493a36ce1b9bb31593c5e9cfdb75465e [file] [log] [blame]
David Teigland869d81d2006-01-17 08:47:12 +00001/*
2 * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved.
3 * Copyright (C) 2004-2005 Red Hat, Inc. All rights reserved.
4 *
5 * This copyrighted material is made available to anyone wishing to use,
6 * modify, copy, or redistribute it subject to the terms and conditions
Steven Whitehousee9fc2aa2006-09-01 11:05:15 -04007 * of the GNU General Public License version 2.
David Teigland869d81d2006-01-17 08:47:12 +00008 */
David Teigland29b79982006-01-16 16:52:38 +00009
10#include <linux/module.h>
11#include <linux/slab.h>
12#include <linux/module.h>
13#include <linux/init.h>
14#include <linux/types.h>
15#include <linux/fs.h>
Fabio Massimo Di Nitto7d308592006-09-19 07:56:29 +020016#include <linux/lm_interface.h>
David Teigland29b79982006-01-16 16:52:38 +000017
18struct nolock_lockspace {
19 unsigned int nl_lvb_size;
20};
21
Steven Whitehouse9b47c112006-09-08 10:17:58 -040022static const struct lm_lockops nolock_ops;
David Teigland29b79982006-01-16 16:52:38 +000023
David Teigland29b79982006-01-16 16:52:38 +000024static int nolock_mount(char *table_name, char *host_data,
Steven Whitehouse9b47c112006-09-08 10:17:58 -040025 lm_callback_t cb, void *cb_data,
David Teigland29b79982006-01-16 16:52:38 +000026 unsigned int min_lvb_size, int flags,
David Teigland869d81d2006-01-17 08:47:12 +000027 struct lm_lockstruct *lockstruct,
28 struct kobject *fskobj)
David Teigland29b79982006-01-16 16:52:38 +000029{
30 char *c;
31 unsigned int jid;
32 struct nolock_lockspace *nl;
33
David Teigland29b79982006-01-16 16:52:38 +000034 c = strstr(host_data, "jid=");
35 if (!c)
36 jid = 0;
37 else {
38 c += 4;
39 sscanf(c, "%u", &jid);
40 }
41
Steven Whitehoused92a8d42006-02-27 10:57:14 -050042 nl = kzalloc(sizeof(struct nolock_lockspace), GFP_KERNEL);
David Teigland29b79982006-01-16 16:52:38 +000043 if (!nl)
44 return -ENOMEM;
45
David Teigland29b79982006-01-16 16:52:38 +000046 nl->nl_lvb_size = min_lvb_size;
47
48 lockstruct->ls_jid = jid;
49 lockstruct->ls_first = 1;
50 lockstruct->ls_lvb_size = min_lvb_size;
Steven Whitehouse9b47c112006-09-08 10:17:58 -040051 lockstruct->ls_lockspace = nl;
David Teigland29b79982006-01-16 16:52:38 +000052 lockstruct->ls_ops = &nolock_ops;
53 lockstruct->ls_flags = LM_LSFLAG_LOCAL;
54
55 return 0;
56}
57
Steven Whitehouse9b47c112006-09-08 10:17:58 -040058static void nolock_others_may_mount(void *lockspace)
David Teigland29b79982006-01-16 16:52:38 +000059{
60}
61
Steven Whitehouse9b47c112006-09-08 10:17:58 -040062static void nolock_unmount(void *lockspace)
David Teigland29b79982006-01-16 16:52:38 +000063{
Steven Whitehouse9b47c112006-09-08 10:17:58 -040064 struct nolock_lockspace *nl = lockspace;
David Teigland29b79982006-01-16 16:52:38 +000065 kfree(nl);
66}
67
Steven Whitehouse9b47c112006-09-08 10:17:58 -040068static void nolock_withdraw(void *lockspace)
David Teigland29b79982006-01-16 16:52:38 +000069{
70}
71
72/**
73 * nolock_get_lock - get a lm_lock_t given a descripton of the lock
74 * @lockspace: the lockspace the lock lives in
75 * @name: the name of the lock
76 * @lockp: return the lm_lock_t here
77 *
78 * Returns: 0 on success, -EXXX on failure
79 */
80
Steven Whitehouse9b47c112006-09-08 10:17:58 -040081static int nolock_get_lock(void *lockspace, struct lm_lockname *name,
82 void **lockp)
David Teigland29b79982006-01-16 16:52:38 +000083{
Steven Whitehouse9b47c112006-09-08 10:17:58 -040084 *lockp = lockspace;
David Teigland29b79982006-01-16 16:52:38 +000085 return 0;
86}
87
88/**
89 * nolock_put_lock - get rid of a lock structure
90 * @lock: the lock to throw away
91 *
92 */
93
Steven Whitehouse9b47c112006-09-08 10:17:58 -040094static void nolock_put_lock(void *lock)
David Teigland29b79982006-01-16 16:52:38 +000095{
96}
97
98/**
99 * nolock_lock - acquire a lock
100 * @lock: the lock to manipulate
101 * @cur_state: the current state
102 * @req_state: the requested state
103 * @flags: modifier flags
104 *
105 * Returns: A bitmap of LM_OUT_*
106 */
107
Steven Whitehouse9b47c112006-09-08 10:17:58 -0400108static unsigned int nolock_lock(void *lock, unsigned int cur_state,
David Teigland29b79982006-01-16 16:52:38 +0000109 unsigned int req_state, unsigned int flags)
110{
111 return req_state | LM_OUT_CACHEABLE;
112}
113
114/**
115 * nolock_unlock - unlock a lock
116 * @lock: the lock to manipulate
117 * @cur_state: the current state
118 *
119 * Returns: 0
120 */
121
Steven Whitehouse9b47c112006-09-08 10:17:58 -0400122static unsigned int nolock_unlock(void *lock, unsigned int cur_state)
David Teigland29b79982006-01-16 16:52:38 +0000123{
124 return 0;
125}
126
Steven Whitehouse9b47c112006-09-08 10:17:58 -0400127static void nolock_cancel(void *lock)
David Teigland29b79982006-01-16 16:52:38 +0000128{
129}
130
131/**
132 * nolock_hold_lvb - hold on to a lock value block
133 * @lock: the lock the LVB is associated with
134 * @lvbp: return the lm_lvb_t here
135 *
136 * Returns: 0 on success, -EXXX on failure
137 */
138
Steven Whitehouse9b47c112006-09-08 10:17:58 -0400139static int nolock_hold_lvb(void *lock, char **lvbp)
David Teigland29b79982006-01-16 16:52:38 +0000140{
Steven Whitehouse9b47c112006-09-08 10:17:58 -0400141 struct nolock_lockspace *nl = lock;
David Teigland29b79982006-01-16 16:52:38 +0000142 int error = 0;
143
Steven Whitehoused92a8d42006-02-27 10:57:14 -0500144 *lvbp = kzalloc(nl->nl_lvb_size, GFP_KERNEL);
145 if (!*lvbp)
David Teigland29b79982006-01-16 16:52:38 +0000146 error = -ENOMEM;
147
148 return error;
149}
150
151/**
152 * nolock_unhold_lvb - release a LVB
153 * @lock: the lock the LVB is associated with
154 * @lvb: the lock value block
155 *
156 */
157
Steven Whitehouse9b47c112006-09-08 10:17:58 -0400158static void nolock_unhold_lvb(void *lock, char *lvb)
David Teigland29b79982006-01-16 16:52:38 +0000159{
160 kfree(lvb);
161}
162
Steven Whitehouse9b47c112006-09-08 10:17:58 -0400163static int nolock_plock_get(void *lockspace, struct lm_lockname *name,
David Teigland29b79982006-01-16 16:52:38 +0000164 struct file *file, struct file_lock *fl)
165{
Marc Eshel9d6a8c52007-02-21 00:55:18 -0500166 posix_test_lock(file, fl);
David Teigland29b79982006-01-16 16:52:38 +0000167
168 return 0;
169}
170
Steven Whitehouse9b47c112006-09-08 10:17:58 -0400171static int nolock_plock(void *lockspace, struct lm_lockname *name,
David Teigland29b79982006-01-16 16:52:38 +0000172 struct file *file, int cmd, struct file_lock *fl)
173{
174 int error;
David Teigland29b79982006-01-16 16:52:38 +0000175 error = posix_lock_file_wait(file, fl);
David Teigland29b79982006-01-16 16:52:38 +0000176 return error;
177}
178
Steven Whitehouse9b47c112006-09-08 10:17:58 -0400179static int nolock_punlock(void *lockspace, struct lm_lockname *name,
David Teigland29b79982006-01-16 16:52:38 +0000180 struct file *file, struct file_lock *fl)
181{
182 int error;
David Teigland29b79982006-01-16 16:52:38 +0000183 error = posix_lock_file_wait(file, fl);
David Teigland29b79982006-01-16 16:52:38 +0000184 return error;
185}
186
Steven Whitehouse9b47c112006-09-08 10:17:58 -0400187static void nolock_recovery_done(void *lockspace, unsigned int jid,
David Teigland29b79982006-01-16 16:52:38 +0000188 unsigned int message)
189{
190}
191
Steven Whitehouse9b47c112006-09-08 10:17:58 -0400192static const struct lm_lockops nolock_ops = {
David Teigland29b79982006-01-16 16:52:38 +0000193 .lm_proto_name = "lock_nolock",
194 .lm_mount = nolock_mount,
195 .lm_others_may_mount = nolock_others_may_mount,
196 .lm_unmount = nolock_unmount,
197 .lm_withdraw = nolock_withdraw,
198 .lm_get_lock = nolock_get_lock,
199 .lm_put_lock = nolock_put_lock,
200 .lm_lock = nolock_lock,
201 .lm_unlock = nolock_unlock,
202 .lm_cancel = nolock_cancel,
203 .lm_hold_lvb = nolock_hold_lvb,
204 .lm_unhold_lvb = nolock_unhold_lvb,
David Teigland29b79982006-01-16 16:52:38 +0000205 .lm_plock_get = nolock_plock_get,
206 .lm_plock = nolock_plock,
207 .lm_punlock = nolock_punlock,
208 .lm_recovery_done = nolock_recovery_done,
209 .lm_owner = THIS_MODULE,
210};
211
Adrian Bunk08bc2db2006-04-28 10:59:12 -0400212static int __init init_nolock(void)
David Teigland29b79982006-01-16 16:52:38 +0000213{
214 int error;
215
David Teigland3120ec52006-08-04 13:14:50 -0500216 error = gfs2_register_lockproto(&nolock_ops);
David Teigland29b79982006-01-16 16:52:38 +0000217 if (error) {
Steven Whitehousef3828942006-02-27 12:07:05 -0500218 printk(KERN_WARNING
219 "lock_nolock: can't register protocol: %d\n", error);
David Teigland29b79982006-01-16 16:52:38 +0000220 return error;
221 }
222
Steven Whitehousef3828942006-02-27 12:07:05 -0500223 printk(KERN_INFO
224 "Lock_Nolock (built %s %s) installed\n", __DATE__, __TIME__);
David Teigland29b79982006-01-16 16:52:38 +0000225 return 0;
226}
227
Adrian Bunk08bc2db2006-04-28 10:59:12 -0400228static void __exit exit_nolock(void)
David Teigland29b79982006-01-16 16:52:38 +0000229{
David Teigland3120ec52006-08-04 13:14:50 -0500230 gfs2_unregister_lockproto(&nolock_ops);
David Teigland29b79982006-01-16 16:52:38 +0000231}
232
233module_init(init_nolock);
234module_exit(exit_nolock);
235
236MODULE_DESCRIPTION("GFS Nolock Locking Module");
237MODULE_AUTHOR("Red Hat, Inc.");
238MODULE_LICENSE("GPL");
239