OSDN Git Service

f2fs: enhance f2fs_is_checkpoint_ready()'s readability
authorChao Yu <yuchao0@huawei.com>
Fri, 23 Aug 2019 09:58:36 +0000 (17:58 +0800)
committer0ranko0P <ranko0p@outlook.com>
Tue, 24 Dec 2019 20:42:25 +0000 (04:42 +0800)
This patch changes sematics of f2fs_is_checkpoint_ready()'s return
value as: return true when checkpoint is ready, other return false,
it can improve readability of below conditions.

f2fs_submit_page_write()
...
if (is_sbi_flag_set(sbi, SBI_IS_SHUTDOWN) ||
!f2fs_is_checkpoint_ready(sbi))
__submit_merged_bio(io);

f2fs_balance_fs()
...
if (!f2fs_is_checkpoint_ready(sbi))
return;

Signed-off-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
fs/f2fs/data.c
fs/f2fs/file.c
fs/f2fs/inode.c
fs/f2fs/namei.c
fs/f2fs/segment.c
fs/f2fs/segment.h
fs/f2fs/xattr.c

index 6b38437..ef683ff 100644 (file)
@@ -668,7 +668,7 @@ skip:
                goto next;
 out:
        if (is_sbi_flag_set(sbi, SBI_IS_SHUTDOWN) ||
-                               f2fs_is_checkpoint_ready(sbi))
+                               !f2fs_is_checkpoint_ready(sbi))
                __submit_merged_bio(io);
        up_write(&io->io_rwsem);
 }
@@ -2612,9 +2612,10 @@ static int f2fs_write_begin(struct file *file, struct address_space *mapping,
        }
        trace_f2fs_write_begin(inode, pos, len, flags);
 
