GFS2: Remove potential race in flock code
authorSteven Whitehouse <swhiteho@redhat.com>
Wed, 9 Mar 2011 11:14:32 +0000 (11:14 +0000)
committerSteven Whitehouse <swhiteho@redhat.com>
Wed, 9 Mar 2011 11:14:32 +0000 (11:14 +0000)
This patch ensures that we always wait for glock demotion when
dropping flocks on a file in order to prevent any race
conditions associated with further flock calls or closing
the file.

Signed-off-by: Steven Whitehouse <swhiteho@redhat.com>
fs/gfs2/file.c

index 216ad2774a622edc87074a83e55c44f61dbaba14..2878481f72a9de5d448cf57781129ed9d9133ea0 100644 (file)
@@ -981,8 +981,10 @@ static void do_unflock(struct file *file, struct file_lock *fl)
 
        mutex_lock(&fp->f_fl_mutex);
        flock_lock_file_wait(file, fl);
-       if (fl_gh->gh_gl)
-               gfs2_glock_dq_uninit(fl_gh);
+       if (fl_gh->gh_gl) {
+               gfs2_glock_dq_wait(fl_gh);
+               gfs2_holder_uninit(fl_gh);
+       }
        mutex_unlock(&fp->f_fl_mutex);
 }