gfs2: gfs2_evict_inode clarification
authorAndreas Gruenbacher <agruenba@redhat.com>
Fri, 4 Oct 2024 12:10:47 +0000 (14:10 +0200)
committerAndreas Gruenbacher <agruenba@redhat.com>
Tue, 5 Nov 2024 11:39:29 +0000 (12:39 +0100)
When function evict_should_delete() returns SHOULD_DEFER_EVICTION, gh is
never initialized, but that isn't obvious; if it did initialize gh and
then return SHOULD_DEFER_EVICTION, gfs2_evict_inode() would fail to
release it.  To clarify the code, change gfs2_evict_inode() to always
check if gh needs to be released, no matter what evict_should_delete()
returns.

Signed-off-by: Andreas Gruenbacher <agruenba@redhat.com>
fs/gfs2/super.c

index 4015839..aadb83e 100644 (file)
@@ -1486,6 +1486,7 @@ static void gfs2_evict_inode(struct inode *inode)
        enum evict_behavior behavior;
        int ret;
 
+       gfs2_holder_mark_uninitialized(&gh);
        if (inode->i_nlink || sb_rdonly(sb) || !ip->i_no_addr)
                goto out;
 
@@ -1497,7 +1498,6 @@ static void gfs2_evict_inode(struct inode *inode)
        if (!sdp->sd_jdesc)
                goto out;
 
-       gfs2_holder_mark_uninitialized(&gh);
        behavior = evict_should_delete(inode, &gh);
        if (behavior == EVICT_SHOULD_DEFER_DELETE &&
            !test_bit(SDF_KILL, &sdp->sd_flags)) {
@@ -1516,11 +1516,11 @@ static void gfs2_evict_inode(struct inode *inode)
        if (gfs2_rs_active(&ip->i_res))
                gfs2_rs_deltree(&ip->i_res);
 
-       if (gfs2_holder_initialized(&gh))
-               gfs2_glock_dq_uninit(&gh);
        if (ret && ret != GLR_TRYFAILED && ret != -EROFS)
                fs_warn(sdp, "gfs2_evict_inode: %d\n", ret);
 out:
+       if (gfs2_holder_initialized(&gh))
+               gfs2_glock_dq_uninit(&gh);
        truncate_inode_pages_final(&inode->i_data);
        if (ip->i_qadata)
                gfs2_assert_warn(sdp, ip->i_qadata->qa_ref == 0);