The previous patch added a new GL_ST_UNLOCK state that simply
cleared the GLF_LOCK bit, then went into the RUN state. Since the
RUN state immediately sets the GLF_LOCK again and does a few other
things, we can optimize it by putting GL_ST_UNLOCK in the middle
of the GL_ST_RUN state. This avoids unlock-then-lock and extra
checks and skips directly to the resulting promotion/demotion state.

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

diff --git a/fs/gfs2/glock.c b/fs/gfs2/glock.c
index 33f4a530caf4..29e6d9a440ec 100644
--- a/fs/gfs2/glock.c
+++ b/fs/gfs2/glock.c
@@ -724,7 +724,9 @@ static void __state_machine(struct gfs2_glock *gl, int 
new_state,
 
                        GLOCK_BUG_ON(gl, test_bit(GLF_DEMOTE_IN_PROGRESS,
                                                  &gl->gl_flags));
+                       /* Fall through */
 
+               case GL_ST_UNLOCK:
                        if (test_bit(GLF_DEMOTE, &gl->gl_flags) &&
                            gl->gl_demote_state != gl->gl_state)
                                gl->gl_mch = nonblock ? GL_ST_DEMOTE_NONBLOCK :
@@ -751,10 +753,6 @@ static void __state_machine(struct gfs2_glock *gl, int 
new_state,
                        gl->gl_mch = GL_ST_RUN;
                        break;
 
-               case GL_ST_UNLOCK:
-                       clear_bit(GLF_LOCK, &gl->gl_flags);
-                       gl->gl_mch = GL_ST_RUN;
-                       break;
                }
        } while (gl->gl_mch != GL_ST_IDLE || new_state != GL_ST_IDLE);
 
diff --git a/fs/gfs2/glock.h b/fs/gfs2/glock.h
index 5bbf3118c7c3..e1a5bc2d3f76 100644
--- a/fs/gfs2/glock.h
+++ b/fs/gfs2/glock.h
@@ -131,7 +131,7 @@ enum gl_machine_states {
        GL_ST_PROMOTE = 6,         /* Promote the lock */
        GL_ST_RUN = 7,          /* "Run" or progress the lock */
        GL_ST_WORK = 8,         /* Perform general glock work */
-       GL_ST_UNLOCK = 9,       /* Unlock then run */
+       GL_ST_UNLOCK = 9,       /* Unlock the glock */
 };
 
 struct lm_lockops {
-- 
2.19.1

Reply via email to