aboutsummaryrefslogtreecommitdiffstats
path: root/fs/btrfs/disk-io.c
diff options
context:
space:
mode:
authorChris Mason <chris.mason@oracle.com>2011-11-01 10:08:06 -0400
committerChris Mason <chris.mason@oracle.com>2011-11-06 03:03:48 -0500
commit01d658f2ca3c85c1ffb20b306e30d16197000ce7 (patch)
treeeda62586bb95967a4001f8fb70e6955b531cf801 /fs/btrfs/disk-io.c
parente688b7252f784c2479d559f9f70ca8354752c5e7 (diff)
Btrfs: make sure to flush queued bios if write_cache_pages waits
write_cache_pages tries to build up a large bio to stuff down the pipe. But if it needs to wait for a page lock, it needs to make sure and send down any pending writes so we don't deadlock with anyone who has the page lock and is waiting for writeback of things inside the bio. Dave Sterba triggered this as a deadlock between the autodefrag code and the extent write_cache_pages Signed-off-by: Chris Mason <chris.mason@oracle.com>
Diffstat (limited to 'fs/btrfs/disk-io.c')
-rw-r--r--fs/btrfs/disk-io.c13
1 files changed, 10 insertions, 3 deletions
diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c
index 51372a521167..6f58911ece0d 100644
--- a/fs/btrfs/disk-io.c
+++ b/fs/btrfs/disk-io.c
@@ -2735,7 +2735,8 @@ int btrfs_read_buffer(struct extent_buffer *buf, u64 parent_transid)
2735 return ret; 2735 return ret;
2736} 2736}
2737 2737
2738int btree_lock_page_hook(struct page *page) 2738static int btree_lock_page_hook(struct page *page, void *data,
2739 void (*flush_fn)(void *))
2739{ 2740{
2740 struct inode *inode = page->mapping->host; 2741 struct inode *inode = page->mapping->host;
2741 struct btrfs_root *root = BTRFS_I(inode)->root; 2742 struct btrfs_root *root = BTRFS_I(inode)->root;
@@ -2752,7 +2753,10 @@ int btree_lock_page_hook(struct page *page)
2752 if (!eb) 2753 if (!eb)
2753 goto out; 2754 goto out;
2754 2755
2755 btrfs_tree_lock(eb); 2756 if (!btrfs_try_tree_write_lock(eb)) {
2757 flush_fn(data);
2758 btrfs_tree_lock(eb);
2759 }
2756 btrfs_set_header_flag(eb, BTRFS_HEADER_FLAG_WRITTEN); 2760 btrfs_set_header_flag(eb, BTRFS_HEADER_FLAG_WRITTEN);
2757 2761
2758 if (test_and_clear_bit(EXTENT_BUFFER_DIRTY, &eb->bflags)) { 2762 if (test_and_clear_bit(EXTENT_BUFFER_DIRTY, &eb->bflags)) {
@@ -2767,7 +2771,10 @@ int btree_lock_page_hook(struct page *page)
2767 btrfs_tree_unlock(eb); 2771 btrfs_tree_unlock(eb);
2768 free_extent_buffer(eb); 2772 free_extent_buffer(eb);
2769out: 2773out:
2770 lock_page(page); 2774 if (!trylock_page(page)) {
2775 flush_fn(data);
2776 lock_page(page);
2777 }
2771 return 0; 2778 return 0;
2772} 2779}
2773 2780