checkpoint.c (a468f0ef516fda9c7d91bb550d458e853d76955e) checkpoint.c (aaec2b1d18792a5f27b69ff37f34f43f89f5aa3b)
1/*
2 * fs/f2fs/checkpoint.c
3 *
4 * Copyright (c) 2012 Samsung Electronics Co., Ltd.
5 * http://www.samsung.com/
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as

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

23#include "trace.h"
24#include <trace/events/f2fs.h>
25
26static struct kmem_cache *ino_entry_slab;
27struct kmem_cache *inode_entry_slab;
28
29void f2fs_stop_checkpoint(struct f2fs_sb_info *sbi, bool end_io)
30{
1/*
2 * fs/f2fs/checkpoint.c
3 *
4 * Copyright (c) 2012 Samsung Electronics Co., Ltd.
5 * http://www.samsung.com/
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as

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

23#include "trace.h"
24#include <trace/events/f2fs.h>
25
26static struct kmem_cache *ino_entry_slab;
27struct kmem_cache *inode_entry_slab;
28
29void f2fs_stop_checkpoint(struct f2fs_sb_info *sbi, bool end_io)
30{
31 set_ckpt_flags(sbi->ckpt, CP_ERROR_FLAG);
31 set_ckpt_flags(sbi, CP_ERROR_FLAG);
32 sbi->sb->s_flags |= MS_RDONLY;
33 if (!end_io)
34 f2fs_flush_merged_bios(sbi);
35}
36
37/*
38 * We guarantee no failure on the returned page.
39 */

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

566 return 0;
567}
568
569int recover_orphan_inodes(struct f2fs_sb_info *sbi)
570{
571 block_t start_blk, orphan_blocks, i, j;
572 int err;
573
32 sbi->sb->s_flags |= MS_RDONLY;
33 if (!end_io)
34 f2fs_flush_merged_bios(sbi);
35}
36
37/*
38 * We guarantee no failure on the returned page.
39 */

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

