add patch fix-type-declaration-of-ext4_validate_block_bitmap
[ext4-patch-queue.git] / start-handle-later-in-ext4-rename
blobf101c5b936bb093948c93a34a845652da6e33bbf
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>
7 ---
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
13 --- a/fs/ext4/namei.c
14 +++ b/fs/ext4/namei.c
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)
18  {
19 -       handle_t *handle;
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));
31 -       if (IS_ERR(handle))
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);
38         /*
39 @@ -3012,6 +3004,16 @@ static int ext4_rename(struct inode *old_dir, struct dentry *old_dentry,
40                         new_bh = NULL;
41                 }
42         }
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));
47 +       if (IS_ERR(handle))
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)) {
54                 if (new_inode) {
55                         retval = -ENOTEMPTY;
56 @@ -3151,7 +3153,8 @@ end_rename:
57         brelse(dir_bh);
58         brelse(old_bh);
59         brelse(new_bh);
60 -       ext4_journal_stop(handle);
61 +       if (handle)
62 +               ext4_journal_stop(handle);
63         if (retval == 0 && force_da_alloc)
64                 ext4_alloc_da_blocks(old_inode);
65         return retval;