aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--fs/f2fs/checkpoint.c12
-rw-r--r--fs/f2fs/data.c2
-rw-r--r--fs/f2fs/f2fs.h30
-rw-r--r--fs/f2fs/node.c4
-rw-r--r--fs/f2fs/recovery.c4
-rw-r--r--fs/f2fs/segment.h10
-rw-r--r--fs/f2fs/super.c15
-rw-r--r--include/trace/events/f2fs.h4
8 files changed, 46 insertions, 35 deletions
diff --git a/fs/f2fs/checkpoint.c b/fs/f2fs/checkpoint.c
index 79f82819086f..19021414d195 100644
--- a/fs/f2fs/checkpoint.c
+++ b/fs/f2fs/checkpoint.c
@@ -190,7 +190,7 @@ static int f2fs_write_meta_page(struct page *page,
190 190
191 trace_f2fs_writepage(page, META); 191 trace_f2fs_writepage(page, META);
192 192
193 if (unlikely(sbi->por_doing)) 193 if (unlikely(is_sbi_flag_set(sbi, SBI_POR_DOING)))
194 goto redirty_out; 194 goto redirty_out;
195 if (wbc->for_reclaim && page->index < GET_SUM_BLOCK(sbi, 0)) 195 if (wbc->for_reclaim && page->index < GET_SUM_BLOCK(sbi, 0))
196 goto redirty_out; 196 goto redirty_out;
@@ -485,7 +485,7 @@ void recover_orphan_inodes(struct f2fs_sb_info *sbi)
485 if (!is_set_ckpt_flags(F2FS_CKPT(sbi), CP_ORPHAN_PRESENT_FLAG)) 485 if (!is_set_ckpt_flags(F2FS_CKPT(sbi), CP_ORPHAN_PRESENT_FLAG))
486 return; 486 return;
487 487
488 sbi->por_doing = true; 488 set_sbi_flag(sbi, SBI_POR_DOING);
489 489
490 start_blk = __start_cp_addr(sbi) + 1 + 490 start_blk = __start_cp_addr(sbi) + 1 +
491 le32_to_cpu(F2FS_RAW_SUPER(sbi)->cp_payload); 491 le32_to_cpu(F2FS_RAW_SUPER(sbi)->cp_payload);
@@ -506,7 +506,7 @@ void recover_orphan_inodes(struct f2fs_sb_info *sbi)
506 } 506 }
507 /* clear Orphan Flag */ 507 /* clear Orphan Flag */
508 clear_ckpt_flags(F2FS_CKPT(sbi), CP_ORPHAN_PRESENT_FLAG); 508 clear_ckpt_flags(F2FS_CKPT(sbi), CP_ORPHAN_PRESENT_FLAG);
509 sbi->por_doing = false; 509 clear_sbi_flag(sbi, SBI_POR_DOING);
510 return; 510 return;
511} 511}
512 512
@@ -973,7 +973,7 @@ static void do_checkpoint(struct f2fs_sb_info *sbi, struct cp_control *cpc)
973 else 973 else
974 clear_ckpt_flags(ckpt, CP_ORPHAN_PRESENT_FLAG); 974 clear_ckpt_flags(ckpt, CP_ORPHAN_PRESENT_FLAG);
975 975
976 if (sbi->need_fsck) 976 if (is_sbi_flag_set(sbi, SBI_NEED_FSCK))
977 set_ckpt_flags(ckpt, CP_FSCK_FLAG); 977 set_ckpt_flags(ckpt, CP_FSCK_FLAG);
978 978
979 /* update SIT/NAT bitmap */ 979 /* update SIT/NAT bitmap */
@@ -1047,7 +1047,7 @@ static void do_checkpoint(struct f2fs_sb_info *sbi, struct cp_control *cpc)
1047 return; 1047 return;
1048 1048
1049 clear_prefree_segments(sbi); 1049 clear_prefree_segments(sbi);
1050 F2FS_RESET_SB_DIRT(sbi); 1050 clear_sbi_flag(sbi, SBI_IS_DIRTY);
1051} 1051}
1052 1052
1053/* 1053/*
@@ -1062,7 +1062,7 @@ void write_checkpoint(struct f2fs_sb_info *sbi, struct cp_control *cpc)
1062 1062
1063 mutex_lock(&sbi->cp_mutex); 1063 mutex_lock(&sbi->cp_mutex);
1064 1064
1065 if (!sbi->s_dirty && 1065 if (!is_sbi_flag_set(sbi, SBI_IS_DIRTY) &&
1066 cpc->reason != CP_DISCARD && cpc->reason != CP_UMOUNT) 1066 cpc->reason != CP_DISCARD && cpc->reason != CP_UMOUNT)
1067 goto out; 1067 goto out;
1068 if (unlikely(f2fs_cp_error(sbi))) 1068 if (unlikely(f2fs_cp_error(sbi)))
diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c
index a7b905cb05f8..6d9e6e4ce439 100644
--- a/fs/f2fs/data.c
+++ b/fs/f2fs/data.c
@@ -818,7 +818,7 @@ static int f2fs_write_data_page(struct page *page,
818 818
819 zero_user_segment(page, offset, PAGE_CACHE_SIZE); 819 zero_user_segment(page, offset, PAGE_CACHE_SIZE);
820write: 820write:
821 if (unlikely(sbi->por_doing)) 821 if (unlikely(is_sbi_flag_set(sbi, SBI_POR_DOING)))
822 goto redirty_out; 822 goto redirty_out;
823 if (f2fs_is_drop_cache(inode)) 823 if (f2fs_is_drop_cache(inode))
824 goto out; 824 goto out;
diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h
index 9e1fcc1f64ee..5abe0836c179 100644
--- a/fs/f2fs/f2fs.h
+++ b/fs/f2fs/f2fs.h
@@ -28,7 +28,7 @@
28 do { \ 28 do { \
29 if (unlikely(condition)) { \ 29 if (unlikely(condition)) { \
30 WARN_ON(1); \ 30 WARN_ON(1); \
31 sbi->need_fsck = true; \ 31 set_sbi_flag(sbi, SBI_NEED_FSCK); \
32 } \ 32 } \
33 } while (0) 33 } while (0)
34#define f2fs_down_write(x, y) down_write(x) 34#define f2fs_down_write(x, y) down_write(x)
@@ -519,14 +519,20 @@ struct inode_management {
519 unsigned long ino_num; /* number of entries */ 519 unsigned long ino_num; /* number of entries */
520}; 520};
521 521
522/* For s_flag in struct f2fs_sb_info */
523enum {
524 SBI_IS_DIRTY, /* dirty flag for checkpoint */
525 SBI_IS_CLOSE, /* specify unmounting */
526 SBI_NEED_FSCK, /* need fsck.f2fs to fix */
527 SBI_POR_DOING, /* recovery is doing or not */
528};
529
522struct f2fs_sb_info { 530struct f2fs_sb_info {
523 struct super_block *sb; /* pointer to VFS super block */ 531 struct super_block *sb; /* pointer to VFS super block */
524 struct proc_dir_entry *s_proc; /* proc entry */ 532 struct proc_dir_entry *s_proc; /* proc entry */
525 struct buffer_head *raw_super_buf; /* buffer head of raw sb */ 533 struct buffer_head *raw_super_buf; /* buffer head of raw sb */
526 struct f2fs_super_block *raw_super; /* raw super block pointer */ 534 struct f2fs_super_block *raw_super; /* raw super block pointer */
527 int s_dirty; /* dirty flag for checkpoint */ 535 int s_flag; /* flags for sbi */
528 bool need_fsck; /* need fsck.f2fs to fix */
529 bool s_closing; /* specify unmounting */
530 536
531 /* for node-related operations */ 537 /* for node-related operations */
532 struct f2fs_nm_info *nm_info; /* node manager */ 538 struct f2fs_nm_info *nm_info; /* node manager */
@@ -546,7 +552,6 @@ struct f2fs_sb_info {
546 struct rw_semaphore cp_rwsem; /* blocking FS operations */ 552 struct rw_semaphore cp_rwsem; /* blocking FS operations */
547 struct rw_semaphore node_write; /* locking node writes */ 553 struct rw_semaphore node_write; /* locking node writes */
548 struct mutex writepages; /* mutex for writepages() */ 554 struct mutex writepages; /* mutex for writepages() */
549 bool por_doing; /* recovery is doing or not */
550 wait_queue_head_t cp_wait; 555 wait_queue_head_t cp_wait;
551 556
552 struct inode_management im[MAX_INO_ENTRY]; /* manage inode cache */ 557 struct inode_management im[MAX_INO_ENTRY]; /* manage inode cache */
@@ -699,14 +704,19 @@ static inline struct address_space *NODE_MAPPING(struct f2fs_sb_info *sbi)
699 return sbi->node_inode->i_mapping; 704 return sbi->node_inode->i_mapping;
700} 705}
701 706
702static inline void F2FS_SET_SB_DIRT(struct f2fs_sb_info *sbi) 707static inline bool is_sbi_flag_set(struct f2fs_sb_info *sbi, unsigned int type)
708{
709 return sbi->s_flag & (0x01 << type);
710}
711
712static inline void set_sbi_flag(struct f2fs_sb_info *sbi, unsigned int type)
703{ 713{
704 sbi->s_dirty = 1; 714 sbi->s_flag |= (0x01 << type);
705} 715}
706 716
707static inline void F2FS_RESET_SB_DIRT(struct f2fs_sb_info *sbi) 717static inline void clear_sbi_flag(struct f2fs_sb_info *sbi, unsigned int type)
708{ 718{
709 sbi->s_dirty = 0; 719 sbi->s_flag &= ~(0x01 << type);
710} 720}
711 721
712static inline unsigned long long cur_cp_version(struct f2fs_checkpoint *cp) 722static inline unsigned long long cur_cp_version(struct f2fs_checkpoint *cp)
@@ -818,7 +828,7 @@ static inline void dec_valid_block_count(struct f2fs_sb_info *sbi,
818static inline void inc_page_count(struct f2fs_sb_info *sbi, int count_type) 828static inline void inc_page_count(struct f2fs_sb_info *sbi, int count_type)
819{ 829{
820 atomic_inc(&sbi->nr_pages[count_type]); 830 atomic_inc(&sbi->nr_pages[count_type]);
821 F2FS_SET_SB_DIRT(sbi); 831 set_sbi_flag(sbi, SBI_IS_DIRTY);
822} 832}
823 833
824static inline void inode_inc_dirty_pages(struct inode *inode) 834static inline void inode_inc_dirty_pages(struct inode *inode)
diff --git a/fs/f2fs/node.c b/fs/f2fs/node.c
index d7c143626705..05e6faa71cff 100644
--- a/fs/f2fs/node.c
+++ b/fs/f2fs/node.c
@@ -588,7 +588,7 @@ static void truncate_node(struct dnode_of_data *dn)
588 } 588 }
589invalidate: 589invalidate:
590 clear_node_page_dirty(dn->node_page); 590 clear_node_page_dirty(dn->node_page);
591 F2FS_SET_SB_DIRT(sbi); 591 set_sbi_flag(sbi, SBI_IS_DIRTY);
592 592
593 f2fs_put_page(dn->node_page, 1); 593 f2fs_put_page(dn->node_page, 1);
594 594
@@ -1284,7 +1284,7 @@ static int f2fs_write_node_page(struct page *page,
1284 1284
1285 trace_f2fs_writepage(page, NODE); 1285 trace_f2fs_writepage(page, NODE);
1286 1286
1287 if (unlikely(sbi->por_doing)) 1287 if (unlikely(is_sbi_flag_set(sbi, SBI_POR_DOING)))
1288 goto redirty_out; 1288 goto redirty_out;
1289 if (unlikely(f2fs_cp_error(sbi))) 1289 if (unlikely(f2fs_cp_error(sbi)))
1290 goto redirty_out; 1290 goto redirty_out;
diff --git a/fs/f2fs/recovery.c b/fs/f2fs/recovery.c
index 57603a7127f7..41afb9534bbd 100644
--- a/fs/f2fs/recovery.c
+++ b/fs/f2fs/recovery.c
@@ -508,7 +508,7 @@ int recover_fsync_data(struct f2fs_sb_info *sbi)
508 INIT_LIST_HEAD(&inode_list); 508 INIT_LIST_HEAD(&inode_list);
509 509
510 /* step #1: find fsynced inode numbers */ 510 /* step #1: find fsynced inode numbers */
511 sbi->por_doing = true; 511 set_sbi_flag(sbi, SBI_POR_DOING);
512 512
513 /* prevent checkpoint */ 513 /* prevent checkpoint */
514 mutex_lock(&sbi->cp_mutex); 514 mutex_lock(&sbi->cp_mutex);
@@ -541,7 +541,7 @@ out:
541 truncate_inode_pages_final(META_MAPPING(sbi)); 541 truncate_inode_pages_final(META_MAPPING(sbi));
542 } 542 }
543 543
544 sbi->por_doing = false; 544 clear_sbi_flag(sbi, SBI_POR_DOING);
545 if (err) { 545 if (err) {
546 discard_next_dnode(sbi, blkaddr); 546 discard_next_dnode(sbi, blkaddr);
547 547
diff --git a/fs/f2fs/segment.h b/fs/f2fs/segment.h
index 7f327c0ba4e3..421d5794b0c8 100644
--- a/fs/f2fs/segment.h
+++ b/fs/f2fs/segment.h
@@ -460,7 +460,7 @@ static inline bool has_not_enough_free_secs(struct f2fs_sb_info *sbi, int freed)
460 int node_secs = get_blocktype_secs(sbi, F2FS_DIRTY_NODES); 460 int node_secs = get_blocktype_secs(sbi, F2FS_DIRTY_NODES);
461 int dent_secs = get_blocktype_secs(sbi, F2FS_DIRTY_DENTS); 461 int dent_secs = get_blocktype_secs(sbi, F2FS_DIRTY_DENTS);
462 462
463 if (unlikely(sbi->por_doing)) 463 if (unlikely(is_sbi_flag_set(sbi, SBI_POR_DOING)))
464 return false; 464 return false;
465 465
466 return (free_sections(sbi) + freed) <= (node_secs + 2 * dent_secs + 466 return (free_sections(sbi) + freed) <= (node_secs + 2 * dent_secs +
@@ -599,13 +599,13 @@ static inline void check_block_count(struct f2fs_sb_info *sbi,
599static inline void check_seg_range(struct f2fs_sb_info *sbi, unsigned int segno) 599static inline void check_seg_range(struct f2fs_sb_info *sbi, unsigned int segno)
600{ 600{
601 if (segno > TOTAL_SEGS(sbi) - 1) 601 if (segno > TOTAL_SEGS(sbi) - 1)
602 sbi->need_fsck = true; 602 set_sbi_flag(sbi, SBI_NEED_FSCK);
603} 603}
604 604
605static inline void verify_block_addr(struct f2fs_sb_info *sbi, block_t blk_addr) 605static inline void verify_block_addr(struct f2fs_sb_info *sbi, block_t blk_addr)
606{ 606{
607 if (blk_addr < SEG0_BLKADDR(sbi) || blk_addr >= MAX_BLKADDR(sbi)) 607 if (blk_addr < SEG0_BLKADDR(sbi) || blk_addr >= MAX_BLKADDR(sbi))
608 sbi->need_fsck = true; 608 set_sbi_flag(sbi, SBI_NEED_FSCK);
609} 609}
610 610
611/* 611/*
@@ -616,11 +616,11 @@ static inline void check_block_count(struct f2fs_sb_info *sbi,
616{ 616{
617 /* check segment usage */ 617 /* check segment usage */
618 if (GET_SIT_VBLOCKS(raw_sit) > sbi->blocks_per_seg) 618 if (GET_SIT_VBLOCKS(raw_sit) > sbi->blocks_per_seg)
619 sbi->need_fsck = true; 619 set_sbi_flag(sbi, SBI_NEED_FSCK);
620 620
621 /* check boundary of a given segment number */ 621 /* check boundary of a given segment number */
622 if (segno > TOTAL_SEGS(sbi) - 1) 622 if (segno > TOTAL_SEGS(sbi) - 1)
623 sbi->need_fsck = true; 623 set_sbi_flag(sbi, SBI_NEED_FSCK);
624} 624}
625#endif 625#endif
626 626
diff --git a/fs/f2fs/super.c b/fs/f2fs/super.c
index 0d627f2d1828..c3aa72f9c8c8 100644
--- a/fs/f2fs/super.c
+++ b/fs/f2fs/super.c
@@ -452,7 +452,7 @@ static void f2fs_put_super(struct super_block *sb)
452 * But, the previous checkpoint was not done by umount, it needs to do 452 * But, the previous checkpoint was not done by umount, it needs to do
453 * clean checkpoint again. 453 * clean checkpoint again.
454 */ 454 */
455 if (sbi->s_dirty || 455 if (is_sbi_flag_set(sbi, SBI_IS_DIRTY) ||
456 !is_set_ckpt_flags(F2FS_CKPT(sbi), CP_UMOUNT_FLAG)) { 456 !is_set_ckpt_flags(F2FS_CKPT(sbi), CP_UMOUNT_FLAG)) {
457 struct cp_control cpc = { 457 struct cp_control cpc = {
458 .reason = CP_UMOUNT, 458 .reason = CP_UMOUNT,
@@ -492,8 +492,9 @@ int f2fs_sync_fs(struct super_block *sb, int sync)
492 if (sync) { 492 if (sync) {
493 struct cp_control cpc; 493 struct cp_control cpc;
494 494
495 cpc.reason = (test_opt(sbi, FASTBOOT) || sbi->s_closing) ? 495 cpc.reason = (test_opt(sbi, FASTBOOT) ||
496 CP_UMOUNT : CP_SYNC; 496 is_sbi_flag_set(sbi, SBI_IS_CLOSE)) ?
497 CP_UMOUNT : CP_SYNC;
497 mutex_lock(&sbi->gc_mutex); 498 mutex_lock(&sbi->gc_mutex);
498 write_checkpoint(sbi, &cpc); 499 write_checkpoint(sbi, &cpc);
499 mutex_unlock(&sbi->gc_mutex); 500 mutex_unlock(&sbi->gc_mutex);
@@ -895,7 +896,7 @@ static void init_sb_info(struct f2fs_sb_info *sbi)
895 atomic_set(&sbi->nr_pages[i], 0); 896 atomic_set(&sbi->nr_pages[i], 0);
896 897
897 sbi->dir_level = DEF_DIR_LEVEL; 898 sbi->dir_level = DEF_DIR_LEVEL;
898 sbi->need_fsck = false; 899 clear_sbi_flag(sbi, SBI_NEED_FSCK);
899} 900}
900 901
901/* 902/*
@@ -1006,7 +1007,7 @@ try_onemore:
1006 mutex_init(&sbi->writepages); 1007 mutex_init(&sbi->writepages);
1007 mutex_init(&sbi->cp_mutex); 1008 mutex_init(&sbi->cp_mutex);
1008 init_rwsem(&sbi->node_write); 1009 init_rwsem(&sbi->node_write);
1009 sbi->por_doing = false; 1010 clear_sbi_flag(sbi, SBI_POR_DOING);
1010 spin_lock_init(&sbi->stat_lock); 1011 spin_lock_init(&sbi->stat_lock);
1011 1012
1012 init_rwsem(&sbi->read_io.io_rwsem); 1013 init_rwsem(&sbi->read_io.io_rwsem);
@@ -1130,7 +1131,7 @@ try_onemore:
1130 goto free_proc; 1131 goto free_proc;
1131 1132
1132 if (!retry) 1133 if (!retry)
1133 sbi->need_fsck = true; 1134 set_sbi_flag(sbi, SBI_NEED_FSCK);
1134 1135
1135 /* recover fsynced data */ 1136 /* recover fsynced data */
1136 if (!test_opt(sbi, DISABLE_ROLL_FORWARD)) { 1137 if (!test_opt(sbi, DISABLE_ROLL_FORWARD)) {
@@ -1199,7 +1200,7 @@ static struct dentry *f2fs_mount(struct file_system_type *fs_type, int flags,
1199static void kill_f2fs_super(struct super_block *sb) 1200static void kill_f2fs_super(struct super_block *sb)
1200{ 1201{
1201 if (sb->s_root) 1202 if (sb->s_root)
1202 F2FS_SB(sb)->s_closing = true; 1203 set_sbi_flag(F2FS_SB(sb), SBI_IS_CLOSE);
1203 kill_block_super(sb); 1204 kill_block_super(sb);
1204} 1205}
1205 1206
diff --git a/include/trace/events/f2fs.h b/include/trace/events/f2fs.h
index 13992f3c1445..5e1c0292250c 100644
--- a/include/trace/events/f2fs.h
+++ b/include/trace/events/f2fs.h
@@ -184,13 +184,13 @@ TRACE_EVENT(f2fs_sync_fs,
184 184
185 TP_STRUCT__entry( 185 TP_STRUCT__entry(
186 __field(dev_t, dev) 186 __field(dev_t, dev)
187 __field(int, dirty) 187 __field(bool, dirty)
188 __field(int, wait) 188 __field(int, wait)
189 ), 189 ),
190 190
191 TP_fast_assign( 191 TP_fast_assign(
192 __entry->dev = sb->s_dev; 192 __entry->dev = sb->s_dev;
193 __entry->dirty = F2FS_SB(sb)->s_dirty; 193 __entry->dirty = is_sbi_flag_set(F2FS_SB(sb), SBI_IS_DIRTY);
194 __entry->wait = wait; 194 __entry->wait = wait;
195 ), 195 ),
196 196