566 return 0;
567}
568
569int recover_orphan_inodes(struct f2fs_sb_info *sbi)
570{
571 block_t start_blk, orphan_blocks, i, j;
572 int err;
573
574 if (!is_set_ckpt_flags(F2FS_CKPT(sbi), CP_ORPHAN_PRESENT_FLAG))
574 if (!is_set_ckpt_flags(sbi, CP_ORPHAN_PRESENT_FLAG))
575 return 0;
576
577 start_blk = __start_cp_addr(sbi) + 1 + __cp_payload(sbi);
578 orphan_blocks = __start_sum_addr(sbi) - 1 - __cp_payload(sbi);
579
580 ra_meta_pages(sbi, start_blk, orphan_blocks, META_CP, true);
581
582 for (i = 0; i < orphan_blocks; i++) {

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

590 if (err) {
591 f2fs_put_page(page, 1);
592 return err;
593 }
594 }
595 f2fs_put_page(page, 1);
596 }
597 /* clear Orphan Flag */
575 return 0;
576
577 start_blk = __start_cp_addr(sbi) + 1 + __cp_payload(sbi);
578 orphan_blocks = __start_sum_addr(sbi) - 1 - __cp_payload(sbi);
579
580 ra_meta_pages(sbi, start_blk, orphan_blocks, META_CP, true);
581
582 for (i = 0; i < orphan_blocks; i++) {

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

590 if (err) {
591 f2fs_put_page(page, 1);
592 return err;
593 }
594 }
595 f2fs_put_page(page, 1);
596 }
597 /* clear Orphan Flag */
598 clear_ckpt_flags(F2FS_CKPT(sbi), CP_ORPHAN_PRESENT_FLAG);
598 clear_ckpt_flags(sbi, CP_ORPHAN_PRESENT_FLAG);
599 return 0;
600}
601
602static void write_orphan_inodes(struct f2fs_sb_info *sbi, block_t start_blk)
603{
604 struct list_head *head;
605 struct f2fs_orphan_block *orphan_blk = NULL;
606 unsigned int nentries = 0;

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

1038 }
1039
1040 ckpt->valid_node_count = cpu_to_le32(valid_node_count(sbi));
1041 ckpt->valid_inode_count = cpu_to_le32(valid_inode_count(sbi));
1042 ckpt->next_free_nid = cpu_to_le32(last_nid);
1043
1044 /* 2 cp + n data seg summary + orphan inode blocks */
1045 data_sum_blocks = npages_for_summary_flush(sbi, false);
599 return 0;
600}
601
602static void write_orphan_inodes(struct f2fs_sb_info *sbi, block_t start_blk)
603{
604 struct list_head *head;
605 struct f2fs_orphan_block *orphan_blk = NULL;
606 unsigned int nentries = 0;

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

1038 }
1039
1040 ckpt->valid_node_count = cpu_to_le32(valid_node_count(sbi));
1041 ckpt->valid_inode_count = cpu_to_le32(valid_inode_count(sbi));
1042 ckpt->next_free_nid = cpu_to_le32(last_nid);
1043
1044 /* 2 cp + n data seg summary + orphan inode blocks */
1045 data_sum_blocks = npages_for_summary_flush(sbi, false);
1046 spin_lock(&sbi->cp_lock);
1046 if (data_sum_blocks < NR_CURSEG_DATA_TYPE)
1047 if (data_sum_blocks < NR_CURSEG_DATA_TYPE)
1047 set_ckpt_flags(ckpt, CP_COMPACT_SUM_FLAG);
1048 __set_ckpt_flags(ckpt, CP_COMPACT_SUM_FLAG);
1048 else
1049 else
1049 clear_ckpt_flags(ckpt, CP_COMPACT_SUM_FLAG);
1050 __clear_ckpt_flags(ckpt, CP_COMPACT_SUM_FLAG);
1051 spin_unlock(&sbi->cp_lock);
1050
1051 orphan_blocks = GET_ORPHAN_BLOCKS(orphan_num);
1052 ckpt->cp_pack_start_sum = cpu_to_le32(1 + cp_payload_blks +
1053 orphan_blocks);
1054
1055 if (__remain_node_summaries(cpc->reason))
1056 ckpt->cp_pack_total_block_count = cpu_to_le32(F2FS_CP_PACKS+
1057 cp_payload_blks + data_sum_blocks +
1058 orphan_blocks + NR_CURSEG_NODE_TYPE);
1059 else
1060 ckpt->cp_pack_total_block_count = cpu_to_le32(F2FS_CP_PACKS +
1061 cp_payload_blks + data_sum_blocks +
1062 orphan_blocks);
1063
1052
1053 orphan_blocks = GET_ORPHAN_BLOCKS(orphan_num);
1054 ckpt->cp_pack_start_sum = cpu_to_le32(1 + cp_payload_blks +
1055 orphan_blocks);
1056
1057 if (__remain_node_summaries(cpc->reason))
1058 ckpt->cp_pack_total_block_count = cpu_to_le32(F2FS_CP_PACKS+
1059 cp_payload_blks + data_sum_blocks +
1060 orphan_blocks + NR_CURSEG_NODE_TYPE);
1061 else
1062 ckpt->cp_pack_total_block_count = cpu_to_le32(F2FS_CP_PACKS +
1063 cp_payload_blks + data_sum_blocks +
1064 orphan_blocks);
1065
1066 spin_lock(&sbi->cp_lock);
1064 if (cpc->reason == CP_UMOUNT)
1067 if (cpc->reason == CP_UMOUNT)
1065 set_ckpt_flags(ckpt, CP_UMOUNT_FLAG);
1068 __set_ckpt_flags(ckpt, CP_UMOUNT_FLAG);
1066 else
1069 else
1067 clear_ckpt_flags(ckpt, CP_UMOUNT_FLAG);
1070 __clear_ckpt_flags(ckpt, CP_UMOUNT_FLAG);
1068
1069 if (cpc->reason == CP_FASTBOOT)
1071
1072 if (cpc->reason == CP_FASTBOOT)
1070 set_ckpt_flags(ckpt, CP_FASTBOOT_FLAG);
1073 __set_ckpt_flags(ckpt, CP_FASTBOOT_FLAG);
1071 else
1074 else
1072 clear_ckpt_flags(ckpt, CP_FASTBOOT_FLAG);
1075 __clear_ckpt_flags(ckpt, CP_FASTBOOT_FLAG);
1073
1074 if (orphan_num)
1076
1077 if (orphan_num)
1075 set_ckpt_flags(ckpt, CP_ORPHAN_PRESENT_FLAG);
1078 __set_ckpt_flags(ckpt, CP_ORPHAN_PRESENT_FLAG);
1076 else
1079 else
1077 clear_ckpt_flags(ckpt, CP_ORPHAN_PRESENT_FLAG);
1080 __clear_ckpt_flags(ckpt, CP_ORPHAN_PRESENT_FLAG);
1078
1079 if (is_sbi_flag_set(sbi, SBI_NEED_FSCK))
1081
1082 if (is_sbi_flag_set(sbi, SBI_NEED_FSCK))
1080 set_ckpt_flags(ckpt, CP_FSCK_FLAG);
1083 __set_ckpt_flags(ckpt, CP_FSCK_FLAG);
1081
1082 /* set this flag to activate crc|cp_ver for recovery */
1084
1085 /* set this flag to activate crc|cp_ver for recovery */
1083 set_ckpt_flags(ckpt, CP_CRC_RECOVERY_FLAG);
1086 __set_ckpt_flags(ckpt, CP_CRC_RECOVERY_FLAG);
1084
1087
1088 spin_unlock(&sbi->cp_lock);
1089
1085 /* update SIT/NAT bitmap */
1086 get_sit_bitmap(sbi, __bitmap_ptr(sbi, SIT_BITMAP));
1087 get_nat_bitmap(sbi, __bitmap_ptr(sbi, NAT_BITMAP));
1088
1089 crc32 = f2fs_crc32(sbi, ckpt, le32_to_cpu(ckpt->checksum_offset));
1090 *((__le32 *)((unsigned char *)ckpt +
1091 le32_to_cpu(ckpt->checksum_offset)))
1092 = cpu_to_le32(crc32);

--- 195 unchanged lines hidden ---
1090 /* update SIT/NAT bitmap */
1091 get_sit_bitmap(sbi, __bitmap_ptr(sbi, SIT_BITMAP));
1092 get_nat_bitmap(sbi, __bitmap_ptr(sbi, NAT_BITMAP));
1093
1094 crc32 = f2fs_crc32(sbi, ckpt, le32_to_cpu(ckpt->checksum_offset));
1095 *((__le32 *)((unsigned char *)ckpt +
1096 le32_to_cpu(ckpt->checksum_offset)))
1097 = cpu_to_le32(crc32);

--- 195 unchanged lines hidden ---