]> git.kernelconcepts.de Git - karo-tx-linux.git/commitdiff
f2fs: allow cpc->reason to indicate more than one reason
authorChao Yu <yuchao0@huawei.com>
Thu, 27 Apr 2017 12:40:39 +0000 (20:40 +0800)
committerJaegeuk Kim <jaegeuk@kernel.org>
Wed, 3 May 2017 17:04:55 +0000 (10:04 -0700)
Change to use different bits of cpc->reason to indicate different status,
so cpc->reason can indicate more than one reason.

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

index 800be94f8cb3a629c84663275658871a1b6ca853..27578903eeb66146ff2cbf8c737d8f4264e06621 100644 (file)
@@ -1054,17 +1054,17 @@ static void update_ckpt_flags(struct f2fs_sb_info *sbi, struct cp_control *cpc)
 
        spin_lock(&sbi->cp_lock);
 
-       if (cpc->reason == CP_UMOUNT &&
+       if ((cpc->reason & CP_UMOUNT) &&
                        le32_to_cpu(ckpt->cp_pack_total_block_count) >
                        sbi->blocks_per_seg - NM_I(sbi)->nat_bits_blocks)
                disable_nat_bits(sbi, false);
 
-       if (cpc->reason == CP_UMOUNT)
+       if (cpc->reason & CP_UMOUNT)
                __set_ckpt_flags(ckpt, CP_UMOUNT_FLAG);
        else
                __clear_ckpt_flags(ckpt, CP_UMOUNT_FLAG);
 
-       if (cpc->reason == CP_FASTBOOT)
+       if (cpc->reason & CP_FASTBOOT)
                __set_ckpt_flags(ckpt, CP_FASTBOOT_FLAG);
        else
                __clear_ckpt_flags(ckpt, CP_FASTBOOT_FLAG);
@@ -1272,8 +1272,8 @@ int write_checkpoint(struct f2fs_sb_info *sbi, struct cp_control *cpc)
        mutex_lock(&sbi->cp_mutex);
 
        if (!is_sbi_flag_set(sbi, SBI_IS_DIRTY) &&
-               (cpc->reason == CP_FASTBOOT || cpc->reason == CP_SYNC ||
-               (cpc->reason == CP_DISCARD && !sbi->discard_blks)))
+               ((cpc->reason & CP_FASTBOOT) || (cpc->reason & CP_SYNC) ||
+               ((cpc->reason & CP_DISCARD) && !sbi->discard_blks)))
                goto out;
        if (unlikely(f2fs_cp_error(sbi))) {
                err = -EIO;
@@ -1295,7 +1295,7 @@ int write_checkpoint(struct f2fs_sb_info *sbi, struct cp_control *cpc)
        f2fs_flush_merged_bios(sbi);
 
        /* this is the case of multiple fstrims without any changes */
-       if (cpc->reason == CP_DISCARD) {
+       if (cpc->reason & CP_DISCARD) {
                if (!exist_trim_candidates(sbi, cpc)) {
                        unblock_operations(sbi);
                        goto out;
@@ -1333,7 +1333,7 @@ int write_checkpoint(struct f2fs_sb_info *sbi, struct cp_control *cpc)
        unblock_operations(sbi);
        stat_inc_cp_count(sbi->stat_info);
 
-       if (cpc->reason == CP_RECOVERY)
+       if (cpc->reason & CP_RECOVERY)
                f2fs_msg(sbi->sb, KERN_NOTICE,
                        "checkpoint: version = %llx", ckpt_ver);
 
index 713f072e5fbc30dd867326dff7cab6e467dd8942..37360b9ad2631acc7563e25cdd15ad2626e38c87 100644 (file)
@@ -125,13 +125,11 @@ enum {
        SIT_BITMAP
 };
 
-enum {
-       CP_UMOUNT,
-       CP_FASTBOOT,
-       CP_SYNC,
-       CP_RECOVERY,
-       CP_DISCARD,
-};
+#define        CP_UMOUNT       0x00000001
+#define        CP_FASTBOOT     0x00000002
+#define        CP_SYNC         0x00000004
+#define        CP_RECOVERY     0x00000008
+#define        CP_DISCARD      0x00000010
 
 #define DEF_BATCHED_TRIM_SECTIONS      2048
 #define BATCHED_TRIM_SEGMENTS(sbi)     \
@@ -1265,7 +1263,7 @@ static inline bool enabled_nat_bits(struct f2fs_sb_info *sbi,
 {
        bool set = is_set_ckpt_flags(sbi, CP_NAT_BITS_FLAG);
 
-       return (cpc) ? (cpc->reason == CP_UMOUNT) && set : set;
+       return (cpc) ? (cpc->reason & CP_UMOUNT) && set : set;
 }
 
 static inline void f2fs_lock_op(struct f2fs_sb_info *sbi)
@@ -1301,7 +1299,7 @@ static inline int __get_cp_reason(struct f2fs_sb_info *sbi)
 
 static inline bool __remain_node_summaries(int reason)
 {
-       return (reason == CP_UMOUNT || reason == CP_FASTBOOT);
+       return (reason & (CP_UMOUNT | CP_FASTBOOT));
 }
 
 static inline bool __exist_node_summaries(struct f2fs_sb_info *sbi)
index e302f30ec7fe6d09c03f103175bdba19ac12abd0..69b99a8f9a01293a1f7620c2dff3eccfa633ecd5 100644 (file)
@@ -1183,7 +1183,7 @@ static bool add_discard_addrs(struct f2fs_sb_info *sbi, struct cp_control *cpc,
        unsigned long *discard_map = (unsigned long *)se->discard_map;
        unsigned long *dmap = SIT_I(sbi)->tmp_map;
        unsigned int start = 0, end = -1;
-       bool force = (cpc->reason == CP_DISCARD);
+       bool force = (cpc->reason & CP_DISCARD);
        struct discard_entry *de = NULL;
        struct list_head *head = &SM_I(sbi)->dcc_info->entry_list;
        int i;
@@ -1266,7 +1266,7 @@ void clear_prefree_segments(struct f2fs_sb_info *sbi, struct cp_control *cpc)
        unsigned long *prefree_map = dirty_i->dirty_segmap[PRE];
        unsigned int start = 0, end = -1;
        unsigned int secno, start_segno;
-       bool force = (cpc->reason == CP_DISCARD);
+       bool force = (cpc->reason & CP_DISCARD);
 
        mutex_lock(&dirty_i->seglist_lock);
 
@@ -2770,7 +2770,7 @@ void flush_sit_entries(struct f2fs_sb_info *sbi, struct cp_control *cpc)
                        se = get_seg_entry(sbi, segno);
 
                        /* add discard candidates */
-                       if (cpc->reason != CP_DISCARD) {
+                       if (!(cpc->reason & CP_DISCARD)) {
                                cpc->trim_start = segno;
                                add_discard_addrs(sbi, cpc, false);
                        }
@@ -2806,7 +2806,7 @@ void flush_sit_entries(struct f2fs_sb_info *sbi, struct cp_control *cpc)
        f2fs_bug_on(sbi, !list_empty(head));
        f2fs_bug_on(sbi, sit_i->dirty_sentries);
 out:
-       if (cpc->reason == CP_DISCARD) {
+       if (cpc->reason & CP_DISCARD) {
                __u64 trim_start = cpc->trim_start;
 
                for (; cpc->trim_start <= cpc->trim_end; cpc->trim_start++)