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