Revert "gfs2: Replace gl_revokes with a GLF flag"
authorBob Peterson <rpeterso@redhat.com>
Thu, 6 Jun 2019 12:33:38 +0000 (07:33 -0500)
committerAndreas Gruenbacher <agruenba@redhat.com>
Thu, 6 Jun 2019 14:29:26 +0000 (16:29 +0200)
Commit 73118ca8baf7 introduced a glock reference counting bug in
gfs2_trans_remove_revoke.  Given that, replacing gl_revokes with a GLF flag is
no longer useful, so revert that commit.

Signed-off-by: Bob Peterson <rpeterso@redhat.com>
Signed-off-by: Andreas Gruenbacher <agruenba@redhat.com>
fs/gfs2/glock.c
fs/gfs2/incore.h
fs/gfs2/log.c
fs/gfs2/lops.c
fs/gfs2/main.c
fs/gfs2/super.c

index 15c605cfcfc8521510aa3acb44b865ea3199ea0a..71c28ff98b564e2f2fa773e0797f6a1516fe2c41 100644 (file)
@@ -140,7 +140,7 @@ void gfs2_glock_free(struct gfs2_glock *gl)
 {
        struct gfs2_sbd *sdp = gl->gl_name.ln_sbd;
 
-       BUG_ON(test_bit(GLF_REVOKES, &gl->gl_flags));
+       BUG_ON(atomic_read(&gl->gl_revokes));
        rhashtable_remove_fast(&gl_hash_table, &gl->gl_node, ht_parms);
        smp_mb();
        wake_up_glock(gl);
@@ -1801,7 +1801,7 @@ void gfs2_dump_glock(struct seq_file *seq, struct gfs2_glock *gl)
                  state2str(gl->gl_target),
                  state2str(gl->gl_demote_state), dtime,
                  atomic_read(&gl->gl_ail_count),
-                 test_bit(GLF_REVOKES, &gl->gl_flags) ? 1 : 0,
+                 atomic_read(&gl->gl_revokes),
                  (int)gl->gl_lockref.count, gl->gl_hold_time);
 
        list_for_each_entry(gh, &gl->gl_holders, gh_list)
index b1575506859318e49c6dfa102b6e736725108f73..1d35e0da0ef8aada48aaec70bbc98ac37dcdad24 100644 (file)
@@ -345,7 +345,6 @@ enum {
        GLF_OBJECT                      = 14, /* Used only for tracing */
        GLF_BLOCKING                    = 15,
        GLF_INODE_CREATING              = 16, /* Inode creation occurring */
-       GLF_REVOKES                     = 17, /* Glock has revokes in queue */
 };
 
 struct gfs2_glock {
@@ -375,6 +374,7 @@ struct gfs2_glock {
        struct list_head gl_lru;
        struct list_head gl_ail_list;
        atomic_t gl_ail_count;
+       atomic_t gl_revokes;
        struct delayed_work gl_work;
        union {
                /* For inode and iopen glocks only */
index a2e1df488df04a305d2a8eca84327a2461e158bf..86703c95353e1d96789f9505c39bcaf5b167ab1f 100644 (file)
@@ -606,10 +606,8 @@ void gfs2_add_revoke(struct gfs2_sbd *sdp, struct gfs2_bufdata *bd)
        gfs2_remove_from_ail(bd); /* drops ref on bh */
        bd->bd_bh = NULL;
        sdp->sd_log_num_revoke++;
-       if (!test_bit(GLF_REVOKES, &gl->gl_flags)) {
-               set_bit(GLF_REVOKES, &gl->gl_flags);
+       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);
 }
index 33ab662c9aacc5f041e102082f4ad0edc876b5a5..bb0e5b8e445e7bb8197f307fc4619456e6487757 100644 (file)
@@ -860,34 +860,19 @@ static void revoke_lo_before_commit(struct gfs2_sbd *sdp, struct gfs2_trans *tr)
 static void revoke_lo_after_commit(struct gfs2_sbd *sdp, struct gfs2_trans *tr)
 {
        struct list_head *head = &sdp->sd_log_revokes;
-       struct gfs2_bufdata *bd, *tmp;
-
-       /*
-        * Glocks can be referenced repeatedly on the revoke list, but the list
-        * only holds one reference.  All glocks on the list will have the
-        * GLF_REVOKES flag set initially.
-        */
-
-       list_for_each_entry_safe(bd, tmp, head, bd_list) {
-               struct gfs2_glock *gl = bd->bd_gl;
+       struct gfs2_bufdata *bd;
+       struct gfs2_glock *gl;
 
-               if (test_bit(GLF_REVOKES, &gl->gl_flags)) {
-                       /* Keep each glock on the list exactly once. */
-                       clear_bit(GLF_REVOKES, &gl->gl_flags);
-                       continue;
+       while (!list_empty(head)) {
+               bd = list_entry(head->next, struct gfs2_bufdata, bd_list);
+               list_del_init(&bd->bd_list);
+               gl = bd->bd_gl;
+               if (atomic_dec_return(&gl->gl_revokes) == 0) {
+                       clear_bit(GLF_LFLUSH, &gl->gl_flags);
+                       gfs2_glock_queue_put(gl);
                }
-               list_del(&bd->bd_list);
-               kmem_cache_free(gfs2_bufdata_cachep, bd);
-       }
-       list_for_each_entry_safe(bd, tmp, head, bd_list) {
-               struct gfs2_glock *gl = bd->bd_gl;
-
-               list_del(&bd->bd_list);
                kmem_cache_free(gfs2_bufdata_cachep, bd);
-               clear_bit(GLF_LFLUSH, &gl->gl_flags);
-               gfs2_glock_queue_put(gl);
        }
-       /* the list is empty now */
 }
 
 static void revoke_lo_before_scan(struct gfs2_jdesc *jd,
index c700738de1f729c7527599628787329e66c86ec9..136484ef35d37de7e4878c54ce98cd35a1326eb7 100644 (file)
@@ -59,6 +59,7 @@ static void gfs2_init_glock_once(void *foo)
        INIT_LIST_HEAD(&gl->gl_lru);
        INIT_LIST_HEAD(&gl->gl_ail_list);
        atomic_set(&gl->gl_ail_count, 0);
+       atomic_set(&gl->gl_revokes, 0);
 }
 
 static void gfs2_init_gl_aspace_once(void *foo)
index fbf6b1fd330b315f761eabd58ab66b87c5bae1bc..2aa4dd050f3d28687668f0c75884fd34523ff02b 100644 (file)
@@ -1477,7 +1477,7 @@ static void gfs2_final_release_pages(struct gfs2_inode *ip)
        truncate_inode_pages(gfs2_glock2aspace(ip->i_gl), 0);
        truncate_inode_pages(&inode->i_data, 0);
 
-       if (!test_bit(GLF_REVOKES, &gl->gl_flags)) {
+       if (atomic_read(&gl->gl_revokes) == 0) {
                clear_bit(GLF_LFLUSH, &gl->gl_flags);
                clear_bit(GLF_DIRTY, &gl->gl_flags);
        }