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