Before this patch, asserts based on glocks did not print the glock with
the error. This patch introduces a new macro, gfs2_glock_assert_withdraw
which first prints the glock, then takes the assert.

This also changes a few glock asserts to the new macro.

Signed-off-by: Bob Peterson <rpete...@redhat.com>
---
 fs/gfs2/glock.c | 7 ++++---
 fs/gfs2/glock.h | 9 +++++++++
 2 files changed, 13 insertions(+), 3 deletions(-)

diff --git a/fs/gfs2/glock.c b/fs/gfs2/glock.c
index 9a5dadc93cfc..64541d8bf9ad 100644
--- a/fs/gfs2/glock.c
+++ b/fs/gfs2/glock.c
@@ -164,7 +164,7 @@ void gfs2_glock_free(struct gfs2_glock *gl)
 {
        struct gfs2_sbd *sdp = gl->gl_name.ln_sbd;
 
-       BUG_ON(atomic_read(&gl->gl_revokes));
+       gfs2_glock_assert_withdraw(gl, atomic_read(&gl->gl_revokes) == 0);
        rhashtable_remove_fast(&gl_hash_table, &gl->gl_node, ht_parms);
        smp_mb();
        wake_up_glock(gl);
@@ -626,7 +626,8 @@ __acquires(&gl->gl_lockref.lock)
                 */
                if ((atomic_read(&gl->gl_ail_count) != 0) &&
                    (!cmpxchg(&sdp->sd_log_error, 0, -EIO))) {
-                       gfs2_assert_warn(sdp, !atomic_read(&gl->gl_ail_count));
+                       gfs2_glock_assert_warn(gl,
+                                              !atomic_read(&gl->gl_ail_count));
                        gfs2_dump_glock(NULL, gl, true);
                }
                glops->go_inval(gl, target == LM_ST_DEFERRED ? 0 : 
DIO_METADATA);
@@ -1836,7 +1837,7 @@ void gfs2_glock_finish_truncate(struct gfs2_inode *ip)
        int ret;
 
        ret = gfs2_truncatei_resume(ip);
-       gfs2_assert_withdraw(gl->gl_name.ln_sbd, ret == 0);
+       gfs2_glock_assert_withdraw(gl, ret == 0);
 
        spin_lock(&gl->gl_lockref.lock);
        clear_bit(GLF_LOCK, &gl->gl_flags);
diff --git a/fs/gfs2/glock.h b/fs/gfs2/glock.h
index b8adaf80e4c5..8472d5ba0142 100644
--- a/fs/gfs2/glock.h
+++ b/fs/gfs2/glock.h
@@ -205,6 +205,15 @@ extern void gfs2_dump_glock(struct seq_file *seq, struct 
gfs2_glock *gl,
 #define GLOCK_BUG_ON(gl,x) do { if (unlikely(x)) {             \
                        gfs2_dump_glock(NULL, gl, true);        \
                        BUG(); } } while(0)
+#define gfs2_glock_assert_warn(gl, x) do { if (unlikely(!(x))) {       \
+                       gfs2_dump_glock(NULL, gl, true);                \
+                       gfs2_assert_warn((gl)->gl_name.ln_sbd, (x)); } } \
+       while(0)
+#define gfs2_glock_assert_withdraw(gl, x) do { if (unlikely(!(x))) {   \
+                       gfs2_dump_glock(NULL, gl, true);                \
+                       gfs2_assert_withdraw((gl)->gl_name.ln_sbd, (x)); } } \
+       while(0)
+
 extern __printf(2, 3)
 void gfs2_print_dbg(struct seq_file *seq, const char *fmt, ...);
 
-- 
2.26.2

Reply via email to