提交 470f00e9 编写于 作者: C Chao Yu 提交者: Jaegeuk Kim

f2fs: fix to release inode page correctly

In following call path, we will pass a locked and referenced ipage
pointer to get_new_data_page:
 - init_inode_metadata
  - make_empty_dir
   - get_new_data_page

There are two exit paths in get_new_data_page when error occurs:
1) grab_cache_page fails, ipage will not be released;
2) f2fs_reserve_block fails, ipage will be released in callee.

So, it's not consistent for error handling in get_new_data_page.

For f2fs_reserve_block, it's not very easy to change the rule
of error handling, since it's already complicated.

Here we deside to choose an easy way to fix this issue:
If any error occur in get_new_data_page, we will ensure releasing
ipage in this function.

The same issue is in f2fs_convert_inline_dir, fix that too.
Signed-off-by: NChao Yu <chao2.yu@samsung.com>
Signed-off-by: NJaegeuk Kim <jaegeuk@kernel.org>
上级 7a04f64d
...@@ -388,7 +388,8 @@ struct page *get_lock_data_page(struct inode *inode, pgoff_t index) ...@@ -388,7 +388,8 @@ struct page *get_lock_data_page(struct inode *inode, pgoff_t index)
* *
* Also, caller should grab and release a rwsem by calling f2fs_lock_op() and * Also, caller should grab and release a rwsem by calling f2fs_lock_op() and
* f2fs_unlock_op(). * f2fs_unlock_op().
* Note that, ipage is set only by make_empty_dir. * Note that, ipage is set only by make_empty_dir, and if any error occur,
* ipage should be released by this function.
*/ */
struct page *get_new_data_page(struct inode *inode, struct page *get_new_data_page(struct inode *inode,
struct page *ipage, pgoff_t index, bool new_i_size) struct page *ipage, pgoff_t index, bool new_i_size)
...@@ -399,8 +400,14 @@ struct page *get_new_data_page(struct inode *inode, ...@@ -399,8 +400,14 @@ struct page *get_new_data_page(struct inode *inode,
int err; int err;
repeat: repeat:
page = grab_cache_page(mapping, index); page = grab_cache_page(mapping, index);
if (!page) if (!page) {
/*
* before exiting, we should make sure ipage will be released
* if any error occur.
*/
f2fs_put_page(ipage, 1);
return ERR_PTR(-ENOMEM); return ERR_PTR(-ENOMEM);
}
set_new_dnode(&dn, inode, ipage, NULL, 0); set_new_dnode(&dn, inode, ipage, NULL, 0);
err = f2fs_reserve_block(&dn, index); err = f2fs_reserve_block(&dn, index);
......
...@@ -360,6 +360,10 @@ int make_empty_inline_dir(struct inode *inode, struct inode *parent, ...@@ -360,6 +360,10 @@ int make_empty_inline_dir(struct inode *inode, struct inode *parent,
return 0; return 0;
} }
/*
* NOTE: ipage is grabbed by caller, but if any error occurs, we should
* release ipage in this function.
*/
static int f2fs_convert_inline_dir(struct inode *dir, struct page *ipage, static int f2fs_convert_inline_dir(struct inode *dir, struct page *ipage,
struct f2fs_inline_dentry *inline_dentry) struct f2fs_inline_dentry *inline_dentry)
{ {
...@@ -369,8 +373,10 @@ static int f2fs_convert_inline_dir(struct inode *dir, struct page *ipage, ...@@ -369,8 +373,10 @@ static int f2fs_convert_inline_dir(struct inode *dir, struct page *ipage,
int err; int err;
page = grab_cache_page(dir->i_mapping, 0); page = grab_cache_page(dir->i_mapping, 0);
if (!page) if (!page) {
f2fs_put_page(ipage, 1);
return -ENOMEM; return -ENOMEM;
}
set_new_dnode(&dn, dir, ipage, NULL, 0); set_new_dnode(&dn, dir, ipage, NULL, 0);
err = f2fs_reserve_block(&dn, 0); err = f2fs_reserve_block(&dn, 0);
...@@ -434,8 +440,9 @@ int f2fs_add_inline_entry(struct inode *dir, const struct qstr *name, ...@@ -434,8 +440,9 @@ int f2fs_add_inline_entry(struct inode *dir, const struct qstr *name,
slots, NR_INLINE_DENTRY); slots, NR_INLINE_DENTRY);
if (bit_pos >= NR_INLINE_DENTRY) { if (bit_pos >= NR_INLINE_DENTRY) {
err = f2fs_convert_inline_dir(dir, ipage, dentry_blk); err = f2fs_convert_inline_dir(dir, ipage, dentry_blk);
if (!err) if (err)
err = -EAGAIN; return err;
err = -EAGAIN;
goto out; goto out;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册