aboutsummaryrefslogtreecommitdiffstats
path: root/fs
diff options
context:
space:
mode:
authorAbhijith Das <adas@redhat.com>2007-09-14 00:35:27 -0400
committerSteven Whitehouse <swhiteho@redhat.com>2007-10-10 03:56:14 -0400
commitb4c20166dcfca106f0f416bfce200099ed76ab18 (patch)
tree474e8c3bda161953202793c0801ab00a5b5433de /fs
parent1ad38c437fa33f85ba4b6a85ea8c5478ee72d5bd (diff)
[GFS2] flocks from same process trip kernel BUG at fs/gfs2/glock.c:1118!
This patch adds a new flag to the gfs2_holder structure GL_FLOCK. It is set on holders of glocks representing flocks. This flag is checked in add_to_queue() and a process is permitted to queue more than one holder onto a glock if it is set. This solves the issue of a process not being able to do multiple flocks on the same file. Through a single descriptor, a process can now promote and demote flocks. Through multiple descriptors a process can now queue multiple flocks on the same file. There's still the problem of a process deadlocking itself (because gfs2 blocking locks are not interruptible) by queueing incompatible deadlock. Signed-off-by: Abhijith Das <adas@redhat.com> Signed-off-by: Steven Whitehouse <swhiteho@redhat.com>
Diffstat (limited to 'fs')
-rw-r--r--fs/gfs2/glock.c43
-rw-r--r--fs/gfs2/glock.h1
-rw-r--r--fs/gfs2/ops_file.c13
3 files changed, 32 insertions, 25 deletions
diff --git a/fs/gfs2/glock.c b/fs/gfs2/glock.c
index 931368a385c8..d631cad0aeee 100644
--- a/fs/gfs2/glock.c
+++ b/fs/gfs2/glock.c
@@ -1106,24 +1106,31 @@ static void add_to_queue(struct gfs2_holder *gh)
1106 if (test_and_set_bit(HIF_WAIT, &gh->gh_iflags)) 1106 if (test_and_set_bit(HIF_WAIT, &gh->gh_iflags))
1107 BUG(); 1107 BUG();
1108 1108
1109 existing = find_holder_by_owner(&gl->gl_holders, gh->gh_owner_pid); 1109 if (!(gh->gh_flags & GL_FLOCK)) {
1110 if (existing) { 1110 existing = find_holder_by_owner(&gl->gl_holders,
1111 print_symbol(KERN_WARNING "original: %s\n", existing->gh_ip); 1111 gh->gh_owner_pid);
1112 printk(KERN_INFO "pid : %d\n", existing->gh_owner_pid); 1112 if (existing) {
1113 printk(KERN_INFO "lock type : %d lock state : %d\n", 1113 print_symbol(KERN_WARNING "original: %s\n",
1114 existing->gh_gl->gl_name.ln_type, existing->gh_gl->gl_state); 1114 existing->gh_ip);
1115 print_symbol(KERN_WARNING "new: %s\n", gh->gh_ip); 1115 printk(KERN_INFO "pid : %d\n", existing->gh_owner_pid);
1116 printk(KERN_INFO "pid : %d\n", gh->gh_owner_pid); 1116 printk(KERN_INFO "lock type : %d lock state : %d\n",
1117 printk(KERN_INFO "lock type : %d lock state : %d\n", 1117 existing->gh_gl->gl_name.ln_type,
1118 gl->gl_name.ln_type, gl->gl_state); 1118 existing->gh_gl->gl_state);
1119 BUG(); 1119 print_symbol(KERN_WARNING "new: %s\n", gh->gh_ip);
1120 } 1120 printk(KERN_INFO "pid : %d\n", gh->gh_owner_pid);
1121 1121 printk(KERN_INFO "lock type : %d lock state : %d\n",
1122 existing = find_holder_by_owner(&gl->gl_waiters3, gh->gh_owner_pid); 1122 gl->gl_name.ln_type, gl->gl_state);
1123 if (existing) { 1123 BUG();
1124 print_symbol(KERN_WARNING "original: %s\n", existing->gh_ip); 1124 }
1125 print_symbol(KERN_WARNING "new: %s\n", gh->gh_ip); 1125
1126 BUG(); 1126 existing = find_holder_by_owner(&gl->gl_waiters3,
1127 gh->gh_owner_pid);
1128 if (existing) {
1129 print_symbol(KERN_WARNING "original: %s\n",
1130 existing->gh_ip);
1131 print_symbol(KERN_WARNING "new: %s\n", gh->gh_ip);
1132 BUG();
1133 }
1127 } 1134 }
1128 1135
1129 if (gh->gh_flags & LM_FLAG_PRIORITY) 1136 if (gh->gh_flags & LM_FLAG_PRIORITY)
diff --git a/fs/gfs2/glock.h b/fs/gfs2/glock.h
index f7a8e626aa08..b16f604eea9f 100644
--- a/fs/gfs2/glock.h
+++ b/fs/gfs2/glock.h
@@ -26,6 +26,7 @@
26#define GL_SKIP 0x00000100 26#define GL_SKIP 0x00000100
27#define GL_ATIME 0x00000200 27#define GL_ATIME 0x00000200
28#define GL_NOCACHE 0x00000400 28#define GL_NOCACHE 0x00000400
29#define GL_FLOCK 0x00000800
29#define GL_NOCANCEL 0x00001000 30#define GL_NOCANCEL 0x00001000
30 31
31#define GLR_TRYFAILED 13 32#define GLR_TRYFAILED 13
diff --git a/fs/gfs2/ops_file.c b/fs/gfs2/ops_file.c
index 94d76ace0b95..46a9e10ff17b 100644
--- a/fs/gfs2/ops_file.c
+++ b/fs/gfs2/ops_file.c
@@ -571,7 +571,8 @@ static int do_flock(struct file *file, int cmd, struct file_lock *fl)
571 int error = 0; 571 int error = 0;
572 572
573 state = (fl->fl_type == F_WRLCK) ? LM_ST_EXCLUSIVE : LM_ST_SHARED; 573 state = (fl->fl_type == F_WRLCK) ? LM_ST_EXCLUSIVE : LM_ST_SHARED;
574 flags = (IS_SETLKW(cmd) ? 0 : LM_FLAG_TRY) | GL_EXACT | GL_NOCACHE; 574 flags = (IS_SETLKW(cmd) ? 0 : LM_FLAG_TRY) | GL_EXACT | GL_NOCACHE
575 | GL_FLOCK;
575 576
576 mutex_lock(&fp->f_fl_mutex); 577 mutex_lock(&fp->f_fl_mutex);
577 578
@@ -579,21 +580,19 @@ static int do_flock(struct file *file, int cmd, struct file_lock *fl)
579 if (gl) { 580 if (gl) {
580 if (fl_gh->gh_state == state) 581 if (fl_gh->gh_state == state)
581 goto out; 582 goto out;
582 gfs2_glock_hold(gl);
583 flock_lock_file_wait(file, 583 flock_lock_file_wait(file,
584 &(struct file_lock){.fl_type = F_UNLCK}); 584 &(struct file_lock){.fl_type = F_UNLCK});
585 gfs2_glock_dq_uninit(fl_gh); 585 gfs2_glock_dq_wait(fl_gh);
586 gfs2_holder_reinit(state, flags, fl_gh);
586 } else { 587 } else {
587 error = gfs2_glock_get(GFS2_SB(&ip->i_inode), 588 error = gfs2_glock_get(GFS2_SB(&ip->i_inode),
588 ip->i_no_addr, &gfs2_flock_glops, 589 ip->i_no_addr, &gfs2_flock_glops,
589 CREATE, &gl); 590 CREATE, &gl);
590 if (error) 591 if (error)
591 goto out; 592 goto out;
593 gfs2_holder_init(gl, state, flags, fl_gh);
594 gfs2_glock_put(gl);
592 } 595 }
593
594 gfs2_holder_init(gl, state, flags, fl_gh);
595 gfs2_glock_put(gl);
596
597 error = gfs2_glock_nq(fl_gh); 596 error = gfs2_glock_nq(fl_gh);
598 if (error) { 597 if (error) {
599 gfs2_holder_uninit(fl_gh); 598 gfs2_holder_uninit(fl_gh);