gfs2: Grab glock reference sooner in gfs2_add_revoke
authorAndreas Gruenbacher <agruenba@redhat.com>
Tue, 5 May 2020 16:56:46 +0000 (11:56 -0500)
committerAndreas Gruenbacher <agruenba@redhat.com>
Fri, 8 May 2020 16:49:04 +0000 (18:49 +0200)
This patch rearranges gfs2_add_revoke so that the extra glock
reference is added earlier on in the function to avoid races in which
the glock is freed before the new reference is taken.

Signed-off-by: Andreas Gruenbacher <agruenba@redhat.com>
Signed-off-by: Bob Peterson <rpeterso@redhat.com>
fs/gfs2/log.c

index cf0b80c78c828838f5fb51fac89fc10538f81363..0644e58c6191b3335bfb2313912c01bbfddbb28f 100644 (file)
@@ -669,13 +669,13 @@ void gfs2_add_revoke(struct gfs2_sbd *sdp, struct gfs2_bufdata *bd)
        struct buffer_head *bh = bd->bd_bh;
        struct gfs2_glock *gl = bd->bd_gl;
 
+       sdp->sd_log_num_revoke++;
+       if (atomic_inc_return(&gl->gl_revokes) == 1)
+               gfs2_glock_hold(gl);
        bh->b_private = NULL;
        bd->bd_blkno = bh->b_blocknr;
        gfs2_remove_from_ail(bd); /* drops ref on bh */
        bd->bd_bh = NULL;
-       sdp->sd_log_num_revoke++;
-       if (atomic_inc_return(&gl->gl_revokes) == 1)
-               gfs2_glock_hold(gl);
        set_bit(GLF_LFLUSH, &gl->gl_flags);
        list_add(&bd->bd_list, &sdp->sd_log_revokes);
 }