Commit a0d00fad authored by Chao Yu's avatar Chao Yu Committed by Jaegeuk Kim

f2fs: fix to avoid race when accessing last_disk_size

last_disk_size could be wrong due to concurrently updating, so using
i_sem semaphore to make last_disk_size updating exclusive to fix this
issue.
Signed-off-by: default avatarChao Yu <yuchao0@huawei.com>
Signed-off-by: default avatarJaegeuk Kim <jaegeuk@kernel.org>
parent ebf7c522
...@@ -1570,8 +1570,11 @@ static int __write_data_page(struct page *page, bool *submitted, ...@@ -1570,8 +1570,11 @@ static int __write_data_page(struct page *page, bool *submitted,
err = do_write_data_page(&fio); err = do_write_data_page(&fio);
} }
} }
down_write(&F2FS_I(inode)->i_sem);
if (F2FS_I(inode)->last_disk_size < psize) if (F2FS_I(inode)->last_disk_size < psize)
F2FS_I(inode)->last_disk_size = psize; F2FS_I(inode)->last_disk_size = psize;
up_write(&F2FS_I(inode)->i_sem);
done: done:
if (err && err != -ENOENT) if (err && err != -ENOENT)
......
...@@ -2284,9 +2284,10 @@ static inline void clear_file(struct inode *inode, int type) ...@@ -2284,9 +2284,10 @@ static inline void clear_file(struct inode *inode, int type)
static inline bool f2fs_skip_inode_update(struct inode *inode, int dsync) static inline bool f2fs_skip_inode_update(struct inode *inode, int dsync)
{ {
bool ret;
if (dsync) { if (dsync) {
struct f2fs_sb_info *sbi = F2FS_I_SB(inode); struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
bool ret;
spin_lock(&sbi->inode_lock[DIRTY_META]); spin_lock(&sbi->inode_lock[DIRTY_META]);
ret = list_empty(&F2FS_I(inode)->gdirty_list); ret = list_empty(&F2FS_I(inode)->gdirty_list);
...@@ -2297,7 +2298,12 @@ static inline bool f2fs_skip_inode_update(struct inode *inode, int dsync) ...@@ -2297,7 +2298,12 @@ static inline bool f2fs_skip_inode_update(struct inode *inode, int dsync)
file_keep_isize(inode) || file_keep_isize(inode) ||
i_size_read(inode) & PAGE_MASK) i_size_read(inode) & PAGE_MASK)
return false; return false;
return F2FS_I(inode)->last_disk_size == i_size_read(inode);
down_read(&F2FS_I(inode)->i_sem);
ret = F2FS_I(inode)->last_disk_size == i_size_read(inode);
up_read(&F2FS_I(inode)->i_sem);
return ret;
} }
static inline int f2fs_readonly(struct super_block *sb) static inline int f2fs_readonly(struct super_block *sb)
......
...@@ -777,6 +777,10 @@ int f2fs_setattr(struct dentry *dentry, struct iattr *attr) ...@@ -777,6 +777,10 @@ int f2fs_setattr(struct dentry *dentry, struct iattr *attr)
inode->i_mtime = inode->i_ctime = current_time(inode); inode->i_mtime = inode->i_ctime = current_time(inode);
} }
down_write(&F2FS_I(inode)->i_sem);
F2FS_I(inode)->last_disk_size = i_size_read(inode);
up_write(&F2FS_I(inode)->i_sem);
size_changed = true; size_changed = true;
} }
......
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