Skip to content

Commit

Permalink
f2fs: fix fs corruption due to zero inode page
Browse files Browse the repository at this point in the history
commit 9bb02c3 upstream.

This patch fixes the following scenario.

- f2fs_create/f2fs_mkdir             - write_checkpoint
 - f2fs_mark_inode_dirty_sync         - block_operations
                                       - f2fs_lock_all
                                       - f2fs_sync_inode_meta
                                        - f2fs_unlock_all
                                        - sync_inode_metadata
 - f2fs_lock_op
                                         - f2fs_write_inode
                                          - update_inode_page
                                           - get_node_page
                                             return -ENOENT
 - new_inode_page
  - fill_node_footer
 - f2fs_mark_inode_dirty_sync
 - ...
 - f2fs_unlock_op
                                          - f2fs_inode_synced
                                       - f2fs_lock_all
                                       - do_checkpoint

In this checkpoint, we can get an inode page which contains zeros having valid
node footer only.

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
  • Loading branch information
Jaegeuk Kim authored and gregkh committed May 20, 2017
1 parent 717946b commit 659ccd9
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
2 changes: 1 addition & 1 deletion fs/f2fs/inode.c
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,6 @@ int update_inode_page(struct inode *inode)
} else if (err != -ENOENT) {
f2fs_stop_checkpoint(sbi, false);
}
f2fs_inode_synced(inode);
return 0;
}
ret = update_inode(inode, node_page);
Expand Down Expand Up @@ -446,6 +445,7 @@ void handle_failed_inode(struct inode *inode)
* in a panic when flushing dirty inodes in gdirty_list.
*/
update_inode_page(inode);
f2fs_inode_synced(inode);

/* don't make bad inode, since it becomes a regular file. */
unlock_new_inode(inode);
Expand Down
20 changes: 10 additions & 10 deletions fs/f2fs/namei.c
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,6 @@ static int f2fs_create(struct inode *dir, struct dentry *dentry, umode_t mode,
inode->i_mapping->a_ops = &f2fs_dblock_aops;
ino = inode->i_ino;

f2fs_balance_fs(sbi, true);

f2fs_lock_op(sbi);
err = f2fs_add_link(dentry, inode);
if (err)
Expand All @@ -163,6 +161,8 @@ static int f2fs_create(struct inode *dir, struct dentry *dentry, umode_t mode,

if (IS_DIRSYNC(dir))
f2fs_sync_fs(sbi->sb, 1);

f2fs_balance_fs(sbi, true);
return 0;
out:
handle_failed_inode(inode);
Expand Down Expand Up @@ -423,8 +423,6 @@ static int f2fs_symlink(struct inode *dir, struct dentry *dentry,
inode_nohighmem(inode);
inode->i_mapping->a_ops = &f2fs_dblock_aops;

f2fs_balance_fs(sbi, true);

f2fs_lock_op(sbi);
err = f2fs_add_link(dentry, inode);
if (err)
Expand Down Expand Up @@ -487,6 +485,8 @@ static int f2fs_symlink(struct inode *dir, struct dentry *dentry,
}

kfree(sd);

f2fs_balance_fs(sbi, true);
return err;
out:
handle_failed_inode(inode);
Expand All @@ -508,8 +508,6 @@ static int f2fs_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode)
inode->i_mapping->a_ops = &f2fs_dblock_aops;
mapping_set_gfp_mask(inode->i_mapping, GFP_F2FS_HIGH_ZERO);

f2fs_balance_fs(sbi, true);

set_inode_flag(inode, FI_INC_LINK);
f2fs_lock_op(sbi);
err = f2fs_add_link(dentry, inode);
Expand All @@ -524,6 +522,8 @@ static int f2fs_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode)

if (IS_DIRSYNC(dir))
f2fs_sync_fs(sbi->sb, 1);

f2fs_balance_fs(sbi, true);
return 0;

out_fail:
Expand Down Expand Up @@ -554,8 +554,6 @@ static int f2fs_mknod(struct inode *dir, struct dentry *dentry,
init_special_inode(inode, inode->i_mode, rdev);
inode->i_op = &f2fs_special_inode_operations;

f2fs_balance_fs(sbi, true);

f2fs_lock_op(sbi);
err = f2fs_add_link(dentry, inode);
if (err)
Expand All @@ -569,6 +567,8 @@ static int f2fs_mknod(struct inode *dir, struct dentry *dentry,

if (IS_DIRSYNC(dir))
f2fs_sync_fs(sbi->sb, 1);

f2fs_balance_fs(sbi, true);
return 0;
out:
handle_failed_inode(inode);
Expand All @@ -595,8 +595,6 @@ static int __f2fs_tmpfile(struct inode *dir, struct dentry *dentry,
inode->i_mapping->a_ops = &f2fs_dblock_aops;
}

f2fs_balance_fs(sbi, true);

f2fs_lock_op(sbi);
err = acquire_orphan_inode(sbi);
if (err)
Expand All @@ -622,6 +620,8 @@ static int __f2fs_tmpfile(struct inode *dir, struct dentry *dentry,
/* link_count was changed by d_tmpfile as well. */
f2fs_unlock_op(sbi);
unlock_new_inode(inode);

f2fs_balance_fs(sbi, true);
return 0;

release_out:
Expand Down

0 comments on commit 659ccd9

Please sign in to comment.