1 ext4: add i_data_sem sanity check
3 From: Dmitry Monakhov <dmonakhov@openvz.org>
5 Each caller of ext4_ext_dirty must hold i_data_sem,
6 The only exception is migration code, let's make it convenient.
8 Signed-off-by: Dmitry Monakhov <dmonakhov@openvz.org>
9 Signed-off-by: Theodore Ts'o <tytso@mit.edu>
10 Reviewed-by: Jan Kara <jack@suse.cz>
12 fs/ext4/extents.c | 2 ++
13 fs/ext4/migrate.c | 7 +++++++
14 2 files changed, 9 insertions(+), 0 deletions(-)
16 diff --git a/fs/ext4/extents.c b/fs/ext4/extents.c
17 index b30172d..ee93f82 100644
18 --- a/fs/ext4/extents.c
19 +++ b/fs/ext4/extents.c
20 @@ -161,6 +161,8 @@ int __ext4_ext_dirty(const char *where, unsigned int line, handle_t *handle,
21 struct inode *inode, struct ext4_ext_path *path)
25 + WARN_ON(!rwsem_is_locked(&EXT4_I(inode)->i_data_sem));
27 ext4_extent_block_csum_set(inode, ext_block_hdr(path->p_bh));
28 /* path points to block */
29 diff --git a/fs/ext4/migrate.c b/fs/ext4/migrate.c
30 index ec09243..d3567f2 100644
31 --- a/fs/ext4/migrate.c
32 +++ b/fs/ext4/migrate.c
33 @@ -39,6 +39,8 @@ static int finish_range(handle_t *handle, struct inode *inode,
34 newext.ee_block = cpu_to_le32(lb->first_block);
35 newext.ee_len = cpu_to_le16(lb->last_block - lb->first_block + 1);
36 ext4_ext_store_pblock(&newext, lb->first_pblock);
37 + /* Locking only for convinience since we are operating on temp inode */
38 + down_write(&EXT4_I(inode)->i_data_sem);
39 path = ext4_ext_find_extent(inode, lb->first_block, NULL, 0);
42 @@ -61,7 +63,9 @@ static int finish_range(handle_t *handle, struct inode *inode,
44 if (needed && ext4_handle_has_enough_credits(handle,
45 EXT4_RESERVE_TRANS_BLOCKS)) {
46 + up_write((&EXT4_I(inode)->i_data_sem));
47 retval = ext4_journal_restart(handle, needed);
48 + down_write((&EXT4_I(inode)->i_data_sem));
52 @@ -70,13 +74,16 @@ static int finish_range(handle_t *handle, struct inode *inode,
54 * IF not able to extend the journal restart the journal
56 + up_write((&EXT4_I(inode)->i_data_sem));
57 retval = ext4_journal_restart(handle, needed);
58 + down_write((&EXT4_I(inode)->i_data_sem));
63 retval = ext4_ext_insert_extent(handle, inode, path, &newext, 0);
65 + up_write((&EXT4_I(inode)->i_data_sem));
67 ext4_ext_drop_refs(path);
73 To unsubscribe from this list: send the line "unsubscribe linux-ext4" in
74 the body of a message to majordomo@vger.kernel.org
75 More majordomo info at http://vger.kernel.org/majordomo-info.html