summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChao Yu <yuchao0@huawei.com>2019-08-23 05:58:36 -0400
committerJaegeuk Kim <jaegeuk@kernel.org>2019-09-06 19:18:26 -0400
commit00e09c0bccc71825ca9a659eb145ed7c4dc95588 (patch)
tree102a0fee320d40270360f9908a04d7a28a3c67da
parentb757f6edbeddd0c43135edfdee18103bd73f0991 (diff)
f2fs: enhance f2fs_is_checkpoint_ready()'s readability
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>
-rw-r--r--fs/f2fs/data.c7
-rw-r--r--fs/f2fs/file.c18
-rw-r--r--fs/f2fs/inode.c2
-rw-r--r--fs/f2fs/namei.c36
-rw-r--r--fs/f2fs/segment.c2
-rw-r--r--fs/f2fs/segment.h8
-rw-r--r--fs/f2fs/xattr.c5
7 files changed, 34 insertions, 44 deletions
diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c
index 0b3728f58d17..ab8c8f2fff70 100644
--- a/fs/f2fs/data.c
+++ b/fs/f2fs/data.c
@@ -634,7 +634,7 @@ skip:
634 goto next; 634 goto next;
635out: 635out:
636 if (is_sbi_flag_set(sbi, SBI_IS_SHUTDOWN) || 636 if (is_sbi_flag_set(sbi, SBI_IS_SHUTDOWN) ||
637 f2fs_is_checkpoint_ready(sbi)) 637 !f2fs_is_checkpoint_ready(sbi))
638 __submit_merged_bio(io); 638 __submit_merged_bio(io);
639 up_write(&io->io_rwsem); 639 up_write(&io->io_rwsem);
640} 640}
@@ -2570,9 +2570,10 @@ static int f2fs_write_begin(struct file *file, struct address_space *mapping,
2570 2570
2571 trace_f2fs_write_begin(inode, pos, len, flags); 2571 trace_f2fs_write_begin(inode, pos, len, flags);
2572 2572
2573 err = f2fs_is_checkpoint_ready(sbi); 2573 if (!f2fs_is_checkpoint_ready(sbi)) {
2574 if (err) 2574 err = -ENOSPC;
2575 goto fail; 2575 goto fail;
2576 }
2576 2577
2577 if ((f2fs_is_atomic_file(inode) && 2578 if ((f2fs_is_atomic_file(inode) &&
2578 !f2fs_available_free_memory(sbi, INMEM_PAGES)) || 2579 !f2fs_available_free_memory(sbi, INMEM_PAGES)) ||
diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c
index 344e0bd638e5..6528216ab832 100644
--- a/fs/f2fs/file.c
+++ b/fs/f2fs/file.c
@@ -57,9 +57,11 @@ static vm_fault_t f2fs_vm_page_mkwrite(struct vm_fault *vmf)
57 err = -EIO; 57 err = -EIO;
58 goto err; 58 goto err;
59 } 59 }
60 err = f2fs_is_checkpoint_ready(sbi); 60
61 if (err) 61 if (!f2fs_is_checkpoint_ready(sbi)) {
62 err = -ENOSPC;
62 goto err; 63 goto err;
64 }
63 65
64 sb_start_pagefault(inode->i_sb); 66 sb_start_pagefault(inode->i_sb);
65 67
@@ -1571,9 +1573,8 @@ static long f2fs_fallocate(struct file *file, int mode,
1571 1573
1572 if (unlikely(f2fs_cp_error(F2FS_I_SB(inode)))) 1574 if (unlikely(f2fs_cp_error(F2FS_I_SB(inode))))
1573 return -EIO; 1575 return -EIO;
1574 ret = f2fs_is_checkpoint_ready(F2FS_I_SB(inode)); 1576 if (!f2fs_is_checkpoint_ready(F2FS_I_SB(inode)))
1575 if (ret) 1577 return -ENOSPC;
1576 return ret;
1577 1578
1578 /* f2fs only support ->fallocate for regular file */ 1579 /* f2fs only support ->fallocate for regular file */
1579 if (!S_ISREG(inode->i_mode)) 1580 if (!S_ISREG(inode->i_mode))
@@ -3146,13 +3147,10 @@ out:
3146 3147
3147long f2fs_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) 3148long f2fs_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
3148{ 3149{
3149 int ret;
3150
3151 if (unlikely(f2fs_cp_error(F2FS_I_SB(file_inode(filp))))) 3150 if (unlikely(f2fs_cp_error(F2FS_I_SB(file_inode(filp)))))
3152 return -EIO; 3151 return -EIO;
3153 ret = f2fs_is_checkpoint_ready(F2FS_I_SB(file_inode(filp))); 3152 if (!f2fs_is_checkpoint_ready(F2FS_I_SB(file_inode(filp))))
3154 if (ret) 3153 return -ENOSPC;
3155 return ret;
3156 3154
3157 switch (cmd) { 3155 switch (cmd) {
3158 case F2FS_IOC_GETFLAGS: 3156 case F2FS_IOC_GETFLAGS:
diff --git a/fs/f2fs/inode.c b/fs/f2fs/inode.c
index 88af85e0db62..87214414936b 100644
--- a/fs/f2fs/inode.c
+++ b/fs/f2fs/inode.c
@@ -616,7 +616,7 @@ int f2fs_write_inode(struct inode *inode, struct writeback_control *wbc)
616 if (!is_inode_flag_set(inode, FI_DIRTY_INODE)) 616 if (!is_inode_flag_set(inode, FI_DIRTY_INODE))
617 return 0; 617 return 0;
618 618
619 if (f2fs_is_checkpoint_ready(sbi)) 619 if (!f2fs_is_checkpoint_ready(sbi))
620 return -ENOSPC; 620 return -ENOSPC;
621 621
622 /* 622 /*
diff --git a/fs/f2fs/namei.c b/fs/f2fs/namei.c
index 9a28c5d9b3e9..4faf06e8bf89 100644
--- a/fs/f2fs/namei.c
+++ b/fs/f2fs/namei.c
@@ -272,9 +272,8 @@ static int f2fs_create(struct inode *dir, struct dentry *dentry, umode_t mode,
272 272
273 if (unlikely(f2fs_cp_error(sbi))) 273 if (unlikely(f2fs_cp_error(sbi)))
274 return -EIO; 274 return -EIO;
275 err = f2fs_is_checkpoint_ready(sbi); 275 if (!f2fs_is_checkpoint_ready(sbi))
276 if (err) 276 return -ENOSPC;
277 return err;
278 277
279 err = dquot_initialize(dir); 278 err = dquot_initialize(dir);
280 if (err) 279 if (err)
@@ -321,9 +320,8 @@ static int f2fs_link(struct dentry *old_dentry, struct inode *dir,
321 320
322 if (unlikely(f2fs_cp_error(sbi))) 321 if (unlikely(f2fs_cp_error(sbi)))
323 return -EIO; 322 return -EIO;
324 err = f2fs_is_checkpoint_ready(sbi); 323 if (!f2fs_is_checkpoint_ready(sbi))
325 if (err) 324 return -ENOSPC;
326 return err;
327 325
328 err = fscrypt_prepare_link(old_dentry, dir, dentry); 326 err = fscrypt_prepare_link(old_dentry, dir, dentry);
329 if (err) 327 if (err)
@@ -592,9 +590,8 @@ static int f2fs_symlink(struct inode *dir, struct dentry *dentry,
592 590
593 if (unlikely(f2fs_cp_error(sbi))) 591 if (unlikely(f2fs_cp_error(sbi)))
594 return -EIO; 592 return -EIO;
595 err = f2fs_is_checkpoint_ready(sbi); 593 if (!f2fs_is_checkpoint_ready(sbi))
596 if (err) 594 return -ENOSPC;
597 return err;
598 595
599 err = fscrypt_prepare_symlink(dir, symname, len, dir->i_sb->s_blocksize, 596 err = fscrypt_prepare_symlink(dir, symname, len, dir->i_sb->s_blocksize,
600 &disk_link); 597 &disk_link);
@@ -724,9 +721,8 @@ static int f2fs_mknod(struct inode *dir, struct dentry *dentry,
724 721
725 if (unlikely(f2fs_cp_error(sbi))) 722 if (unlikely(f2fs_cp_error(sbi)))
726 return -EIO; 723 return -EIO;
727 err = f2fs_is_checkpoint_ready(sbi); 724 if (!f2fs_is_checkpoint_ready(sbi))
728 if (err) 725 return -ENOSPC;
729 return err;
730 726
731 err = dquot_initialize(dir); 727 err = dquot_initialize(dir);
732 if (err) 728 if (err)
@@ -822,13 +818,11 @@ out:
822static int f2fs_tmpfile(struct inode *dir, struct dentry *dentry, umode_t mode) 818static int f2fs_tmpfile(struct inode *dir, struct dentry *dentry, umode_t mode)
823{ 819{
824 struct f2fs_sb_info *sbi = F2FS_I_SB(dir); 820 struct f2fs_sb_info *sbi = F2FS_I_SB(dir);
825 int ret;
826 821
827 if (unlikely(f2fs_cp_error(sbi))) 822 if (unlikely(f2fs_cp_error(sbi)))
828 return -EIO; 823 return -EIO;
829 ret = f2fs_is_checkpoint_ready(sbi); 824 if (!f2fs_is_checkpoint_ready(sbi))
830 if (ret) 825 return -ENOSPC;
831 return ret;
832 826
833 if (IS_ENCRYPTED(dir) || DUMMY_ENCRYPTION_ENABLED(sbi)) { 827 if (IS_ENCRYPTED(dir) || DUMMY_ENCRYPTION_ENABLED(sbi)) {
834 int err = fscrypt_get_encryption_info(dir); 828 int err = fscrypt_get_encryption_info(dir);
@@ -865,9 +859,8 @@ static int f2fs_rename(struct inode *old_dir, struct dentry *old_dentry,
865 859
866 if (unlikely(f2fs_cp_error(sbi))) 860 if (unlikely(f2fs_cp_error(sbi)))
867 return -EIO; 861 return -EIO;
868 err = f2fs_is_checkpoint_ready(sbi); 862 if (!f2fs_is_checkpoint_ready(sbi))
869 if (err) 863 return -ENOSPC;
870 return err;
871 864
872 if (is_inode_flag_set(new_dir, FI_PROJ_INHERIT) && 865 if (is_inode_flag_set(new_dir, FI_PROJ_INHERIT) &&
873 (!projid_eq(F2FS_I(new_dir)->i_projid, 866 (!projid_eq(F2FS_I(new_dir)->i_projid,
@@ -1060,9 +1053,8 @@ static int f2fs_cross_rename(struct inode *old_dir, struct dentry *old_dentry,
1060 1053
1061 if (unlikely(f2fs_cp_error(sbi))) 1054 if (unlikely(f2fs_cp_error(sbi)))
1062 return -EIO; 1055 return -EIO;
1063 err = f2fs_is_checkpoint_ready(sbi); 1056 if (!f2fs_is_checkpoint_ready(sbi))
1064 if (err) 1057 return -ENOSPC;
1065 return err;
1066 1058
1067 if ((is_inode_flag_set(new_dir, FI_PROJ_INHERIT) && 1059 if ((is_inode_flag_set(new_dir, FI_PROJ_INHERIT) &&
1068 !projid_eq(F2FS_I(new_dir)->i_projid, 1060 !projid_eq(F2FS_I(new_dir)->i_projid,
diff --git a/fs/f2fs/segment.c b/fs/f2fs/segment.c
index cc230fc829e1..18584d4c078a 100644
--- a/fs/f2fs/segment.c
+++ b/fs/f2fs/segment.c
@@ -501,7 +501,7 @@ void f2fs_balance_fs(struct f2fs_sb_info *sbi, bool need)
501 if (need && excess_cached_nats(sbi)) 501 if (need && excess_cached_nats(sbi))
502 f2fs_balance_fs_bg(sbi); 502 f2fs_balance_fs_bg(sbi);
503 503
504 if (f2fs_is_checkpoint_ready(sbi)) 504 if (!f2fs_is_checkpoint_ready(sbi))
505 return; 505 return;
506 506
507 /* 507 /*
diff --git a/fs/f2fs/segment.h b/fs/f2fs/segment.h
index b219009c3e20..325781a1ae4d 100644
--- a/fs/f2fs/segment.h
+++ b/fs/f2fs/segment.h
@@ -586,13 +586,13 @@ static inline bool has_not_enough_free_secs(struct f2fs_sb_info *sbi,
586 reserved_sections(sbi) + needed); 586 reserved_sections(sbi) + needed);
587} 587}
588 588
589static inline int f2fs_is_checkpoint_ready(struct f2fs_sb_info *sbi) 589static inline bool f2fs_is_checkpoint_ready(struct f2fs_sb_info *sbi)
590{ 590{
591 if (likely(!is_sbi_flag_set(sbi, SBI_CP_DISABLED))) 591 if (likely(!is_sbi_flag_set(sbi, SBI_CP_DISABLED)))
592 return 0; 592 return true;
593 if (likely(!has_not_enough_free_secs(sbi, 0, 0))) 593 if (likely(!has_not_enough_free_secs(sbi, 0, 0)))
594 return 0; 594 return true;
595 return -ENOSPC; 595 return false;
596} 596}
597 597
598static inline bool excess_prefree_segs(struct f2fs_sb_info *sbi) 598static inline bool excess_prefree_segs(struct f2fs_sb_info *sbi)
diff --git a/fs/f2fs/xattr.c b/fs/f2fs/xattr.c
index f85c810e33ca..181900af2576 100644
--- a/fs/f2fs/xattr.c
+++ b/fs/f2fs/xattr.c
@@ -732,9 +732,8 @@ int f2fs_setxattr(struct inode *inode, int index, const char *name,
732 732
733 if (unlikely(f2fs_cp_error(sbi))) 733 if (unlikely(f2fs_cp_error(sbi)))
734 return -EIO; 734 return -EIO;
735 err = f2fs_is_checkpoint_ready(sbi); 735 if (!f2fs_is_checkpoint_ready(sbi))
736 if (err) 736 return -ENOSPC;
737 return err;
738 737
739 err = dquot_initialize(inode); 738 err = dquot_initialize(inode);
740 if (err) 739 if (err)