Commit 931b6864 authored by Theodore Ts'o's avatar Theodore Ts'o

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

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 47564bfb
...@@ -2787,7 +2787,7 @@ static int ext4_unlink(struct inode *dir, struct dentry *dentry) ...@@ -2787,7 +2787,7 @@ static int ext4_unlink(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;
trace_ext4_unlink_enter(dir, dentry); trace_ext4_unlink_enter(dir, dentry);
/* Initialize quotas before so that eventual writes go /* Initialize quotas before so that eventual writes go
...@@ -2795,14 +2795,6 @@ static int ext4_unlink(struct inode *dir, struct dentry *dentry) ...@@ -2795,14 +2795,6 @@ static int ext4_unlink(struct inode *dir, struct dentry *dentry)
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);
if (IS_DIRSYNC(dir))
ext4_handle_sync(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)
...@@ -2814,6 +2806,17 @@ static int ext4_unlink(struct inode *dir, struct dentry *dentry) ...@@ -2814,6 +2806,17 @@ static int ext4_unlink(struct inode *dir, struct dentry *dentry)
if (le32_to_cpu(de->inode) != inode->i_ino) if (le32_to_cpu(de->inode) != inode->i_ino)
goto end_unlink; goto end_unlink;
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_unlink;
}
if (IS_DIRSYNC(dir))
ext4_handle_sync(handle);
if (!inode->i_nlink) { if (!inode->i_nlink) {
ext4_warning(inode->i_sb, ext4_warning(inode->i_sb,
"Deleting nonexistent file (%lu), %d", "Deleting nonexistent file (%lu), %d",
...@@ -2834,8 +2837,9 @@ static int ext4_unlink(struct inode *dir, struct dentry *dentry) ...@@ -2834,8 +2837,9 @@ static int ext4_unlink(struct inode *dir, struct dentry *dentry)
retval = 0; retval = 0;
end_unlink: end_unlink:
ext4_journal_stop(handle);
brelse(bh); brelse(bh);
if (handle)
ext4_journal_stop(handle);
trace_ext4_unlink_exit(dentry, retval); trace_ext4_unlink_exit(dentry, retval);
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