-       err = f2fs_is_checkpoint_ready(sbi);
-       if (err)
+       if (!f2fs_is_checkpoint_ready(sbi)) {
+               err = -ENOSPC;
                goto fail;
+       }
 
        if ((f2fs_is_atomic_file(inode) &&
                        !f2fs_available_free_memory(sbi, INMEM_PAGES)) ||
index 5f6c3e3..00b7a63 100644 (file)
@@ -59,9 +59,11 @@ static int f2fs_vm_page_mkwrite(struct vm_area_struct *vma,
                err = -EIO;
                goto err;
        }
-       err = f2fs_is_checkpoint_ready(sbi);
-       if (err)
+
+       if (!f2fs_is_checkpoint_ready(sbi)) {
+               err = -ENOSPC;
                goto err;
+       }
 
        sb_start_pagefault(inode->i_sb);
 
@@ -1579,9 +1581,8 @@ static long f2fs_fallocate(struct file *file, int mode,
 
        if (unlikely(f2fs_cp_error(F2FS_I_SB(inode))))
                return -EIO;
-       ret = f2fs_is_checkpoint_ready(F2FS_I_SB(inode));
-       if (ret)
-               return ret;
+       if (!f2fs_is_checkpoint_ready(F2FS_I_SB(inode)))
+               return -ENOSPC;
 
        /* f2fs only support ->fallocate for regular file */
        if (!S_ISREG(inode->i_mode))
@@ -2873,13 +2874,10 @@ static int f2fs_ioc_resize_fs(struct file *filp, unsigned long arg)
 
 long f2fs_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
 {
-       int ret;
-
        if (unlikely(f2fs_cp_error(F2FS_I_SB(file_inode(filp)))))
                return -EIO;
-       ret = f2fs_is_checkpoint_ready(F2FS_I_SB(file_inode(filp)));
-       if (ret)
-               return ret;
+       if (!f2fs_is_checkpoint_ready(F2FS_I_SB(file_inode(filp))))
+               return -ENOSPC;
 
        switch (cmd) {
        case F2FS_IOC_GETFLAGS:
index 8b9ad87..24560b6 100644 (file)
@@ -614,7 +614,7 @@ int f2fs_write_inode(struct inode *inode, struct writeback_control *wbc)
        if (!is_inode_flag_set(inode, FI_DIRTY_INODE))
                return 0;
 
-       if (f2fs_is_checkpoint_ready(sbi))
+       if (!f2fs_is_checkpoint_ready(sbi))
                return -ENOSPC;
 
        /*
index 467f9fe..0a44f88 100644 (file)
@@ -272,9 +272,8 @@ static int f2fs_create(struct inode *dir, struct dentry *dentry, umode_t mode,
 
        if (unlikely(f2fs_cp_error(sbi)))
                return -EIO;
-       err = f2fs_is_checkpoint_ready(sbi);
-       if (err)
-               return err;
+       if (!f2fs_is_checkpoint_ready(sbi))
+               return -ENOSPC;
 
        err = dquot_initialize(dir);
        if (err)
@@ -322,9 +321,8 @@ static int f2fs_link(struct dentry *old_dentry, struct inode *dir,
 
        if (unlikely(f2fs_cp_error(sbi)))
                return -EIO;
-       err = f2fs_is_checkpoint_ready(sbi);
-       if (err)
-               return err;
+       if (!f2fs_is_checkpoint_ready(sbi))
+               return -ENOSPC;
 
        err = fscrypt_prepare_link(old_dentry, dir, dentry);
        if (err)
@@ -566,9 +564,8 @@ static int f2fs_symlink(struct inode *dir, struct dentry *dentry,
 
        if (unlikely(f2fs_cp_error(sbi)))
                return -EIO;
-       err = f2fs_is_checkpoint_ready(sbi);
-       if (err)
-               return err;
+       if (!f2fs_is_checkpoint_ready(sbi))
+               return -ENOSPC;
 
        err = fscrypt_prepare_symlink(dir, symname, len, dir->i_sb->s_blocksize,
                                      &disk_link);
@@ -700,9 +697,8 @@ static int f2fs_mknod(struct inode *dir, struct dentry *dentry,
 
        if (unlikely(f2fs_cp_error(sbi)))
                return -EIO;
-       err = f2fs_is_checkpoint_ready(sbi);
-       if (err)
-               return err;
+       if (!f2fs_is_checkpoint_ready(sbi))
+               return -ENOSPC;
 
        err = dquot_initialize(dir);
        if (err)
@@ -799,13 +795,11 @@ out:
 static int f2fs_tmpfile(struct inode *dir, struct dentry *dentry, umode_t mode)
 {
        struct f2fs_sb_info *sbi = F2FS_I_SB(dir);
-       int ret;
 
        if (unlikely(f2fs_cp_error(sbi)))
                return -EIO;
-       ret = f2fs_is_checkpoint_ready(sbi);
-       if (ret)
-               return ret;
+       if (!f2fs_is_checkpoint_ready(sbi))
+               return -ENOSPC;
 
        if (f2fs_encrypted_inode(dir) || DUMMY_ENCRYPTION_ENABLED(sbi)) {
                int err = fscrypt_get_encryption_info(dir);
@@ -842,9 +836,8 @@ static int f2fs_rename(struct inode *old_dir, struct dentry *old_dentry,
 
        if (unlikely(f2fs_cp_error(sbi)))
                return -EIO;
-       err = f2fs_is_checkpoint_ready(sbi);
-       if (err)
-               return err;
+       if (!f2fs_is_checkpoint_ready(sbi))
+               return -ENOSPC;
 
        if (is_inode_flag_set(new_dir, FI_PROJ_INHERIT) &&
                        (!projid_eq(F2FS_I(new_dir)->i_projid,
@@ -1037,9 +1030,8 @@ static int f2fs_cross_rename(struct inode *old_dir, struct dentry *old_dentry,
 
        if (unlikely(f2fs_cp_error(sbi)))
                return -EIO;
-       err = f2fs_is_checkpoint_ready(sbi);
-       if (err)
-               return err;
+       if (!f2fs_is_checkpoint_ready(sbi))
+               return -ENOSPC;
 
        if ((is_inode_flag_set(new_dir, FI_PROJ_INHERIT) &&
                        !projid_eq(F2FS_I(new_dir)->i_projid,
index 856518b..7ad326b 100644 (file)
@@ -501,7 +501,7 @@ void f2fs_balance_fs(struct f2fs_sb_info *sbi, bool need)
        if (need && excess_cached_nats(sbi))
                f2fs_balance_fs_bg(sbi);
 
-       if (f2fs_is_checkpoint_ready(sbi))
+       if (!f2fs_is_checkpoint_ready(sbi))
                return;
 
        /*
index b219009..325781a 100644 (file)
@@ -586,13 +586,13 @@ static inline bool has_not_enough_free_secs(struct f2fs_sb_info *sbi,
                reserved_sections(sbi) + needed);
 }
 
-static inline int f2fs_is_checkpoint_ready(struct f2fs_sb_info *sbi)
+static inline bool f2fs_is_checkpoint_ready(struct f2fs_sb_info *sbi)
 {
        if (likely(!is_sbi_flag_set(sbi, SBI_CP_DISABLED)))
-               return 0;
+               return true;
        if (likely(!has_not_enough_free_secs(sbi, 0, 0)))
-               return 0;
-       return -ENOSPC;
+               return true;
+       return false;
 }
 
 static inline bool excess_prefree_segs(struct f2fs_sb_info *sbi)
index c0fc00d..3ab948d 100644 (file)
@@ -771,9 +771,8 @@ int f2fs_setxattr(struct inode *inode, int index, const char *name,
 
        if (unlikely(f2fs_cp_error(sbi)))
                return -EIO;
-       err = f2fs_is_checkpoint_ready(sbi);
-       if (err)
-               return err;
+       if (!f2fs_is_checkpoint_ready(sbi))
+               return -ENOSPC;
 
        err = dquot_initialize(inode);
        if (err)