From 9e09fc855dd6f6ed510b3db7f3c3c1dd73631ac7 Mon Sep 17 00:00:00 2001 From: Jaegeuk Kim Date: Fri, 27 Dec 2013 12:28:59 +0900 Subject: f2fs: refactor f2fs_convert_inline_data Change log from v1: o handle NULL pointer of grab_cache_page_write_begin() pointed by Chao Yu. This patch refactors f2fs_convert_inline_data to check a couple of conditions internally for deciding whether it needs to convert inline_data or not. So, the new f2fs_convert_inline_data initially checks: 1) f2fs_has_inline_data(), and 2) the data size to be changed. If the inode has inline_data but the size to fill is less than MAX_INLINE_DATA, then we don't need to convert the inline_data with data allocation. Signed-off-by: Jaegeuk Kim --- fs/f2fs/file.c | 25 +++++++++---------------- 1 file changed, 9 insertions(+), 16 deletions(-) (limited to 'fs/f2fs/file.c') diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c index f64a1c8291af..68dd7bfce1a1 100644 --- a/fs/f2fs/file.c +++ b/fs/f2fs/file.c @@ -370,17 +370,12 @@ int f2fs_setattr(struct dentry *dentry, struct iattr *attr) if ((attr->ia_valid & ATTR_SIZE) && attr->ia_size != i_size_read(inode)) { - if (f2fs_has_inline_data(inode) && - (attr->ia_size > MAX_INLINE_DATA)) { - unsigned flags = AOP_FLAG_NOFS; - err = f2fs_convert_inline_data(inode, NULL, flags); - if (err) - return err; - } + err = f2fs_convert_inline_data(inode, attr->ia_size); + if (err) + return err; truncate_setsize(inode, attr->ia_size); - if (!f2fs_has_inline_data(inode)) - f2fs_truncate(inode); + f2fs_truncate(inode); f2fs_balance_fs(F2FS_SB(inode->i_sb)); } @@ -462,7 +457,7 @@ static int punch_hole(struct inode *inode, loff_t offset, loff_t len) loff_t off_start, off_end; int ret = 0; - ret = f2fs_convert_inline_data(inode, NULL, AOP_FLAG_NOFS); + ret = f2fs_convert_inline_data(inode, MAX_INLINE_DATA + 1); if (ret) return ret; @@ -512,16 +507,14 @@ static int expand_inode_data(struct inode *inode, loff_t offset, loff_t off_start, off_end; int ret = 0; - if (f2fs_has_inline_data(inode) && (offset + len > MAX_INLINE_DATA)) { - ret = f2fs_convert_inline_data(inode, NULL, AOP_FLAG_NOFS); - if (ret) - return ret; - } - ret = inode_newsize_ok(inode, (len + offset)); if (ret) return ret; + ret = f2fs_convert_inline_data(inode, offset + len); + if (ret) + return ret; + pg_start = ((unsigned long long) offset) >> PAGE_CACHE_SHIFT; pg_end = ((unsigned long long) offset + len) >> PAGE_CACHE_SHIFT; -- cgit v1.2.3