blob: 7b263fc6c273724ae93d0b670f7f17f62e082e99 [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>
16#include <linux/smp_lock.h>
17
18#include "../../lm_interface.h"
19
20struct nolock_lockspace {
21 unsigned int nl_lvb_size;
22};
23
Steven Whitehouse9b47c112006-09-08 10:17:58 -040024static const struct lm_lockops nolock_ops;
David Teigland29b79982006-01-16 16:52:38 +000025
David Teigland29b79982006-01-16 16:52:38 +000026static int nolock_mount(char *table_name, char *host_data,
Steven Whitehouse9b47c112006-09-08 10:17:58 -040027 lm_callback_t cb, void *cb_data,
David Teigland29b79982006-01-16 16:52:38 +000028 unsigned int min_lvb_size, int flags,
David Teigland869d81d2006-01-17 08:47:12 +000029 struct lm_lockstruct *lockstruct,
30 struct kobject *fskobj)
David Teigland29b79982006-01-16 16:52:38 +000031{
32 char *c;
33 unsigned int jid;
34 struct nolock_lockspace *nl;
35
David Teigland29b79982006-01-16 16:52:38 +000036 c = strstr(host_data, "jid=");
37 if (!c)
38 jid = 0;
39 else {
40 c += 4;
41 sscanf(c, "%u", &jid);
42 }
43
Steven Whitehoused92a8d42006-02-27 10:57:14 -050044 nl = kzalloc(sizeof(struct nolock_lockspace), GFP_KERNEL);
David Teigland29b79982006-01-16 16:52:38 +000045 if (!nl)
46 return -ENOMEM;
47
David Teigland29b79982006-01-16 16:52:38 +000048 nl->nl_lvb_size = min_lvb_size;
49
50 lockstruct->ls_jid = jid;
51 lockstruct->ls_first = 1;
52 lockstruct->ls_lvb_size = min_lvb_size;
Steven Whitehouse9b47c112006-09-08 10:17:58 -040053 lockstruct->ls_lockspace = nl;
David Teigland29b79982006-01-16 16:52:38 +000054 lockstruct->ls_ops = &nolock_ops;
55 lockstruct->ls_flags = LM_LSFLAG_LOCAL;
56
57 return 0;
58}
59
Steven Whitehouse9b47c112006-09-08 10:17:58 -040060static void nolock_others_may_mount(void *lockspace)
David Teigland29b79982006-01-16 16:52:38 +000061{
62}
63
Steven Whitehouse9b47c112006-09-08 10:17:58 -040064static void nolock_unmount(void *lockspace)
David Teigland29b79982006-01-16 16:52:38 +000065{
Steven Whitehouse9b47c112006-09-08 10:17:58 -040066 struct nolock_lockspace *nl = lockspace;
David Teigland29b79982006-01-16 16:52:38 +000067 kfree(nl);
68}
69
Steven Whitehouse9b47c112006-09-08 10:17:58 -040070static void nolock_withdraw(void *lockspace)
David Teigland29b79982006-01-16 16:52:38 +000071{
72}
73
74/**
75 * nolock_get_lock - get a lm_lock_t given a descripton of the lock
76 * @lockspace: the lockspace the lock lives in
77 * @name: the name of the lock
78 * @lockp: return the lm_lock_t here
79 *
80 * Returns: 0 on success, -EXXX on failure
81 */
82
Steven Whitehouse9b47c112006-09-08 10:17:58 -040083static int nolock_get_lock(void *lockspace, struct lm_lockname *name,
84 void **lockp)
David Teigland29b79982006-01-16 16:52:38 +000085{
Steven Whitehouse9b47c112006-09-08 10:17:58 -040086 *lockp = lockspace;
David Teigland29b79982006-01-16 16:52:38 +000087 return 0;
88}
89
90/**
91 * nolock_put_lock - get rid of a lock structure
92 * @lock: the lock to throw away
93 *
94 */
95
Steven Whitehouse9b47c112006-09-08 10:17:58 -040096static void nolock_put_lock(void *lock)
David Teigland29b79982006-01-16 16:52:38 +000097{
98}
99
100/**
101 * nolock_lock - acquire a lock
102 * @lock: the lock to manipulate
103 * @cur_state: the current state
104 * @req_state: the requested state
105 * @flags: modifier flags
106 *
107 * Returns: A bitmap of LM_OUT_*
108 */
109
Steven Whitehouse9b47c112006-09-08 10:17:58 -0400110static unsigned int nolock_lock(void *lock, unsigned int cur_state,
David Teigland29b79982006-01-16 16:52:38 +0000111 unsigned int req_state, unsigned int flags)
112{
113 return req_state | LM_OUT_CACHEABLE;
114}
115
116/**
117 * nolock_unlock - unlock a lock
118 * @lock: the lock to manipulate
119 * @cur_state: the current state
120 *
121 * Returns: 0
122 */
123
Steven Whitehouse9b47c112006-09-08 10:17:58 -0400124static unsigned int nolock_unlock(void *lock, unsigned int cur_state)
David Teigland29b79982006-01-16 16:52:38 +0000125{
126 return 0;
127}
128
Steven Whitehouse9b47c112006-09-08 10:17:58 -0400129static void nolock_cancel(void *lock)
David Teigland29b79982006-01-16 16:52:38 +0000130{
131}
132
133/**
134 * nolock_hold_lvb - hold on to a lock value block
135 * @lock: the lock the LVB is associated with
136 * @lvbp: return the lm_lvb_t here
137 *
138 * Returns: 0 on success, -EXXX on failure
139 */
140
Steven Whitehouse9b47c112006-09-08 10:17:58 -0400141static int nolock_hold_lvb(void *lock, char **lvbp)
David Teigland29b79982006-01-16 16:52:38 +0000142{
Steven Whitehouse9b47c112006-09-08 10:17:58 -0400143 struct nolock_lockspace *nl = lock;
David Teigland29b79982006-01-16 16:52:38 +0000144 int error = 0;
145
Steven Whitehoused92a8d42006-02-27 10:57:14 -0500146 *lvbp = kzalloc(nl->nl_lvb_size, GFP_KERNEL);
147 if (!*lvbp)
David Teigland29b79982006-01-16 16:52:38 +0000148 error = -ENOMEM;
149
150 return error;
151}
152
153/**
154 * nolock_unhold_lvb - release a LVB
155 * @lock: the lock the LVB is associated with
156 * @lvb: the lock value block
157 *
158 */
159
Steven Whitehouse9b47c112006-09-08 10:17:58 -0400160static void nolock_unhold_lvb(void *lock, char *lvb)
David Teigland29b79982006-01-16 16:52:38 +0000161{
162 kfree(lvb);
163}
164
Steven Whitehouse9b47c112006-09-08 10:17:58 -0400165static int nolock_plock_get(void *lockspace, struct lm_lockname *name,
David Teigland29b79982006-01-16 16:52:38 +0000166 struct file *file, struct file_lock *fl)
167{
Steven Whitehouse8628de02006-03-31 16:48:41 -0500168 struct file_lock tmp;
169 int ret;
David Teigland29b79982006-01-16 16:52:38 +0000170
Steven Whitehouse8628de02006-03-31 16:48:41 -0500171 ret = posix_test_lock(file, fl, &tmp);
David Teigland29b79982006-01-16 16:52:38 +0000172 fl->fl_type = F_UNLCK;
Steven Whitehouse8628de02006-03-31 16:48:41 -0500173 if (ret)
174 memcpy(fl, &tmp, sizeof(struct file_lock));
David Teigland29b79982006-01-16 16:52:38 +0000175
176 return 0;
177}
178
Steven Whitehouse9b47c112006-09-08 10:17:58 -0400179static int nolock_plock(void *lockspace, struct lm_lockname *name,
David Teigland29b79982006-01-16 16:52:38 +0000180 struct file *file, int cmd, 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 int nolock_punlock(void *lockspace, struct lm_lockname *name,
David Teigland29b79982006-01-16 16:52:38 +0000188 struct file *file, struct file_lock *fl)
189{
190 int error;
David Teigland29b79982006-01-16 16:52:38 +0000191 error = posix_lock_file_wait(file, fl);
David Teigland29b79982006-01-16 16:52:38 +0000192 return error;
193}
194
Steven Whitehouse9b47c112006-09-08 10:17:58 -0400195static void nolock_recovery_done(void *lockspace, unsigned int jid,
David Teigland29b79982006-01-16 16:52:38 +0000196 unsigned int message)
197{
198}
199
Steven Whitehouse9b47c112006-09-08 10:17:58 -0400200static const struct lm_lockops nolock_ops = {
David Teigland29b79982006-01-16 16:52:38 +0000201 .lm_proto_name = "lock_nolock",
202 .lm_mount = nolock_mount,
203 .lm_others_may_mount = nolock_others_may_mount,
204 .lm_unmount = nolock_unmount,
205 .lm_withdraw = nolock_withdraw,
206 .lm_get_lock = nolock_get_lock,
207 .lm_put_lock = nolock_put_lock,
208 .lm_lock = nolock_lock,
209 .lm_unlock = nolock_unlock,
210 .lm_cancel = nolock_cancel,
211 .lm_hold_lvb = nolock_hold_lvb,
212 .lm_unhold_lvb = nolock_unhold_lvb,
David Teigland29b79982006-01-16 16:52:38 +0000213 .lm_plock_get = nolock_plock_get,
214 .lm_plock = nolock_plock,
215 .lm_punlock = nolock_punlock,
216 .lm_recovery_done = nolock_recovery_done,
217 .lm_owner = THIS_MODULE,
218};
219
Adrian Bunk08bc2db2006-04-28 10:59:12 -0400220static int __init init_nolock(void)
David Teigland29b79982006-01-16 16:52:38 +0000221{
222 int error;
223
David Teigland3120ec52006-08-04 13:14:50 -0500224 error = gfs2_register_lockproto(&nolock_ops);
David Teigland29b79982006-01-16 16:52:38 +0000225 if (error) {
Steven Whitehousef3828942006-02-27 12:07:05 -0500226 printk(KERN_WARNING
227 "lock_nolock: can't register protocol: %d\n", error);
David Teigland29b79982006-01-16 16:52:38 +0000228 return error;
229 }
230
Steven Whitehousef3828942006-02-27 12:07:05 -0500231 printk(KERN_INFO
232 "Lock_Nolock (built %s %s) installed\n", __DATE__, __TIME__);
David Teigland29b79982006-01-16 16:52:38 +0000233 return 0;
234}
235
Adrian Bunk08bc2db2006-04-28 10:59:12 -0400236static void __exit exit_nolock(void)
David Teigland29b79982006-01-16 16:52:38 +0000237{
David Teigland3120ec52006-08-04 13:14:50 -0500238 gfs2_unregister_lockproto(&nolock_ops);
David Teigland29b79982006-01-16 16:52:38 +0000239}
240
241module_init(init_nolock);
242module_exit(exit_nolock);
243
244MODULE_DESCRIPTION("GFS Nolock Locking Module");
245MODULE_AUTHOR("Red Hat, Inc.");
246MODULE_LICENSE("GPL");
247