gfs2: Add new go_held glock operation
authorAndreas Gruenbacher <agruenba@redhat.com>
Fri, 10 Jun 2022 09:42:33 +0000 (11:42 +0200)
committerAndreas Gruenbacher <agruenba@redhat.com>
Wed, 29 Jun 2022 14:56:41 +0000 (16:56 +0200)
Right now, inode_go_instantiate() contains functionality that relates to
how a glock is held rather than the glock itself, like waiting for
pending direct I/O to complete and completing interrupted truncates.
This code is meant to be run each time a holder is acquired, but
go_instantiate is actually only called once, when the glock is
instantiated.

To fix that, introduce a new go_held glock operation that is called each
time a glock holder is acquired.  Move the holder specific code in
inode_go_instantiate() over to inode_go_held().

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

index 347c7bc1fae355ae8af55e82b6e6248b6018740a..6fe088644d7d95888467d7056557be6b98dcefb9 100644 (file)
@@ -488,7 +488,7 @@ int gfs2_instantiate(struct gfs2_holder *gh)
 
 again:
        if (!test_bit(GLF_INSTANTIATE_NEEDED, &gl->gl_flags))
-               return 0;
+               goto done;
 
        /*
         * Since we unlock the lockref lock, we set a flag to indicate
@@ -511,7 +511,13 @@ again:
        if (!ret)
                clear_bit(GLF_INSTANTIATE_NEEDED, &gl->gl_flags);
        clear_and_wake_up_bit(GLF_INSTANTIATE_IN_PROG, &gl->gl_flags);
-       return ret;
+       if (ret)
+               return ret;
+
+done:
+       if (glops->go_held)
+               return glops->go_held(gh);
+       return 0;
 }
 
 /**
index c387f80ca65e8f48da1b8e86f1e8947561f9f8f3..4e0a9909087c61c1dc85f0538e6b8574643a7ace 100644 (file)
@@ -489,14 +489,21 @@ static int inode_go_instantiate(struct gfs2_holder *gh)
 {
        struct gfs2_glock *gl = gh->gh_gl;
        struct gfs2_inode *ip = gl->gl_object;
-       int error = 0;
 
        if (!ip) /* no inode to populate - read it in later */
-               goto out;
+               return 0;
 
-       error = gfs2_inode_refresh(ip);
-       if (error)
-               goto out;
+       return gfs2_inode_refresh(ip);
+}
+
+static int inode_go_held(struct gfs2_holder *gh)
+{
+       struct gfs2_glock *gl = gh->gh_gl;
+       struct gfs2_inode *ip = gl->gl_object;
+       int error = 0;
+
+       if (!ip) /* no inode to populate - read it in later */
+               return 0;
 
        if (gh->gh_state != LM_ST_DEFERRED)
                inode_dio_wait(&ip->i_inode);
@@ -506,7 +513,6 @@ static int inode_go_instantiate(struct gfs2_holder *gh)
            (gh->gh_state == LM_ST_EXCLUSIVE))
                error = gfs2_truncatei_resume(ip);
 
-out:
        return error;
 }
 
@@ -730,6 +736,7 @@ const struct gfs2_glock_operations gfs2_inode_glops = {
        .go_inval = inode_go_inval,
        .go_demote_ok = inode_go_demote_ok,
        .go_instantiate = inode_go_instantiate,
+       .go_held = inode_go_held,
        .go_dump = inode_go_dump,
        .go_type = LM_TYPE_INODE,
        .go_flags = GLOF_ASPACE | GLOF_LRU | GLOF_LVB,
index 9e319c8f9efda86faaf39bd16cb6e24a55b67049..15e4258a1dad4faf0add3ea2899eb64ca0304199 100644 (file)
@@ -220,6 +220,7 @@ struct gfs2_glock_operations {
        void (*go_inval) (struct gfs2_glock *gl, int flags);
        int (*go_demote_ok) (const struct gfs2_glock *gl);
        int (*go_instantiate) (struct gfs2_holder *gh);
+       int (*go_held)(struct gfs2_holder *gh);
        void (*go_dump)(struct seq_file *seq, struct gfs2_glock *gl,
                        const char *fs_id_buf);
        void (*go_callback)(struct gfs2_glock *gl, bool remote);