Committer: Michael Beasley <mike@snafu.setup>
[mikesnafu-overlay.git] / fs / gfs2 / locking / nolock / main.c
blobd3b8ce6fbbe34aafd0f0045ad1091bd0704f9c44
1 /*
2 * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved.
3 * Copyright (C) 2004-2005 Red Hat, Inc. All rights reserved.
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 version 2.
8 */
10 #include <linux/module.h>
11 #include <linux/slab.h>
12 #include <linux/init.h>
13 #include <linux/types.h>
14 #include <linux/fs.h>
15 #include <linux/lm_interface.h>
17 struct nolock_lockspace {
18 unsigned int nl_lvb_size;
21 static const struct lm_lockops nolock_ops;
23 static int nolock_mount(char *table_name, char *host_data,
24 lm_callback_t cb, void *cb_data,
25 unsigned int min_lvb_size, int flags,
26 struct lm_lockstruct *lockstruct,
27 struct kobject *fskobj)
29 char *c;
30 unsigned int jid;
31 struct nolock_lockspace *nl;
33 c = strstr(host_data, "jid=");
34 if (!c)
35 jid = 0;
36 else {
37 c += 4;
38 sscanf(c, "%u", &jid);
41 nl = kzalloc(sizeof(struct nolock_lockspace), GFP_KERNEL);
42 if (!nl)
43 return -ENOMEM;
45 nl->nl_lvb_size = min_lvb_size;
47 lockstruct->ls_jid = jid;
48 lockstruct->ls_first = 1;
49 lockstruct->ls_lvb_size = min_lvb_size;
50 lockstruct->ls_lockspace = nl;
51 lockstruct->ls_ops = &nolock_ops;
52 lockstruct->ls_flags = LM_LSFLAG_LOCAL;
54 return 0;
57 static void nolock_others_may_mount(void *lockspace)
61 static void nolock_unmount(void *lockspace)
63 struct nolock_lockspace *nl = lockspace;
64 kfree(nl);
67 static void nolock_withdraw(void *lockspace)
71 /**
72 * nolock_get_lock - get a lm_lock_t given a descripton of the lock
73 * @lockspace: the lockspace the lock lives in
74 * @name: the name of the lock
75 * @lockp: return the lm_lock_t here
77 * Returns: 0 on success, -EXXX on failure
80 static int nolock_get_lock(void *lockspace, struct lm_lockname *name,
81 void **lockp)
83 *lockp = lockspace;
84 return 0;
87 /**
88 * nolock_put_lock - get rid of a lock structure
89 * @lock: the lock to throw away
93 static void nolock_put_lock(void *lock)
97 /**
98 * nolock_lock - acquire a lock
99 * @lock: the lock to manipulate
100 * @cur_state: the current state
101 * @req_state: the requested state
102 * @flags: modifier flags
104 * Returns: A bitmap of LM_OUT_*
107 static unsigned int nolock_lock(void *lock, unsigned int cur_state,
108 unsigned int req_state, unsigned int flags)
110 return req_state | LM_OUT_CACHEABLE;
114 * nolock_unlock - unlock a lock
115 * @lock: the lock to manipulate
116 * @cur_state: the current state
118 * Returns: 0
121 static unsigned int nolock_unlock(void *lock, unsigned int cur_state)
123 return 0;
126 static void nolock_cancel(void *lock)
131 * nolock_hold_lvb - hold on to a lock value block
132 * @lock: the lock the LVB is associated with
133 * @lvbp: return the lm_lvb_t here
135 * Returns: 0 on success, -EXXX on failure
138 static int nolock_hold_lvb(void *lock, char **lvbp)
140 struct nolock_lockspace *nl = lock;
141 int error = 0;
143 *lvbp = kzalloc(nl->nl_lvb_size, GFP_KERNEL);
144 if (!*lvbp)
145 error = -ENOMEM;
147 return error;
151 * nolock_unhold_lvb - release a LVB
152 * @lock: the lock the LVB is associated with
153 * @lvb: the lock value block
157 static void nolock_unhold_lvb(void *lock, char *lvb)
159 kfree(lvb);
162 static int nolock_plock_get(void *lockspace, struct lm_lockname *name,
163 struct file *file, struct file_lock *fl)
165 posix_test_lock(file, fl);
167 return 0;
170 static int nolock_plock(void *lockspace, struct lm_lockname *name,
171 struct file *file, int cmd, struct file_lock *fl)
173 int error;
174 error = posix_lock_file_wait(file, fl);
175 return error;
178 static int nolock_punlock(void *lockspace, struct lm_lockname *name,
179 struct file *file, struct file_lock *fl)
181 int error;
182 error = posix_lock_file_wait(file, fl);
183 return error;
186 static void nolock_recovery_done(void *lockspace, unsigned int jid,
187 unsigned int message)
191 static const struct lm_lockops nolock_ops = {
192 .lm_proto_name = "lock_nolock",
193 .lm_mount = nolock_mount,
194 .lm_others_may_mount = nolock_others_may_mount,
195 .lm_unmount = nolock_unmount,
196 .lm_withdraw = nolock_withdraw,
197 .lm_get_lock = nolock_get_lock,
198 .lm_put_lock = nolock_put_lock,
199 .lm_lock = nolock_lock,
200 .lm_unlock = nolock_unlock,
201 .lm_cancel = nolock_cancel,
202 .lm_hold_lvb = nolock_hold_lvb,
203 .lm_unhold_lvb = nolock_unhold_lvb,
204 .lm_plock_get = nolock_plock_get,
205 .lm_plock = nolock_plock,
206 .lm_punlock = nolock_punlock,
207 .lm_recovery_done = nolock_recovery_done,
208 .lm_owner = THIS_MODULE,
211 static int __init init_nolock(void)
213 int error;
215 error = gfs2_register_lockproto(&nolock_ops);
216 if (error) {
217 printk(KERN_WARNING
218 "lock_nolock: can't register protocol: %d\n", error);
219 return error;
222 printk(KERN_INFO
223 "Lock_Nolock (built %s %s) installed\n", __DATE__, __TIME__);
224 return 0;
227 static void __exit exit_nolock(void)
229 gfs2_unregister_lockproto(&nolock_ops);
232 module_init(init_nolock);
233 module_exit(exit_nolock);
235 MODULE_DESCRIPTION("GFS Nolock Locking Module");
236 MODULE_AUTHOR("Red Hat, Inc.");
237 MODULE_LICENSE("GPL");