1 ext4: start handle at least possible moment when renaming files
3 In ext4_rename(), don't start the journal handle until the the
4 directory entries have been successfully looked up.
6 Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
8 fs/ext4/namei.c | 23 +++++++++++++----------
9 1 file changed, 13 insertions(+), 10 deletions(-)
11 diff --git a/fs/ext4/namei.c b/fs/ext4/namei.c
12 index ab2f6dc..f57980c 100644
15 @@ -2965,7 +2965,7 @@ static struct buffer_head *ext4_get_first_dir_block(handle_t *handle,
16 static int ext4_rename(struct inode *old_dir, struct dentry *old_dentry,
17 struct inode *new_dir, struct dentry *new_dentry)
20 + handle_t *handle = NULL;
21 struct inode *old_inode, *new_inode;
22 struct buffer_head *old_bh, *new_bh, *dir_bh;
23 struct ext4_dir_entry_2 *old_de, *new_de;
24 @@ -2982,14 +2982,6 @@ static int ext4_rename(struct inode *old_dir, struct dentry *old_dentry,
25 * in separate transaction */
26 if (new_dentry->d_inode)
27 dquot_initialize(new_dentry->d_inode);
28 - handle = ext4_journal_start(old_dir, EXT4_HT_DIR,
29 - (2 * EXT4_DATA_TRANS_BLOCKS(old_dir->i_sb) +
30 - EXT4_INDEX_EXTRA_TRANS_BLOCKS + 2));
32 - return PTR_ERR(handle);
34 - if (IS_DIRSYNC(old_dir) || IS_DIRSYNC(new_dir))
35 - ext4_handle_sync(handle);
37 old_bh = ext4_find_entry(old_dir, &old_dentry->d_name, &old_de, NULL);
39 @@ -3012,6 +3004,16 @@ static int ext4_rename(struct inode *old_dir, struct dentry *old_dentry,
44 + handle = ext4_journal_start(old_dir, EXT4_HT_DIR,
45 + (2 * EXT4_DATA_TRANS_BLOCKS(old_dir->i_sb) +
46 + EXT4_INDEX_EXTRA_TRANS_BLOCKS + 2));
48 + return PTR_ERR(handle);
50 + if (IS_DIRSYNC(old_dir) || IS_DIRSYNC(new_dir))
51 + ext4_handle_sync(handle);
53 if (S_ISDIR(old_inode->i_mode)) {
56 @@ -3151,7 +3153,8 @@ end_rename:
60 - ext4_journal_stop(handle);
62 + ext4_journal_stop(handle);
63 if (retval == 0 && force_da_alloc)
64 ext4_alloc_da_blocks(old_inode);