Thread (24 messages) 24 messages, 7 authors, 2012-01-12
STALE5251d REVIEWED: 1 (0M)
Revisions (2)
  1. resend [diff vs current]
  2. v2 current

[PATCH v2 5/7] VFS: Avoid read-write deadlock in try_to_writeback_inodes_sb

From: Kamal Mostafa <hidden>
Date: 2011-12-08 18:04:35
Also in: linux-fsdevel, lkml
Subsystem: filesystems (vfs and infrastructure), the rest · Maintainers: Alexander Viro, Christian Brauner, Linus Torvalds

From: Valerie Aurora <redacted>

Use trylock in try_to_writeback_inodes_sb to avoid read-write
deadlocks that could be triggered by freeze.

BugLink: https://bugs.launchpad.net/bugs/897421
Signed-off-by: Valerie Aurora <redacted>
Cc: Kamal Mostafa <redacted>
Tested-by: Peter M. Petrakis <redacted>
[kamal@canonical.com: patch restructure]
Signed-off-by: Kamal Mostafa <redacted>
---
 fs/fs-writeback.c |   13 ++++++++-----
 1 files changed, 8 insertions(+), 5 deletions(-)
diff --git a/fs/fs-writeback.c b/fs/fs-writeback.c
index ea89b3f..3a80f1b 100644
--- a/fs/fs-writeback.c
+++ b/fs/fs-writeback.c
@@ -1274,8 +1274,9 @@ EXPORT_SYMBOL(writeback_inodes_sb);
  * try_to_writeback_inodes_sb	-	start writeback if none underway
  * @sb: the superblock
  *
- * Invoke writeback_inodes_sb if no writeback is currently underway.
- * Returns 1 if writeback was started, 0 if not.
+ * Invoke writeback_inodes_sb if no writeback is currently underway
+ * and no one else holds the s_umount lock.  Returns 1 if writeback
+ * was started, 0 if not.
  */
 int try_to_writeback_inodes_sb(struct super_block *sb, enum wb_reason reason)
 {
@@ -1288,15 +1289,17 @@ EXPORT_SYMBOL(try_to_writeback_inodes_sb);
  * @sb: the superblock
  * @nr: the number of pages to write
  *
- * Invoke writeback_inodes_sb if no writeback is currently underway.
- * Returns 1 if writeback was started, 0 if not.
+ * Invoke writeback_inodes_sb if no writeback is currently underway
+ * and no one else holds the s_umount lock.  Returns 1 if writeback
+ * was started, 0 if not.
  */
 int try_to_writeback_inodes_sb_nr(struct super_block *sb,
 				   unsigned long nr,
 				   enum wb_reason reason)
 {
 	if (!writeback_in_progress(sb->s_bdi)) {
-		down_read(&sb->s_umount);
+		if (!down_read_trylock(&sb->s_umount))
+		    return 0;
 		if (nr == 0)
 			writeback_inodes_sb(sb, reason);
 		else
-- 
1.7.5.4
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help