aboutsummaryrefslogtreecommitdiffstats
path: root/fs/dlm/device.c
diff options
context:
space:
mode:
authorDavid Teigland <teigland@redhat.com>2006-01-20 03:47:07 -0500
committerSteven Whitehouse <steve@chygwyn.com>2006-01-20 03:47:07 -0500
commit901359256b2666f52a3a7d3f31927677e91b3a2a (patch)
tree24d4ee2c1ad63a0e6c3a303ad67eac3342772c4f /fs/dlm/device.c
parentec5800246607183a1d7fd0bae5f087c12439e9e7 (diff)
[DLM] Update DLM to the latest patch level
Signed-off-by: David Teigland <teigland@redhat.com> Signed-off-by: Steve Whitehouse <swhiteho@redhat.com>
Diffstat (limited to 'fs/dlm/device.c')
-rw-r--r--fs/dlm/device.c55
1 files changed, 33 insertions, 22 deletions
diff --git a/fs/dlm/device.c b/fs/dlm/device.c
index a8bf600ed13d..899d4f92a4d7 100644
--- a/fs/dlm/device.c
+++ b/fs/dlm/device.c
@@ -43,7 +43,7 @@
43static struct file_operations _dlm_fops; 43static struct file_operations _dlm_fops;
44static const char *name_prefix="dlm"; 44static const char *name_prefix="dlm";
45static struct list_head user_ls_list; 45static struct list_head user_ls_list;
46static struct semaphore user_ls_lock; 46static struct mutex user_ls_lock;
47 47
48/* Lock infos are stored in here indexed by lock ID */ 48/* Lock infos are stored in here indexed by lock ID */
49static DEFINE_IDR(lockinfo_idr); 49static DEFINE_IDR(lockinfo_idr);
@@ -53,6 +53,7 @@ static rwlock_t lockinfo_lock;
53#define LI_FLAG_COMPLETE 1 53#define LI_FLAG_COMPLETE 1
54#define LI_FLAG_FIRSTLOCK 2 54#define LI_FLAG_FIRSTLOCK 2
55#define LI_FLAG_PERSISTENT 3 55#define LI_FLAG_PERSISTENT 3
56#define LI_FLAG_ONLIST 4
56 57
57/* flags in ls_flags*/ 58/* flags in ls_flags*/
58#define LS_FLAG_DELETED 1 59#define LS_FLAG_DELETED 1
@@ -211,18 +212,18 @@ static struct user_ls *find_lockspace(int minor)
211{ 212{
212 struct user_ls *lsinfo; 213 struct user_ls *lsinfo;
213 214
214 down(&user_ls_lock); 215 mutex_lock(&user_ls_lock);
215 lsinfo = __find_lockspace(minor); 216 lsinfo = __find_lockspace(minor);
216 up(&user_ls_lock); 217 mutex_unlock(&user_ls_lock);
217 218
218 return lsinfo; 219 return lsinfo;
219} 220}
220 221
221static void add_lockspace_to_list(struct user_ls *lsinfo) 222static void add_lockspace_to_list(struct user_ls *lsinfo)
222{ 223{
223 down(&user_ls_lock); 224 mutex_lock(&user_ls_lock);
224 list_add(&lsinfo->ls_list, &user_ls_list); 225 list_add(&lsinfo->ls_list, &user_ls_list);
225 up(&user_ls_lock); 226 mutex_unlock(&user_ls_lock);
226} 227}
227 228
228/* Register a lockspace with the DLM and create a misc 229/* Register a lockspace with the DLM and create a misc
@@ -235,12 +236,11 @@ static int register_lockspace(char *name, struct user_ls **ls, int flags)
235 236
236 namelen = strlen(name)+strlen(name_prefix)+2; 237 namelen = strlen(name)+strlen(name_prefix)+2;
237 238
238 newls = kmalloc(sizeof(struct user_ls), GFP_KERNEL); 239 newls = kzalloc(sizeof(struct user_ls), GFP_KERNEL);
239 if (!newls) 240 if (!newls)
240 return -ENOMEM; 241 return -ENOMEM;
241 memset(newls, 0, sizeof(struct user_ls));
242 242
243 newls->ls_miscinfo.name = kmalloc(namelen, GFP_KERNEL); 243 newls->ls_miscinfo.name = kzalloc(namelen, GFP_KERNEL);
244 if (!newls->ls_miscinfo.name) { 244 if (!newls->ls_miscinfo.name) {
245 kfree(newls); 245 kfree(newls);
246 return -ENOMEM; 246 return -ENOMEM;
@@ -277,7 +277,7 @@ static int register_lockspace(char *name, struct user_ls **ls, int flags)
277 return 0; 277 return 0;
278} 278}
279 279
280/* Called with the user_ls_lock semaphore held */ 280/* Called with the user_ls_lock mutex held */
281static int unregister_lockspace(struct user_ls *lsinfo, int force) 281static int unregister_lockspace(struct user_ls *lsinfo, int force)
282{ 282{
283 int status; 283 int status;
@@ -305,11 +305,10 @@ static int unregister_lockspace(struct user_ls *lsinfo, int force)
305static void add_to_astqueue(struct lock_info *li, void *astaddr, void *astparam, 305static void add_to_astqueue(struct lock_info *li, void *astaddr, void *astparam,
306 int lvb_updated) 306 int lvb_updated)
307{ 307{
308 struct ast_info *ast = kmalloc(sizeof(struct ast_info), GFP_KERNEL); 308 struct ast_info *ast = kzalloc(sizeof(struct ast_info), GFP_KERNEL);
309 if (!ast) 309 if (!ast)
310 return; 310 return;
311 311
312 memset(ast, 0, sizeof(*ast));
313 ast->result.user_astparam = astparam; 312 ast->result.user_astparam = astparam;
314 ast->result.user_astaddr = astaddr; 313 ast->result.user_astaddr = astaddr;
315 ast->result.user_lksb = li->li_user_lksb; 314 ast->result.user_lksb = li->li_user_lksb;
@@ -382,6 +381,7 @@ static void ast_routine(void *param)
382 381
383 spin_lock(&li->li_file->fi_li_lock); 382 spin_lock(&li->li_file->fi_li_lock);
384 list_del(&li->li_ownerqueue); 383 list_del(&li->li_ownerqueue);
384 clear_bit(LI_FLAG_ONLIST, &li->li_flags);
385 spin_unlock(&li->li_file->fi_li_lock); 385 spin_unlock(&li->li_file->fi_li_lock);
386 release_lockinfo(li); 386 release_lockinfo(li);
387 return; 387 return;
@@ -437,7 +437,7 @@ static int dlm_open(struct inode *inode, struct file *file)
437 if (!lsinfo) 437 if (!lsinfo)
438 return -ENOENT; 438 return -ENOENT;
439 439
440 f = kmalloc(sizeof(struct file_info), GFP_KERNEL); 440 f = kzalloc(sizeof(struct file_info), GFP_KERNEL);
441 if (!f) 441 if (!f)
442 return -ENOMEM; 442 return -ENOMEM;
443 443
@@ -570,7 +570,7 @@ static int dlm_close(struct inode *inode, struct file *file)
570 * then free the struct. If it's an AUTOFREE lockspace 570 * then free the struct. If it's an AUTOFREE lockspace
571 * then free the whole thing. 571 * then free the whole thing.
572 */ 572 */
573 down(&user_ls_lock); 573 mutex_lock(&user_ls_lock);
574 if (atomic_dec_and_test(&lsinfo->ls_refcnt)) { 574 if (atomic_dec_and_test(&lsinfo->ls_refcnt)) {
575 575
576 if (lsinfo->ls_lockspace) { 576 if (lsinfo->ls_lockspace) {
@@ -582,7 +582,7 @@ static int dlm_close(struct inode *inode, struct file *file)
582 kfree(lsinfo); 582 kfree(lsinfo);
583 } 583 }
584 } 584 }
585 up(&user_ls_lock); 585 mutex_unlock(&user_ls_lock);
586 put_file_info(f); 586 put_file_info(f);
587 587
588 /* Restore signals */ 588 /* Restore signals */
@@ -620,10 +620,10 @@ static int do_user_remove_lockspace(struct file_info *fi, uint8_t cmd,
620 if (!capable(CAP_SYS_ADMIN)) 620 if (!capable(CAP_SYS_ADMIN))
621 return -EPERM; 621 return -EPERM;
622 622
623 down(&user_ls_lock); 623 mutex_lock(&user_ls_lock);
624 lsinfo = __find_lockspace(kparams->minor); 624 lsinfo = __find_lockspace(kparams->minor);
625 if (!lsinfo) { 625 if (!lsinfo) {
626 up(&user_ls_lock); 626 mutex_unlock(&user_ls_lock);
627 return -EINVAL; 627 return -EINVAL;
628 } 628 }
629 629
@@ -631,7 +631,7 @@ static int do_user_remove_lockspace(struct file_info *fi, uint8_t cmd,
631 force = 2; 631 force = 2;
632 632
633 status = unregister_lockspace(lsinfo, force); 633 status = unregister_lockspace(lsinfo, force);
634 up(&user_ls_lock); 634 mutex_unlock(&user_ls_lock);
635 635
636 return status; 636 return status;
637} 637}
@@ -752,7 +752,7 @@ static struct lock_info *allocate_lockinfo(struct file_info *fi, uint8_t cmd,
752 if (!try_module_get(THIS_MODULE)) 752 if (!try_module_get(THIS_MODULE))
753 return NULL; 753 return NULL;
754 754
755 li = kmalloc(sizeof(struct lock_info), GFP_KERNEL); 755 li = kzalloc(sizeof(struct lock_info), GFP_KERNEL);
756 if (li) { 756 if (li) {
757 li->li_magic = LOCKINFO_MAGIC; 757 li->li_magic = LOCKINFO_MAGIC;
758 li->li_file = fi; 758 li->li_file = fi;
@@ -800,8 +800,10 @@ static int do_user_lock(struct file_info *fi, uint8_t cmd,
800 800
801 /* If this is a persistent lock we will have to create a 801 /* If this is a persistent lock we will have to create a
802 lockinfo again */ 802 lockinfo again */
803 if (!li && DLM_LKF_PERSISTENT) { 803 if (!li && (kparams->flags & DLM_LKF_PERSISTENT)) {
804 li = allocate_lockinfo(fi, cmd, kparams); 804 li = allocate_lockinfo(fi, cmd, kparams);
805 if (!li)
806 return -ENOMEM;
805 807
806 li->li_lksb.sb_lkid = kparams->lkid; 808 li->li_lksb.sb_lkid = kparams->lkid;
807 li->li_castaddr = kparams->castaddr; 809 li->li_castaddr = kparams->castaddr;
@@ -887,6 +889,7 @@ static int do_user_lock(struct file_info *fi, uint8_t cmd,
887 889
888 spin_lock(&fi->fi_li_lock); 890 spin_lock(&fi->fi_li_lock);
889 list_add(&li->li_ownerqueue, &fi->fi_li_list); 891 list_add(&li->li_ownerqueue, &fi->fi_li_list);
892 set_bit(LI_FLAG_ONLIST, &li->li_flags);
890 spin_unlock(&fi->fi_li_lock); 893 spin_unlock(&fi->fi_li_lock);
891 if (add_lockinfo(li)) 894 if (add_lockinfo(li))
892 printk(KERN_WARNING "Add lockinfo failed\n"); 895 printk(KERN_WARNING "Add lockinfo failed\n");
@@ -914,12 +917,13 @@ static int do_user_unlock(struct file_info *fi, uint8_t cmd,
914 li = get_lockinfo(kparams->lkid); 917 li = get_lockinfo(kparams->lkid);
915 if (!li) { 918 if (!li) {
916 li = allocate_lockinfo(fi, cmd, kparams); 919 li = allocate_lockinfo(fi, cmd, kparams);
920 if (!li)
921 return -ENOMEM;
917 spin_lock(&fi->fi_li_lock); 922 spin_lock(&fi->fi_li_lock);
918 list_add(&li->li_ownerqueue, &fi->fi_li_list); 923 list_add(&li->li_ownerqueue, &fi->fi_li_list);
924 set_bit(LI_FLAG_ONLIST, &li->li_flags);
919 spin_unlock(&fi->fi_li_lock); 925 spin_unlock(&fi->fi_li_lock);
920 } 926 }
921 if (!li)
922 return -ENOMEM;
923 927
924 if (li->li_magic != LOCKINFO_MAGIC) 928 if (li->li_magic != LOCKINFO_MAGIC)
925 return -EINVAL; 929 return -EINVAL;
@@ -932,6 +936,12 @@ static int do_user_unlock(struct file_info *fi, uint8_t cmd,
932 if (kparams->flags & DLM_LKF_CANCEL && li->li_grmode != -1) 936 if (kparams->flags & DLM_LKF_CANCEL && li->li_grmode != -1)
933 convert_cancel = 1; 937 convert_cancel = 1;
934 938
939 /* Wait until dlm_lock() has completed */
940 if (!test_bit(LI_FLAG_ONLIST, &li->li_flags)) {
941 down(&li->li_firstlock);
942 up(&li->li_firstlock);
943 }
944
935 /* dlm_unlock() passes a 0 for castaddr which means don't overwrite 945 /* dlm_unlock() passes a 0 for castaddr which means don't overwrite
936 the existing li_castaddr as that's the completion routine for 946 the existing li_castaddr as that's the completion routine for
937 unlocks. dlm_unlock_wait() specifies a new AST routine to be 947 unlocks. dlm_unlock_wait() specifies a new AST routine to be
@@ -947,6 +957,7 @@ static int do_user_unlock(struct file_info *fi, uint8_t cmd,
947 if (!status && !convert_cancel) { 957 if (!status && !convert_cancel) {
948 spin_lock(&fi->fi_li_lock); 958 spin_lock(&fi->fi_li_lock);
949 list_del(&li->li_ownerqueue); 959 list_del(&li->li_ownerqueue);
960 clear_bit(LI_FLAG_ONLIST, &li->li_flags);
950 spin_unlock(&fi->fi_li_lock); 961 spin_unlock(&fi->fi_li_lock);
951 } 962 }
952 963
@@ -1055,7 +1066,7 @@ static int __init dlm_device_init(void)
1055 int r; 1066 int r;
1056 1067
1057 INIT_LIST_HEAD(&user_ls_list); 1068 INIT_LIST_HEAD(&user_ls_list);
1058 init_MUTEX(&user_ls_lock); 1069 mutex_init(&user_ls_lock);
1059 rwlock_init(&lockinfo_lock); 1070 rwlock_init(&lockinfo_lock);
1060 1071
1061 ctl_device.name = "dlm-control"; 1072 ctl_device.name = "dlm-control";