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

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

613 return false;
614
615 if (f2fs_get_node_info(sbi, nid, dni)) {
616 f2fs_put_page(node_page, 1);
617 return false;
618 }
619
620 if (sum->version != dni->version) {
1// SPDX-License-Identifier: GPL-2.0
2/*
3 * fs/f2fs/gc.c
4 *
5 * Copyright (c) 2012 Samsung Electronics Co., Ltd.
6 * http://www.samsung.com/
7 */
8#include <linux/fs.h>

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

613 return false;
614
615 if (f2fs_get_node_info(sbi, nid, dni)) {
616 f2fs_put_page(node_page, 1);
617 return false;
618 }
619
620 if (sum->version != dni->version) {
621 f2fs_msg(sbi->sb, KERN_WARNING,
622 "%s: valid data with mismatched node version.",
623 __func__);
621 f2fs_warn(sbi, "%s: valid data with mismatched node version.",
622 __func__);
624 set_sbi_flag(sbi, SBI_NEED_FSCK);
625 }
626
627 *nofs = ofs_of_node(node_page);
628 source_blkaddr = datablock_addr(NULL, node_page, ofs_in_node);
629 f2fs_put_page(node_page, 1);
630
631 if (source_blkaddr != blkaddr)

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

1178 if (__is_large_section(sbi) &&
1179 migrated >= sbi->migration_granularity)
1180 goto skip;
1181 if (!PageUptodate(sum_page) || unlikely(f2fs_cp_error(sbi)))
1182 goto skip;
1183
1184 sum = page_address(sum_page);
1185 if (type != GET_SUM_TYPE((&sum->footer))) {
623 set_sbi_flag(sbi, SBI_NEED_FSCK);
624 }
625
626 *nofs = ofs_of_node(node_page);
627 source_blkaddr = datablock_addr(NULL, node_page, ofs_in_node);
628 f2fs_put_page(node_page, 1);
629
630 if (source_blkaddr != blkaddr)

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

1177 if (__is_large_section(sbi) &&
1178 migrated >= sbi->migration_granularity)
1179 goto skip;
1180 if (!PageUptodate(sum_page) || unlikely(f2fs_cp_error(sbi)))
1181 goto skip;
1182
1183 sum = page_address(sum_page);
1184 if (type != GET_SUM_TYPE((&sum->footer))) {
1186 f2fs_msg(sbi->sb, KERN_ERR, "Inconsistent segment (%u) "
1187 "type [%d, %d] in SSA and SIT",
1188 segno, type, GET_SUM_TYPE((&sum->footer)));
1185 f2fs_err(sbi, "Inconsistent segment (%u) type [%d, %d] in SSA and SIT",
1186 segno, type, GET_SUM_TYPE((&sum->footer)));
1189 set_sbi_flag(sbi, SBI_NEED_FSCK);
1190 f2fs_stop_checkpoint(sbi, false);
1191 goto skip;
1192 }
1193
1194 /*
1195 * this is to avoid deadlock:
1196 * - lock_page(sum_page) - f2fs_replace_block

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

1392 }
1393
1394 err = f2fs_sync_fs(sbi->sb, 1);
1395 if (err)
1396 return err;
1397
1398 next_inuse = find_next_inuse(FREE_I(sbi), end + 1, start);
1399 if (next_inuse <= end) {
1187 set_sbi_flag(sbi, SBI_NEED_FSCK);
1188 f2fs_stop_checkpoint(sbi, false);
1189 goto skip;
1190 }
1191
1192 /*
1193 * this is to avoid deadlock:
1194 * - lock_page(sum_page) - f2fs_replace_block

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

1390 }
1391
1392 err = f2fs_sync_fs(sbi->sb, 1);
1393 if (err)
1394 return err;
1395
1396 next_inuse = find_next_inuse(FREE_I(sbi), end + 1, start);
1397 if (next_inuse <= end) {
1400 f2fs_msg(sbi->sb, KERN_ERR,
1401 "segno %u should be free but still inuse!", next_inuse);
1398 f2fs_err(sbi, "segno %u should be free but still inuse!",
1399 next_inuse);
1402 f2fs_bug_on(sbi, 1);
1403 }
1404 return err;
1405}
1406
1407static void update_sb_metadata(struct f2fs_sb_info *sbi, int secs)
1408{
1409 struct f2fs_super_block *raw_sb = F2FS_RAW_SUPER(sbi);

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

1450 div_u64_rem(block_count, BLKS_PER_SEC(sbi), &rem);
1451 if (rem)
1452 return -EINVAL;
1453
1454 if (block_count == old_block_count)
1455 return 0;
1456
1457 if (is_sbi_flag_set(sbi, SBI_NEED_FSCK)) {
1400 f2fs_bug_on(sbi, 1);
1401 }
1402 return err;
1403}
1404
1405static void update_sb_metadata(struct f2fs_sb_info *sbi, int secs)
1406{
1407 struct f2fs_super_block *raw_sb = F2FS_RAW_SUPER(sbi);

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

1448 div_u64_rem(block_count, BLKS_PER_SEC(sbi), &rem);
1449 if (rem)
1450 return -EINVAL;
1451
1452 if (block_count == old_block_count)
1453 return 0;
1454
1455 if (is_sbi_flag_set(sbi, SBI_NEED_FSCK)) {
1458 f2fs_msg(sbi->sb, KERN_ERR,
1459 "Should run fsck to repair first.");
1456 f2fs_err(sbi, "Should run fsck to repair first.");
1460 return -EINVAL;
1461 }
1462
1463 if (test_opt(sbi, DISABLE_CHECKPOINT)) {
1457 return -EINVAL;
1458 }
1459
1460 if (test_opt(sbi, DISABLE_CHECKPOINT)) {
1464 f2fs_msg(sbi->sb, KERN_ERR,
1465 "Checkpoint should be enabled.");
1461 f2fs_err(sbi, "Checkpoint should be enabled.");
1466 return -EINVAL;
1467 }
1468
1469 freeze_bdev(sbi->sb->s_bdev);
1470
1471 shrunk_blocks = old_block_count - block_count;
1472 secs = div_u64(shrunk_blocks, BLKS_PER_SEC(sbi));
1473 spin_lock(&sbi->stat_lock);

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

1521 if (err) {
1522 update_fs_metadata(sbi, secs);
1523 update_sb_metadata(sbi, secs);
1524 f2fs_commit_super(sbi, false);
1525 }
1526out:
1527 if (err) {
1528 set_sbi_flag(sbi, SBI_NEED_FSCK);
1462 return -EINVAL;
1463 }
1464
1465 freeze_bdev(sbi->sb->s_bdev);
1466
1467 shrunk_blocks = old_block_count - block_count;
1468 secs = div_u64(shrunk_blocks, BLKS_PER_SEC(sbi));
1469 spin_lock(&sbi->stat_lock);

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

1517 if (err) {
1518 update_fs_metadata(sbi, secs);
1519 update_sb_metadata(sbi, secs);
1520 f2fs_commit_super(sbi, false);
1521 }
1522out:
1523 if (err) {
1524 set_sbi_flag(sbi, SBI_NEED_FSCK);
1529 f2fs_msg(sbi->sb, KERN_ERR,
1530 "resize_fs failed, should run fsck to repair!");
1525 f2fs_err(sbi, "resize_fs failed, should run fsck to repair!");
1531
1532 MAIN_SECS(sbi) += secs;
1533 spin_lock(&sbi->stat_lock);
1534 sbi->user_block_count += shrunk_blocks;
1535 spin_unlock(&sbi->stat_lock);
1536 }
1537 clear_sbi_flag(sbi, SBI_IS_RESIZEFS);
1538 mutex_unlock(&sbi->resize_mutex);
1539 thaw_bdev(sbi->sb->s_bdev, sbi->sb);
1540 return err;
1541}
1526
1527 MAIN_SECS(sbi) += secs;
1528 spin_lock(&sbi->stat_lock);
1529 sbi->user_block_count += shrunk_blocks;
1530 spin_unlock(&sbi->stat_lock);
1531 }
1532 clear_sbi_flag(sbi, SBI_IS_RESIZEFS);
1533 mutex_unlock(&sbi->resize_mutex);
1534 thaw_bdev(sbi->sb->s_bdev, sbi->sb);
1535 return err;
1536}