Commit a1961246 authored by Jaegeuk Kim's avatar Jaegeuk Kim

f2fs: introduce f2fs_i_links_write with mark_inode_dirty_sync

This patch introduces f2fs_i_links_write() to call mark_inode_dirty_sync() when
changing inode->i_links.
Signed-off-by: default avatarJaegeuk Kim <jaegeuk@kernel.org>
parent 8edd03c8
...@@ -535,6 +535,7 @@ static int recover_orphan_inode(struct f2fs_sb_info *sbi, nid_t ino) ...@@ -535,6 +535,7 @@ static int recover_orphan_inode(struct f2fs_sb_info *sbi, nid_t ino)
} }
clear_nlink(inode); clear_nlink(inode);
mark_inode_dirty_sync(inode);
/* truncate all the data during iput */ /* truncate all the data during iput */
iput(inode); iput(inode);
......
...@@ -437,7 +437,7 @@ struct page *init_inode_metadata(struct inode *inode, struct inode *dir, ...@@ -437,7 +437,7 @@ struct page *init_inode_metadata(struct inode *inode, struct inode *dir,
*/ */
if (inode->i_nlink == 0) if (inode->i_nlink == 0)
remove_orphan_inode(F2FS_I_SB(dir), inode->i_ino); remove_orphan_inode(F2FS_I_SB(dir), inode->i_ino);
inc_nlink(inode); f2fs_i_links_write(inode, true);
} }
return page; return page;
...@@ -456,7 +456,7 @@ void update_parent_metadata(struct inode *dir, struct inode *inode, ...@@ -456,7 +456,7 @@ void update_parent_metadata(struct inode *dir, struct inode *inode,
{ {
if (inode && is_inode_flag_set(inode, FI_NEW_INODE)) { if (inode && is_inode_flag_set(inode, FI_NEW_INODE)) {
if (S_ISDIR(inode->i_mode)) { if (S_ISDIR(inode->i_mode)) {
inc_nlink(dir); f2fs_i_links_write(dir, true);
set_inode_flag(dir, FI_UPDATE_DIR); set_inode_flag(dir, FI_UPDATE_DIR);
} }
clear_inode_flag(inode, FI_NEW_INODE); clear_inode_flag(inode, FI_NEW_INODE);
...@@ -675,7 +675,7 @@ void f2fs_drop_nlink(struct inode *dir, struct inode *inode, struct page *page) ...@@ -675,7 +675,7 @@ void f2fs_drop_nlink(struct inode *dir, struct inode *inode, struct page *page)
down_write(&F2FS_I(inode)->i_sem); down_write(&F2FS_I(inode)->i_sem);
if (S_ISDIR(inode->i_mode)) { if (S_ISDIR(inode->i_mode)) {
drop_nlink(dir); f2fs_i_links_write(dir, false);
if (page) if (page)
update_inode(dir, page); update_inode(dir, page);
else else
...@@ -683,9 +683,9 @@ void f2fs_drop_nlink(struct inode *dir, struct inode *inode, struct page *page) ...@@ -683,9 +683,9 @@ void f2fs_drop_nlink(struct inode *dir, struct inode *inode, struct page *page)
} }
inode->i_ctime = CURRENT_TIME; inode->i_ctime = CURRENT_TIME;
drop_nlink(inode); f2fs_i_links_write(inode, false);
if (S_ISDIR(inode->i_mode)) { if (S_ISDIR(inode->i_mode)) {
drop_nlink(inode); f2fs_i_links_write(inode, false);
f2fs_i_size_write(inode, 0); f2fs_i_size_write(inode, 0);
} }
up_write(&F2FS_I(inode)->i_sem); up_write(&F2FS_I(inode)->i_sem);
......
...@@ -1557,6 +1557,15 @@ static inline void set_acl_inode(struct inode *inode, umode_t mode) ...@@ -1557,6 +1557,15 @@ static inline void set_acl_inode(struct inode *inode, umode_t mode)
set_inode_flag(inode, FI_ACL_MODE); set_inode_flag(inode, FI_ACL_MODE);
} }
static inline void f2fs_i_links_write(struct inode *inode, bool inc)
{
if (inc)
inc_nlink(inode);
else
drop_nlink(inode);
mark_inode_dirty_sync(inode);
}
static inline void f2fs_i_blocks_write(struct inode *inode, static inline void f2fs_i_blocks_write(struct inode *inode,
blkcnt_t diff, bool add) blkcnt_t diff, bool add)
{ {
......
...@@ -349,9 +349,6 @@ static int f2fs_unlink(struct inode *dir, struct dentry *dentry) ...@@ -349,9 +349,6 @@ static int f2fs_unlink(struct inode *dir, struct dentry *dentry)
f2fs_delete_entry(de, page, dir, inode); f2fs_delete_entry(de, page, dir, inode);
f2fs_unlock_op(sbi); f2fs_unlock_op(sbi);
/* In order to evict this inode, we set it dirty */
mark_inode_dirty(inode);
if (IS_DIRSYNC(dir)) if (IS_DIRSYNC(dir))
f2fs_sync_fs(sbi->sb, 1); f2fs_sync_fs(sbi->sb, 1);
fail: fail:
...@@ -597,16 +594,16 @@ static int __f2fs_tmpfile(struct inode *dir, struct dentry *dentry, ...@@ -597,16 +594,16 @@ static int __f2fs_tmpfile(struct inode *dir, struct dentry *dentry,
* remove all unused data of tmpfile after abnormal power-off. * remove all unused data of tmpfile after abnormal power-off.
*/ */
add_orphan_inode(sbi, inode->i_ino); add_orphan_inode(sbi, inode->i_ino);
f2fs_unlock_op(sbi);
alloc_nid_done(sbi, inode->i_ino); alloc_nid_done(sbi, inode->i_ino);
if (whiteout) { if (whiteout) {
inode_dec_link_count(inode); f2fs_i_links_write(inode, false);
*whiteout = inode; *whiteout = inode;
} else { } else {
d_tmpfile(dentry, inode); d_tmpfile(dentry, inode);
} }
/* link_count was changed by d_tmpfile as well. */
f2fs_unlock_op(sbi);
unlock_new_inode(inode); unlock_new_inode(inode);
return 0; return 0;
...@@ -704,12 +701,10 @@ static int f2fs_rename(struct inode *old_dir, struct dentry *old_dentry, ...@@ -704,12 +701,10 @@ static int f2fs_rename(struct inode *old_dir, struct dentry *old_dentry,
new_inode->i_ctime = CURRENT_TIME; new_inode->i_ctime = CURRENT_TIME;
down_write(&F2FS_I(new_inode)->i_sem); down_write(&F2FS_I(new_inode)->i_sem);
if (old_dir_entry) if (old_dir_entry)
drop_nlink(new_inode); f2fs_i_links_write(new_inode, false);
drop_nlink(new_inode); f2fs_i_links_write(new_inode, false);
up_write(&F2FS_I(new_inode)->i_sem); up_write(&F2FS_I(new_inode)->i_sem);
mark_inode_dirty(new_inode);
if (!new_inode->i_nlink) if (!new_inode->i_nlink)
add_orphan_inode(sbi, new_inode->i_ino); add_orphan_inode(sbi, new_inode->i_ino);
else else
...@@ -729,7 +724,7 @@ static int f2fs_rename(struct inode *old_dir, struct dentry *old_dentry, ...@@ -729,7 +724,7 @@ static int f2fs_rename(struct inode *old_dir, struct dentry *old_dentry,
} }
if (old_dir_entry) { if (old_dir_entry) {
inc_nlink(new_dir); f2fs_i_links_write(new_dir, true);
update_inode_page(new_dir); update_inode_page(new_dir);
} }
...@@ -784,8 +779,7 @@ static int f2fs_rename(struct inode *old_dir, struct dentry *old_dentry, ...@@ -784,8 +779,7 @@ static int f2fs_rename(struct inode *old_dir, struct dentry *old_dentry,
f2fs_dentry_kunmap(old_inode, old_dir_page); f2fs_dentry_kunmap(old_inode, old_dir_page);
f2fs_put_page(old_dir_page, 0); f2fs_put_page(old_dir_page, 0);
} }
drop_nlink(old_dir); f2fs_i_links_write(old_dir, false);
mark_inode_dirty(old_dir);
update_inode_page(old_dir); update_inode_page(old_dir);
} }
...@@ -913,10 +907,7 @@ static int f2fs_cross_rename(struct inode *old_dir, struct dentry *old_dentry, ...@@ -913,10 +907,7 @@ static int f2fs_cross_rename(struct inode *old_dir, struct dentry *old_dentry,
old_dir->i_ctime = CURRENT_TIME; old_dir->i_ctime = CURRENT_TIME;
if (old_nlink) { if (old_nlink) {
down_write(&F2FS_I(old_dir)->i_sem); down_write(&F2FS_I(old_dir)->i_sem);
if (old_nlink < 0) f2fs_i_links_write(old_dir, old_nlink > 0);
drop_nlink(old_dir);
else
inc_nlink(old_dir);
up_write(&F2FS_I(old_dir)->i_sem); up_write(&F2FS_I(old_dir)->i_sem);
} }
mark_inode_dirty(old_dir); mark_inode_dirty(old_dir);
...@@ -934,10 +925,7 @@ static int f2fs_cross_rename(struct inode *old_dir, struct dentry *old_dentry, ...@@ -934,10 +925,7 @@ static int f2fs_cross_rename(struct inode *old_dir, struct dentry *old_dentry,
new_dir->i_ctime = CURRENT_TIME; new_dir->i_ctime = CURRENT_TIME;
if (new_nlink) { if (new_nlink) {
down_write(&F2FS_I(new_dir)->i_sem); down_write(&F2FS_I(new_dir)->i_sem);
if (new_nlink < 0) f2fs_i_links_write(new_dir, new_nlink > 0);
drop_nlink(new_dir);
else
inc_nlink(new_dir);
up_write(&F2FS_I(new_dir)->i_sem); up_write(&F2FS_I(new_dir)->i_sem);
} }
mark_inode_dirty(new_dir); mark_inode_dirty(new_dir);
......
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