super.c (25c6d98fc4c245d164cf688815a7b259257ead2a) super.c (02f310fcf47fa9311d6ba2946a8d19e7d7d11f37)
1// SPDX-License-Identifier: GPL-2.0
2/*
3 * linux/fs/ext4/super.c
4 *
5 * Copyright (C) 1992, 1993, 1994, 1995
6 * Remy Card (card@masi.ibp.fr)
7 * Laboratoire MASI - Institut Blaise Pascal
8 * Universite Pierre et Marie Curie (Paris VI)

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

1169 int aborted = 0;
1170 int i, err;
1171
1172 ext4_unregister_li_request(sb);
1173 ext4_quota_off_umount(sb);
1174
1175 flush_work(&sbi->s_error_work);
1176 destroy_workqueue(sbi->rsv_conversion_wq);
1// SPDX-License-Identifier: GPL-2.0
2/*
3 * linux/fs/ext4/super.c
4 *
5 * Copyright (C) 1992, 1993, 1994, 1995
6 * Remy Card (card@masi.ibp.fr)
7 * Laboratoire MASI - Institut Blaise Pascal
8 * Universite Pierre et Marie Curie (Paris VI)

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

1169 int aborted = 0;
1170 int i, err;
1171
1172 ext4_unregister_li_request(sb);
1173 ext4_quota_off_umount(sb);
1174
1175 flush_work(&sbi->s_error_work);
1176 destroy_workqueue(sbi->rsv_conversion_wq);
1177 ext4_release_orphan_info(sb);
1177
1178 /*
1179 * Unregister sysfs before destroying jbd2 journal.
1180 * Since we could still access attr_journal_task attribute via sysfs
1181 * path which could have sbi->s_journal->j_task as NULL
1182 */
1183 ext4_unregister_sysfs(sb);
1184

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

1194 ext4_es_unregister_shrinker(sbi);
1195 del_timer_sync(&sbi->s_err_report);
1196 ext4_release_system_zone(sb);
1197 ext4_mb_release(sb);
1198 ext4_ext_release(sb);
1199
1200 if (!sb_rdonly(sb) && !aborted) {
1201 ext4_clear_feature_journal_needs_recovery(sb);
1178
1179 /*
1180 * Unregister sysfs before destroying jbd2 journal.
1181 * Since we could still access attr_journal_task attribute via sysfs
1182 * path which could have sbi->s_journal->j_task as NULL
1183 */
1184 ext4_unregister_sysfs(sb);
1185

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

1195 ext4_es_unregister_shrinker(sbi);
1196 del_timer_sync(&sbi->s_err_report);
1197 ext4_release_system_zone(sb);
1198 ext4_mb_release(sb);
1199 ext4_ext_release(sb);
1200
1201 if (!sb_rdonly(sb) && !aborted) {
1202 ext4_clear_feature_journal_needs_recovery(sb);
1203 ext4_clear_feature_orphan_present(sb);
1202 es->s_state = cpu_to_le16(sbi->s_mount_state);
1203 }
1204 if (!sb_rdonly(sb))
1205 ext4_commit_super(sb);
1206
1207 rcu_read_lock();
1208 group_desc = rcu_dereference(sbi->s_group_desc);
1209 for (i = 0; i < sbi->s_gdb_count; i++)

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

2679 "warning: checktime reached, "
2680 "running e2fsck is recommended");
2681 if (!sbi->s_journal)
2682 es->s_state &= cpu_to_le16(~EXT4_VALID_FS);
2683 if (!(__s16) le16_to_cpu(es->s_max_mnt_count))
2684 es->s_max_mnt_count = cpu_to_le16(EXT4_DFL_MAX_MNT_COUNT);
2685 le16_add_cpu(&es->s_mnt_count, 1);
2686 ext4_update_tstamp(es, s_mtime);
1204 es->s_state = cpu_to_le16(sbi->s_mount_state);
1205 }
1206 if (!sb_rdonly(sb))
1207 ext4_commit_super(sb);
1208
1209 rcu_read_lock();
1210 group_desc = rcu_dereference(sbi->s_group_desc);
1211 for (i = 0; i < sbi->s_gdb_count; i++)

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

