Commit 8dcfaad2 authored by Theodore Ts'o's avatar Theodore Ts'o

ext4: start handle at the last possible moment in ext4_rmdir()

Don't start the jbd2 transaction handle until after the directory
entry has been found, to minimize the amount of time that a handle is
held active.
Signed-off-by: default avatar"Theodore Ts'o" <tytso@mit.edu>
Reviewed-by: default avatarJan Kara <jack@suse.cz>
parent 931b6864
...@@ -2725,26 +2725,18 @@ static int ext4_rmdir(struct inode *dir, struct dentry *dentry) ...@@ -2725,26 +2725,18 @@ static int ext4_rmdir(struct inode *dir, struct dentry *dentry)
struct inode *inode; struct inode *inode;
struct buffer_head *bh; struct buffer_head *bh;
struct ext4_dir_entry_2 *de; struct ext4_dir_entry_2 *de;
handle_t *handle; handle_t *handle = NULL;
/* Initialize quotas before so that eventual writes go in /* Initialize quotas before so that eventual writes go in
* separate transaction */ * separate transaction */
dquot_initialize(dir); dquot_initialize(dir);
dquot_initialize(dentry->d_inode); dquot_initialize(dentry->d_inode);
handle = ext4_journal_start(dir, EXT4_HT_DIR,
EXT4_DELETE_TRANS_BLOCKS(dir->i_sb));
if (IS_ERR(handle))
return PTR_ERR(handle);
retval = -ENOENT; retval = -ENOENT;
bh = ext4_find_entry(dir, &dentry->d_name, &de, NULL); bh = ext4_find_entry(dir, &dentry->d_name, &de, NULL);
if (!bh) if (!bh)
goto end_rmdir; goto end_rmdir;
if (IS_DIRSYNC(dir))
ext4_handle_sync(handle);
inode = dentry->d_inode; inode = dentry->d_inode;
retval = -EIO; retval = -EIO;
...@@ -2755,6 +2747,17 @@ static int ext4_rmdir(struct inode *dir, struct dentry *dentry) ...@@ -2755,6 +2747,17 @@ static int ext4_rmdir(struct inode *dir, struct dentry *dentry)
if (!empty_dir(inode)) if (!empty_dir(inode))
goto end_rmdir; goto end_rmdir;
handle = ext4_journal_start(dir, EXT4_HT_DIR,
EXT4_DELETE_TRANS_BLOCKS(dir->i_sb));
if (IS_ERR(handle)) {
retval = PTR_ERR(handle);
handle = NULL;
goto end_rmdir;
}
if (IS_DIRSYNC(dir))
ext4_handle_sync(handle);
retval = ext4_delete_entry(handle, dir, de, bh); retval = ext4_delete_entry(handle, dir, de, bh);
if (retval) if (retval)
goto end_rmdir; goto end_rmdir;
...@@ -2776,8 +2779,9 @@ static int ext4_rmdir(struct inode *dir, struct dentry *dentry) ...@@ -2776,8 +2779,9 @@ static int ext4_rmdir(struct inode *dir, struct dentry *dentry)
ext4_mark_inode_dirty(handle, dir); ext4_mark_inode_dirty(handle, dir);
end_rmdir: end_rmdir:
ext4_journal_stop(handle);
brelse(bh); brelse(bh);
if (handle)
ext4_journal_stop(handle);
return retval; return retval;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment