gfs2: Split the two kinds of glock "delete" work
authorAndreas Gruenbacher <agruenba@redhat.com>
Tue, 20 Dec 2022 23:52:51 +0000 (00:52 +0100)
committerAndreas Gruenbacher <agruenba@redhat.com>
Tue, 31 Jan 2023 21:40:24 +0000 (22:40 +0100)
Function delete_work_func() is used for two purposes:

 * to immediately try to evict the glock's inode, and

 * to verify after a little while that the inode has been deleted as
   expected, and didn't just get skipped.

These two operations are not separated very well, so introduce two new
glock flags to improved that.  Split gfs2_queue_delete_work() into
gfs2_queue_try_to_evict and gfs2_queue_verify_evict().

Signed-off-by: Andreas Gruenbacher <agruenba@redhat.com>
fs/gfs2/glock.c
fs/gfs2/glock.h
fs/gfs2/glops.c
fs/gfs2/incore.h
fs/gfs2/rgrp.c
fs/gfs2/super.c

index 1565fdf32ac007d96e51bc5fe09aeff9d1faed8a..b184375df9bd98d7c361ac1459d24f136c11a896 100644 (file)
@@ -975,6 +975,26 @@ static bool gfs2_try_evict(struct gfs2_glock *gl)
        return evicted;
 }
 
+bool gfs2_queue_try_to_evict(struct gfs2_glock *gl)
+{
+       struct gfs2_sbd *sdp = gl->gl_name.ln_sbd;
+
+       if (test_and_set_bit(GLF_TRY_TO_EVICT, &gl->gl_flags))
+               return false;
+       return queue_delayed_work(sdp->sd_delete_wq,
+                                 &gl->gl_delete, 0);
+}
+
+static bool gfs2_queue_verify_evict(struct gfs2_glock *gl)
+{
+       struct gfs2_sbd *sdp = gl->gl_name.ln_sbd;
+
+       if (test_and_set_bit(GLF_VERIFY_EVICT, &gl->gl_flags))
+               return false;
+       return queue_delayed_work(sdp->sd_delete_wq,
+                                 &gl->gl_delete, 5 * HZ);
+}
+
 static void delete_work_func(struct work_struct *work)
 {
        struct delayed_work *dwork = to_delayed_work(work);
@@ -983,7 +1003,7 @@ static void delete_work_func(struct work_struct *work)
        struct inode *inode;
        u64 no_addr = gl->gl_name.ln_number;
 
-       if (test_bit(GLF_DEMOTE, &gl->gl_flags)) {
+       if (test_and_clear_bit(GLF_TRY_TO_EVICT, &gl->gl_flags)) {
                /*
                 * If we can evict the inode, give the remote node trying to
                 * delete the inode some time before verifying that the delete
@@ -1002,22 +1022,25 @@ static void delete_work_func(struct work_struct *work)
                 * step entirely.
                 */
                if (gfs2_try_evict(gl)) {
-                       if (gfs2_queue_delete_work(gl, 5 * HZ))
+                       if (gfs2_queue_verify_evict(gl))
                                return;
                }
                goto out;
        }
 
-       inode = gfs2_lookup_by_inum(sdp, no_addr, gl->gl_no_formal_ino,
-                                   GFS2_BLKST_UNLINKED);
-       if (IS_ERR(inode)) {
-               if (PTR_ERR(inode) == -EAGAIN &&
-                       (gfs2_queue_delete_work(gl, 5 * HZ)))
+       if (test_and_clear_bit(GLF_VERIFY_EVICT, &gl->gl_flags)) {
+               inode = gfs2_lookup_by_inum(sdp, no_addr, gl->gl_no_formal_ino,
+                                           GFS2_BLKST_UNLINKED);
+               if (IS_ERR(inode)) {
+                       if (PTR_ERR(inode) == -EAGAIN &&
+                           gfs2_queue_verify_evict(gl))
                                return;
-       } else {
-               d_prune_aliases(inode);
-               iput(inode);
+               } else {
+                       d_prune_aliases(inode);
+                       iput(inode);
+               }
        }
+
 out:
        gfs2_glock_put(gl);
 }
@@ -2057,16 +2080,10 @@ static void glock_hash_walk(glock_examiner examiner, const struct gfs2_sbd *sdp)
        rhashtable_walk_exit(&iter);
 }
 
-bool gfs2_queue_delete_work(struct gfs2_glock *gl, unsigned long delay)
-{
-       struct gfs2_sbd *sdp = gl->gl_name.ln_sbd;
-
-       return queue_delayed_work(sdp->sd_delete_wq,
-                                 &gl->gl_delete, delay);
-}
-
 void gfs2_cancel_delete_work(struct gfs2_glock *gl)
 {
+       clear_bit(GLF_TRY_TO_EVICT, &gl->gl_flags);
+       clear_bit(GLF_VERIFY_EVICT, &gl->gl_flags);
        if (cancel_delayed_work(&gl->gl_delete))
                gfs2_glock_put(gl);
 }
@@ -2298,6 +2315,10 @@ static const char *gflags2str(char *buf, const struct gfs2_glock *gl)
                *p++ = 'n';
        if (test_bit(GLF_INSTANTIATE_IN_PROG, gflags))
                *p++ = 'N';
+       if (test_bit(GLF_TRY_TO_EVICT, gflags))
+               *p++ = 'e';
+       if (test_bit(GLF_VERIFY_EVICT, gflags))
+               *p++ = 'E';
        *p = 0;
        return buf;
 }
