David Teigland | 869d81d | 2006-01-17 08:47:12 +0000 | [diff] [blame] | 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 |
Steven Whitehouse | e9fc2aa | 2006-09-01 11:05:15 -0400 | [diff] [blame] | 7 | * of the GNU General Public License version 2. |
David Teigland | 869d81d | 2006-01-17 08:47:12 +0000 | [diff] [blame] | 8 | */ |
David Teigland | 29b7998 | 2006-01-16 16:52:38 +0000 | [diff] [blame] | 9 | |
| 10 | #include <linux/module.h> |
| 11 | #include <linux/slab.h> |
David Teigland | 29b7998 | 2006-01-16 16:52:38 +0000 | [diff] [blame] | 12 | #include <linux/init.h> |
| 13 | #include <linux/types.h> |
| 14 | #include <linux/fs.h> |
Fabio Massimo Di Nitto | 7d30859 | 2006-09-19 07:56:29 +0200 | [diff] [blame] | 15 | #include <linux/lm_interface.h> |
David Teigland | 29b7998 | 2006-01-16 16:52:38 +0000 | [diff] [blame] | 16 | |
| 17 | struct nolock_lockspace { |
| 18 | unsigned int nl_lvb_size; |
| 19 | }; |
| 20 | |
Steven Whitehouse | 9b47c11 | 2006-09-08 10:17:58 -0400 | [diff] [blame] | 21 | static const struct lm_lockops nolock_ops; |
David Teigland | 29b7998 | 2006-01-16 16:52:38 +0000 | [diff] [blame] | 22 | |
David Teigland | 29b7998 | 2006-01-16 16:52:38 +0000 | [diff] [blame] | 23 | static int nolock_mount(char *table_name, char *host_data, |
Steven Whitehouse | 9b47c11 | 2006-09-08 10:17:58 -0400 | [diff] [blame] | 24 | lm_callback_t cb, void *cb_data, |
David Teigland | 29b7998 | 2006-01-16 16:52:38 +0000 | [diff] [blame] | 25 | unsigned int min_lvb_size, int flags, |
David Teigland | 869d81d | 2006-01-17 08:47:12 +0000 | [diff] [blame] | 26 | struct lm_lockstruct *lockstruct, |
| 27 | struct kobject *fskobj) |
David Teigland | 29b7998 | 2006-01-16 16:52:38 +0000 | [diff] [blame] | 28 | { |
| 29 | char *c; |
| 30 | unsigned int jid; |
| 31 | struct nolock_lockspace *nl; |
| 32 | |
David Teigland | 29b7998 | 2006-01-16 16:52:38 +0000 | [diff] [blame] | 33 | c = strstr(host_data, "jid="); |
| 34 | if (!c) |
| 35 | jid = 0; |
| 36 | else { |
| 37 | c += 4; |
| 38 | sscanf(c, "%u", &jid); |
| 39 | } |
| 40 | |
Steven Whitehouse | d92a8d4 | 2006-02-27 10:57:14 -0500 | [diff] [blame] | 41 | nl = kzalloc(sizeof(struct nolock_lockspace), GFP_KERNEL); |
David Teigland | 29b7998 | 2006-01-16 16:52:38 +0000 | [diff] [blame] | 42 | if (!nl) |
| 43 | return -ENOMEM; |
| 44 | |
David Teigland | 29b7998 | 2006-01-16 16:52:38 +0000 | [diff] [blame] | 45 | nl->nl_lvb_size = min_lvb_size; |
| 46 | |
| 47 | lockstruct->ls_jid = jid; |
| 48 | lockstruct->ls_first = 1; |
| 49 | lockstruct->ls_lvb_size = min_lvb_size; |
Steven Whitehouse | 9b47c11 | 2006-09-08 10:17:58 -0400 | [diff] [blame] | 50 | lockstruct->ls_lockspace = nl; |
David Teigland | 29b7998 | 2006-01-16 16:52:38 +0000 | [diff] [blame] | 51 | lockstruct->ls_ops = &nolock_ops; |
| 52 | lockstruct->ls_flags = LM_LSFLAG_LOCAL; |
| 53 | |
| 54 | return 0; |
| 55 | } |
| 56 | |
Steven Whitehouse | 9b47c11 | 2006-09-08 10:17:58 -0400 | [diff] [blame] | 57 | static void nolock_others_may_mount(void *lockspace) |
David Teigland | 29b7998 | 2006-01-16 16:52:38 +0000 | [diff] [blame] | 58 | { |
| 59 | } |
| 60 | |
Steven Whitehouse | 9b47c11 | 2006-09-08 10:17:58 -0400 | [diff] [blame] | 61 | static void nolock_unmount(void *lockspace) |
David Teigland | 29b7998 | 2006-01-16 16:52:38 +0000 | [diff] [blame] | 62 | { |
Steven Whitehouse | 9b47c11 | 2006-09-08 10:17:58 -0400 | [diff] [blame] | 63 | struct nolock_lockspace *nl = lockspace; |
David Teigland | 29b7998 | 2006-01-16 16:52:38 +0000 | [diff] [blame] | 64 | kfree(nl); |
| 65 | } |
| 66 | |
Steven Whitehouse | 9b47c11 | 2006-09-08 10:17:58 -0400 | [diff] [blame] | 67 | static void nolock_withdraw(void *lockspace) |
David Teigland | 29b7998 | 2006-01-16 16:52:38 +0000 | [diff] [blame] | 68 | { |
| 69 | } |
| 70 | |
| 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 |
| 76 | * |
| 77 | * Returns: 0 on success, -EXXX on failure |
| 78 | */ |
| 79 | |
Steven Whitehouse | 9b47c11 | 2006-09-08 10:17:58 -0400 | [diff] [blame] | 80 | static int nolock_get_lock(void *lockspace, struct lm_lockname *name, |
| 81 | void **lockp) |
David Teigland | 29b7998 | 2006-01-16 16:52:38 +0000 | [diff] [blame] | 82 | { |
Steven Whitehouse | 9b47c11 | 2006-09-08 10:17:58 -0400 | [diff] [blame] | 83 | *lockp = lockspace; |
David Teigland | 29b7998 | 2006-01-16 16:52:38 +0000 | [diff] [blame] | 84 | return 0; |
| 85 | } |
| 86 | |
| 87 | /** |
| 88 | * nolock_put_lock - get rid of a lock structure |
| 89 | * @lock: the lock to throw away |
| 90 | * |
| 91 | */ |
| 92 | |
Steven Whitehouse | 9b47c11 | 2006-09-08 10:17:58 -0400 | [diff] [blame] | 93 | static void nolock_put_lock(void *lock) |
David Teigland | 29b7998 | 2006-01-16 16:52:38 +0000 | [diff] [blame] | 94 | { |
| 95 | } |
| 96 | |
| 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 |
| 103 | * |
| 104 | * Returns: A bitmap of LM_OUT_* |
| 105 | */ |
| 106 | |
Steven Whitehouse | 9b47c11 | 2006-09-08 10:17:58 -0400 | [diff] [blame] | 107 | static unsigned int nolock_lock(void *lock, unsigned int cur_state, |
David Teigland | 29b7998 | 2006-01-16 16:52:38 +0000 | [diff] [blame] | 108 | unsigned int req_state, unsigned int flags) |
| 109 | { |
| 110 | return req_state | LM_OUT_CACHEABLE; |
| 111 | } |
| 112 | |
| 113 | /** |
| 114 | * nolock_unlock - unlock a lock |
| 115 | * @lock: the lock to manipulate |
| 116 | * @cur_state: the current state |
| 117 | * |
| 118 | * Returns: 0 |
| 119 | */ |
| 120 | |
Steven Whitehouse | 9b47c11 | 2006-09-08 10:17:58 -0400 | [diff] [blame] | 121 | static unsigned int nolock_unlock(void *lock, unsigned int cur_state) |
David Teigland | 29b7998 | 2006-01-16 16:52:38 +0000 | [diff] [blame] | 122 | { |
| 123 | return 0; |
| 124 | } |
| 125 | |
Steven Whitehouse | 9b47c11 | 2006-09-08 10:17:58 -0400 | [diff] [blame] | 126 | static void nolock_cancel(void *lock) |
David Teigland | 29b7998 | 2006-01-16 16:52:38 +0000 | [diff] [blame] | 127 | { |
| 128 | } |
| 129 | |
| 130 | /** |
| 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 |
| 134 | * |
| 135 | * Returns: 0 on success, -EXXX on failure |
| 136 | */ |
| 137 | |
Steven Whitehouse | 9b47c11 | 2006-09-08 10:17:58 -0400 | [diff] [blame] | 138 | static int nolock_hold_lvb(void *lock, char **lvbp) |
David Teigland | 29b7998 | 2006-01-16 16:52:38 +0000 | [diff] [blame] | 139 | { |
Steven Whitehouse | 9b47c11 | 2006-09-08 10:17:58 -0400 | [diff] [blame] | 140 | struct nolock_lockspace *nl = lock; |
David Teigland | 29b7998 | 2006-01-16 16:52:38 +0000 | [diff] [blame] | 141 | int error = 0; |
| 142 | |
Josef Bacik | 16c5f06 | 2008-04-09 09:33:41 -0400 | [diff] [blame] | 143 | *lvbp = kzalloc(nl->nl_lvb_size, GFP_NOFS); |
Steven Whitehouse | d92a8d4 | 2006-02-27 10:57:14 -0500 | [diff] [blame] | 144 | if (!*lvbp) |
David Teigland | 29b7998 | 2006-01-16 16:52:38 +0000 | [diff] [blame] | 145 | error = -ENOMEM; |
| 146 | |
| 147 | return error; |
| 148 | } |
| 149 | |
| 150 | /** |
| 151 | * nolock_unhold_lvb - release a LVB |
| 152 | * @lock: the lock the LVB is associated with |
| 153 | * @lvb: the lock value block |
| 154 | * |
| 155 | */ |
| 156 | |
Steven Whitehouse | 9b47c11 | 2006-09-08 10:17:58 -0400 | [diff] [blame] | 157 | static void nolock_unhold_lvb(void *lock, char *lvb) |
David Teigland | 29b7998 | 2006-01-16 16:52:38 +0000 | [diff] [blame] | 158 | { |
| 159 | kfree(lvb); |
| 160 | } |
| 161 | |
Steven Whitehouse | 9b47c11 | 2006-09-08 10:17:58 -0400 | [diff] [blame] | 162 | static int nolock_plock_get(void *lockspace, struct lm_lockname *name, |
David Teigland | 29b7998 | 2006-01-16 16:52:38 +0000 | [diff] [blame] | 163 | struct file *file, struct file_lock *fl) |
| 164 | { |
Marc Eshel | 9d6a8c5 | 2007-02-21 00:55:18 -0500 | [diff] [blame] | 165 | posix_test_lock(file, fl); |
David Teigland | 29b7998 | 2006-01-16 16:52:38 +0000 | [diff] [blame] | 166 | |
| 167 | return 0; |
| 168 | } |
| 169 | |
Steven Whitehouse | 9b47c11 | 2006-09-08 10:17:58 -0400 | [diff] [blame] | 170 | static int nolock_plock(void *lockspace, struct lm_lockname *name, |
David Teigland | 29b7998 | 2006-01-16 16:52:38 +0000 | [diff] [blame] | 171 | struct file *file, int cmd, struct file_lock *fl) |
| 172 | { |
| 173 | int error; |
David Teigland | 29b7998 | 2006-01-16 16:52:38 +0000 | [diff] [blame] | 174 | error = posix_lock_file_wait(file, fl); |
David Teigland | 29b7998 | 2006-01-16 16:52:38 +0000 | [diff] [blame] | 175 | return error; |
| 176 | } |
| 177 | |
Steven Whitehouse | 9b47c11 | 2006-09-08 10:17:58 -0400 | [diff] [blame] | 178 | static int nolock_punlock(void *lockspace, struct lm_lockname *name, |
David Teigland | 29b7998 | 2006-01-16 16:52:38 +0000 | [diff] [blame] | 179 | struct file *file, struct file_lock *fl) |
| 180 | { |
| 181 | int error; |
David Teigland | 29b7998 | 2006-01-16 16:52:38 +0000 | [diff] [blame] | 182 | error = posix_lock_file_wait(file, fl); |
David Teigland | 29b7998 | 2006-01-16 16:52:38 +0000 | [diff] [blame] | 183 | return error; |
| 184 | } |
| 185 | |
Steven Whitehouse | 9b47c11 | 2006-09-08 10:17:58 -0400 | [diff] [blame] | 186 | static void nolock_recovery_done(void *lockspace, unsigned int jid, |
David Teigland | 29b7998 | 2006-01-16 16:52:38 +0000 | [diff] [blame] | 187 | unsigned int message) |
| 188 | { |
| 189 | } |
| 190 | |
Steven Whitehouse | 9b47c11 | 2006-09-08 10:17:58 -0400 | [diff] [blame] | 191 | static const struct lm_lockops nolock_ops = { |
David Teigland | 29b7998 | 2006-01-16 16:52:38 +0000 | [diff] [blame] | 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, |
David Teigland | 29b7998 | 2006-01-16 16:52:38 +0000 | [diff] [blame] | 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, |
| 209 | }; |
| 210 | |
Adrian Bunk | 08bc2db | 2006-04-28 10:59:12 -0400 | [diff] [blame] | 211 | static int __init init_nolock(void) |
David Teigland | 29b7998 | 2006-01-16 16:52:38 +0000 | [diff] [blame] | 212 | { |
| 213 | int error; |
| 214 | |
David Teigland | 3120ec5 | 2006-08-04 13:14:50 -0500 | [diff] [blame] | 215 | error = gfs2_register_lockproto(&nolock_ops); |
David Teigland | 29b7998 | 2006-01-16 16:52:38 +0000 | [diff] [blame] | 216 | if (error) { |
Steven Whitehouse | f382894 | 2006-02-27 12:07:05 -0500 | [diff] [blame] | 217 | printk(KERN_WARNING |
| 218 | "lock_nolock: can't register protocol: %d\n", error); |
David Teigland | 29b7998 | 2006-01-16 16:52:38 +0000 | [diff] [blame] | 219 | return error; |
| 220 | } |
| 221 | |
Steven Whitehouse | f382894 | 2006-02-27 12:07:05 -0500 | [diff] [blame] | 222 | printk(KERN_INFO |
| 223 | "Lock_Nolock (built %s %s) installed\n", __DATE__, __TIME__); |
David Teigland | 29b7998 | 2006-01-16 16:52:38 +0000 | [diff] [blame] | 224 | return 0; |
| 225 | } |
| 226 | |
Adrian Bunk | 08bc2db | 2006-04-28 10:59:12 -0400 | [diff] [blame] | 227 | static void __exit exit_nolock(void) |
David Teigland | 29b7998 | 2006-01-16 16:52:38 +0000 | [diff] [blame] | 228 | { |
David Teigland | 3120ec5 | 2006-08-04 13:14:50 -0500 | [diff] [blame] | 229 | gfs2_unregister_lockproto(&nolock_ops); |
David Teigland | 29b7998 | 2006-01-16 16:52:38 +0000 | [diff] [blame] | 230 | } |
| 231 | |
| 232 | module_init(init_nolock); |
| 233 | module_exit(exit_nolock); |
| 234 | |
| 235 | MODULE_DESCRIPTION("GFS Nolock Locking Module"); |
| 236 | MODULE_AUTHOR("Red Hat, Inc."); |
| 237 | MODULE_LICENSE("GPL"); |
| 238 | |