]> git.karo-electronics.de Git - linux-beck.git/commitdiff
[GFS2] Fix page lock/glock deadlock
authorSteven Whitehouse <swhiteho@redhat.com>
Wed, 8 Nov 2006 15:26:54 +0000 (10:26 -0500)
committerSteven Whitehouse <swhiteho@redhat.com>
Thu, 30 Nov 2006 15:34:43 +0000 (10:34 -0500)
This fixes a race between the glock and the page lock encountered
during truncate in gfs2_readpage and gfs2_prepare_write. The gfs2_readpages
function doesn't need the same fix since it only uses a try lock anyway, so
it will fail back to gfs2_readpage in the case of a potential deadlock.

This bug was spotted by Russell Cattelan.

Cc: Russell Cattelan <cattelan@redhat.com>
Signed-off-by: Steven Whitehouse <swhiteho@redhat.com>
fs/gfs2/glock.h
fs/gfs2/ops_address.c

index b9856274df5934a75784b57f026a66f6769f2857..a331bf8175ea227a6169837d6470050dff1ac4f6 100644 (file)
@@ -27,7 +27,6 @@
 #define GL_ATIME               0x00000200
 #define GL_NOCACHE             0x00000400
 #define GL_NOCANCEL            0x00001000
-#define GL_AOP                 0x00004000
 
 #define GLR_TRYFAILED          13
 #define GLR_CANCELED           14
index 5c3962c80e883d4e14a2ac9aeeaccac19abba318..3822189454a30e75be8f6d64497725afa31ad945 100644 (file)
@@ -230,7 +230,7 @@ static int gfs2_readpage(struct file *file, struct page *page)
                                /* gfs2_sharewrite_nopage has grabbed the ip->i_gl already */
                                goto skip_lock;
                }
-               gfs2_holder_init(ip->i_gl, LM_ST_SHARED, GL_ATIME|GL_AOP, &gh);
+               gfs2_holder_init(ip->i_gl, LM_ST_SHARED, GL_ATIME|LM_FLAG_TRY_1CB, &gh);
                do_unlock = 1;
                error = gfs2_glock_nq_m_atime(1, &gh);
                if (unlikely(error))
@@ -254,6 +254,8 @@ skip_lock:
 out:
        return error;
 out_unlock:
+       if (error == GLR_TRYFAILED)
+               error = AOP_TRUNCATED_PAGE;
        unlock_page(page);
        if (do_unlock)
                gfs2_holder_uninit(&gh);
@@ -293,7 +295,7 @@ static int gfs2_readpages(struct file *file, struct address_space *mapping,
                                goto skip_lock;
                }
                gfs2_holder_init(ip->i_gl, LM_ST_SHARED,
-                                LM_FLAG_TRY_1CB|GL_ATIME|GL_AOP, &gh);
+                                LM_FLAG_TRY_1CB|GL_ATIME, &gh);
                do_unlock = 1;
                ret = gfs2_glock_nq_m_atime(1, &gh);
                if (ret == GLR_TRYFAILED)
@@ -366,10 +368,13 @@ static int gfs2_prepare_write(struct file *file, struct page *page,
        unsigned int write_len = to - from;
 
 
-       gfs2_holder_init(ip->i_gl, LM_ST_EXCLUSIVE, GL_ATIME|GL_AOP, &ip->i_gh);
+       gfs2_holder_init(ip->i_gl, LM_ST_EXCLUSIVE, GL_ATIME|LM_FLAG_TRY_1CB, &ip->i_gh);
        error = gfs2_glock_nq_m_atime(1, &ip->i_gh);
-       if (error)
+       if (unlikely(error)) {
+               if (error == GLR_TRYFAILED)
+                       error = AOP_TRUNCATED_PAGE;
                goto out_uninit;
+       }
 
        gfs2_write_calc_reserv(ip, write_len, &data_blocks, &ind_blocks);