aboutsummaryrefslogtreecommitdiffstats
path: root/fs/ocfs2/file.c
diff options
context:
space:
mode:
authorJunxiao Bi <junxiao.bi@oracle.com>2014-10-09 18:25:15 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2014-10-09 22:25:48 -0400
commitf775da2fc2a8e42aa49eddbf5186ac3df8961a71 (patch)
treeadcebcd842d13b8678f164fd4f7de3618c90dca6 /fs/ocfs2/file.c
parent70e82a12dbfa3acbff41be08a36e8be4578878c9 (diff)
ocfs2: fix deadlock due to wrong locking order
For commit ocfs2 journal, ocfs2 journal thread will acquire the mutex osb->journal->j_trans_barrier and wake up jbd2 commit thread, then it will wait until jbd2 commit thread done. In order journal mode, jbd2 needs flushing dirty data pages first, and this needs get page lock. So osb->journal->j_trans_barrier should be got before page lock. But ocfs2_write_zero_page() and ocfs2_write_begin_inline() obey this locking order, and this will cause deadlock and hung the whole cluster. One deadlock catched is the following: PID: 13449 TASK: ffff8802e2f08180 CPU: 31 COMMAND: "oracle" #0 [ffff8802ee3f79b0] __schedule at ffffffff8150a524 #1 [ffff8802ee3f7a58] schedule at ffffffff8150acbf #2 [ffff8802ee3f7a68] rwsem_down_failed_common at ffffffff8150cb85 #3 [ffff8802ee3f7ad8] rwsem_down_read_failed at ffffffff8150cc55 #4 [ffff8802ee3f7ae8] call_rwsem_down_read_failed at ffffffff812617a4 #5 [ffff8802ee3f7b50] ocfs2_start_trans at ffffffffa0498919 [ocfs2] #6 [ffff8802ee3f7ba0] ocfs2_zero_start_ordered_transaction at ffffffffa048b2b8 [ocfs2] #7 [ffff8802ee3f7bf0] ocfs2_write_zero_page at ffffffffa048e9bd [ocfs2] #8 [ffff8802ee3f7c80] ocfs2_zero_extend_range at ffffffffa048ec83 [ocfs2] #9 [ffff8802ee3f7ce0] ocfs2_zero_extend at ffffffffa048edfd [ocfs2] #10 [ffff8802ee3f7d50] ocfs2_extend_file at ffffffffa049079e [ocfs2] #11 [ffff8802ee3f7da0] ocfs2_setattr at ffffffffa04910ed [ocfs2] #12 [ffff8802ee3f7e70] notify_change at ffffffff81187d29 #13 [ffff8802ee3f7ee0] do_truncate at ffffffff8116bbc1 #14 [ffff8802ee3f7f50] sys_ftruncate at ffffffff8116bcbd #15 [ffff8802ee3f7f80] system_call_fastpath at ffffffff81515142 RIP: 00007f8de750c6f7 RSP: 00007fffe786e478 RFLAGS: 00000206 RAX: 000000000000004d RBX: ffffffff81515142 RCX: 0000000000000000 RDX: 0000000000000200 RSI: 0000000000028400 RDI: 000000000000000d RBP: 00007fffe786e040 R8: 0000000000000000 R9: 000000000000000d R10: 0000000000000000 R11: 0000000000000206 R12: 000000000000000d R13: 00007fffe786e710 R14: 00007f8de70f8340 R15: 0000000000028400 ORIG_RAX: 000000000000004d CS: 0033 SS: 002b crash64> bt PID: 7610 TASK: ffff88100fd56140 CPU: 1 COMMAND: "ocfs2cmt" #0 [ffff88100f4d1c50] __schedule at ffffffff8150a524 #1 [ffff88100f4d1cf8] schedule at ffffffff8150acbf #2 [ffff88100f4d1d08] jbd2_log_wait_commit at ffffffffa01274fd [jbd2] #3 [ffff88100f4d1d98] jbd2_journal_flush at ffffffffa01280b4 [jbd2] #4 [ffff88100f4d1dd8] ocfs2_commit_cache at ffffffffa0499b14 [ocfs2] #5 [ffff88100f4d1e38] ocfs2_commit_thread at ffffffffa0499d38 [ocfs2] #6 [ffff88100f4d1ee8] kthread at ffffffff81090db6 #7 [ffff88100f4d1f48] kernel_thread_helper at ffffffff81516284 crash64> bt PID: 7609 TASK: ffff88100f2d4480 CPU: 0 COMMAND: "jbd2/dm-20-86" #0 [ffff88100def3920] __schedule at ffffffff8150a524 #1 [ffff88100def39c8] schedule at ffffffff8150acbf #2 [ffff88100def39d8] io_schedule at ffffffff8150ad6c #3 [ffff88100def39f8] sleep_on_page at ffffffff8111069e #4 [ffff88100def3a08] __wait_on_bit_lock at ffffffff8150b30a #5 [ffff88100def3a58] __lock_page at ffffffff81110687 #6 [ffff88100def3ab8] write_cache_pages at ffffffff8111b752 #7 [ffff88100def3be8] generic_writepages at ffffffff8111b901 #8 [ffff88100def3c48] journal_submit_data_buffers at ffffffffa0120f67 [jbd2] #9 [ffff88100def3cf8] jbd2_journal_commit_transaction at ffffffffa0121372[jbd2] #10 [ffff88100def3e68] kjournald2 at ffffffffa0127a86 [jbd2] #11 [ffff88100def3ee8] kthread at ffffffff81090db6 #12 [ffff88100def3f48] kernel_thread_helper at ffffffff81516284 Signed-off-by: Junxiao Bi <junxiao.bi@oracle.com> Cc: Mark Fasheh <mfasheh@suse.com> Cc: Joel Becker <jlbec@evilplan.org> Cc: Alex Chen <alex.chen@huawei.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'fs/ocfs2/file.c')
-rw-r--r--fs/ocfs2/file.c47
1 files changed, 23 insertions, 24 deletions
diff --git a/fs/ocfs2/file.c b/fs/ocfs2/file.c
index 2930e231f3f9..682732f3f0d8 100644
--- a/fs/ocfs2/file.c
+++ b/fs/ocfs2/file.c
@@ -760,7 +760,7 @@ static int ocfs2_write_zero_page(struct inode *inode, u64 abs_from,
760 struct address_space *mapping = inode->i_mapping; 760 struct address_space *mapping = inode->i_mapping;
761 struct page *page; 761 struct page *page;
762 unsigned long index = abs_from >> PAGE_CACHE_SHIFT; 762 unsigned long index = abs_from >> PAGE_CACHE_SHIFT;
763 handle_t *handle = NULL; 763 handle_t *handle;
764 int ret = 0; 764 int ret = 0;
765 unsigned zero_from, zero_to, block_start, block_end; 765 unsigned zero_from, zero_to, block_start, block_end;
766 struct ocfs2_dinode *di = (struct ocfs2_dinode *)di_bh->b_data; 766 struct ocfs2_dinode *di = (struct ocfs2_dinode *)di_bh->b_data;
@@ -769,11 +769,17 @@ static int ocfs2_write_zero_page(struct inode *inode, u64 abs_from,
769 BUG_ON(abs_to > (((u64)index + 1) << PAGE_CACHE_SHIFT)); 769 BUG_ON(abs_to > (((u64)index + 1) << PAGE_CACHE_SHIFT));
770 BUG_ON(abs_from & (inode->i_blkbits - 1)); 770 BUG_ON(abs_from & (inode->i_blkbits - 1));
771 771
772 handle = ocfs2_zero_start_ordered_transaction(inode, di_bh);
773 if (IS_ERR(handle)) {
774 ret = PTR_ERR(handle);
775 goto out;
776 }
777
772 page = find_or_create_page(mapping, index, GFP_NOFS); 778 page = find_or_create_page(mapping, index, GFP_NOFS);
773 if (!page) { 779 if (!page) {
774 ret = -ENOMEM; 780 ret = -ENOMEM;
775 mlog_errno(ret); 781 mlog_errno(ret);
776 goto out; 782 goto out_commit_trans;
777 } 783 }
778 784
779 /* Get the offsets within the page that we want to zero */ 785 /* Get the offsets within the page that we want to zero */
@@ -805,15 +811,6 @@ static int ocfs2_write_zero_page(struct inode *inode, u64 abs_from,
805 goto out_unlock; 811 goto out_unlock;
806 } 812 }
807 813
808 if (!handle) {
809 handle = ocfs2_zero_start_ordered_transaction(inode,
810 di_bh);
811 if (IS_ERR(handle)) {
812 ret = PTR_ERR(handle);
813 handle = NULL;
814 break;
815 }
816 }
817 814
818 /* must not update i_size! */ 815 /* must not update i_size! */
819 ret = block_commit_write(page, block_start + 1, 816 ret = block_commit_write(page, block_start + 1,
@@ -824,27 +821,29 @@ static int ocfs2_write_zero_page(struct inode *inode, u64 abs_from,
824 ret = 0; 821 ret = 0;
825 } 822 }
826 823
824 /*
825 * fs-writeback will release the dirty pages without page lock
826 * whose offset are over inode size, the release happens at
827 * block_write_full_page().
828 */
829 i_size_write(inode, abs_to);
830 inode->i_blocks = ocfs2_inode_sector_count(inode);
831 di->i_size = cpu_to_le64((u64)i_size_read(inode));
832 inode->i_mtime = inode->i_ctime = CURRENT_TIME;
833 di->i_mtime = di->i_ctime = cpu_to_le64(inode->i_mtime.tv_sec);
834 di->i_ctime_nsec = cpu_to_le32(inode->i_mtime.tv_nsec);
835 di->i_mtime_nsec = di->i_ctime_nsec;
827 if (handle) { 836 if (handle) {
828 /*
829 * fs-writeback will release the dirty pages without page lock
830 * whose offset are over inode size, the release happens at
831 * block_write_full_page().
832 */
833 i_size_write(inode, abs_to);
834 inode->i_blocks = ocfs2_inode_sector_count(inode);
835 di->i_size = cpu_to_le64((u64)i_size_read(inode));
836 inode->i_mtime = inode->i_ctime = CURRENT_TIME;
837 di->i_mtime = di->i_ctime = cpu_to_le64(inode->i_mtime.tv_sec);
838 di->i_ctime_nsec = cpu_to_le32(inode->i_mtime.tv_nsec);
839 di->i_mtime_nsec = di->i_ctime_nsec;
840 ocfs2_journal_dirty(handle, di_bh); 837 ocfs2_journal_dirty(handle, di_bh);
841 ocfs2_update_inode_fsync_trans(handle, inode, 1); 838 ocfs2_update_inode_fsync_trans(handle, inode, 1);
842 ocfs2_commit_trans(OCFS2_SB(inode->i_sb), handle);
843 } 839 }
844 840
845out_unlock: 841out_unlock:
846 unlock_page(page); 842 unlock_page(page);
847 page_cache_release(page); 843 page_cache_release(page);
844out_commit_trans:
845 if (handle)
846 ocfs2_commit_trans(OCFS2_SB(inode->i_sb), handle);
848out: 847out:
849 return ret; 848 return ret;
850} 849}