Before this patch, the gfs2_promote kernel trace point would would only
record the "first" flag if the go_lock function was called. This patch
simplifies do_promote by eliminating the redundant code in do_promote
and fixes the trace point by adding a new gfs2_first_holder function.
This will also be used in a future patch.

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

diff --git a/fs/gfs2/glock.c b/fs/gfs2/glock.c
index b8248ceff3c3..4fcf340603e7 100644
--- a/fs/gfs2/glock.c
+++ b/fs/gfs2/glock.c
@@ -394,6 +394,7 @@ __acquires(&gl->gl_lockref.lock)
 {
        const struct gfs2_glock_operations *glops = gl->gl_ops;
        struct gfs2_holder *gh, *tmp;
+       int first;
        int ret;
 
 restart:
@@ -401,8 +402,8 @@ __acquires(&gl->gl_lockref.lock)
                if (test_bit(HIF_HOLDER, &gh->gh_iflags))
                        continue;
                if (may_grant(gl, gh)) {
-                       if (gh->gh_list.prev == &gl->gl_holders &&
-                           glops->go_lock) {
+                       first = gfs2_first_holder(gh);
+                       if (first && glops->go_lock) {
                                if (!(gh->gh_flags & GL_SKIP)) {
                                        spin_unlock(&gl->gl_lockref.lock);
                                        /* FIXME: eliminate this eventually */
@@ -418,14 +419,18 @@ __acquires(&gl->gl_lockref.lock)
                                                goto restart;
                                        }
                                }
-                               set_bit(HIF_HOLDER, &gh->gh_iflags);
-                               trace_gfs2_promote(gh, 1);
-                               gfs2_holder_wake(gh);
-                               goto restart;
                        }
                        set_bit(HIF_HOLDER, &gh->gh_iflags);
-                       trace_gfs2_promote(gh, 0);
+                       trace_gfs2_promote(gh, first);
                        gfs2_holder_wake(gh);
+                       /*
+                        * If this was the first holder, we may have released
+                        * the gl_lockref.lock, so the holders list may have
+                        * changed. For that reason, we start again at the
+                        * start of the holders queue.
+                        */
+                       if (first)
+                               goto restart;
                        continue;
                }
                if (gh->gh_list.prev == &gl->gl_holders)
diff --git a/fs/gfs2/glock.h b/fs/gfs2/glock.h
index 31a8f2f649b5..699c5e95006a 100644
--- a/fs/gfs2/glock.h
+++ b/fs/gfs2/glock.h
@@ -325,6 +325,13 @@ static inline void glock_clear_object(struct gfs2_glock 
*gl, void *object)
        spin_unlock(&gl->gl_lockref.lock);
 }
 
+static inline bool gfs2_first_holder(struct gfs2_holder *gh)
+{
+       struct gfs2_glock *gl = gh->gh_gl;
+
+       return (gh->gh_list.prev == &gl->gl_holders);
+}
+
 extern void gfs2_inode_remember_delete(struct gfs2_glock *gl, u64 generation);
 extern bool gfs2_inode_already_deleted(struct gfs2_glock *gl, u64 generation);
 
-- 
2.31.1

Reply via email to