@@ -160,14 +160,11 @@ static int f2fs_write_meta_page(struct page *page,
160160 goto redirty_out ;
161161 if (wbc -> for_reclaim )
162162 goto redirty_out ;
163-
164- /* Should not write any meta pages, if any IO error was occurred */
165- if (unlikely (is_set_ckpt_flags (F2FS_CKPT (sbi ), CP_ERROR_FLAG )))
166- goto no_write ;
163+ if (unlikely (f2fs_cp_error (sbi )))
164+ goto redirty_out ;
167165
168166 f2fs_wait_on_page_writeback (page , META );
169167 write_meta_page (sbi , page );
170- no_write :
171168 dec_page_count (sbi , F2FS_DIRTY_META );
172169 unlock_page (page );
173170 return 0 ;
@@ -348,7 +345,7 @@ bool exist_written_data(struct f2fs_sb_info *sbi, nid_t ino, int mode)
348345 return e ? true : false;
349346}
350347
351- static void release_dirty_inode (struct f2fs_sb_info * sbi )
348+ void release_dirty_inode (struct f2fs_sb_info * sbi )
352349{
353350 struct ino_entry * e , * tmp ;
354351 int i ;
@@ -446,8 +443,8 @@ static void write_orphan_inodes(struct f2fs_sb_info *sbi, block_t start_blk)
446443 struct f2fs_orphan_block * orphan_blk = NULL ;
447444 unsigned int nentries = 0 ;
448445 unsigned short index ;
449- unsigned short orphan_blocks = ( unsigned short )(( sbi -> n_orphans +
450- ( F2FS_ORPHANS_PER_BLOCK - 1 )) / F2FS_ORPHANS_PER_BLOCK );
446+ unsigned short orphan_blocks =
447+ ( unsigned short ) GET_ORPHAN_BLOCKS ( sbi -> n_orphans );
451448 struct page * page = NULL ;
452449 struct ino_entry * orphan = NULL ;
453450
@@ -737,14 +734,15 @@ void sync_dirty_dir_inodes(struct f2fs_sb_info *sbi)
737734/*
738735 * Freeze all the FS-operations for checkpoint.
739736 */
740- static void block_operations (struct f2fs_sb_info * sbi )
737+ static int block_operations (struct f2fs_sb_info * sbi )
741738{
742739 struct writeback_control wbc = {
743740 .sync_mode = WB_SYNC_ALL ,
744741 .nr_to_write = LONG_MAX ,
745742 .for_reclaim = 0 ,
746743 };
747744 struct blk_plug plug ;
745+ int err = 0 ;
748746
749747 blk_start_plug (& plug );
750748
@@ -754,11 +752,15 @@ static void block_operations(struct f2fs_sb_info *sbi)
754752 if (get_pages (sbi , F2FS_DIRTY_DENTS )) {
755753 f2fs_unlock_all (sbi );
756754 sync_dirty_dir_inodes (sbi );
755+ if (unlikely (f2fs_cp_error (sbi ))) {
756+ err = - EIO ;
757+ goto out ;
758+ }
757759 goto retry_flush_dents ;
758760 }
759761
760762 /*
761- * POR: we should ensure that there is no dirty node pages
763+ * POR: we should ensure that there are no dirty node pages
762764 * until finishing nat/sit flush.
763765 */
764766retry_flush_nodes :
@@ -767,9 +769,16 @@ static void block_operations(struct f2fs_sb_info *sbi)
767769 if (get_pages (sbi , F2FS_DIRTY_NODES )) {
768770 up_write (& sbi -> node_write );
769771 sync_node_pages (sbi , 0 , & wbc );
772+ if (unlikely (f2fs_cp_error (sbi ))) {
773+ f2fs_unlock_all (sbi );
774+ err = - EIO ;
775+ goto out ;
776+ }
770777 goto retry_flush_nodes ;
771778 }
779+ out :
772780 blk_finish_plug (& plug );
781+ return err ;
773782}
774783
775784static void unblock_operations (struct f2fs_sb_info * sbi )
@@ -813,8 +822,11 @@ static void do_checkpoint(struct f2fs_sb_info *sbi, bool is_umount)
813822 discard_next_dnode (sbi , NEXT_FREE_BLKADDR (sbi , curseg ));
814823
815824 /* Flush all the NAT/SIT pages */
816- while (get_pages (sbi , F2FS_DIRTY_META ))
825+ while (get_pages (sbi , F2FS_DIRTY_META )) {
817826 sync_meta_pages (sbi , META , LONG_MAX );
827+ if (unlikely (f2fs_cp_error (sbi )))
828+ return ;
829+ }
818830
819831 next_free_nid (sbi , & last_nid );
820832
@@ -825,15 +837,15 @@ static void do_checkpoint(struct f2fs_sb_info *sbi, bool is_umount)
825837 ckpt -> elapsed_time = cpu_to_le64 (get_mtime (sbi ));
826838 ckpt -> valid_block_count = cpu_to_le64 (valid_user_blocks (sbi ));
827839 ckpt -> free_segment_count = cpu_to_le32 (free_segments (sbi ));
828- for (i = 0 ; i < 3 ; i ++ ) {
840+ for (i = 0 ; i < NR_CURSEG_NODE_TYPE ; i ++ ) {
829841 ckpt -> cur_node_segno [i ] =
830842 cpu_to_le32 (curseg_segno (sbi , i + CURSEG_HOT_NODE ));
831843 ckpt -> cur_node_blkoff [i ] =
832844 cpu_to_le16 (curseg_blkoff (sbi , i + CURSEG_HOT_NODE ));
833845 ckpt -> alloc_type [i + CURSEG_HOT_NODE ] =
834846 curseg_alloc_type (sbi , i + CURSEG_HOT_NODE );
835847 }
836- for (i = 0 ; i < 3 ; i ++ ) {
848+ for (i = 0 ; i < NR_CURSEG_DATA_TYPE ; i ++ ) {
837849 ckpt -> cur_data_segno [i ] =
838850 cpu_to_le32 (curseg_segno (sbi , i + CURSEG_HOT_DATA ));
839851 ckpt -> cur_data_blkoff [i ] =
@@ -848,24 +860,23 @@ static void do_checkpoint(struct f2fs_sb_info *sbi, bool is_umount)
848860
849861 /* 2 cp + n data seg summary + orphan inode blocks */
850862 data_sum_blocks = npages_for_summary_flush (sbi );
851- if (data_sum_blocks < 3 )
863+ if (data_sum_blocks < NR_CURSEG_DATA_TYPE )
852864 set_ckpt_flags (ckpt , CP_COMPACT_SUM_FLAG );
853865 else
854866 clear_ckpt_flags (ckpt , CP_COMPACT_SUM_FLAG );
855867
856- orphan_blocks = (sbi -> n_orphans + F2FS_ORPHANS_PER_BLOCK - 1 )
857- / F2FS_ORPHANS_PER_BLOCK ;
868+ orphan_blocks = GET_ORPHAN_BLOCKS (sbi -> n_orphans );
858869 ckpt -> cp_pack_start_sum = cpu_to_le32 (1 + cp_payload_blks +
859870 orphan_blocks );
860871
861872 if (is_umount ) {
862873 set_ckpt_flags (ckpt , CP_UMOUNT_FLAG );
863- ckpt -> cp_pack_total_block_count = cpu_to_le32 (2 +
874+ ckpt -> cp_pack_total_block_count = cpu_to_le32 (F2FS_CP_PACKS +
864875 cp_payload_blks + data_sum_blocks +
865876 orphan_blocks + NR_CURSEG_NODE_TYPE );
866877 } else {
867878 clear_ckpt_flags (ckpt , CP_UMOUNT_FLAG );
868- ckpt -> cp_pack_total_block_count = cpu_to_le32 (2 +
879+ ckpt -> cp_pack_total_block_count = cpu_to_le32 (F2FS_CP_PACKS +
869880 cp_payload_blks + data_sum_blocks +
870881 orphan_blocks );
871882 }
@@ -924,6 +935,9 @@ static void do_checkpoint(struct f2fs_sb_info *sbi, bool is_umount)
924935 /* wait for previous submitted node/meta pages writeback */
925936 wait_on_all_pages_writeback (sbi );
926937
938+ if (unlikely (f2fs_cp_error (sbi )))
939+ return ;
940+
927941 filemap_fdatawait_range (NODE_MAPPING (sbi ), 0 , LONG_MAX );
928942 filemap_fdatawait_range (META_MAPPING (sbi ), 0 , LONG_MAX );
929943
@@ -934,15 +948,17 @@ static void do_checkpoint(struct f2fs_sb_info *sbi, bool is_umount)
934948 /* Here, we only have one bio having CP pack */
935949 sync_meta_pages (sbi , META_FLUSH , LONG_MAX );
936950
937- if (!is_set_ckpt_flags (ckpt , CP_ERROR_FLAG )) {
938- clear_prefree_segments (sbi );
939- release_dirty_inode (sbi );
940- F2FS_RESET_SB_DIRT (sbi );
941- }
951+ release_dirty_inode (sbi );
952+
953+ if (unlikely (f2fs_cp_error (sbi )))
954+ return ;
955+
956+ clear_prefree_segments (sbi );
957+ F2FS_RESET_SB_DIRT (sbi );
942958}
943959
944960/*
945- * We guarantee that this checkpoint procedure should not fail.
961+ * We guarantee that this checkpoint procedure will not fail.
946962 */
947963void write_checkpoint (struct f2fs_sb_info * sbi , bool is_umount )
948964{
@@ -952,7 +968,13 @@ void write_checkpoint(struct f2fs_sb_info *sbi, bool is_umount)
952968 trace_f2fs_write_checkpoint (sbi -> sb , is_umount , "start block_ops" );
953969
954970 mutex_lock (& sbi -> cp_mutex );
955- block_operations (sbi );
971+
972+ if (!sbi -> s_dirty )
973+ goto out ;
974+ if (unlikely (f2fs_cp_error (sbi )))
975+ goto out ;
976+ if (block_operations (sbi ))
977+ goto out ;
956978
957979 trace_f2fs_write_checkpoint (sbi -> sb , is_umount , "finish block_ops" );
958980
@@ -976,9 +998,9 @@ void write_checkpoint(struct f2fs_sb_info *sbi, bool is_umount)
976998 do_checkpoint (sbi , is_umount );
977999
9781000 unblock_operations (sbi );
979- mutex_unlock (& sbi -> cp_mutex );
980-
9811001 stat_inc_cp_count (sbi -> stat_info );
1002+ out :
1003+ mutex_unlock (& sbi -> cp_mutex );
9821004 trace_f2fs_write_checkpoint (sbi -> sb , is_umount , "finish checkpoint" );
9831005}
9841006
@@ -999,8 +1021,8 @@ void init_ino_entry_info(struct f2fs_sb_info *sbi)
9991021 * for cp pack we can have max 1020*504 orphan entries
10001022 */
10011023 sbi -> n_orphans = 0 ;
1002- sbi -> max_orphans = (sbi -> blocks_per_seg - 2 - NR_CURSEG_TYPE )
1003- * F2FS_ORPHANS_PER_BLOCK ;
1024+ sbi -> max_orphans = (sbi -> blocks_per_seg - F2FS_CP_PACKS -
1025+ NR_CURSEG_TYPE ) * F2FS_ORPHANS_PER_BLOCK ;
10041026}
10051027
10061028int __init create_checkpoint_caches (void )
0 commit comments