diff options
Diffstat (limited to 'fs/ext4/super.c')
-rw-r--r-- | fs/ext4/super.c | 245 |
1 files changed, 128 insertions, 117 deletions
diff --git a/fs/ext4/super.c b/fs/ext4/super.c index 05c159218bc2..1eda6ab0ef9d 100644 --- a/fs/ext4/super.c +++ b/fs/ext4/super.c | |||
@@ -70,7 +70,6 @@ static void ext4_mark_recovery_complete(struct super_block *sb, | |||
70 | static void ext4_clear_journal_err(struct super_block *sb, | 70 | static void ext4_clear_journal_err(struct super_block *sb, |
71 | struct ext4_super_block *es); | 71 | struct ext4_super_block *es); |
72 | static int ext4_sync_fs(struct super_block *sb, int wait); | 72 | static int ext4_sync_fs(struct super_block *sb, int wait); |
73 | static int ext4_sync_fs_nojournal(struct super_block *sb, int wait); | ||
74 | static int ext4_remount(struct super_block *sb, int *flags, char *data); | 73 | static int ext4_remount(struct super_block *sb, int *flags, char *data); |
75 | static int ext4_statfs(struct dentry *dentry, struct kstatfs *buf); | 74 | static int ext4_statfs(struct dentry *dentry, struct kstatfs *buf); |
76 | static int ext4_unfreeze(struct super_block *sb); | 75 | static int ext4_unfreeze(struct super_block *sb); |
@@ -141,8 +140,7 @@ static __le32 ext4_superblock_csum(struct super_block *sb, | |||
141 | static int ext4_superblock_csum_verify(struct super_block *sb, | 140 | static int ext4_superblock_csum_verify(struct super_block *sb, |
142 | struct ext4_super_block *es) | 141 | struct ext4_super_block *es) |
143 | { | 142 | { |
144 | if (!EXT4_HAS_RO_COMPAT_FEATURE(sb, | 143 | if (!ext4_has_metadata_csum(sb)) |
145 | EXT4_FEATURE_RO_COMPAT_METADATA_CSUM)) | ||
146 | return 1; | 144 | return 1; |
147 | 145 | ||
148 | return es->s_checksum == ext4_superblock_csum(sb, es); | 146 | return es->s_checksum == ext4_superblock_csum(sb, es); |
@@ -152,8 +150,7 @@ void ext4_superblock_csum_set(struct super_block *sb) | |||
152 | { | 150 | { |
153 | struct ext4_super_block *es = EXT4_SB(sb)->s_es; | 151 | struct ext4_super_block *es = EXT4_SB(sb)->s_es; |
154 | 152 | ||
155 | if (!EXT4_HAS_RO_COMPAT_FEATURE(sb, | 153 | if (!ext4_has_metadata_csum(sb)) |
156 | EXT4_FEATURE_RO_COMPAT_METADATA_CSUM)) | ||
157 | return; | 154 | return; |
158 | 155 | ||
159 | es->s_checksum = ext4_superblock_csum(sb, es); | 156 | es->s_checksum = ext4_superblock_csum(sb, es); |
@@ -820,10 +817,9 @@ static void ext4_put_super(struct super_block *sb) | |||
820 | percpu_counter_destroy(&sbi->s_freeinodes_counter); | 817 | percpu_counter_destroy(&sbi->s_freeinodes_counter); |
821 | percpu_counter_destroy(&sbi->s_dirs_counter); | 818 | percpu_counter_destroy(&sbi->s_dirs_counter); |
822 | percpu_counter_destroy(&sbi->s_dirtyclusters_counter); | 819 | percpu_counter_destroy(&sbi->s_dirtyclusters_counter); |
823 | percpu_counter_destroy(&sbi->s_extent_cache_cnt); | ||
824 | brelse(sbi->s_sbh); | 820 | brelse(sbi->s_sbh); |
825 | #ifdef CONFIG_QUOTA | 821 | #ifdef CONFIG_QUOTA |
826 | for (i = 0; i < MAXQUOTAS; i++) | 822 | for (i = 0; i < EXT4_MAXQUOTAS; i++) |
827 | kfree(sbi->s_qf_names[i]); | 823 | kfree(sbi->s_qf_names[i]); |
828 | #endif | 824 | #endif |
829 | 825 | ||
@@ -885,6 +881,7 @@ static struct inode *ext4_alloc_inode(struct super_block *sb) | |||
885 | ext4_es_init_tree(&ei->i_es_tree); | 881 | ext4_es_init_tree(&ei->i_es_tree); |
886 | rwlock_init(&ei->i_es_lock); | 882 | rwlock_init(&ei->i_es_lock); |
887 | INIT_LIST_HEAD(&ei->i_es_lru); | 883 | INIT_LIST_HEAD(&ei->i_es_lru); |
884 | ei->i_es_all_nr = 0; | ||
888 | ei->i_es_lru_nr = 0; | 885 | ei->i_es_lru_nr = 0; |
889 | ei->i_touch_when = 0; | 886 | ei->i_touch_when = 0; |
890 | ei->i_reserved_data_blocks = 0; | 887 | ei->i_reserved_data_blocks = 0; |
@@ -1002,7 +999,7 @@ static struct inode *ext4_nfs_get_inode(struct super_block *sb, | |||
1002 | * Currently we don't know the generation for parent directory, so | 999 | * Currently we don't know the generation for parent directory, so |
1003 | * a generation of 0 means "accept any" | 1000 | * a generation of 0 means "accept any" |
1004 | */ | 1001 | */ |
1005 | inode = ext4_iget(sb, ino); | 1002 | inode = ext4_iget_normal(sb, ino); |
1006 | if (IS_ERR(inode)) | 1003 | if (IS_ERR(inode)) |
1007 | return ERR_CAST(inode); | 1004 | return ERR_CAST(inode); |
1008 | if (generation && inode->i_generation != generation) { | 1005 | if (generation && inode->i_generation != generation) { |
@@ -1124,25 +1121,6 @@ static const struct super_operations ext4_sops = { | |||
1124 | .bdev_try_to_free_page = bdev_try_to_free_page, | 1121 | .bdev_try_to_free_page = bdev_try_to_free_page, |
1125 | }; | 1122 | }; |
1126 | 1123 | ||
1127 | static const struct super_operations ext4_nojournal_sops = { | ||
1128 | .alloc_inode = ext4_alloc_inode, | ||
1129 | .destroy_inode = ext4_destroy_inode, | ||
1130 | .write_inode = ext4_write_inode, | ||
1131 | .dirty_inode = ext4_dirty_inode, | ||
1132 | .drop_inode = ext4_drop_inode, | ||
1133 | .evict_inode = ext4_evict_inode, | ||
1134 | .sync_fs = ext4_sync_fs_nojournal, | ||
1135 | .put_super = ext4_put_super, | ||
1136 | .statfs = ext4_statfs, | ||
1137 | .remount_fs = ext4_remount, | ||
1138 | .show_options = ext4_show_options, | ||
1139 | #ifdef CONFIG_QUOTA | ||
1140 | .quota_read = ext4_quota_read, | ||
1141 | .quota_write = ext4_quota_write, | ||
1142 | #endif | ||
1143 | .bdev_try_to_free_page = bdev_try_to_free_page, | ||
1144 | }; | ||
1145 | |||
1146 | static const struct export_operations ext4_export_ops = { | 1124 | static const struct export_operations ext4_export_ops = { |
1147 | .fh_to_dentry = ext4_fh_to_dentry, | 1125 | .fh_to_dentry = ext4_fh_to_dentry, |
1148 | .fh_to_parent = ext4_fh_to_parent, | 1126 | .fh_to_parent = ext4_fh_to_parent, |
@@ -1712,13 +1690,6 @@ static int parse_options(char *options, struct super_block *sb, | |||
1712 | "not specified"); | 1690 | "not specified"); |
1713 | return 0; | 1691 | return 0; |
1714 | } | 1692 | } |
1715 | } else { | ||
1716 | if (sbi->s_jquota_fmt) { | ||
1717 | ext4_msg(sb, KERN_ERR, "journaled quota format " | ||
1718 | "specified with no journaling " | ||
1719 | "enabled"); | ||
1720 | return 0; | ||
1721 | } | ||
1722 | } | 1693 | } |
1723 | #endif | 1694 | #endif |
1724 | if (test_opt(sb, DIOREAD_NOLOCK)) { | 1695 | if (test_opt(sb, DIOREAD_NOLOCK)) { |
@@ -2016,8 +1987,7 @@ static __le16 ext4_group_desc_csum(struct ext4_sb_info *sbi, __u32 block_group, | |||
2016 | __u16 crc = 0; | 1987 | __u16 crc = 0; |
2017 | __le32 le_group = cpu_to_le32(block_group); | 1988 | __le32 le_group = cpu_to_le32(block_group); |
2018 | 1989 | ||
2019 | if ((sbi->s_es->s_feature_ro_compat & | 1990 | if (ext4_has_metadata_csum(sbi->s_sb)) { |
2020 | cpu_to_le32(EXT4_FEATURE_RO_COMPAT_METADATA_CSUM))) { | ||
2021 | /* Use new metadata_csum algorithm */ | 1991 | /* Use new metadata_csum algorithm */ |
2022 | __le16 save_csum; | 1992 | __le16 save_csum; |
2023 | __u32 csum32; | 1993 | __u32 csum32; |
@@ -2035,6 +2005,10 @@ static __le16 ext4_group_desc_csum(struct ext4_sb_info *sbi, __u32 block_group, | |||
2035 | } | 2005 | } |
2036 | 2006 | ||
2037 | /* old crc16 code */ | 2007 | /* old crc16 code */ |
2008 | if (!(sbi->s_es->s_feature_ro_compat & | ||
2009 | cpu_to_le32(EXT4_FEATURE_RO_COMPAT_GDT_CSUM))) | ||
2010 | return 0; | ||
2011 | |||
2038 | offset = offsetof(struct ext4_group_desc, bg_checksum); | 2012 | offset = offsetof(struct ext4_group_desc, bg_checksum); |
2039 | 2013 | ||
2040 | crc = crc16(~0, sbi->s_es->s_uuid, sizeof(sbi->s_es->s_uuid)); | 2014 | crc = crc16(~0, sbi->s_es->s_uuid, sizeof(sbi->s_es->s_uuid)); |
@@ -2191,7 +2165,7 @@ static void ext4_orphan_cleanup(struct super_block *sb, | |||
2191 | if (EXT4_SB(sb)->s_mount_state & EXT4_ERROR_FS) { | 2165 | if (EXT4_SB(sb)->s_mount_state & EXT4_ERROR_FS) { |
2192 | /* don't clear list on RO mount w/ errors */ | 2166 | /* don't clear list on RO mount w/ errors */ |
2193 | if (es->s_last_orphan && !(s_flags & MS_RDONLY)) { | 2167 | if (es->s_last_orphan && !(s_flags & MS_RDONLY)) { |
2194 | jbd_debug(1, "Errors on filesystem, " | 2168 | ext4_msg(sb, KERN_INFO, "Errors on filesystem, " |
2195 | "clearing orphan list.\n"); | 2169 | "clearing orphan list.\n"); |
2196 | es->s_last_orphan = 0; | 2170 | es->s_last_orphan = 0; |
2197 | } | 2171 | } |
@@ -2207,7 +2181,7 @@ static void ext4_orphan_cleanup(struct super_block *sb, | |||
2207 | /* Needed for iput() to work correctly and not trash data */ | 2181 | /* Needed for iput() to work correctly and not trash data */ |
2208 | sb->s_flags |= MS_ACTIVE; | 2182 | sb->s_flags |= MS_ACTIVE; |
2209 | /* Turn on quotas so that they are updated correctly */ | 2183 | /* Turn on quotas so that they are updated correctly */ |
2210 | for (i = 0; i < MAXQUOTAS; i++) { | 2184 | for (i = 0; i < EXT4_MAXQUOTAS; i++) { |
2211 | if (EXT4_SB(sb)->s_qf_names[i]) { | 2185 | if (EXT4_SB(sb)->s_qf_names[i]) { |
2212 | int ret = ext4_quota_on_mount(sb, i); | 2186 | int ret = ext4_quota_on_mount(sb, i); |
2213 | if (ret < 0) | 2187 | if (ret < 0) |
@@ -2263,7 +2237,7 @@ static void ext4_orphan_cleanup(struct super_block *sb, | |||
2263 | PLURAL(nr_truncates)); | 2237 | PLURAL(nr_truncates)); |
2264 | #ifdef CONFIG_QUOTA | 2238 | #ifdef CONFIG_QUOTA |
2265 | /* Turn quotas off */ | 2239 | /* Turn quotas off */ |
2266 | for (i = 0; i < MAXQUOTAS; i++) { | 2240 | for (i = 0; i < EXT4_MAXQUOTAS; i++) { |
2267 | if (sb_dqopt(sb)->files[i]) | 2241 | if (sb_dqopt(sb)->files[i]) |
2268 | dquot_quota_off(sb, i); | 2242 | dquot_quota_off(sb, i); |
2269 | } | 2243 | } |
@@ -2548,6 +2522,16 @@ static ssize_t sbi_ui_store(struct ext4_attr *a, | |||
2548 | return count; | 2522 | return count; |
2549 | } | 2523 | } |
2550 | 2524 | ||
2525 | static ssize_t es_ui_show(struct ext4_attr *a, | ||
2526 | struct ext4_sb_info *sbi, char *buf) | ||
2527 | { | ||
2528 | |||
2529 | unsigned int *ui = (unsigned int *) (((char *) sbi->s_es) + | ||
2530 | a->u.offset); | ||
2531 | |||
2532 | return snprintf(buf, PAGE_SIZE, "%u\n", *ui); | ||
2533 | } | ||
2534 | |||
2551 | static ssize_t reserved_clusters_show(struct ext4_attr *a, | 2535 | static ssize_t reserved_clusters_show(struct ext4_attr *a, |
2552 | struct ext4_sb_info *sbi, char *buf) | 2536 | struct ext4_sb_info *sbi, char *buf) |
2553 | { | 2537 | { |
@@ -2601,14 +2585,29 @@ static struct ext4_attr ext4_attr_##_name = { \ | |||
2601 | .offset = offsetof(struct ext4_sb_info, _elname),\ | 2585 | .offset = offsetof(struct ext4_sb_info, _elname),\ |
2602 | }, \ | 2586 | }, \ |
2603 | } | 2587 | } |
2588 | |||
2589 | #define EXT4_ATTR_OFFSET_ES(_name,_mode,_show,_store,_elname) \ | ||
2590 | static struct ext4_attr ext4_attr_##_name = { \ | ||
2591 | .attr = {.name = __stringify(_name), .mode = _mode }, \ | ||
2592 | .show = _show, \ | ||
2593 | .store = _store, \ | ||
2594 | .u = { \ | ||
2595 | .offset = offsetof(struct ext4_super_block, _elname), \ | ||
2596 | }, \ | ||
2597 | } | ||
2598 | |||
2604 | #define EXT4_ATTR(name, mode, show, store) \ | 2599 | #define EXT4_ATTR(name, mode, show, store) \ |
2605 | static struct ext4_attr ext4_attr_##name = __ATTR(name, mode, show, store) | 2600 | static struct ext4_attr ext4_attr_##name = __ATTR(name, mode, show, store) |
2606 | 2601 | ||
2607 | #define EXT4_INFO_ATTR(name) EXT4_ATTR(name, 0444, NULL, NULL) | 2602 | #define EXT4_INFO_ATTR(name) EXT4_ATTR(name, 0444, NULL, NULL) |
2608 | #define EXT4_RO_ATTR(name) EXT4_ATTR(name, 0444, name##_show, NULL) | 2603 | #define EXT4_RO_ATTR(name) EXT4_ATTR(name, 0444, name##_show, NULL) |
2609 | #define EXT4_RW_ATTR(name) EXT4_ATTR(name, 0644, name##_show, name##_store) | 2604 | #define EXT4_RW_ATTR(name) EXT4_ATTR(name, 0644, name##_show, name##_store) |
2605 | |||
2606 | #define EXT4_RO_ATTR_ES_UI(name, elname) \ | ||
2607 | EXT4_ATTR_OFFSET_ES(name, 0444, es_ui_show, NULL, elname) | ||
2610 | #define EXT4_RW_ATTR_SBI_UI(name, elname) \ | 2608 | #define EXT4_RW_ATTR_SBI_UI(name, elname) \ |
2611 | EXT4_ATTR_OFFSET(name, 0644, sbi_ui_show, sbi_ui_store, elname) | 2609 | EXT4_ATTR_OFFSET(name, 0644, sbi_ui_show, sbi_ui_store, elname) |
2610 | |||
2612 | #define ATTR_LIST(name) &ext4_attr_##name.attr | 2611 | #define ATTR_LIST(name) &ext4_attr_##name.attr |
2613 | #define EXT4_DEPRECATED_ATTR(_name, _val) \ | 2612 | #define EXT4_DEPRECATED_ATTR(_name, _val) \ |
2614 | static struct ext4_attr ext4_attr_##_name = { \ | 2613 | static struct ext4_attr ext4_attr_##_name = { \ |
@@ -2641,6 +2640,9 @@ EXT4_RW_ATTR_SBI_UI(warning_ratelimit_interval_ms, s_warning_ratelimit_state.int | |||
2641 | EXT4_RW_ATTR_SBI_UI(warning_ratelimit_burst, s_warning_ratelimit_state.burst); | 2640 | EXT4_RW_ATTR_SBI_UI(warning_ratelimit_burst, s_warning_ratelimit_state.burst); |
2642 | EXT4_RW_ATTR_SBI_UI(msg_ratelimit_interval_ms, s_msg_ratelimit_state.interval); | 2641 | EXT4_RW_ATTR_SBI_UI(msg_ratelimit_interval_ms, s_msg_ratelimit_state.interval); |
2643 | EXT4_RW_ATTR_SBI_UI(msg_ratelimit_burst, s_msg_ratelimit_state.burst); | 2642 | EXT4_RW_ATTR_SBI_UI(msg_ratelimit_burst, s_msg_ratelimit_state.burst); |
2643 | EXT4_RO_ATTR_ES_UI(errors_count, s_error_count); | ||
2644 | EXT4_RO_ATTR_ES_UI(first_error_time, s_first_error_time); | ||
2645 | EXT4_RO_ATTR_ES_UI(last_error_time, s_last_error_time); | ||
2644 | 2646 | ||
2645 | static struct attribute *ext4_attrs[] = { | 2647 | static struct attribute *ext4_attrs[] = { |
2646 | ATTR_LIST(delayed_allocation_blocks), | 2648 | ATTR_LIST(delayed_allocation_blocks), |
@@ -2664,6 +2666,9 @@ static struct attribute *ext4_attrs[] = { | |||
2664 | ATTR_LIST(warning_ratelimit_burst), | 2666 | ATTR_LIST(warning_ratelimit_burst), |
2665 | ATTR_LIST(msg_ratelimit_interval_ms), | 2667 | ATTR_LIST(msg_ratelimit_interval_ms), |
2666 | ATTR_LIST(msg_ratelimit_burst), | 2668 | ATTR_LIST(msg_ratelimit_burst), |
2669 | ATTR_LIST(errors_count), | ||
2670 | ATTR_LIST(first_error_time), | ||
2671 | ATTR_LIST(last_error_time), | ||
2667 | NULL, | 2672 | NULL, |
2668 | }; | 2673 | }; |
2669 | 2674 | ||
@@ -2723,9 +2728,25 @@ static void ext4_feat_release(struct kobject *kobj) | |||
2723 | complete(&ext4_feat->f_kobj_unregister); | 2728 | complete(&ext4_feat->f_kobj_unregister); |
2724 | } | 2729 | } |
2725 | 2730 | ||
2731 | static ssize_t ext4_feat_show(struct kobject *kobj, | ||
2732 | struct attribute *attr, char *buf) | ||
2733 | { | ||
2734 | return snprintf(buf, PAGE_SIZE, "supported\n"); | ||
2735 | } | ||
2736 | |||
2737 | /* | ||
2738 | * We can not use ext4_attr_show/store because it relies on the kobject | ||
2739 | * being embedded in the ext4_sb_info structure which is definitely not | ||
2740 | * true in this case. | ||
2741 | */ | ||
2742 | static const struct sysfs_ops ext4_feat_ops = { | ||
2743 | .show = ext4_feat_show, | ||
2744 | .store = NULL, | ||
2745 | }; | ||
2746 | |||
2726 | static struct kobj_type ext4_feat_ktype = { | 2747 | static struct kobj_type ext4_feat_ktype = { |
2727 | .default_attrs = ext4_feat_attrs, | 2748 | .default_attrs = ext4_feat_attrs, |
2728 | .sysfs_ops = &ext4_attr_ops, | 2749 | .sysfs_ops = &ext4_feat_ops, |
2729 | .release = ext4_feat_release, | 2750 | .release = ext4_feat_release, |
2730 | }; | 2751 | }; |
2731 | 2752 | ||
@@ -3179,8 +3200,7 @@ static int set_journal_csum_feature_set(struct super_block *sb) | |||
3179 | int compat, incompat; | 3200 | int compat, incompat; |
3180 | struct ext4_sb_info *sbi = EXT4_SB(sb); | 3201 | struct ext4_sb_info *sbi = EXT4_SB(sb); |
3181 | 3202 | ||
3182 | if (EXT4_HAS_RO_COMPAT_FEATURE(sb, | 3203 | if (ext4_has_metadata_csum(sb)) { |
3183 | EXT4_FEATURE_RO_COMPAT_METADATA_CSUM)) { | ||
3184 | /* journal checksum v3 */ | 3204 | /* journal checksum v3 */ |
3185 | compat = 0; | 3205 | compat = 0; |
3186 | incompat = JBD2_FEATURE_INCOMPAT_CSUM_V3; | 3206 | incompat = JBD2_FEATURE_INCOMPAT_CSUM_V3; |
@@ -3190,6 +3210,10 @@ static int set_journal_csum_feature_set(struct super_block *sb) | |||
3190 | incompat = 0; | 3210 | incompat = 0; |
3191 | } | 3211 | } |
3192 | 3212 | ||
3213 | jbd2_journal_clear_features(sbi->s_journal, | ||
3214 | JBD2_FEATURE_COMPAT_CHECKSUM, 0, | ||
3215 | JBD2_FEATURE_INCOMPAT_CSUM_V3 | | ||
3216 | JBD2_FEATURE_INCOMPAT_CSUM_V2); | ||
3193 | if (test_opt(sb, JOURNAL_ASYNC_COMMIT)) { | 3217 | if (test_opt(sb, JOURNAL_ASYNC_COMMIT)) { |
3194 | ret = jbd2_journal_set_features(sbi->s_journal, | 3218 | ret = jbd2_journal_set_features(sbi->s_journal, |
3195 | compat, 0, | 3219 | compat, 0, |
@@ -3202,11 +3226,8 @@ static int set_journal_csum_feature_set(struct super_block *sb) | |||
3202 | jbd2_journal_clear_features(sbi->s_journal, 0, 0, | 3226 | jbd2_journal_clear_features(sbi->s_journal, 0, 0, |
3203 | JBD2_FEATURE_INCOMPAT_ASYNC_COMMIT); | 3227 | JBD2_FEATURE_INCOMPAT_ASYNC_COMMIT); |
3204 | } else { | 3228 | } else { |
3205 | jbd2_journal_clear_features(sbi->s_journal, | 3229 | jbd2_journal_clear_features(sbi->s_journal, 0, 0, |
3206 | JBD2_FEATURE_COMPAT_CHECKSUM, 0, | 3230 | JBD2_FEATURE_INCOMPAT_ASYNC_COMMIT); |
3207 | JBD2_FEATURE_INCOMPAT_ASYNC_COMMIT | | ||
3208 | JBD2_FEATURE_INCOMPAT_CSUM_V3 | | ||
3209 | JBD2_FEATURE_INCOMPAT_CSUM_V2); | ||
3210 | } | 3231 | } |
3211 | 3232 | ||
3212 | return ret; | 3233 | return ret; |
@@ -3436,7 +3457,7 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent) | |||
3436 | logical_sb_block = sb_block; | 3457 | logical_sb_block = sb_block; |
3437 | } | 3458 | } |
3438 | 3459 | ||
3439 | if (!(bh = sb_bread(sb, logical_sb_block))) { | 3460 | if (!(bh = sb_bread_unmovable(sb, logical_sb_block))) { |
3440 | ext4_msg(sb, KERN_ERR, "unable to read superblock"); | 3461 | ext4_msg(sb, KERN_ERR, "unable to read superblock"); |
3441 | goto out_fail; | 3462 | goto out_fail; |
3442 | } | 3463 | } |
@@ -3487,8 +3508,7 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent) | |||
3487 | } | 3508 | } |
3488 | 3509 | ||
3489 | /* Precompute checksum seed for all metadata */ | 3510 | /* Precompute checksum seed for all metadata */ |
3490 | if (EXT4_HAS_RO_COMPAT_FEATURE(sb, | 3511 | if (ext4_has_metadata_csum(sb)) |
3491 | EXT4_FEATURE_RO_COMPAT_METADATA_CSUM)) | ||
3492 | sbi->s_csum_seed = ext4_chksum(sbi, ~0, es->s_uuid, | 3512 | sbi->s_csum_seed = ext4_chksum(sbi, ~0, es->s_uuid, |
3493 | sizeof(es->s_uuid)); | 3513 | sizeof(es->s_uuid)); |
3494 | 3514 | ||
@@ -3519,8 +3539,8 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent) | |||
3519 | set_opt(sb, ERRORS_CONT); | 3539 | set_opt(sb, ERRORS_CONT); |
3520 | else | 3540 | else |
3521 | set_opt(sb, ERRORS_RO); | 3541 | set_opt(sb, ERRORS_RO); |
3522 | if (def_mount_opts & EXT4_DEFM_BLOCK_VALIDITY) | 3542 | /* block_validity enabled by default; disable with noblock_validity */ |
3523 | set_opt(sb, BLOCK_VALIDITY); | 3543 | set_opt(sb, BLOCK_VALIDITY); |
3524 | if (def_mount_opts & EXT4_DEFM_DISCARD) | 3544 | if (def_mount_opts & EXT4_DEFM_DISCARD) |
3525 | set_opt(sb, DISCARD); | 3545 | set_opt(sb, DISCARD); |
3526 | 3546 | ||
@@ -3646,7 +3666,7 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent) | |||
3646 | brelse(bh); | 3666 | brelse(bh); |
3647 | logical_sb_block = sb_block * EXT4_MIN_BLOCK_SIZE; | 3667 | logical_sb_block = sb_block * EXT4_MIN_BLOCK_SIZE; |
3648 | offset = do_div(logical_sb_block, blocksize); | 3668 | offset = do_div(logical_sb_block, blocksize); |
3649 | bh = sb_bread(sb, logical_sb_block); | 3669 | bh = sb_bread_unmovable(sb, logical_sb_block); |
3650 | if (!bh) { | 3670 | if (!bh) { |
3651 | ext4_msg(sb, KERN_ERR, | 3671 | ext4_msg(sb, KERN_ERR, |
3652 | "Can't read superblock on 2nd try"); | 3672 | "Can't read superblock on 2nd try"); |
@@ -3868,7 +3888,7 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent) | |||
3868 | 3888 | ||
3869 | for (i = 0; i < db_count; i++) { | 3889 | for (i = 0; i < db_count; i++) { |
3870 | block = descriptor_loc(sb, logical_sb_block, i); | 3890 | block = descriptor_loc(sb, logical_sb_block, i); |
3871 | sbi->s_group_desc[i] = sb_bread(sb, block); | 3891 | sbi->s_group_desc[i] = sb_bread_unmovable(sb, block); |
3872 | if (!sbi->s_group_desc[i]) { | 3892 | if (!sbi->s_group_desc[i]) { |
3873 | ext4_msg(sb, KERN_ERR, | 3893 | ext4_msg(sb, KERN_ERR, |
3874 | "can't read group descriptor %d", i); | 3894 | "can't read group descriptor %d", i); |
@@ -3890,13 +3910,8 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent) | |||
3890 | sbi->s_err_report.data = (unsigned long) sb; | 3910 | sbi->s_err_report.data = (unsigned long) sb; |
3891 | 3911 | ||
3892 | /* Register extent status tree shrinker */ | 3912 | /* Register extent status tree shrinker */ |
3893 | ext4_es_register_shrinker(sbi); | 3913 | if (ext4_es_register_shrinker(sbi)) |
3894 | |||
3895 | err = percpu_counter_init(&sbi->s_extent_cache_cnt, 0, GFP_KERNEL); | ||
3896 | if (err) { | ||
3897 | ext4_msg(sb, KERN_ERR, "insufficient memory"); | ||
3898 | goto failed_mount3; | 3914 | goto failed_mount3; |
3899 | } | ||
3900 | 3915 | ||
3901 | sbi->s_stripe = ext4_get_stripe_size(sbi); | 3916 | sbi->s_stripe = ext4_get_stripe_size(sbi); |
3902 | sbi->s_extent_max_zeroout_kb = 32; | 3917 | sbi->s_extent_max_zeroout_kb = 32; |
@@ -3904,11 +3919,7 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent) | |||
3904 | /* | 3919 | /* |
3905 | * set up enough so that it can read an inode | 3920 | * set up enough so that it can read an inode |
3906 | */ | 3921 | */ |
3907 | if (!test_opt(sb, NOLOAD) && | 3922 | sb->s_op = &ext4_sops; |
3908 | EXT4_HAS_COMPAT_FEATURE(sb, EXT4_FEATURE_COMPAT_HAS_JOURNAL)) | ||
3909 | sb->s_op = &ext4_sops; | ||
3910 | else | ||
3911 | sb->s_op = &ext4_nojournal_sops; | ||
3912 | sb->s_export_op = &ext4_export_ops; | 3923 | sb->s_export_op = &ext4_export_ops; |
3913 | sb->s_xattr = ext4_xattr_handlers; | 3924 | sb->s_xattr = ext4_xattr_handlers; |
3914 | #ifdef CONFIG_QUOTA | 3925 | #ifdef CONFIG_QUOTA |
@@ -4229,10 +4240,9 @@ failed_mount_wq: | |||
4229 | jbd2_journal_destroy(sbi->s_journal); | 4240 | jbd2_journal_destroy(sbi->s_journal); |
4230 | sbi->s_journal = NULL; | 4241 | sbi->s_journal = NULL; |
4231 | } | 4242 | } |
4232 | failed_mount3: | ||
4233 | ext4_es_unregister_shrinker(sbi); | 4243 | ext4_es_unregister_shrinker(sbi); |
4244 | failed_mount3: | ||
4234 | del_timer_sync(&sbi->s_err_report); | 4245 | del_timer_sync(&sbi->s_err_report); |
4235 | percpu_counter_destroy(&sbi->s_extent_cache_cnt); | ||
4236 | if (sbi->s_mmp_tsk) | 4246 | if (sbi->s_mmp_tsk) |
4237 | kthread_stop(sbi->s_mmp_tsk); | 4247 | kthread_stop(sbi->s_mmp_tsk); |
4238 | failed_mount2: | 4248 | failed_mount2: |
@@ -4247,7 +4257,7 @@ failed_mount: | |||
4247 | remove_proc_entry(sb->s_id, ext4_proc_root); | 4257 | remove_proc_entry(sb->s_id, ext4_proc_root); |
4248 | } | 4258 | } |
4249 | #ifdef CONFIG_QUOTA | 4259 | #ifdef CONFIG_QUOTA |
4250 | for (i = 0; i < MAXQUOTAS; i++) | 4260 | for (i = 0; i < EXT4_MAXQUOTAS; i++) |
4251 | kfree(sbi->s_qf_names[i]); | 4261 | kfree(sbi->s_qf_names[i]); |
4252 | #endif | 4262 | #endif |
4253 | ext4_blkdev_remove(sbi); | 4263 | ext4_blkdev_remove(sbi); |
@@ -4375,6 +4385,15 @@ static journal_t *ext4_get_dev_journal(struct super_block *sb, | |||
4375 | goto out_bdev; | 4385 | goto out_bdev; |
4376 | } | 4386 | } |
4377 | 4387 | ||
4388 | if ((le32_to_cpu(es->s_feature_ro_compat) & | ||
4389 | EXT4_FEATURE_RO_COMPAT_METADATA_CSUM) && | ||
4390 | es->s_checksum != ext4_superblock_csum(sb, es)) { | ||
4391 | ext4_msg(sb, KERN_ERR, "external journal has " | ||
4392 | "corrupt superblock"); | ||
4393 | brelse(bh); | ||
4394 | goto out_bdev; | ||
4395 | } | ||
4396 | |||
4378 | if (memcmp(EXT4_SB(sb)->s_es->s_journal_uuid, es->s_uuid, 16)) { | 4397 | if (memcmp(EXT4_SB(sb)->s_es->s_journal_uuid, es->s_uuid, 16)) { |
4379 | ext4_msg(sb, KERN_ERR, "journal UUID does not match"); | 4398 | ext4_msg(sb, KERN_ERR, "journal UUID does not match"); |
4380 | brelse(bh); | 4399 | brelse(bh); |
@@ -4677,15 +4696,19 @@ static int ext4_sync_fs(struct super_block *sb, int wait) | |||
4677 | * being sent at the end of the function. But we can skip it if | 4696 | * being sent at the end of the function. But we can skip it if |
4678 | * transaction_commit will do it for us. | 4697 | * transaction_commit will do it for us. |
4679 | */ | 4698 | */ |
4680 | target = jbd2_get_latest_transaction(sbi->s_journal); | 4699 | if (sbi->s_journal) { |
4681 | if (wait && sbi->s_journal->j_flags & JBD2_BARRIER && | 4700 | target = jbd2_get_latest_transaction(sbi->s_journal); |
4682 | !jbd2_trans_will_send_data_barrier(sbi->s_journal, target)) | 4701 | if (wait && sbi->s_journal->j_flags & JBD2_BARRIER && |
4702 | !jbd2_trans_will_send_data_barrier(sbi->s_journal, target)) | ||
4703 | needs_barrier = true; | ||
4704 | |||
4705 | if (jbd2_journal_start_commit(sbi->s_journal, &target)) { | ||
4706 | if (wait) | ||
4707 | ret = jbd2_log_wait_commit(sbi->s_journal, | ||
4708 | target); | ||
4709 | } | ||
4710 | } else if (wait && test_opt(sb, BARRIER)) | ||
4683 | needs_barrier = true; | 4711 | needs_barrier = true; |
4684 | |||
4685 | if (jbd2_journal_start_commit(sbi->s_journal, &target)) { | ||
4686 | if (wait) | ||
4687 | ret = jbd2_log_wait_commit(sbi->s_journal, target); | ||
4688 | } | ||
4689 | if (needs_barrier) { | 4712 | if (needs_barrier) { |
4690 | int err; | 4713 | int err; |
4691 | err = blkdev_issue_flush(sb->s_bdev, GFP_KERNEL, NULL); | 4714 | err = blkdev_issue_flush(sb->s_bdev, GFP_KERNEL, NULL); |
@@ -4696,19 +4719,6 @@ static int ext4_sync_fs(struct super_block *sb, int wait) | |||
4696 | return ret; | 4719 | return ret; |
4697 | } | 4720 | } |
4698 | 4721 | ||
4699 | static int ext4_sync_fs_nojournal(struct super_block *sb, int wait) | ||
4700 | { | ||
4701 | int ret = 0; | ||
4702 | |||
4703 | trace_ext4_sync_fs(sb, wait); | ||
4704 | flush_workqueue(EXT4_SB(sb)->rsv_conversion_wq); | ||
4705 | dquot_writeback_dquots(sb, -1); | ||
4706 | if (wait && test_opt(sb, BARRIER)) | ||
4707 | ret = blkdev_issue_flush(sb->s_bdev, GFP_KERNEL, NULL); | ||
4708 | |||
4709 | return ret; | ||
4710 | } | ||
4711 | |||
4712 | /* | 4722 | /* |
4713 | * LVM calls this function before a (read-only) snapshot is created. This | 4723 | * LVM calls this function before a (read-only) snapshot is created. This |
4714 | * gives us a chance to flush the journal completely and mark the fs clean. | 4724 | * gives us a chance to flush the journal completely and mark the fs clean. |
@@ -4727,23 +4737,26 @@ static int ext4_freeze(struct super_block *sb) | |||
4727 | 4737 | ||
4728 | journal = EXT4_SB(sb)->s_journal; | 4738 | journal = EXT4_SB(sb)->s_journal; |
4729 | 4739 | ||
4730 | /* Now we set up the journal barrier. */ | 4740 | if (journal) { |
4731 | jbd2_journal_lock_updates(journal); | 4741 | /* Now we set up the journal barrier. */ |
4742 | jbd2_journal_lock_updates(journal); | ||
4732 | 4743 | ||
4733 | /* | 4744 | /* |
4734 | * Don't clear the needs_recovery flag if we failed to flush | 4745 | * Don't clear the needs_recovery flag if we failed to |
4735 | * the journal. | 4746 | * flush the journal. |
4736 | */ | 4747 | */ |
4737 | error = jbd2_journal_flush(journal); | 4748 | error = jbd2_journal_flush(journal); |
4738 | if (error < 0) | 4749 | if (error < 0) |
4739 | goto out; | 4750 | goto out; |
4751 | } | ||
4740 | 4752 | ||
4741 | /* Journal blocked and flushed, clear needs_recovery flag. */ | 4753 | /* Journal blocked and flushed, clear needs_recovery flag. */ |
4742 | EXT4_CLEAR_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_RECOVER); | 4754 | EXT4_CLEAR_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_RECOVER); |
4743 | error = ext4_commit_super(sb, 1); | 4755 | error = ext4_commit_super(sb, 1); |
4744 | out: | 4756 | out: |
4745 | /* we rely on upper layer to stop further updates */ | 4757 | if (journal) |
4746 | jbd2_journal_unlock_updates(EXT4_SB(sb)->s_journal); | 4758 | /* we rely on upper layer to stop further updates */ |
4759 | jbd2_journal_unlock_updates(journal); | ||
4747 | return error; | 4760 | return error; |
4748 | } | 4761 | } |
4749 | 4762 | ||
@@ -4774,7 +4787,7 @@ struct ext4_mount_options { | |||
4774 | u32 s_min_batch_time, s_max_batch_time; | 4787 | u32 s_min_batch_time, s_max_batch_time; |
4775 | #ifdef CONFIG_QUOTA | 4788 | #ifdef CONFIG_QUOTA |
4776 | int s_jquota_fmt; | 4789 | int s_jquota_fmt; |
4777 | char *s_qf_names[MAXQUOTAS]; | 4790 | char *s_qf_names[EXT4_MAXQUOTAS]; |
4778 | #endif | 4791 | #endif |
4779 | }; | 4792 | }; |
4780 | 4793 | ||
@@ -4804,7 +4817,7 @@ static int ext4_remount(struct super_block *sb, int *flags, char *data) | |||
4804 | old_opts.s_max_batch_time = sbi->s_max_batch_time; | 4817 | old_opts.s_max_batch_time = sbi->s_max_batch_time; |
4805 | #ifdef CONFIG_QUOTA | 4818 | #ifdef CONFIG_QUOTA |
4806 | old_opts.s_jquota_fmt = sbi->s_jquota_fmt; | 4819 | old_opts.s_jquota_fmt = sbi->s_jquota_fmt; |
4807 | for (i = 0; i < MAXQUOTAS; i++) | 4820 | for (i = 0; i < EXT4_MAXQUOTAS; i++) |
4808 | if (sbi->s_qf_names[i]) { | 4821 | if (sbi->s_qf_names[i]) { |
4809 | old_opts.s_qf_names[i] = kstrdup(sbi->s_qf_names[i], | 4822 | old_opts.s_qf_names[i] = kstrdup(sbi->s_qf_names[i], |
4810 | GFP_KERNEL); | 4823 | GFP_KERNEL); |
@@ -4965,7 +4978,7 @@ static int ext4_remount(struct super_block *sb, int *flags, char *data) | |||
4965 | 4978 | ||
4966 | #ifdef CONFIG_QUOTA | 4979 | #ifdef CONFIG_QUOTA |
4967 | /* Release old quota file names */ | 4980 | /* Release old quota file names */ |
4968 | for (i = 0; i < MAXQUOTAS; i++) | 4981 | for (i = 0; i < EXT4_MAXQUOTAS; i++) |
4969 | kfree(old_opts.s_qf_names[i]); | 4982 | kfree(old_opts.s_qf_names[i]); |
4970 | if (enable_quota) { | 4983 | if (enable_quota) { |
4971 | if (sb_any_quota_suspended(sb)) | 4984 | if (sb_any_quota_suspended(sb)) |
@@ -4994,7 +5007,7 @@ restore_opts: | |||
4994 | sbi->s_max_batch_time = old_opts.s_max_batch_time; | 5007 | sbi->s_max_batch_time = old_opts.s_max_batch_time; |
4995 | #ifdef CONFIG_QUOTA | 5008 | #ifdef CONFIG_QUOTA |
4996 | sbi->s_jquota_fmt = old_opts.s_jquota_fmt; | 5009 | sbi->s_jquota_fmt = old_opts.s_jquota_fmt; |
4997 | for (i = 0; i < MAXQUOTAS; i++) { | 5010 | for (i = 0; i < EXT4_MAXQUOTAS; i++) { |
4998 | kfree(sbi->s_qf_names[i]); | 5011 | kfree(sbi->s_qf_names[i]); |
4999 | sbi->s_qf_names[i] = old_opts.s_qf_names[i]; | 5012 | sbi->s_qf_names[i] = old_opts.s_qf_names[i]; |
5000 | } | 5013 | } |
@@ -5197,7 +5210,7 @@ static int ext4_quota_enable(struct super_block *sb, int type, int format_id, | |||
5197 | { | 5210 | { |
5198 | int err; | 5211 | int err; |
5199 | struct inode *qf_inode; | 5212 | struct inode *qf_inode; |
5200 | unsigned long qf_inums[MAXQUOTAS] = { | 5213 | unsigned long qf_inums[EXT4_MAXQUOTAS] = { |
5201 | le32_to_cpu(EXT4_SB(sb)->s_es->s_usr_quota_inum), | 5214 | le32_to_cpu(EXT4_SB(sb)->s_es->s_usr_quota_inum), |
5202 | le32_to_cpu(EXT4_SB(sb)->s_es->s_grp_quota_inum) | 5215 | le32_to_cpu(EXT4_SB(sb)->s_es->s_grp_quota_inum) |
5203 | }; | 5216 | }; |
@@ -5225,13 +5238,13 @@ static int ext4_quota_enable(struct super_block *sb, int type, int format_id, | |||
5225 | static int ext4_enable_quotas(struct super_block *sb) | 5238 | static int ext4_enable_quotas(struct super_block *sb) |
5226 | { | 5239 | { |
5227 | int type, err = 0; | 5240 | int type, err = 0; |
5228 | unsigned long qf_inums[MAXQUOTAS] = { | 5241 | unsigned long qf_inums[EXT4_MAXQUOTAS] = { |
5229 | le32_to_cpu(EXT4_SB(sb)->s_es->s_usr_quota_inum), | 5242 | le32_to_cpu(EXT4_SB(sb)->s_es->s_usr_quota_inum), |
5230 | le32_to_cpu(EXT4_SB(sb)->s_es->s_grp_quota_inum) | 5243 | le32_to_cpu(EXT4_SB(sb)->s_es->s_grp_quota_inum) |
5231 | }; | 5244 | }; |
5232 | 5245 | ||
5233 | sb_dqopt(sb)->flags |= DQUOT_QUOTA_SYS_FILE; | 5246 | sb_dqopt(sb)->flags |= DQUOT_QUOTA_SYS_FILE; |
5234 | for (type = 0; type < MAXQUOTAS; type++) { | 5247 | for (type = 0; type < EXT4_MAXQUOTAS; type++) { |
5235 | if (qf_inums[type]) { | 5248 | if (qf_inums[type]) { |
5236 | err = ext4_quota_enable(sb, type, QFMT_VFS_V1, | 5249 | err = ext4_quota_enable(sb, type, QFMT_VFS_V1, |
5237 | DQUOT_USAGE_ENABLED); | 5250 | DQUOT_USAGE_ENABLED); |
@@ -5309,7 +5322,6 @@ static ssize_t ext4_quota_read(struct super_block *sb, int type, char *data, | |||
5309 | { | 5322 | { |
5310 | struct inode *inode = sb_dqopt(sb)->files[type]; | 5323 | struct inode *inode = sb_dqopt(sb)->files[type]; |
5311 | ext4_lblk_t blk = off >> EXT4_BLOCK_SIZE_BITS(sb); | 5324 | ext4_lblk_t blk = off >> EXT4_BLOCK_SIZE_BITS(sb); |
5312 | int err = 0; | ||
5313 | int offset = off & (sb->s_blocksize - 1); | 5325 | int offset = off & (sb->s_blocksize - 1); |
5314 | int tocopy; | 5326 | int tocopy; |
5315 | size_t toread; | 5327 | size_t toread; |
@@ -5324,9 +5336,9 @@ static ssize_t ext4_quota_read(struct super_block *sb, int type, char *data, | |||
5324 | while (toread > 0) { | 5336 | while (toread > 0) { |
5325 | tocopy = sb->s_blocksize - offset < toread ? | 5337 | tocopy = sb->s_blocksize - offset < toread ? |
5326 | sb->s_blocksize - offset : toread; | 5338 | sb->s_blocksize - offset : toread; |
5327 | bh = ext4_bread(NULL, inode, blk, 0, &err); | 5339 | bh = ext4_bread(NULL, inode, blk, 0); |
5328 | if (err) | 5340 | if (IS_ERR(bh)) |
5329 | return err; | 5341 | return PTR_ERR(bh); |
5330 | if (!bh) /* A hole? */ | 5342 | if (!bh) /* A hole? */ |
5331 | memset(data, 0, tocopy); | 5343 | memset(data, 0, tocopy); |
5332 | else | 5344 | else |
@@ -5347,8 +5359,7 @@ static ssize_t ext4_quota_write(struct super_block *sb, int type, | |||
5347 | { | 5359 | { |
5348 | struct inode *inode = sb_dqopt(sb)->files[type]; | 5360 | struct inode *inode = sb_dqopt(sb)->files[type]; |
5349 | ext4_lblk_t blk = off >> EXT4_BLOCK_SIZE_BITS(sb); | 5361 | ext4_lblk_t blk = off >> EXT4_BLOCK_SIZE_BITS(sb); |
5350 | int err = 0; | 5362 | int err, offset = off & (sb->s_blocksize - 1); |
5351 | int offset = off & (sb->s_blocksize - 1); | ||
5352 | struct buffer_head *bh; | 5363 | struct buffer_head *bh; |
5353 | handle_t *handle = journal_current_handle(); | 5364 | handle_t *handle = journal_current_handle(); |
5354 | 5365 | ||
@@ -5369,14 +5380,16 @@ static ssize_t ext4_quota_write(struct super_block *sb, int type, | |||
5369 | return -EIO; | 5380 | return -EIO; |
5370 | } | 5381 | } |
5371 | 5382 | ||
5372 | bh = ext4_bread(handle, inode, blk, 1, &err); | 5383 | bh = ext4_bread(handle, inode, blk, 1); |
5384 | if (IS_ERR(bh)) | ||
5385 | return PTR_ERR(bh); | ||
5373 | if (!bh) | 5386 | if (!bh) |
5374 | goto out; | 5387 | goto out; |
5375 | BUFFER_TRACE(bh, "get write access"); | 5388 | BUFFER_TRACE(bh, "get write access"); |
5376 | err = ext4_journal_get_write_access(handle, bh); | 5389 | err = ext4_journal_get_write_access(handle, bh); |
5377 | if (err) { | 5390 | if (err) { |
5378 | brelse(bh); | 5391 | brelse(bh); |
5379 | goto out; | 5392 | return err; |
5380 | } | 5393 | } |
5381 | lock_buffer(bh); | 5394 | lock_buffer(bh); |
5382 | memcpy(bh->b_data+offset, data, len); | 5395 | memcpy(bh->b_data+offset, data, len); |
@@ -5385,8 +5398,6 @@ static ssize_t ext4_quota_write(struct super_block *sb, int type, | |||
5385 | err = ext4_handle_dirty_metadata(handle, NULL, bh); | 5398 | err = ext4_handle_dirty_metadata(handle, NULL, bh); |
5386 | brelse(bh); | 5399 | brelse(bh); |
5387 | out: | 5400 | out: |
5388 | if (err) | ||
5389 | return err; | ||
5390 | if (inode->i_size < off + len) { | 5401 | if (inode->i_size < off + len) { |
5391 | i_size_write(inode, off + len); | 5402 | i_size_write(inode, off + len); |
5392 | EXT4_I(inode)->i_disksize = inode->i_size; | 5403 | EXT4_I(inode)->i_disksize = inode->i_size; |