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.c889
1 files changed, 468 insertions, 421 deletions
diff --git a/fs/ext4/super.c b/fs/ext4/super.c
index 2958f4e6f222..8f4f079e6b9a 100644
--- a/fs/ext4/super.c
+++ b/fs/ext4/super.c
@@ -20,6 +20,7 @@
20#include <linux/string.h> 20#include <linux/string.h>
21#include <linux/fs.h> 21#include <linux/fs.h>
22#include <linux/time.h> 22#include <linux/time.h>
23#include <linux/vmalloc.h>
23#include <linux/jbd2.h> 24#include <linux/jbd2.h>
24#include <linux/slab.h> 25#include <linux/slab.h>
25#include <linux/init.h> 26#include <linux/init.h>
@@ -36,7 +37,6 @@
36#include <linux/seq_file.h> 37#include <linux/seq_file.h>
37#include <linux/proc_fs.h> 38#include <linux/proc_fs.h>
38#include <linux/ctype.h> 39#include <linux/ctype.h>
39#include <linux/marker.h>
40#include <linux/log2.h> 40#include <linux/log2.h>
41#include <linux/crc16.h> 41#include <linux/crc16.h>
42#include <asm/uaccess.h> 42#include <asm/uaccess.h>
@@ -45,16 +45,23 @@
45#include "ext4_jbd2.h" 45#include "ext4_jbd2.h"
46#include "xattr.h" 46#include "xattr.h"
47#include "acl.h" 47#include "acl.h"
48#include "namei.h" 48
49#include "group.h" 49#define CREATE_TRACE_POINTS
50#include <trace/events/ext4.h>
51
52static int default_mb_history_length = 1000;
53
54module_param_named(default_mb_history_length, default_mb_history_length,
55 int, 0644);
56MODULE_PARM_DESC(default_mb_history_length,
57 "Default number of entries saved for mb_history");
50 58
51struct proc_dir_entry *ext4_proc_root; 59struct proc_dir_entry *ext4_proc_root;
52static struct kset *ext4_kset; 60static struct kset *ext4_kset;
53 61
54static int ext4_load_journal(struct super_block *, struct ext4_super_block *, 62static int ext4_load_journal(struct super_block *, struct ext4_super_block *,
55 unsigned long journal_devnum); 63 unsigned long journal_devnum);
56static int ext4_commit_super(struct super_block *sb, 64static int ext4_commit_super(struct super_block *sb, int sync);
57 struct ext4_super_block *es, int sync);
58static void ext4_mark_recovery_complete(struct super_block *sb, 65static void ext4_mark_recovery_complete(struct super_block *sb,
59 struct ext4_super_block *es); 66 struct ext4_super_block *es);
60static void ext4_clear_journal_err(struct super_block *sb, 67static void ext4_clear_journal_err(struct super_block *sb,
@@ -74,7 +81,7 @@ ext4_fsblk_t ext4_block_bitmap(struct super_block *sb,
74{ 81{
75 return le32_to_cpu(bg->bg_block_bitmap_lo) | 82 return le32_to_cpu(bg->bg_block_bitmap_lo) |
76 (EXT4_DESC_SIZE(sb) >= EXT4_MIN_DESC_SIZE_64BIT ? 83 (EXT4_DESC_SIZE(sb) >= EXT4_MIN_DESC_SIZE_64BIT ?
77 (ext4_fsblk_t)le32_to_cpu(bg->bg_block_bitmap_hi) << 32 : 0); 84 (ext4_fsblk_t)le32_to_cpu(bg->bg_block_bitmap_hi) << 32 : 0);
78} 85}
79 86
80ext4_fsblk_t ext4_inode_bitmap(struct super_block *sb, 87ext4_fsblk_t ext4_inode_bitmap(struct super_block *sb,
@@ -82,7 +89,7 @@ ext4_fsblk_t ext4_inode_bitmap(struct super_block *sb,
82{ 89{
83 return le32_to_cpu(bg->bg_inode_bitmap_lo) | 90 return le32_to_cpu(bg->bg_inode_bitmap_lo) |
84 (EXT4_DESC_SIZE(sb) >= EXT4_MIN_DESC_SIZE_64BIT ? 91 (EXT4_DESC_SIZE(sb) >= EXT4_MIN_DESC_SIZE_64BIT ?
85 (ext4_fsblk_t)le32_to_cpu(bg->bg_inode_bitmap_hi) << 32 : 0); 92 (ext4_fsblk_t)le32_to_cpu(bg->bg_inode_bitmap_hi) << 32 : 0);
86} 93}
87 94
88ext4_fsblk_t ext4_inode_table(struct super_block *sb, 95ext4_fsblk_t ext4_inode_table(struct super_block *sb,
@@ -90,7 +97,7 @@ ext4_fsblk_t ext4_inode_table(struct super_block *sb,
90{ 97{
91 return le32_to_cpu(bg->bg_inode_table_lo) | 98 return le32_to_cpu(bg->bg_inode_table_lo) |
92 (EXT4_DESC_SIZE(sb) >= EXT4_MIN_DESC_SIZE_64BIT ? 99 (EXT4_DESC_SIZE(sb) >= EXT4_MIN_DESC_SIZE_64BIT ?
93 (ext4_fsblk_t)le32_to_cpu(bg->bg_inode_table_hi) << 32 : 0); 100 (ext4_fsblk_t)le32_to_cpu(bg->bg_inode_table_hi) << 32 : 0);
94} 101}
95 102
96__u32 ext4_free_blks_count(struct super_block *sb, 103__u32 ext4_free_blks_count(struct super_block *sb,
@@ -98,7 +105,7 @@ __u32 ext4_free_blks_count(struct super_block *sb,
98{ 105{
99 return le16_to_cpu(bg->bg_free_blocks_count_lo) | 106 return le16_to_cpu(bg->bg_free_blocks_count_lo) |
100 (EXT4_DESC_SIZE(sb) >= EXT4_MIN_DESC_SIZE_64BIT ? 107 (EXT4_DESC_SIZE(sb) >= EXT4_MIN_DESC_SIZE_64BIT ?
101 (__u32)le16_to_cpu(bg->bg_free_blocks_count_hi) << 16 : 0); 108 (__u32)le16_to_cpu(bg->bg_free_blocks_count_hi) << 16 : 0);
102} 109}
103 110
104__u32 ext4_free_inodes_count(struct super_block *sb, 111__u32 ext4_free_inodes_count(struct super_block *sb,
@@ -106,7 +113,7 @@ __u32 ext4_free_inodes_count(struct super_block *sb,
106{ 113{
107 return le16_to_cpu(bg->bg_free_inodes_count_lo) | 114 return le16_to_cpu(bg->bg_free_inodes_count_lo) |
108 (EXT4_DESC_SIZE(sb) >= EXT4_MIN_DESC_SIZE_64BIT ? 115 (EXT4_DESC_SIZE(sb) >= EXT4_MIN_DESC_SIZE_64BIT ?
109 (__u32)le16_to_cpu(bg->bg_free_inodes_count_hi) << 16 : 0); 116 (__u32)le16_to_cpu(bg->bg_free_inodes_count_hi) << 16 : 0);
110} 117}
111 118
112__u32 ext4_used_dirs_count(struct super_block *sb, 119__u32 ext4_used_dirs_count(struct super_block *sb,
@@ -114,7 +121,7 @@ __u32 ext4_used_dirs_count(struct super_block *sb,
114{ 121{
115 return le16_to_cpu(bg->bg_used_dirs_count_lo) | 122 return le16_to_cpu(bg->bg_used_dirs_count_lo) |
116 (EXT4_DESC_SIZE(sb) >= EXT4_MIN_DESC_SIZE_64BIT ? 123 (EXT4_DESC_SIZE(sb) >= EXT4_MIN_DESC_SIZE_64BIT ?
117 (__u32)le16_to_cpu(bg->bg_used_dirs_count_hi) << 16 : 0); 124 (__u32)le16_to_cpu(bg->bg_used_dirs_count_hi) << 16 : 0);
118} 125}
119 126
120__u32 ext4_itable_unused_count(struct super_block *sb, 127__u32 ext4_itable_unused_count(struct super_block *sb,
@@ -122,7 +129,7 @@ __u32 ext4_itable_unused_count(struct super_block *sb,
122{ 129{
123 return le16_to_cpu(bg->bg_itable_unused_lo) | 130 return le16_to_cpu(bg->bg_itable_unused_lo) |
124 (EXT4_DESC_SIZE(sb) >= EXT4_MIN_DESC_SIZE_64BIT ? 131 (EXT4_DESC_SIZE(sb) >= EXT4_MIN_DESC_SIZE_64BIT ?
125 (__u32)le16_to_cpu(bg->bg_itable_unused_hi) << 16 : 0); 132 (__u32)le16_to_cpu(bg->bg_itable_unused_hi) << 16 : 0);
126} 133}
127 134
128void ext4_block_bitmap_set(struct super_block *sb, 135void ext4_block_bitmap_set(struct super_block *sb,
@@ -202,8 +209,7 @@ handle_t *ext4_journal_start_sb(struct super_block *sb, int nblocks)
202 journal = EXT4_SB(sb)->s_journal; 209 journal = EXT4_SB(sb)->s_journal;
203 if (journal) { 210 if (journal) {
204 if (is_journal_aborted(journal)) { 211 if (is_journal_aborted(journal)) {
205 ext4_abort(sb, __func__, 212 ext4_abort(sb, __func__, "Detected aborted journal");
206 "Detected aborted journal");
207 return ERR_PTR(-EROFS); 213 return ERR_PTR(-EROFS);
208 } 214 }
209 return jbd2_journal_start(journal, nblocks); 215 return jbd2_journal_start(journal, nblocks);
@@ -297,15 +303,15 @@ static void ext4_handle_error(struct super_block *sb)
297 if (!test_opt(sb, ERRORS_CONT)) { 303 if (!test_opt(sb, ERRORS_CONT)) {
298 journal_t *journal = EXT4_SB(sb)->s_journal; 304 journal_t *journal = EXT4_SB(sb)->s_journal;
299 305
300 EXT4_SB(sb)->s_mount_opt |= EXT4_MOUNT_ABORT; 306 EXT4_SB(sb)->s_mount_flags |= EXT4_MF_FS_ABORTED;
301 if (journal) 307 if (journal)
302 jbd2_journal_abort(journal, -EIO); 308 jbd2_journal_abort(journal, -EIO);
303 } 309 }
304 if (test_opt(sb, ERRORS_RO)) { 310 if (test_opt(sb, ERRORS_RO)) {
305 printk(KERN_CRIT "Remounting filesystem read-only\n"); 311 ext4_msg(sb, KERN_CRIT, "Remounting filesystem read-only");
306 sb->s_flags |= MS_RDONLY; 312 sb->s_flags |= MS_RDONLY;
307 } 313 }
308 ext4_commit_super(sb, es, 1); 314 ext4_commit_super(sb, 1);
309 if (test_opt(sb, ERRORS_PANIC)) 315 if (test_opt(sb, ERRORS_PANIC))
310 panic("EXT4-fs (device %s): panic forced after error\n", 316 panic("EXT4-fs (device %s): panic forced after error\n",
311 sb->s_id); 317 sb->s_id);
@@ -395,8 +401,6 @@ void ext4_abort(struct super_block *sb, const char *function,
395{ 401{
396 va_list args; 402 va_list args;
397 403
398 printk(KERN_CRIT "ext4_abort called.\n");
399
400 va_start(args, fmt); 404 va_start(args, fmt);
401 printk(KERN_CRIT "EXT4-fs error (device %s): %s: ", sb->s_id, function); 405 printk(KERN_CRIT "EXT4-fs error (device %s): %s: ", sb->s_id, function);
402 vprintk(fmt, args); 406 vprintk(fmt, args);
@@ -409,14 +413,26 @@ void ext4_abort(struct super_block *sb, const char *function,
409 if (sb->s_flags & MS_RDONLY) 413 if (sb->s_flags & MS_RDONLY)
410 return; 414 return;
411 415
412 printk(KERN_CRIT "Remounting filesystem read-only\n"); 416 ext4_msg(sb, KERN_CRIT, "Remounting filesystem read-only");
413 EXT4_SB(sb)->s_mount_state |= EXT4_ERROR_FS; 417 EXT4_SB(sb)->s_mount_state |= EXT4_ERROR_FS;
414 sb->s_flags |= MS_RDONLY; 418 sb->s_flags |= MS_RDONLY;
415 EXT4_SB(sb)->s_mount_opt |= EXT4_MOUNT_ABORT; 419 EXT4_SB(sb)->s_mount_flags |= EXT4_MF_FS_ABORTED;
416 if (EXT4_SB(sb)->s_journal) 420 if (EXT4_SB(sb)->s_journal)
417 jbd2_journal_abort(EXT4_SB(sb)->s_journal, -EIO); 421 jbd2_journal_abort(EXT4_SB(sb)->s_journal, -EIO);
418} 422}
419 423
424void ext4_msg (struct super_block * sb, const char *prefix,
425 const char *fmt, ...)
426{
427 va_list args;
428
429 va_start(args, fmt);
430 printk("%sEXT4-fs (%s): ", prefix, sb->s_id);
431 vprintk(fmt, args);
432 printk("\n");
433 va_end(args);
434}
435
420void ext4_warning(struct super_block *sb, const char *function, 436void ext4_warning(struct super_block *sb, const char *function,
421 const char *fmt, ...) 437 const char *fmt, ...)
422{ 438{
@@ -431,7 +447,7 @@ void ext4_warning(struct super_block *sb, const char *function,
431} 447}
432 448
433void ext4_grp_locked_error(struct super_block *sb, ext4_group_t grp, 449void ext4_grp_locked_error(struct super_block *sb, ext4_group_t grp,
434 const char *function, const char *fmt, ...) 450 const char *function, const char *fmt, ...)
435__releases(bitlock) 451__releases(bitlock)
436__acquires(bitlock) 452__acquires(bitlock)
437{ 453{
@@ -447,7 +463,7 @@ __acquires(bitlock)
447 if (test_opt(sb, ERRORS_CONT)) { 463 if (test_opt(sb, ERRORS_CONT)) {
448 EXT4_SB(sb)->s_mount_state |= EXT4_ERROR_FS; 464 EXT4_SB(sb)->s_mount_state |= EXT4_ERROR_FS;
449 es->s_state |= cpu_to_le16(EXT4_ERROR_FS); 465 es->s_state |= cpu_to_le16(EXT4_ERROR_FS);
450 ext4_commit_super(sb, es, 0); 466 ext4_commit_super(sb, 0);
451 return; 467 return;
452 } 468 }
453 ext4_unlock_group(sb, grp); 469 ext4_unlock_group(sb, grp);
@@ -467,7 +483,6 @@ __acquires(bitlock)
467 return; 483 return;
468} 484}
469 485
470
471void ext4_update_dynamic_rev(struct super_block *sb) 486void ext4_update_dynamic_rev(struct super_block *sb)
472{ 487{
473 struct ext4_super_block *es = EXT4_SB(sb)->s_es; 488 struct ext4_super_block *es = EXT4_SB(sb)->s_es;
@@ -496,7 +511,7 @@ void ext4_update_dynamic_rev(struct super_block *sb)
496/* 511/*
497 * Open the external journal device 512 * Open the external journal device
498 */ 513 */
499static struct block_device *ext4_blkdev_get(dev_t dev) 514static struct block_device *ext4_blkdev_get(dev_t dev, struct super_block *sb)
500{ 515{
501 struct block_device *bdev; 516 struct block_device *bdev;
502 char b[BDEVNAME_SIZE]; 517 char b[BDEVNAME_SIZE];
@@ -507,7 +522,7 @@ static struct block_device *ext4_blkdev_get(dev_t dev)
507 return bdev; 522 return bdev;
508 523
509fail: 524fail:
510 printk(KERN_ERR "EXT4-fs: failed to open journal device %s: %ld\n", 525 ext4_msg(sb, KERN_ERR, "failed to open journal device %s: %ld",
511 __bdevname(dev, b), PTR_ERR(bdev)); 526 __bdevname(dev, b), PTR_ERR(bdev));
512 return NULL; 527 return NULL;
513} 528}
@@ -543,8 +558,8 @@ static void dump_orphan_list(struct super_block *sb, struct ext4_sb_info *sbi)
543{ 558{
544 struct list_head *l; 559 struct list_head *l;
545 560
546 printk(KERN_ERR "sb orphan head is %d\n", 561 ext4_msg(sb, KERN_ERR, "sb orphan head is %d",
547 le32_to_cpu(sbi->s_es->s_last_orphan)); 562 le32_to_cpu(sbi->s_es->s_last_orphan));
548 563
549 printk(KERN_ERR "sb_info orphan list:\n"); 564 printk(KERN_ERR "sb_info orphan list:\n");
550 list_for_each(l, &sbi->s_orphan) { 565 list_for_each(l, &sbi->s_orphan) {
@@ -563,6 +578,12 @@ static void ext4_put_super(struct super_block *sb)
563 struct ext4_super_block *es = sbi->s_es; 578 struct ext4_super_block *es = sbi->s_es;
564 int i, err; 579 int i, err;
565 580
581 lock_super(sb);
582 lock_kernel();
583 if (sb->s_dirt)
584 ext4_commit_super(sb, 1);
585
586 ext4_release_system_zone(sb);
566 ext4_mb_release(sb); 587 ext4_mb_release(sb);
567 ext4_ext_release(sb); 588 ext4_ext_release(sb);
568 ext4_xattr_put_super(sb); 589 ext4_xattr_put_super(sb);
@@ -576,7 +597,7 @@ static void ext4_put_super(struct super_block *sb)
576 if (!(sb->s_flags & MS_RDONLY)) { 597 if (!(sb->s_flags & MS_RDONLY)) {
577 EXT4_CLEAR_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_RECOVER); 598 EXT4_CLEAR_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_RECOVER);
578 es->s_state = cpu_to_le16(sbi->s_mount_state); 599 es->s_state = cpu_to_le16(sbi->s_mount_state);
579 ext4_commit_super(sb, es, 1); 600 ext4_commit_super(sb, 1);
580 } 601 }
581 if (sbi->s_proc) { 602 if (sbi->s_proc) {
582 remove_proc_entry(sb->s_id, ext4_proc_root); 603 remove_proc_entry(sb->s_id, ext4_proc_root);
@@ -586,7 +607,10 @@ static void ext4_put_super(struct super_block *sb)
586 for (i = 0; i < sbi->s_gdb_count; i++) 607 for (i = 0; i < sbi->s_gdb_count; i++)
587 brelse(sbi->s_group_desc[i]); 608 brelse(sbi->s_group_desc[i]);
588 kfree(sbi->s_group_desc); 609 kfree(sbi->s_group_desc);
589 kfree(sbi->s_flex_groups); 610 if (is_vmalloc_addr(sbi->s_flex_groups))
611 vfree(sbi->s_flex_groups);
612 else
613 kfree(sbi->s_flex_groups);
590 percpu_counter_destroy(&sbi->s_freeblocks_counter); 614 percpu_counter_destroy(&sbi->s_freeblocks_counter);
591 percpu_counter_destroy(&sbi->s_freeinodes_counter); 615 percpu_counter_destroy(&sbi->s_freeinodes_counter);
592 percpu_counter_destroy(&sbi->s_dirs_counter); 616 percpu_counter_destroy(&sbi->s_dirs_counter);
@@ -625,11 +649,8 @@ static void ext4_put_super(struct super_block *sb)
625 unlock_super(sb); 649 unlock_super(sb);
626 kobject_put(&sbi->s_kobj); 650 kobject_put(&sbi->s_kobj);
627 wait_for_completion(&sbi->s_kobj_unregister); 651 wait_for_completion(&sbi->s_kobj_unregister);
628 lock_super(sb);
629 lock_kernel();
630 kfree(sbi->s_blockgroup_lock); 652 kfree(sbi->s_blockgroup_lock);
631 kfree(sbi); 653 kfree(sbi);
632 return;
633} 654}
634 655
635static struct kmem_cache *ext4_inode_cachep; 656static struct kmem_cache *ext4_inode_cachep;
@@ -644,10 +665,7 @@ static struct inode *ext4_alloc_inode(struct super_block *sb)
644 ei = kmem_cache_alloc(ext4_inode_cachep, GFP_NOFS); 665 ei = kmem_cache_alloc(ext4_inode_cachep, GFP_NOFS);
645 if (!ei) 666 if (!ei)
646 return NULL; 667 return NULL;
647#ifdef CONFIG_EXT4_FS_POSIX_ACL 668
648 ei->i_acl = EXT4_ACL_NOT_CACHED;
649 ei->i_default_acl = EXT4_ACL_NOT_CACHED;
650#endif
651 ei->vfs_inode.i_version = 1; 669 ei->vfs_inode.i_version = 1;
652 ei->vfs_inode.i_data.writeback_index = 0; 670 ei->vfs_inode.i_data.writeback_index = 0;
653 memset(&ei->i_cached_extent, 0, sizeof(struct ext4_ext_cache)); 671 memset(&ei->i_cached_extent, 0, sizeof(struct ext4_ext_cache));
@@ -664,14 +682,16 @@ static struct inode *ext4_alloc_inode(struct super_block *sb)
664 ei->i_allocated_meta_blocks = 0; 682 ei->i_allocated_meta_blocks = 0;
665 ei->i_delalloc_reserved_flag = 0; 683 ei->i_delalloc_reserved_flag = 0;
666 spin_lock_init(&(ei->i_block_reservation_lock)); 684 spin_lock_init(&(ei->i_block_reservation_lock));
685
667 return &ei->vfs_inode; 686 return &ei->vfs_inode;
668} 687}
669 688
670static void ext4_destroy_inode(struct inode *inode) 689static void ext4_destroy_inode(struct inode *inode)
671{ 690{
672 if (!list_empty(&(EXT4_I(inode)->i_orphan))) { 691 if (!list_empty(&(EXT4_I(inode)->i_orphan))) {
673 printk("EXT4 Inode %p: orphan list check failed!\n", 692 ext4_msg(inode->i_sb, KERN_ERR,
674 EXT4_I(inode)); 693 "Inode %lu (%p): orphan list check failed!",
694 inode->i_ino, EXT4_I(inode));
675 print_hex_dump(KERN_INFO, "", DUMP_PREFIX_ADDRESS, 16, 4, 695 print_hex_dump(KERN_INFO, "", DUMP_PREFIX_ADDRESS, 16, 4,
676 EXT4_I(inode), sizeof(struct ext4_inode_info), 696 EXT4_I(inode), sizeof(struct ext4_inode_info),
677 true); 697 true);
@@ -711,18 +731,6 @@ static void destroy_inodecache(void)
711 731
712static void ext4_clear_inode(struct inode *inode) 732static void ext4_clear_inode(struct inode *inode)
713{ 733{
714#ifdef CONFIG_EXT4_FS_POSIX_ACL
715 if (EXT4_I(inode)->i_acl &&
716 EXT4_I(inode)->i_acl != EXT4_ACL_NOT_CACHED) {
717 posix_acl_release(EXT4_I(inode)->i_acl);
718 EXT4_I(inode)->i_acl = EXT4_ACL_NOT_CACHED;
719 }
720 if (EXT4_I(inode)->i_default_acl &&
721 EXT4_I(inode)->i_default_acl != EXT4_ACL_NOT_CACHED) {
722 posix_acl_release(EXT4_I(inode)->i_default_acl);
723 EXT4_I(inode)->i_default_acl = EXT4_ACL_NOT_CACHED;
724 }
725#endif
726 ext4_discard_preallocations(inode); 734 ext4_discard_preallocations(inode);
727 if (EXT4_JOURNAL(inode)) 735 if (EXT4_JOURNAL(inode))
728 jbd2_journal_release_jbd_inode(EXT4_SB(inode->i_sb)->s_journal, 736 jbd2_journal_release_jbd_inode(EXT4_SB(inode->i_sb)->s_journal,
@@ -870,12 +878,12 @@ static int ext4_show_options(struct seq_file *seq, struct vfsmount *vfs)
870 seq_puts(seq, ",noauto_da_alloc"); 878 seq_puts(seq, ",noauto_da_alloc");
871 879
872 ext4_show_quota_options(seq, sb); 880 ext4_show_quota_options(seq, sb);
881
873 return 0; 882 return 0;
874} 883}
875 884
876
877static struct inode *ext4_nfs_get_inode(struct super_block *sb, 885static struct inode *ext4_nfs_get_inode(struct super_block *sb,
878 u64 ino, u32 generation) 886 u64 ino, u32 generation)
879{ 887{
880 struct inode *inode; 888 struct inode *inode;
881 889
@@ -904,14 +912,14 @@ static struct inode *ext4_nfs_get_inode(struct super_block *sb,
904} 912}
905 913
906static struct dentry *ext4_fh_to_dentry(struct super_block *sb, struct fid *fid, 914static struct dentry *ext4_fh_to_dentry(struct super_block *sb, struct fid *fid,
907 int fh_len, int fh_type) 915 int fh_len, int fh_type)
908{ 916{
909 return generic_fh_to_dentry(sb, fid, fh_len, fh_type, 917 return generic_fh_to_dentry(sb, fid, fh_len, fh_type,
910 ext4_nfs_get_inode); 918 ext4_nfs_get_inode);
911} 919}
912 920
913static struct dentry *ext4_fh_to_parent(struct super_block *sb, struct fid *fid, 921static struct dentry *ext4_fh_to_parent(struct super_block *sb, struct fid *fid,
914 int fh_len, int fh_type) 922 int fh_len, int fh_type)
915{ 923{
916 return generic_fh_to_parent(sb, fid, fh_len, fh_type, 924 return generic_fh_to_parent(sb, fid, fh_len, fh_type,
917 ext4_nfs_get_inode); 925 ext4_nfs_get_inode);
@@ -923,7 +931,8 @@ static struct dentry *ext4_fh_to_parent(struct super_block *sb, struct fid *fid,
923 * which would prevent try_to_free_buffers() from freeing them, we must use 931 * which would prevent try_to_free_buffers() from freeing them, we must use
924 * jbd2 layer's try_to_free_buffers() function to release them. 932 * jbd2 layer's try_to_free_buffers() function to release them.
925 */ 933 */
926static int bdev_try_to_free_page(struct super_block *sb, struct page *page, gfp_t wait) 934static int bdev_try_to_free_page(struct super_block *sb, struct page *page,
935 gfp_t wait)
927{ 936{
928 journal_t *journal = EXT4_SB(sb)->s_journal; 937 journal_t *journal = EXT4_SB(sb)->s_journal;
929 938
@@ -992,7 +1001,6 @@ static const struct super_operations ext4_sops = {
992 .dirty_inode = ext4_dirty_inode, 1001 .dirty_inode = ext4_dirty_inode,
993 .delete_inode = ext4_delete_inode, 1002 .delete_inode = ext4_delete_inode,
994 .put_super = ext4_put_super, 1003 .put_super = ext4_put_super,
995 .write_super = ext4_write_super,
996 .sync_fs = ext4_sync_fs, 1004 .sync_fs = ext4_sync_fs,
997 .freeze_fs = ext4_freeze, 1005 .freeze_fs = ext4_freeze,
998 .unfreeze_fs = ext4_unfreeze, 1006 .unfreeze_fs = ext4_unfreeze,
@@ -1007,6 +1015,25 @@ static const struct super_operations ext4_sops = {
1007 .bdev_try_to_free_page = bdev_try_to_free_page, 1015 .bdev_try_to_free_page = bdev_try_to_free_page,
1008}; 1016};
1009 1017
1018static const struct super_operations ext4_nojournal_sops = {
1019 .alloc_inode = ext4_alloc_inode,
1020 .destroy_inode = ext4_destroy_inode,
1021 .write_inode = ext4_write_inode,
1022 .dirty_inode = ext4_dirty_inode,
1023 .delete_inode = ext4_delete_inode,
1024 .write_super = ext4_write_super,
1025 .put_super = ext4_put_super,
1026 .statfs = ext4_statfs,
1027 .remount_fs = ext4_remount,
1028 .clear_inode = ext4_clear_inode,
1029 .show_options = ext4_show_options,
1030#ifdef CONFIG_QUOTA
1031 .quota_read = ext4_quota_read,
1032 .quota_write = ext4_quota_write,
1033#endif
1034 .bdev_try_to_free_page = bdev_try_to_free_page,
1035};
1036
1010static const struct export_operations ext4_export_ops = { 1037static const struct export_operations ext4_export_ops = {
1011 .fh_to_dentry = ext4_fh_to_dentry, 1038 .fh_to_dentry = ext4_fh_to_dentry,
1012 .fh_to_parent = ext4_fh_to_parent, 1039 .fh_to_parent = ext4_fh_to_parent,
@@ -1023,12 +1050,13 @@ enum {
1023 Opt_journal_update, Opt_journal_dev, 1050 Opt_journal_update, Opt_journal_dev,
1024 Opt_journal_checksum, Opt_journal_async_commit, 1051 Opt_journal_checksum, Opt_journal_async_commit,
1025 Opt_abort, Opt_data_journal, Opt_data_ordered, Opt_data_writeback, 1052 Opt_abort, Opt_data_journal, Opt_data_ordered, Opt_data_writeback,
1026 Opt_data_err_abort, Opt_data_err_ignore, 1053 Opt_data_err_abort, Opt_data_err_ignore, Opt_mb_history_length,
1027 Opt_usrjquota, Opt_grpjquota, Opt_offusrjquota, Opt_offgrpjquota, 1054 Opt_usrjquota, Opt_grpjquota, Opt_offusrjquota, Opt_offgrpjquota,
1028 Opt_jqfmt_vfsold, Opt_jqfmt_vfsv0, Opt_quota, Opt_noquota, 1055 Opt_jqfmt_vfsold, Opt_jqfmt_vfsv0, Opt_quota, Opt_noquota,
1029 Opt_ignore, Opt_barrier, Opt_nobarrier, Opt_err, Opt_resize, 1056 Opt_ignore, Opt_barrier, Opt_nobarrier, Opt_err, Opt_resize,
1030 Opt_usrquota, Opt_grpquota, Opt_i_version, 1057 Opt_usrquota, Opt_grpquota, Opt_i_version,
1031 Opt_stripe, Opt_delalloc, Opt_nodelalloc, 1058 Opt_stripe, Opt_delalloc, Opt_nodelalloc,
1059 Opt_block_validity, Opt_noblock_validity,
1032 Opt_inode_readahead_blks, Opt_journal_ioprio 1060 Opt_inode_readahead_blks, Opt_journal_ioprio
1033}; 1061};
1034 1062
@@ -1069,6 +1097,7 @@ static const match_table_t tokens = {
1069 {Opt_data_writeback, "data=writeback"}, 1097 {Opt_data_writeback, "data=writeback"},
1070 {Opt_data_err_abort, "data_err=abort"}, 1098 {Opt_data_err_abort, "data_err=abort"},
1071 {Opt_data_err_ignore, "data_err=ignore"}, 1099 {Opt_data_err_ignore, "data_err=ignore"},
1100 {Opt_mb_history_length, "mb_history_length=%u"},
1072 {Opt_offusrjquota, "usrjquota="}, 1101 {Opt_offusrjquota, "usrjquota="},
1073 {Opt_usrjquota, "usrjquota=%s"}, 1102 {Opt_usrjquota, "usrjquota=%s"},
1074 {Opt_offgrpjquota, "grpjquota="}, 1103 {Opt_offgrpjquota, "grpjquota="},
@@ -1087,6 +1116,8 @@ static const match_table_t tokens = {
1087 {Opt_resize, "resize"}, 1116 {Opt_resize, "resize"},
1088 {Opt_delalloc, "delalloc"}, 1117 {Opt_delalloc, "delalloc"},
1089 {Opt_nodelalloc, "nodelalloc"}, 1118 {Opt_nodelalloc, "nodelalloc"},
1119 {Opt_block_validity, "block_validity"},
1120 {Opt_noblock_validity, "noblock_validity"},
1090 {Opt_inode_readahead_blks, "inode_readahead_blks=%u"}, 1121 {Opt_inode_readahead_blks, "inode_readahead_blks=%u"},
1091 {Opt_journal_ioprio, "journal_ioprio=%u"}, 1122 {Opt_journal_ioprio, "journal_ioprio=%u"},
1092 {Opt_auto_da_alloc, "auto_da_alloc=%u"}, 1123 {Opt_auto_da_alloc, "auto_da_alloc=%u"},
@@ -1102,8 +1133,9 @@ static ext4_fsblk_t get_sb_block(void **data)
1102 1133
1103 if (!options || strncmp(options, "sb=", 3) != 0) 1134 if (!options || strncmp(options, "sb=", 3) != 0)
1104 return 1; /* Default location */ 1135 return 1; /* Default location */
1136
1105 options += 3; 1137 options += 3;
1106 /*todo: use simple_strtoll with >32bit ext4 */ 1138 /* TODO: use simple_strtoll with >32bit ext4 */
1107 sb_block = simple_strtoul(options, &options, 0); 1139 sb_block = simple_strtoul(options, &options, 0);
1108 if (*options && *options != ',') { 1140 if (*options && *options != ',') {
1109 printk(KERN_ERR "EXT4-fs: Invalid sb specification: %s\n", 1141 printk(KERN_ERR "EXT4-fs: Invalid sb specification: %s\n",
@@ -1113,6 +1145,7 @@ static ext4_fsblk_t get_sb_block(void **data)
1113 if (*options == ',') 1145 if (*options == ',')
1114 options++; 1146 options++;
1115 *data = (void *) options; 1147 *data = (void *) options;
1148
1116 return sb_block; 1149 return sb_block;
1117} 1150}
1118 1151
@@ -1206,8 +1239,7 @@ static int parse_options(char *options, struct super_block *sb,
1206#else 1239#else
1207 case Opt_user_xattr: 1240 case Opt_user_xattr:
1208 case Opt_nouser_xattr: 1241 case Opt_nouser_xattr:
1209 printk(KERN_ERR "EXT4 (no)user_xattr options " 1242 ext4_msg(sb, KERN_ERR, "(no)user_xattr options not supported");
1210 "not supported\n");
1211 break; 1243 break;
1212#endif 1244#endif
1213#ifdef CONFIG_EXT4_FS_POSIX_ACL 1245#ifdef CONFIG_EXT4_FS_POSIX_ACL
@@ -1220,8 +1252,7 @@ static int parse_options(char *options, struct super_block *sb,
1220#else 1252#else
1221 case Opt_acl: 1253 case Opt_acl:
1222 case Opt_noacl: 1254 case Opt_noacl:
1223 printk(KERN_ERR "EXT4 (no)acl options " 1255 ext4_msg(sb, KERN_ERR, "(no)acl options not supported");
1224 "not supported\n");
1225 break; 1256 break;
1226#endif 1257#endif
1227 case Opt_journal_update: 1258 case Opt_journal_update:
@@ -1231,16 +1262,16 @@ static int parse_options(char *options, struct super_block *sb,
1231 user to specify an existing inode to be the 1262 user to specify an existing inode to be the
1232 journal file. */ 1263 journal file. */
1233 if (is_remount) { 1264 if (is_remount) {
1234 printk(KERN_ERR "EXT4-fs: cannot specify " 1265 ext4_msg(sb, KERN_ERR,
1235 "journal on remount\n"); 1266 "Cannot specify journal on remount");
1236 return 0; 1267 return 0;
1237 } 1268 }
1238 set_opt(sbi->s_mount_opt, UPDATE_JOURNAL); 1269 set_opt(sbi->s_mount_opt, UPDATE_JOURNAL);
1239 break; 1270 break;
1240 case Opt_journal_dev: 1271 case Opt_journal_dev:
1241 if (is_remount) { 1272 if (is_remount) {
1242 printk(KERN_ERR "EXT4-fs: cannot specify " 1273 ext4_msg(sb, KERN_ERR,
1243 "journal on remount\n"); 1274 "Cannot specify journal on remount");
1244 return 0; 1275 return 0;
1245 } 1276 }
1246 if (match_int(&args[0], &option)) 1277 if (match_int(&args[0], &option))
@@ -1294,9 +1325,8 @@ static int parse_options(char *options, struct super_block *sb,
1294 if (is_remount) { 1325 if (is_remount) {
1295 if ((sbi->s_mount_opt & EXT4_MOUNT_DATA_FLAGS) 1326 if ((sbi->s_mount_opt & EXT4_MOUNT_DATA_FLAGS)
1296 != data_opt) { 1327 != data_opt) {
1297 printk(KERN_ERR 1328 ext4_msg(sb, KERN_ERR,
1298 "EXT4-fs: cannot change data " 1329 "Cannot change data mode on remount");
1299 "mode on remount\n");
1300 return 0; 1330 return 0;
1301 } 1331 }
1302 } else { 1332 } else {
@@ -1310,6 +1340,13 @@ static int parse_options(char *options, struct super_block *sb,
1310 case Opt_data_err_ignore: 1340 case Opt_data_err_ignore:
1311 clear_opt(sbi->s_mount_opt, DATA_ERR_ABORT); 1341 clear_opt(sbi->s_mount_opt, DATA_ERR_ABORT);
1312 break; 1342 break;
1343 case Opt_mb_history_length:
1344 if (match_int(&args[0], &option))
1345 return 0;
1346 if (option < 0)
1347 return 0;
1348 sbi->s_mb_history_max = option;
1349 break;
1313#ifdef CONFIG_QUOTA 1350#ifdef CONFIG_QUOTA
1314 case Opt_usrjquota: 1351 case Opt_usrjquota:
1315 qtype = USRQUOTA; 1352 qtype = USRQUOTA;
@@ -1319,31 +1356,31 @@ static int parse_options(char *options, struct super_block *sb,
1319set_qf_name: 1356set_qf_name:
1320 if (sb_any_quota_loaded(sb) && 1357 if (sb_any_quota_loaded(sb) &&
1321 !sbi->s_qf_names[qtype]) { 1358 !sbi->s_qf_names[qtype]) {
1322 printk(KERN_ERR 1359 ext4_msg(sb, KERN_ERR,
1323 "EXT4-fs: Cannot change journaled " 1360 "Cannot change journaled "
1324 "quota options when quota turned on.\n"); 1361 "quota options when quota turned on");
1325 return 0; 1362 return 0;
1326 } 1363 }
1327 qname = match_strdup(&args[0]); 1364 qname = match_strdup(&args[0]);
1328 if (!qname) { 1365 if (!qname) {
1329 printk(KERN_ERR 1366 ext4_msg(sb, KERN_ERR,
1330 "EXT4-fs: not enough memory for " 1367 "Not enough memory for "
1331 "storing quotafile name.\n"); 1368 "storing quotafile name");
1332 return 0; 1369 return 0;
1333 } 1370 }
1334 if (sbi->s_qf_names[qtype] && 1371 if (sbi->s_qf_names[qtype] &&
1335 strcmp(sbi->s_qf_names[qtype], qname)) { 1372 strcmp(sbi->s_qf_names[qtype], qname)) {
1336 printk(KERN_ERR 1373 ext4_msg(sb, KERN_ERR,
1337 "EXT4-fs: %s quota file already " 1374 "%s quota file already "
1338 "specified.\n", QTYPE2NAME(qtype)); 1375 "specified", QTYPE2NAME(qtype));
1339 kfree(qname); 1376 kfree(qname);
1340 return 0; 1377 return 0;
1341 } 1378 }
1342 sbi->s_qf_names[qtype] = qname; 1379 sbi->s_qf_names[qtype] = qname;
1343 if (strchr(sbi->s_qf_names[qtype], '/')) { 1380 if (strchr(sbi->s_qf_names[qtype], '/')) {
1344 printk(KERN_ERR 1381 ext4_msg(sb, KERN_ERR,
1345 "EXT4-fs: quotafile must be on " 1382 "quotafile must be on "
1346 "filesystem root.\n"); 1383 "filesystem root");
1347 kfree(sbi->s_qf_names[qtype]); 1384 kfree(sbi->s_qf_names[qtype]);
1348 sbi->s_qf_names[qtype] = NULL; 1385 sbi->s_qf_names[qtype] = NULL;
1349 return 0; 1386 return 0;
@@ -1358,9 +1395,9 @@ set_qf_name:
1358clear_qf_name: 1395clear_qf_name:
1359 if (sb_any_quota_loaded(sb) && 1396 if (sb_any_quota_loaded(sb) &&
1360 sbi->s_qf_names[qtype]) { 1397 sbi->s_qf_names[qtype]) {
1361 printk(KERN_ERR "EXT4-fs: Cannot change " 1398 ext4_msg(sb, KERN_ERR, "Cannot change "
1362 "journaled quota options when " 1399 "journaled quota options when "
1363 "quota turned on.\n"); 1400 "quota turned on");
1364 return 0; 1401 return 0;
1365 } 1402 }
1366 /* 1403 /*
@@ -1377,9 +1414,9 @@ clear_qf_name:
1377set_qf_format: 1414set_qf_format:
1378 if (sb_any_quota_loaded(sb) && 1415 if (sb_any_quota_loaded(sb) &&
1379 sbi->s_jquota_fmt != qfmt) { 1416 sbi->s_jquota_fmt != qfmt) {
1380 printk(KERN_ERR "EXT4-fs: Cannot change " 1417 ext4_msg(sb, KERN_ERR, "Cannot change "
1381 "journaled quota options when " 1418 "journaled quota options when "
1382 "quota turned on.\n"); 1419 "quota turned on");
1383 return 0; 1420 return 0;
1384 } 1421 }
1385 sbi->s_jquota_fmt = qfmt; 1422 sbi->s_jquota_fmt = qfmt;
@@ -1395,8 +1432,8 @@ set_qf_format:
1395 break; 1432 break;
1396 case Opt_noquota: 1433 case Opt_noquota:
1397 if (sb_any_quota_loaded(sb)) { 1434 if (sb_any_quota_loaded(sb)) {
1398 printk(KERN_ERR "EXT4-fs: Cannot change quota " 1435 ext4_msg(sb, KERN_ERR, "Cannot change quota "
1399 "options when quota turned on.\n"); 1436 "options when quota turned on");
1400 return 0; 1437 return 0;
1401 } 1438 }
1402 clear_opt(sbi->s_mount_opt, QUOTA); 1439 clear_opt(sbi->s_mount_opt, QUOTA);
@@ -1407,8 +1444,8 @@ set_qf_format:
1407 case Opt_quota: 1444 case Opt_quota:
1408 case Opt_usrquota: 1445 case Opt_usrquota:
1409 case Opt_grpquota: 1446 case Opt_grpquota:
1410 printk(KERN_ERR 1447 ext4_msg(sb, KERN_ERR,
1411 "EXT4-fs: quota options not supported.\n"); 1448 "quota options not supported");
1412 break; 1449 break;
1413 case Opt_usrjquota: 1450 case Opt_usrjquota:
1414 case Opt_grpjquota: 1451 case Opt_grpjquota:
@@ -1416,15 +1453,14 @@ set_qf_format:
1416 case Opt_offgrpjquota: 1453 case Opt_offgrpjquota:
1417 case Opt_jqfmt_vfsold: 1454 case Opt_jqfmt_vfsold:
1418 case Opt_jqfmt_vfsv0: 1455 case Opt_jqfmt_vfsv0:
1419 printk(KERN_ERR 1456 ext4_msg(sb, KERN_ERR,
1420 "EXT4-fs: journaled quota options not " 1457 "journaled quota options not supported");
1421 "supported.\n");
1422 break; 1458 break;
1423 case Opt_noquota: 1459 case Opt_noquota:
1424 break; 1460 break;
1425#endif 1461#endif
1426 case Opt_abort: 1462 case Opt_abort:
1427 set_opt(sbi->s_mount_opt, ABORT); 1463 sbi->s_mount_flags |= EXT4_MF_FS_ABORTED;
1428 break; 1464 break;
1429 case Opt_nobarrier: 1465 case Opt_nobarrier:
1430 clear_opt(sbi->s_mount_opt, BARRIER); 1466 clear_opt(sbi->s_mount_opt, BARRIER);
@@ -1443,8 +1479,9 @@ set_qf_format:
1443 break; 1479 break;
1444 case Opt_resize: 1480 case Opt_resize:
1445 if (!is_remount) { 1481 if (!is_remount) {
1446 printk("EXT4-fs: resize option only available " 1482 ext4_msg(sb, KERN_ERR,
1447 "for remount\n"); 1483 "resize option only available "
1484 "for remount");
1448 return 0; 1485 return 0;
1449 } 1486 }
1450 if (match_int(&args[0], &option) != 0) 1487 if (match_int(&args[0], &option) != 0)
@@ -1474,14 +1511,21 @@ set_qf_format:
1474 case Opt_delalloc: 1511 case Opt_delalloc:
1475 set_opt(sbi->s_mount_opt, DELALLOC); 1512 set_opt(sbi->s_mount_opt, DELALLOC);
1476 break; 1513 break;
1514 case Opt_block_validity:
1515 set_opt(sbi->s_mount_opt, BLOCK_VALIDITY);
1516 break;
1517 case Opt_noblock_validity:
1518 clear_opt(sbi->s_mount_opt, BLOCK_VALIDITY);
1519 break;
1477 case Opt_inode_readahead_blks: 1520 case Opt_inode_readahead_blks:
1478 if (match_int(&args[0], &option)) 1521 if (match_int(&args[0], &option))
1479 return 0; 1522 return 0;
1480 if (option < 0 || option > (1 << 30)) 1523 if (option < 0 || option > (1 << 30))
1481 return 0; 1524 return 0;
1482 if (option & (option - 1)) { 1525 if (!is_power_of_2(option)) {
1483 printk(KERN_ERR "EXT4-fs: inode_readahead_blks" 1526 ext4_msg(sb, KERN_ERR,
1484 " must be a power of 2\n"); 1527 "EXT4-fs: inode_readahead_blks"
1528 " must be a power of 2");
1485 return 0; 1529 return 0;
1486 } 1530 }
1487 sbi->s_inode_readahead_blks = option; 1531 sbi->s_inode_readahead_blks = option;
@@ -1508,9 +1552,9 @@ set_qf_format:
1508 set_opt(sbi->s_mount_opt,NO_AUTO_DA_ALLOC); 1552 set_opt(sbi->s_mount_opt,NO_AUTO_DA_ALLOC);
1509 break; 1553 break;
1510 default: 1554 default:
1511 printk(KERN_ERR 1555 ext4_msg(sb, KERN_ERR,
1512 "EXT4-fs: Unrecognized mount option \"%s\" " 1556 "Unrecognized mount option \"%s\" "
1513 "or missing value\n", p); 1557 "or missing value", p);
1514 return 0; 1558 return 0;
1515 } 1559 }
1516 } 1560 }
@@ -1528,21 +1572,21 @@ set_qf_format:
1528 (sbi->s_mount_opt & EXT4_MOUNT_GRPQUOTA)) || 1572 (sbi->s_mount_opt & EXT4_MOUNT_GRPQUOTA)) ||
1529 (sbi->s_qf_names[GRPQUOTA] && 1573 (sbi->s_qf_names[GRPQUOTA] &&
1530 (sbi->s_mount_opt & EXT4_MOUNT_USRQUOTA))) { 1574 (sbi->s_mount_opt & EXT4_MOUNT_USRQUOTA))) {
1531 printk(KERN_ERR "EXT4-fs: old and new quota " 1575 ext4_msg(sb, KERN_ERR, "old and new quota "
1532 "format mixing.\n"); 1576 "format mixing");
1533 return 0; 1577 return 0;
1534 } 1578 }
1535 1579
1536 if (!sbi->s_jquota_fmt) { 1580 if (!sbi->s_jquota_fmt) {
1537 printk(KERN_ERR "EXT4-fs: journaled quota format " 1581 ext4_msg(sb, KERN_ERR, "journaled quota format "
1538 "not specified.\n"); 1582 "not specified");
1539 return 0; 1583 return 0;
1540 } 1584 }
1541 } else { 1585 } else {
1542 if (sbi->s_jquota_fmt) { 1586 if (sbi->s_jquota_fmt) {
1543 printk(KERN_ERR "EXT4-fs: journaled quota format " 1587 ext4_msg(sb, KERN_ERR, "journaled quota format "
1544 "specified with no journaling " 1588 "specified with no journaling "
1545 "enabled.\n"); 1589 "enabled");
1546 return 0; 1590 return 0;
1547 } 1591 }
1548 } 1592 }
@@ -1557,32 +1601,32 @@ static int ext4_setup_super(struct super_block *sb, struct ext4_super_block *es,
1557 int res = 0; 1601 int res = 0;
1558 1602
1559 if (le32_to_cpu(es->s_rev_level) > EXT4_MAX_SUPP_REV) { 1603 if (le32_to_cpu(es->s_rev_level) > EXT4_MAX_SUPP_REV) {
1560 printk(KERN_ERR "EXT4-fs warning: revision level too high, " 1604 ext4_msg(sb, KERN_ERR, "revision level too high, "
1561 "forcing read-only mode\n"); 1605 "forcing read-only mode");
1562 res = MS_RDONLY; 1606 res = MS_RDONLY;
1563 } 1607 }
1564 if (read_only) 1608 if (read_only)
1565 return res; 1609 return res;
1566 if (!(sbi->s_mount_state & EXT4_VALID_FS)) 1610 if (!(sbi->s_mount_state & EXT4_VALID_FS))
1567 printk(KERN_WARNING "EXT4-fs warning: mounting unchecked fs, " 1611 ext4_msg(sb, KERN_WARNING, "warning: mounting unchecked fs, "
1568 "running e2fsck is recommended\n"); 1612 "running e2fsck is recommended");
1569 else if ((sbi->s_mount_state & EXT4_ERROR_FS)) 1613 else if ((sbi->s_mount_state & EXT4_ERROR_FS))
1570 printk(KERN_WARNING 1614 ext4_msg(sb, KERN_WARNING,
1571 "EXT4-fs warning: mounting fs with errors, " 1615 "warning: mounting fs with errors, "
1572 "running e2fsck is recommended\n"); 1616 "running e2fsck is recommended");
1573 else if ((__s16) le16_to_cpu(es->s_max_mnt_count) >= 0 && 1617 else if ((__s16) le16_to_cpu(es->s_max_mnt_count) >= 0 &&
1574 le16_to_cpu(es->s_mnt_count) >= 1618 le16_to_cpu(es->s_mnt_count) >=
1575 (unsigned short) (__s16) le16_to_cpu(es->s_max_mnt_count)) 1619 (unsigned short) (__s16) le16_to_cpu(es->s_max_mnt_count))
1576 printk(KERN_WARNING 1620 ext4_msg(sb, KERN_WARNING,
1577 "EXT4-fs warning: maximal mount count reached, " 1621 "warning: maximal mount count reached, "
1578 "running e2fsck is recommended\n"); 1622 "running e2fsck is recommended");
1579 else if (le32_to_cpu(es->s_checkinterval) && 1623 else if (le32_to_cpu(es->s_checkinterval) &&
1580 (le32_to_cpu(es->s_lastcheck) + 1624 (le32_to_cpu(es->s_lastcheck) +
1581 le32_to_cpu(es->s_checkinterval) <= get_seconds())) 1625 le32_to_cpu(es->s_checkinterval) <= get_seconds()))
1582 printk(KERN_WARNING 1626 ext4_msg(sb, KERN_WARNING,
1583 "EXT4-fs warning: checktime reached, " 1627 "warning: checktime reached, "
1584 "running e2fsck is recommended\n"); 1628 "running e2fsck is recommended");
1585 if (!sbi->s_journal) 1629 if (!sbi->s_journal)
1586 es->s_state &= cpu_to_le16(~EXT4_VALID_FS); 1630 es->s_state &= cpu_to_le16(~EXT4_VALID_FS);
1587 if (!(__s16) le16_to_cpu(es->s_max_mnt_count)) 1631 if (!(__s16) le16_to_cpu(es->s_max_mnt_count))
1588 es->s_max_mnt_count = cpu_to_le16(EXT4_DFL_MAX_MNT_COUNT); 1632 es->s_max_mnt_count = cpu_to_le16(EXT4_DFL_MAX_MNT_COUNT);
@@ -1592,10 +1636,10 @@ static int ext4_setup_super(struct super_block *sb, struct ext4_super_block *es,
1592 if (sbi->s_journal) 1636 if (sbi->s_journal)
1593 EXT4_SET_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_RECOVER); 1637 EXT4_SET_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_RECOVER);
1594 1638
1595 ext4_commit_super(sb, es, 1); 1639 ext4_commit_super(sb, 1);
1596 if (test_opt(sb, DEBUG)) 1640 if (test_opt(sb, DEBUG))
1597 printk(KERN_INFO "[EXT4 FS bs=%lu, gc=%u, " 1641 printk(KERN_INFO "[EXT4 FS bs=%lu, gc=%u, "
1598 "bpg=%lu, ipg=%lu, mo=%04lx]\n", 1642 "bpg=%lu, ipg=%lu, mo=%04x]\n",
1599 sb->s_blocksize, 1643 sb->s_blocksize,
1600 sbi->s_groups_count, 1644 sbi->s_groups_count,
1601 EXT4_BLOCKS_PER_GROUP(sb), 1645 EXT4_BLOCKS_PER_GROUP(sb),
@@ -1603,11 +1647,11 @@ static int ext4_setup_super(struct super_block *sb, struct ext4_super_block *es,
1603 sbi->s_mount_opt); 1647 sbi->s_mount_opt);
1604 1648
1605 if (EXT4_SB(sb)->s_journal) { 1649 if (EXT4_SB(sb)->s_journal) {
1606 printk(KERN_INFO "EXT4 FS on %s, %s journal on %s\n", 1650 ext4_msg(sb, KERN_INFO, "%s journal on %s",
1607 sb->s_id, EXT4_SB(sb)->s_journal->j_inode ? "internal" : 1651 EXT4_SB(sb)->s_journal->j_inode ? "internal" :
1608 "external", EXT4_SB(sb)->s_journal->j_devname); 1652 "external", EXT4_SB(sb)->s_journal->j_devname);
1609 } else { 1653 } else {
1610 printk(KERN_INFO "EXT4 FS on %s, no journal\n", sb->s_id); 1654 ext4_msg(sb, KERN_INFO, "no journal");
1611 } 1655 }
1612 return res; 1656 return res;
1613} 1657}
@@ -1616,10 +1660,10 @@ static int ext4_fill_flex_info(struct super_block *sb)
1616{ 1660{
1617 struct ext4_sb_info *sbi = EXT4_SB(sb); 1661 struct ext4_sb_info *sbi = EXT4_SB(sb);
1618 struct ext4_group_desc *gdp = NULL; 1662 struct ext4_group_desc *gdp = NULL;
1619 struct buffer_head *bh;
1620 ext4_group_t flex_group_count; 1663 ext4_group_t flex_group_count;
1621 ext4_group_t flex_group; 1664 ext4_group_t flex_group;
1622 int groups_per_flex = 0; 1665 int groups_per_flex = 0;
1666 size_t size;
1623 int i; 1667 int i;
1624 1668
1625 if (!sbi->s_es->s_log_groups_per_flex) { 1669 if (!sbi->s_es->s_log_groups_per_flex) {
@@ -1634,16 +1678,21 @@ static int ext4_fill_flex_info(struct super_block *sb)
1634 flex_group_count = ((sbi->s_groups_count + groups_per_flex - 1) + 1678 flex_group_count = ((sbi->s_groups_count + groups_per_flex - 1) +
1635 ((le16_to_cpu(sbi->s_es->s_reserved_gdt_blocks) + 1) << 1679 ((le16_to_cpu(sbi->s_es->s_reserved_gdt_blocks) + 1) <<
1636 EXT4_DESC_PER_BLOCK_BITS(sb))) / groups_per_flex; 1680 EXT4_DESC_PER_BLOCK_BITS(sb))) / groups_per_flex;
1637 sbi->s_flex_groups = kzalloc(flex_group_count * 1681 size = flex_group_count * sizeof(struct flex_groups);
1638 sizeof(struct flex_groups), GFP_KERNEL); 1682 sbi->s_flex_groups = kzalloc(size, GFP_KERNEL);
1683 if (sbi->s_flex_groups == NULL) {
1684 sbi->s_flex_groups = vmalloc(size);
1685 if (sbi->s_flex_groups)
1686 memset(sbi->s_flex_groups, 0, size);
1687 }
1639 if (sbi->s_flex_groups == NULL) { 1688 if (sbi->s_flex_groups == NULL) {
1640 printk(KERN_ERR "EXT4-fs: not enough memory for " 1689 ext4_msg(sb, KERN_ERR, "not enough memory for "
1641 "%u flex groups\n", flex_group_count); 1690 "%u flex groups", flex_group_count);
1642 goto failed; 1691 goto failed;
1643 } 1692 }
1644 1693
1645 for (i = 0; i < sbi->s_groups_count; i++) { 1694 for (i = 0; i < sbi->s_groups_count; i++) {
1646 gdp = ext4_get_group_desc(sb, i, &bh); 1695 gdp = ext4_get_group_desc(sb, i, NULL);
1647 1696
1648 flex_group = ext4_flex_group(sbi, i); 1697 flex_group = ext4_flex_group(sbi, i);
1649 atomic_set(&sbi->s_flex_groups[flex_group].free_inodes, 1698 atomic_set(&sbi->s_flex_groups[flex_group].free_inodes,
@@ -1724,44 +1773,44 @@ static int ext4_check_descriptors(struct super_block *sb)
1724 1773
1725 block_bitmap = ext4_block_bitmap(sb, gdp); 1774 block_bitmap = ext4_block_bitmap(sb, gdp);
1726 if (block_bitmap < first_block || block_bitmap > last_block) { 1775 if (block_bitmap < first_block || block_bitmap > last_block) {
1727 printk(KERN_ERR "EXT4-fs: ext4_check_descriptors: " 1776 ext4_msg(sb, KERN_ERR, "ext4_check_descriptors: "
1728 "Block bitmap for group %u not in group " 1777 "Block bitmap for group %u not in group "
1729 "(block %llu)!\n", i, block_bitmap); 1778 "(block %llu)!", i, block_bitmap);
1730 return 0; 1779 return 0;
1731 } 1780 }
1732 inode_bitmap = ext4_inode_bitmap(sb, gdp); 1781 inode_bitmap = ext4_inode_bitmap(sb, gdp);
1733 if (inode_bitmap < first_block || inode_bitmap > last_block) { 1782 if (inode_bitmap < first_block || inode_bitmap > last_block) {
1734 printk(KERN_ERR "EXT4-fs: ext4_check_descriptors: " 1783 ext4_msg(sb, KERN_ERR, "ext4_check_descriptors: "
1735 "Inode bitmap for group %u not in group " 1784 "Inode bitmap for group %u not in group "
1736 "(block %llu)!\n", i, inode_bitmap); 1785 "(block %llu)!", i, inode_bitmap);
1737 return 0; 1786 return 0;
1738 } 1787 }
1739 inode_table = ext4_inode_table(sb, gdp); 1788 inode_table = ext4_inode_table(sb, gdp);
1740 if (inode_table < first_block || 1789 if (inode_table < first_block ||
1741 inode_table + sbi->s_itb_per_group - 1 > last_block) { 1790 inode_table + sbi->s_itb_per_group - 1 > last_block) {
1742 printk(KERN_ERR "EXT4-fs: ext4_check_descriptors: " 1791 ext4_msg(sb, KERN_ERR, "ext4_check_descriptors: "
1743 "Inode table for group %u not in group " 1792 "Inode table for group %u not in group "
1744 "(block %llu)!\n", i, inode_table); 1793 "(block %llu)!", i, inode_table);
1745 return 0; 1794 return 0;
1746 } 1795 }
1747 spin_lock(sb_bgl_lock(sbi, i)); 1796 ext4_lock_group(sb, i);
1748 if (!ext4_group_desc_csum_verify(sbi, i, gdp)) { 1797 if (!ext4_group_desc_csum_verify(sbi, i, gdp)) {
1749 printk(KERN_ERR "EXT4-fs: ext4_check_descriptors: " 1798 ext4_msg(sb, KERN_ERR, "ext4_check_descriptors: "
1750 "Checksum for group %u failed (%u!=%u)\n", 1799 "Checksum for group %u failed (%u!=%u)",
1751 i, le16_to_cpu(ext4_group_desc_csum(sbi, i, 1800 i, le16_to_cpu(ext4_group_desc_csum(sbi, i,
1752 gdp)), le16_to_cpu(gdp->bg_checksum)); 1801 gdp)), le16_to_cpu(gdp->bg_checksum));
1753 if (!(sb->s_flags & MS_RDONLY)) { 1802 if (!(sb->s_flags & MS_RDONLY)) {
1754 spin_unlock(sb_bgl_lock(sbi, i)); 1803 ext4_unlock_group(sb, i);
1755 return 0; 1804 return 0;
1756 } 1805 }
1757 } 1806 }
1758 spin_unlock(sb_bgl_lock(sbi, i)); 1807 ext4_unlock_group(sb, i);
1759 if (!flexbg_flag) 1808 if (!flexbg_flag)
1760 first_block += EXT4_BLOCKS_PER_GROUP(sb); 1809 first_block += EXT4_BLOCKS_PER_GROUP(sb);
1761 } 1810 }
1762 1811
1763 ext4_free_blocks_count_set(sbi->s_es, ext4_count_free_blocks(sb)); 1812 ext4_free_blocks_count_set(sbi->s_es, ext4_count_free_blocks(sb));
1764 sbi->s_es->s_free_inodes_count = cpu_to_le32(ext4_count_free_inodes(sb)); 1813 sbi->s_es->s_free_inodes_count =cpu_to_le32(ext4_count_free_inodes(sb));
1765 return 1; 1814 return 1;
1766} 1815}
1767 1816
@@ -1796,8 +1845,8 @@ static void ext4_orphan_cleanup(struct super_block *sb,
1796 } 1845 }
1797 1846
1798 if (bdev_read_only(sb->s_bdev)) { 1847 if (bdev_read_only(sb->s_bdev)) {
1799 printk(KERN_ERR "EXT4-fs: write access " 1848 ext4_msg(sb, KERN_ERR, "write access "
1800 "unavailable, skipping orphan cleanup.\n"); 1849 "unavailable, skipping orphan cleanup");
1801 return; 1850 return;
1802 } 1851 }
1803 1852
@@ -1811,8 +1860,7 @@ static void ext4_orphan_cleanup(struct super_block *sb,
1811 } 1860 }
1812 1861
1813 if (s_flags & MS_RDONLY) { 1862 if (s_flags & MS_RDONLY) {
1814 printk(KERN_INFO "EXT4-fs: %s: orphan cleanup on readonly fs\n", 1863 ext4_msg(sb, KERN_INFO, "orphan cleanup on readonly fs");
1815 sb->s_id);
1816 sb->s_flags &= ~MS_RDONLY; 1864 sb->s_flags &= ~MS_RDONLY;
1817 } 1865 }
1818#ifdef CONFIG_QUOTA 1866#ifdef CONFIG_QUOTA
@@ -1823,9 +1871,9 @@ static void ext4_orphan_cleanup(struct super_block *sb,
1823 if (EXT4_SB(sb)->s_qf_names[i]) { 1871 if (EXT4_SB(sb)->s_qf_names[i]) {
1824 int ret = ext4_quota_on_mount(sb, i); 1872 int ret = ext4_quota_on_mount(sb, i);
1825 if (ret < 0) 1873 if (ret < 0)
1826 printk(KERN_ERR 1874 ext4_msg(sb, KERN_ERR,
1827 "EXT4-fs: Cannot turn on journaled " 1875 "Cannot turn on journaled "
1828 "quota: error %d\n", ret); 1876 "quota: error %d", ret);
1829 } 1877 }
1830 } 1878 }
1831#endif 1879#endif
@@ -1842,16 +1890,16 @@ static void ext4_orphan_cleanup(struct super_block *sb,
1842 list_add(&EXT4_I(inode)->i_orphan, &EXT4_SB(sb)->s_orphan); 1890 list_add(&EXT4_I(inode)->i_orphan, &EXT4_SB(sb)->s_orphan);
1843 vfs_dq_init(inode); 1891 vfs_dq_init(inode);
1844 if (inode->i_nlink) { 1892 if (inode->i_nlink) {
1845 printk(KERN_DEBUG 1893 ext4_msg(sb, KERN_DEBUG,
1846 "%s: truncating inode %lu to %lld bytes\n", 1894 "%s: truncating inode %lu to %lld bytes",
1847 __func__, inode->i_ino, inode->i_size); 1895 __func__, inode->i_ino, inode->i_size);
1848 jbd_debug(2, "truncating inode %lu to %lld bytes\n", 1896 jbd_debug(2, "truncating inode %lu to %lld bytes\n",
1849 inode->i_ino, inode->i_size); 1897 inode->i_ino, inode->i_size);
1850 ext4_truncate(inode); 1898 ext4_truncate(inode);
1851 nr_truncates++; 1899 nr_truncates++;
1852 } else { 1900 } else {
1853 printk(KERN_DEBUG 1901 ext4_msg(sb, KERN_DEBUG,
1854 "%s: deleting unreferenced inode %lu\n", 1902 "%s: deleting unreferenced inode %lu",
1855 __func__, inode->i_ino); 1903 __func__, inode->i_ino);
1856 jbd_debug(2, "deleting unreferenced inode %lu\n", 1904 jbd_debug(2, "deleting unreferenced inode %lu\n",
1857 inode->i_ino); 1905 inode->i_ino);
@@ -1863,11 +1911,11 @@ static void ext4_orphan_cleanup(struct super_block *sb,
1863#define PLURAL(x) (x), ((x) == 1) ? "" : "s" 1911#define PLURAL(x) (x), ((x) == 1) ? "" : "s"
1864 1912
1865 if (nr_orphans) 1913 if (nr_orphans)
1866 printk(KERN_INFO "EXT4-fs: %s: %d orphan inode%s deleted\n", 1914 ext4_msg(sb, KERN_INFO, "%d orphan inode%s deleted",
1867 sb->s_id, PLURAL(nr_orphans)); 1915 PLURAL(nr_orphans));
1868 if (nr_truncates) 1916 if (nr_truncates)
1869 printk(KERN_INFO "EXT4-fs: %s: %d truncate%s cleaned up\n", 1917 ext4_msg(sb, KERN_INFO, "%d truncate%s cleaned up",
1870 sb->s_id, PLURAL(nr_truncates)); 1918 PLURAL(nr_truncates));
1871#ifdef CONFIG_QUOTA 1919#ifdef CONFIG_QUOTA
1872 /* Turn quotas off */ 1920 /* Turn quotas off */
1873 for (i = 0; i < MAXQUOTAS; i++) { 1921 for (i = 0; i < MAXQUOTAS; i++) {
@@ -1877,6 +1925,7 @@ static void ext4_orphan_cleanup(struct super_block *sb,
1877#endif 1925#endif
1878 sb->s_flags = s_flags; /* Restore MS_RDONLY status */ 1926 sb->s_flags = s_flags; /* Restore MS_RDONLY status */
1879} 1927}
1928
1880/* 1929/*
1881 * Maximal extent format file size. 1930 * Maximal extent format file size.
1882 * Resulting logical blkno at s_maxbytes must fit in our on-disk 1931 * Resulting logical blkno at s_maxbytes must fit in our on-disk
@@ -1894,7 +1943,7 @@ static loff_t ext4_max_size(int blkbits, int has_huge_files)
1894 /* small i_blocks in vfs inode? */ 1943 /* small i_blocks in vfs inode? */
1895 if (!has_huge_files || sizeof(blkcnt_t) < sizeof(u64)) { 1944 if (!has_huge_files || sizeof(blkcnt_t) < sizeof(u64)) {
1896 /* 1945 /*
1897 * CONFIG_LBD is not enabled implies the inode 1946 * CONFIG_LBDAF is not enabled implies the inode
1898 * i_block represent total blocks in 512 bytes 1947 * i_block represent total blocks in 512 bytes
1899 * 32 == size of vfs inode i_blocks * 8 1948 * 32 == size of vfs inode i_blocks * 8
1900 */ 1949 */
@@ -1927,19 +1976,19 @@ static loff_t ext4_max_bitmap_size(int bits, int has_huge_files)
1927 loff_t res = EXT4_NDIR_BLOCKS; 1976 loff_t res = EXT4_NDIR_BLOCKS;
1928 int meta_blocks; 1977 int meta_blocks;
1929 loff_t upper_limit; 1978 loff_t upper_limit;
1930 /* This is calculated to be the largest file size for a 1979 /* This is calculated to be the largest file size for a dense, block
1931 * dense, bitmapped file such that the total number of 1980 * mapped file such that the file's total number of 512-byte sectors,
1932 * sectors in the file, including data and all indirect blocks, 1981 * including data and all indirect blocks, does not exceed (2^48 - 1).
1933 * does not exceed 2^48 -1 1982 *
1934 * __u32 i_blocks_lo and _u16 i_blocks_high representing the 1983 * __u32 i_blocks_lo and _u16 i_blocks_high represent the total
1935 * total number of 512 bytes blocks of the file 1984 * number of 512-byte sectors of the file.
1936 */ 1985 */
1937 1986
1938 if (!has_huge_files || sizeof(blkcnt_t) < sizeof(u64)) { 1987 if (!has_huge_files || sizeof(blkcnt_t) < sizeof(u64)) {
1939 /* 1988 /*
1940 * !has_huge_files or CONFIG_LBD is not enabled 1989 * !has_huge_files or CONFIG_LBDAF not enabled implies that
1941 * implies the inode i_block represent total blocks in 1990 * the inode i_block field represents total file blocks in
1942 * 512 bytes 32 == size of vfs inode i_blocks * 8 1991 * 2^32 512-byte sectors == size of vfs inode i_blocks * 8
1943 */ 1992 */
1944 upper_limit = (1LL << 32) - 1; 1993 upper_limit = (1LL << 32) - 1;
1945 1994
@@ -1981,7 +2030,7 @@ static loff_t ext4_max_bitmap_size(int bits, int has_huge_files)
1981} 2030}
1982 2031
1983static ext4_fsblk_t descriptor_loc(struct super_block *sb, 2032static ext4_fsblk_t descriptor_loc(struct super_block *sb,
1984 ext4_fsblk_t logical_sb_block, int nr) 2033 ext4_fsblk_t logical_sb_block, int nr)
1985{ 2034{
1986 struct ext4_sb_info *sbi = EXT4_SB(sb); 2035 struct ext4_sb_info *sbi = EXT4_SB(sb);
1987 ext4_group_t bg, first_meta_bg; 2036 ext4_group_t bg, first_meta_bg;
@@ -1995,6 +2044,7 @@ static ext4_fsblk_t descriptor_loc(struct super_block *sb,
1995 bg = sbi->s_desc_per_block * nr; 2044 bg = sbi->s_desc_per_block * nr;
1996 if (ext4_bg_has_super(sb, bg)) 2045 if (ext4_bg_has_super(sb, bg))
1997 has_super = 1; 2046 has_super = 1;
2047
1998 return (has_super + ext4_group_first_block_no(sb, bg)); 2048 return (has_super + ext4_group_first_block_no(sb, bg));
1999} 2049}
2000 2050
@@ -2091,8 +2141,7 @@ static ssize_t inode_readahead_blks_store(struct ext4_attr *a,
2091 if (parse_strtoul(buf, 0x40000000, &t)) 2141 if (parse_strtoul(buf, 0x40000000, &t))
2092 return -EINVAL; 2142 return -EINVAL;
2093 2143
2094 /* inode_readahead_blks must be a power of 2 */ 2144 if (!is_power_of_2(t))
2095 if (t & (t-1))
2096 return -EINVAL; 2145 return -EINVAL;
2097 2146
2098 sbi->s_inode_readahead_blks = t; 2147 sbi->s_inode_readahead_blks = t;
@@ -2100,7 +2149,7 @@ static ssize_t inode_readahead_blks_store(struct ext4_attr *a,
2100} 2149}
2101 2150
2102static ssize_t sbi_ui_show(struct ext4_attr *a, 2151static ssize_t sbi_ui_show(struct ext4_attr *a,
2103 struct ext4_sb_info *sbi, char *buf) 2152 struct ext4_sb_info *sbi, char *buf)
2104{ 2153{
2105 unsigned int *ui = (unsigned int *) (((char *) sbi) + a->offset); 2154 unsigned int *ui = (unsigned int *) (((char *) sbi) + a->offset);
2106 2155
@@ -2141,6 +2190,7 @@ EXT4_RO_ATTR(session_write_kbytes);
2141EXT4_RO_ATTR(lifetime_write_kbytes); 2190EXT4_RO_ATTR(lifetime_write_kbytes);
2142EXT4_ATTR_OFFSET(inode_readahead_blks, 0644, sbi_ui_show, 2191EXT4_ATTR_OFFSET(inode_readahead_blks, 0644, sbi_ui_show,
2143 inode_readahead_blks_store, s_inode_readahead_blks); 2192 inode_readahead_blks_store, s_inode_readahead_blks);
2193EXT4_RW_ATTR_SBI_UI(inode_goal, s_inode_goal);
2144EXT4_RW_ATTR_SBI_UI(mb_stats, s_mb_stats); 2194EXT4_RW_ATTR_SBI_UI(mb_stats, s_mb_stats);
2145EXT4_RW_ATTR_SBI_UI(mb_max_to_scan, s_mb_max_to_scan); 2195EXT4_RW_ATTR_SBI_UI(mb_max_to_scan, s_mb_max_to_scan);
2146EXT4_RW_ATTR_SBI_UI(mb_min_to_scan, s_mb_min_to_scan); 2196EXT4_RW_ATTR_SBI_UI(mb_min_to_scan, s_mb_min_to_scan);
@@ -2153,6 +2203,7 @@ static struct attribute *ext4_attrs[] = {
2153 ATTR_LIST(session_write_kbytes), 2203 ATTR_LIST(session_write_kbytes),
2154 ATTR_LIST(lifetime_write_kbytes), 2204 ATTR_LIST(lifetime_write_kbytes),
2155 ATTR_LIST(inode_readahead_blks), 2205 ATTR_LIST(inode_readahead_blks),
2206 ATTR_LIST(inode_goal),
2156 ATTR_LIST(mb_stats), 2207 ATTR_LIST(mb_stats),
2157 ATTR_LIST(mb_max_to_scan), 2208 ATTR_LIST(mb_max_to_scan),
2158 ATTR_LIST(mb_min_to_scan), 2209 ATTR_LIST(mb_min_to_scan),
@@ -2205,7 +2256,6 @@ static struct kobj_type ext4_ktype = {
2205static int ext4_fill_super(struct super_block *sb, void *data, int silent) 2256static int ext4_fill_super(struct super_block *sb, void *data, int silent)
2206 __releases(kernel_lock) 2257 __releases(kernel_lock)
2207 __acquires(kernel_lock) 2258 __acquires(kernel_lock)
2208
2209{ 2259{
2210 struct buffer_head *bh; 2260 struct buffer_head *bh;
2211 struct ext4_super_block *es = NULL; 2261 struct ext4_super_block *es = NULL;
@@ -2256,7 +2306,7 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent)
2256 2306
2257 blocksize = sb_min_blocksize(sb, EXT4_MIN_BLOCK_SIZE); 2307 blocksize = sb_min_blocksize(sb, EXT4_MIN_BLOCK_SIZE);
2258 if (!blocksize) { 2308 if (!blocksize) {
2259 printk(KERN_ERR "EXT4-fs: unable to set blocksize\n"); 2309 ext4_msg(sb, KERN_ERR, "unable to set blocksize");
2260 goto out_fail; 2310 goto out_fail;
2261 } 2311 }
2262 2312
@@ -2272,7 +2322,7 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent)
2272 } 2322 }
2273 2323
2274 if (!(bh = sb_bread(sb, logical_sb_block))) { 2324 if (!(bh = sb_bread(sb, logical_sb_block))) {
2275 printk(KERN_ERR "EXT4-fs: unable to read superblock\n"); 2325 ext4_msg(sb, KERN_ERR, "unable to read superblock");
2276 goto out_fail; 2326 goto out_fail;
2277 } 2327 }
2278 /* 2328 /*
@@ -2321,6 +2371,7 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent)
2321 sbi->s_commit_interval = JBD2_DEFAULT_MAX_COMMIT_AGE * HZ; 2371 sbi->s_commit_interval = JBD2_DEFAULT_MAX_COMMIT_AGE * HZ;
2322 sbi->s_min_batch_time = EXT4_DEF_MIN_BATCH_TIME; 2372 sbi->s_min_batch_time = EXT4_DEF_MIN_BATCH_TIME;
2323 sbi->s_max_batch_time = EXT4_DEF_MAX_BATCH_TIME; 2373 sbi->s_max_batch_time = EXT4_DEF_MAX_BATCH_TIME;
2374 sbi->s_mb_history_max = default_mb_history_length;
2324 2375
2325 set_opt(sbi->s_mount_opt, BARRIER); 2376 set_opt(sbi->s_mount_opt, BARRIER);
2326 2377
@@ -2330,7 +2381,6 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent)
2330 */ 2381 */
2331 set_opt(sbi->s_mount_opt, DELALLOC); 2382 set_opt(sbi->s_mount_opt, DELALLOC);
2332 2383
2333
2334 if (!parse_options((char *) data, sb, &journal_devnum, 2384 if (!parse_options((char *) data, sb, &journal_devnum,
2335 &journal_ioprio, NULL, 0)) 2385 &journal_ioprio, NULL, 0))
2336 goto failed_mount; 2386 goto failed_mount;
@@ -2342,9 +2392,9 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent)
2342 (EXT4_HAS_COMPAT_FEATURE(sb, ~0U) || 2392 (EXT4_HAS_COMPAT_FEATURE(sb, ~0U) ||
2343 EXT4_HAS_RO_COMPAT_FEATURE(sb, ~0U) || 2393 EXT4_HAS_RO_COMPAT_FEATURE(sb, ~0U) ||
2344 EXT4_HAS_INCOMPAT_FEATURE(sb, ~0U))) 2394 EXT4_HAS_INCOMPAT_FEATURE(sb, ~0U)))
2345 printk(KERN_WARNING 2395 ext4_msg(sb, KERN_WARNING,
2346 "EXT4-fs warning: feature flags set on rev 0 fs, " 2396 "feature flags set on rev 0 fs, "
2347 "running e2fsck is recommended\n"); 2397 "running e2fsck is recommended");
2348 2398
2349 /* 2399 /*
2350 * Check feature flags regardless of the revision level, since we 2400 * Check feature flags regardless of the revision level, since we
@@ -2353,16 +2403,18 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent)
2353 */ 2403 */
2354 features = EXT4_HAS_INCOMPAT_FEATURE(sb, ~EXT4_FEATURE_INCOMPAT_SUPP); 2404 features = EXT4_HAS_INCOMPAT_FEATURE(sb, ~EXT4_FEATURE_INCOMPAT_SUPP);
2355 if (features) { 2405 if (features) {
2356 printk(KERN_ERR "EXT4-fs: %s: couldn't mount because of " 2406 ext4_msg(sb, KERN_ERR,
2357 "unsupported optional features (%x).\n", sb->s_id, 2407 "Couldn't mount because of "
2408 "unsupported optional features (%x)",
2358 (le32_to_cpu(EXT4_SB(sb)->s_es->s_feature_incompat) & 2409 (le32_to_cpu(EXT4_SB(sb)->s_es->s_feature_incompat) &
2359 ~EXT4_FEATURE_INCOMPAT_SUPP)); 2410 ~EXT4_FEATURE_INCOMPAT_SUPP));
2360 goto failed_mount; 2411 goto failed_mount;
2361 } 2412 }
2362 features = EXT4_HAS_RO_COMPAT_FEATURE(sb, ~EXT4_FEATURE_RO_COMPAT_SUPP); 2413 features = EXT4_HAS_RO_COMPAT_FEATURE(sb, ~EXT4_FEATURE_RO_COMPAT_SUPP);
2363 if (!(sb->s_flags & MS_RDONLY) && features) { 2414 if (!(sb->s_flags & MS_RDONLY) && features) {
2364 printk(KERN_ERR "EXT4-fs: %s: couldn't mount RDWR because of " 2415 ext4_msg(sb, KERN_ERR,
2365 "unsupported optional features (%x).\n", sb->s_id, 2416 "Couldn't mount RDWR because of "
2417 "unsupported optional features (%x)",
2366 (le32_to_cpu(EXT4_SB(sb)->s_es->s_feature_ro_compat) & 2418 (le32_to_cpu(EXT4_SB(sb)->s_es->s_feature_ro_compat) &
2367 ~EXT4_FEATURE_RO_COMPAT_SUPP)); 2419 ~EXT4_FEATURE_RO_COMPAT_SUPP));
2368 goto failed_mount; 2420 goto failed_mount;
@@ -2372,13 +2424,13 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent)
2372 if (has_huge_files) { 2424 if (has_huge_files) {
2373 /* 2425 /*
2374 * Large file size enabled file system can only be 2426 * Large file size enabled file system can only be
2375 * mount if kernel is build with CONFIG_LBD 2427 * mount if kernel is build with CONFIG_LBDAF
2376 */ 2428 */
2377 if (sizeof(root->i_blocks) < sizeof(u64) && 2429 if (sizeof(root->i_blocks) < sizeof(u64) &&
2378 !(sb->s_flags & MS_RDONLY)) { 2430 !(sb->s_flags & MS_RDONLY)) {
2379 printk(KERN_ERR "EXT4-fs: %s: Filesystem with huge " 2431 ext4_msg(sb, KERN_ERR, "Filesystem with huge "
2380 "files cannot be mounted read-write " 2432 "files cannot be mounted read-write "
2381 "without CONFIG_LBD.\n", sb->s_id); 2433 "without CONFIG_LBDAF");
2382 goto failed_mount; 2434 goto failed_mount;
2383 } 2435 }
2384 } 2436 }
@@ -2386,17 +2438,15 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent)
2386 2438
2387 if (blocksize < EXT4_MIN_BLOCK_SIZE || 2439 if (blocksize < EXT4_MIN_BLOCK_SIZE ||
2388 blocksize > EXT4_MAX_BLOCK_SIZE) { 2440 blocksize > EXT4_MAX_BLOCK_SIZE) {
2389 printk(KERN_ERR 2441 ext4_msg(sb, KERN_ERR,
2390 "EXT4-fs: Unsupported filesystem blocksize %d on %s.\n", 2442 "Unsupported filesystem blocksize %d", blocksize);
2391 blocksize, sb->s_id);
2392 goto failed_mount; 2443 goto failed_mount;
2393 } 2444 }
2394 2445
2395 if (sb->s_blocksize != blocksize) { 2446 if (sb->s_blocksize != blocksize) {
2396
2397 /* Validate the filesystem blocksize */ 2447 /* Validate the filesystem blocksize */
2398 if (!sb_set_blocksize(sb, blocksize)) { 2448 if (!sb_set_blocksize(sb, blocksize)) {
2399 printk(KERN_ERR "EXT4-fs: bad block size %d.\n", 2449 ext4_msg(sb, KERN_ERR, "bad block size %d",
2400 blocksize); 2450 blocksize);
2401 goto failed_mount; 2451 goto failed_mount;
2402 } 2452 }
@@ -2406,15 +2456,15 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent)
2406 offset = do_div(logical_sb_block, blocksize); 2456 offset = do_div(logical_sb_block, blocksize);
2407 bh = sb_bread(sb, logical_sb_block); 2457 bh = sb_bread(sb, logical_sb_block);
2408 if (!bh) { 2458 if (!bh) {
2409 printk(KERN_ERR 2459 ext4_msg(sb, KERN_ERR,
2410 "EXT4-fs: Can't read superblock on 2nd try.\n"); 2460 "Can't read superblock on 2nd try");
2411 goto failed_mount; 2461 goto failed_mount;
2412 } 2462 }
2413 es = (struct ext4_super_block *)(((char *)bh->b_data) + offset); 2463 es = (struct ext4_super_block *)(((char *)bh->b_data) + offset);
2414 sbi->s_es = es; 2464 sbi->s_es = es;
2415 if (es->s_magic != cpu_to_le16(EXT4_SUPER_MAGIC)) { 2465 if (es->s_magic != cpu_to_le16(EXT4_SUPER_MAGIC)) {
2416 printk(KERN_ERR 2466 ext4_msg(sb, KERN_ERR,
2417 "EXT4-fs: Magic mismatch, very weird !\n"); 2467 "Magic mismatch, very weird!");
2418 goto failed_mount; 2468 goto failed_mount;
2419 } 2469 }
2420 } 2470 }
@@ -2432,30 +2482,33 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent)
2432 if ((sbi->s_inode_size < EXT4_GOOD_OLD_INODE_SIZE) || 2482 if ((sbi->s_inode_size < EXT4_GOOD_OLD_INODE_SIZE) ||
2433 (!is_power_of_2(sbi->s_inode_size)) || 2483 (!is_power_of_2(sbi->s_inode_size)) ||
2434 (sbi->s_inode_size > blocksize)) { 2484 (sbi->s_inode_size > blocksize)) {
2435 printk(KERN_ERR 2485 ext4_msg(sb, KERN_ERR,
2436 "EXT4-fs: unsupported inode size: %d\n", 2486 "unsupported inode size: %d",
2437 sbi->s_inode_size); 2487 sbi->s_inode_size);
2438 goto failed_mount; 2488 goto failed_mount;
2439 } 2489 }
2440 if (sbi->s_inode_size > EXT4_GOOD_OLD_INODE_SIZE) 2490 if (sbi->s_inode_size > EXT4_GOOD_OLD_INODE_SIZE)
2441 sb->s_time_gran = 1 << (EXT4_EPOCH_BITS - 2); 2491 sb->s_time_gran = 1 << (EXT4_EPOCH_BITS - 2);
2442 } 2492 }
2493
2443 sbi->s_desc_size = le16_to_cpu(es->s_desc_size); 2494 sbi->s_desc_size = le16_to_cpu(es->s_desc_size);
2444 if (EXT4_HAS_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_64BIT)) { 2495 if (EXT4_HAS_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_64BIT)) {
2445 if (sbi->s_desc_size < EXT4_MIN_DESC_SIZE_64BIT || 2496 if (sbi->s_desc_size < EXT4_MIN_DESC_SIZE_64BIT ||
2446 sbi->s_desc_size > EXT4_MAX_DESC_SIZE || 2497 sbi->s_desc_size > EXT4_MAX_DESC_SIZE ||
2447 !is_power_of_2(sbi->s_desc_size)) { 2498 !is_power_of_2(sbi->s_desc_size)) {
2448 printk(KERN_ERR 2499 ext4_msg(sb, KERN_ERR,
2449 "EXT4-fs: unsupported descriptor size %lu\n", 2500 "unsupported descriptor size %lu",
2450 sbi->s_desc_size); 2501 sbi->s_desc_size);
2451 goto failed_mount; 2502 goto failed_mount;
2452 } 2503 }
2453 } else 2504 } else
2454 sbi->s_desc_size = EXT4_MIN_DESC_SIZE; 2505 sbi->s_desc_size = EXT4_MIN_DESC_SIZE;
2506
2455 sbi->s_blocks_per_group = le32_to_cpu(es->s_blocks_per_group); 2507 sbi->s_blocks_per_group = le32_to_cpu(es->s_blocks_per_group);
2456 sbi->s_inodes_per_group = le32_to_cpu(es->s_inodes_per_group); 2508 sbi->s_inodes_per_group = le32_to_cpu(es->s_inodes_per_group);
2457 if (EXT4_INODE_SIZE(sb) == 0 || EXT4_INODES_PER_GROUP(sb) == 0) 2509 if (EXT4_INODE_SIZE(sb) == 0 || EXT4_INODES_PER_GROUP(sb) == 0)
2458 goto cantfind_ext4; 2510 goto cantfind_ext4;
2511
2459 sbi->s_inodes_per_block = blocksize / EXT4_INODE_SIZE(sb); 2512 sbi->s_inodes_per_block = blocksize / EXT4_INODE_SIZE(sb);
2460 if (sbi->s_inodes_per_block == 0) 2513 if (sbi->s_inodes_per_block == 0)
2461 goto cantfind_ext4; 2514 goto cantfind_ext4;
@@ -2466,6 +2519,7 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent)
2466 sbi->s_mount_state = le16_to_cpu(es->s_state); 2519 sbi->s_mount_state = le16_to_cpu(es->s_state);
2467 sbi->s_addr_per_block_bits = ilog2(EXT4_ADDR_PER_BLOCK(sb)); 2520 sbi->s_addr_per_block_bits = ilog2(EXT4_ADDR_PER_BLOCK(sb));
2468 sbi->s_desc_per_block_bits = ilog2(EXT4_DESC_PER_BLOCK(sb)); 2521 sbi->s_desc_per_block_bits = ilog2(EXT4_DESC_PER_BLOCK(sb));
2522
2469 for (i = 0; i < 4; i++) 2523 for (i = 0; i < 4; i++)
2470 sbi->s_hash_seed[i] = le32_to_cpu(es->s_hash_seed[i]); 2524 sbi->s_hash_seed[i] = le32_to_cpu(es->s_hash_seed[i]);
2471 sbi->s_def_hash_version = es->s_def_hash_version; 2525 sbi->s_def_hash_version = es->s_def_hash_version;
@@ -2483,25 +2537,24 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent)
2483 } 2537 }
2484 2538
2485 if (sbi->s_blocks_per_group > blocksize * 8) { 2539 if (sbi->s_blocks_per_group > blocksize * 8) {
2486 printk(KERN_ERR 2540 ext4_msg(sb, KERN_ERR,
2487 "EXT4-fs: #blocks per group too big: %lu\n", 2541 "#blocks per group too big: %lu",
2488 sbi->s_blocks_per_group); 2542 sbi->s_blocks_per_group);
2489 goto failed_mount; 2543 goto failed_mount;
2490 } 2544 }
2491 if (sbi->s_inodes_per_group > blocksize * 8) { 2545 if (sbi->s_inodes_per_group > blocksize * 8) {
2492 printk(KERN_ERR 2546 ext4_msg(sb, KERN_ERR,
2493 "EXT4-fs: #inodes per group too big: %lu\n", 2547 "#inodes per group too big: %lu",
2494 sbi->s_inodes_per_group); 2548 sbi->s_inodes_per_group);
2495 goto failed_mount; 2549 goto failed_mount;
2496 } 2550 }
2497 2551
2498 if (ext4_blocks_count(es) > 2552 if (ext4_blocks_count(es) >
2499 (sector_t)(~0ULL) >> (sb->s_blocksize_bits - 9)) { 2553 (sector_t)(~0ULL) >> (sb->s_blocksize_bits - 9)) {
2500 printk(KERN_ERR "EXT4-fs: filesystem on %s:" 2554 ext4_msg(sb, KERN_ERR, "filesystem"
2501 " too large to mount safely\n", sb->s_id); 2555 " too large to mount safely");
2502 if (sizeof(sector_t) < 8) 2556 if (sizeof(sector_t) < 8)
2503 printk(KERN_WARNING "EXT4-fs: CONFIG_LBD not " 2557 ext4_msg(sb, KERN_WARNING, "CONFIG_LBDAF not enabled");
2504 "enabled\n");
2505 goto failed_mount; 2558 goto failed_mount;
2506 } 2559 }
2507 2560
@@ -2511,21 +2564,21 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent)
2511 /* check blocks count against device size */ 2564 /* check blocks count against device size */
2512 blocks_count = sb->s_bdev->bd_inode->i_size >> sb->s_blocksize_bits; 2565 blocks_count = sb->s_bdev->bd_inode->i_size >> sb->s_blocksize_bits;
2513 if (blocks_count && ext4_blocks_count(es) > blocks_count) { 2566 if (blocks_count && ext4_blocks_count(es) > blocks_count) {
2514 printk(KERN_WARNING "EXT4-fs: bad geometry: block count %llu " 2567 ext4_msg(sb, KERN_WARNING, "bad geometry: block count %llu "
2515 "exceeds size of device (%llu blocks)\n", 2568 "exceeds size of device (%llu blocks)",
2516 ext4_blocks_count(es), blocks_count); 2569 ext4_blocks_count(es), blocks_count);
2517 goto failed_mount; 2570 goto failed_mount;
2518 } 2571 }
2519 2572
2520 /* 2573 /*
2521 * It makes no sense for the first data block to be beyond the end 2574 * It makes no sense for the first data block to be beyond the end
2522 * of the filesystem. 2575 * of the filesystem.
2523 */ 2576 */
2524 if (le32_to_cpu(es->s_first_data_block) >= ext4_blocks_count(es)) { 2577 if (le32_to_cpu(es->s_first_data_block) >= ext4_blocks_count(es)) {
2525 printk(KERN_WARNING "EXT4-fs: bad geometry: first data" 2578 ext4_msg(sb, KERN_WARNING, "bad geometry: first data"
2526 "block %u is beyond end of filesystem (%llu)\n", 2579 "block %u is beyond end of filesystem (%llu)",
2527 le32_to_cpu(es->s_first_data_block), 2580 le32_to_cpu(es->s_first_data_block),
2528 ext4_blocks_count(es)); 2581 ext4_blocks_count(es));
2529 goto failed_mount; 2582 goto failed_mount;
2530 } 2583 }
2531 blocks_count = (ext4_blocks_count(es) - 2584 blocks_count = (ext4_blocks_count(es) -
@@ -2533,9 +2586,9 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent)
2533 EXT4_BLOCKS_PER_GROUP(sb) - 1); 2586 EXT4_BLOCKS_PER_GROUP(sb) - 1);
2534 do_div(blocks_count, EXT4_BLOCKS_PER_GROUP(sb)); 2587 do_div(blocks_count, EXT4_BLOCKS_PER_GROUP(sb));
2535 if (blocks_count > ((uint64_t)1<<32) - EXT4_DESC_PER_BLOCK(sb)) { 2588 if (blocks_count > ((uint64_t)1<<32) - EXT4_DESC_PER_BLOCK(sb)) {
2536 printk(KERN_WARNING "EXT4-fs: groups count too large: %u " 2589 ext4_msg(sb, KERN_WARNING, "groups count too large: %u "
2537 "(block count %llu, first data block %u, " 2590 "(block count %llu, first data block %u, "
2538 "blocks per group %lu)\n", sbi->s_groups_count, 2591 "blocks per group %lu)", sbi->s_groups_count,
2539 ext4_blocks_count(es), 2592 ext4_blocks_count(es),
2540 le32_to_cpu(es->s_first_data_block), 2593 le32_to_cpu(es->s_first_data_block),
2541 EXT4_BLOCKS_PER_GROUP(sb)); 2594 EXT4_BLOCKS_PER_GROUP(sb));
@@ -2547,7 +2600,7 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent)
2547 sbi->s_group_desc = kmalloc(db_count * sizeof(struct buffer_head *), 2600 sbi->s_group_desc = kmalloc(db_count * sizeof(struct buffer_head *),
2548 GFP_KERNEL); 2601 GFP_KERNEL);
2549 if (sbi->s_group_desc == NULL) { 2602 if (sbi->s_group_desc == NULL) {
2550 printk(KERN_ERR "EXT4-fs: not enough memory\n"); 2603 ext4_msg(sb, KERN_ERR, "not enough memory");
2551 goto failed_mount; 2604 goto failed_mount;
2552 } 2605 }
2553 2606
@@ -2562,21 +2615,21 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent)
2562 block = descriptor_loc(sb, logical_sb_block, i); 2615 block = descriptor_loc(sb, logical_sb_block, i);
2563 sbi->s_group_desc[i] = sb_bread(sb, block); 2616 sbi->s_group_desc[i] = sb_bread(sb, block);
2564 if (!sbi->s_group_desc[i]) { 2617 if (!sbi->s_group_desc[i]) {
2565 printk(KERN_ERR "EXT4-fs: " 2618 ext4_msg(sb, KERN_ERR,
2566 "can't read group descriptor %d\n", i); 2619 "can't read group descriptor %d", i);
2567 db_count = i; 2620 db_count = i;
2568 goto failed_mount2; 2621 goto failed_mount2;
2569 } 2622 }
2570 } 2623 }
2571 if (!ext4_check_descriptors(sb)) { 2624 if (!ext4_check_descriptors(sb)) {
2572 printk(KERN_ERR "EXT4-fs: group descriptors corrupted!\n"); 2625 ext4_msg(sb, KERN_ERR, "group descriptors corrupted!");
2573 goto failed_mount2; 2626 goto failed_mount2;
2574 } 2627 }
2575 if (EXT4_HAS_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_FLEX_BG)) 2628 if (EXT4_HAS_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_FLEX_BG))
2576 if (!ext4_fill_flex_info(sb)) { 2629 if (!ext4_fill_flex_info(sb)) {
2577 printk(KERN_ERR 2630 ext4_msg(sb, KERN_ERR,
2578 "EXT4-fs: unable to initialize " 2631 "unable to initialize "
2579 "flex_bg meta info!\n"); 2632 "flex_bg meta info!");
2580 goto failed_mount2; 2633 goto failed_mount2;
2581 } 2634 }
2582 2635
@@ -2598,7 +2651,7 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent)
2598 err = percpu_counter_init(&sbi->s_dirtyblocks_counter, 0); 2651 err = percpu_counter_init(&sbi->s_dirtyblocks_counter, 0);
2599 } 2652 }
2600 if (err) { 2653 if (err) {
2601 printk(KERN_ERR "EXT4-fs: insufficient memory\n"); 2654 ext4_msg(sb, KERN_ERR, "insufficient memory");
2602 goto failed_mount3; 2655 goto failed_mount3;
2603 } 2656 }
2604 2657
@@ -2607,7 +2660,11 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent)
2607 /* 2660 /*
2608 * set up enough so that it can read an inode 2661 * set up enough so that it can read an inode
2609 */ 2662 */
2610 sb->s_op = &ext4_sops; 2663 if (!test_opt(sb, NOLOAD) &&
2664 EXT4_HAS_COMPAT_FEATURE(sb, EXT4_FEATURE_COMPAT_HAS_JOURNAL))
2665 sb->s_op = &ext4_sops;
2666 else
2667 sb->s_op = &ext4_nojournal_sops;
2611 sb->s_export_op = &ext4_export_ops; 2668 sb->s_export_op = &ext4_export_ops;
2612 sb->s_xattr = ext4_xattr_handlers; 2669 sb->s_xattr = ext4_xattr_handlers;
2613#ifdef CONFIG_QUOTA 2670#ifdef CONFIG_QUOTA
@@ -2615,6 +2672,8 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent)
2615 sb->dq_op = &ext4_quota_operations; 2672 sb->dq_op = &ext4_quota_operations;
2616#endif 2673#endif
2617 INIT_LIST_HEAD(&sbi->s_orphan); /* unlinked but open files */ 2674 INIT_LIST_HEAD(&sbi->s_orphan); /* unlinked but open files */
2675 mutex_init(&sbi->s_orphan_lock);
2676 mutex_init(&sbi->s_resize_lock);
2618 2677
2619 sb->s_root = NULL; 2678 sb->s_root = NULL;
2620 2679
@@ -2632,13 +2691,13 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent)
2632 goto failed_mount3; 2691 goto failed_mount3;
2633 if (!(sb->s_flags & MS_RDONLY) && 2692 if (!(sb->s_flags & MS_RDONLY) &&
2634 EXT4_SB(sb)->s_journal->j_failed_commit) { 2693 EXT4_SB(sb)->s_journal->j_failed_commit) {
2635 printk(KERN_CRIT "EXT4-fs error (device %s): " 2694 ext4_msg(sb, KERN_CRIT, "error: "
2636 "ext4_fill_super: Journal transaction " 2695 "ext4_fill_super: Journal transaction "
2637 "%u is corrupt\n", sb->s_id, 2696 "%u is corrupt",
2638 EXT4_SB(sb)->s_journal->j_failed_commit); 2697 EXT4_SB(sb)->s_journal->j_failed_commit);
2639 if (test_opt(sb, ERRORS_RO)) { 2698 if (test_opt(sb, ERRORS_RO)) {
2640 printk(KERN_CRIT 2699 ext4_msg(sb, KERN_CRIT,
2641 "Mounting filesystem read-only\n"); 2700 "Mounting filesystem read-only");
2642 sb->s_flags |= MS_RDONLY; 2701 sb->s_flags |= MS_RDONLY;
2643 EXT4_SB(sb)->s_mount_state |= EXT4_ERROR_FS; 2702 EXT4_SB(sb)->s_mount_state |= EXT4_ERROR_FS;
2644 es->s_state |= cpu_to_le16(EXT4_ERROR_FS); 2703 es->s_state |= cpu_to_le16(EXT4_ERROR_FS);
@@ -2646,14 +2705,14 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent)
2646 if (test_opt(sb, ERRORS_PANIC)) { 2705 if (test_opt(sb, ERRORS_PANIC)) {
2647 EXT4_SB(sb)->s_mount_state |= EXT4_ERROR_FS; 2706 EXT4_SB(sb)->s_mount_state |= EXT4_ERROR_FS;
2648 es->s_state |= cpu_to_le16(EXT4_ERROR_FS); 2707 es->s_state |= cpu_to_le16(EXT4_ERROR_FS);
2649 ext4_commit_super(sb, es, 1); 2708 ext4_commit_super(sb, 1);
2650 goto failed_mount4; 2709 goto failed_mount4;
2651 } 2710 }
2652 } 2711 }
2653 } else if (test_opt(sb, NOLOAD) && !(sb->s_flags & MS_RDONLY) && 2712 } else if (test_opt(sb, NOLOAD) && !(sb->s_flags & MS_RDONLY) &&
2654 EXT4_HAS_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_RECOVER)) { 2713 EXT4_HAS_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_RECOVER)) {
2655 printk(KERN_ERR "EXT4-fs: required journal recovery " 2714 ext4_msg(sb, KERN_ERR, "required journal recovery "
2656 "suppressed and not mounted read-only\n"); 2715 "suppressed and not mounted read-only");
2657 goto failed_mount4; 2716 goto failed_mount4;
2658 } else { 2717 } else {
2659 clear_opt(sbi->s_mount_opt, DATA_FLAGS); 2718 clear_opt(sbi->s_mount_opt, DATA_FLAGS);
@@ -2666,7 +2725,7 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent)
2666 if (ext4_blocks_count(es) > 0xffffffffULL && 2725 if (ext4_blocks_count(es) > 0xffffffffULL &&
2667 !jbd2_journal_set_features(EXT4_SB(sb)->s_journal, 0, 0, 2726 !jbd2_journal_set_features(EXT4_SB(sb)->s_journal, 0, 0,
2668 JBD2_FEATURE_INCOMPAT_64BIT)) { 2727 JBD2_FEATURE_INCOMPAT_64BIT)) {
2669 printk(KERN_ERR "EXT4-fs: Failed to set 64-bit journal feature\n"); 2728 ext4_msg(sb, KERN_ERR, "Failed to set 64-bit journal feature");
2670 goto failed_mount4; 2729 goto failed_mount4;
2671 } 2730 }
2672 2731
@@ -2704,8 +2763,8 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent)
2704 case EXT4_MOUNT_WRITEBACK_DATA: 2763 case EXT4_MOUNT_WRITEBACK_DATA:
2705 if (!jbd2_journal_check_available_features 2764 if (!jbd2_journal_check_available_features
2706 (sbi->s_journal, 0, 0, JBD2_FEATURE_INCOMPAT_REVOKE)) { 2765 (sbi->s_journal, 0, 0, JBD2_FEATURE_INCOMPAT_REVOKE)) {
2707 printk(KERN_ERR "EXT4-fs: Journal does not support " 2766 ext4_msg(sb, KERN_ERR, "Journal does not support "
2708 "requested data journaling mode\n"); 2767 "requested data journaling mode");
2709 goto failed_mount4; 2768 goto failed_mount4;
2710 } 2769 }
2711 default: 2770 default:
@@ -2717,8 +2776,8 @@ no_journal:
2717 2776
2718 if (test_opt(sb, NOBH)) { 2777 if (test_opt(sb, NOBH)) {
2719 if (!(test_opt(sb, DATA_FLAGS) == EXT4_MOUNT_WRITEBACK_DATA)) { 2778 if (!(test_opt(sb, DATA_FLAGS) == EXT4_MOUNT_WRITEBACK_DATA)) {
2720 printk(KERN_WARNING "EXT4-fs: Ignoring nobh option - " 2779 ext4_msg(sb, KERN_WARNING, "Ignoring nobh option - "
2721 "its supported only with writeback mode\n"); 2780 "its supported only with writeback mode");
2722 clear_opt(sbi->s_mount_opt, NOBH); 2781 clear_opt(sbi->s_mount_opt, NOBH);
2723 } 2782 }
2724 } 2783 }
@@ -2729,18 +2788,18 @@ no_journal:
2729 2788
2730 root = ext4_iget(sb, EXT4_ROOT_INO); 2789 root = ext4_iget(sb, EXT4_ROOT_INO);
2731 if (IS_ERR(root)) { 2790 if (IS_ERR(root)) {
2732 printk(KERN_ERR "EXT4-fs: get root inode failed\n"); 2791 ext4_msg(sb, KERN_ERR, "get root inode failed");
2733 ret = PTR_ERR(root); 2792 ret = PTR_ERR(root);
2734 goto failed_mount4; 2793 goto failed_mount4;
2735 } 2794 }
2736 if (!S_ISDIR(root->i_mode) || !root->i_blocks || !root->i_size) { 2795 if (!S_ISDIR(root->i_mode) || !root->i_blocks || !root->i_size) {
2737 iput(root); 2796 iput(root);
2738 printk(KERN_ERR "EXT4-fs: corrupt root inode, run e2fsck\n"); 2797 ext4_msg(sb, KERN_ERR, "corrupt root inode, run e2fsck");
2739 goto failed_mount4; 2798 goto failed_mount4;
2740 } 2799 }
2741 sb->s_root = d_alloc_root(root); 2800 sb->s_root = d_alloc_root(root);
2742 if (!sb->s_root) { 2801 if (!sb->s_root) {
2743 printk(KERN_ERR "EXT4-fs: get root dentry failed\n"); 2802 ext4_msg(sb, KERN_ERR, "get root dentry failed");
2744 iput(root); 2803 iput(root);
2745 ret = -ENOMEM; 2804 ret = -ENOMEM;
2746 goto failed_mount4; 2805 goto failed_mount4;
@@ -2769,22 +2828,29 @@ no_journal:
2769 sbi->s_inode_size) { 2828 sbi->s_inode_size) {
2770 sbi->s_want_extra_isize = sizeof(struct ext4_inode) - 2829 sbi->s_want_extra_isize = sizeof(struct ext4_inode) -
2771 EXT4_GOOD_OLD_INODE_SIZE; 2830 EXT4_GOOD_OLD_INODE_SIZE;
2772 printk(KERN_INFO "EXT4-fs: required extra inode space not" 2831 ext4_msg(sb, KERN_INFO, "required extra inode space not"
2773 "available.\n"); 2832 "available");
2774 } 2833 }
2775 2834
2776 if (test_opt(sb, DATA_FLAGS) == EXT4_MOUNT_JOURNAL_DATA) { 2835 if (test_opt(sb, DATA_FLAGS) == EXT4_MOUNT_JOURNAL_DATA) {
2777 printk(KERN_WARNING "EXT4-fs: Ignoring delalloc option - " 2836 ext4_msg(sb, KERN_WARNING, "Ignoring delalloc option - "
2778 "requested data journaling mode\n"); 2837 "requested data journaling mode");
2779 clear_opt(sbi->s_mount_opt, DELALLOC); 2838 clear_opt(sbi->s_mount_opt, DELALLOC);
2780 } else if (test_opt(sb, DELALLOC)) 2839 } else if (test_opt(sb, DELALLOC))
2781 printk(KERN_INFO "EXT4-fs: delayed allocation enabled\n"); 2840 ext4_msg(sb, KERN_INFO, "delayed allocation enabled");
2841
2842 err = ext4_setup_system_zone(sb);
2843 if (err) {
2844 ext4_msg(sb, KERN_ERR, "failed to initialize system "
2845 "zone (%d)\n", err);
2846 goto failed_mount4;
2847 }
2782 2848
2783 ext4_ext_init(sb); 2849 ext4_ext_init(sb);
2784 err = ext4_mb_init(sb, needs_recovery); 2850 err = ext4_mb_init(sb, needs_recovery);
2785 if (err) { 2851 if (err) {
2786 printk(KERN_ERR "EXT4-fs: failed to initalize mballoc (%d)\n", 2852 ext4_msg(sb, KERN_ERR, "failed to initalize mballoc (%d)",
2787 err); 2853 err);
2788 goto failed_mount4; 2854 goto failed_mount4;
2789 } 2855 }
2790 2856
@@ -2798,19 +2864,11 @@ no_journal:
2798 goto failed_mount4; 2864 goto failed_mount4;
2799 }; 2865 };
2800 2866
2801 /*
2802 * akpm: core read_super() calls in here with the superblock locked.
2803 * That deadlocks, because orphan cleanup needs to lock the superblock
2804 * in numerous places. Here we just pop the lock - it's relatively
2805 * harmless, because we are now ready to accept write_super() requests,
2806 * and aviro says that's the only reason for hanging onto the
2807 * superblock lock.
2808 */
2809 EXT4_SB(sb)->s_mount_state |= EXT4_ORPHAN_FS; 2867 EXT4_SB(sb)->s_mount_state |= EXT4_ORPHAN_FS;
2810 ext4_orphan_cleanup(sb, es); 2868 ext4_orphan_cleanup(sb, es);
2811 EXT4_SB(sb)->s_mount_state &= ~EXT4_ORPHAN_FS; 2869 EXT4_SB(sb)->s_mount_state &= ~EXT4_ORPHAN_FS;
2812 if (needs_recovery) { 2870 if (needs_recovery) {
2813 printk(KERN_INFO "EXT4-fs: recovery complete.\n"); 2871 ext4_msg(sb, KERN_INFO, "recovery complete");
2814 ext4_mark_recovery_complete(sb, es); 2872 ext4_mark_recovery_complete(sb, es);
2815 } 2873 }
2816 if (EXT4_SB(sb)->s_journal) { 2874 if (EXT4_SB(sb)->s_journal) {
@@ -2823,25 +2881,30 @@ no_journal:
2823 } else 2881 } else
2824 descr = "out journal"; 2882 descr = "out journal";
2825 2883
2826 printk(KERN_INFO "EXT4-fs: mounted filesystem %s with%s\n", 2884 ext4_msg(sb, KERN_INFO, "mounted filesystem with%s", descr);
2827 sb->s_id, descr);
2828 2885
2829 lock_kernel(); 2886 lock_kernel();
2830 return 0; 2887 return 0;
2831 2888
2832cantfind_ext4: 2889cantfind_ext4:
2833 if (!silent) 2890 if (!silent)
2834 printk(KERN_ERR "VFS: Can't find ext4 filesystem on dev %s.\n", 2891 ext4_msg(sb, KERN_ERR, "VFS: Can't find ext4 filesystem");
2835 sb->s_id);
2836 goto failed_mount; 2892 goto failed_mount;
2837 2893
2838failed_mount4: 2894failed_mount4:
2839 printk(KERN_ERR "EXT4-fs (device %s): mount failed\n", sb->s_id); 2895 ext4_msg(sb, KERN_ERR, "mount failed");
2896 ext4_release_system_zone(sb);
2840 if (sbi->s_journal) { 2897 if (sbi->s_journal) {
2841 jbd2_journal_destroy(sbi->s_journal); 2898 jbd2_journal_destroy(sbi->s_journal);
2842 sbi->s_journal = NULL; 2899 sbi->s_journal = NULL;
2843 } 2900 }
2844failed_mount3: 2901failed_mount3:
2902 if (sbi->s_flex_groups) {
2903 if (is_vmalloc_addr(sbi->s_flex_groups))
2904 vfree(sbi->s_flex_groups);
2905 else
2906 kfree(sbi->s_flex_groups);
2907 }
2845 percpu_counter_destroy(&sbi->s_freeblocks_counter); 2908 percpu_counter_destroy(&sbi->s_freeblocks_counter);
2846 percpu_counter_destroy(&sbi->s_freeinodes_counter); 2909 percpu_counter_destroy(&sbi->s_freeinodes_counter);
2847 percpu_counter_destroy(&sbi->s_dirs_counter); 2910 percpu_counter_destroy(&sbi->s_dirs_counter);
@@ -2862,6 +2925,7 @@ failed_mount:
2862 brelse(bh); 2925 brelse(bh);
2863out_fail: 2926out_fail:
2864 sb->s_fs_info = NULL; 2927 sb->s_fs_info = NULL;
2928 kfree(sbi->s_blockgroup_lock);
2865 kfree(sbi); 2929 kfree(sbi);
2866 lock_kernel(); 2930 lock_kernel();
2867 return ret; 2931 return ret;
@@ -2906,27 +2970,27 @@ static journal_t *ext4_get_journal(struct super_block *sb,
2906 2970
2907 journal_inode = ext4_iget(sb, journal_inum); 2971 journal_inode = ext4_iget(sb, journal_inum);
2908 if (IS_ERR(journal_inode)) { 2972 if (IS_ERR(journal_inode)) {
2909 printk(KERN_ERR "EXT4-fs: no journal found.\n"); 2973 ext4_msg(sb, KERN_ERR, "no journal found");
2910 return NULL; 2974 return NULL;
2911 } 2975 }
2912 if (!journal_inode->i_nlink) { 2976 if (!journal_inode->i_nlink) {
2913 make_bad_inode(journal_inode); 2977 make_bad_inode(journal_inode);
2914 iput(journal_inode); 2978 iput(journal_inode);
2915 printk(KERN_ERR "EXT4-fs: journal inode is deleted.\n"); 2979 ext4_msg(sb, KERN_ERR, "journal inode is deleted");
2916 return NULL; 2980 return NULL;
2917 } 2981 }
2918 2982
2919 jbd_debug(2, "Journal inode found at %p: %lld bytes\n", 2983 jbd_debug(2, "Journal inode found at %p: %lld bytes\n",
2920 journal_inode, journal_inode->i_size); 2984 journal_inode, journal_inode->i_size);
2921 if (!S_ISREG(journal_inode->i_mode)) { 2985 if (!S_ISREG(journal_inode->i_mode)) {
2922 printk(KERN_ERR "EXT4-fs: invalid journal inode.\n"); 2986 ext4_msg(sb, KERN_ERR, "invalid journal inode");
2923 iput(journal_inode); 2987 iput(journal_inode);
2924 return NULL; 2988 return NULL;
2925 } 2989 }
2926 2990
2927 journal = jbd2_journal_init_inode(journal_inode); 2991 journal = jbd2_journal_init_inode(journal_inode);
2928 if (!journal) { 2992 if (!journal) {
2929 printk(KERN_ERR "EXT4-fs: Could not load journal inode\n"); 2993 ext4_msg(sb, KERN_ERR, "Could not load journal inode");
2930 iput(journal_inode); 2994 iput(journal_inode);
2931 return NULL; 2995 return NULL;
2932 } 2996 }
@@ -2950,22 +3014,22 @@ static journal_t *ext4_get_dev_journal(struct super_block *sb,
2950 3014
2951 BUG_ON(!EXT4_HAS_COMPAT_FEATURE(sb, EXT4_FEATURE_COMPAT_HAS_JOURNAL)); 3015 BUG_ON(!EXT4_HAS_COMPAT_FEATURE(sb, EXT4_FEATURE_COMPAT_HAS_JOURNAL));
2952 3016
2953 bdev = ext4_blkdev_get(j_dev); 3017 bdev = ext4_blkdev_get(j_dev, sb);
2954 if (bdev == NULL) 3018 if (bdev == NULL)
2955 return NULL; 3019 return NULL;
2956 3020
2957 if (bd_claim(bdev, sb)) { 3021 if (bd_claim(bdev, sb)) {
2958 printk(KERN_ERR 3022 ext4_msg(sb, KERN_ERR,
2959 "EXT4-fs: failed to claim external journal device.\n"); 3023 "failed to claim external journal device");
2960 blkdev_put(bdev, FMODE_READ|FMODE_WRITE); 3024 blkdev_put(bdev, FMODE_READ|FMODE_WRITE);
2961 return NULL; 3025 return NULL;
2962 } 3026 }
2963 3027
2964 blocksize = sb->s_blocksize; 3028 blocksize = sb->s_blocksize;
2965 hblock = bdev_hardsect_size(bdev); 3029 hblock = bdev_logical_block_size(bdev);
2966 if (blocksize < hblock) { 3030 if (blocksize < hblock) {
2967 printk(KERN_ERR 3031 ext4_msg(sb, KERN_ERR,
2968 "EXT4-fs: blocksize too small for journal device.\n"); 3032 "blocksize too small for journal device");
2969 goto out_bdev; 3033 goto out_bdev;
2970 } 3034 }
2971 3035
@@ -2973,8 +3037,8 @@ static journal_t *ext4_get_dev_journal(struct super_block *sb,
2973 offset = EXT4_MIN_BLOCK_SIZE % blocksize; 3037 offset = EXT4_MIN_BLOCK_SIZE % blocksize;
2974 set_blocksize(bdev, blocksize); 3038 set_blocksize(bdev, blocksize);
2975 if (!(bh = __bread(bdev, sb_block, blocksize))) { 3039 if (!(bh = __bread(bdev, sb_block, blocksize))) {
2976 printk(KERN_ERR "EXT4-fs: couldn't read superblock of " 3040 ext4_msg(sb, KERN_ERR, "couldn't read superblock of "
2977 "external journal\n"); 3041 "external journal");
2978 goto out_bdev; 3042 goto out_bdev;
2979 } 3043 }
2980 3044
@@ -2982,14 +3046,14 @@ static journal_t *ext4_get_dev_journal(struct super_block *sb,
2982 if ((le16_to_cpu(es->s_magic) != EXT4_SUPER_MAGIC) || 3046 if ((le16_to_cpu(es->s_magic) != EXT4_SUPER_MAGIC) ||
2983 !(le32_to_cpu(es->s_feature_incompat) & 3047 !(le32_to_cpu(es->s_feature_incompat) &
2984 EXT4_FEATURE_INCOMPAT_JOURNAL_DEV)) { 3048 EXT4_FEATURE_INCOMPAT_JOURNAL_DEV)) {
2985 printk(KERN_ERR "EXT4-fs: external journal has " 3049 ext4_msg(sb, KERN_ERR, "external journal has "
2986 "bad superblock\n"); 3050 "bad superblock");
2987 brelse(bh); 3051 brelse(bh);
2988 goto out_bdev; 3052 goto out_bdev;
2989 } 3053 }
2990 3054
2991 if (memcmp(EXT4_SB(sb)->s_es->s_journal_uuid, es->s_uuid, 16)) { 3055 if (memcmp(EXT4_SB(sb)->s_es->s_journal_uuid, es->s_uuid, 16)) {
2992 printk(KERN_ERR "EXT4-fs: journal UUID does not match\n"); 3056 ext4_msg(sb, KERN_ERR, "journal UUID does not match");
2993 brelse(bh); 3057 brelse(bh);
2994 goto out_bdev; 3058 goto out_bdev;
2995 } 3059 }
@@ -3001,25 +3065,26 @@ static journal_t *ext4_get_dev_journal(struct super_block *sb,
3001 journal = jbd2_journal_init_dev(bdev, sb->s_bdev, 3065 journal = jbd2_journal_init_dev(bdev, sb->s_bdev,
3002 start, len, blocksize); 3066 start, len, blocksize);
3003 if (!journal) { 3067 if (!journal) {
3004 printk(KERN_ERR "EXT4-fs: failed to create device journal\n"); 3068 ext4_msg(sb, KERN_ERR, "failed to create device journal");
3005 goto out_bdev; 3069 goto out_bdev;
3006 } 3070 }
3007 journal->j_private = sb; 3071 journal->j_private = sb;
3008 ll_rw_block(READ, 1, &journal->j_sb_buffer); 3072 ll_rw_block(READ, 1, &journal->j_sb_buffer);
3009 wait_on_buffer(journal->j_sb_buffer); 3073 wait_on_buffer(journal->j_sb_buffer);
3010 if (!buffer_uptodate(journal->j_sb_buffer)) { 3074 if (!buffer_uptodate(journal->j_sb_buffer)) {
3011 printk(KERN_ERR "EXT4-fs: I/O error on journal device\n"); 3075 ext4_msg(sb, KERN_ERR, "I/O error on journal device");
3012 goto out_journal; 3076 goto out_journal;
3013 } 3077 }
3014 if (be32_to_cpu(journal->j_superblock->s_nr_users) != 1) { 3078 if (be32_to_cpu(journal->j_superblock->s_nr_users) != 1) {
3015 printk(KERN_ERR "EXT4-fs: External journal has more than one " 3079 ext4_msg(sb, KERN_ERR, "External journal has more than one "
3016 "user (unsupported) - %d\n", 3080 "user (unsupported) - %d",
3017 be32_to_cpu(journal->j_superblock->s_nr_users)); 3081 be32_to_cpu(journal->j_superblock->s_nr_users));
3018 goto out_journal; 3082 goto out_journal;
3019 } 3083 }
3020 EXT4_SB(sb)->journal_bdev = bdev; 3084 EXT4_SB(sb)->journal_bdev = bdev;
3021 ext4_init_journal_params(sb, journal); 3085 ext4_init_journal_params(sb, journal);
3022 return journal; 3086 return journal;
3087
3023out_journal: 3088out_journal:
3024 jbd2_journal_destroy(journal); 3089 jbd2_journal_destroy(journal);
3025out_bdev: 3090out_bdev:
@@ -3041,8 +3106,8 @@ static int ext4_load_journal(struct super_block *sb,
3041 3106
3042 if (journal_devnum && 3107 if (journal_devnum &&
3043 journal_devnum != le32_to_cpu(es->s_journal_dev)) { 3108 journal_devnum != le32_to_cpu(es->s_journal_dev)) {
3044 printk(KERN_INFO "EXT4-fs: external journal device major/minor " 3109 ext4_msg(sb, KERN_INFO, "external journal device major/minor "
3045 "numbers have changed\n"); 3110 "numbers have changed");
3046 journal_dev = new_decode_dev(journal_devnum); 3111 journal_dev = new_decode_dev(journal_devnum);
3047 } else 3112 } else
3048 journal_dev = new_decode_dev(le32_to_cpu(es->s_journal_dev)); 3113 journal_dev = new_decode_dev(le32_to_cpu(es->s_journal_dev));
@@ -3054,24 +3119,23 @@ static int ext4_load_journal(struct super_block *sb,
3054 * crash? For recovery, we need to check in advance whether we 3119 * crash? For recovery, we need to check in advance whether we
3055 * can get read-write access to the device. 3120 * can get read-write access to the device.
3056 */ 3121 */
3057
3058 if (EXT4_HAS_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_RECOVER)) { 3122 if (EXT4_HAS_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_RECOVER)) {
3059 if (sb->s_flags & MS_RDONLY) { 3123 if (sb->s_flags & MS_RDONLY) {
3060 printk(KERN_INFO "EXT4-fs: INFO: recovery " 3124 ext4_msg(sb, KERN_INFO, "INFO: recovery "
3061 "required on readonly filesystem.\n"); 3125 "required on readonly filesystem");
3062 if (really_read_only) { 3126 if (really_read_only) {
3063 printk(KERN_ERR "EXT4-fs: write access " 3127 ext4_msg(sb, KERN_ERR, "write access "
3064 "unavailable, cannot proceed.\n"); 3128 "unavailable, cannot proceed");
3065 return -EROFS; 3129 return -EROFS;
3066 } 3130 }
3067 printk(KERN_INFO "EXT4-fs: write access will " 3131 ext4_msg(sb, KERN_INFO, "write access will "
3068 "be enabled during recovery.\n"); 3132 "be enabled during recovery");
3069 } 3133 }
3070 } 3134 }
3071 3135
3072 if (journal_inum && journal_dev) { 3136 if (journal_inum && journal_dev) {
3073 printk(KERN_ERR "EXT4-fs: filesystem has both journal " 3137 ext4_msg(sb, KERN_ERR, "filesystem has both journal "
3074 "and inode journals!\n"); 3138 "and inode journals!");
3075 return -EINVAL; 3139 return -EINVAL;
3076 } 3140 }
3077 3141
@@ -3084,14 +3148,14 @@ static int ext4_load_journal(struct super_block *sb,
3084 } 3148 }
3085 3149
3086 if (journal->j_flags & JBD2_BARRIER) 3150 if (journal->j_flags & JBD2_BARRIER)
3087 printk(KERN_INFO "EXT4-fs: barriers enabled\n"); 3151 ext4_msg(sb, KERN_INFO, "barriers enabled");
3088 else 3152 else
3089 printk(KERN_INFO "EXT4-fs: barriers disabled\n"); 3153 ext4_msg(sb, KERN_INFO, "barriers disabled");
3090 3154
3091 if (!really_read_only && test_opt(sb, UPDATE_JOURNAL)) { 3155 if (!really_read_only && test_opt(sb, UPDATE_JOURNAL)) {
3092 err = jbd2_journal_update_format(journal); 3156 err = jbd2_journal_update_format(journal);
3093 if (err) { 3157 if (err) {
3094 printk(KERN_ERR "EXT4-fs: error updating journal.\n"); 3158 ext4_msg(sb, KERN_ERR, "error updating journal");
3095 jbd2_journal_destroy(journal); 3159 jbd2_journal_destroy(journal);
3096 return err; 3160 return err;
3097 } 3161 }
@@ -3103,7 +3167,7 @@ static int ext4_load_journal(struct super_block *sb,
3103 err = jbd2_journal_load(journal); 3167 err = jbd2_journal_load(journal);
3104 3168
3105 if (err) { 3169 if (err) {
3106 printk(KERN_ERR "EXT4-fs: error loading journal.\n"); 3170 ext4_msg(sb, KERN_ERR, "error loading journal");
3107 jbd2_journal_destroy(journal); 3171 jbd2_journal_destroy(journal);
3108 return err; 3172 return err;
3109 } 3173 }
@@ -3114,18 +3178,17 @@ static int ext4_load_journal(struct super_block *sb,
3114 if (journal_devnum && 3178 if (journal_devnum &&
3115 journal_devnum != le32_to_cpu(es->s_journal_dev)) { 3179 journal_devnum != le32_to_cpu(es->s_journal_dev)) {
3116 es->s_journal_dev = cpu_to_le32(journal_devnum); 3180 es->s_journal_dev = cpu_to_le32(journal_devnum);
3117 sb->s_dirt = 1;
3118 3181
3119 /* Make sure we flush the recovery flag to disk. */ 3182 /* Make sure we flush the recovery flag to disk. */
3120 ext4_commit_super(sb, es, 1); 3183 ext4_commit_super(sb, 1);
3121 } 3184 }
3122 3185
3123 return 0; 3186 return 0;
3124} 3187}
3125 3188
3126static int ext4_commit_super(struct super_block *sb, 3189static int ext4_commit_super(struct super_block *sb, int sync)
3127 struct ext4_super_block *es, int sync)
3128{ 3190{
3191 struct ext4_super_block *es = EXT4_SB(sb)->s_es;
3129 struct buffer_head *sbh = EXT4_SB(sb)->s_sbh; 3192 struct buffer_head *sbh = EXT4_SB(sb)->s_sbh;
3130 int error = 0; 3193 int error = 0;
3131 3194
@@ -3140,8 +3203,8 @@ static int ext4_commit_super(struct super_block *sb,
3140 * be remapped. Nothing we can do but to retry the 3203 * be remapped. Nothing we can do but to retry the
3141 * write and hope for the best. 3204 * write and hope for the best.
3142 */ 3205 */
3143 printk(KERN_ERR "EXT4-fs: previous I/O error to " 3206 ext4_msg(sb, KERN_ERR, "previous I/O error to "
3144 "superblock detected for %s.\n", sb->s_id); 3207 "superblock detected");
3145 clear_buffer_write_io_error(sbh); 3208 clear_buffer_write_io_error(sbh);
3146 set_buffer_uptodate(sbh); 3209 set_buffer_uptodate(sbh);
3147 } 3210 }
@@ -3154,7 +3217,7 @@ static int ext4_commit_super(struct super_block *sb,
3154 &EXT4_SB(sb)->s_freeblocks_counter)); 3217 &EXT4_SB(sb)->s_freeblocks_counter));
3155 es->s_free_inodes_count = cpu_to_le32(percpu_counter_sum_positive( 3218 es->s_free_inodes_count = cpu_to_le32(percpu_counter_sum_positive(
3156 &EXT4_SB(sb)->s_freeinodes_counter)); 3219 &EXT4_SB(sb)->s_freeinodes_counter));
3157 3220 sb->s_dirt = 0;
3158 BUFFER_TRACE(sbh, "marking dirty"); 3221 BUFFER_TRACE(sbh, "marking dirty");
3159 mark_buffer_dirty(sbh); 3222 mark_buffer_dirty(sbh);
3160 if (sync) { 3223 if (sync) {
@@ -3164,8 +3227,8 @@ static int ext4_commit_super(struct super_block *sb,
3164 3227
3165 error = buffer_write_io_error(sbh); 3228 error = buffer_write_io_error(sbh);
3166 if (error) { 3229 if (error) {
3167 printk(KERN_ERR "EXT4-fs: I/O error while writing " 3230 ext4_msg(sb, KERN_ERR, "I/O error while writing "
3168 "superblock for %s.\n", sb->s_id); 3231 "superblock");
3169 clear_buffer_write_io_error(sbh); 3232 clear_buffer_write_io_error(sbh);
3170 set_buffer_uptodate(sbh); 3233 set_buffer_uptodate(sbh);
3171 } 3234 }
@@ -3173,7 +3236,6 @@ static int ext4_commit_super(struct super_block *sb,
3173 return error; 3236 return error;
3174} 3237}
3175 3238
3176
3177/* 3239/*
3178 * Have we just finished recovery? If so, and if we are mounting (or 3240 * Have we just finished recovery? If so, and if we are mounting (or
3179 * remounting) the filesystem readonly, then we will end up with a 3241 * remounting) the filesystem readonly, then we will end up with a
@@ -3192,14 +3254,11 @@ static void ext4_mark_recovery_complete(struct super_block *sb,
3192 if (jbd2_journal_flush(journal) < 0) 3254 if (jbd2_journal_flush(journal) < 0)
3193 goto out; 3255 goto out;
3194 3256
3195 lock_super(sb);
3196 if (EXT4_HAS_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_RECOVER) && 3257 if (EXT4_HAS_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_RECOVER) &&
3197 sb->s_flags & MS_RDONLY) { 3258 sb->s_flags & MS_RDONLY) {
3198 EXT4_CLEAR_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_RECOVER); 3259 EXT4_CLEAR_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_RECOVER);
3199 sb->s_dirt = 0; 3260 ext4_commit_super(sb, 1);
3200 ext4_commit_super(sb, es, 1);
3201 } 3261 }
3202 unlock_super(sb);
3203 3262
3204out: 3263out:
3205 jbd2_journal_unlock_updates(journal); 3264 jbd2_journal_unlock_updates(journal);
@@ -3238,7 +3297,7 @@ static void ext4_clear_journal_err(struct super_block *sb,
3238 3297
3239 EXT4_SB(sb)->s_mount_state |= EXT4_ERROR_FS; 3298 EXT4_SB(sb)->s_mount_state |= EXT4_ERROR_FS;
3240 es->s_state |= cpu_to_le16(EXT4_ERROR_FS); 3299 es->s_state |= cpu_to_le16(EXT4_ERROR_FS);
3241 ext4_commit_super(sb, es, 1); 3300 ext4_commit_super(sb, 1);
3242 3301
3243 jbd2_journal_clear_err(journal); 3302 jbd2_journal_clear_err(journal);
3244 } 3303 }
@@ -3257,29 +3316,17 @@ int ext4_force_commit(struct super_block *sb)
3257 return 0; 3316 return 0;
3258 3317
3259 journal = EXT4_SB(sb)->s_journal; 3318 journal = EXT4_SB(sb)->s_journal;
3260 if (journal) { 3319 if (journal)
3261 sb->s_dirt = 0;
3262 ret = ext4_journal_force_commit(journal); 3320 ret = ext4_journal_force_commit(journal);
3263 }
3264 3321
3265 return ret; 3322 return ret;
3266} 3323}
3267 3324
3268/*
3269 * Ext4 always journals updates to the superblock itself, so we don't
3270 * have to propagate any other updates to the superblock on disk at this
3271 * point. (We can probably nuke this function altogether, and remove
3272 * any mention to sb->s_dirt in all of fs/ext4; eventual cleanup...)
3273 */
3274static void ext4_write_super(struct super_block *sb) 3325static void ext4_write_super(struct super_block *sb)
3275{ 3326{
3276 if (EXT4_SB(sb)->s_journal) { 3327 lock_super(sb);
3277 if (mutex_trylock(&sb->s_lock) != 0) 3328 ext4_commit_super(sb, 1);
3278 BUG(); 3329 unlock_super(sb);
3279 sb->s_dirt = 0;
3280 } else {
3281 ext4_commit_super(sb, EXT4_SB(sb)->s_es, 1);
3282 }
3283} 3330}
3284 3331
3285static int ext4_sync_fs(struct super_block *sb, int wait) 3332static int ext4_sync_fs(struct super_block *sb, int wait)
@@ -3287,17 +3334,10 @@ static int ext4_sync_fs(struct super_block *sb, int wait)
3287 int ret = 0; 3334 int ret = 0;
3288 tid_t target; 3335 tid_t target;
3289 3336
3290 trace_mark(ext4_sync_fs, "dev %s wait %d", sb->s_id, wait); 3337 trace_ext4_sync_fs(sb, wait);
3291 sb->s_dirt = 0; 3338 if (jbd2_journal_start_commit(EXT4_SB(sb)->s_journal, &target)) {
3292 if (EXT4_SB(sb)->s_journal) { 3339 if (wait)
3293 if (jbd2_journal_start_commit(EXT4_SB(sb)->s_journal, 3340 jbd2_log_wait_commit(EXT4_SB(sb)->s_journal, target);
3294 &target)) {
3295 if (wait)
3296 jbd2_log_wait_commit(EXT4_SB(sb)->s_journal,
3297 target);
3298 }
3299 } else {
3300 ext4_commit_super(sb, EXT4_SB(sb)->s_es, wait);
3301 } 3341 }
3302 return ret; 3342 return ret;
3303} 3343}
@@ -3310,34 +3350,32 @@ static int ext4_freeze(struct super_block *sb)
3310{ 3350{
3311 int error = 0; 3351 int error = 0;
3312 journal_t *journal; 3352 journal_t *journal;
3313 sb->s_dirt = 0;
3314 3353
3315 if (!(sb->s_flags & MS_RDONLY)) { 3354 if (sb->s_flags & MS_RDONLY)
3316 journal = EXT4_SB(sb)->s_journal; 3355 return 0;
3317 3356
3318 if (journal) { 3357 journal = EXT4_SB(sb)->s_journal;
3319 /* Now we set up the journal barrier. */
3320 jbd2_journal_lock_updates(journal);
3321 3358
3322 /* 3359 /* Now we set up the journal barrier. */
3323 * We don't want to clear needs_recovery flag when we 3360 jbd2_journal_lock_updates(journal);
3324 * failed to flush the journal.
3325 */
3326 error = jbd2_journal_flush(journal);
3327 if (error < 0)
3328 goto out;
3329 }
3330 3361
3331 /* Journal blocked and flushed, clear needs_recovery flag. */ 3362 /*
3332 EXT4_CLEAR_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_RECOVER); 3363 * Don't clear the needs_recovery flag if we failed to flush
3333 error = ext4_commit_super(sb, EXT4_SB(sb)->s_es, 1); 3364 * the journal.
3334 if (error) 3365 */
3335 goto out; 3366 error = jbd2_journal_flush(journal);
3367 if (error < 0) {
3368 out:
3369 jbd2_journal_unlock_updates(journal);
3370 return error;
3336 } 3371 }
3372
3373 /* Journal blocked and flushed, clear needs_recovery flag. */
3374 EXT4_CLEAR_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_RECOVER);
3375 error = ext4_commit_super(sb, 1);
3376 if (error)
3377 goto out;
3337 return 0; 3378 return 0;
3338out:
3339 jbd2_journal_unlock_updates(journal);
3340 return error;
3341} 3379}
3342 3380
3343/* 3381/*
@@ -3346,14 +3384,15 @@ out:
3346 */ 3384 */
3347static int ext4_unfreeze(struct super_block *sb) 3385static int ext4_unfreeze(struct super_block *sb)
3348{ 3386{
3349 if (EXT4_SB(sb)->s_journal && !(sb->s_flags & MS_RDONLY)) { 3387 if (sb->s_flags & MS_RDONLY)
3350 lock_super(sb); 3388 return 0;
3351 /* Reser the needs_recovery flag before the fs is unlocked. */ 3389
3352 EXT4_SET_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_RECOVER); 3390 lock_super(sb);
3353 ext4_commit_super(sb, EXT4_SB(sb)->s_es, 1); 3391 /* Reset the needs_recovery flag before the fs is unlocked. */
3354 unlock_super(sb); 3392 EXT4_SET_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_RECOVER);
3355 jbd2_journal_unlock_updates(EXT4_SB(sb)->s_journal); 3393 ext4_commit_super(sb, 1);
3356 } 3394 unlock_super(sb);
3395 jbd2_journal_unlock_updates(EXT4_SB(sb)->s_journal);
3357 return 0; 3396 return 0;
3358} 3397}
3359 3398
@@ -3371,7 +3410,10 @@ static int ext4_remount(struct super_block *sb, int *flags, char *data)
3371 int i; 3410 int i;
3372#endif 3411#endif
3373 3412
3413 lock_kernel();
3414
3374 /* Store the original options */ 3415 /* Store the original options */
3416 lock_super(sb);
3375 old_sb_flags = sb->s_flags; 3417 old_sb_flags = sb->s_flags;
3376 old_opts.s_mount_opt = sbi->s_mount_opt; 3418 old_opts.s_mount_opt = sbi->s_mount_opt;
3377 old_opts.s_resuid = sbi->s_resuid; 3419 old_opts.s_resuid = sbi->s_resuid;
@@ -3396,7 +3438,7 @@ static int ext4_remount(struct super_block *sb, int *flags, char *data)
3396 goto restore_opts; 3438 goto restore_opts;
3397 } 3439 }
3398 3440
3399 if (sbi->s_mount_opt & EXT4_MOUNT_ABORT) 3441 if (sbi->s_mount_flags & EXT4_MF_FS_ABORTED)
3400 ext4_abort(sb, __func__, "Abort forced by user"); 3442 ext4_abort(sb, __func__, "Abort forced by user");
3401 3443
3402 sb->s_flags = (sb->s_flags & ~MS_POSIXACL) | 3444 sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
@@ -3411,7 +3453,7 @@ static int ext4_remount(struct super_block *sb, int *flags, char *data)
3411 3453
3412 if ((*flags & MS_RDONLY) != (sb->s_flags & MS_RDONLY) || 3454 if ((*flags & MS_RDONLY) != (sb->s_flags & MS_RDONLY) ||
3413 n_blocks_count > ext4_blocks_count(es)) { 3455 n_blocks_count > ext4_blocks_count(es)) {
3414 if (sbi->s_mount_opt & EXT4_MOUNT_ABORT) { 3456 if (sbi->s_mount_flags & EXT4_MF_FS_ABORTED) {
3415 err = -EROFS; 3457 err = -EROFS;
3416 goto restore_opts; 3458 goto restore_opts;
3417 } 3459 }
@@ -3432,22 +3474,15 @@ static int ext4_remount(struct super_block *sb, int *flags, char *data)
3432 (sbi->s_mount_state & EXT4_VALID_FS)) 3474 (sbi->s_mount_state & EXT4_VALID_FS))
3433 es->s_state = cpu_to_le16(sbi->s_mount_state); 3475 es->s_state = cpu_to_le16(sbi->s_mount_state);
3434 3476
3435 /* 3477 if (sbi->s_journal)
3436 * We have to unlock super so that we can wait for
3437 * transactions.
3438 */
3439 if (sbi->s_journal) {
3440 unlock_super(sb);
3441 ext4_mark_recovery_complete(sb, es); 3478 ext4_mark_recovery_complete(sb, es);
3442 lock_super(sb);
3443 }
3444 } else { 3479 } else {
3445 int ret; 3480 int ret;
3446 if ((ret = EXT4_HAS_RO_COMPAT_FEATURE(sb, 3481 if ((ret = EXT4_HAS_RO_COMPAT_FEATURE(sb,
3447 ~EXT4_FEATURE_RO_COMPAT_SUPP))) { 3482 ~EXT4_FEATURE_RO_COMPAT_SUPP))) {
3448 printk(KERN_WARNING "EXT4-fs: %s: couldn't " 3483 ext4_msg(sb, KERN_WARNING, "couldn't "
3449 "remount RDWR because of unsupported " 3484 "remount RDWR because of unsupported "
3450 "optional features (%x).\n", sb->s_id, 3485 "optional features (%x)",
3451 (le32_to_cpu(sbi->s_es->s_feature_ro_compat) & 3486 (le32_to_cpu(sbi->s_es->s_feature_ro_compat) &
3452 ~EXT4_FEATURE_RO_COMPAT_SUPP)); 3487 ~EXT4_FEATURE_RO_COMPAT_SUPP));
3453 err = -EROFS; 3488 err = -EROFS;
@@ -3456,17 +3491,15 @@ static int ext4_remount(struct super_block *sb, int *flags, char *data)
3456 3491
3457 /* 3492 /*
3458 * Make sure the group descriptor checksums 3493 * Make sure the group descriptor checksums
3459 * are sane. If they aren't, refuse to 3494 * are sane. If they aren't, refuse to remount r/w.
3460 * remount r/w.
3461 */ 3495 */
3462 for (g = 0; g < sbi->s_groups_count; g++) { 3496 for (g = 0; g < sbi->s_groups_count; g++) {
3463 struct ext4_group_desc *gdp = 3497 struct ext4_group_desc *gdp =
3464 ext4_get_group_desc(sb, g, NULL); 3498 ext4_get_group_desc(sb, g, NULL);
3465 3499
3466 if (!ext4_group_desc_csum_verify(sbi, g, gdp)) { 3500 if (!ext4_group_desc_csum_verify(sbi, g, gdp)) {
3467 printk(KERN_ERR 3501 ext4_msg(sb, KERN_ERR,
3468 "EXT4-fs: ext4_remount: " 3502 "ext4_remount: Checksum for group %u failed (%u!=%u)",
3469 "Checksum for group %u failed (%u!=%u)\n",
3470 g, le16_to_cpu(ext4_group_desc_csum(sbi, g, gdp)), 3503 g, le16_to_cpu(ext4_group_desc_csum(sbi, g, gdp)),
3471 le16_to_cpu(gdp->bg_checksum)); 3504 le16_to_cpu(gdp->bg_checksum));
3472 err = -EINVAL; 3505 err = -EINVAL;
@@ -3480,11 +3513,10 @@ static int ext4_remount(struct super_block *sb, int *flags, char *data)
3480 * require a full umount/remount for now. 3513 * require a full umount/remount for now.
3481 */ 3514 */
3482 if (es->s_last_orphan) { 3515 if (es->s_last_orphan) {
3483 printk(KERN_WARNING "EXT4-fs: %s: couldn't " 3516 ext4_msg(sb, KERN_WARNING, "Couldn't "
3484 "remount RDWR because of unprocessed " 3517 "remount RDWR because of unprocessed "
3485 "orphan inode list. Please " 3518 "orphan inode list. Please "
3486 "umount/remount instead.\n", 3519 "umount/remount instead");
3487 sb->s_id);
3488 err = -EINVAL; 3520 err = -EINVAL;
3489 goto restore_opts; 3521 goto restore_opts;
3490 } 3522 }
@@ -3504,8 +3536,9 @@ static int ext4_remount(struct super_block *sb, int *flags, char *data)
3504 sb->s_flags &= ~MS_RDONLY; 3536 sb->s_flags &= ~MS_RDONLY;
3505 } 3537 }
3506 } 3538 }
3539 ext4_setup_system_zone(sb);
3507 if (sbi->s_journal == NULL) 3540 if (sbi->s_journal == NULL)
3508 ext4_commit_super(sb, es, 1); 3541 ext4_commit_super(sb, 1);
3509 3542
3510#ifdef CONFIG_QUOTA 3543#ifdef CONFIG_QUOTA
3511 /* Release old quota file names */ 3544 /* Release old quota file names */
@@ -3514,7 +3547,10 @@ static int ext4_remount(struct super_block *sb, int *flags, char *data)
3514 old_opts.s_qf_names[i] != sbi->s_qf_names[i]) 3547 old_opts.s_qf_names[i] != sbi->s_qf_names[i])
3515 kfree(old_opts.s_qf_names[i]); 3548 kfree(old_opts.s_qf_names[i]);
3516#endif 3549#endif
3550 unlock_super(sb);
3551 unlock_kernel();
3517 return 0; 3552 return 0;
3553
3518restore_opts: 3554restore_opts:
3519 sb->s_flags = old_sb_flags; 3555 sb->s_flags = old_sb_flags;
3520 sbi->s_mount_opt = old_opts.s_mount_opt; 3556 sbi->s_mount_opt = old_opts.s_mount_opt;
@@ -3532,6 +3568,8 @@ restore_opts:
3532 sbi->s_qf_names[i] = old_opts.s_qf_names[i]; 3568 sbi->s_qf_names[i] = old_opts.s_qf_names[i];
3533 } 3569 }
3534#endif 3570#endif
3571 unlock_super(sb);
3572 unlock_kernel();
3535 return err; 3573 return err;
3536} 3574}
3537 3575
@@ -3545,9 +3583,8 @@ static int ext4_statfs(struct dentry *dentry, struct kstatfs *buf)
3545 if (test_opt(sb, MINIX_DF)) { 3583 if (test_opt(sb, MINIX_DF)) {
3546 sbi->s_overhead_last = 0; 3584 sbi->s_overhead_last = 0;
3547 } else if (sbi->s_blocks_last != ext4_blocks_count(es)) { 3585 } else if (sbi->s_blocks_last != ext4_blocks_count(es)) {
3548 ext4_group_t ngroups = sbi->s_groups_count, i; 3586 ext4_group_t i, ngroups = ext4_get_groups_count(sb);
3549 ext4_fsblk_t overhead = 0; 3587 ext4_fsblk_t overhead = 0;
3550 smp_rmb();
3551 3588
3552 /* 3589 /*
3553 * Compute the overhead (FS structures). This is constant 3590 * Compute the overhead (FS structures). This is constant
@@ -3599,11 +3636,12 @@ static int ext4_statfs(struct dentry *dentry, struct kstatfs *buf)
3599 le64_to_cpup((void *)es->s_uuid + sizeof(u64)); 3636 le64_to_cpup((void *)es->s_uuid + sizeof(u64));
3600 buf->f_fsid.val[0] = fsid & 0xFFFFFFFFUL; 3637 buf->f_fsid.val[0] = fsid & 0xFFFFFFFFUL;
3601 buf->f_fsid.val[1] = (fsid >> 32) & 0xFFFFFFFFUL; 3638 buf->f_fsid.val[1] = (fsid >> 32) & 0xFFFFFFFFUL;
3639
3602 return 0; 3640 return 0;
3603} 3641}
3604 3642
3605/* Helper function for writing quotas on sync - we need to start transaction before quota file 3643/* Helper function for writing quotas on sync - we need to start transaction
3606 * is locked for write. Otherwise the are possible deadlocks: 3644 * before quota file is locked for write. Otherwise the are possible deadlocks:
3607 * Process 1 Process 2 3645 * Process 1 Process 2
3608 * ext4_create() quota_sync() 3646 * ext4_create() quota_sync()
3609 * jbd2_journal_start() write_dquot() 3647 * jbd2_journal_start() write_dquot()
@@ -3627,7 +3665,7 @@ static int ext4_write_dquot(struct dquot *dquot)
3627 3665
3628 inode = dquot_to_inode(dquot); 3666 inode = dquot_to_inode(dquot);
3629 handle = ext4_journal_start(inode, 3667 handle = ext4_journal_start(inode,
3630 EXT4_QUOTA_TRANS_BLOCKS(dquot->dq_sb)); 3668 EXT4_QUOTA_TRANS_BLOCKS(dquot->dq_sb));
3631 if (IS_ERR(handle)) 3669 if (IS_ERR(handle))
3632 return PTR_ERR(handle); 3670 return PTR_ERR(handle);
3633 ret = dquot_commit(dquot); 3671 ret = dquot_commit(dquot);
@@ -3643,7 +3681,7 @@ static int ext4_acquire_dquot(struct dquot *dquot)
3643 handle_t *handle; 3681 handle_t *handle;
3644 3682
3645 handle = ext4_journal_start(dquot_to_inode(dquot), 3683 handle = ext4_journal_start(dquot_to_inode(dquot),
3646 EXT4_QUOTA_INIT_BLOCKS(dquot->dq_sb)); 3684 EXT4_QUOTA_INIT_BLOCKS(dquot->dq_sb));
3647 if (IS_ERR(handle)) 3685 if (IS_ERR(handle))
3648 return PTR_ERR(handle); 3686 return PTR_ERR(handle);
3649 ret = dquot_acquire(dquot); 3687 ret = dquot_acquire(dquot);
@@ -3659,7 +3697,7 @@ static int ext4_release_dquot(struct dquot *dquot)
3659 handle_t *handle; 3697 handle_t *handle;
3660 3698
3661 handle = ext4_journal_start(dquot_to_inode(dquot), 3699 handle = ext4_journal_start(dquot_to_inode(dquot),
3662 EXT4_QUOTA_DEL_BLOCKS(dquot->dq_sb)); 3700 EXT4_QUOTA_DEL_BLOCKS(dquot->dq_sb));
3663 if (IS_ERR(handle)) { 3701 if (IS_ERR(handle)) {
3664 /* Release dquot anyway to avoid endless cycle in dqput() */ 3702 /* Release dquot anyway to avoid endless cycle in dqput() */
3665 dquot_release(dquot); 3703 dquot_release(dquot);
@@ -3707,7 +3745,7 @@ static int ext4_write_info(struct super_block *sb, int type)
3707static int ext4_quota_on_mount(struct super_block *sb, int type) 3745static int ext4_quota_on_mount(struct super_block *sb, int type)
3708{ 3746{
3709 return vfs_quota_on_mount(sb, EXT4_SB(sb)->s_qf_names[type], 3747 return vfs_quota_on_mount(sb, EXT4_SB(sb)->s_qf_names[type],
3710 EXT4_SB(sb)->s_jquota_fmt, type); 3748 EXT4_SB(sb)->s_jquota_fmt, type);
3711} 3749}
3712 3750
3713/* 3751/*
@@ -3738,9 +3776,9 @@ static int ext4_quota_on(struct super_block *sb, int type, int format_id,
3738 if (EXT4_SB(sb)->s_qf_names[type]) { 3776 if (EXT4_SB(sb)->s_qf_names[type]) {
3739 /* Quotafile not in fs root? */ 3777 /* Quotafile not in fs root? */
3740 if (path.dentry->d_parent != sb->s_root) 3778 if (path.dentry->d_parent != sb->s_root)
3741 printk(KERN_WARNING 3779 ext4_msg(sb, KERN_WARNING,
3742 "EXT4-fs: Quota file not on filesystem root. " 3780 "Quota file not on filesystem root. "
3743 "Journaled quota will not work.\n"); 3781 "Journaled quota will not work");
3744 } 3782 }
3745 3783
3746 /* 3784 /*
@@ -3823,8 +3861,8 @@ static ssize_t ext4_quota_write(struct super_block *sb, int type,
3823 handle_t *handle = journal_current_handle(); 3861 handle_t *handle = journal_current_handle();
3824 3862
3825 if (EXT4_SB(sb)->s_journal && !handle) { 3863 if (EXT4_SB(sb)->s_journal && !handle) {
3826 printk(KERN_WARNING "EXT4-fs: Quota write (off=%llu, len=%llu)" 3864 ext4_msg(sb, KERN_WARNING, "Quota write (off=%llu, len=%llu)"
3827 " cancelled because transaction is not started.\n", 3865 " cancelled because transaction is not started",
3828 (unsigned long long)off, (unsigned long long)len); 3866 (unsigned long long)off, (unsigned long long)len);
3829 return -EIO; 3867 return -EIO;
3830 } 3868 }
@@ -3878,10 +3916,10 @@ out:
3878 3916
3879#endif 3917#endif
3880 3918
3881static int ext4_get_sb(struct file_system_type *fs_type, 3919static int ext4_get_sb(struct file_system_type *fs_type, int flags,
3882 int flags, const char *dev_name, void *data, struct vfsmount *mnt) 3920 const char *dev_name, void *data, struct vfsmount *mnt)
3883{ 3921{
3884 return get_sb_bdev(fs_type, flags, dev_name, data, ext4_fill_super, mnt); 3922 return get_sb_bdev(fs_type, flags, dev_name, data, ext4_fill_super,mnt);
3885} 3923}
3886 3924
3887static struct file_system_type ext4_fs_type = { 3925static struct file_system_type ext4_fs_type = {
@@ -3893,14 +3931,14 @@ static struct file_system_type ext4_fs_type = {
3893}; 3931};
3894 3932
3895#ifdef CONFIG_EXT4DEV_COMPAT 3933#ifdef CONFIG_EXT4DEV_COMPAT
3896static int ext4dev_get_sb(struct file_system_type *fs_type, 3934static int ext4dev_get_sb(struct file_system_type *fs_type, int flags,
3897 int flags, const char *dev_name, void *data, struct vfsmount *mnt) 3935 const char *dev_name, void *data,struct vfsmount *mnt)
3898{ 3936{
3899 printk(KERN_WARNING "EXT4-fs: Update your userspace programs " 3937 printk(KERN_WARNING "EXT4-fs (%s): Update your userspace programs "
3900 "to mount using ext4\n"); 3938 "to mount using ext4\n", dev_name);
3901 printk(KERN_WARNING "EXT4-fs: ext4dev backwards compatibility " 3939 printk(KERN_WARNING "EXT4-fs (%s): ext4dev backwards compatibility "
3902 "will go away by 2.6.31\n"); 3940 "will go away by 2.6.31\n", dev_name);
3903 return get_sb_bdev(fs_type, flags, dev_name, data, ext4_fill_super, mnt); 3941 return get_sb_bdev(fs_type, flags, dev_name, data, ext4_fill_super,mnt);
3904} 3942}
3905 3943
3906static struct file_system_type ext4dev_fs_type = { 3944static struct file_system_type ext4dev_fs_type = {
@@ -3917,13 +3955,16 @@ static int __init init_ext4_fs(void)
3917{ 3955{
3918 int err; 3956 int err;
3919 3957
3958 err = init_ext4_system_zone();
3959 if (err)
3960 return err;
3920 ext4_kset = kset_create_and_add("ext4", NULL, fs_kobj); 3961 ext4_kset = kset_create_and_add("ext4", NULL, fs_kobj);
3921 if (!ext4_kset) 3962 if (!ext4_kset)
3922 return -ENOMEM; 3963 goto out4;
3923 ext4_proc_root = proc_mkdir("fs/ext4", NULL); 3964 ext4_proc_root = proc_mkdir("fs/ext4", NULL);
3924 err = init_ext4_mballoc(); 3965 err = init_ext4_mballoc();
3925 if (err) 3966 if (err)
3926 return err; 3967 goto out3;
3927 3968
3928 err = init_ext4_xattr(); 3969 err = init_ext4_xattr();
3929 if (err) 3970 if (err)
@@ -3948,6 +3989,11 @@ out1:
3948 exit_ext4_xattr(); 3989 exit_ext4_xattr();
3949out2: 3990out2:
3950 exit_ext4_mballoc(); 3991 exit_ext4_mballoc();
3992out3:
3993 remove_proc_entry("fs/ext4", NULL);
3994 kset_unregister(ext4_kset);
3995out4:
3996 exit_ext4_system_zone();
3951 return err; 3997 return err;
3952} 3998}
3953 3999
@@ -3962,6 +4008,7 @@ static void __exit exit_ext4_fs(void)
3962 exit_ext4_mballoc(); 4008 exit_ext4_mballoc();
3963 remove_proc_entry("fs/ext4", NULL); 4009 remove_proc_entry("fs/ext4", NULL);
3964 kset_unregister(ext4_kset); 4010 kset_unregister(ext4_kset);
4011 exit_ext4_system_zone();
3965} 4012}
3966 4013
3967MODULE_AUTHOR("Remy Card, Stephen Tweedie, Andrew Morton, Andreas Dilger, Theodore Ts'o and others"); 4014MODULE_AUTHOR("Remy Card, Stephen Tweedie, Andrew Morton, Andreas Dilger, Theodore Ts'o and others");