index b9da61dbe550d9b41e649f268cc9fc1f8fa08967..1f1ba92c15a8ff055ded885a5ef1ae5f907fda9c 100644 (file)
@@ -267,7 +267,7 @@ static inline int gfs2_glock_nq_init(struct gfs2_glock *gl,
 
 extern void gfs2_glock_cb(struct gfs2_glock *gl, unsigned int state);
 extern void gfs2_glock_complete(struct gfs2_glock *gl, int ret);
-extern bool gfs2_queue_delete_work(struct gfs2_glock *gl, unsigned long delay);
+extern bool gfs2_queue_try_to_evict(struct gfs2_glock *gl);
 extern void gfs2_cancel_delete_work(struct gfs2_glock *gl);
 extern void gfs2_flush_delete_work(struct gfs2_sbd *sdp);
 extern void gfs2_gl_hash_clear(struct gfs2_sbd *sdp);
index 68676bc781716694504c78d1f162bbae9b22fc24..e4c585f16ddd430b2c22a3f7070dc9faeb09269e 100644 (file)
@@ -651,7 +651,7 @@ static void iopen_go_callback(struct gfs2_glock *gl, bool remote)
        if (gl->gl_demote_state == LM_ST_UNLOCKED &&
            gl->gl_state == LM_ST_SHARED && ip) {
                gl->gl_lockref.count++;
-               if (!gfs2_queue_delete_work(gl, 0))
+               if (!gfs2_queue_try_to_evict(gl))
                        gl->gl_lockref.count--;
        }
 }
index 6e8a5f2d6b4942e6abe1c06631901ee74d55772b..9b380125eb78c817098cce8e4f58abcfba62b960 100644 (file)
@@ -330,6 +330,8 @@ enum {
        GLF_OBJECT                      = 14, /* Used only for tracing */
        GLF_BLOCKING                    = 15,
        GLF_FREEING                     = 16, /* Wait for glock to be freed */
+       GLF_TRY_TO_EVICT                = 17, /* iopen glocks only */
+       GLF_VERIFY_EVICT                = 18, /* iopen glocks only */
 };
 
 struct gfs2_glock {
index f602fb844951935c93b55e2ab1afac27fc2e6637..3b9b76e980ada5bd13d6393f104d660a3e988776 100644 (file)
@@ -1879,7 +1879,7 @@ static void try_rgrp_unlink(struct gfs2_rgrpd *rgd, u64 *last_unlinked, u64 skip
                 */
                ip = gl->gl_object;
 
-               if (ip || !gfs2_queue_delete_work(gl, 0))
+               if (ip || !gfs2_queue_try_to_evict(gl))
                        gfs2_glock_put(gl);
                else
                        found++;
index 0b5cda46478783b038200040e05cce177119aaf4..7b0bfe41b5cc387cb6644a982e384cad50caa8ac 100644 (file)
@@ -954,7 +954,7 @@ static int gfs2_drop_inode(struct inode *inode)
                struct gfs2_glock *gl = ip->i_iopen_gh.gh_gl;
 
                gfs2_glock_hold(gl);
-               if (!gfs2_queue_delete_work(gl, 0))
+               if (!gfs2_queue_try_to_evict(gl))
                        gfs2_glock_queue_put(gl);
                return 0;
        }