Commit 9e09fc85 authored by Jaegeuk Kim's avatar Jaegeuk Kim

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: default avatarJaegeuk Kim <jaegeuk.kim@samsung.com>
parent 26f466f4
...@@ -906,21 +906,17 @@ static int f2fs_write_begin(struct file *file, struct address_space *mapping, ...@@ -906,21 +906,17 @@ static int f2fs_write_begin(struct file *file, struct address_space *mapping,
f2fs_balance_fs(sbi); f2fs_balance_fs(sbi);
repeat: repeat:
err = f2fs_convert_inline_data(inode, pos + len);
if (err)
return err;
page = grab_cache_page_write_begin(mapping, index, flags); page = grab_cache_page_write_begin(mapping, index, flags);
if (!page) if (!page)
return -ENOMEM; return -ENOMEM;
*pagep = page; *pagep = page;
if ((pos + len) < MAX_INLINE_DATA) { if (f2fs_has_inline_data(inode) && (pos + len) <= MAX_INLINE_DATA)
if (f2fs_has_inline_data(inode)) goto inline_data;
goto inline_data;
} else if (f2fs_has_inline_data(inode)) {
err = f2fs_convert_inline_data(inode, page, flags);
if (err) {
f2fs_put_page(page, 1);
return err;
}
}
f2fs_lock_op(sbi); f2fs_lock_op(sbi);
set_new_dnode(&dn, inode, NULL, NULL, 0); set_new_dnode(&dn, inode, NULL, NULL, 0);
......
...@@ -1302,6 +1302,6 @@ extern const struct inode_operations f2fs_special_inode_operations; ...@@ -1302,6 +1302,6 @@ extern const struct inode_operations f2fs_special_inode_operations;
inline int f2fs_has_inline_data(struct inode *); inline int f2fs_has_inline_data(struct inode *);
bool f2fs_may_inline(struct inode *); bool f2fs_may_inline(struct inode *);
int f2fs_read_inline_data(struct inode *, struct page *); int f2fs_read_inline_data(struct inode *, struct page *);
int f2fs_convert_inline_data(struct inode *, struct page *, unsigned); int f2fs_convert_inline_data(struct inode *, pgoff_t);
int f2fs_write_inline_data(struct inode *, struct page *, unsigned int); int f2fs_write_inline_data(struct inode *, struct page *, unsigned int);
#endif #endif
...@@ -370,17 +370,12 @@ int f2fs_setattr(struct dentry *dentry, struct iattr *attr) ...@@ -370,17 +370,12 @@ int f2fs_setattr(struct dentry *dentry, struct iattr *attr)
if ((attr->ia_valid & ATTR_SIZE) && if ((attr->ia_valid & ATTR_SIZE) &&
attr->ia_size != i_size_read(inode)) { attr->ia_size != i_size_read(inode)) {
if (f2fs_has_inline_data(inode) && err = f2fs_convert_inline_data(inode, attr->ia_size);
(attr->ia_size > MAX_INLINE_DATA)) { if (err)
unsigned flags = AOP_FLAG_NOFS; return err;
err = f2fs_convert_inline_data(inode, NULL, flags);
if (err)
return err;
}
truncate_setsize(inode, attr->ia_size); 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)); 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) ...@@ -462,7 +457,7 @@ static int punch_hole(struct inode *inode, loff_t offset, loff_t len)
loff_t off_start, off_end; loff_t off_start, off_end;
int ret = 0; 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) if (ret)
return ret; return ret;
...@@ -512,16 +507,14 @@ static int expand_inode_data(struct inode *inode, loff_t offset, ...@@ -512,16 +507,14 @@ static int expand_inode_data(struct inode *inode, loff_t offset,
loff_t off_start, off_end; loff_t off_start, off_end;
int ret = 0; 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)); ret = inode_newsize_ok(inode, (len + offset));
if (ret) if (ret)
return 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_start = ((unsigned long long) offset) >> PAGE_CACHE_SHIFT;
pg_end = ((unsigned long long) offset + len) >> PAGE_CACHE_SHIFT; pg_end = ((unsigned long long) offset + len) >> PAGE_CACHE_SHIFT;
......
...@@ -101,6 +101,7 @@ static int __f2fs_convert_inline_data(struct inode *inode, struct page *page) ...@@ -101,6 +101,7 @@ static int __f2fs_convert_inline_data(struct inode *inode, struct page *page)
dst_addr = kmap(page); dst_addr = kmap(page);
memcpy(dst_addr, src_addr, MAX_INLINE_DATA); memcpy(dst_addr, src_addr, MAX_INLINE_DATA);
kunmap(page); kunmap(page);
SetPageUptodate(page);
/* write data page to try to make data consistent */ /* write data page to try to make data consistent */
set_page_writeback(page); set_page_writeback(page);
...@@ -120,25 +121,22 @@ static int __f2fs_convert_inline_data(struct inode *inode, struct page *page) ...@@ -120,25 +121,22 @@ static int __f2fs_convert_inline_data(struct inode *inode, struct page *page)
return err; return err;
} }
int f2fs_convert_inline_data(struct inode *inode, int f2fs_convert_inline_data(struct inode *inode, pgoff_t to_size)
struct page *p, unsigned flags)
{ {
int err;
struct page *page; struct page *page;
int err;
if (!p || p->index) { if (!f2fs_has_inline_data(inode))
page = grab_cache_page_write_begin(inode->i_mapping, 0, flags); return 0;
if (IS_ERR(page)) else if (to_size <= MAX_INLINE_DATA)
return PTR_ERR(page); return 0;
} else {
page = p;
}
err = __f2fs_convert_inline_data(inode, page);
if (!p || p->index) page = grab_cache_page_write_begin(inode->i_mapping, 0, AOP_FLAG_NOFS);
f2fs_put_page(page, 1); if (!page)
return -ENOMEM;
err = __f2fs_convert_inline_data(inode, page);
f2fs_put_page(page, 1);
return err; return err;
} }
......
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