]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
gfs2: Further sanitize lock_dlm.c
authorAndreas Gruenbacher <agruenba@redhat.com>
Thu, 7 Aug 2025 08:21:33 +0000 (10:21 +0200)
committerAndreas Gruenbacher <agruenba@redhat.com>
Fri, 12 Sep 2025 10:02:20 +0000 (12:02 +0200)
The gl_req field and GLF_BLOCKING flag are only relevant to gdlm_lock(),
its callback gdlm_ast(), and their helpers, so set and clear them inside
lock_dlm.c.

Also, the LM_FLAG_ANY flag is relevant to gdlm_lock(), but do_xmote()
doesn't pass that flag down to gdlm_lock() as it should.  Fix that by
passing down all the flags.

In addition, document the effect of the LM_FLAG_ANY flag on locks held
in EX mode locally.

Signed-off-by: Andreas Gruenbacher <agruenba@redhat.com>
Reviewed-by: Andrew Price <anprice@redhat.com>
fs/gfs2/glock.c
fs/gfs2/glock.h
fs/gfs2/lock_dlm.c

index 1ced38b9a5a25dc55b6e3220aba2cd924c5836c0..5958910154158e0a014182a4f8bbec4b92320684 100644 (file)
@@ -717,12 +717,6 @@ __acquires(&gl->gl_lockref.lock)
                        return;
                do_error(gl, 0); /* Fail queued try locks */
        }
-       gl->gl_req = target;
-       set_bit(GLF_BLOCKING, &gl->gl_flags);
-       if ((gl->gl_req == LM_ST_UNLOCKED) ||
-           (gl->gl_state == LM_ST_EXCLUSIVE) ||
-           (lck_flags & (LM_FLAG_TRY|LM_FLAG_TRY_1CB)))
-               clear_bit(GLF_BLOCKING, &gl->gl_flags);
        if (!glops->go_inval && !glops->go_sync)
                goto skip_inval;
 
index 9339a3bff6eeb1db620a4f828826ab886647ac37..d041b922b45e3b3b0e5f648081f5d7b1f8ee7e1c 100644 (file)
@@ -68,6 +68,10 @@ enum {
  * also be granted in SHARED.  The preferred state is whichever is compatible
  * with other granted locks, or the specified state if no other locks exist.
  *
+ * In addition, when a lock is already held in EX mode locally, a SHARED or
+ * DEFERRED mode request with the LM_FLAG_ANY flag set will be granted.
+ * (The LM_FLAG_ANY flag is only use for SHARED mode requests currently.)
+ *
  * LM_FLAG_NODE_SCOPE
  * This holder agrees to share the lock within this node. In other words,
  * the glock is held in EX mode according to DLM, but local holders on the
index cee5d199d2d87086afbb61e4727f9422501365db..5daaeaaaf18dd869e108ba2ece817732e0d58927 100644 (file)
@@ -58,6 +58,7 @@ static inline void gfs2_update_stats(struct gfs2_lkstats *s, unsigned index,
 /**
  * gfs2_update_reply_times - Update locking statistics
  * @gl: The glock to update
+ * @blocking: The operation may have been blocking
  *
  * This assumes that gl->gl_dstamp has been set earlier.
  *
@@ -72,12 +73,12 @@ static inline void gfs2_update_stats(struct gfs2_lkstats *s, unsigned index,
  * TRY_1CB flags are set are classified as non-blocking. All
  * other DLM requests are counted as (potentially) blocking.
  */
-static inline void gfs2_update_reply_times(struct gfs2_glock *gl)
+static inline void gfs2_update_reply_times(struct gfs2_glock *gl,
+                                          bool blocking)
 {
        struct gfs2_pcpu_lkstats *lks;
        const unsigned gltype = gl->gl_name.ln_type;
-       unsigned index = test_bit(GLF_BLOCKING, &gl->gl_flags) ?
-                        GFS2_LKS_SRTTB : GFS2_LKS_SRTT;
+       unsigned index = blocking ? GFS2_LKS_SRTTB : GFS2_LKS_SRTT;
        s64 rtt;
 
        preempt_disable();
@@ -119,14 +120,18 @@ static inline void gfs2_update_request_times(struct gfs2_glock *gl)
 static void gdlm_ast(void *arg)
 {
        struct gfs2_glock *gl = arg;
+       bool blocking;
        unsigned ret;
 
+       blocking = test_bit(GLF_BLOCKING, &gl->gl_flags);
+       gfs2_update_reply_times(gl, blocking);
+       clear_bit(GLF_BLOCKING, &gl->gl_flags);
+
        /* If the glock is dead, we only react to a dlm_unlock() reply. */
        if (__lockref_is_dead(&gl->gl_lockref) &&
            gl->gl_lksb.sb_status != -DLM_EUNLOCK)
                return;
 
-       gfs2_update_reply_times(gl);
        BUG_ON(gl->gl_lksb.sb_flags & DLM_SBF_DEMOTED);
 
        if ((gl->gl_lksb.sb_flags & DLM_SBF_VALNOTVALID) && gl->gl_lksb.sb_lvbptr)
@@ -241,7 +246,7 @@ static bool down_conversion(int cur, int req)
 }
 
 static u32 make_flags(struct gfs2_glock *gl, const unsigned int gfs_flags,
-                     const int cur, const int req)
+                     const int req, bool blocking)
 {
        u32 lkf = 0;
 
@@ -274,7 +279,7 @@ static u32 make_flags(struct gfs2_glock *gl, const unsigned int gfs_flags,
                 * "upward" lock conversions or else DLM will reject the
                 * request as invalid.
                 */
-               if (!down_conversion(cur, req))
+               if (blocking)
                        lkf |= DLM_LKF_QUECVT;
        }
 
@@ -294,14 +299,20 @@ static int gdlm_lock(struct gfs2_glock *gl, unsigned int req_state,
                     unsigned int flags)
 {
        struct lm_lockstruct *ls = &gl->gl_name.ln_sbd->sd_lockstruct;
+       bool blocking;
        int cur, req;
        u32 lkf;
        char strname[GDLM_STRNAME_BYTES] = "";
        int error;
 
+       gl->gl_req = req_state;
        cur = make_mode(gl->gl_name.ln_sbd, gl->gl_state);
        req = make_mode(gl->gl_name.ln_sbd, req_state);
-       lkf = make_flags(gl, flags, cur, req);
+       blocking = !down_conversion(cur, req) &&
+                  !(flags & (LM_FLAG_TRY|LM_FLAG_TRY_1CB));
+       lkf = make_flags(gl, flags, req, blocking);
+       if (blocking)
+               set_bit(GLF_BLOCKING, &gl->gl_flags);
        gfs2_glstats_inc(gl, GFS2_LKS_DCOUNT);
        gfs2_sbstats_inc(gl, GFS2_LKS_DCOUNT);
        if (test_bit(GLF_INITIAL, &gl->gl_flags)) {
@@ -341,7 +352,6 @@ static void gdlm_put_lock(struct gfs2_glock *gl)
                return;
        }
 
-       clear_bit(GLF_BLOCKING, &gl->gl_flags);
        gfs2_glstats_inc(gl, GFS2_LKS_DCOUNT);
        gfs2_sbstats_inc(gl, GFS2_LKS_DCOUNT);
        gfs2_update_request_times(gl);