Commit c473f1a9 authored by Chao Yu's avatar Chao Yu Committed by Jaegeuk Kim

f2fs: allow cpc->reason to indicate more than one reason

Change to use different bits of cpc->reason to indicate different status,
so cpc->reason can indicate more than one reason.
Signed-off-by: default avatarChao Yu <yuchao0@huawei.com>
Signed-off-by: default avatarJaegeuk Kim <jaegeuk@kernel.org>
parent 279d6df2
...@@ -1054,17 +1054,17 @@ static void update_ckpt_flags(struct f2fs_sb_info *sbi, struct cp_control *cpc) ...@@ -1054,17 +1054,17 @@ static void update_ckpt_flags(struct f2fs_sb_info *sbi, struct cp_control *cpc)
spin_lock(&sbi->cp_lock); spin_lock(&sbi->cp_lock);
if (cpc->reason == CP_UMOUNT && if ((cpc->reason & CP_UMOUNT) &&
le32_to_cpu(ckpt->cp_pack_total_block_count) > le32_to_cpu(ckpt->cp_pack_total_block_count) >
sbi->blocks_per_seg - NM_I(sbi)->nat_bits_blocks) sbi->blocks_per_seg - NM_I(sbi)->nat_bits_blocks)
disable_nat_bits(sbi, false); disable_nat_bits(sbi, false);
if (cpc->reason == CP_UMOUNT) if (cpc->reason & CP_UMOUNT)
__set_ckpt_flags(ckpt, CP_UMOUNT_FLAG); __set_ckpt_flags(ckpt, CP_UMOUNT_FLAG);
else else
__clear_ckpt_flags(ckpt, CP_UMOUNT_FLAG); __clear_ckpt_flags(ckpt, CP_UMOUNT_FLAG);
if (cpc->reason == CP_FASTBOOT) if (cpc->reason & CP_FASTBOOT)
__set_ckpt_flags(ckpt, CP_FASTBOOT_FLAG); __set_ckpt_flags(ckpt, CP_FASTBOOT_FLAG);
else else
__clear_ckpt_flags(ckpt, CP_FASTBOOT_FLAG); __clear_ckpt_flags(ckpt, CP_FASTBOOT_FLAG);
...@@ -1272,8 +1272,8 @@ int write_checkpoint(struct f2fs_sb_info *sbi, struct cp_control *cpc) ...@@ -1272,8 +1272,8 @@ int write_checkpoint(struct f2fs_sb_info *sbi, struct cp_control *cpc)
mutex_lock(&sbi->cp_mutex); mutex_lock(&sbi->cp_mutex);
if (!is_sbi_flag_set(sbi, SBI_IS_DIRTY) && if (!is_sbi_flag_set(sbi, SBI_IS_DIRTY) &&
(cpc->reason == CP_FASTBOOT || cpc->reason == CP_SYNC || ((cpc->reason & CP_FASTBOOT) || (cpc->reason & CP_SYNC) ||
(cpc->reason == CP_DISCARD && !sbi->discard_blks))) ((cpc->reason & CP_DISCARD) && !sbi->discard_blks)))
goto out; goto out;
if (unlikely(f2fs_cp_error(sbi))) { if (unlikely(f2fs_cp_error(sbi))) {
err = -EIO; err = -EIO;
...@@ -1295,7 +1295,7 @@ int write_checkpoint(struct f2fs_sb_info *sbi, struct cp_control *cpc) ...@@ -1295,7 +1295,7 @@ int write_checkpoint(struct f2fs_sb_info *sbi, struct cp_control *cpc)
f2fs_flush_merged_bios(sbi); f2fs_flush_merged_bios(sbi);
/* this is the case of multiple fstrims without any changes */ /* 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)) { if (!exist_trim_candidates(sbi, cpc)) {
unblock_operations(sbi); unblock_operations(sbi);
goto out; goto out;
...@@ -1333,7 +1333,7 @@ int write_checkpoint(struct f2fs_sb_info *sbi, struct cp_control *cpc) ...@@ -1333,7 +1333,7 @@ int write_checkpoint(struct f2fs_sb_info *sbi, struct cp_control *cpc)
unblock_operations(sbi); unblock_operations(sbi);
stat_inc_cp_count(sbi->stat_info); stat_inc_cp_count(sbi->stat_info);
if (cpc->reason == CP_RECOVERY) if (cpc->reason & CP_RECOVERY)
f2fs_msg(sbi->sb, KERN_NOTICE, f2fs_msg(sbi->sb, KERN_NOTICE,
"checkpoint: version = %llx", ckpt_ver); "checkpoint: version = %llx", ckpt_ver);
......
...@@ -125,13 +125,11 @@ enum { ...@@ -125,13 +125,11 @@ enum {
SIT_BITMAP SIT_BITMAP
}; };
enum { #define CP_UMOUNT 0x00000001
CP_UMOUNT, #define CP_FASTBOOT 0x00000002
CP_FASTBOOT, #define CP_SYNC 0x00000004
CP_SYNC, #define CP_RECOVERY 0x00000008
CP_RECOVERY, #define CP_DISCARD 0x00000010
CP_DISCARD,
};
#define DEF_BATCHED_TRIM_SECTIONS 2048 #define DEF_BATCHED_TRIM_SECTIONS 2048
#define BATCHED_TRIM_SEGMENTS(sbi) \ #define BATCHED_TRIM_SEGMENTS(sbi) \
...@@ -1265,7 +1263,7 @@ static inline bool enabled_nat_bits(struct f2fs_sb_info *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); 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) 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) ...@@ -1301,7 +1299,7 @@ static inline int __get_cp_reason(struct f2fs_sb_info *sbi)
static inline bool __remain_node_summaries(int reason) 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) static inline bool __exist_node_summaries(struct f2fs_sb_info *sbi)
......
...@@ -1183,7 +1183,7 @@ static bool add_discard_addrs(struct f2fs_sb_info *sbi, struct cp_control *cpc, ...@@ -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 *discard_map = (unsigned long *)se->discard_map;
unsigned long *dmap = SIT_I(sbi)->tmp_map; unsigned long *dmap = SIT_I(sbi)->tmp_map;
unsigned int start = 0, end = -1; unsigned int start = 0, end = -1;
bool force = (cpc->reason == CP_DISCARD); bool force = (cpc->reason & CP_DISCARD);
struct discard_entry *de = NULL; struct discard_entry *de = NULL;
struct list_head *head = &SM_I(sbi)->dcc_info->entry_list; struct list_head *head = &SM_I(sbi)->dcc_info->entry_list;
int i; int i;
...@@ -1266,7 +1266,7 @@ void clear_prefree_segments(struct f2fs_sb_info *sbi, struct cp_control *cpc) ...@@ -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 long *prefree_map = dirty_i->dirty_segmap[PRE];
unsigned int start = 0, end = -1; unsigned int start = 0, end = -1;
unsigned int secno, start_segno; unsigned int secno, start_segno;
bool force = (cpc->reason == CP_DISCARD); bool force = (cpc->reason & CP_DISCARD);
mutex_lock(&dirty_i->seglist_lock); mutex_lock(&dirty_i->seglist_lock);
...@@ -2770,7 +2770,7 @@ void flush_sit_entries(struct f2fs_sb_info *sbi, struct cp_control *cpc) ...@@ -2770,7 +2770,7 @@ void flush_sit_entries(struct f2fs_sb_info *sbi, struct cp_control *cpc)
se = get_seg_entry(sbi, segno); se = get_seg_entry(sbi, segno);
/* add discard candidates */ /* add discard candidates */
if (cpc->reason != CP_DISCARD) { if (!(cpc->reason & CP_DISCARD)) {
cpc->trim_start = segno; cpc->trim_start = segno;
add_discard_addrs(sbi, cpc, false); add_discard_addrs(sbi, cpc, false);
} }
...@@ -2806,7 +2806,7 @@ void flush_sit_entries(struct f2fs_sb_info *sbi, struct cp_control *cpc) ...@@ -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, !list_empty(head));
f2fs_bug_on(sbi, sit_i->dirty_sentries); f2fs_bug_on(sbi, sit_i->dirty_sentries);
out: out:
if (cpc->reason == CP_DISCARD) { if (cpc->reason & CP_DISCARD) {
__u64 trim_start = cpc->trim_start; __u64 trim_start = cpc->trim_start;
for (; cpc->trim_start <= cpc->trim_end; cpc->trim_start++) for (; cpc->trim_start <= cpc->trim_end; cpc->trim_start++)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment