checkpoint.c (9a87ffc99ec8eb8d35eed7c4f816d75f5cc9662e) checkpoint.c (b62e71be2110d8b52bf5faf3c3ed7ca1a0c113a5)
1// SPDX-License-Identifier: GPL-2.0
2/*
3 * fs/f2fs/checkpoint.c
4 *
5 * Copyright (c) 2012 Samsung Electronics Co., Ltd.
6 * http://www.samsung.com/
7 */
8#include <linux/fs.h>

--- 16 unchanged lines hidden (view full) ---

25
26static struct kmem_cache *ino_entry_slab;
27struct kmem_cache *f2fs_inode_entry_slab;
28
29void f2fs_stop_checkpoint(struct f2fs_sb_info *sbi, bool end_io,
30 unsigned char reason)
31{
32 f2fs_build_fault_attr(sbi, 0, 0);
1// SPDX-License-Identifier: GPL-2.0
2/*
3 * fs/f2fs/checkpoint.c
4 *
5 * Copyright (c) 2012 Samsung Electronics Co., Ltd.
6 * http://www.samsung.com/
7 */
8#include <linux/fs.h>

--- 16 unchanged lines hidden (view full) ---

25
26static struct kmem_cache *ino_entry_slab;
27struct kmem_cache *f2fs_inode_entry_slab;
28
29void f2fs_stop_checkpoint(struct f2fs_sb_info *sbi, bool end_io,
30 unsigned char reason)
31{
32 f2fs_build_fault_attr(sbi, 0, 0);
33 set_ckpt_flags(sbi, CP_ERROR_FLAG);
34 if (!end_io) {
33 if (!end_io)
35 f2fs_flush_merged_writes(sbi);
34 f2fs_flush_merged_writes(sbi);
36
37 f2fs_handle_stop(sbi, reason);
38 }
35 f2fs_handle_critical_error(sbi, reason, end_io);
39}
40
41/*
42 * We guarantee no failure on the returned page.
43 */
44struct page *f2fs_grab_meta_page(struct f2fs_sb_info *sbi, pgoff_t index)
45{
46 struct address_space *mapping = META_MAPPING(sbi);

--- 100 unchanged lines hidden (view full) ---

147 if (type == DATA_GENERIC)
148 return true;
149
150 segno = GET_SEGNO(sbi, blkaddr);
151 offset = GET_BLKOFF_FROM_SEG0(sbi, blkaddr);
152 se = get_seg_entry(sbi, segno);
153
154 exist = f2fs_test_bit(offset, se->cur_valid_map);
36}
37
38/*
39 * We guarantee no failure on the returned page.
40 */
41struct page *f2fs_grab_meta_page(struct f2fs_sb_info *sbi, pgoff_t index)
42{
43 struct address_space *mapping = META_MAPPING(sbi);

--- 100 unchanged lines hidden (view full) ---

144 if (type == DATA_GENERIC)
145 return true;
146
147 segno = GET_SEGNO(sbi, blkaddr);
148 offset = GET_BLKOFF_FROM_SEG0(sbi, blkaddr);
149 se = get_seg_entry(sbi, segno);
150
151 exist = f2fs_test_bit(offset, se->cur_valid_map);
152
153 /* skip data, if we already have an error in checkpoint. */
154 if (unlikely(f2fs_cp_error(sbi)))
155 return exist;
156
155 if (exist && type == DATA_GENERIC_ENHANCE_UPDATE) {
156 f2fs_err(sbi, "Inconsistent error blkaddr:%u, sit bitmap:%d",
157 blkaddr, exist);
158 set_sbi_flag(sbi, SBI_NEED_FSCK);
159 return exist;
160 }
161
162 if (!exist && type == DATA_GENERIC_ENHANCE) {

--- 34 unchanged lines hidden (view full) ---

197 return false;
198 break;
199 case DATA_GENERIC:
200 case DATA_GENERIC_ENHANCE:
201 case DATA_GENERIC_ENHANCE_READ:
202 case DATA_GENERIC_ENHANCE_UPDATE:
203 if (unlikely(blkaddr >= MAX_BLKADDR(sbi) ||
204 blkaddr < MAIN_BLKADDR(sbi))) {
157 if (exist && type == DATA_GENERIC_ENHANCE_UPDATE) {
158 f2fs_err(sbi, "Inconsistent error blkaddr:%u, sit bitmap:%d",
159 blkaddr, exist);
160 set_sbi_flag(sbi, SBI_NEED_FSCK);
161 return exist;
162 }
163
164 if (!exist && type == DATA_GENERIC_ENHANCE) {

--- 34 unchanged lines hidden (view full) ---

199 return false;
200 break;
201 case DATA_GENERIC:
202 case DATA_GENERIC_ENHANCE:
203 case DATA_GENERIC_ENHANCE_READ:
204 case DATA_GENERIC_ENHANCE_UPDATE:
205 if (unlikely(blkaddr >= MAX_BLKADDR(sbi) ||
206 blkaddr < MAIN_BLKADDR(sbi))) {
207
208 /* Skip to emit an error message. */
209 if (unlikely(f2fs_cp_error(sbi)))
210 return false;
211
205 f2fs_warn(sbi, "access invalid blkaddr:%u",
206 blkaddr);
207 set_sbi_flag(sbi, SBI_NEED_FSCK);
208 dump_stack();
209 return false;
210 } else {
211 return __is_bitmap_valid(sbi, blkaddr, type);
212 }

--- 107 unchanged lines hidden (view full) ---

320static int __f2fs_write_meta_page(struct page *page,
321 struct writeback_control *wbc,
322 enum iostat_type io_type)
323{
324 struct f2fs_sb_info *sbi = F2FS_P_SB(page);
325
326 trace_f2fs_writepage(page, META);
327
212 f2fs_warn(sbi, "access invalid blkaddr:%u",
213 blkaddr);
214 set_sbi_flag(sbi, SBI_NEED_FSCK);
215 dump_stack();
216 return false;
217 } else {
218 return __is_bitmap_valid(sbi, blkaddr, type);
219 }

--- 107 unchanged lines hidden (view full) ---

327static int __f2fs_write_meta_page(struct page *page,
328 struct writeback_control *wbc,
329 enum iostat_type io_type)
330{
331 struct f2fs_sb_info *sbi = F2FS_P_SB(page);
332
333 trace_f2fs_writepage(page, META);
334
328 if (unlikely(f2fs_cp_error(sbi)))
335 if (unlikely(f2fs_cp_error(sbi))) {
336 if (is_sbi_flag_set(sbi, SBI_IS_CLOSE)) {
337 ClearPageUptodate(page);
338 dec_page_count(sbi, F2FS_DIRTY_META);
339 unlock_page(page);
340 return 0;
341 }
329 goto redirty_out;
342 goto redirty_out;
343 }
330 if (unlikely(is_sbi_flag_set(sbi, SBI_POR_DOING)))
331 goto redirty_out;
332 if (wbc->for_reclaim && page->index < GET_SUM_BLOCK(sbi, 0))
333 goto redirty_out;
334
335 f2fs_do_write_meta_page(sbi, page, io_type);
336 dec_page_count(sbi, F2FS_DIRTY_META);
337

--- 165 unchanged lines hidden (view full) ---

503
504 radix_tree_preload(GFP_NOFS | __GFP_NOFAIL);
505
506 spin_lock(&im->ino_lock);
507 e = radix_tree_lookup(&im->ino_root, ino);
508 if (!e) {
509 if (!new) {
510 spin_unlock(&im->ino_lock);
344 if (unlikely(is_sbi_flag_set(sbi, SBI_POR_DOING)))
345 goto redirty_out;
346 if (wbc->for_reclaim && page->index < GET_SUM_BLOCK(sbi, 0))
347 goto redirty_out;
348
349 f2fs_do_write_meta_page(sbi, page, io_type);
350 dec_page_count(sbi, F2FS_DIRTY_META);
351

--- 165 unchanged lines hidden (view full) ---

517
518 radix_tree_preload(GFP_NOFS | __GFP_NOFAIL);
519
520 spin_lock(&im->ino_lock);
521 e = radix_tree_lookup(&im->ino_root, ino);
522 if (!e) {
523 if (!new) {
524 spin_unlock(&im->ino_lock);
525 radix_tree_preload_end();
511 goto retry;
512 }
513 e = new;
514 if (unlikely(radix_tree_insert(&im->ino_root, ino, e)))
515 f2fs_bug_on(sbi, 1);
516
517 memset(e, 0, sizeof(struct ino_entry));
518 e->ino = ino;

--- 182 unchanged lines hidden (view full) ---

701 f2fs_warn(sbi, "%s: orphan failed (ino=%x), run fsck to fix.",
702 __func__, ino);
703 return err;
704}
705
706int f2fs_recover_orphan_inodes(struct f2fs_sb_info *sbi)
707{
708 block_t start_blk, orphan_blocks, i, j;
526 goto retry;
527 }
528 e = new;
529 if (unlikely(radix_tree_insert(&im->ino_root, ino, e)))
530 f2fs_bug_on(sbi, 1);
531
532 memset(e, 0, sizeof(struct ino_entry));
533 e->ino = ino;

--- 182 unchanged lines hidden (view full) ---

716 f2fs_warn(sbi, "%s: orphan failed (ino=%x), run fsck to fix.",
717 __func__, ino);
718 return err;
719}
720
721int f2fs_recover_orphan_inodes(struct f2fs_sb_info *sbi)
722{
723 block_t start_blk, orphan_blocks, i, j;
709 unsigned int s_flags = sbi->sb->s_flags;
710 int err = 0;
724 int err = 0;
711#ifdef CONFIG_QUOTA
712 int quota_enabled;
713#endif
714
715 if (!is_set_ckpt_flags(sbi, CP_ORPHAN_PRESENT_FLAG))
716 return 0;
717
725
726 if (!is_set_ckpt_flags(sbi, CP_ORPHAN_PRESENT_FLAG))
727 return 0;
728
718 if (bdev_read_only(sbi->sb->s_bdev)) {
729 if (f2fs_hw_is_readonly(sbi)) {
719 f2fs_info(sbi, "write access unavailable, skipping orphan cleanup");
720 return 0;
721 }
722
730 f2fs_info(sbi, "write access unavailable, skipping orphan cleanup");
731 return 0;
732 }
733
723 if (s_flags & SB_RDONLY) {
734 if (is_sbi_flag_set(sbi, SBI_IS_WRITABLE))
724 f2fs_info(sbi, "orphan cleanup on readonly fs");
735 f2fs_info(sbi, "orphan cleanup on readonly fs");
725 sbi->sb->s_flags &= ~SB_RDONLY;
726 }
727
736
728#ifdef CONFIG_QUOTA
729 /*
730 * Turn on quotas which were not enabled for read-only mounts if
731 * filesystem has quota feature, so that they are updated correctly.
732 */
733 quota_enabled = f2fs_enable_quota_files(sbi, s_flags & SB_RDONLY);
734#endif
735
736 start_blk = __start_cp_addr(sbi) + 1 + __cp_payload(sbi);
737 orphan_blocks = __start_sum_addr(sbi) - 1 - __cp_payload(sbi);
738
739 f2fs_ra_meta_pages(sbi, start_blk, orphan_blocks, META_CP, true);
740
741 for (i = 0; i < orphan_blocks; i++) {
742 struct page *page;
743 struct f2fs_orphan_block *orphan_blk;

--- 16 unchanged lines hidden (view full) ---

760 }
761 f2fs_put_page(page, 1);
762 }
763 /* clear Orphan Flag */
764 clear_ckpt_flags(sbi, CP_ORPHAN_PRESENT_FLAG);
765out:
766 set_sbi_flag(sbi, SBI_IS_RECOVERED);
767
737 start_blk = __start_cp_addr(sbi) + 1 + __cp_payload(sbi);
738 orphan_blocks = __start_sum_addr(sbi) - 1 - __cp_payload(sbi);
739
740 f2fs_ra_meta_pages(sbi, start_blk, orphan_blocks, META_CP, true);
741
742 for (i = 0; i < orphan_blocks; i++) {
743 struct page *page;
744 struct f2fs_orphan_block *orphan_blk;

--- 16 unchanged lines hidden (view full) ---

761 }
762 f2fs_put_page(page, 1);
763 }
764 /* clear Orphan Flag */
765 clear_ckpt_flags(sbi, CP_ORPHAN_PRESENT_FLAG);
766out:
767 set_sbi_flag(sbi, SBI_IS_RECOVERED);
768
768#ifdef CONFIG_QUOTA
769 /* Turn quotas off */
770 if (quota_enabled)
771 f2fs_quota_off_umount(sbi->sb);
772#endif
773 sbi->sb->s_flags = s_flags; /* Restore SB_RDONLY status */
774
775 return err;
776}
777
778static void write_orphan_inodes(struct f2fs_sb_info *sbi, block_t start_blk)
779{
780 struct list_head *head;
781 struct f2fs_orphan_block *orphan_blk = NULL;
782 unsigned int nentries = 0;

--- 194 unchanged lines hidden (view full) ---

977 goto free_fail_no_cp;
978 }
979
980 if (cp_blks <= 1)
981 goto done;
982
983 cp_blk_no = le32_to_cpu(fsb->cp_blkaddr);
984 if (cur_page == cp2)
769 return err;
770}
771
772static void write_orphan_inodes(struct f2fs_sb_info *sbi, block_t start_blk)
773{
774 struct list_head *head;
775 struct f2fs_orphan_block *orphan_blk = NULL;
776 unsigned int nentries = 0;

--- 194 unchanged lines hidden (view full) ---

971 goto free_fail_no_cp;
972 }
973
974 if (cp_blks <= 1)
975 goto done;
976
977 cp_blk_no = le32_to_cpu(fsb->cp_blkaddr);
978 if (cur_page == cp2)
985 cp_blk_no += 1 << le32_to_cpu(fsb->log_blocks_per_seg);
979 cp_blk_no += BIT(le32_to_cpu(fsb->log_blocks_per_seg));
986
987 for (i = 1; i < cp_blks; i++) {
988 void *sit_bitmap_ptr;
989 unsigned char *ckpt = (unsigned char *)sbi->ckpt;
990
991 cur_page = f2fs_get_meta_page(sbi, cp_blk_no + i);
992 if (IS_ERR(cur_page)) {
993 err = PTR_ERR(cur_page);

--- 134 unchanged lines hidden (view full) ---

1128 * writebacking dentry pages in the freeing inode.
1129 */
1130 f2fs_submit_merged_write(sbi, DATA);
1131 cond_resched();
1132 }
1133 goto retry;
1134}
1135
980
981 for (i = 1; i < cp_blks; i++) {
982 void *sit_bitmap_ptr;
983 unsigned char *ckpt = (unsigned char *)sbi->ckpt;
984
985 cur_page = f2fs_get_meta_page(sbi, cp_blk_no + i);
986 if (IS_ERR(cur_page)) {
987 err = PTR_ERR(cur_page);

--- 134 unchanged lines hidden (view full) ---

1122 * writebacking dentry pages in the freeing inode.
1123 */
1124 f2fs_submit_merged_write(sbi, DATA);
1125 cond_resched();
1126 }
1127 goto retry;
1128}
1129
1136int f2fs_sync_inode_meta(struct f2fs_sb_info *sbi)
1130static int f2fs_sync_inode_meta(struct f2fs_sb_info *sbi)
1137{
1138 struct list_head *head = &sbi->inode_list[DIRTY_META];
1139 struct inode *inode;
1140 struct f2fs_inode_info *fi;
1141 s64 total = get_pages(sbi, F2FS_DIRTY_IMETA);
1142
1143 while (total--) {
1144 if (unlikely(f2fs_cp_error(sbi)))

--- 156 unchanged lines hidden (view full) ---

1301void f2fs_wait_on_all_pages(struct f2fs_sb_info *sbi, int type)
1302{
1303 DEFINE_WAIT(wait);
1304
1305 for (;;) {
1306 if (!get_pages(sbi, type))
1307 break;
1308
1131{
1132 struct list_head *head = &sbi->inode_list[DIRTY_META];
1133 struct inode *inode;
1134 struct f2fs_inode_info *fi;
1135 s64 total = get_pages(sbi, F2FS_DIRTY_IMETA);
1136
1137 while (total--) {
1138 if (unlikely(f2fs_cp_error(sbi)))

--- 156 unchanged lines hidden (view full) ---

1295void f2fs_wait_on_all_pages(struct f2fs_sb_info *sbi, int type)
1296{
1297 DEFINE_WAIT(wait);
1298
1299 for (;;) {
1300 if (!get_pages(sbi, type))
1301 break;
1302
1309 if (unlikely(f2fs_cp_error(sbi)))
1303 if (unlikely(f2fs_cp_error(sbi) &&
1304 !is_sbi_flag_set(sbi, SBI_IS_CLOSE)))
1310 break;
1311
1312 if (type == F2FS_DIRTY_META)
1313 f2fs_sync_meta_pages(sbi, META, LONG_MAX,
1314 FS_CP_META_IO);
1315 else if (type == F2FS_WB_CP_DATA)
1316 f2fs_submit_merged_write(sbi, DATA);
1317

--- 634 unchanged lines hidden ---
1305 break;
1306
1307 if (type == F2FS_DIRTY_META)
1308 f2fs_sync_meta_pages(sbi, META, LONG_MAX,
1309 FS_CP_META_IO);
1310 else if (type == F2FS_WB_CP_DATA)
1311 f2fs_submit_merged_write(sbi, DATA);
1312

--- 634 unchanged lines hidden ---