aboutsummaryrefslogtreecommitdiffstats
path: root/fs/ext4/super.c
diff options
context:
space:
mode:
Diffstat (limited to 'fs/ext4/super.c')
-rw-r--r--fs/ext4/super.c92
1 files changed, 60 insertions, 32 deletions
diff --git a/fs/ext4/super.c b/fs/ext4/super.c
index 69c55d4e4626..7265a0367476 100644
--- a/fs/ext4/super.c
+++ b/fs/ext4/super.c
@@ -420,7 +420,7 @@ static void __save_error_info(struct super_block *sb, const char *func,
420 */ 420 */
421 if (!es->s_error_count) 421 if (!es->s_error_count)
422 mod_timer(&EXT4_SB(sb)->s_err_report, jiffies + 24*60*60*HZ); 422 mod_timer(&EXT4_SB(sb)->s_err_report, jiffies + 24*60*60*HZ);
423 es->s_error_count = cpu_to_le32(le32_to_cpu(es->s_error_count) + 1); 423 le32_add_cpu(&es->s_error_count, 1);
424} 424}
425 425
426static void save_error_info(struct super_block *sb, const char *func, 426static void save_error_info(struct super_block *sb, const char *func,
@@ -850,7 +850,6 @@ static void ext4_put_super(struct super_block *sb)
850 flush_workqueue(sbi->dio_unwritten_wq); 850 flush_workqueue(sbi->dio_unwritten_wq);
851 destroy_workqueue(sbi->dio_unwritten_wq); 851 destroy_workqueue(sbi->dio_unwritten_wq);
852 852
853 lock_super(sb);
854 if (sbi->s_journal) { 853 if (sbi->s_journal) {
855 err = jbd2_journal_destroy(sbi->s_journal); 854 err = jbd2_journal_destroy(sbi->s_journal);
856 sbi->s_journal = NULL; 855 sbi->s_journal = NULL;
@@ -917,7 +916,6 @@ static void ext4_put_super(struct super_block *sb)
917 * Now that we are completely done shutting down the 916 * Now that we are completely done shutting down the
918 * superblock, we need to actually destroy the kobject. 917 * superblock, we need to actually destroy the kobject.
919 */ 918 */
920 unlock_super(sb);
921 kobject_put(&sbi->s_kobj); 919 kobject_put(&sbi->s_kobj);
922 wait_for_completion(&sbi->s_kobj_unregister); 920 wait_for_completion(&sbi->s_kobj_unregister);
923 if (sbi->s_chksum_driver) 921 if (sbi->s_chksum_driver)
@@ -956,11 +954,10 @@ static struct inode *ext4_alloc_inode(struct super_block *sb)
956 ei->jinode = NULL; 954 ei->jinode = NULL;
957 INIT_LIST_HEAD(&ei->i_completed_io_list); 955 INIT_LIST_HEAD(&ei->i_completed_io_list);
958 spin_lock_init(&ei->i_completed_io_lock); 956 spin_lock_init(&ei->i_completed_io_lock);
959 ei->cur_aio_dio = NULL;
960 ei->i_sync_tid = 0; 957 ei->i_sync_tid = 0;
961 ei->i_datasync_tid = 0; 958 ei->i_datasync_tid = 0;
962 atomic_set(&ei->i_ioend_count, 0); 959 atomic_set(&ei->i_ioend_count, 0);
963 atomic_set(&ei->i_aiodio_unwritten, 0); 960 atomic_set(&ei->i_unwritten, 0);
964 961
965 return &ei->vfs_inode; 962 return &ei->vfs_inode;
966} 963}
@@ -1224,6 +1221,7 @@ enum {
1224 Opt_inode_readahead_blks, Opt_journal_ioprio, 1221 Opt_inode_readahead_blks, Opt_journal_ioprio,
1225 Opt_dioread_nolock, Opt_dioread_lock, 1222 Opt_dioread_nolock, Opt_dioread_lock,
1226 Opt_discard, Opt_nodiscard, Opt_init_itable, Opt_noinit_itable, 1223 Opt_discard, Opt_nodiscard, Opt_init_itable, Opt_noinit_itable,
1224 Opt_max_dir_size_kb,
1227}; 1225};
1228 1226
1229static const match_table_t tokens = { 1227static const match_table_t tokens = {
@@ -1297,6 +1295,7 @@ static const match_table_t tokens = {
1297 {Opt_init_itable, "init_itable=%u"}, 1295 {Opt_init_itable, "init_itable=%u"},
1298 {Opt_init_itable, "init_itable"}, 1296 {Opt_init_itable, "init_itable"},
1299 {Opt_noinit_itable, "noinit_itable"}, 1297 {Opt_noinit_itable, "noinit_itable"},
1298 {Opt_max_dir_size_kb, "max_dir_size_kb=%u"},
1300 {Opt_removed, "check=none"}, /* mount option from ext2/3 */ 1299 {Opt_removed, "check=none"}, /* mount option from ext2/3 */
1301 {Opt_removed, "nocheck"}, /* mount option from ext2/3 */ 1300 {Opt_removed, "nocheck"}, /* mount option from ext2/3 */
1302 {Opt_removed, "reservation"}, /* mount option from ext2/3 */ 1301 {Opt_removed, "reservation"}, /* mount option from ext2/3 */
@@ -1477,6 +1476,7 @@ static const struct mount_opts {
1477 {Opt_jqfmt_vfsold, QFMT_VFS_OLD, MOPT_QFMT}, 1476 {Opt_jqfmt_vfsold, QFMT_VFS_OLD, MOPT_QFMT},
1478 {Opt_jqfmt_vfsv0, QFMT_VFS_V0, MOPT_QFMT}, 1477 {Opt_jqfmt_vfsv0, QFMT_VFS_V0, MOPT_QFMT},
1479 {Opt_jqfmt_vfsv1, QFMT_VFS_V1, MOPT_QFMT}, 1478 {Opt_jqfmt_vfsv1, QFMT_VFS_V1, MOPT_QFMT},
1479 {Opt_max_dir_size_kb, 0, MOPT_GTE0},
1480 {Opt_err, 0, 0} 1480 {Opt_err, 0, 0}
1481}; 1481};
1482 1482
@@ -1592,6 +1592,8 @@ static int handle_mount_opt(struct super_block *sb, char *opt, int token,
1592 if (!args->from) 1592 if (!args->from)
1593 arg = EXT4_DEF_LI_WAIT_MULT; 1593 arg = EXT4_DEF_LI_WAIT_MULT;
1594 sbi->s_li_wait_mult = arg; 1594 sbi->s_li_wait_mult = arg;
1595 } else if (token == Opt_max_dir_size_kb) {
1596 sbi->s_max_dir_size_kb = arg;
1595 } else if (token == Opt_stripe) { 1597 } else if (token == Opt_stripe) {
1596 sbi->s_stripe = arg; 1598 sbi->s_stripe = arg;
1597 } else if (m->flags & MOPT_DATAJ) { 1599 } else if (m->flags & MOPT_DATAJ) {
@@ -1664,7 +1666,7 @@ static int parse_options(char *options, struct super_block *sb,
1664 * Initialize args struct so we know whether arg was 1666 * Initialize args struct so we know whether arg was
1665 * found; some options take optional arguments. 1667 * found; some options take optional arguments.
1666 */ 1668 */
1667 args[0].to = args[0].from = 0; 1669 args[0].to = args[0].from = NULL;
1668 token = match_token(p, tokens, args); 1670 token = match_token(p, tokens, args);
1669 if (handle_mount_opt(sb, p, token, args, journal_devnum, 1671 if (handle_mount_opt(sb, p, token, args, journal_devnum,
1670 journal_ioprio, is_remount) < 0) 1672 journal_ioprio, is_remount) < 0)
@@ -1740,7 +1742,7 @@ static inline void ext4_show_quota_options(struct seq_file *seq,
1740 1742
1741static const char *token2str(int token) 1743static const char *token2str(int token)
1742{ 1744{
1743 static const struct match_token *t; 1745 const struct match_token *t;
1744 1746
1745 for (t = tokens; t->token != Opt_err; t++) 1747 for (t = tokens; t->token != Opt_err; t++)
1746 if (t->token == token && !strchr(t->pattern, '=')) 1748 if (t->token == token && !strchr(t->pattern, '='))
@@ -1823,6 +1825,8 @@ static int _ext4_show_options(struct seq_file *seq, struct super_block *sb,
1823 if (nodefs || (test_opt(sb, INIT_INODE_TABLE) && 1825 if (nodefs || (test_opt(sb, INIT_INODE_TABLE) &&
1824 (sbi->s_li_wait_mult != EXT4_DEF_LI_WAIT_MULT))) 1826 (sbi->s_li_wait_mult != EXT4_DEF_LI_WAIT_MULT)))
1825 SEQ_OPTS_PRINT("init_itable=%u", sbi->s_li_wait_mult); 1827 SEQ_OPTS_PRINT("init_itable=%u", sbi->s_li_wait_mult);
1828 if (nodefs || sbi->s_max_dir_size_kb)
1829 SEQ_OPTS_PRINT("max_dir_size_kb=%u", sbi->s_max_dir_size_kb);
1826 1830
1827 ext4_show_quota_options(seq, sb); 1831 ext4_show_quota_options(seq, sb);
1828 return 0; 1832 return 0;
@@ -1914,15 +1918,45 @@ done:
1914 return res; 1918 return res;
1915} 1919}
1916 1920
1921int ext4_alloc_flex_bg_array(struct super_block *sb, ext4_group_t ngroup)
1922{
1923 struct ext4_sb_info *sbi = EXT4_SB(sb);
1924 struct flex_groups *new_groups;
1925 int size;
1926
1927 if (!sbi->s_log_groups_per_flex)
1928 return 0;
1929
1930 size = ext4_flex_group(sbi, ngroup - 1) + 1;
1931 if (size <= sbi->s_flex_groups_allocated)
1932 return 0;
1933
1934 size = roundup_pow_of_two(size * sizeof(struct flex_groups));
1935 new_groups = ext4_kvzalloc(size, GFP_KERNEL);
1936 if (!new_groups) {
1937 ext4_msg(sb, KERN_ERR, "not enough memory for %d flex groups",
1938 size / (int) sizeof(struct flex_groups));
1939 return -ENOMEM;
1940 }
1941
1942 if (sbi->s_flex_groups) {
1943 memcpy(new_groups, sbi->s_flex_groups,
1944 (sbi->s_flex_groups_allocated *
1945 sizeof(struct flex_groups)));
1946 ext4_kvfree(sbi->s_flex_groups);
1947 }
1948 sbi->s_flex_groups = new_groups;
1949 sbi->s_flex_groups_allocated = size / sizeof(struct flex_groups);
1950 return 0;
1951}
1952
1917static int ext4_fill_flex_info(struct super_block *sb) 1953static int ext4_fill_flex_info(struct super_block *sb)
1918{ 1954{
1919 struct ext4_sb_info *sbi = EXT4_SB(sb); 1955 struct ext4_sb_info *sbi = EXT4_SB(sb);
1920 struct ext4_group_desc *gdp = NULL; 1956 struct ext4_group_desc *gdp = NULL;
1921 ext4_group_t flex_group_count;
1922 ext4_group_t flex_group; 1957 ext4_group_t flex_group;
1923 unsigned int groups_per_flex = 0; 1958 unsigned int groups_per_flex = 0;
1924 size_t size; 1959 int i, err;
1925 int i;
1926 1960
1927 sbi->s_log_groups_per_flex = sbi->s_es->s_log_groups_per_flex; 1961 sbi->s_log_groups_per_flex = sbi->s_es->s_log_groups_per_flex;
1928 if (sbi->s_log_groups_per_flex < 1 || sbi->s_log_groups_per_flex > 31) { 1962 if (sbi->s_log_groups_per_flex < 1 || sbi->s_log_groups_per_flex > 31) {
@@ -1931,17 +1965,9 @@ static int ext4_fill_flex_info(struct super_block *sb)
1931 } 1965 }
1932 groups_per_flex = 1 << sbi->s_log_groups_per_flex; 1966 groups_per_flex = 1 << sbi->s_log_groups_per_flex;
1933 1967
1934 /* We allocate both existing and potentially added groups */ 1968 err = ext4_alloc_flex_bg_array(sb, sbi->s_groups_count);
1935 flex_group_count = ((sbi->s_groups_count + groups_per_flex - 1) + 1969 if (err)
1936 ((le16_to_cpu(sbi->s_es->s_reserved_gdt_blocks) + 1) <<
1937 EXT4_DESC_PER_BLOCK_BITS(sb))) / groups_per_flex;
1938 size = flex_group_count * sizeof(struct flex_groups);
1939 sbi->s_flex_groups = ext4_kvzalloc(size, GFP_KERNEL);
1940 if (sbi->s_flex_groups == NULL) {
1941 ext4_msg(sb, KERN_ERR, "not enough memory for %u flex groups",
1942 flex_group_count);
1943 goto failed; 1970 goto failed;
1944 }
1945 1971
1946 for (i = 0; i < sbi->s_groups_count; i++) { 1972 for (i = 0; i < sbi->s_groups_count; i++) {
1947 gdp = ext4_get_group_desc(sb, i, NULL); 1973 gdp = ext4_get_group_desc(sb, i, NULL);
@@ -2144,10 +2170,12 @@ static void ext4_orphan_cleanup(struct super_block *sb,
2144 } 2170 }
2145 2171
2146 if (EXT4_SB(sb)->s_mount_state & EXT4_ERROR_FS) { 2172 if (EXT4_SB(sb)->s_mount_state & EXT4_ERROR_FS) {
2147 if (es->s_last_orphan) 2173 /* don't clear list on RO mount w/ errors */
2174 if (es->s_last_orphan && !(s_flags & MS_RDONLY)) {
2148 jbd_debug(1, "Errors on filesystem, " 2175 jbd_debug(1, "Errors on filesystem, "
2149 "clearing orphan list.\n"); 2176 "clearing orphan list.\n");
2150 es->s_last_orphan = 0; 2177 es->s_last_orphan = 0;
2178 }
2151 jbd_debug(1, "Skipping orphan recovery on fs with errors.\n"); 2179 jbd_debug(1, "Skipping orphan recovery on fs with errors.\n");
2152 return; 2180 return;
2153 } 2181 }
@@ -2528,6 +2556,7 @@ EXT4_RW_ATTR_SBI_UI(mb_order2_req, s_mb_order2_reqs);
2528EXT4_RW_ATTR_SBI_UI(mb_stream_req, s_mb_stream_request); 2556EXT4_RW_ATTR_SBI_UI(mb_stream_req, s_mb_stream_request);
2529EXT4_RW_ATTR_SBI_UI(mb_group_prealloc, s_mb_group_prealloc); 2557EXT4_RW_ATTR_SBI_UI(mb_group_prealloc, s_mb_group_prealloc);
2530EXT4_RW_ATTR_SBI_UI(max_writeback_mb_bump, s_max_writeback_mb_bump); 2558EXT4_RW_ATTR_SBI_UI(max_writeback_mb_bump, s_max_writeback_mb_bump);
2559EXT4_RW_ATTR_SBI_UI(extent_max_zeroout_kb, s_extent_max_zeroout_kb);
2531EXT4_ATTR(trigger_fs_error, 0200, NULL, trigger_test_error); 2560EXT4_ATTR(trigger_fs_error, 0200, NULL, trigger_test_error);
2532 2561
2533static struct attribute *ext4_attrs[] = { 2562static struct attribute *ext4_attrs[] = {
@@ -2543,6 +2572,7 @@ static struct attribute *ext4_attrs[] = {
2543 ATTR_LIST(mb_stream_req), 2572 ATTR_LIST(mb_stream_req),
2544 ATTR_LIST(mb_group_prealloc), 2573 ATTR_LIST(mb_group_prealloc),
2545 ATTR_LIST(max_writeback_mb_bump), 2574 ATTR_LIST(max_writeback_mb_bump),
2575 ATTR_LIST(extent_max_zeroout_kb),
2546 ATTR_LIST(trigger_fs_error), 2576 ATTR_LIST(trigger_fs_error),
2547 NULL, 2577 NULL,
2548}; 2578};
@@ -2550,10 +2580,12 @@ static struct attribute *ext4_attrs[] = {
2550/* Features this copy of ext4 supports */ 2580/* Features this copy of ext4 supports */
2551EXT4_INFO_ATTR(lazy_itable_init); 2581EXT4_INFO_ATTR(lazy_itable_init);
2552EXT4_INFO_ATTR(batched_discard); 2582EXT4_INFO_ATTR(batched_discard);
2583EXT4_INFO_ATTR(meta_bg_resize);
2553 2584
2554static struct attribute *ext4_feat_attrs[] = { 2585static struct attribute *ext4_feat_attrs[] = {
2555 ATTR_LIST(lazy_itable_init), 2586 ATTR_LIST(lazy_itable_init),
2556 ATTR_LIST(batched_discard), 2587 ATTR_LIST(batched_discard),
2588 ATTR_LIST(meta_bg_resize),
2557 NULL, 2589 NULL,
2558}; 2590};
2559 2591
@@ -3374,7 +3406,7 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent)
3374 * enable delayed allocation by default 3406 * enable delayed allocation by default
3375 * Use -o nodelalloc to turn it off 3407 * Use -o nodelalloc to turn it off
3376 */ 3408 */
3377 if (!IS_EXT3_SB(sb) && 3409 if (!IS_EXT3_SB(sb) && !IS_EXT2_SB(sb) &&
3378 ((def_mount_opts & EXT4_DEFM_NODELALLOC) == 0)) 3410 ((def_mount_opts & EXT4_DEFM_NODELALLOC) == 0))
3379 set_opt(sb, DELALLOC); 3411 set_opt(sb, DELALLOC);
3380 3412
@@ -3743,6 +3775,7 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent)
3743 3775
3744 sbi->s_stripe = ext4_get_stripe_size(sbi); 3776 sbi->s_stripe = ext4_get_stripe_size(sbi);
3745 sbi->s_max_writeback_mb_bump = 128; 3777 sbi->s_max_writeback_mb_bump = 128;
3778 sbi->s_extent_max_zeroout_kb = 32;
3746 3779
3747 /* 3780 /*
3748 * set up enough so that it can read an inode 3781 * set up enough so that it can read an inode
@@ -4519,11 +4552,9 @@ static int ext4_unfreeze(struct super_block *sb)
4519 if (sb->s_flags & MS_RDONLY) 4552 if (sb->s_flags & MS_RDONLY)
4520 return 0; 4553 return 0;
4521 4554
4522 lock_super(sb);
4523 /* Reset the needs_recovery flag before the fs is unlocked. */ 4555 /* Reset the needs_recovery flag before the fs is unlocked. */
4524 EXT4_SET_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_RECOVER); 4556 EXT4_SET_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_RECOVER);
4525 ext4_commit_super(sb, 1); 4557 ext4_commit_super(sb, 1);
4526 unlock_super(sb);
4527 return 0; 4558 return 0;
4528} 4559}
4529 4560
@@ -4559,7 +4590,6 @@ static int ext4_remount(struct super_block *sb, int *flags, char *data)
4559 char *orig_data = kstrdup(data, GFP_KERNEL); 4590 char *orig_data = kstrdup(data, GFP_KERNEL);
4560 4591
4561 /* Store the original options */ 4592 /* Store the original options */
4562 lock_super(sb);
4563 old_sb_flags = sb->s_flags; 4593 old_sb_flags = sb->s_flags;
4564 old_opts.s_mount_opt = sbi->s_mount_opt; 4594 old_opts.s_mount_opt = sbi->s_mount_opt;
4565 old_opts.s_mount_opt2 = sbi->s_mount_opt2; 4595 old_opts.s_mount_opt2 = sbi->s_mount_opt2;
@@ -4701,7 +4731,6 @@ static int ext4_remount(struct super_block *sb, int *flags, char *data)
4701 if (sbi->s_journal == NULL) 4731 if (sbi->s_journal == NULL)
4702 ext4_commit_super(sb, 1); 4732 ext4_commit_super(sb, 1);
4703 4733
4704 unlock_super(sb);
4705#ifdef CONFIG_QUOTA 4734#ifdef CONFIG_QUOTA
4706 /* Release old quota file names */ 4735 /* Release old quota file names */
4707 for (i = 0; i < MAXQUOTAS; i++) 4736 for (i = 0; i < MAXQUOTAS; i++)
@@ -4714,10 +4743,8 @@ static int ext4_remount(struct super_block *sb, int *flags, char *data)
4714 else if (EXT4_HAS_RO_COMPAT_FEATURE(sb, 4743 else if (EXT4_HAS_RO_COMPAT_FEATURE(sb,
4715 EXT4_FEATURE_RO_COMPAT_QUOTA)) { 4744 EXT4_FEATURE_RO_COMPAT_QUOTA)) {
4716 err = ext4_enable_quotas(sb); 4745 err = ext4_enable_quotas(sb);
4717 if (err) { 4746 if (err)
4718 lock_super(sb);
4719 goto restore_opts; 4747 goto restore_opts;
4720 }
4721 } 4748 }
4722 } 4749 }
4723#endif 4750#endif
@@ -4744,7 +4771,6 @@ restore_opts:
4744 sbi->s_qf_names[i] = old_opts.s_qf_names[i]; 4771 sbi->s_qf_names[i] = old_opts.s_qf_names[i];
4745 } 4772 }
4746#endif 4773#endif
4747 unlock_super(sb);
4748 kfree(orig_data); 4774 kfree(orig_data);
4749 return err; 4775 return err;
4750} 4776}
@@ -5269,8 +5295,10 @@ static int __init ext4_init_fs(void)
5269 if (err) 5295 if (err)
5270 goto out6; 5296 goto out6;
5271 ext4_kset = kset_create_and_add("ext4", NULL, fs_kobj); 5297 ext4_kset = kset_create_and_add("ext4", NULL, fs_kobj);
5272 if (!ext4_kset) 5298 if (!ext4_kset) {
5299 err = -ENOMEM;
5273 goto out5; 5300 goto out5;
5301 }
5274 ext4_proc_root = proc_mkdir("fs/ext4", NULL); 5302 ext4_proc_root = proc_mkdir("fs/ext4", NULL);
5275 5303
5276 err = ext4_init_feat_adverts(); 5304 err = ext4_init_feat_adverts();