Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

[GFS2] An update of the GFS2 lock modules

This brings the lock modules uptodate and removes the stray
.mod.c file which accidently got included in the last check in.

Signed-off-by: David Teigland <teigland@redhat.com>
Signed-off-by: Steven Whitehouse <swhiteho@redhat.com>

authored by

David Teigland and committed by
Steven Whitehouse
869d81df a8f2d647

+792 -490
+1 -1
fs/gfs2/locking/dlm/Makefile
··· 1 1 obj-$(CONFIG_GFS2_FS) += lock_dlm.o 2 - lock_dlm-y := lock.o main.o mount.o sysfs.o thread.o 2 + lock_dlm-y := lock.o main.o mount.o sysfs.o thread.o plock.o 3 3
+52 -52
fs/gfs2/locking/dlm/lock.c
··· 1 - /****************************************************************************** 2 - ******************************************************************************* 3 - ** 4 - ** Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. 5 - ** Copyright (C) 2004-2005 Red Hat, Inc. All rights reserved. 6 - ** 7 - ** This copyrighted material is made available to anyone wishing to use, 8 - ** modify, copy, or redistribute it subject to the terms and conditions 9 - ** of the GNU General Public License v.2. 10 - ** 11 - ******************************************************************************* 12 - ******************************************************************************/ 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 + */ 13 9 14 10 #include "lock_dlm.h" 15 11 ··· 34 38 struct gdlm_ls *ls = lp->ls; 35 39 36 40 if (!mode) { 37 - printk("lock_dlm: bast mode zero %x,%"PRIx64"\n", 41 + printk("lock_dlm: bast mode zero %x,%llx\n", 38 42 lp->lockname.ln_type, lp->lockname.ln_number); 39 43 return; 40 44 } ··· 71 75 return DLM_LOCK_CW; 72 76 case LM_ST_SHARED: 73 77 return DLM_LOCK_PR; 74 - default: 75 - GDLM_ASSERT(0, printk("unknown LM state %d\n", lmstate);); 76 78 } 79 + gdlm_assert(0, "unknown LM state %d", lmstate); 80 + return -1; 77 81 } 78 82 79 83 /* convert dlm lock-mode to gfs lock-state */ ··· 90 94 return LM_ST_DEFERRED; 91 95 case DLM_LOCK_PR: 92 96 return LM_ST_SHARED; 93 - default: 94 - GDLM_ASSERT(0, printk("unknown DLM mode %d\n", dlmmode);); 95 97 } 98 + gdlm_assert(0, "unknown DLM mode %d", dlmmode); 99 + return -1; 96 100 } 97 101 98 102 /* verify agreement with GFS on the current lock state, NB: DLM_LOCK_NL and ··· 102 106 { 103 107 int16_t cur = make_mode(cur_state); 104 108 if (lp->cur != DLM_LOCK_IV) 105 - GDLM_ASSERT(lp->cur == cur, printk("%d, %d\n", lp->cur, cur);); 109 + gdlm_assert(lp->cur == cur, "%d, %d", lp->cur, cur); 106 110 } 107 111 108 112 static inline unsigned int make_flags(struct gdlm_lock *lp, ··· 153 157 static inline void make_strname(struct lm_lockname *lockname, 154 158 struct gdlm_strname *str) 155 159 { 156 - sprintf(str->name, "%8x%16"PRIx64, lockname->ln_type, 160 + sprintf(str->name, "%8x%16llx", lockname->ln_type, 157 161 lockname->ln_number); 158 162 str->namelen = GDLM_STRNAME_BYTES; 159 163 } ··· 163 167 { 164 168 struct gdlm_lock *lp; 165 169 166 - lp = kmalloc(sizeof(struct gdlm_lock), GFP_KERNEL); 170 + lp = kzalloc(sizeof(struct gdlm_lock), GFP_KERNEL); 167 171 if (!lp) 168 172 return -ENOMEM; 169 173 170 - memset(lp, 0, sizeof(struct gdlm_lock)); 171 174 lp->lockname = *name; 172 175 lp->ls = ls; 173 176 lp->cur = DLM_LOCK_IV; ··· 197 202 list_del_init(&lp->blist); 198 203 if (!list_empty(&lp->delay_list)) 199 204 list_del_init(&lp->delay_list); 200 - GDLM_ASSERT(!list_empty(&lp->all_list),); 205 + gdlm_assert(!list_empty(&lp->all_list), 206 + "%x,%llx", lp->lockname.ln_type, lp->lockname.ln_number); 201 207 list_del_init(&lp->all_list); 202 208 ls->all_locks_count--; 203 209 spin_unlock(&ls->async_lock); ··· 223 227 gdlm_delete_lp((struct gdlm_lock *) lock); 224 228 } 225 229 226 - void gdlm_do_lock(struct gdlm_lock *lp, struct dlm_range *range) 230 + unsigned int gdlm_do_lock(struct gdlm_lock *lp, struct dlm_range *range) 227 231 { 228 232 struct gdlm_ls *ls = lp->ls; 229 233 struct gdlm_strname str; ··· 238 242 if (test_bit(DFL_BLOCK_LOCKS, &ls->flags) && 239 243 !test_bit(LFL_NOBLOCK, &lp->flags) && lp->req != DLM_LOCK_NL) { 240 244 gdlm_queue_delayed(lp); 241 - return; 245 + return LM_OUT_ASYNC; 242 246 } 243 247 244 248 /* ··· 252 256 253 257 set_bit(LFL_ACTIVE, &lp->flags); 254 258 255 - log_debug("lk %x,%"PRIx64" id %x %d,%d %x", lp->lockname.ln_type, 259 + log_debug("lk %x,%llx id %x %d,%d %x", lp->lockname.ln_type, 256 260 lp->lockname.ln_number, lp->lksb.sb_lkid, 257 261 lp->cur, lp->req, lp->lkf); 258 262 ··· 266 270 error = 0; 267 271 } 268 272 269 - GDLM_ASSERT(!error, 270 - printk("%s: num=%x,%"PRIx64" err=%d cur=%d req=%d lkf=%x\n", 271 - ls->fsname, lp->lockname.ln_type, 273 + if (error) { 274 + log_debug("%s: gdlm_lock %x,%llx err=%d cur=%d req=%d lkf=%x " 275 + "flags=%lx", ls->fsname, lp->lockname.ln_type, 272 276 lp->lockname.ln_number, error, lp->cur, lp->req, 273 - lp->lkf);); 277 + lp->lkf, lp->flags); 278 + return LM_OUT_ERROR; 279 + } 280 + return LM_OUT_ASYNC; 274 281 } 275 282 276 - void gdlm_do_unlock(struct gdlm_lock *lp) 283 + unsigned int gdlm_do_unlock(struct gdlm_lock *lp) 277 284 { 285 + struct gdlm_ls *ls = lp->ls; 278 286 unsigned int lkf = 0; 279 287 int error; 280 288 ··· 288 288 if (lp->lvb) 289 289 lkf = DLM_LKF_VALBLK; 290 290 291 - log_debug("un %x,%"PRIx64" %x %d %x", lp->lockname.ln_type, 291 + log_debug("un %x,%llx %x %d %x", lp->lockname.ln_type, 292 292 lp->lockname.ln_number, lp->lksb.sb_lkid, lp->cur, lkf); 293 293 294 - error = dlm_unlock(lp->ls->dlm_lockspace, lp->lksb.sb_lkid, lkf, 295 - NULL, lp); 294 + error = dlm_unlock(ls->dlm_lockspace, lp->lksb.sb_lkid, lkf, NULL, lp); 296 295 297 - GDLM_ASSERT(!error, 298 - printk("%s: error=%d num=%x,%"PRIx64" lkf=%x flags=%lx\n", 299 - lp->ls->fsname, error, lp->lockname.ln_type, 300 - lp->lockname.ln_number, lkf, lp->flags);); 296 + if (error) { 297 + log_debug("%s: gdlm_unlock %x,%llx err=%d cur=%d req=%d lkf=%x " 298 + "flags=%lx", ls->fsname, lp->lockname.ln_type, 299 + lp->lockname.ln_number, error, lp->cur, lp->req, 300 + lp->lkf, lp->flags); 301 + return LM_OUT_ERROR; 302 + } 303 + return LM_OUT_ASYNC; 301 304 } 302 305 303 306 unsigned int gdlm_lock(lm_lock_t *lock, unsigned int cur_state, ··· 316 313 lp->req = make_mode(req_state); 317 314 lp->lkf = make_flags(lp, flags, lp->cur, lp->req); 318 315 319 - gdlm_do_lock(lp, NULL); 320 - return LM_OUT_ASYNC; 316 + return gdlm_do_lock(lp, NULL); 321 317 } 322 318 323 319 unsigned int gdlm_unlock(lm_lock_t *lock, unsigned int cur_state) ··· 326 324 clear_bit(LFL_DLM_CANCEL, &lp->flags); 327 325 if (lp->cur == DLM_LOCK_IV) 328 326 return 0; 329 - gdlm_do_unlock(lp); 330 - return LM_OUT_ASYNC; 327 + return gdlm_do_unlock(lp); 331 328 } 332 329 333 330 void gdlm_cancel(lm_lock_t *lock) ··· 338 337 if (test_bit(LFL_DLM_CANCEL, &lp->flags)) 339 338 return; 340 339 341 - log_all("gdlm_cancel %x,%"PRIx64" flags %lx", 342 - lp->lockname.ln_type, lp->lockname.ln_number, lp->flags); 340 + log_info("gdlm_cancel %x,%llx flags %lx", 341 + lp->lockname.ln_type, lp->lockname.ln_number, lp->flags); 343 342 344 343 spin_lock(&ls->async_lock); 345 344 if (!list_empty(&lp->delay_list)) { ··· 357 356 358 357 if (!test_bit(LFL_ACTIVE, &lp->flags) || 359 358 test_bit(LFL_DLM_UNLOCK, &lp->flags)) { 360 - log_all("gdlm_cancel skip %x,%"PRIx64" flags %lx", 361 - lp->lockname.ln_type, lp->lockname.ln_number, 362 - lp->flags); 359 + log_info("gdlm_cancel skip %x,%llx flags %lx", 360 + lp->lockname.ln_type, lp->lockname.ln_number, 361 + lp->flags); 363 362 return; 364 363 } 365 364 ··· 371 370 error = dlm_unlock(ls->dlm_lockspace, lp->lksb.sb_lkid, DLM_LKF_CANCEL, 372 371 NULL, lp); 373 372 374 - log_all("gdlm_cancel rv %d %x,%"PRIx64" flags %lx", error, 375 - lp->lockname.ln_type, lp->lockname.ln_number, lp->flags); 373 + log_info("gdlm_cancel rv %d %x,%llx flags %lx", error, 374 + lp->lockname.ln_type, lp->lockname.ln_number, lp->flags); 376 375 377 376 if (error == -EBUSY) 378 377 clear_bit(LFL_DLM_CANCEL, &lp->flags); ··· 382 381 { 383 382 char *lvb; 384 383 385 - lvb = kmalloc(GDLM_LVB_SIZE, GFP_KERNEL); 384 + lvb = kzalloc(GDLM_LVB_SIZE, GFP_KERNEL); 386 385 if (!lvb) 387 386 return -ENOMEM; 388 - 389 - memset(lvb, 0, GDLM_LVB_SIZE); 390 387 391 388 lp->lksb.sb_lvbptr = lvb; 392 389 lp->lvb = lvb; ··· 447 448 { 448 449 struct gdlm_lock *lpn = lp->hold_null; 449 450 450 - GDLM_ASSERT(lpn,); 451 + gdlm_assert(lpn, "%x,%llx", 452 + lp->lockname.ln_type, lp->lockname.ln_number); 451 453 lpn->lksb.sb_lvbptr = NULL; 452 454 lpn->lvb = NULL; 453 455 set_bit(LFL_UNLOCK_DELETE, &lpn->flags);
+191
fs/gfs2/locking/dlm/lock_dlm.h
··· 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 + #ifndef LOCK_DLM_DOT_H 11 + #define LOCK_DLM_DOT_H 12 + 13 + #include <linux/module.h> 14 + #include <linux/slab.h> 15 + #include <linux/spinlock.h> 16 + #include <linux/module.h> 17 + #include <linux/types.h> 18 + #include <linux/string.h> 19 + #include <linux/list.h> 20 + #include <linux/socket.h> 21 + #include <linux/delay.h> 22 + #include <linux/kthread.h> 23 + #include <linux/kobject.h> 24 + #include <linux/fcntl.h> 25 + #include <linux/wait.h> 26 + #include <net/sock.h> 27 + 28 + #include <linux/dlm.h> 29 + #include "../../lm_interface.h" 30 + 31 + /* 32 + * Internally, we prefix things with gdlm_ and GDLM_ (for gfs-dlm) since a 33 + * prefix of lock_dlm_ gets awkward. Externally, GFS refers to this module 34 + * as "lock_dlm". 35 + */ 36 + 37 + #define GDLM_STRNAME_BYTES 24 38 + #define GDLM_LVB_SIZE 32 39 + #define GDLM_DROP_COUNT 50000 40 + #define GDLM_DROP_PERIOD 60 41 + #define GDLM_NAME_LEN 128 42 + 43 + /* GFS uses 12 bytes to identify a resource (32 bit type + 64 bit number). 44 + We sprintf these numbers into a 24 byte string of hex values to make them 45 + human-readable (to make debugging simpler.) */ 46 + 47 + struct gdlm_strname { 48 + unsigned char name[GDLM_STRNAME_BYTES]; 49 + unsigned short namelen; 50 + }; 51 + 52 + enum { 53 + DFL_BLOCK_LOCKS = 0, 54 + DFL_SPECTATOR = 1, 55 + DFL_WITHDRAW = 2, 56 + }; 57 + 58 + struct gdlm_ls { 59 + uint32_t id; 60 + int jid; 61 + int first; 62 + int first_done; 63 + unsigned long flags; 64 + struct kobject kobj; 65 + char clustername[GDLM_NAME_LEN]; 66 + char fsname[GDLM_NAME_LEN]; 67 + int fsflags; 68 + dlm_lockspace_t *dlm_lockspace; 69 + lm_callback_t fscb; 70 + lm_fsdata_t *fsdata; 71 + int recover_jid; 72 + int recover_jid_done; 73 + spinlock_t async_lock; 74 + struct list_head complete; 75 + struct list_head blocking; 76 + struct list_head delayed; 77 + struct list_head submit; 78 + struct list_head all_locks; 79 + uint32_t all_locks_count; 80 + wait_queue_head_t wait_control; 81 + struct task_struct *thread1; 82 + struct task_struct *thread2; 83 + wait_queue_head_t thread_wait; 84 + unsigned long drop_time; 85 + int drop_locks_count; 86 + int drop_locks_period; 87 + }; 88 + 89 + enum { 90 + LFL_NOBLOCK = 0, 91 + LFL_NOCACHE = 1, 92 + LFL_DLM_UNLOCK = 2, 93 + LFL_DLM_CANCEL = 3, 94 + LFL_SYNC_LVB = 4, 95 + LFL_FORCE_PROMOTE = 5, 96 + LFL_REREQUEST = 6, 97 + LFL_ACTIVE = 7, 98 + LFL_INLOCK = 8, 99 + LFL_CANCEL = 9, 100 + LFL_NOBAST = 10, 101 + LFL_HEADQUE = 11, 102 + LFL_UNLOCK_DELETE = 12, 103 + }; 104 + 105 + struct gdlm_lock { 106 + struct gdlm_ls *ls; 107 + struct lm_lockname lockname; 108 + char *lvb; 109 + struct dlm_lksb lksb; 110 + 111 + int16_t cur; 112 + int16_t req; 113 + int16_t prev_req; 114 + uint32_t lkf; /* dlm flags DLM_LKF_ */ 115 + unsigned long flags; /* lock_dlm flags LFL_ */ 116 + 117 + int bast_mode; /* protected by async_lock */ 118 + struct completion ast_wait; 119 + 120 + struct list_head clist; /* complete */ 121 + struct list_head blist; /* blocking */ 122 + struct list_head delay_list; /* delayed */ 123 + struct list_head all_list; /* all locks for the fs */ 124 + struct gdlm_lock *hold_null; /* NL lock for hold_lvb */ 125 + }; 126 + 127 + #define gdlm_assert(assertion, fmt, args...) \ 128 + do { \ 129 + if (unlikely(!(assertion))) { \ 130 + printk(KERN_EMERG "lock_dlm: fatal assertion failed \"%s\"\n" \ 131 + "lock_dlm: " fmt "\n", \ 132 + #assertion, ##args); \ 133 + BUG(); \ 134 + } \ 135 + } while (0) 136 + 137 + #define log_print(lev, fmt, arg...) printk(lev "lock_dlm: " fmt "\n" , ## arg) 138 + #define log_info(fmt, arg...) log_print(KERN_INFO , fmt , ## arg) 139 + #define log_error(fmt, arg...) log_print(KERN_ERR , fmt , ## arg) 140 + #ifdef LOCK_DLM_LOG_DEBUG 141 + #define log_debug(fmt, arg...) log_print(KERN_DEBUG , fmt , ## arg) 142 + #else 143 + #define log_debug(fmt, arg...) 144 + #endif 145 + 146 + /* sysfs.c */ 147 + 148 + int gdlm_sysfs_init(void); 149 + void gdlm_sysfs_exit(void); 150 + int gdlm_kobject_setup(struct gdlm_ls *, struct kobject *); 151 + void gdlm_kobject_release(struct gdlm_ls *); 152 + 153 + /* thread.c */ 154 + 155 + int gdlm_init_threads(struct gdlm_ls *); 156 + void gdlm_release_threads(struct gdlm_ls *); 157 + 158 + /* lock.c */ 159 + 160 + int16_t gdlm_make_lmstate(int16_t); 161 + void gdlm_queue_delayed(struct gdlm_lock *); 162 + void gdlm_submit_delayed(struct gdlm_ls *); 163 + int gdlm_release_all_locks(struct gdlm_ls *); 164 + int gdlm_create_lp(struct gdlm_ls *, struct lm_lockname *, struct gdlm_lock **); 165 + void gdlm_delete_lp(struct gdlm_lock *); 166 + int gdlm_add_lvb(struct gdlm_lock *); 167 + void gdlm_del_lvb(struct gdlm_lock *); 168 + unsigned int gdlm_do_lock(struct gdlm_lock *, struct dlm_range *); 169 + unsigned int gdlm_do_unlock(struct gdlm_lock *); 170 + 171 + int gdlm_get_lock(lm_lockspace_t *, struct lm_lockname *, lm_lock_t **); 172 + void gdlm_put_lock(lm_lock_t *); 173 + unsigned int gdlm_lock(lm_lock_t *, unsigned int, unsigned int, unsigned int); 174 + unsigned int gdlm_unlock(lm_lock_t *, unsigned int); 175 + void gdlm_cancel(lm_lock_t *); 176 + int gdlm_hold_lvb(lm_lock_t *, char **); 177 + void gdlm_unhold_lvb(lm_lock_t *, char *); 178 + void gdlm_sync_lvb(lm_lock_t *, char *); 179 + 180 + /* plock.c */ 181 + 182 + int gdlm_plock_init(void); 183 + void gdlm_plock_exit(void); 184 + int gdlm_plock(lm_lockspace_t *, struct lm_lockname *, struct file *, int, 185 + struct file_lock *); 186 + int gdlm_plock_get(lm_lockspace_t *, struct lm_lockname *, struct file *, 187 + struct file_lock *); 188 + int gdlm_punlock(lm_lockspace_t *, struct lm_lockname *, struct file *, 189 + struct file_lock *); 190 + #endif 191 +
+19 -15
fs/gfs2/locking/dlm/main.c
··· 1 - /****************************************************************************** 2 - ******************************************************************************* 3 - ** 4 - ** Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. 5 - ** Copyright (C) 2004-2005 Red Hat, Inc. All rights reserved. 6 - ** 7 - ** This copyrighted material is made available to anyone wishing to use, 8 - ** modify, copy, or redistribute it subject to the terms and conditions 9 - ** of the GNU General Public License v.2. 10 - ** 11 - ******************************************************************************* 12 - ******************************************************************************/ 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 + */ 13 9 14 10 #include <linux/init.h> 15 11 ··· 20 24 { 21 25 int error; 22 26 23 - error = lm_register_proto(&gdlm_ops); 27 + error = gfs_register_lockproto(&gdlm_ops); 24 28 if (error) { 25 29 printk("lock_dlm: can't register protocol: %d\n", error); 26 30 return error; ··· 28 32 29 33 error = gdlm_sysfs_init(); 30 34 if (error) { 31 - lm_unregister_proto(&gdlm_ops); 35 + gfs_unregister_lockproto(&gdlm_ops); 36 + return error; 37 + } 38 + 39 + error = gdlm_plock_init(); 40 + if (error) { 41 + gdlm_sysfs_exit(); 42 + gfs_unregister_lockproto(&gdlm_ops); 32 43 return error; 33 44 } 34 45 ··· 48 45 49 46 void __exit exit_lock_dlm(void) 50 47 { 51 - lm_unregister_proto(&gdlm_ops); 48 + gdlm_plock_exit(); 52 49 gdlm_sysfs_exit(); 50 + gfs_unregister_lockproto(&gdlm_ops); 53 51 } 54 52 55 53 module_init(init_lock_dlm);
+98 -91
fs/gfs2/locking/dlm/mount.c
··· 1 - /****************************************************************************** 2 - ******************************************************************************* 3 - ** 4 - ** Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. 5 - ** Copyright (C) 2004-2005 Red Hat, Inc. All rights reserved. 6 - ** 7 - ** This copyrighted material is made available to anyone wishing to use, 8 - ** modify, copy, or redistribute it subject to the terms and conditions 9 - ** of the GNU General Public License v.2. 10 - ** 11 - ******************************************************************************* 12 - ******************************************************************************/ 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 + */ 13 9 14 10 #include "lock_dlm.h" 15 11 ··· 20 24 struct gdlm_ls *ls; 21 25 char buf[256], *p; 22 26 23 - ls = kmalloc(sizeof(struct gdlm_ls), GFP_KERNEL); 27 + ls = kzalloc(sizeof(struct gdlm_ls), GFP_KERNEL); 24 28 if (!ls) 25 29 return NULL; 26 30 27 - memset(ls, 0, sizeof(struct gdlm_ls)); 28 - 29 31 ls->drop_locks_count = gdlm_drop_count; 30 32 ls->drop_locks_period = gdlm_drop_period; 31 - 32 33 ls->fscb = cb; 33 34 ls->fsdata = fsdata; 34 35 ls->fsflags = flags; 35 - 36 36 spin_lock_init(&ls->async_lock); 37 - 38 37 INIT_LIST_HEAD(&ls->complete); 39 38 INIT_LIST_HEAD(&ls->blocking); 40 39 INIT_LIST_HEAD(&ls->delayed); 41 40 INIT_LIST_HEAD(&ls->submit); 42 41 INIT_LIST_HEAD(&ls->all_locks); 43 - 44 42 init_waitqueue_head(&ls->thread_wait); 45 43 init_waitqueue_head(&ls->wait_control); 46 44 ls->thread1 = NULL; ··· 47 57 48 58 p = strstr(buf, ":"); 49 59 if (!p) { 50 - printk("lock_dlm: invalid table_name \"%s\"\n", table_name); 60 + log_info("invalid table_name \"%s\"", table_name); 51 61 kfree(ls); 52 62 return NULL; 53 63 } 54 64 *p = '\0'; 55 65 p++; 56 66 57 - strncpy(ls->clustername, buf, 128); 58 - strncpy(ls->fsname, p, 128); 67 + strncpy(ls->clustername, buf, GDLM_NAME_LEN); 68 + strncpy(ls->fsname, p, GDLM_NAME_LEN); 59 69 60 70 return ls; 71 + } 72 + 73 + static int make_args(struct gdlm_ls *ls, char *data_arg) 74 + { 75 + char data[256]; 76 + char *options, *x, *y; 77 + int error = 0; 78 + 79 + memset(data, 0, 256); 80 + strncpy(data, data_arg, 255); 81 + 82 + for (options = data; (x = strsep(&options, ":")); ) { 83 + if (!*x) 84 + continue; 85 + 86 + y = strchr(x, '='); 87 + if (y) 88 + *y++ = 0; 89 + 90 + if (!strcmp(x, "jid")) { 91 + if (!y) { 92 + log_error("need argument to jid"); 93 + error = -EINVAL; 94 + break; 95 + } 96 + sscanf(y, "%u", &ls->jid); 97 + 98 + } else if (!strcmp(x, "first")) { 99 + if (!y) { 100 + log_error("need argument to first"); 101 + error = -EINVAL; 102 + break; 103 + } 104 + sscanf(y, "%u", &ls->first); 105 + 106 + } else if (!strcmp(x, "id")) { 107 + if (!y) { 108 + log_error("need argument to id"); 109 + error = -EINVAL; 110 + break; 111 + } 112 + sscanf(y, "%u", &ls->id); 113 + 114 + } else { 115 + log_error("unkonwn option: %s", x); 116 + error = -EINVAL; 117 + break; 118 + } 119 + } 120 + 121 + return error; 61 122 } 62 123 63 124 static int gdlm_mount(char *table_name, char *host_data, 64 125 lm_callback_t cb, lm_fsdata_t *fsdata, 65 126 unsigned int min_lvb_size, int flags, 66 - struct lm_lockstruct *lockstruct) 127 + struct lm_lockstruct *lockstruct, 128 + struct kobject *fskobj) 67 129 { 68 130 struct gdlm_ls *ls; 69 131 int error = -ENOMEM; ··· 134 92 error = dlm_new_lockspace(ls->fsname, strlen(ls->fsname), 135 93 &ls->dlm_lockspace, 0, GDLM_LVB_SIZE); 136 94 if (error) { 137 - printk("lock_dlm: dlm_new_lockspace error %d\n", error); 95 + log_error("dlm_new_lockspace error %d", error); 138 96 goto out_thread; 139 97 } 140 98 141 - error = gdlm_kobject_setup(ls); 99 + error = gdlm_kobject_setup(ls, fskobj); 142 100 if (error) 143 101 goto out_dlm; 144 - kobject_uevent(&ls->kobj, KOBJ_MOUNT, NULL); 145 102 146 - /* Now we depend on userspace to notice the new mount, 147 - join the appropriate group, and do a write to our sysfs 148 - "mounted" or "terminate" file. Before the start, userspace 149 - must set "jid" and "first". */ 150 - 151 - error = wait_event_interruptible(ls->wait_control, 152 - test_bit(DFL_JOIN_DONE, &ls->flags)); 103 + error = make_args(ls, host_data); 153 104 if (error) 154 105 goto out_sysfs; 155 - 156 - if (test_bit(DFL_TERMINATE, &ls->flags)) { 157 - error = -ERESTARTSYS; 158 - goto out_sysfs; 159 - } 160 106 161 107 lockstruct->ls_jid = ls->jid; 162 108 lockstruct->ls_first = ls->first; ··· 173 143 174 144 log_debug("unmount flags %lx", ls->flags); 175 145 176 - if (test_bit(DFL_WITHDRAW, &ls->flags)) { 177 - gdlm_kobject_release(ls); 146 + /* FIXME: serialize unmount and withdraw in case they 147 + happen at once. Also, if unmount follows withdraw, 148 + wait for withdraw to finish. */ 149 + 150 + if (test_bit(DFL_WITHDRAW, &ls->flags)) 178 151 goto out; 179 - } 180 - 181 - kobject_uevent(&ls->kobj, KOBJ_UMOUNT, NULL); 182 - 183 - wait_event_interruptible(ls->wait_control, 184 - test_bit(DFL_LEAVE_DONE, &ls->flags)); 185 152 186 153 gdlm_kobject_release(ls); 187 154 dlm_release_lockspace(ls->dlm_lockspace, 2); 188 155 gdlm_release_threads(ls); 189 156 rv = gdlm_release_all_locks(ls); 190 157 if (rv) 191 - log_all("lm_dlm_unmount: %d stray locks freed", rv); 158 + log_info("gdlm_unmount: %d stray locks freed", rv); 192 159 out: 193 160 kfree(ls); 194 161 } ··· 194 167 unsigned int message) 195 168 { 196 169 struct gdlm_ls *ls = (struct gdlm_ls *) lockspace; 197 - ls->recover_done = jid; 170 + ls->recover_jid_done = jid; 198 171 kobject_uevent(&ls->kobj, KOBJ_CHANGE, NULL); 199 172 } 200 173 ··· 205 178 kobject_uevent(&ls->kobj, KOBJ_CHANGE, NULL); 206 179 } 207 180 181 + /* Userspace gets the offline uevent, blocks new gfs locks on 182 + other mounters, and lets us know (sets WITHDRAW flag). Then, 183 + userspace leaves the mount group while we leave the lockspace. */ 184 + 208 185 static void gdlm_withdraw(lm_lockspace_t *lockspace) 209 186 { 210 187 struct gdlm_ls *ls = (struct gdlm_ls *) lockspace; 211 - 212 - /* userspace suspends locking on all other members */ 213 188 214 189 kobject_uevent(&ls->kobj, KOBJ_OFFLINE, NULL); 215 190 ··· 221 192 dlm_release_lockspace(ls->dlm_lockspace, 2); 222 193 gdlm_release_threads(ls); 223 194 gdlm_release_all_locks(ls); 224 - 225 - kobject_uevent(&ls->kobj, KOBJ_UMOUNT, NULL); 226 - 227 - /* userspace leaves the mount group, we don't need to wait for 228 - that to complete */ 229 - } 230 - 231 - int gdlm_plock_get(lm_lockspace_t *lockspace, struct lm_lockname *name, 232 - struct file *file, struct file_lock *fl) 233 - { 234 - return -ENOSYS; 235 - } 236 - 237 - int gdlm_punlock(lm_lockspace_t *lockspace, struct lm_lockname *name, 238 - struct file *file, struct file_lock *fl) 239 - { 240 - return -ENOSYS; 241 - } 242 - 243 - int gdlm_plock(lm_lockspace_t *lockspace, struct lm_lockname *name, 244 - struct file *file, int cmd, struct file_lock *fl) 245 - { 246 - return -ENOSYS; 195 + gdlm_kobject_release(ls); 247 196 } 248 197 249 198 struct lm_lockops gdlm_ops = { 250 - lm_proto_name:"lock_dlm", 251 - lm_mount:gdlm_mount, 252 - lm_others_may_mount:gdlm_others_may_mount, 253 - lm_unmount:gdlm_unmount, 254 - lm_withdraw:gdlm_withdraw, 255 - lm_get_lock:gdlm_get_lock, 256 - lm_put_lock:gdlm_put_lock, 257 - lm_lock:gdlm_lock, 258 - lm_unlock:gdlm_unlock, 259 - lm_plock:gdlm_plock, 260 - lm_punlock:gdlm_punlock, 261 - lm_plock_get:gdlm_plock_get, 262 - lm_cancel:gdlm_cancel, 263 - lm_hold_lvb:gdlm_hold_lvb, 264 - lm_unhold_lvb:gdlm_unhold_lvb, 265 - lm_sync_lvb:gdlm_sync_lvb, 266 - lm_recovery_done:gdlm_recovery_done, 267 - lm_owner:THIS_MODULE, 199 + .lm_proto_name = "lock_dlm", 200 + .lm_mount = gdlm_mount, 201 + .lm_others_may_mount = gdlm_others_may_mount, 202 + .lm_unmount = gdlm_unmount, 203 + .lm_withdraw = gdlm_withdraw, 204 + .lm_get_lock = gdlm_get_lock, 205 + .lm_put_lock = gdlm_put_lock, 206 + .lm_lock = gdlm_lock, 207 + .lm_unlock = gdlm_unlock, 208 + .lm_plock = gdlm_plock, 209 + .lm_punlock = gdlm_punlock, 210 + .lm_plock_get = gdlm_plock_get, 211 + .lm_cancel = gdlm_cancel, 212 + .lm_hold_lvb = gdlm_hold_lvb, 213 + .lm_unhold_lvb = gdlm_unhold_lvb, 214 + .lm_sync_lvb = gdlm_sync_lvb, 215 + .lm_recovery_done = gdlm_recovery_done, 216 + .lm_owner = THIS_MODULE, 268 217 }; 269 218
+297
fs/gfs2/locking/dlm/plock.c
··· 1 + /* 2 + * Copyright (C) 2005 Red Hat, Inc. All rights reserved. 3 + * 4 + * This copyrighted material is made available to anyone wishing to use, 5 + * modify, copy, or redistribute it subject to the terms and conditions 6 + * of the GNU General Public License v.2. 7 + */ 8 + 9 + #include <linux/miscdevice.h> 10 + #include <linux/lock_dlm_plock.h> 11 + 12 + #include "lock_dlm.h" 13 + 14 + 15 + static spinlock_t ops_lock; 16 + static struct list_head send_list; 17 + static struct list_head recv_list; 18 + static wait_queue_head_t send_wq; 19 + static wait_queue_head_t recv_wq; 20 + 21 + struct plock_op { 22 + struct list_head list; 23 + int done; 24 + struct gdlm_plock_info info; 25 + }; 26 + 27 + static inline void set_version(struct gdlm_plock_info *info) 28 + { 29 + info->version[0] = GDLM_PLOCK_VERSION_MAJOR; 30 + info->version[1] = GDLM_PLOCK_VERSION_MINOR; 31 + info->version[2] = GDLM_PLOCK_VERSION_PATCH; 32 + } 33 + 34 + static int check_version(struct gdlm_plock_info *info) 35 + { 36 + if ((GDLM_PLOCK_VERSION_MAJOR != info->version[0]) || 37 + (GDLM_PLOCK_VERSION_MINOR < info->version[1])) { 38 + log_error("plock device version mismatch: " 39 + "kernel (%u.%u.%u), user (%u.%u.%u)", 40 + GDLM_PLOCK_VERSION_MAJOR, 41 + GDLM_PLOCK_VERSION_MINOR, 42 + GDLM_PLOCK_VERSION_PATCH, 43 + info->version[0], 44 + info->version[1], 45 + info->version[2]); 46 + return -EINVAL; 47 + } 48 + return 0; 49 + } 50 + 51 + static void send_op(struct plock_op *op) 52 + { 53 + set_version(&op->info); 54 + INIT_LIST_HEAD(&op->list); 55 + spin_lock(&ops_lock); 56 + list_add_tail(&op->list, &send_list); 57 + spin_unlock(&ops_lock); 58 + wake_up(&send_wq); 59 + } 60 + 61 + int gdlm_plock(lm_lockspace_t *lockspace, struct lm_lockname *name, 62 + struct file *file, int cmd, struct file_lock *fl) 63 + { 64 + struct gdlm_ls *ls = (struct gdlm_ls *) lockspace; 65 + struct plock_op *op; 66 + int rv; 67 + 68 + op = kzalloc(sizeof(*op), GFP_KERNEL); 69 + if (!op) 70 + return -ENOMEM; 71 + 72 + op->info.optype = GDLM_PLOCK_OP_LOCK; 73 + op->info.pid = (uint32_t) fl->fl_owner; 74 + op->info.ex = (fl->fl_type == F_WRLCK); 75 + op->info.wait = IS_SETLKW(cmd); 76 + op->info.fsid = ls->id; 77 + op->info.number = name->ln_number; 78 + op->info.start = fl->fl_start; 79 + op->info.end = fl->fl_end; 80 + 81 + send_op(op); 82 + wait_event(recv_wq, (op->done != 0)); 83 + 84 + spin_lock(&ops_lock); 85 + if (!list_empty(&op->list)) { 86 + printk("plock op on list\n"); 87 + list_del(&op->list); 88 + } 89 + spin_unlock(&ops_lock); 90 + 91 + rv = op->info.rv; 92 + 93 + if (!rv) { 94 + if (posix_lock_file_wait(file, fl) < 0) 95 + log_error("gdlm_plock: vfs lock error %x,%llx", 96 + name->ln_type, name->ln_number); 97 + } 98 + 99 + kfree(op); 100 + return rv; 101 + } 102 + 103 + int gdlm_punlock(lm_lockspace_t *lockspace, struct lm_lockname *name, 104 + struct file *file, struct file_lock *fl) 105 + { 106 + struct gdlm_ls *ls = (struct gdlm_ls *) lockspace; 107 + struct plock_op *op; 108 + int rv; 109 + 110 + op = kzalloc(sizeof(*op), GFP_KERNEL); 111 + if (!op) 112 + return -ENOMEM; 113 + 114 + if (posix_lock_file_wait(file, fl) < 0) 115 + log_error("gdlm_punlock: vfs unlock error %x,%llx", 116 + name->ln_type, name->ln_number); 117 + 118 + op->info.optype = GDLM_PLOCK_OP_UNLOCK; 119 + op->info.pid = (uint32_t) fl->fl_owner; 120 + op->info.fsid = ls->id; 121 + op->info.number = name->ln_number; 122 + op->info.start = fl->fl_start; 123 + op->info.end = fl->fl_end; 124 + 125 + send_op(op); 126 + wait_event(recv_wq, (op->done != 0)); 127 + 128 + spin_lock(&ops_lock); 129 + if (!list_empty(&op->list)) { 130 + printk("punlock op on list\n"); 131 + list_del(&op->list); 132 + } 133 + spin_unlock(&ops_lock); 134 + 135 + rv = op->info.rv; 136 + 137 + kfree(op); 138 + return rv; 139 + } 140 + 141 + int gdlm_plock_get(lm_lockspace_t *lockspace, struct lm_lockname *name, 142 + struct file *file, struct file_lock *fl) 143 + { 144 + struct gdlm_ls *ls = (struct gdlm_ls *) lockspace; 145 + struct plock_op *op; 146 + int rv; 147 + 148 + op = kzalloc(sizeof(*op), GFP_KERNEL); 149 + if (!op) 150 + return -ENOMEM; 151 + 152 + op->info.optype = GDLM_PLOCK_OP_GET; 153 + op->info.pid = (uint32_t) fl->fl_owner; 154 + op->info.ex = (fl->fl_type == F_WRLCK); 155 + op->info.fsid = ls->id; 156 + op->info.number = name->ln_number; 157 + op->info.start = fl->fl_start; 158 + op->info.end = fl->fl_end; 159 + 160 + send_op(op); 161 + wait_event(recv_wq, (op->done != 0)); 162 + 163 + spin_lock(&ops_lock); 164 + if (!list_empty(&op->list)) { 165 + printk("plock_get op on list\n"); 166 + list_del(&op->list); 167 + } 168 + spin_unlock(&ops_lock); 169 + 170 + rv = op->info.rv; 171 + 172 + if (rv == 0) 173 + fl->fl_type = F_UNLCK; 174 + else if (rv > 0) { 175 + fl->fl_type = (op->info.ex) ? F_WRLCK : F_RDLCK; 176 + fl->fl_pid = op->info.pid; 177 + fl->fl_start = op->info.start; 178 + fl->fl_end = op->info.end; 179 + } 180 + 181 + kfree(op); 182 + return rv; 183 + } 184 + 185 + /* a read copies out one plock request from the send list */ 186 + static ssize_t dev_read(struct file *file, char __user *u, size_t count, 187 + loff_t *ppos) 188 + { 189 + struct gdlm_plock_info info; 190 + struct plock_op *op = NULL; 191 + 192 + if (count < sizeof(info)) 193 + return -EINVAL; 194 + 195 + spin_lock(&ops_lock); 196 + if (!list_empty(&send_list)) { 197 + op = list_entry(send_list.next, struct plock_op, list); 198 + list_move(&op->list, &recv_list); 199 + memcpy(&info, &op->info, sizeof(info)); 200 + } 201 + spin_unlock(&ops_lock); 202 + 203 + if (!op) 204 + return -EAGAIN; 205 + 206 + if (copy_to_user(u, &info, sizeof(info))) 207 + return -EFAULT; 208 + return sizeof(info); 209 + } 210 + 211 + /* a write copies in one plock result that should match a plock_op 212 + on the recv list */ 213 + static ssize_t dev_write(struct file *file, const char __user *u, size_t count, 214 + loff_t *ppos) 215 + { 216 + struct gdlm_plock_info info; 217 + struct plock_op *op; 218 + int found = 0; 219 + 220 + if (count != sizeof(info)) 221 + return -EINVAL; 222 + 223 + if (copy_from_user(&info, u, sizeof(info))) 224 + return -EFAULT; 225 + 226 + if (check_version(&info)) 227 + return -EINVAL; 228 + 229 + spin_lock(&ops_lock); 230 + list_for_each_entry(op, &recv_list, list) { 231 + if (op->info.fsid == info.fsid && 232 + op->info.number == info.number) { 233 + list_del_init(&op->list); 234 + found = 1; 235 + op->done = 1; 236 + memcpy(&op->info, &info, sizeof(info)); 237 + break; 238 + } 239 + } 240 + spin_unlock(&ops_lock); 241 + 242 + if (found) 243 + wake_up(&recv_wq); 244 + else 245 + printk("gdlm dev_write no op %x %llx\n", info.fsid, 246 + info.number); 247 + return count; 248 + } 249 + 250 + static unsigned int dev_poll(struct file *file, poll_table *wait) 251 + { 252 + poll_wait(file, &send_wq, wait); 253 + 254 + spin_lock(&ops_lock); 255 + if (!list_empty(&send_list)) { 256 + spin_unlock(&ops_lock); 257 + return POLLIN | POLLRDNORM; 258 + } 259 + spin_unlock(&ops_lock); 260 + return 0; 261 + } 262 + 263 + static struct file_operations dev_fops = { 264 + .read = dev_read, 265 + .write = dev_write, 266 + .poll = dev_poll, 267 + .owner = THIS_MODULE 268 + }; 269 + 270 + static struct miscdevice plock_dev_misc = { 271 + .minor = MISC_DYNAMIC_MINOR, 272 + .name = GDLM_PLOCK_MISC_NAME, 273 + .fops = &dev_fops 274 + }; 275 + 276 + int gdlm_plock_init(void) 277 + { 278 + int rv; 279 + 280 + spin_lock_init(&ops_lock); 281 + INIT_LIST_HEAD(&send_list); 282 + INIT_LIST_HEAD(&recv_list); 283 + init_waitqueue_head(&send_wq); 284 + init_waitqueue_head(&recv_wq); 285 + 286 + rv = misc_register(&plock_dev_misc); 287 + if (rv) 288 + printk("gdlm_plock_init: misc_register failed %d", rv); 289 + return rv; 290 + } 291 + 292 + void gdlm_plock_exit(void) 293 + { 294 + if (misc_deregister(&plock_dev_misc) < 0) 295 + printk("gdlm_plock_exit: misc_deregister failed"); 296 + } 297 +
+53 -150
fs/gfs2/locking/dlm/sysfs.c
··· 1 - /****************************************************************************** 2 - ******************************************************************************* 3 - ** 4 - ** Copyright (C) 2005 Red Hat, Inc. All rights reserved. 5 - ** 6 - ** This copyrighted material is made available to anyone wishing to use, 7 - ** modify, copy, or redistribute it subject to the terms and conditions 8 - ** of the GNU General Public License v.2. 9 - ** 10 - ******************************************************************************* 11 - ******************************************************************************/ 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 + */ 12 9 13 10 #include <linux/ctype.h> 14 11 #include <linux/stat.h> 15 12 16 13 #include "lock_dlm.h" 17 14 18 - static ssize_t gdlm_block_show(struct gdlm_ls *ls, char *buf) 15 + extern struct lm_lockops gdlm_ops; 16 + 17 + static ssize_t proto_name_show(struct gdlm_ls *ls, char *buf) 18 + { 19 + return sprintf(buf, "%s\n", gdlm_ops.lm_proto_name); 20 + } 21 + 22 + static ssize_t block_show(struct gdlm_ls *ls, char *buf) 19 23 { 20 24 ssize_t ret; 21 25 int val = 0; ··· 30 26 return ret; 31 27 } 32 28 33 - static ssize_t gdlm_block_store(struct gdlm_ls *ls, const char *buf, size_t len) 29 + static ssize_t block_store(struct gdlm_ls *ls, const char *buf, size_t len) 34 30 { 35 31 ssize_t ret = len; 36 32 int val; ··· 47 43 return ret; 48 44 } 49 45 50 - static ssize_t gdlm_mounted_show(struct gdlm_ls *ls, char *buf) 51 - { 52 - ssize_t ret; 53 - int val = -2; 54 - 55 - if (test_bit(DFL_TERMINATE, &ls->flags)) 56 - val = -1; 57 - else if (test_bit(DFL_LEAVE_DONE, &ls->flags)) 58 - val = 0; 59 - else if (test_bit(DFL_JOIN_DONE, &ls->flags)) 60 - val = 1; 61 - ret = sprintf(buf, "%d\n", val); 62 - return ret; 63 - } 64 - 65 - static ssize_t gdlm_mounted_store(struct gdlm_ls *ls, const char *buf, size_t len) 66 - { 67 - ssize_t ret = len; 68 - int val; 69 - 70 - val = simple_strtol(buf, NULL, 0); 71 - 72 - if (val == 1) 73 - set_bit(DFL_JOIN_DONE, &ls->flags); 74 - else if (val == 0) 75 - set_bit(DFL_LEAVE_DONE, &ls->flags); 76 - else if (val == -1) { 77 - set_bit(DFL_TERMINATE, &ls->flags); 78 - set_bit(DFL_JOIN_DONE, &ls->flags); 79 - set_bit(DFL_LEAVE_DONE, &ls->flags); 80 - } else 81 - ret = -EINVAL; 82 - wake_up(&ls->wait_control); 83 - return ret; 84 - } 85 - 86 - static ssize_t gdlm_withdraw_show(struct gdlm_ls *ls, char *buf) 46 + static ssize_t withdraw_show(struct gdlm_ls *ls, char *buf) 87 47 { 88 48 ssize_t ret; 89 49 int val = 0; ··· 58 90 return ret; 59 91 } 60 92 61 - static ssize_t gdlm_withdraw_store(struct gdlm_ls *ls, const char *buf, size_t len) 93 + static ssize_t withdraw_store(struct gdlm_ls *ls, const char *buf, size_t len) 62 94 { 63 95 ssize_t ret = len; 64 96 int val; ··· 73 105 return ret; 74 106 } 75 107 76 - static ssize_t gdlm_jid_show(struct gdlm_ls *ls, char *buf) 108 + static ssize_t id_show(struct gdlm_ls *ls, char *buf) 77 109 { 78 - return sprintf(buf, "%u\n", ls->jid); 110 + return sprintf(buf, "%u\n", ls->id); 79 111 } 80 112 81 - static ssize_t gdlm_jid_store(struct gdlm_ls *ls, const char *buf, size_t len) 113 + static ssize_t jid_show(struct gdlm_ls *ls, char *buf) 82 114 { 83 - ls->jid = simple_strtol(buf, NULL, 0); 84 - return len; 115 + return sprintf(buf, "%d\n", ls->jid); 85 116 } 86 117 87 - static ssize_t gdlm_first_show(struct gdlm_ls *ls, char *buf) 118 + static ssize_t first_show(struct gdlm_ls *ls, char *buf) 88 119 { 89 - return sprintf(buf, "%u\n", ls->first); 120 + return sprintf(buf, "%d\n", ls->first); 90 121 } 91 122 92 - static ssize_t gdlm_first_store(struct gdlm_ls *ls, const char *buf, size_t len) 93 - { 94 - ls->first = simple_strtol(buf, NULL, 0); 95 - return len; 96 - } 97 - 98 - static ssize_t gdlm_first_done_show(struct gdlm_ls *ls, char *buf) 123 + static ssize_t first_done_show(struct gdlm_ls *ls, char *buf) 99 124 { 100 125 return sprintf(buf, "%d\n", ls->first_done); 101 126 } 102 127 103 - static ssize_t gdlm_recover_show(struct gdlm_ls *ls, char *buf) 128 + static ssize_t recover_show(struct gdlm_ls *ls, char *buf) 104 129 { 105 - return sprintf(buf, "%u\n", ls->recover_jid); 130 + return sprintf(buf, "%d\n", ls->recover_jid); 106 131 } 107 132 108 - static ssize_t gdlm_recover_store(struct gdlm_ls *ls, const char *buf, size_t len) 133 + static ssize_t recover_store(struct gdlm_ls *ls, const char *buf, size_t len) 109 134 { 110 135 ls->recover_jid = simple_strtol(buf, NULL, 0); 111 136 ls->fscb(ls->fsdata, LM_CB_NEED_RECOVERY, &ls->recover_jid); 112 137 return len; 113 138 } 114 139 115 - static ssize_t gdlm_recover_done_show(struct gdlm_ls *ls, char *buf) 140 + static ssize_t recover_done_show(struct gdlm_ls *ls, char *buf) 116 141 { 117 - ssize_t ret; 118 - ret = sprintf(buf, "%d\n", ls->recover_done); 119 - return ret; 120 - } 121 - 122 - static ssize_t gdlm_cluster_show(struct gdlm_ls *ls, char *buf) 123 - { 124 - ssize_t ret; 125 - ret = sprintf(buf, "%s\n", ls->clustername); 126 - return ret; 127 - } 128 - 129 - static ssize_t gdlm_options_show(struct gdlm_ls *ls, char *buf) 130 - { 131 - ssize_t ret = 0; 132 - 133 - if (ls->fsflags & LM_MFLAG_SPECTATOR) 134 - ret += sprintf(buf, "spectator "); 135 - 136 - return ret; 142 + return sprintf(buf, "%d\n", ls->recover_jid_done); 137 143 } 138 144 139 145 struct gdlm_attr { ··· 116 174 ssize_t (*store)(struct gdlm_ls *, const char *, size_t); 117 175 }; 118 176 119 - static struct gdlm_attr gdlm_attr_block = { 120 - .attr = {.name = "block", .mode = S_IRUGO | S_IWUSR}, 121 - .show = gdlm_block_show, 122 - .store = gdlm_block_store 123 - }; 177 + #define GDLM_ATTR(_name,_mode,_show,_store) \ 178 + static struct gdlm_attr gdlm_attr_##_name = __ATTR(_name,_mode,_show,_store) 124 179 125 - static struct gdlm_attr gdlm_attr_mounted = { 126 - .attr = {.name = "mounted", .mode = S_IRUGO | S_IWUSR}, 127 - .show = gdlm_mounted_show, 128 - .store = gdlm_mounted_store 129 - }; 130 - 131 - static struct gdlm_attr gdlm_attr_withdraw = { 132 - .attr = {.name = "withdraw", .mode = S_IRUGO | S_IWUSR}, 133 - .show = gdlm_withdraw_show, 134 - .store = gdlm_withdraw_store 135 - }; 136 - 137 - static struct gdlm_attr gdlm_attr_jid = { 138 - .attr = {.name = "jid", .mode = S_IRUGO | S_IWUSR}, 139 - .show = gdlm_jid_show, 140 - .store = gdlm_jid_store 141 - }; 142 - 143 - static struct gdlm_attr gdlm_attr_first = { 144 - .attr = {.name = "first", .mode = S_IRUGO | S_IWUSR}, 145 - .show = gdlm_first_show, 146 - .store = gdlm_first_store 147 - }; 148 - 149 - static struct gdlm_attr gdlm_attr_first_done = { 150 - .attr = {.name = "first_done", .mode = S_IRUGO}, 151 - .show = gdlm_first_done_show, 152 - }; 153 - 154 - static struct gdlm_attr gdlm_attr_recover = { 155 - .attr = {.name = "recover", .mode = S_IRUGO | S_IWUSR}, 156 - .show = gdlm_recover_show, 157 - .store = gdlm_recover_store 158 - }; 159 - 160 - static struct gdlm_attr gdlm_attr_recover_done = { 161 - .attr = {.name = "recover_done", .mode = S_IRUGO | S_IWUSR}, 162 - .show = gdlm_recover_done_show, 163 - }; 164 - 165 - static struct gdlm_attr gdlm_attr_cluster = { 166 - .attr = {.name = "cluster", .mode = S_IRUGO | S_IWUSR}, 167 - .show = gdlm_cluster_show, 168 - }; 169 - 170 - static struct gdlm_attr gdlm_attr_options = { 171 - .attr = {.name = "options", .mode = S_IRUGO | S_IWUSR}, 172 - .show = gdlm_options_show, 173 - }; 180 + GDLM_ATTR(proto_name, 0444, proto_name_show, NULL); 181 + GDLM_ATTR(block, 0644, block_show, block_store); 182 + GDLM_ATTR(withdraw, 0644, withdraw_show, withdraw_store); 183 + GDLM_ATTR(id, 0444, id_show, NULL); 184 + GDLM_ATTR(jid, 0444, jid_show, NULL); 185 + GDLM_ATTR(first, 0444, first_show, NULL); 186 + GDLM_ATTR(first_done, 0444, first_done_show, NULL); 187 + GDLM_ATTR(recover, 0644, recover_show, recover_store); 188 + GDLM_ATTR(recover_done, 0444, recover_done_show, NULL); 174 189 175 190 static struct attribute *gdlm_attrs[] = { 191 + &gdlm_attr_proto_name.attr, 176 192 &gdlm_attr_block.attr, 177 - &gdlm_attr_mounted.attr, 178 193 &gdlm_attr_withdraw.attr, 194 + &gdlm_attr_id.attr, 179 195 &gdlm_attr_jid.attr, 180 196 &gdlm_attr_first.attr, 181 197 &gdlm_attr_first_done.attr, 182 198 &gdlm_attr_recover.attr, 183 199 &gdlm_attr_recover_done.attr, 184 - &gdlm_attr_cluster.attr, 185 - &gdlm_attr_options.attr, 186 200 NULL, 187 201 }; 188 202 ··· 174 276 .ktype = &gdlm_ktype, 175 277 }; 176 278 177 - int gdlm_kobject_setup(struct gdlm_ls *ls) 279 + int gdlm_kobject_setup(struct gdlm_ls *ls, struct kobject *fskobj) 178 280 { 179 281 int error; 180 282 181 - error = kobject_set_name(&ls->kobj, "%s", ls->fsname); 182 - if (error) 283 + error = kobject_set_name(&ls->kobj, "%s", "lock_module"); 284 + if (error) { 285 + log_error("can't set kobj name %d", error); 183 286 return error; 287 + } 184 288 185 289 ls->kobj.kset = &gdlm_kset; 186 290 ls->kobj.ktype = &gdlm_ktype; 291 + ls->kobj.parent = fskobj; 187 292 188 293 error = kobject_register(&ls->kobj); 294 + if (error) 295 + log_error("can't register kobj %d", error); 189 296 190 - return 0; 297 + return error; 191 298 } 192 299 193 300 void gdlm_kobject_release(struct gdlm_ls *ls)
+29 -36
fs/gfs2/locking/dlm/thread.c
··· 1 - /****************************************************************************** 2 - ******************************************************************************* 3 - ** 4 - ** Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. 5 - ** Copyright (C) 2004-2005 Red Hat, Inc. All rights reserved. 6 - ** 7 - ** This copyrighted material is made available to anyone wishing to use, 8 - ** modify, copy, or redistribute it subject to the terms and conditions 9 - ** of the GNU General Public License v.2. 10 - ** 11 - ******************************************************************************* 12 - ******************************************************************************/ 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 + */ 13 9 14 10 #include "lock_dlm.h" 15 11 ··· 22 26 wake_up(&ls->thread_wait); 23 27 } 24 28 25 - static void process_submit(struct gdlm_lock *lp) 26 - { 27 - gdlm_do_lock(lp, NULL); 28 - } 29 - 30 29 static void process_blocking(struct gdlm_lock *lp, int bast_mode) 31 30 { 32 31 struct gdlm_ls *ls = lp->ls; 33 - unsigned int cb; 32 + unsigned int cb = 0; 34 33 35 34 switch (gdlm_make_lmstate(bast_mode)) { 36 35 case LM_ST_EXCLUSIVE: ··· 38 47 cb = LM_CB_NEED_S; 39 48 break; 40 49 default: 41 - GDLM_ASSERT(0, printk("unknown bast mode %u\n",lp->bast_mode);); 50 + gdlm_assert(0, "unknown bast mode %u", lp->bast_mode); 42 51 } 43 52 44 53 ls->fscb(ls->fsdata, cb, &lp->lockname); ··· 53 62 memset(&acb, 0, sizeof(acb)); 54 63 55 64 if (lp->lksb.sb_status == -DLM_ECANCEL) { 56 - log_all("complete dlm cancel %x,%"PRIx64" flags %lx", 57 - lp->lockname.ln_type, lp->lockname.ln_number, 58 - lp->flags); 65 + log_info("complete dlm cancel %x,%llx flags %lx", 66 + lp->lockname.ln_type, lp->lockname.ln_number, 67 + lp->flags); 59 68 60 69 lp->req = lp->cur; 61 70 acb.lc_ret |= LM_OUT_CANCELED; ··· 66 75 67 76 if (test_and_clear_bit(LFL_DLM_UNLOCK, &lp->flags)) { 68 77 if (lp->lksb.sb_status != -DLM_EUNLOCK) { 69 - log_all("unlock sb_status %d %x,%"PRIx64" flags %lx", 70 - lp->lksb.sb_status, lp->lockname.ln_type, 71 - lp->lockname.ln_number, lp->flags); 78 + log_info("unlock sb_status %d %x,%llx flags %lx", 79 + lp->lksb.sb_status, lp->lockname.ln_type, 80 + lp->lockname.ln_number, lp->flags); 72 81 return; 73 82 } 74 83 ··· 99 108 */ 100 109 101 110 if (test_and_clear_bit(LFL_CANCEL, &lp->flags)) { 102 - log_all("complete internal cancel %x,%"PRIx64"", 103 - lp->lockname.ln_type, lp->lockname.ln_number); 111 + log_info("complete internal cancel %x,%llx", 112 + lp->lockname.ln_type, lp->lockname.ln_number); 104 113 lp->req = lp->cur; 105 114 acb.lc_ret |= LM_OUT_CANCELED; 106 115 goto out; ··· 121 130 } 122 131 123 132 /* this could only happen with cancels I think */ 124 - log_all("ast sb_status %d %x,%"PRIx64" flags %lx", 125 - lp->lksb.sb_status, lp->lockname.ln_type, 126 - lp->lockname.ln_number, lp->flags); 133 + log_info("ast sb_status %d %x,%llx flags %lx", 134 + lp->lksb.sb_status, lp->lockname.ln_type, 135 + lp->lockname.ln_number, lp->flags); 127 136 return; 128 137 } 129 138 ··· 143 152 */ 144 153 145 154 if (test_and_clear_bit(LFL_REREQUEST, &lp->flags)) { 146 - GDLM_ASSERT(lp->req == DLM_LOCK_NL,); 147 - GDLM_ASSERT(lp->prev_req > DLM_LOCK_NL,); 155 + gdlm_assert(lp->req == DLM_LOCK_NL, "%x,%llx", 156 + lp->lockname.ln_type, lp->lockname.ln_number); 157 + gdlm_assert(lp->prev_req > DLM_LOCK_NL, "%x,%llx", 158 + lp->lockname.ln_type, lp->lockname.ln_number); 148 159 149 160 lp->cur = DLM_LOCK_NL; 150 161 lp->req = lp->prev_req; ··· 182 189 lp->lkf |= DLM_LKF_CONVERT; 183 190 lp->lkf &= ~DLM_LKF_CONVDEADLK; 184 191 185 - log_debug("rereq %x,%"PRIx64" id %x %d,%d", 192 + log_debug("rereq %x,%llx id %x %d,%d", 186 193 lp->lockname.ln_type, lp->lockname.ln_number, 187 194 lp->lksb.sb_lkid, lp->cur, lp->req); 188 195 ··· 308 315 process_blocking(lp, blocking); 309 316 310 317 else if (submit) 311 - process_submit(lp); 318 + gdlm_do_lock(lp, NULL); 312 319 313 320 if (drop) 314 321 ls->fscb(ls->fsdata, LM_CB_DROPLOCKS, NULL); ··· 327 334 p = kthread_run(gdlm_thread, ls, "lock_dlm1"); 328 335 error = IS_ERR(p); 329 336 if (error) { 330 - log_all("can't start lock_dlm1 thread %d", error); 337 + log_error("can't start lock_dlm1 thread %d", error); 331 338 return error; 332 339 } 333 340 ls->thread1 = p; ··· 335 342 p = kthread_run(gdlm_thread, ls, "lock_dlm2"); 336 343 error = IS_ERR(p); 337 344 if (error) { 338 - log_all("can't start lock_dlm2 thread %d", error); 345 + log_error("can't start lock_dlm2 thread %d", error); 339 346 kthread_stop(ls->thread1); 340 347 return error; 341 348 }
-44
fs/gfs2/locking/nolock/lock_nolock.mod.c
··· 1 - #include <linux/module.h> 2 - #include <linux/vermagic.h> 3 - #include <linux/compiler.h> 4 - 5 - MODULE_INFO(vermagic, VERMAGIC_STRING); 6 - 7 - #undef unix 8 - struct module __this_module 9 - __attribute__((section(".gnu.linkonce.this_module"))) = { 10 - .name = __stringify(KBUILD_MODNAME), 11 - .init = init_module, 12 - #ifdef CONFIG_MODULE_UNLOAD 13 - .exit = cleanup_module, 14 - #endif 15 - }; 16 - 17 - static const struct modversion_info ____versions[] 18 - __attribute_used__ 19 - __attribute__((section("__versions"))) = { 20 - { 0x316962fc, "struct_module" }, 21 - { 0x5a34a45c, "__kmalloc" }, 22 - { 0x724beef2, "malloc_sizes" }, 23 - { 0x3fa03a97, "memset" }, 24 - { 0xc16fe12d, "__memcpy" }, 25 - { 0xdd132261, "printk" }, 26 - { 0x859204af, "sscanf" }, 27 - { 0x3656bf5a, "lock_kernel" }, 28 - { 0x1e6d26a8, "strstr" }, 29 - { 0x41ede9df, "lm_register_proto" }, 30 - { 0xb1f975aa, "unlock_kernel" }, 31 - { 0x87b0b01f, "posix_lock_file_wait" }, 32 - { 0x75f29cfd, "kmem_cache_alloc" }, 33 - { 0x69384280, "lm_unregister_proto" }, 34 - { 0x37a0cba, "kfree" }, 35 - { 0x5d16bfe6, "posix_test_lock" }, 36 - }; 37 - 38 - static const char __module_depends[] 39 - __attribute_used__ 40 - __attribute__((section(".modinfo"))) = 41 - "depends=gfs2"; 42 - 43 - 44 - MODULE_INFO(srcversion, "123E446F965A386A0C017C4");
+12 -101
fs/gfs2/locking/nolock/main.c
··· 1 - /****************************************************************************** 2 - ******************************************************************************* 3 - ** 4 - ** Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. 5 - ** Copyright (C) 2004-2005 Red Hat, Inc. All rights reserved. 6 - ** 7 - ** This copyrighted material is made available to anyone wishing to use, 8 - ** modify, copy, or redistribute it subject to the terms and conditions 9 - ** of the GNU General Public License v.2. 10 - ** 11 - ******************************************************************************* 12 - ******************************************************************************/ 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 + */ 13 9 14 10 #include <linux/module.h> 15 11 #include <linux/slab.h> ··· 23 27 24 28 struct lm_lockops nolock_ops; 25 29 26 - /** 27 - * nolock_mount - mount a nolock lockspace 28 - * @table_name: the name of the space to mount 29 - * @host_data: host specific data 30 - * @cb: the callback 31 - * @fsdata: 32 - * @min_lvb_size: 33 - * @flags: 34 - * @lockstruct: the structure of crap to fill in 35 - * 36 - * Returns: 0 on success, -EXXX on failure 37 - */ 38 - 39 30 static int nolock_mount(char *table_name, char *host_data, 40 31 lm_callback_t cb, lm_fsdata_t *fsdata, 41 32 unsigned int min_lvb_size, int flags, 42 - struct lm_lockstruct *lockstruct) 33 + struct lm_lockstruct *lockstruct, 34 + struct kobject *fskobj) 43 35 { 44 36 char *c; 45 37 unsigned int jid; ··· 61 77 return 0; 62 78 } 63 79 64 - /** 65 - * nolock_others_may_mount - unmount a lock space 66 - * @lockspace: the lockspace to unmount 67 - * 68 - */ 69 - 70 80 static void nolock_others_may_mount(lm_lockspace_t *lockspace) 71 81 { 72 82 } 73 - 74 - /** 75 - * nolock_unmount - unmount a lock space 76 - * @lockspace: the lockspace to unmount 77 - * 78 - */ 79 83 80 84 static void nolock_unmount(lm_lockspace_t *lockspace) 81 85 { 82 86 struct nolock_lockspace *nl = (struct nolock_lockspace *)lockspace; 83 87 kfree(nl); 84 88 } 85 - 86 - /** 87 - * nolock_withdraw - withdraw from a lock space 88 - * @lockspace: the lockspace 89 - * 90 - */ 91 89 92 90 static void nolock_withdraw(lm_lockspace_t *lockspace) 93 91 { ··· 130 164 return 0; 131 165 } 132 166 133 - /** 134 - * nolock_cancel - cancel a request on a lock 135 - * @lock: the lock to cancel request for 136 - * 137 - */ 138 - 139 167 static void nolock_cancel(lm_lock_t *lock) 140 168 { 141 169 } ··· 179 219 { 180 220 } 181 221 182 - /** 183 - * nolock_plock_get - 184 - * @lockspace: the lockspace 185 - * @name: 186 - * @file: 187 - * @fl: 188 - * 189 - * Returns: errno 190 - */ 191 - 192 222 static int nolock_plock_get(lm_lockspace_t *lockspace, struct lm_lockname *name, 193 223 struct file *file, struct file_lock *fl) 194 224 { ··· 194 244 return 0; 195 245 } 196 246 197 - /** 198 - * nolock_plock - 199 - * @lockspace: the lockspace 200 - * @name: 201 - * @file: 202 - * @cmd: 203 - * @fl: 204 - * 205 - * Returns: errno 206 - */ 207 - 208 247 static int nolock_plock(lm_lockspace_t *lockspace, struct lm_lockname *name, 209 248 struct file *file, int cmd, struct file_lock *fl) 210 249 { ··· 204 265 return error; 205 266 } 206 267 207 - /** 208 - * nolock_punlock - 209 - * @lockspace: the lockspace 210 - * @name: 211 - * @file: 212 - * @fl: 213 - * 214 - * Returns: errno 215 - */ 216 - 217 268 static int nolock_punlock(lm_lockspace_t *lockspace, struct lm_lockname *name, 218 269 struct file *file, struct file_lock *fl) 219 270 { ··· 213 284 unlock_kernel(); 214 285 return error; 215 286 } 216 - 217 - /** 218 - * nolock_recovery_done - reset the expired locks for a given jid 219 - * @lockspace: the lockspace 220 - * @jid: the jid 221 - * 222 - */ 223 287 224 288 static void nolock_recovery_done(lm_lockspace_t *lockspace, unsigned int jid, 225 289 unsigned int message) ··· 240 318 .lm_owner = THIS_MODULE, 241 319 }; 242 320 243 - /** 244 - * init_nolock - Initialize the nolock module 245 - * 246 - * Returns: 0 on success, -EXXX on failure 247 - */ 248 - 249 321 int __init init_nolock(void) 250 322 { 251 323 int error; 252 324 253 - error = lm_register_proto(&nolock_ops); 325 + error = gfs_register_lockproto(&nolock_ops); 254 326 if (error) { 255 327 printk("lock_nolock: can't register protocol: %d\n", error); 256 328 return error; ··· 254 338 return 0; 255 339 } 256 340 257 - /** 258 - * exit_nolock - cleanup the nolock module 259 - * 260 - */ 261 - 262 341 void __exit exit_nolock(void) 263 342 { 264 - lm_unregister_proto(&nolock_ops); 343 + gfs_unregister_lockproto(&nolock_ops); 265 344 } 266 345 267 346 module_init(init_nolock);
+40
include/linux/lock_dlm_plock.h
··· 1 + /* 2 + * Copyright (C) 2005 Red Hat, Inc. All rights reserved. 3 + * 4 + * This copyrighted material is made available to anyone wishing to use, 5 + * modify, copy, or redistribute it subject to the terms and conditions 6 + * of the GNU General Public License v.2. 7 + */ 8 + 9 + #ifndef __LOCK_DLM_PLOCK_DOT_H__ 10 + #define __LOCK_DLM_PLOCK_DOT_H__ 11 + 12 + #define GDLM_PLOCK_MISC_NAME "lock_dlm_plock" 13 + 14 + #define GDLM_PLOCK_VERSION_MAJOR 1 15 + #define GDLM_PLOCK_VERSION_MINOR 0 16 + #define GDLM_PLOCK_VERSION_PATCH 0 17 + 18 + enum { 19 + GDLM_PLOCK_OP_LOCK = 1, 20 + GDLM_PLOCK_OP_UNLOCK, 21 + GDLM_PLOCK_OP_GET, 22 + }; 23 + 24 + struct gdlm_plock_info { 25 + __u32 version[3]; 26 + __u8 optype; 27 + __u8 ex; 28 + __u8 wait; 29 + __u8 pad; 30 + __u32 pid; 31 + __s32 nodeid; 32 + __s32 rv; 33 + __u32 fsid; 34 + __u64 number; 35 + __u64 start; 36 + __u64 end; 37 + }; 38 + 39 + #endif 40 +