From: Bob Peterson <rpeterso@redhat.com>
To: cluster-devel.redhat.com
Subject: [Cluster-devel] [GFS2 PATCH 3/5] gfs2: further simplify gfs2_evict_inode with new func may_delete_evicted
Date: Tue, 15 Sep 2020 09:38:20 -0500 [thread overview]
Message-ID: <20200915143822.16485-4-rpeterso@redhat.com> (raw)
In-Reply-To: <20200915143822.16485-1-rpeterso@redhat.com>
This patch further simplifies function gfs2_evict_inode() by adding a new
function may_delete_evicted(). The function may also lock the inode glock.
Signed-off-by: Bob Peterson <rpeterso@redhat.com>
---
fs/gfs2/super.c | 115 +++++++++++++++++++++++++++++++-----------------
1 file changed, 75 insertions(+), 40 deletions(-)
diff --git a/fs/gfs2/super.c b/fs/gfs2/super.c
index 6f9e394d2a2e..82c79143681a 100644
--- a/fs/gfs2/super.c
+++ b/fs/gfs2/super.c
@@ -1350,91 +1350,126 @@ static int delete_evicted_inode(struct inode *inode)
}
/**
- * gfs2_evict_inode - Remove an inode from cache
+ * may_delete_evicted - determine whether the inode is eligible for deletion
* @inode: The inode to evict
*
- * There are three cases to consider:
- * 1. i_nlink == 0, we are final opener (and must deallocate)
- * 2. i_nlink == 0, we are not the final opener (and cannot deallocate)
- * 3. i_nlink > 0
+ * This function determines whether the evicted inode is eligible to be deleted
+ * and locks the inode glock.
*
- * If the fs is read only, then we have to treat all cases as per #3
- * since we are unable to do any deallocation. The inode will be
- * deallocated by the next read/write node to attempt an allocation
- * in the same resource group
- *
- * We have to (at the moment) hold the inodes main lock to cover
- * the gap between unlocking the shared lock on the iopen lock and
- * taking the exclusive lock. I'd rather do a shared -> exclusive
- * conversion on the iopen lock, but we can change that later. This
- * is safe, just less efficient.
+ * Returns: 1 if the dinode associated with this inode should be deleted
+ * 0 if the dinode should not be deleted, or
+ * -EEXIST if the decision must be deferred at this time.
*/
-
-static void gfs2_evict_inode(struct inode *inode)
+static int may_delete_evicted(struct inode *inode, struct gfs2_holder *gh)
{
+ struct gfs2_inode *ip = GFS2_I(inode);
struct super_block *sb = inode->i_sb;
struct gfs2_sbd *sdp = sb->s_fs_info;
- struct gfs2_inode *ip = GFS2_I(inode);
- struct gfs2_holder gh;
- struct address_space *metamapping;
int ret;
- if (test_bit(GIF_FREE_VFS_INODE, &ip->i_flags)) {
- clear_inode(inode);
- return;
- }
-
- if (inode->i_nlink || sb_rdonly(sb))
- goto out;
-
if (test_bit(GIF_ALLOC_FAILED, &ip->i_flags)) {
BUG_ON(!gfs2_glock_is_locked_by_me(ip->i_gl));
- gfs2_holder_mark_uninitialized(&gh);
- goto out_delete;
+ gfs2_holder_mark_uninitialized(gh);
+ goto may_delete;
}
if (test_bit(GIF_DEFERRED_DELETE, &ip->i_flags))
- goto out;
+ goto defer;
/* Deletes should never happen under memory pressure anymore. */
if (WARN_ON_ONCE(current->flags & PF_MEMALLOC))
- goto out;
+ goto defer;
/* Must not read inode block until block type has been verified */
- ret = gfs2_glock_nq_init(ip->i_gl, LM_ST_EXCLUSIVE, GL_SKIP, &gh);
+ ret = gfs2_glock_nq_init(ip->i_gl, LM_ST_EXCLUSIVE, GL_SKIP, gh);
if (unlikely(ret)) {
glock_clear_object(ip->i_iopen_gh.gh_gl, ip);
ip->i_iopen_gh.gh_flags |= GL_NOCACHE;
gfs2_glock_dq_uninit(&ip->i_iopen_gh);
- goto out;
+ goto defer;
}
if (gfs2_inode_already_deleted(ip->i_gl, ip->i_no_formal_ino))
- goto out_truncate;
+ goto may_not_delete;
ret = gfs2_check_blk_type(sdp, ip->i_no_addr, GFS2_BLKST_UNLINKED);
if (ret)
- goto out_truncate;
+ goto may_not_delete;
if (test_bit(GIF_INVALID, &ip->i_flags)) {
ret = gfs2_inode_refresh(ip);
if (ret)
- goto out_truncate;
+ goto may_not_delete;
}
/*
* The inode may have been recreated in the meantime.
*/
if (inode->i_nlink)
- goto out_truncate;
+ goto may_not_delete;
-out_delete:
+may_delete:
if (gfs2_holder_initialized(&ip->i_iopen_gh) &&
test_bit(HIF_HOLDER, &ip->i_iopen_gh.gh_iflags)) {
if (!gfs2_upgrade_iopen_glock(inode)) {
gfs2_holder_uninit(&ip->i_iopen_gh);
- goto out_truncate;
+ goto may_not_delete;
}
}
+ return 1;
+
+may_not_delete:
+ return 0;
+
+defer:
+ return -EEXIST;
+}
+
+/**
+ * gfs2_evict_inode - Remove an inode from cache
+ * @inode: The inode to evict
+ *
+ * There are three cases to consider:
+ * 1. i_nlink == 0, we are final opener (and must deallocate)
+ * 2. i_nlink == 0, we are not the final opener (and cannot deallocate)
+ * 3. i_nlink > 0
+ *
+ * If the fs is read only, then we have to treat all cases as per #3
+ * since we are unable to do any deallocation. The inode will be
+ * deallocated by the next read/write node to attempt an allocation
+ * in the same resource group
+ *
+ * We have to (at the moment) hold the inodes main lock to cover
+ * the gap between unlocking the shared lock on the iopen lock and
+ * taking the exclusive lock. I'd rather do a shared -> exclusive
+ * conversion on the iopen lock, but we can change that later. This
+ * is safe, just less efficient.
+ */
+
+static void gfs2_evict_inode(struct inode *inode)
+{
+ struct super_block *sb = inode->i_sb;
+ struct gfs2_sbd *sdp = sb->s_fs_info;
+ struct gfs2_inode *ip = GFS2_I(inode);
+ struct gfs2_holder gh;
+ struct address_space *metamapping;
+ int ret;
+
+ if (test_bit(GIF_FREE_VFS_INODE, &ip->i_flags)) {
+ clear_inode(inode);
+ return;
+ }
+
+ if (inode->i_nlink || sb_rdonly(sb))
+ goto out;
+
+ gfs2_holder_mark_uninitialized(&gh);
+ /* may_delete_evicted also locks the inode glock */
+ ret = may_delete_evicted(inode, &gh);
+ if (ret == -EEXIST)
+ goto out;
+ if (!ret)
+ goto out_truncate;
+
ret = delete_evicted_inode(inode);
goto out_unlock;
--
2.26.2
next prev parent reply other threads:[~2020-09-15 14:38 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-09-15 14:38 [Cluster-devel] [GFS2 PATCH 0/5] Refactor gfs2_evict_inode Bob Peterson
2020-09-15 14:38 ` [Cluster-devel] [GFS2 PATCH 1/5] gfs2: switch variable error to ret in gfs2_evict_inode Bob Peterson
2020-09-15 14:38 ` [Cluster-devel] [GFS2 PATCH 2/5] gfs2: factor delete_evicted_inode out of gfs2_evict_inode Bob Peterson
2020-09-15 19:08 ` Andreas Gruenbacher
2020-09-15 14:38 ` Bob Peterson [this message]
2020-09-15 19:09 ` [Cluster-devel] [GFS2 PATCH 3/5] gfs2: further simplify gfs2_evict_inode with new func may_delete_evicted Andreas Gruenbacher
2020-09-15 14:38 ` [Cluster-devel] [GFS2 PATCH 4/5] gfs2: factor out evict code related to dinodes we are not deleting Bob Peterson
2020-09-15 19:09 ` Andreas Gruenbacher
2020-09-15 14:38 ` [Cluster-devel] [GFS2 PATCH 5/5] gfs2: simplify the logic in gfs2_evict_inode Bob Peterson
2020-09-15 19:08 ` [Cluster-devel] [GFS2 PATCH 0/5] Refactor gfs2_evict_inode Andreas Gruenbacher
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200915143822.16485-4-rpeterso@redhat.com \
--to=rpeterso@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).