f2fs: introduce f2fs_do_tmpfile for code consistency

This patch adds f2fs_do_tmpfile to eliminate the redundant init_inode_metadata
flow.
Throught this, we can provide the consistent lock usage, e.g., fi->i_sem,  and
this will enable better debugging stuffs.

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
This commit is contained in:
Jaegeuk Kim 2014-06-20 21:37:02 -07:00
parent 50732df02e
commit b97a9b5da8
3 changed files with 33 additions and 25 deletions

View File

@ -337,8 +337,7 @@ static struct page *init_inode_metadata(struct inode *inode,
struct page *page;
int err;
if (is_inode_flag_set(F2FS_I(inode), FI_NEW_INODE) &&
inode->i_nlink) {
if (is_inode_flag_set(F2FS_I(inode), FI_NEW_INODE)) {
page = new_inode_page(inode, name);
if (IS_ERR(page))
return page;
@ -364,6 +363,7 @@ static struct page *init_inode_metadata(struct inode *inode,
set_cold_node(inode, page);
}
if (name)
init_dent_inode(name, page);
/*
@ -537,6 +537,27 @@ fail:
return err;
}
int f2fs_do_tmpfile(struct inode *inode, struct inode *dir)
{
struct page *page;
int err = 0;
down_write(&F2FS_I(inode)->i_sem);
page = init_inode_metadata(inode, dir, NULL);
if (IS_ERR(page)) {
err = PTR_ERR(page);
goto fail;
}
/* we don't need to mark_inode_dirty now */
update_inode(inode, page);
f2fs_put_page(page, 1);
clear_inode_flag(F2FS_I(inode), FI_NEW_INODE);
fail:
up_write(&F2FS_I(inode)->i_sem);
return err;
}
/*
* It only removes the dentry from the dentry page,corresponding name
* entry in name page does not need to be touched during deletion.

View File

@ -1136,6 +1136,7 @@ void f2fs_set_link(struct inode *, struct f2fs_dir_entry *,
int update_dent_inode(struct inode *, const struct qstr *);
int __f2fs_add_link(struct inode *, const struct qstr *, struct inode *);
void f2fs_delete_entry(struct f2fs_dir_entry *, struct page *, struct inode *);
int f2fs_do_tmpfile(struct inode *, struct inode *);
int f2fs_make_empty(struct inode *, struct inode *);
bool f2fs_empty_dir(struct inode *);

View File

@ -493,7 +493,6 @@ static int f2fs_tmpfile(struct inode *dir, struct dentry *dentry, umode_t mode)
struct super_block *sb = dir->i_sb;
struct f2fs_sb_info *sbi = F2FS_SB(sb);
struct inode *inode;
struct page *page;
int err;
inode = f2fs_new_inode(dir, mode);
@ -508,38 +507,25 @@ static int f2fs_tmpfile(struct inode *dir, struct dentry *dentry, umode_t mode)
err = acquire_orphan_inode(sbi);
if (err)
goto out;
err = f2fs_do_tmpfile(inode, dir);
if (err)
goto release_out;
/*
* add this non-linked tmpfile to orphan list, in this way we could
* remove all unused data of tmpfile after abnormal power-off.
*/
add_orphan_inode(sbi, inode->i_ino);
page = new_inode_page(inode, NULL);
if (IS_ERR(page)) {
err = PTR_ERR(page);
goto remove_out;
}
err = f2fs_init_acl(inode, dir, page);
if (err)
goto unlock_out;
err = f2fs_init_security(inode, dir, NULL, page);
if (err)
goto unlock_out;
f2fs_put_page(page, 1);
f2fs_unlock_op(sbi);
alloc_nid_done(sbi, inode->i_ino);
mark_inode_dirty(inode);
d_tmpfile(dentry, inode);
unlock_new_inode(inode);
return 0;
unlock_out:
f2fs_put_page(page, 1);
remove_out:
remove_orphan_inode(sbi, inode->i_ino);
release_out:
release_orphan_inode(sbi);
out:
f2fs_unlock_op(sbi);
clear_nlink(inode);