2681 "warning: checktime reached, "
2682 "running e2fsck is recommended");
2683 if (!sbi->s_journal)
2684 es->s_state &= cpu_to_le16(~EXT4_VALID_FS);
2685 if (!(__s16) le16_to_cpu(es->s_max_mnt_count))
2686 es->s_max_mnt_count = cpu_to_le16(EXT4_DFL_MAX_MNT_COUNT);
2687 le16_add_cpu(&es->s_mnt_count, 1);
2688 ext4_update_tstamp(es, s_mtime);
2687 if (sbi->s_journal)
2689 if (sbi->s_journal) {
2688 ext4_set_feature_journal_needs_recovery(sb);
2690 ext4_set_feature_journal_needs_recovery(sb);
2691 if (ext4_has_feature_orphan_file(sb))
2692 ext4_set_feature_orphan_present(sb);
2693 }
2689
2690 err = ext4_commit_super(sb);
2691done:
2692 if (test_opt(sb, DEBUG))
2693 printk(KERN_INFO "[EXT4 FS bs=%lu, gc=%u, "
2694 "bpg=%lu, ipg=%lu, mo=%04x, mo2=%04x]\n",
2695 sb->s_blocksize,
2696 sbi->s_groups_count,

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

3955
3956 /* Check for a known checksum algorithm */
3957 if (!ext4_verify_csum_type(sb, es)) {
3958 ext4_msg(sb, KERN_ERR, "VFS: Found ext4 filesystem with "
3959 "unknown checksum algorithm.");
3960 silent = 1;
3961 goto cantfind_ext4;
3962 }
2694
2695 err = ext4_commit_super(sb);
2696done:
2697 if (test_opt(sb, DEBUG))
2698 printk(KERN_INFO "[EXT4 FS bs=%lu, gc=%u, "
2699 "bpg=%lu, ipg=%lu, mo=%04x, mo2=%04x]\n",
2700 sb->s_blocksize,
2701 sbi->s_groups_count,

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

3960
3961 /* Check for a known checksum algorithm */
3962 if (!ext4_verify_csum_type(sb, es)) {
3963 ext4_msg(sb, KERN_ERR, "VFS: Found ext4 filesystem with "
3964 "unknown checksum algorithm.");
3965 silent = 1;
3966 goto cantfind_ext4;
3967 }
3968 ext4_setup_csum_trigger(sb, EXT4_JTR_ORPHAN_FILE,
3969 ext4_orphan_file_block_trigger);
3963
3964 /* Load the checksum driver */
3965 sbi->s_chksum_driver = crypto_alloc_shash("crc32c", 0, 0);
3966 if (IS_ERR(sbi->s_chksum_driver)) {
3967 ext4_msg(sb, KERN_ERR, "Cannot load crc32c driver.");
3968 ret = PTR_ERR(sbi->s_chksum_driver);
3969 sbi->s_chksum_driver = NULL;
3970 goto failed_mount;

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

4619 sbi->s_fc_replay_state.fc_regions_valid = 0;
4620 sbi->s_fc_replay_state.fc_modified_inodes = NULL;
4621 sbi->s_fc_replay_state.fc_modified_inodes_size = 0;
4622 sbi->s_fc_replay_state.fc_modified_inodes_used = 0;
4623
4624 sb->s_root = NULL;
4625
4626 needs_recovery = (es->s_last_orphan != 0 ||
3970
3971 /* Load the checksum driver */
3972 sbi->s_chksum_driver = crypto_alloc_shash("crc32c", 0, 0);
3973 if (IS_ERR(sbi->s_chksum_driver)) {
3974 ext4_msg(sb, KERN_ERR, "Cannot load crc32c driver.");
3975 ret = PTR_ERR(sbi->s_chksum_driver);
3976 sbi->s_chksum_driver = NULL;
3977 goto failed_mount;

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

4626 sbi->s_fc_replay_state.fc_regions_valid = 0;
4627 sbi->s_fc_replay_state.fc_modified_inodes = NULL;
4628 sbi->s_fc_replay_state.fc_modified_inodes_size = 0;
4629 sbi->s_fc_replay_state.fc_modified_inodes_used = 0;
4630
4631 sb->s_root = NULL;
4632
4633 needs_recovery = (es->s_last_orphan != 0 ||
4634 ext4_has_feature_orphan_present(sb) ||
4627 ext4_has_feature_journal_needs_recovery(sb));
4628
4629 if (ext4_has_feature_mmp(sb) && !sb_rdonly(sb))
4630 if (ext4_multi_mount_protect(sb, le64_to_cpu(es->s_mmp_block)))
4631 goto failed_mount3a;
4632
4633 /*
4634 * The first inode we look at is the journal inode. Don't try

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

4917 err = ext4_register_li_request(sb, first_not_zeroed);
4918 if (err)
4919 goto failed_mount6;
4920
4921 err = ext4_register_sysfs(sb);
4922 if (err)
4923 goto failed_mount7;
4924
4635 ext4_has_feature_journal_needs_recovery(sb));
4636
4637 if (ext4_has_feature_mmp(sb) && !sb_rdonly(sb))
4638 if (ext4_multi_mount_protect(sb, le64_to_cpu(es->s_mmp_block)))
4639 goto failed_mount3a;
4640
4641 /*
4642 * The first inode we look at is the journal inode. Don't try

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

4925 err = ext4_register_li_request(sb, first_not_zeroed);
4926 if (err)
4927 goto failed_mount6;
4928
4929 err = ext4_register_sysfs(sb);
4930 if (err)
4931 goto failed_mount7;
4932
4933 err = ext4_init_orphan_info(sb);
4934 if (err)
4935 goto failed_mount8;
4925#ifdef CONFIG_QUOTA
4926 /* Enable quota usage during mount. */
4927 if (ext4_has_feature_quota(sb) && !sb_rdonly(sb)) {
4928 err = ext4_enable_quotas(sb);
4929 if (err)
4936#ifdef CONFIG_QUOTA
4937 /* Enable quota usage during mount. */
4938 if (ext4_has_feature_quota(sb) && !sb_rdonly(sb)) {
4939 err = ext4_enable_quotas(sb);
4940 if (err)
4930 goto failed_mount8;
4941 goto failed_mount9;
4931 }
4932#endif /* CONFIG_QUOTA */
4933
4934 /*
4935 * Save the original bdev mapping's wb_err value which could be
4936 * used to detect the metadata async write error.
4937 */
4938 spin_lock_init(&sbi->s_bdev_wb_lock);
4939 errseq_check_and_advance(&sb->s_bdev->bd_inode->i_mapping->wb_err,
4940 &sbi->s_bdev_wb_err);
4941 sb->s_bdev->bd_super = sb;
4942 EXT4_SB(sb)->s_mount_state |= EXT4_ORPHAN_FS;
4943 ext4_orphan_cleanup(sb, es);
4944 EXT4_SB(sb)->s_mount_state &= ~EXT4_ORPHAN_FS;
4945 if (needs_recovery) {
4946 ext4_msg(sb, KERN_INFO, "recovery complete");
4947 err = ext4_mark_recovery_complete(sb, es);
4948 if (err)
4942 }
4943#endif /* CONFIG_QUOTA */
4944
4945 /*
4946 * Save the original bdev mapping's wb_err value which could be
4947 * used to detect the metadata async write error.
4948 */
4949 spin_lock_init(&sbi->s_bdev_wb_lock);
4950 errseq_check_and_advance(&sb->s_bdev->bd_inode->i_mapping->wb_err,
4951 &sbi->s_bdev_wb_err);
4952 sb->s_bdev->bd_super = sb;
4953 EXT4_SB(sb)->s_mount_state |= EXT4_ORPHAN_FS;
4954 ext4_orphan_cleanup(sb, es);
4955 EXT4_SB(sb)->s_mount_state &= ~EXT4_ORPHAN_FS;
4956 if (needs_recovery) {
4957 ext4_msg(sb, KERN_INFO, "recovery complete");
4958 err = ext4_mark_recovery_complete(sb, es);
4959 if (err)
4949 goto failed_mount8;
4960 goto failed_mount9;
4950 }
4951 if (EXT4_SB(sb)->s_journal) {
4952 if (test_opt(sb, DATA_FLAGS) == EXT4_MOUNT_JOURNAL_DATA)
4953 descr = " journalled data mode";
4954 else if (test_opt(sb, DATA_FLAGS) == EXT4_MOUNT_ORDERED_DATA)
4955 descr = " ordered data mode";
4956 else
4957 descr = " writeback data mode";

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

4987 kfree(orig_data);
4988 return 0;
4989
4990cantfind_ext4:
4991 if (!silent)
4992 ext4_msg(sb, KERN_ERR, "VFS: Can't find ext4 filesystem");
4993 goto failed_mount;
4994
4961 }
4962 if (EXT4_SB(sb)->s_journal) {
4963 if (test_opt(sb, DATA_FLAGS) == EXT4_MOUNT_JOURNAL_DATA)
4964 descr = " journalled data mode";
4965 else if (test_opt(sb, DATA_FLAGS) == EXT4_MOUNT_ORDERED_DATA)
4966 descr = " ordered data mode";
4967 else
4968 descr = " writeback data mode";

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

4998 kfree(orig_data);
4999 return 0;
5000
5001cantfind_ext4:
5002 if (!silent)
5003 ext4_msg(sb, KERN_ERR, "VFS: Can't find ext4 filesystem");
5004 goto failed_mount;
5005
5006failed_mount9:
5007 ext4_release_orphan_info(sb);
4995failed_mount8:
4996 ext4_unregister_sysfs(sb);
4997 kobject_put(&sbi->s_kobj);
4998failed_mount7:
4999 ext4_unregister_li_request(sb);
5000failed_mount6:
5001 ext4_mb_release(sb);
5002 rcu_read_lock();

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

5497 }
5498 return 0;
5499 }
5500 jbd2_journal_lock_updates(journal);
5501 err = jbd2_journal_flush(journal, 0);
5502 if (err < 0)
5503 goto out;
5504
5008failed_mount8:
5009 ext4_unregister_sysfs(sb);
5010 kobject_put(&sbi->s_kobj);
5011failed_mount7:
5012 ext4_unregister_li_request(sb);
5013failed_mount6:
5014 ext4_mb_release(sb);
5015 rcu_read_lock();

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

5510 }
5511 return 0;
5512 }
5513 jbd2_journal_lock_updates(journal);
5514 err = jbd2_journal_flush(journal, 0);
5515 if (err < 0)
5516 goto out;
5517
5505 if (ext4_has_feature_journal_needs_recovery(sb) && sb_rdonly(sb)) {
5518 if (sb_rdonly(sb) && (ext4_has_feature_journal_needs_recovery(sb) ||
5519 ext4_has_feature_orphan_present(sb))) {
5520 if (!ext4_orphan_file_empty(sb)) {
5521 ext4_error(sb, "Orphan file not empty on read-only fs.");
5522 err = -EFSCORRUPTED;
5523 goto out;
5524 }
5506 ext4_clear_feature_journal_needs_recovery(sb);
5525 ext4_clear_feature_journal_needs_recovery(sb);
5526 ext4_clear_feature_orphan_present(sb);
5507 ext4_commit_super(sb);
5508 }
5509out:
5510 jbd2_journal_unlock_updates(journal);
5511 return err;
5512}
5513
5514/*

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

5641 * flush the journal.
5642 */
5643 error = jbd2_journal_flush(journal, 0);
5644 if (error < 0)
5645 goto out;
5646
5647 /* Journal blocked and flushed, clear needs_recovery flag. */
5648 ext4_clear_feature_journal_needs_recovery(sb);
5527 ext4_commit_super(sb);
5528 }
5529out:
5530 jbd2_journal_unlock_updates(journal);
5531 return err;
5532}
5533
5534/*

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

5661 * flush the journal.
5662 */
5663 error = jbd2_journal_flush(journal, 0);
5664 if (error < 0)
5665 goto out;
5666
5667 /* Journal blocked and flushed, clear needs_recovery flag. */
5668 ext4_clear_feature_journal_needs_recovery(sb);
5669 if (ext4_orphan_file_empty(sb))
5670 ext4_clear_feature_orphan_present(sb);
5649 }
5650
5651 error = ext4_commit_super(sb);
5652out:
5653 if (journal)
5654 /* we rely on upper layer to stop further updates */
5655 jbd2_journal_unlock_updates(journal);
5656 return error;

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

