Skip to content

Commit

Permalink
f2fs: introduce need_do_checkpoint for readability
Browse files Browse the repository at this point in the history
This patch introduce need_do_checkpoint() to include numerous judgment condition
for readability.

Signed-off-by: Chao Yu <chao2.yu@samsung.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
  • Loading branch information
Chao Yu authored and Jaegeuk Kim committed Aug 21, 2014
1 parent c200b1a commit 9d1589e
Showing 1 changed file with 21 additions and 13 deletions.
34 changes: 21 additions & 13 deletions fs/f2fs/file.c
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,25 @@ static int get_parent_ino(struct inode *inode, nid_t *pino)
return 1;
}

static inline bool need_do_checkpoint(struct inode *inode)
{
struct f2fs_sb_info *sbi = F2FS_SB(inode->i_sb);
bool need_cp = false;

if (!S_ISREG(inode->i_mode) || inode->i_nlink != 1)
need_cp = true;
else if (file_wrong_pino(inode))
need_cp = true;
else if (!space_for_roll_forward(sbi))
need_cp = true;
else if (!is_checkpointed_node(sbi, F2FS_I(inode)->i_pino))
need_cp = true;
else if (F2FS_I(inode)->xattr_ver == cur_cp_version(F2FS_CKPT(sbi)))
need_cp = true;

return need_cp;
}

int f2fs_sync_file(struct file *file, loff_t start, loff_t end, int datasync)
{
struct inode *inode = file->f_mapping->host;
Expand Down Expand Up @@ -159,23 +178,12 @@ int f2fs_sync_file(struct file *file, loff_t start, loff_t end, int datasync)
/* guarantee free sections for fsync */
f2fs_balance_fs(sbi);

down_read(&fi->i_sem);

/*
* Both of fdatasync() and fsync() are able to be recovered from
* sudden-power-off.
*/
if (!S_ISREG(inode->i_mode) || inode->i_nlink != 1)
need_cp = true;
else if (file_wrong_pino(inode))
need_cp = true;
else if (!space_for_roll_forward(sbi))
need_cp = true;
else if (!is_checkpointed_node(sbi, F2FS_I(inode)->i_pino))
need_cp = true;
else if (F2FS_I(inode)->xattr_ver == cur_cp_version(F2FS_CKPT(sbi)))
need_cp = true;

down_read(&fi->i_sem);
need_cp = need_do_checkpoint(inode);
up_read(&fi->i_sem);

if (need_cp) {
Expand Down

0 comments on commit 9d1589e

Please sign in to comment.