aboutsummaryrefslogtreecommitdiffstats
path: root/fs/ext4/extents.c
diff options
context:
space:
mode:
authorJan Kara <jack@suse.cz>2008-07-11 19:27:31 -0400
committerTheodore Ts'o <tytso@mit.edu>2008-07-11 19:27:31 -0400
commit9ddfc3dc75b5cc55ff3cfa586e962d252f1db9d3 (patch)
tree4932f75d2f303561b0038fb5ea8985345b3ccd6b /fs/ext4/extents.c
parentcf108bca465dde0c015f32dd453b99457d31c7c7 (diff)
ext4: Fix lock inversion in ext4_ext_truncate()
We cannot call ext4_orphan_add() from under i_data_sem because that causes a lock ordering violation between i_data_sem and and the superblock lock. Updated with Aneesh's locking order fix Signed-off-by: Jan Kara <jack@suse.cz> Signed-off-by: Mingming Cao <cmm@us.ibm.com> Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com> Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
Diffstat (limited to 'fs/ext4/extents.c')
-rw-r--r--fs/ext4/extents.c7
1 files changed, 4 insertions, 3 deletions
diff --git a/fs/ext4/extents.c b/fs/ext4/extents.c
index b722bce7d662..7844bbb2bac0 100644
--- a/fs/ext4/extents.c
+++ b/fs/ext4/extents.c
@@ -2768,6 +2768,9 @@ void ext4_ext_truncate(struct inode *inode)
2768 if (inode->i_size & (sb->s_blocksize - 1)) 2768 if (inode->i_size & (sb->s_blocksize - 1))
2769 ext4_block_truncate_page(handle, mapping, inode->i_size); 2769 ext4_block_truncate_page(handle, mapping, inode->i_size);
2770 2770
2771 if (ext4_orphan_add(handle, inode))
2772 goto out_stop;
2773
2771 down_write(&EXT4_I(inode)->i_data_sem); 2774 down_write(&EXT4_I(inode)->i_data_sem);
2772 ext4_ext_invalidate_cache(inode); 2775 ext4_ext_invalidate_cache(inode);
2773 2776
@@ -2778,8 +2781,6 @@ void ext4_ext_truncate(struct inode *inode)
2778 * Probably we need not scan at all, 2781 * Probably we need not scan at all,
2779 * because page truncation is enough. 2782 * because page truncation is enough.
2780 */ 2783 */
2781 if (ext4_orphan_add(handle, inode))
2782 goto out_stop;
2783 2784
2784 /* we have to know where to truncate from in crash case */ 2785 /* we have to know where to truncate from in crash case */
2785 EXT4_I(inode)->i_disksize = inode->i_size; 2786 EXT4_I(inode)->i_disksize = inode->i_size;
@@ -2796,6 +2797,7 @@ void ext4_ext_truncate(struct inode *inode)
2796 handle->h_sync = 1; 2797 handle->h_sync = 1;
2797 2798
2798out_stop: 2799out_stop:
2800 up_write(&EXT4_I(inode)->i_data_sem);
2799 /* 2801 /*
2800 * If this was a simple ftruncate() and the file will remain alive, 2802 * If this was a simple ftruncate() and the file will remain alive,
2801 * then we need to clear up the orphan record which we created above. 2803 * then we need to clear up the orphan record which we created above.
@@ -2806,7 +2808,6 @@ out_stop:
2806 if (inode->i_nlink) 2808 if (inode->i_nlink)
2807 ext4_orphan_del(handle, inode); 2809 ext4_orphan_del(handle, inode);
2808 2810
2809 up_write(&EXT4_I(inode)->i_data_sem);
2810 inode->i_mtime = inode->i_ctime = ext4_current_time(inode); 2811 inode->i_mtime = inode->i_ctime = ext4_current_time(inode);
2811 ext4_mark_inode_dirty(handle, inode); 2812 ext4_mark_inode_dirty(handle, inode);
2812 ext4_journal_stop(handle); 2813 ext4_journal_stop(handle);