aboutsummaryrefslogtreecommitdiffstats
path: root/fs/f2fs
diff options
context:
space:
mode:
authorJaegeuk Kim <jaegeuk@kernel.org>2014-06-21 00:37:02 -0400
committerJaegeuk Kim <jaegeuk@kernel.org>2014-07-09 17:04:24 -0400
commitb97a9b5da891ab6aff5a6a19c569c9c4c5563d48 (patch)
treec8e3fe4ddbba29eed50b9bf461cb088b21a13d00 /fs/f2fs
parent50732df02eefb39ab414ef655979c2c9b64ad21c (diff)
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>
Diffstat (limited to 'fs/f2fs')
-rw-r--r--fs/f2fs/dir.c27
-rw-r--r--fs/f2fs/f2fs.h1
-rw-r--r--fs/f2fs/namei.c30
3 files changed, 33 insertions, 25 deletions
diff --git a/fs/f2fs/dir.c b/fs/f2fs/dir.c
index 3677f4124541..fb7e01ed47dc 100644
--- a/fs/f2fs/dir.c
+++ b/fs/f2fs/dir.c
@@ -337,8 +337,7 @@ static struct page *init_inode_metadata(struct inode *inode,
337 struct page *page; 337 struct page *page;
338 int err; 338 int err;
339 339
340 if (is_inode_flag_set(F2FS_I(inode), FI_NEW_INODE) && 340 if (is_inode_flag_set(F2FS_I(inode), FI_NEW_INODE)) {
341 inode->i_nlink) {
342 page = new_inode_page(inode, name); 341 page = new_inode_page(inode, name);
343 if (IS_ERR(page)) 342 if (IS_ERR(page))
344 return page; 343 return page;
@@ -364,7 +363,8 @@ static struct page *init_inode_metadata(struct inode *inode,
364 set_cold_node(inode, page); 363 set_cold_node(inode, page);
365 } 364 }
366 365
367 init_dent_inode(name, page); 366 if (name)
367 init_dent_inode(name, page);
368 368
369 /* 369 /*
370 * This file should be checkpointed during fsync. 370 * This file should be checkpointed during fsync.
@@ -537,6 +537,27 @@ fail:
537 return err; 537 return err;
538} 538}
539 539
540int f2fs_do_tmpfile(struct inode *inode, struct inode *dir)
541{
542 struct page *page;
543 int err = 0;
544
545 down_write(&F2FS_I(inode)->i_sem);
546 page = init_inode_metadata(inode, dir, NULL);
547 if (IS_ERR(page)) {
548 err = PTR_ERR(page);
549 goto fail;
550 }
551 /* we don't need to mark_inode_dirty now */
552 update_inode(inode, page);
553 f2fs_put_page(page, 1);
554
555 clear_inode_flag(F2FS_I(inode), FI_NEW_INODE);
556fail:
557 up_write(&F2FS_I(inode)->i_sem);
558 return err;
559}
560
540/* 561/*
541 * It only removes the dentry from the dentry page,corresponding name 562 * It only removes the dentry from the dentry page,corresponding name
542 * entry in name page does not need to be touched during deletion. 563 * entry in name page does not need to be touched during deletion.
diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h
index 58df97e174d0..ca421a8e47d9 100644
--- a/fs/f2fs/f2fs.h
+++ b/fs/f2fs/f2fs.h
@@ -1136,6 +1136,7 @@ void f2fs_set_link(struct inode *, struct f2fs_dir_entry *,
1136int update_dent_inode(struct inode *, const struct qstr *); 1136int update_dent_inode(struct inode *, const struct qstr *);
1137int __f2fs_add_link(struct inode *, const struct qstr *, struct inode *); 1137int __f2fs_add_link(struct inode *, const struct qstr *, struct inode *);
1138void f2fs_delete_entry(struct f2fs_dir_entry *, struct page *, struct inode *); 1138void f2fs_delete_entry(struct f2fs_dir_entry *, struct page *, struct inode *);
1139int f2fs_do_tmpfile(struct inode *, struct inode *);
1139int f2fs_make_empty(struct inode *, struct inode *); 1140int f2fs_make_empty(struct inode *, struct inode *);
1140bool f2fs_empty_dir(struct inode *); 1141bool f2fs_empty_dir(struct inode *);
1141 1142
diff --git a/fs/f2fs/namei.c b/fs/f2fs/namei.c
index 5c08c546e4c8..1994d2e449d6 100644
--- a/fs/f2fs/namei.c
+++ b/fs/f2fs/namei.c
@@ -493,7 +493,6 @@ static int f2fs_tmpfile(struct inode *dir, struct dentry *dentry, umode_t mode)
493 struct super_block *sb = dir->i_sb; 493 struct super_block *sb = dir->i_sb;
494 struct f2fs_sb_info *sbi = F2FS_SB(sb); 494 struct f2fs_sb_info *sbi = F2FS_SB(sb);
495 struct inode *inode; 495 struct inode *inode;
496 struct page *page;
497 int err; 496 int err;
498 497
499 inode = f2fs_new_inode(dir, mode); 498 inode = f2fs_new_inode(dir, mode);
@@ -508,38 +507,25 @@ static int f2fs_tmpfile(struct inode *dir, struct dentry *dentry, umode_t mode)
508 err = acquire_orphan_inode(sbi); 507 err = acquire_orphan_inode(sbi);
509 if (err) 508 if (err)
510 goto out; 509 goto out;
510
511 err = f2fs_do_tmpfile(inode, dir);
512 if (err)
513 goto release_out;
514
511 /* 515 /*
512 * add this non-linked tmpfile to orphan list, in this way we could 516 * add this non-linked tmpfile to orphan list, in this way we could
513 * remove all unused data of tmpfile after abnormal power-off. 517 * remove all unused data of tmpfile after abnormal power-off.
514 */ 518 */
515 add_orphan_inode(sbi, inode->i_ino); 519 add_orphan_inode(sbi, inode->i_ino);
516
517 page = new_inode_page(inode, NULL);
518 if (IS_ERR(page)) {
519 err = PTR_ERR(page);
520 goto remove_out;
521 }
522
523 err = f2fs_init_acl(inode, dir, page);
524 if (err)
525 goto unlock_out;
526
527 err = f2fs_init_security(inode, dir, NULL, page);
528 if (err)
529 goto unlock_out;
530
531 f2fs_put_page(page, 1);
532 f2fs_unlock_op(sbi); 520 f2fs_unlock_op(sbi);
533 521
534 alloc_nid_done(sbi, inode->i_ino); 522 alloc_nid_done(sbi, inode->i_ino);
535 mark_inode_dirty(inode);
536 d_tmpfile(dentry, inode); 523 d_tmpfile(dentry, inode);
537 unlock_new_inode(inode); 524 unlock_new_inode(inode);
538 return 0; 525 return 0;
539unlock_out: 526
540 f2fs_put_page(page, 1); 527release_out:
541remove_out: 528 release_orphan_inode(sbi);
542 remove_orphan_inode(sbi, inode->i_ino);
543out: 529out:
544 f2fs_unlock_op(sbi); 530 f2fs_unlock_op(sbi);
545 clear_nlink(inode); 531 clear_nlink(inode);