UPSTREAM: f2fs: add a fast path in finish_preallocate_blocks()
This patch uses i_sem to protect access/update on f2fs_inode_info.flag in finish_preallocate_blocks(), it avoids grabbing inode_lock() in each open(). Change-Id: Id1b88ced3367b13fa74740bd99a167473ab3d524 Signed-off-by: Chao Yu <chao@kernel.org> Reviewed-by: Zhiguo Niu <zhiguo.niu@unisoc.com> Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org> (cherry picked from commit ecf68ffee7be3f012c978e8e31d7b243af340f77)
This commit is contained in:
@@ -557,19 +557,21 @@ static int f2fs_file_mmap(struct file *file, struct vm_area_struct *vma)
|
||||
|
||||
static int finish_preallocate_blocks(struct inode *inode)
|
||||
{
|
||||
int ret;
|
||||
int ret = 0;
|
||||
bool opened;
|
||||
|
||||
f2fs_down_read(&F2FS_I(inode)->i_sem);
|
||||
opened = is_inode_flag_set(inode, FI_OPENED_FILE);
|
||||
f2fs_up_read(&F2FS_I(inode)->i_sem);
|
||||
if (opened)
|
||||
return 0;
|
||||
|
||||
inode_lock(inode);
|
||||
if (is_inode_flag_set(inode, FI_OPENED_FILE)) {
|
||||
inode_unlock(inode);
|
||||
return 0;
|
||||
}
|
||||
if (is_inode_flag_set(inode, FI_OPENED_FILE))
|
||||
goto out_unlock;
|
||||
|
||||
if (!file_should_truncate(inode)) {
|
||||
set_inode_flag(inode, FI_OPENED_FILE);
|
||||
inode_unlock(inode);
|
||||
return 0;
|
||||
}
|
||||
if (!file_should_truncate(inode))
|
||||
goto out_update;
|
||||
|
||||
f2fs_down_write(&F2FS_I(inode)->i_gc_rwsem[WRITE]);
|
||||
filemap_invalidate_lock(inode->i_mapping);
|
||||
@@ -579,16 +581,17 @@ static int finish_preallocate_blocks(struct inode *inode)
|
||||
|
||||
filemap_invalidate_unlock(inode->i_mapping);
|
||||
f2fs_up_write(&F2FS_I(inode)->i_gc_rwsem[WRITE]);
|
||||
|
||||
if (!ret)
|
||||
set_inode_flag(inode, FI_OPENED_FILE);
|
||||
|
||||
inode_unlock(inode);
|
||||
if (ret)
|
||||
return ret;
|
||||
goto out_unlock;
|
||||
|
||||
file_dont_truncate(inode);
|
||||
return 0;
|
||||
out_update:
|
||||
f2fs_down_write(&F2FS_I(inode)->i_sem);
|
||||
set_inode_flag(inode, FI_OPENED_FILE);
|
||||
f2fs_up_write(&F2FS_I(inode)->i_sem);
|
||||
out_unlock:
|
||||
inode_unlock(inode);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int f2fs_file_open(struct inode *inode, struct file *filp)
|
||||
|
||||
Reference in New Issue
Block a user