blob: acfbc941f31950c87323928cd6d48d82082f2685 [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>
Fabio Massimo Di Nitto7d308592006-09-19 07:56:29 +020017#include <linux/lm_interface.h>
David Teigland29b79982006-01-16 16:52:38 +000018
19struct nolock_lockspace {
20 unsigned int nl_lvb_size;
21};
22
Steven Whitehouse9b47c112006-09-08 10:17:58 -040023static const struct lm_lockops nolock_ops;
David Teigland29b79982006-01-16 16:52:38 +000024
David Teigland29b79982006-01-16 16:52:38 +000025static int nolock_mount(char *table_name, char *host_data,
Steven Whitehouse9b47c112006-09-08 10:17:58 -040026 lm_callback_t cb, void *cb_data,
David Teigland29b79982006-01-16 16:52:38 +000027 unsigned int min_lvb_size, int flags,
David Teigland869d81d2006-01-17 08:47:12 +000028 struct lm_lockstruct *lockstruct,
29 struct kobject *fskobj)
David Teigland29b79982006-01-16 16:52:38 +000030{
31 char *c;
32 unsigned int jid;
33 struct nolock_lockspace *nl;
34
David Teigland29b79982006-01-16 16:52:38 +000035 c = strstr(host_data, "jid=");
36 if (!c)
37 jid = 0;
38 else {
39 c += 4;
40 sscanf(c, "%u", &jid);
41 }
42
Steven Whitehoused92a8d42006-02-27 10:57:14 -050043 nl = kzalloc(sizeof(struct nolock_lockspace), GFP_KERNEL);
David Teigland29b79982006-01-16 16:52:38 +000044 if (!nl)
45 return -ENOMEM;
46
David Teigland29b79982006-01-16 16:52:38 +000047 nl->nl_lvb_size = min_lvb_size;
48
49 lockstruct->ls_jid = jid;
50 lockstruct->ls_first = 1;
51 lockstruct->ls_lvb_size = min_lvb_size;
Steven Whitehouse9b47c112006-09-08 10:17:58 -040052 lockstruct->ls_lockspace = nl;
David Teigland29b79982006-01-16 16:52:38 +000053 lockstruct->ls_ops = &nolock_ops;
54 lockstruct->ls_flags = LM_LSFLAG_LOCAL;
55
56 return 0;
57}
58
Steven Whitehouse9b47c112006-09-08 10:17:58 -040059static void nolock_others_may_mount(void *lockspace)
David Teigland29b79982006-01-16 16:52:38 +000060{
61}
62
Steven Whitehouse9b47c112006-09-08 10:17:58 -040063static void nolock_unmount(void *lockspace)
David Teigland29b79982006-01-16 16:52:38 +000064{
Steven Whitehouse9b47c112006-09-08 10:17:58 -040065 struct nolock_lockspace *nl = lockspace;
David Teigland29b79982006-01-16 16:52:38 +000066 kfree(nl);
67}
68
Steven Whitehouse9b47c112006-09-08 10:17:58 -040069static void nolock_withdraw(void *lockspace)
David Teigland29b79982006-01-16 16:52:38 +000070{
71}
72
73/**
74 * nolock_get_lock - get a lm_lock_t given a descripton of the lock
75 * @lockspace: the lockspace the lock lives in
76 * @name: the name of the lock
77 * @lockp: return the lm_lock_t here
78 *
79 * Returns: 0 on success, -EXXX on failure
80 */
81
Steven Whitehouse9b47c112006-09-08 10:17:58 -040082static int nolock_get_lock(void *lockspace, struct lm_lockname *name,
83 void **lockp)
David Teigland29b79982006-01-16 16:52:38 +000084{
Steven Whitehouse9b47c112006-09-08 10:17:58 -040085 *lockp = lockspace;
David Teigland29b79982006-01-16 16:52:38 +000086 return 0;
87}
88
89/**
90 * nolock_put_lock - get rid of a lock structure
91 * @lock: the lock to throw away
92 *
93 */
94
Steven Whitehouse9b47c112006-09-08 10:17:58 -040095static void nolock_put_lock(void *lock)
David Teigland29b79982006-01-16 16:52:38 +000096{
97}
98
99/**
100 * nolock_lock - acquire a lock
101 * @lock: the lock to manipulate
102 * @cur_state: the current state
103 * @req_state: the requested state
104 * @flags: modifier flags
105 *
106 * Returns: A bitmap of LM_OUT_*
107 */
108
Steven Whitehouse9b47c112006-09-08 10:17:58 -0400109static unsigned int nolock_lock(void *lock, unsigned int cur_state,
David Teigland29b79982006-01-16 16:52:38 +0000110 unsigned int req_state, unsigned int flags)
111{
112 return req_state | LM_OUT_CACHEABLE;
113}
114
115/**
116 * nolock_unlock - unlock a lock
117 * @lock: the lock to manipulate
118 * @cur_state: the current state
119 *
120 * Returns: 0
121 */
122
Steven Whitehouse9b47c112006-09-08 10:17:58 -0400123static unsigned int nolock_unlock(void *lock, unsigned int cur_state)
David Teigland29b79982006-01-16 16:52:38 +0000124{
125 return 0;
126}
127
Steven Whitehouse9b47c112006-09-08 10:17:58 -0400128static void nolock_cancel(void *lock)
David Teigland29b79982006-01-16 16:52:38 +0000129{
130}
131
132/**
133 * nolock_hold_lvb - hold on to a lock value block
134 * @lock: the lock the LVB is associated with
135 * @lvbp: return the lm_lvb_t here
136 *
137 * Returns: 0 on success, -EXXX on failure
138 */
139
Steven Whitehouse9b47c112006-09-08 10:17:58 -0400140static int nolock_hold_lvb(void *lock, char **lvbp)
David Teigland29b79982006-01-16 16:52:38 +0000141{
Steven Whitehouse9b47c112006-09-08 10:17:58 -0400142 struct nolock_lockspace *nl = lock;
David Teigland29b79982006-01-16 16:52:38 +0000143 int error = 0;
144
Steven Whitehoused92a8d42006-02-27 10:57:14 -0500145 *lvbp = kzalloc(nl->nl_lvb_size, GFP_KERNEL);
146 if (!*lvbp)
David Teigland29b79982006-01-16 16:52:38 +0000147 error = -ENOMEM;
148
149 return error;
150}
151
152/**
153 * nolock_unhold_lvb - release a LVB
154 * @lock: the lock the LVB is associated with
155 * @lvb: the lock value block
156 *
157 */
158
Steven Whitehouse9b47c112006-09-08 10:17:58 -0400159static void nolock_unhold_lvb(void *lock, char *lvb)
David Teigland29b79982006-01-16 16:52:38 +0000160{
161 kfree(lvb);
162}
163
Steven Whitehouse9b47c112006-09-08 10:17:58 -0400164static int nolock_plock_get(void *lockspace, struct lm_lockname *name,
David Teigland29b79982006-01-16 16:52:38 +0000165 struct file *file, struct file_lock *fl)
166{
Steven Whitehouse8628de02006-03-31 16:48:41 -0500167 struct file_lock tmp;
168 int ret;
David Teigland29b79982006-01-16 16:52:38 +0000169
Steven Whitehouse8628de02006-03-31 16:48:41 -0500170 ret = posix_test_lock(file, fl, &tmp);
David Teigland29b79982006-01-16 16:52:38 +0000171 fl->fl_type = F_UNLCK;
Steven Whitehouse8628de02006-03-31 16:48:41 -0500172 if (ret)
173 memcpy(fl, &tmp, sizeof(struct file_lock));
David Teigland29b79982006-01-16 16:52:38 +0000174
175 return 0;
176}
177
Steven Whitehouse9b47c112006-09-08 10:17:58 -0400178static int nolock_plock(void *lockspace, struct lm_lockname *name,
David Teigland29b79982006-01-16 16:52:38 +0000179 struct file *file, int cmd, struct file_lock *fl)
180{
181 int error;
David Teigland29b79982006-01-16 16:52:38 +0000182 error = posix_lock_file_wait(file, fl);
David Teigland29b79982006-01-16 16:52:38 +0000183 return error;
184}
185
Steven Whitehouse9b47c112006-09-08 10:17:58 -0400186static int nolock_punlock(void *lockspace, struct lm_lockname *name,
David Teigland29b79982006-01-16 16:52:38 +0000187 struct file *file, struct file_lock *fl)
188{
189 int error;
David Teigland29b79982006-01-16 16:52:38 +0000190 error = posix_lock_file_wait(file, fl);
David Teigland29b79982006-01-16 16:52:38 +0000191 return error;
192}
193
Steven Whitehouse9b47c112006-09-08 10:17:58 -0400194static void nolock_recovery_done(void *lockspace, unsigned int jid,
David Teigland29b79982006-01-16 16:52:38 +0000195 unsigned int message)
196{
197}
198
Steven Whitehouse9b47c112006-09-08 10:17:58 -0400199static const struct lm_lockops nolock_ops = {
David Teigland29b79982006-01-16 16:52:38 +0000200 .lm_proto_name = "lock_nolock",
201 .lm_mount = nolock_mount,
202 .lm_others_may_mount = nolock_others_may_mount,
203 .lm_unmount = nolock_unmount,
204 .lm_withdraw = nolock_withdraw,
205 .lm_get_lock = nolock_get_lock,
206 .lm_put_lock = nolock_put_lock,
207 .lm_lock = nolock_lock,
208 .lm_unlock = nolock_unlock,
209 .lm_cancel = nolock_cancel,
210 .lm_hold_lvb = nolock_hold_lvb,
211 .lm_unhold_lvb = nolock_unhold_lvb,
David Teigland29b79982006-01-16 16:52:38 +0000212 .lm_plock_get = nolock_plock_get,
213 .lm_plock = nolock_plock,
214 .lm_punlock = nolock_punlock,
215 .lm_recovery_done = nolock_recovery_done,
216 .lm_owner = THIS_MODULE,
217};
218
Adrian Bunk08bc2db2006-04-28 10:59:12 -0400219static int __init init_nolock(void)
David Teigland29b79982006-01-16 16:52:38 +0000220{
221 int error;
222
David Teigland3120ec52006-08-04 13:14:50 -0500223 error = gfs2_register_lockproto(&nolock_ops);
David Teigland29b79982006-01-16 16:52:38 +0000224 if (error) {
Steven Whitehousef3828942006-02-27 12:07:05 -0500225 printk(KERN_WARNING
226 "lock_nolock: can't register protocol: %d\n", error);
David Teigland29b79982006-01-16 16:52:38 +0000227 return error;
228 }
229
Steven Whitehousef3828942006-02-27 12:07:05 -0500230 printk(KERN_INFO
231 "Lock_Nolock (built %s %s) installed\n", __DATE__, __TIME__);
David Teigland29b79982006-01-16 16:52:38 +0000232 return 0;
233}
234
Adrian Bunk08bc2db2006-04-28 10:59:12 -0400235static void __exit exit_nolock(void)
David Teigland29b79982006-01-16 16:52:38 +0000236{
David Teigland3120ec52006-08-04 13:14:50 -0500237 gfs2_unregister_lockproto(&nolock_ops);
David Teigland29b79982006-01-16 16:52:38 +0000238}
239
240module_init(init_nolock);
241module_exit(exit_nolock);
242
243MODULE_DESCRIPTION("GFS Nolock Locking Module");
244MODULE_AUTHOR("Red Hat, Inc.");
245MODULE_LICENSE("GPL");
246