From: Bob Peterson <rpeterso@redhat.com>
To: cluster-devel.redhat.com
Subject: [Cluster-devel] [PATCH 06/11] GFS2: Prevent gl_delete work for re-used inodes
Date: Thu, 10 Sep 2015 14:49:46 -0500 [thread overview]
Message-ID: <1441914591-11949-7-git-send-email-rpeterso@redhat.com> (raw)
In-Reply-To: <1441914591-11949-1-git-send-email-rpeterso@redhat.com>
This patch adds a new glock flag GLF_INODE_DELETING which signifies
when a glock is being used to change an inode from unlinked to
deleted. The flag is used in a few places:
1. If an iopen callback is received, it checks the flag. If the bit
is set, someone else has already started deleting the inode.
In that case, the delete_func may already be running, so we don't
want to queue it to run another time. Doing so only gets us into
trouble.
2. When a dinode is in the process of being created, we've been
assigned that block by the allocator, so it must have been free.
At that point, we check if there is pending delete work pending,
and if so, we cancel it to prevent the block from being deleted
while we're creating it. This is necessary because there could
be pending delete work that was queued up a while ago, but the
delete work might have been done on another node, which is how
the block became freed. However, we keep the GLF_INODE_DELETING
set to prevent new delete work from being queued. After we're
done creating, we clear the bit, otherwise the file may not be
deleted ever again, even in legitimate cases in the future.
3. In function try_rgrp_unlink, we also make sure the bit isn't
already set before we try to reclaim an unlinked block.
---
fs/gfs2/glops.c | 3 ++-
fs/gfs2/incore.h | 1 +
fs/gfs2/inode.c | 21 ++++++++++++++++++++-
fs/gfs2/rgrp.c | 6 ++++++
4 files changed, 29 insertions(+), 2 deletions(-)
diff --git a/fs/gfs2/glops.c b/fs/gfs2/glops.c
index 1f6c9c3..b604343 100644
--- a/fs/gfs2/glops.c
+++ b/fs/gfs2/glops.c
@@ -553,7 +553,8 @@ static void iopen_go_callback(struct gfs2_glock *gl, bool remote)
return;
if (gl->gl_demote_state == LM_ST_UNLOCKED &&
- gl->gl_state == LM_ST_SHARED && ip) {
+ gl->gl_state == LM_ST_SHARED && ip &&
+ !test_and_set_bit(GLF_INODE_DELETING, &gl->gl_flags)) {
gl->gl_lockref.count++;
if (queue_work(gfs2_delete_workqueue, &gl->gl_delete) == 0)
gl->gl_lockref.count--;
diff --git a/fs/gfs2/incore.h b/fs/gfs2/incore.h
index 121ed08..5065e0c 100644
--- a/fs/gfs2/incore.h
+++ b/fs/gfs2/incore.h
@@ -326,6 +326,7 @@ enum {
GLF_LRU = 13,
GLF_OBJECT = 14, /* Used only for tracing */
GLF_BLOCKING = 15,
+ GLF_INODE_DELETING = 16, /* Was unlinked, being deleted */
};
struct gfs2_glock {
diff --git a/fs/gfs2/inode.c b/fs/gfs2/inode.c
index ce4b793..833f8fa 100644
--- a/fs/gfs2/inode.c
+++ b/fs/gfs2/inode.c
@@ -597,6 +597,7 @@ static int gfs2_create_inode(struct inode *dir, struct dentry *dentry,
int error, free_vfs_inode = 0;
u32 aflags = 0;
unsigned blocks = 1;
+ int delete_prevented = 0;
struct gfs2_diradd da = { .bh = NULL, .save_loc = 1, };
if (!name->len || name->len > GFS2_FNAMESIZE)
@@ -705,6 +706,17 @@ static int gfs2_create_inode(struct inode *dir, struct dentry *dentry,
if (error)
goto fail_free_inode;
+ /*
+ * Cancel any pending delete work for this glock. If there's pending
+ * delete work, we'd otherwise try to delete the dinode, but since we
+ * were assigned this address by alloc_dinode, the block is already
+ * free, so there's no need to attempt to change it from unlinked to
+ * free. We'd just get into trouble trying to do so. The biggest
+ * problem is having gfs2_delete_inode called while there pages
+ * still in existence due to a race between create and delete.
+ */
+ if (cancel_work_sync(&ip->i_gl->gl_delete))
+ delete_prevented = 1;
ip->i_gl->gl_object = ip;
error = gfs2_glock_nq_init(ip->i_gl, LM_ST_EXCLUSIVE, GL_SKIP, ghs + 1);
if (error)
@@ -762,6 +774,10 @@ static int gfs2_create_inode(struct inode *dir, struct dentry *dentry,
*opened |= FILE_CREATED;
error = finish_open(file, dentry, gfs2_open_common, opened);
}
+ if (delete_prevented) {
+ gfs2_glock_put(ip->i_gl); /* fix the gl reference count */
+ clear_bit(GLF_INODE_DELETING, &ip->i_gl->gl_flags);
+ }
gfs2_glock_dq_uninit(ghs);
gfs2_glock_dq_uninit(ghs + 1);
return error;
@@ -772,8 +788,11 @@ fail_gunlock3:
fail_gunlock2:
gfs2_glock_dq_uninit(ghs + 1);
fail_free_inode:
- if (ip->i_gl)
+ if (ip->i_gl) {
+ if (delete_prevented)
+ clear_bit(GLF_INODE_DELETING, &ip->i_gl->gl_flags);
gfs2_glock_put(ip->i_gl);
+ }
gfs2_rs_delete(ip, NULL);
fail_free_acls:
if (default_acl)
diff --git a/fs/gfs2/rgrp.c b/fs/gfs2/rgrp.c
index 475985d..b936ee1 100644
--- a/fs/gfs2/rgrp.c
+++ b/fs/gfs2/rgrp.c
@@ -1807,6 +1807,12 @@ static void try_rgrp_unlink(struct gfs2_rgrpd *rgd, u64 *last_unlinked, u64 skip
if (error)
continue;
+ /* Make sure we're not queuing a delete if someone else has */
+ if (test_and_set_bit(GLF_INODE_DELETING, &gl->gl_flags)) {
+ gfs2_glock_put(gl);
+ continue;
+ }
+
/* If the inode is already in cache, we can ignore it here
* because the existing inode disposal code will deal with
* it when all refs have gone away. Accessing gl_object like
--
2.4.3
next prev parent reply other threads:[~2015-09-10 19:49 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-09-10 19:49 [Cluster-devel] [PATCH 00/11] Eleven patches related to file unlink->delete->new Bob Peterson
2015-09-10 19:49 ` [Cluster-devel] [PATCH 01/11] GFS2: Update master statfs buffer with sd_statfs_spin locked Bob Peterson
2015-09-10 19:49 ` [Cluster-devel] [PATCH 02/11] GFS2: Allow fail_gunlock3 to set the free_vfs_inode bit Bob Peterson
2015-09-10 19:49 ` [Cluster-devel] [PATCH 03/11] GFS2: Protect log tail calculations with inside locks Bob Peterson
2015-09-10 19:49 ` [Cluster-devel] [PATCH 04/11] GFS2: Wait for iopen glock dequeues Bob Peterson
2015-09-10 19:49 ` [Cluster-devel] [PATCH 05/11] GFS2: Reintroduce a timeout in function gfs2_gl_hash_clear Bob Peterson
2015-09-10 19:49 ` Bob Peterson [this message]
2015-09-10 19:49 ` [Cluster-devel] [PATCH 07/11] GFS2: Truncate address space mapping when deleting an inode Bob Peterson
2015-09-10 19:49 ` [Cluster-devel] [PATCH 08/11] GFS2: Don't filter out I_FREEING inodes anymore Bob Peterson
2015-09-10 19:49 ` [Cluster-devel] [PATCH 09/11] GFS2: generalize gfs2_check_blk_type Bob Peterson
2015-09-10 19:49 ` [Cluster-devel] [PATCH 10/11] GFS2: Rework transition from unlinked to deleted dinodes Bob Peterson
2015-09-10 19:49 ` [Cluster-devel] [PATCH 11/11] GFS2: Change from tr_touched to tr_bufs Bob Peterson
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=1441914591-11949-7-git-send-email-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).