linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Andreas Gruenbacher <agruenba@redhat.com>
To: Alexander Viro <viro@zeniv.linux.org.uk>,
	Bob Peterson <rpeterso@redhat.com>,
	Steven Whitehouse <swhiteho@redhat.com>
Cc: Andreas Gruenbacher <agruenba@redhat.com>,
	cluster-devel@redhat.com, linux-fsdevel@vger.kernel.org
Subject: [PATCH 5/7] vfs: Introduce prepare_wait_on_freeing_inode
Date: Fri, 13 May 2016 19:42:27 +0200	[thread overview]
Message-ID: <1463161349-547-6-git-send-email-agruenba@redhat.com> (raw)
In-Reply-To: <1463161349-547-1-git-send-email-agruenba@redhat.com>

Add function prepare_wait_on_freeing_inode: during an inode lookup,
freeing an inode can require taking a lock that the filesystem already
holds.  The lock must be dropped before we can wait for the inode to go
away; waiting inside find_inode / find_inode_fast would deadlock.

In that case, filesystems can use find_inode_nowait.  When an inode that
is being freed is found, they can prepare to wait for the inode to go
away inside find_inode_nowait, then drop the conflicting lock and wait
outside of find_inode_nowait.

Signed-off-by: Andreas Gruenbacher <agruenba@redhat.com>
---
 fs/inode.c           | 17 ++++++++++++++---
 include/linux/fs.h   |  1 +
 include/linux/wait.h | 21 +++++++++++++++------
 3 files changed, 30 insertions(+), 9 deletions(-)

diff --git a/fs/inode.c b/fs/inode.c
index 69b8b52..2979a7f 100644
--- a/fs/inode.c
+++ b/fs/inode.c
@@ -1818,6 +1818,17 @@ int inode_needs_sync(struct inode *inode)
 }
 EXPORT_SYMBOL(inode_needs_sync);
 
+wait_queue_head_t *prepare_wait_on_freeing_inode(
+		struct inode *inode, struct wait_bit_queue *wait)
+{
+	wait_queue_head_t *wq = bit_waitqueue(&inode->i_state, __I_NEW);
+
+	init_wait_bit(wait, &inode->i_state, __I_NEW);
+	prepare_to_wait(wq, &wait->wait, TASK_UNINTERRUPTIBLE);
+	return wq;
+}
+EXPORT_SYMBOL(prepare_wait_on_freeing_inode);
+
 /*
  * If we try to find an inode in the inode hash while it is being
  * deleted, we have to wait until the filesystem completes its
@@ -1831,10 +1842,10 @@ EXPORT_SYMBOL(inode_needs_sync);
  */
 static void __wait_on_freeing_inode(struct inode *inode)
 {
+	struct wait_bit_queue wait;
 	wait_queue_head_t *wq;
-	DEFINE_WAIT_BIT(wait, &inode->i_state, __I_NEW);
-	wq = bit_waitqueue(&inode->i_state, __I_NEW);
-	prepare_to_wait(wq, &wait.wait, TASK_UNINTERRUPTIBLE);
+
+	wq = prepare_wait_on_freeing_inode(inode, &wait);
 	spin_unlock(&inode->i_lock);
 	spin_unlock(&inode_hash_lock);
 	schedule();
diff --git a/include/linux/fs.h b/include/linux/fs.h
index 70e61b5..7cdf365 100644
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
@@ -2629,6 +2629,7 @@ extern void address_space_init_once(struct address_space *mapping);
 extern struct inode * igrab(struct inode *);
 extern ino_t iunique(struct super_block *, ino_t);
 extern int inode_needs_sync(struct inode *inode);
+extern wait_queue_head_t *prepare_wait_on_freeing_inode(struct inode *inode, struct wait_bit_queue *wait);
 extern int generic_delete_inode(struct inode *inode);
 static inline int generic_drop_inode(struct inode *inode)
 {
diff --git a/include/linux/wait.h b/include/linux/wait.h
index 27d7a0a..45ef1d2 100644
--- a/include/linux/wait.h
+++ b/include/linux/wait.h
@@ -991,6 +991,14 @@ int wake_bit_function(wait_queue_t *wait, unsigned mode, int sync, void *key);
 
 #define DEFINE_WAIT(name) DEFINE_WAIT_FUNC(name, autoremove_wake_function)
 
+#define init_wait(wait)							\
+	do {								\
+		(wait)->private = current;				\
+		(wait)->func = autoremove_wake_function;		\
+		INIT_LIST_HEAD(&(wait)->task_list);			\
+		(wait)->flags = 0;					\
+	} while (0)
+
 #define DEFINE_WAIT_BIT(name, word, bit)				\
 	struct wait_bit_queue name = {					\
 		.key = __WAIT_BIT_KEY_INITIALIZER(word, bit),		\
@@ -1002,15 +1010,16 @@ int wake_bit_function(wait_queue_t *wait, unsigned mode, int sync, void *key);
 		},							\
 	}
 
-#define init_wait(wait)							\
+#define init_wait_bit(wbit, word, bit)					\
 	do {								\
-		(wait)->private = current;				\
-		(wait)->func = autoremove_wake_function;		\
-		INIT_LIST_HEAD(&(wait)->task_list);			\
-		(wait)->flags = 0;					\
+		(wbit)->key.flags = word;				\
+		(wbit)->key.bit_nr = bit;				\
+		(wbit)->wait.private = current;				\
+		(wbit)->wait.func = wake_bit_function;			\
+		INIT_LIST_HEAD(&(wbit)->wait.task_list);		\
+		(wbit)->wait.flags = 0;					\
 	} while (0)
 
-
 extern int bit_wait(struct wait_bit_key *, int);
 extern int bit_wait_io(struct wait_bit_key *, int);
 extern int bit_wait_timeout(struct wait_bit_key *, int);
-- 
2.5.5


  parent reply	other threads:[~2016-05-13 17:42 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-05-13 17:42 [PATCH 0/7] Allow lock dropping before waiting on inodes being freed Andreas Gruenbacher
2016-05-13 17:42 ` [PATCH 1/7] Revert "GFS2: Eliminate parameter non_block on gfs2_inode_lookup" Andreas Gruenbacher
2016-05-13 17:42 ` [PATCH 2/7] Revert "GFS2: Don't filter out I_FREEING inodes anymore" Andreas Gruenbacher
2016-05-13 17:42 ` [PATCH 3/7] GFS2: Remove superfluous assignment Andreas Gruenbacher
2016-05-13 17:42 ` [PATCH 4/7] GFS2: No need for non-blocking gfs2_ilookup in delete_work_func Andreas Gruenbacher
2016-05-13 17:42 ` Andreas Gruenbacher [this message]
2016-05-13 17:42 ` [PATCH 6/7] GFS2: Use non-blocking wait in gfs2_iget Andreas Gruenbacher
2016-05-13 17:42 ` [PATCH 7/7] GFS2: Prevent deadlock in gfs2_lookup_by_inum Andreas Gruenbacher
2016-05-16 12:14 ` [PATCH 0/7] Allow lock dropping before waiting on inodes being freed Andreas Gruenbacher
2016-05-31 16:45 ` 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=1463161349-547-6-git-send-email-agruenba@redhat.com \
    --to=agruenba@redhat.com \
    --cc=cluster-devel@redhat.com \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=rpeterso@redhat.com \
    --cc=swhiteho@redhat.com \
    --cc=viro@zeniv.linux.org.uk \
    /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).