aboutsummaryrefslogtreecommitdiffstats
path: root/fs
diff options
context:
space:
mode:
authorMiao Xie <miaox@cn.fujitsu.com>2013-02-07 01:01:35 -0500
committerJosef Bacik <jbacik@fusionio.com>2013-02-20 12:59:40 -0500
commit2b8195bb5717729e4e94ab4ad73a543feaafb0a2 (patch)
treed4b369f7e7dcf35b6023282d8fdac001f67cb847 /fs
parentcb95e7bf7ba481c3d35b238b1cd671b63f54238a (diff)
Btrfs: fix the race between bio and btrfs_stop_workers
open_ctree() need read the metadata to initialize the global information of btrfs. But it may fail after it submit some bio, and then it will jump to the error path. Unfortunately, it doesn't check if there are some bios in flight, and just stop all the worker threads. As a result, when the submitted bios end, they can not find any worker thread which can deal with subsequent work, then oops happen. kernel BUG at fs/btrfs/async-thread.c:605! Fix this problem by invoking invalidate_inode_pages2() before we stop the worker threads. This function will wait until the bio end because it need lock the pages which are going to be invalidated, and if a page is under disk read IO, it must be locked. invalidate_inode_pages2() need wait until end bio handler to unlocked it. Reported-and-Tested-by: Tsutomu Itoh <t-itoh@jp.fujitsu.com> Signed-off-by: Eric Sandeen <sandeen@redhat.com> Signed-off-by: Miao Xie <miaox@cn.fujitsu.com> Signed-off-by: Josef Bacik <jbacik@fusionio.com>
Diffstat (limited to 'fs')
-rw-r--r--fs/btrfs/disk-io.c3
1 files changed, 1 insertions, 2 deletions
diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c
index 259d7891d10c..9fcce54ecde4 100644
--- a/fs/btrfs/disk-io.c
+++ b/fs/btrfs/disk-io.c
@@ -2711,13 +2711,13 @@ fail_cleaner:
2711 * kthreads 2711 * kthreads
2712 */ 2712 */
2713 filemap_write_and_wait(fs_info->btree_inode->i_mapping); 2713 filemap_write_and_wait(fs_info->btree_inode->i_mapping);
2714 invalidate_inode_pages2(fs_info->btree_inode->i_mapping);
2715 2714
2716fail_block_groups: 2715fail_block_groups:
2717 btrfs_free_block_groups(fs_info); 2716 btrfs_free_block_groups(fs_info);
2718 2717
2719fail_tree_roots: 2718fail_tree_roots:
2720 free_root_pointers(fs_info, 1); 2719 free_root_pointers(fs_info, 1);
2720 invalidate_inode_pages2(fs_info->btree_inode->i_mapping);
2721 2721
2722fail_sb_buffer: 2722fail_sb_buffer:
2723 btrfs_stop_workers(&fs_info->generic_worker); 2723 btrfs_stop_workers(&fs_info->generic_worker);
@@ -2738,7 +2738,6 @@ fail_alloc:
2738fail_iput: 2738fail_iput:
2739 btrfs_mapping_tree_free(&fs_info->mapping_tree); 2739 btrfs_mapping_tree_free(&fs_info->mapping_tree);
2740 2740
2741 invalidate_inode_pages2(fs_info->btree_inode->i_mapping);
2742 iput(fs_info->btree_inode); 2741 iput(fs_info->btree_inode);
2743fail_delalloc_bytes: 2742fail_delalloc_bytes:
2744 percpu_counter_destroy(&fs_info->delalloc_bytes); 2743 percpu_counter_destroy(&fs_info->delalloc_bytes);