5663static int ext4_unfreeze(struct super_block *sb)
5664{
5665 if (sb_rdonly(sb) || ext4_forced_shutdown(EXT4_SB(sb)))
5666 return 0;
5667
5668 if (EXT4_SB(sb)->s_journal) {
5669 /* Reset the needs_recovery flag before the fs is unlocked. */
5670 ext4_set_feature_journal_needs_recovery(sb);
5671 }
5672
5673 error = ext4_commit_super(sb);
5674out:
5675 if (journal)
5676 /* we rely on upper layer to stop further updates */
5677 jbd2_journal_unlock_updates(journal);
5678 return error;

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

5685static int ext4_unfreeze(struct super_block *sb)
5686{
5687 if (sb_rdonly(sb) || ext4_forced_shutdown(EXT4_SB(sb)))
5688 return 0;
5689
5690 if (EXT4_SB(sb)->s_journal) {
5691 /* Reset the needs_recovery flag before the fs is unlocked. */
5692 ext4_set_feature_journal_needs_recovery(sb);
5693 if (ext4_has_feature_orphan_file(sb))
5694 ext4_set_feature_orphan_present(sb);
5671 }
5672
5673 ext4_commit_super(sb);
5674 return 0;
5675}
5676
5677/*
5678 * Structure to save mount options for ext4_remount's benefit

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

5866 }
5867 }
5868
5869 /*
5870 * If we have an unprocessed orphan list hanging
5871 * around from a previously readonly bdev mount,
5872 * require a full umount/remount for now.
5873 */
5695 }
5696
5697 ext4_commit_super(sb);
5698 return 0;
5699}
5700
5701/*
5702 * Structure to save mount options for ext4_remount's benefit

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

5890 }
5891 }
5892
5893 /*
5894 * If we have an unprocessed orphan list hanging
5895 * around from a previously readonly bdev mount,
5896 * require a full umount/remount for now.
5897 */
5874 if (es->s_last_orphan) {
5898 if (es->s_last_orphan || !ext4_orphan_file_empty(sb)) {
5875 ext4_msg(sb, KERN_WARNING, "Couldn't "
5876 "remount RDWR because of unprocessed "
5877 "orphan inode list. Please "
5878 "umount/remount instead");
5879 err = -EINVAL;
5880 goto restore_opts;
5881 }
5882

--- 772 unchanged lines hidden ---
5899 ext4_msg(sb, KERN_WARNING, "Couldn't "
5900 "remount RDWR because of unprocessed "
5901 "orphan inode list. Please "
5902 "umount/remount instead");
5903 err = -EINVAL;
5904 goto restore_opts;
5905 }
5906

--- 772 unchanged lines hidden ---