]> Pileus Git - ~andy/linux/blob - fs/gfs2/locking/nolock/main.c
Merge branch 'master'
[~andy/linux] / fs / gfs2 / locking / nolock / main.c
1 /*
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
7  * of the GNU General Public License v.2.
8  */
9
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
20 struct nolock_lockspace {
21         unsigned int nl_lvb_size;
22 };
23
24 struct lm_lockops nolock_ops;
25
26 static int nolock_mount(char *table_name, char *host_data,
27                         lm_callback_t cb, lm_fsdata_t *fsdata,
28                         unsigned int min_lvb_size, int flags,
29                         struct lm_lockstruct *lockstruct,
30                         struct kobject *fskobj)
31 {
32         char *c;
33         unsigned int jid;
34         struct nolock_lockspace *nl;
35
36         /* If there is a "jid=" in the hostdata, return that jid.
37            Otherwise, return zero. */
38
39         c = strstr(host_data, "jid=");
40         if (!c)
41                 jid = 0;
42         else {
43                 c += 4;
44                 sscanf(c, "%u", &jid);
45         }
46
47         nl = kmalloc(sizeof(struct nolock_lockspace), GFP_KERNEL);
48         if (!nl)
49                 return -ENOMEM;
50
51         memset(nl, 0, sizeof(struct nolock_lockspace));
52         nl->nl_lvb_size = min_lvb_size;
53
54         lockstruct->ls_jid = jid;
55         lockstruct->ls_first = 1;
56         lockstruct->ls_lvb_size = min_lvb_size;
57         lockstruct->ls_lockspace = (lm_lockspace_t *)nl;
58         lockstruct->ls_ops = &nolock_ops;
59         lockstruct->ls_flags = LM_LSFLAG_LOCAL;
60
61         return 0;
62 }
63
64 static void nolock_others_may_mount(lm_lockspace_t *lockspace)
65 {
66 }
67
68 static void nolock_unmount(lm_lockspace_t *lockspace)
69 {
70         struct nolock_lockspace *nl = (struct nolock_lockspace *)lockspace;
71         kfree(nl);
72 }
73
74 static void nolock_withdraw(lm_lockspace_t *lockspace)
75 {
76 }
77
78 /**
79  * nolock_get_lock - get a lm_lock_t given a descripton of the lock
80  * @lockspace: the lockspace the lock lives in
81  * @name: the name of the lock
82  * @lockp: return the lm_lock_t here
83  *
84  * Returns: 0 on success, -EXXX on failure
85  */
86
87 static int nolock_get_lock(lm_lockspace_t *lockspace, struct lm_lockname *name,
88                            lm_lock_t **lockp)
89 {
90         *lockp = (lm_lock_t *)lockspace;
91         return 0;
92 }
93
94 /**
95  * nolock_put_lock - get rid of a lock structure
96  * @lock: the lock to throw away
97  *
98  */
99
100 static void nolock_put_lock(lm_lock_t *lock)
101 {
102 }
103
104 /**
105  * nolock_lock - acquire a lock
106  * @lock: the lock to manipulate
107  * @cur_state: the current state
108  * @req_state: the requested state
109  * @flags: modifier flags
110  *
111  * Returns: A bitmap of LM_OUT_*
112  */
113
114 static unsigned int nolock_lock(lm_lock_t *lock, unsigned int cur_state,
115                                 unsigned int req_state, unsigned int flags)
116 {
117         return req_state | LM_OUT_CACHEABLE;
118 }
119
120 /**
121  * nolock_unlock - unlock a lock
122  * @lock: the lock to manipulate
123  * @cur_state: the current state
124  *
125  * Returns: 0
126  */
127
128 static unsigned int nolock_unlock(lm_lock_t *lock, unsigned int cur_state)
129 {
130         return 0;
131 }
132
133 static void nolock_cancel(lm_lock_t *lock)
134 {
135 }
136
137 /**
138  * nolock_hold_lvb - hold on to a lock value block
139  * @lock: the lock the LVB is associated with
140  * @lvbp: return the lm_lvb_t here
141  *
142  * Returns: 0 on success, -EXXX on failure
143  */
144
145 static int nolock_hold_lvb(lm_lock_t *lock, char **lvbp)
146 {
147         struct nolock_lockspace *nl = (struct nolock_lockspace *)lock;
148         int error = 0;
149
150         *lvbp = kmalloc(nl->nl_lvb_size, GFP_KERNEL);
151         if (*lvbp)
152                 memset(*lvbp, 0, nl->nl_lvb_size);
153         else
154                 error = -ENOMEM;
155
156         return error;
157 }
158
159 /**
160  * nolock_unhold_lvb - release a LVB
161  * @lock: the lock the LVB is associated with
162  * @lvb: the lock value block
163  *
164  */
165
166 static void nolock_unhold_lvb(lm_lock_t *lock, char *lvb)
167 {
168         kfree(lvb);
169 }
170
171 /**
172  * nolock_sync_lvb - sync out the value of a lvb
173  * @lock: the lock the LVB is associated with
174  * @lvb: the lock value block
175  *
176  */
177
178 static void nolock_sync_lvb(lm_lock_t *lock, char *lvb)
179 {
180 }
181
182 static int nolock_plock_get(lm_lockspace_t *lockspace, struct lm_lockname *name,
183                             struct file *file, struct file_lock *fl)
184 {
185         struct file_lock *tmp;
186
187         lock_kernel();
188         tmp = posix_test_lock(file, fl);
189         fl->fl_type = F_UNLCK;
190         if (tmp)
191                 memcpy(fl, tmp, sizeof(struct file_lock));
192         unlock_kernel();
193
194         return 0;
195 }
196
197 static int nolock_plock(lm_lockspace_t *lockspace, struct lm_lockname *name,
198                         struct file *file, int cmd, struct file_lock *fl)
199 {
200         int error;
201         lock_kernel();
202         error = posix_lock_file_wait(file, fl);
203         unlock_kernel();
204         return error;
205 }
206
207 static int nolock_punlock(lm_lockspace_t *lockspace, struct lm_lockname *name,
208                           struct file *file, struct file_lock *fl)
209 {
210         int error;
211         lock_kernel();
212         error = posix_lock_file_wait(file, fl);
213         unlock_kernel();
214         return error;
215 }
216
217 static void nolock_recovery_done(lm_lockspace_t *lockspace, unsigned int jid,
218                                  unsigned int message)
219 {
220 }
221
222 struct lm_lockops nolock_ops = {
223         .lm_proto_name = "lock_nolock",
224         .lm_mount = nolock_mount,
225         .lm_others_may_mount = nolock_others_may_mount,
226         .lm_unmount = nolock_unmount,
227         .lm_withdraw = nolock_withdraw,
228         .lm_get_lock = nolock_get_lock,
229         .lm_put_lock = nolock_put_lock,
230         .lm_lock = nolock_lock,
231         .lm_unlock = nolock_unlock,
232         .lm_cancel = nolock_cancel,
233         .lm_hold_lvb = nolock_hold_lvb,
234         .lm_unhold_lvb = nolock_unhold_lvb,
235         .lm_sync_lvb = nolock_sync_lvb,
236         .lm_plock_get = nolock_plock_get,
237         .lm_plock = nolock_plock,
238         .lm_punlock = nolock_punlock,
239         .lm_recovery_done = nolock_recovery_done,
240         .lm_owner = THIS_MODULE,
241 };
242
243 int __init init_nolock(void)
244 {
245         int error;
246
247         error = gfs_register_lockproto(&nolock_ops);
248         if (error) {
249                 printk("lock_nolock: can't register protocol: %d\n", error);
250                 return error;
251         }
252
253         printk("Lock_Nolock (built %s %s) installed\n", __DATE__, __TIME__);
254         return 0;
255 }
256
257 void __exit exit_nolock(void)
258 {
259         gfs_unregister_lockproto(&nolock_ops);
260 }
261
262 module_init(init_nolock);
263 module_exit(exit_nolock);
264
265 MODULE_DESCRIPTION("GFS Nolock Locking Module");
266 MODULE_AUTHOR("Red Hat, Inc.");
267 MODULE_LICENSE("GPL");
268