diff options
Diffstat (limited to 'fs/ext4/super.c')
-rw-r--r-- | fs/ext4/super.c | 622 |
1 files changed, 394 insertions, 228 deletions
diff --git a/fs/ext4/super.c b/fs/ext4/super.c index 9494bb249390..8f7e0be8ab1b 100644 --- a/fs/ext4/super.c +++ b/fs/ext4/super.c | |||
@@ -51,8 +51,6 @@ struct proc_dir_entry *ext4_proc_root; | |||
51 | 51 | ||
52 | static int ext4_load_journal(struct super_block *, struct ext4_super_block *, | 52 | static int ext4_load_journal(struct super_block *, struct ext4_super_block *, |
53 | unsigned long journal_devnum); | 53 | unsigned long journal_devnum); |
54 | static int ext4_create_journal(struct super_block *, struct ext4_super_block *, | ||
55 | unsigned int); | ||
56 | static void ext4_commit_super(struct super_block *sb, | 54 | static void ext4_commit_super(struct super_block *sb, |
57 | struct ext4_super_block *es, int sync); | 55 | struct ext4_super_block *es, int sync); |
58 | static void ext4_mark_recovery_complete(struct super_block *sb, | 56 | static void ext4_mark_recovery_complete(struct super_block *sb, |
@@ -93,6 +91,38 @@ ext4_fsblk_t ext4_inode_table(struct super_block *sb, | |||
93 | (ext4_fsblk_t)le32_to_cpu(bg->bg_inode_table_hi) << 32 : 0); | 91 | (ext4_fsblk_t)le32_to_cpu(bg->bg_inode_table_hi) << 32 : 0); |
94 | } | 92 | } |
95 | 93 | ||
94 | __u32 ext4_free_blks_count(struct super_block *sb, | ||
95 | struct ext4_group_desc *bg) | ||
96 | { | ||
97 | return le16_to_cpu(bg->bg_free_blocks_count_lo) | | ||
98 | (EXT4_DESC_SIZE(sb) >= EXT4_MIN_DESC_SIZE_64BIT ? | ||
99 | (__u32)le16_to_cpu(bg->bg_free_blocks_count_hi) << 16 : 0); | ||
100 | } | ||
101 | |||
102 | __u32 ext4_free_inodes_count(struct super_block *sb, | ||
103 | struct ext4_group_desc *bg) | ||
104 | { | ||
105 | return le16_to_cpu(bg->bg_free_inodes_count_lo) | | ||
106 | (EXT4_DESC_SIZE(sb) >= EXT4_MIN_DESC_SIZE_64BIT ? | ||
107 | (__u32)le16_to_cpu(bg->bg_free_inodes_count_hi) << 16 : 0); | ||
108 | } | ||
109 | |||
110 | __u32 ext4_used_dirs_count(struct super_block *sb, | ||
111 | struct ext4_group_desc *bg) | ||
112 | { | ||
113 | return le16_to_cpu(bg->bg_used_dirs_count_lo) | | ||
114 | (EXT4_DESC_SIZE(sb) >= EXT4_MIN_DESC_SIZE_64BIT ? | ||
115 | (__u32)le16_to_cpu(bg->bg_used_dirs_count_hi) << 16 : 0); | ||
116 | } | ||
117 | |||
118 | __u32 ext4_itable_unused_count(struct super_block *sb, | ||
119 | struct ext4_group_desc *bg) | ||
120 | { | ||
121 | return le16_to_cpu(bg->bg_itable_unused_lo) | | ||
122 | (EXT4_DESC_SIZE(sb) >= EXT4_MIN_DESC_SIZE_64BIT ? | ||
123 | (__u32)le16_to_cpu(bg->bg_itable_unused_hi) << 16 : 0); | ||
124 | } | ||
125 | |||
96 | void ext4_block_bitmap_set(struct super_block *sb, | 126 | void ext4_block_bitmap_set(struct super_block *sb, |
97 | struct ext4_group_desc *bg, ext4_fsblk_t blk) | 127 | struct ext4_group_desc *bg, ext4_fsblk_t blk) |
98 | { | 128 | { |
@@ -117,6 +147,38 @@ void ext4_inode_table_set(struct super_block *sb, | |||
117 | bg->bg_inode_table_hi = cpu_to_le32(blk >> 32); | 147 | bg->bg_inode_table_hi = cpu_to_le32(blk >> 32); |
118 | } | 148 | } |
119 | 149 | ||
150 | void ext4_free_blks_set(struct super_block *sb, | ||
151 | struct ext4_group_desc *bg, __u32 count) | ||
152 | { | ||
153 | bg->bg_free_blocks_count_lo = cpu_to_le16((__u16)count); | ||
154 | if (EXT4_DESC_SIZE(sb) >= EXT4_MIN_DESC_SIZE_64BIT) | ||
155 | bg->bg_free_blocks_count_hi = cpu_to_le16(count >> 16); | ||
156 | } | ||
157 | |||
158 | void ext4_free_inodes_set(struct super_block *sb, | ||
159 | struct ext4_group_desc *bg, __u32 count) | ||
160 | { | ||
161 | bg->bg_free_inodes_count_lo = cpu_to_le16((__u16)count); | ||
162 | if (EXT4_DESC_SIZE(sb) >= EXT4_MIN_DESC_SIZE_64BIT) | ||
163 | bg->bg_free_inodes_count_hi = cpu_to_le16(count >> 16); | ||
164 | } | ||
165 | |||
166 | void ext4_used_dirs_set(struct super_block *sb, | ||
167 | struct ext4_group_desc *bg, __u32 count) | ||
168 | { | ||
169 | bg->bg_used_dirs_count_lo = cpu_to_le16((__u16)count); | ||
170 | if (EXT4_DESC_SIZE(sb) >= EXT4_MIN_DESC_SIZE_64BIT) | ||
171 | bg->bg_used_dirs_count_hi = cpu_to_le16(count >> 16); | ||
172 | } | ||
173 | |||
174 | void ext4_itable_unused_set(struct super_block *sb, | ||
175 | struct ext4_group_desc *bg, __u32 count) | ||
176 | { | ||
177 | bg->bg_itable_unused_lo = cpu_to_le16((__u16)count); | ||
178 | if (EXT4_DESC_SIZE(sb) >= EXT4_MIN_DESC_SIZE_64BIT) | ||
179 | bg->bg_itable_unused_hi = cpu_to_le16(count >> 16); | ||
180 | } | ||
181 | |||
120 | /* | 182 | /* |
121 | * Wrappers for jbd2_journal_start/end. | 183 | * Wrappers for jbd2_journal_start/end. |
122 | * | 184 | * |
@@ -136,13 +198,19 @@ handle_t *ext4_journal_start_sb(struct super_block *sb, int nblocks) | |||
136 | * backs (eg. EIO in the commit thread), then we still need to | 198 | * backs (eg. EIO in the commit thread), then we still need to |
137 | * take the FS itself readonly cleanly. */ | 199 | * take the FS itself readonly cleanly. */ |
138 | journal = EXT4_SB(sb)->s_journal; | 200 | journal = EXT4_SB(sb)->s_journal; |
139 | if (is_journal_aborted(journal)) { | 201 | if (journal) { |
140 | ext4_abort(sb, __func__, | 202 | if (is_journal_aborted(journal)) { |
141 | "Detected aborted journal"); | 203 | ext4_abort(sb, __func__, |
142 | return ERR_PTR(-EROFS); | 204 | "Detected aborted journal"); |
205 | return ERR_PTR(-EROFS); | ||
206 | } | ||
207 | return jbd2_journal_start(journal, nblocks); | ||
143 | } | 208 | } |
144 | 209 | /* | |
145 | return jbd2_journal_start(journal, nblocks); | 210 | * We're not journaling, return the appropriate indication. |
211 | */ | ||
212 | current->journal_info = EXT4_NOJOURNAL_HANDLE; | ||
213 | return current->journal_info; | ||
146 | } | 214 | } |
147 | 215 | ||
148 | /* | 216 | /* |
@@ -157,6 +225,14 @@ int __ext4_journal_stop(const char *where, handle_t *handle) | |||
157 | int err; | 225 | int err; |
158 | int rc; | 226 | int rc; |
159 | 227 | ||
228 | if (!ext4_handle_valid(handle)) { | ||
229 | /* | ||
230 | * Do this here since we don't call jbd2_journal_stop() in | ||
231 | * no-journal mode. | ||
232 | */ | ||
233 | current->journal_info = NULL; | ||
234 | return 0; | ||
235 | } | ||
160 | sb = handle->h_transaction->t_journal->j_private; | 236 | sb = handle->h_transaction->t_journal->j_private; |
161 | err = handle->h_err; | 237 | err = handle->h_err; |
162 | rc = jbd2_journal_stop(handle); | 238 | rc = jbd2_journal_stop(handle); |
@@ -174,6 +250,8 @@ void ext4_journal_abort_handle(const char *caller, const char *err_fn, | |||
174 | char nbuf[16]; | 250 | char nbuf[16]; |
175 | const char *errstr = ext4_decode_error(NULL, err, nbuf); | 251 | const char *errstr = ext4_decode_error(NULL, err, nbuf); |
176 | 252 | ||
253 | BUG_ON(!ext4_handle_valid(handle)); | ||
254 | |||
177 | if (bh) | 255 | if (bh) |
178 | BUFFER_TRACE(bh, "abort"); | 256 | BUFFER_TRACE(bh, "abort"); |
179 | 257 | ||
@@ -350,6 +428,44 @@ void ext4_warning(struct super_block *sb, const char *function, | |||
350 | va_end(args); | 428 | va_end(args); |
351 | } | 429 | } |
352 | 430 | ||
431 | void ext4_grp_locked_error(struct super_block *sb, ext4_group_t grp, | ||
432 | const char *function, const char *fmt, ...) | ||
433 | __releases(bitlock) | ||
434 | __acquires(bitlock) | ||
435 | { | ||
436 | va_list args; | ||
437 | struct ext4_super_block *es = EXT4_SB(sb)->s_es; | ||
438 | |||
439 | va_start(args, fmt); | ||
440 | printk(KERN_CRIT "EXT4-fs error (device %s): %s: ", sb->s_id, function); | ||
441 | vprintk(fmt, args); | ||
442 | printk("\n"); | ||
443 | va_end(args); | ||
444 | |||
445 | if (test_opt(sb, ERRORS_CONT)) { | ||
446 | EXT4_SB(sb)->s_mount_state |= EXT4_ERROR_FS; | ||
447 | es->s_state |= cpu_to_le16(EXT4_ERROR_FS); | ||
448 | ext4_commit_super(sb, es, 0); | ||
449 | return; | ||
450 | } | ||
451 | ext4_unlock_group(sb, grp); | ||
452 | ext4_handle_error(sb); | ||
453 | /* | ||
454 | * We only get here in the ERRORS_RO case; relocking the group | ||
455 | * may be dangerous, but nothing bad will happen since the | ||
456 | * filesystem will have already been marked read/only and the | ||
457 | * journal has been aborted. We return 1 as a hint to callers | ||
458 | * who might what to use the return value from | ||
459 | * ext4_grp_locked_error() to distinguish beween the | ||
460 | * ERRORS_CONT and ERRORS_RO case, and perhaps return more | ||
461 | * aggressively from the ext4 function in question, with a | ||
462 | * more appropriate error code. | ||
463 | */ | ||
464 | ext4_lock_group(sb, grp); | ||
465 | return; | ||
466 | } | ||
467 | |||
468 | |||
353 | void ext4_update_dynamic_rev(struct super_block *sb) | 469 | void ext4_update_dynamic_rev(struct super_block *sb) |
354 | { | 470 | { |
355 | struct ext4_super_block *es = EXT4_SB(sb)->s_es; | 471 | struct ext4_super_block *es = EXT4_SB(sb)->s_es; |
@@ -389,7 +505,7 @@ static struct block_device *ext4_blkdev_get(dev_t dev) | |||
389 | return bdev; | 505 | return bdev; |
390 | 506 | ||
391 | fail: | 507 | fail: |
392 | printk(KERN_ERR "EXT4: failed to open journal device %s: %ld\n", | 508 | printk(KERN_ERR "EXT4-fs: failed to open journal device %s: %ld\n", |
393 | __bdevname(dev, b), PTR_ERR(bdev)); | 509 | __bdevname(dev, b), PTR_ERR(bdev)); |
394 | return NULL; | 510 | return NULL; |
395 | } | 511 | } |
@@ -448,11 +564,13 @@ static void ext4_put_super(struct super_block *sb) | |||
448 | ext4_mb_release(sb); | 564 | ext4_mb_release(sb); |
449 | ext4_ext_release(sb); | 565 | ext4_ext_release(sb); |
450 | ext4_xattr_put_super(sb); | 566 | ext4_xattr_put_super(sb); |
451 | err = jbd2_journal_destroy(sbi->s_journal); | 567 | if (sbi->s_journal) { |
452 | sbi->s_journal = NULL; | 568 | err = jbd2_journal_destroy(sbi->s_journal); |
453 | if (err < 0) | 569 | sbi->s_journal = NULL; |
454 | ext4_abort(sb, __func__, "Couldn't clean up the journal"); | 570 | if (err < 0) |
455 | 571 | ext4_abort(sb, __func__, | |
572 | "Couldn't clean up the journal"); | ||
573 | } | ||
456 | if (!(sb->s_flags & MS_RDONLY)) { | 574 | if (!(sb->s_flags & MS_RDONLY)) { |
457 | EXT4_CLEAR_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_RECOVER); | 575 | EXT4_CLEAR_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_RECOVER); |
458 | es->s_state = cpu_to_le16(sbi->s_mount_state); | 576 | es->s_state = cpu_to_le16(sbi->s_mount_state); |
@@ -522,6 +640,11 @@ static struct inode *ext4_alloc_inode(struct super_block *sb) | |||
522 | memset(&ei->i_cached_extent, 0, sizeof(struct ext4_ext_cache)); | 640 | memset(&ei->i_cached_extent, 0, sizeof(struct ext4_ext_cache)); |
523 | INIT_LIST_HEAD(&ei->i_prealloc_list); | 641 | INIT_LIST_HEAD(&ei->i_prealloc_list); |
524 | spin_lock_init(&ei->i_prealloc_lock); | 642 | spin_lock_init(&ei->i_prealloc_lock); |
643 | /* | ||
644 | * Note: We can be called before EXT4_SB(sb)->s_journal is set, | ||
645 | * therefore it can be null here. Don't check it, just initialize | ||
646 | * jinode. | ||
647 | */ | ||
525 | jbd2_journal_init_jbd_inode(&ei->jinode, &ei->vfs_inode); | 648 | jbd2_journal_init_jbd_inode(&ei->jinode, &ei->vfs_inode); |
526 | ei->i_reserved_data_blocks = 0; | 649 | ei->i_reserved_data_blocks = 0; |
527 | ei->i_reserved_meta_blocks = 0; | 650 | ei->i_reserved_meta_blocks = 0; |
@@ -588,7 +711,8 @@ static void ext4_clear_inode(struct inode *inode) | |||
588 | } | 711 | } |
589 | #endif | 712 | #endif |
590 | ext4_discard_preallocations(inode); | 713 | ext4_discard_preallocations(inode); |
591 | jbd2_journal_release_jbd_inode(EXT4_SB(inode->i_sb)->s_journal, | 714 | if (EXT4_JOURNAL(inode)) |
715 | jbd2_journal_release_jbd_inode(EXT4_SB(inode->i_sb)->s_journal, | ||
592 | &EXT4_I(inode)->jinode); | 716 | &EXT4_I(inode)->jinode); |
593 | } | 717 | } |
594 | 718 | ||
@@ -681,10 +805,19 @@ static int ext4_show_options(struct seq_file *seq, struct vfsmount *vfs) | |||
681 | #endif | 805 | #endif |
682 | if (!test_opt(sb, RESERVATION)) | 806 | if (!test_opt(sb, RESERVATION)) |
683 | seq_puts(seq, ",noreservation"); | 807 | seq_puts(seq, ",noreservation"); |
684 | if (sbi->s_commit_interval) { | 808 | if (sbi->s_commit_interval != JBD2_DEFAULT_MAX_COMMIT_AGE*HZ) { |
685 | seq_printf(seq, ",commit=%u", | 809 | seq_printf(seq, ",commit=%u", |
686 | (unsigned) (sbi->s_commit_interval / HZ)); | 810 | (unsigned) (sbi->s_commit_interval / HZ)); |
687 | } | 811 | } |
812 | if (sbi->s_min_batch_time != EXT4_DEF_MIN_BATCH_TIME) { | ||
813 | seq_printf(seq, ",min_batch_time=%u", | ||
814 | (unsigned) sbi->s_min_batch_time); | ||
815 | } | ||
816 | if (sbi->s_max_batch_time != EXT4_DEF_MAX_BATCH_TIME) { | ||
817 | seq_printf(seq, ",max_batch_time=%u", | ||
818 | (unsigned) sbi->s_min_batch_time); | ||
819 | } | ||
820 | |||
688 | /* | 821 | /* |
689 | * We're changing the default of barrier mount option, so | 822 | * We're changing the default of barrier mount option, so |
690 | * let's always display its mount state so it's clear what its | 823 | * let's always display its mount state so it's clear what its |
@@ -696,8 +829,6 @@ static int ext4_show_options(struct seq_file *seq, struct vfsmount *vfs) | |||
696 | seq_puts(seq, ",journal_async_commit"); | 829 | seq_puts(seq, ",journal_async_commit"); |
697 | if (test_opt(sb, NOBH)) | 830 | if (test_opt(sb, NOBH)) |
698 | seq_puts(seq, ",nobh"); | 831 | seq_puts(seq, ",nobh"); |
699 | if (!test_opt(sb, EXTENTS)) | ||
700 | seq_puts(seq, ",noextents"); | ||
701 | if (test_opt(sb, I_VERSION)) | 832 | if (test_opt(sb, I_VERSION)) |
702 | seq_puts(seq, ",i_version"); | 833 | seq_puts(seq, ",i_version"); |
703 | if (!test_opt(sb, DELALLOC)) | 834 | if (!test_opt(sb, DELALLOC)) |
@@ -772,6 +903,25 @@ static struct dentry *ext4_fh_to_parent(struct super_block *sb, struct fid *fid, | |||
772 | ext4_nfs_get_inode); | 903 | ext4_nfs_get_inode); |
773 | } | 904 | } |
774 | 905 | ||
906 | /* | ||
907 | * Try to release metadata pages (indirect blocks, directories) which are | ||
908 | * mapped via the block device. Since these pages could have journal heads | ||
909 | * which would prevent try_to_free_buffers() from freeing them, we must use | ||
910 | * jbd2 layer's try_to_free_buffers() function to release them. | ||
911 | */ | ||
912 | static int bdev_try_to_free_page(struct super_block *sb, struct page *page, gfp_t wait) | ||
913 | { | ||
914 | journal_t *journal = EXT4_SB(sb)->s_journal; | ||
915 | |||
916 | WARN_ON(PageChecked(page)); | ||
917 | if (!page_has_buffers(page)) | ||
918 | return 0; | ||
919 | if (journal) | ||
920 | return jbd2_journal_try_to_free_buffers(journal, page, | ||
921 | wait & ~__GFP_WAIT); | ||
922 | return try_to_free_buffers(page); | ||
923 | } | ||
924 | |||
775 | #ifdef CONFIG_QUOTA | 925 | #ifdef CONFIG_QUOTA |
776 | #define QTYPE2NAME(t) ((t) == USRQUOTA ? "user" : "group") | 926 | #define QTYPE2NAME(t) ((t) == USRQUOTA ? "user" : "group") |
777 | #define QTYPE2MOPT(on, t) ((t) == USRQUOTA?((on)##USRJQUOTA):((on)##GRPJQUOTA)) | 927 | #define QTYPE2MOPT(on, t) ((t) == USRQUOTA?((on)##USRJQUOTA):((on)##GRPJQUOTA)) |
@@ -838,6 +988,7 @@ static const struct super_operations ext4_sops = { | |||
838 | .quota_read = ext4_quota_read, | 988 | .quota_read = ext4_quota_read, |
839 | .quota_write = ext4_quota_write, | 989 | .quota_write = ext4_quota_write, |
840 | #endif | 990 | #endif |
991 | .bdev_try_to_free_page = bdev_try_to_free_page, | ||
841 | }; | 992 | }; |
842 | 993 | ||
843 | static const struct export_operations ext4_export_ops = { | 994 | static const struct export_operations ext4_export_ops = { |
@@ -852,16 +1003,17 @@ enum { | |||
852 | Opt_nouid32, Opt_debug, Opt_oldalloc, Opt_orlov, | 1003 | Opt_nouid32, Opt_debug, Opt_oldalloc, Opt_orlov, |
853 | Opt_user_xattr, Opt_nouser_xattr, Opt_acl, Opt_noacl, | 1004 | Opt_user_xattr, Opt_nouser_xattr, Opt_acl, Opt_noacl, |
854 | Opt_reservation, Opt_noreservation, Opt_noload, Opt_nobh, Opt_bh, | 1005 | Opt_reservation, Opt_noreservation, Opt_noload, Opt_nobh, Opt_bh, |
855 | Opt_commit, Opt_journal_update, Opt_journal_inum, Opt_journal_dev, | 1006 | Opt_commit, Opt_min_batch_time, Opt_max_batch_time, |
1007 | Opt_journal_update, Opt_journal_dev, | ||
856 | Opt_journal_checksum, Opt_journal_async_commit, | 1008 | Opt_journal_checksum, Opt_journal_async_commit, |
857 | Opt_abort, Opt_data_journal, Opt_data_ordered, Opt_data_writeback, | 1009 | Opt_abort, Opt_data_journal, Opt_data_ordered, Opt_data_writeback, |
858 | Opt_data_err_abort, Opt_data_err_ignore, | 1010 | Opt_data_err_abort, Opt_data_err_ignore, |
859 | Opt_usrjquota, Opt_grpjquota, Opt_offusrjquota, Opt_offgrpjquota, | 1011 | Opt_usrjquota, Opt_grpjquota, Opt_offusrjquota, Opt_offgrpjquota, |
860 | Opt_jqfmt_vfsold, Opt_jqfmt_vfsv0, Opt_quota, Opt_noquota, | 1012 | Opt_jqfmt_vfsold, Opt_jqfmt_vfsv0, Opt_quota, Opt_noquota, |
861 | Opt_ignore, Opt_barrier, Opt_err, Opt_resize, Opt_usrquota, | 1013 | Opt_ignore, Opt_barrier, Opt_err, Opt_resize, Opt_usrquota, |
862 | Opt_grpquota, Opt_extents, Opt_noextents, Opt_i_version, | 1014 | Opt_grpquota, Opt_i_version, |
863 | Opt_stripe, Opt_delalloc, Opt_nodelalloc, | 1015 | Opt_stripe, Opt_delalloc, Opt_nodelalloc, |
864 | Opt_inode_readahead_blks | 1016 | Opt_inode_readahead_blks, Opt_journal_ioprio |
865 | }; | 1017 | }; |
866 | 1018 | ||
867 | static const match_table_t tokens = { | 1019 | static const match_table_t tokens = { |
@@ -891,8 +1043,9 @@ static const match_table_t tokens = { | |||
891 | {Opt_nobh, "nobh"}, | 1043 | {Opt_nobh, "nobh"}, |
892 | {Opt_bh, "bh"}, | 1044 | {Opt_bh, "bh"}, |
893 | {Opt_commit, "commit=%u"}, | 1045 | {Opt_commit, "commit=%u"}, |
1046 | {Opt_min_batch_time, "min_batch_time=%u"}, | ||
1047 | {Opt_max_batch_time, "max_batch_time=%u"}, | ||
894 | {Opt_journal_update, "journal=update"}, | 1048 | {Opt_journal_update, "journal=update"}, |
895 | {Opt_journal_inum, "journal=%u"}, | ||
896 | {Opt_journal_dev, "journal_dev=%u"}, | 1049 | {Opt_journal_dev, "journal_dev=%u"}, |
897 | {Opt_journal_checksum, "journal_checksum"}, | 1050 | {Opt_journal_checksum, "journal_checksum"}, |
898 | {Opt_journal_async_commit, "journal_async_commit"}, | 1051 | {Opt_journal_async_commit, "journal_async_commit"}, |
@@ -913,14 +1066,13 @@ static const match_table_t tokens = { | |||
913 | {Opt_quota, "quota"}, | 1066 | {Opt_quota, "quota"}, |
914 | {Opt_usrquota, "usrquota"}, | 1067 | {Opt_usrquota, "usrquota"}, |
915 | {Opt_barrier, "barrier=%u"}, | 1068 | {Opt_barrier, "barrier=%u"}, |
916 | {Opt_extents, "extents"}, | ||
917 | {Opt_noextents, "noextents"}, | ||
918 | {Opt_i_version, "i_version"}, | 1069 | {Opt_i_version, "i_version"}, |
919 | {Opt_stripe, "stripe=%u"}, | 1070 | {Opt_stripe, "stripe=%u"}, |
920 | {Opt_resize, "resize"}, | 1071 | {Opt_resize, "resize"}, |
921 | {Opt_delalloc, "delalloc"}, | 1072 | {Opt_delalloc, "delalloc"}, |
922 | {Opt_nodelalloc, "nodelalloc"}, | 1073 | {Opt_nodelalloc, "nodelalloc"}, |
923 | {Opt_inode_readahead_blks, "inode_readahead_blks=%u"}, | 1074 | {Opt_inode_readahead_blks, "inode_readahead_blks=%u"}, |
1075 | {Opt_journal_ioprio, "journal_ioprio=%u"}, | ||
924 | {Opt_err, NULL}, | 1076 | {Opt_err, NULL}, |
925 | }; | 1077 | }; |
926 | 1078 | ||
@@ -945,8 +1097,11 @@ static ext4_fsblk_t get_sb_block(void **data) | |||
945 | return sb_block; | 1097 | return sb_block; |
946 | } | 1098 | } |
947 | 1099 | ||
1100 | #define DEFAULT_JOURNAL_IOPRIO (IOPRIO_PRIO_VALUE(IOPRIO_CLASS_BE, 3)) | ||
1101 | |||
948 | static int parse_options(char *options, struct super_block *sb, | 1102 | static int parse_options(char *options, struct super_block *sb, |
949 | unsigned int *inum, unsigned long *journal_devnum, | 1103 | unsigned long *journal_devnum, |
1104 | unsigned int *journal_ioprio, | ||
950 | ext4_fsblk_t *n_blocks_count, int is_remount) | 1105 | ext4_fsblk_t *n_blocks_count, int is_remount) |
951 | { | 1106 | { |
952 | struct ext4_sb_info *sbi = EXT4_SB(sb); | 1107 | struct ext4_sb_info *sbi = EXT4_SB(sb); |
@@ -958,7 +1113,6 @@ static int parse_options(char *options, struct super_block *sb, | |||
958 | int qtype, qfmt; | 1113 | int qtype, qfmt; |
959 | char *qname; | 1114 | char *qname; |
960 | #endif | 1115 | #endif |
961 | ext4_fsblk_t last_block; | ||
962 | 1116 | ||
963 | if (!options) | 1117 | if (!options) |
964 | return 1; | 1118 | return 1; |
@@ -1070,16 +1224,6 @@ static int parse_options(char *options, struct super_block *sb, | |||
1070 | } | 1224 | } |
1071 | set_opt(sbi->s_mount_opt, UPDATE_JOURNAL); | 1225 | set_opt(sbi->s_mount_opt, UPDATE_JOURNAL); |
1072 | break; | 1226 | break; |
1073 | case Opt_journal_inum: | ||
1074 | if (is_remount) { | ||
1075 | printk(KERN_ERR "EXT4-fs: cannot specify " | ||
1076 | "journal on remount\n"); | ||
1077 | return 0; | ||
1078 | } | ||
1079 | if (match_int(&args[0], &option)) | ||
1080 | return 0; | ||
1081 | *inum = option; | ||
1082 | break; | ||
1083 | case Opt_journal_dev: | 1227 | case Opt_journal_dev: |
1084 | if (is_remount) { | 1228 | if (is_remount) { |
1085 | printk(KERN_ERR "EXT4-fs: cannot specify " | 1229 | printk(KERN_ERR "EXT4-fs: cannot specify " |
@@ -1109,6 +1253,22 @@ static int parse_options(char *options, struct super_block *sb, | |||
1109 | option = JBD2_DEFAULT_MAX_COMMIT_AGE; | 1253 | option = JBD2_DEFAULT_MAX_COMMIT_AGE; |
1110 | sbi->s_commit_interval = HZ * option; | 1254 | sbi->s_commit_interval = HZ * option; |
1111 | break; | 1255 | break; |
1256 | case Opt_max_batch_time: | ||
1257 | if (match_int(&args[0], &option)) | ||
1258 | return 0; | ||
1259 | if (option < 0) | ||
1260 | return 0; | ||
1261 | if (option == 0) | ||
1262 | option = EXT4_DEF_MAX_BATCH_TIME; | ||
1263 | sbi->s_max_batch_time = option; | ||
1264 | break; | ||
1265 | case Opt_min_batch_time: | ||
1266 | if (match_int(&args[0], &option)) | ||
1267 | return 0; | ||
1268 | if (option < 0) | ||
1269 | return 0; | ||
1270 | sbi->s_min_batch_time = option; | ||
1271 | break; | ||
1112 | case Opt_data_journal: | 1272 | case Opt_data_journal: |
1113 | data_opt = EXT4_MOUNT_JOURNAL_DATA; | 1273 | data_opt = EXT4_MOUNT_JOURNAL_DATA; |
1114 | goto datacheck; | 1274 | goto datacheck; |
@@ -1279,33 +1439,6 @@ set_qf_format: | |||
1279 | case Opt_bh: | 1439 | case Opt_bh: |
1280 | clear_opt(sbi->s_mount_opt, NOBH); | 1440 | clear_opt(sbi->s_mount_opt, NOBH); |
1281 | break; | 1441 | break; |
1282 | case Opt_extents: | ||
1283 | if (!EXT4_HAS_INCOMPAT_FEATURE(sb, | ||
1284 | EXT4_FEATURE_INCOMPAT_EXTENTS)) { | ||
1285 | ext4_warning(sb, __func__, | ||
1286 | "extents feature not enabled " | ||
1287 | "on this filesystem, use tune2fs\n"); | ||
1288 | return 0; | ||
1289 | } | ||
1290 | set_opt(sbi->s_mount_opt, EXTENTS); | ||
1291 | break; | ||
1292 | case Opt_noextents: | ||
1293 | /* | ||
1294 | * When e2fsprogs support resizing an already existing | ||
1295 | * ext3 file system to greater than 2**32 we need to | ||
1296 | * add support to block allocator to handle growing | ||
1297 | * already existing block mapped inode so that blocks | ||
1298 | * allocated for them fall within 2**32 | ||
1299 | */ | ||
1300 | last_block = ext4_blocks_count(sbi->s_es) - 1; | ||
1301 | if (last_block > 0xffffffffULL) { | ||
1302 | printk(KERN_ERR "EXT4-fs: Filesystem too " | ||
1303 | "large to mount with " | ||
1304 | "-o noextents options\n"); | ||
1305 | return 0; | ||
1306 | } | ||
1307 | clear_opt(sbi->s_mount_opt, EXTENTS); | ||
1308 | break; | ||
1309 | case Opt_i_version: | 1442 | case Opt_i_version: |
1310 | set_opt(sbi->s_mount_opt, I_VERSION); | 1443 | set_opt(sbi->s_mount_opt, I_VERSION); |
1311 | sb->s_flags |= MS_I_VERSION; | 1444 | sb->s_flags |= MS_I_VERSION; |
@@ -1330,6 +1463,14 @@ set_qf_format: | |||
1330 | return 0; | 1463 | return 0; |
1331 | sbi->s_inode_readahead_blks = option; | 1464 | sbi->s_inode_readahead_blks = option; |
1332 | break; | 1465 | break; |
1466 | case Opt_journal_ioprio: | ||
1467 | if (match_int(&args[0], &option)) | ||
1468 | return 0; | ||
1469 | if (option < 0 || option > 7) | ||
1470 | break; | ||
1471 | *journal_ioprio = IOPRIO_PRIO_VALUE(IOPRIO_CLASS_BE, | ||
1472 | option); | ||
1473 | break; | ||
1333 | default: | 1474 | default: |
1334 | printk(KERN_ERR | 1475 | printk(KERN_ERR |
1335 | "EXT4-fs: Unrecognized mount option \"%s\" " | 1476 | "EXT4-fs: Unrecognized mount option \"%s\" " |
@@ -1405,24 +1546,19 @@ static int ext4_setup_super(struct super_block *sb, struct ext4_super_block *es, | |||
1405 | printk(KERN_WARNING | 1546 | printk(KERN_WARNING |
1406 | "EXT4-fs warning: checktime reached, " | 1547 | "EXT4-fs warning: checktime reached, " |
1407 | "running e2fsck is recommended\n"); | 1548 | "running e2fsck is recommended\n"); |
1408 | #if 0 | 1549 | if (!sbi->s_journal) |
1409 | /* @@@ We _will_ want to clear the valid bit if we find | 1550 | es->s_state &= cpu_to_le16(~EXT4_VALID_FS); |
1410 | * inconsistencies, to force a fsck at reboot. But for | ||
1411 | * a plain journaled filesystem we can keep it set as | ||
1412 | * valid forever! :) | ||
1413 | */ | ||
1414 | es->s_state &= cpu_to_le16(~EXT4_VALID_FS); | ||
1415 | #endif | ||
1416 | if (!(__s16) le16_to_cpu(es->s_max_mnt_count)) | 1551 | if (!(__s16) le16_to_cpu(es->s_max_mnt_count)) |
1417 | es->s_max_mnt_count = cpu_to_le16(EXT4_DFL_MAX_MNT_COUNT); | 1552 | es->s_max_mnt_count = cpu_to_le16(EXT4_DFL_MAX_MNT_COUNT); |
1418 | le16_add_cpu(&es->s_mnt_count, 1); | 1553 | le16_add_cpu(&es->s_mnt_count, 1); |
1419 | es->s_mtime = cpu_to_le32(get_seconds()); | 1554 | es->s_mtime = cpu_to_le32(get_seconds()); |
1420 | ext4_update_dynamic_rev(sb); | 1555 | ext4_update_dynamic_rev(sb); |
1421 | EXT4_SET_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_RECOVER); | 1556 | if (sbi->s_journal) |
1557 | EXT4_SET_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_RECOVER); | ||
1422 | 1558 | ||
1423 | ext4_commit_super(sb, es, 1); | 1559 | ext4_commit_super(sb, es, 1); |
1424 | if (test_opt(sb, DEBUG)) | 1560 | if (test_opt(sb, DEBUG)) |
1425 | printk(KERN_INFO "[EXT4 FS bs=%lu, gc=%lu, " | 1561 | printk(KERN_INFO "[EXT4 FS bs=%lu, gc=%u, " |
1426 | "bpg=%lu, ipg=%lu, mo=%04lx]\n", | 1562 | "bpg=%lu, ipg=%lu, mo=%04lx]\n", |
1427 | sb->s_blocksize, | 1563 | sb->s_blocksize, |
1428 | sbi->s_groups_count, | 1564 | sbi->s_groups_count, |
@@ -1430,9 +1566,13 @@ static int ext4_setup_super(struct super_block *sb, struct ext4_super_block *es, | |||
1430 | EXT4_INODES_PER_GROUP(sb), | 1566 | EXT4_INODES_PER_GROUP(sb), |
1431 | sbi->s_mount_opt); | 1567 | sbi->s_mount_opt); |
1432 | 1568 | ||
1433 | printk(KERN_INFO "EXT4 FS on %s, %s journal on %s\n", | 1569 | if (EXT4_SB(sb)->s_journal) { |
1434 | sb->s_id, EXT4_SB(sb)->s_journal->j_inode ? "internal" : | 1570 | printk(KERN_INFO "EXT4 FS on %s, %s journal on %s\n", |
1435 | "external", EXT4_SB(sb)->s_journal->j_devname); | 1571 | sb->s_id, EXT4_SB(sb)->s_journal->j_inode ? "internal" : |
1572 | "external", EXT4_SB(sb)->s_journal->j_devname); | ||
1573 | } else { | ||
1574 | printk(KERN_INFO "EXT4 FS on %s, no journal\n", sb->s_id); | ||
1575 | } | ||
1436 | return res; | 1576 | return res; |
1437 | } | 1577 | } |
1438 | 1578 | ||
@@ -1444,7 +1584,6 @@ static int ext4_fill_flex_info(struct super_block *sb) | |||
1444 | ext4_group_t flex_group_count; | 1584 | ext4_group_t flex_group_count; |
1445 | ext4_group_t flex_group; | 1585 | ext4_group_t flex_group; |
1446 | int groups_per_flex = 0; | 1586 | int groups_per_flex = 0; |
1447 | __u64 block_bitmap = 0; | ||
1448 | int i; | 1587 | int i; |
1449 | 1588 | ||
1450 | if (!sbi->s_es->s_log_groups_per_flex) { | 1589 | if (!sbi->s_es->s_log_groups_per_flex) { |
@@ -1463,21 +1602,18 @@ static int ext4_fill_flex_info(struct super_block *sb) | |||
1463 | sizeof(struct flex_groups), GFP_KERNEL); | 1602 | sizeof(struct flex_groups), GFP_KERNEL); |
1464 | if (sbi->s_flex_groups == NULL) { | 1603 | if (sbi->s_flex_groups == NULL) { |
1465 | printk(KERN_ERR "EXT4-fs: not enough memory for " | 1604 | printk(KERN_ERR "EXT4-fs: not enough memory for " |
1466 | "%lu flex groups\n", flex_group_count); | 1605 | "%u flex groups\n", flex_group_count); |
1467 | goto failed; | 1606 | goto failed; |
1468 | } | 1607 | } |
1469 | 1608 | ||
1470 | gdp = ext4_get_group_desc(sb, 1, &bh); | ||
1471 | block_bitmap = ext4_block_bitmap(sb, gdp) - 1; | ||
1472 | |||
1473 | for (i = 0; i < sbi->s_groups_count; i++) { | 1609 | for (i = 0; i < sbi->s_groups_count; i++) { |
1474 | gdp = ext4_get_group_desc(sb, i, &bh); | 1610 | gdp = ext4_get_group_desc(sb, i, &bh); |
1475 | 1611 | ||
1476 | flex_group = ext4_flex_group(sbi, i); | 1612 | flex_group = ext4_flex_group(sbi, i); |
1477 | sbi->s_flex_groups[flex_group].free_inodes += | 1613 | sbi->s_flex_groups[flex_group].free_inodes += |
1478 | le16_to_cpu(gdp->bg_free_inodes_count); | 1614 | ext4_free_inodes_count(sb, gdp); |
1479 | sbi->s_flex_groups[flex_group].free_blocks += | 1615 | sbi->s_flex_groups[flex_group].free_blocks += |
1480 | le16_to_cpu(gdp->bg_free_blocks_count); | 1616 | ext4_free_blks_count(sb, gdp); |
1481 | } | 1617 | } |
1482 | 1618 | ||
1483 | return 1; | 1619 | return 1; |
@@ -1551,14 +1687,14 @@ static int ext4_check_descriptors(struct super_block *sb) | |||
1551 | block_bitmap = ext4_block_bitmap(sb, gdp); | 1687 | block_bitmap = ext4_block_bitmap(sb, gdp); |
1552 | if (block_bitmap < first_block || block_bitmap > last_block) { | 1688 | if (block_bitmap < first_block || block_bitmap > last_block) { |
1553 | printk(KERN_ERR "EXT4-fs: ext4_check_descriptors: " | 1689 | printk(KERN_ERR "EXT4-fs: ext4_check_descriptors: " |
1554 | "Block bitmap for group %lu not in group " | 1690 | "Block bitmap for group %u not in group " |
1555 | "(block %llu)!\n", i, block_bitmap); | 1691 | "(block %llu)!\n", i, block_bitmap); |
1556 | return 0; | 1692 | return 0; |
1557 | } | 1693 | } |
1558 | inode_bitmap = ext4_inode_bitmap(sb, gdp); | 1694 | inode_bitmap = ext4_inode_bitmap(sb, gdp); |
1559 | if (inode_bitmap < first_block || inode_bitmap > last_block) { | 1695 | if (inode_bitmap < first_block || inode_bitmap > last_block) { |
1560 | printk(KERN_ERR "EXT4-fs: ext4_check_descriptors: " | 1696 | printk(KERN_ERR "EXT4-fs: ext4_check_descriptors: " |
1561 | "Inode bitmap for group %lu not in group " | 1697 | "Inode bitmap for group %u not in group " |
1562 | "(block %llu)!\n", i, inode_bitmap); | 1698 | "(block %llu)!\n", i, inode_bitmap); |
1563 | return 0; | 1699 | return 0; |
1564 | } | 1700 | } |
@@ -1566,14 +1702,14 @@ static int ext4_check_descriptors(struct super_block *sb) | |||
1566 | if (inode_table < first_block || | 1702 | if (inode_table < first_block || |
1567 | inode_table + sbi->s_itb_per_group - 1 > last_block) { | 1703 | inode_table + sbi->s_itb_per_group - 1 > last_block) { |
1568 | printk(KERN_ERR "EXT4-fs: ext4_check_descriptors: " | 1704 | printk(KERN_ERR "EXT4-fs: ext4_check_descriptors: " |
1569 | "Inode table for group %lu not in group " | 1705 | "Inode table for group %u not in group " |
1570 | "(block %llu)!\n", i, inode_table); | 1706 | "(block %llu)!\n", i, inode_table); |
1571 | return 0; | 1707 | return 0; |
1572 | } | 1708 | } |
1573 | spin_lock(sb_bgl_lock(sbi, i)); | 1709 | spin_lock(sb_bgl_lock(sbi, i)); |
1574 | if (!ext4_group_desc_csum_verify(sbi, i, gdp)) { | 1710 | if (!ext4_group_desc_csum_verify(sbi, i, gdp)) { |
1575 | printk(KERN_ERR "EXT4-fs: ext4_check_descriptors: " | 1711 | printk(KERN_ERR "EXT4-fs: ext4_check_descriptors: " |
1576 | "Checksum for group %lu failed (%u!=%u)\n", | 1712 | "Checksum for group %u failed (%u!=%u)\n", |
1577 | i, le16_to_cpu(ext4_group_desc_csum(sbi, i, | 1713 | i, le16_to_cpu(ext4_group_desc_csum(sbi, i, |
1578 | gdp)), le16_to_cpu(gdp->bg_checksum)); | 1714 | gdp)), le16_to_cpu(gdp->bg_checksum)); |
1579 | if (!(sb->s_flags & MS_RDONLY)) { | 1715 | if (!(sb->s_flags & MS_RDONLY)) { |
@@ -1865,19 +2001,20 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent) | |||
1865 | ext4_fsblk_t sb_block = get_sb_block(&data); | 2001 | ext4_fsblk_t sb_block = get_sb_block(&data); |
1866 | ext4_fsblk_t logical_sb_block; | 2002 | ext4_fsblk_t logical_sb_block; |
1867 | unsigned long offset = 0; | 2003 | unsigned long offset = 0; |
1868 | unsigned int journal_inum = 0; | ||
1869 | unsigned long journal_devnum = 0; | 2004 | unsigned long journal_devnum = 0; |
1870 | unsigned long def_mount_opts; | 2005 | unsigned long def_mount_opts; |
1871 | struct inode *root; | 2006 | struct inode *root; |
1872 | char *cp; | 2007 | char *cp; |
2008 | const char *descr; | ||
1873 | int ret = -EINVAL; | 2009 | int ret = -EINVAL; |
1874 | int blocksize; | 2010 | int blocksize; |
1875 | int db_count; | 2011 | unsigned int db_count; |
1876 | int i; | 2012 | unsigned int i; |
1877 | int needs_recovery, has_huge_files; | 2013 | int needs_recovery, has_huge_files; |
1878 | __le32 features; | 2014 | int features; |
1879 | __u64 blocks_count; | 2015 | __u64 blocks_count; |
1880 | int err; | 2016 | int err; |
2017 | unsigned int journal_ioprio = DEFAULT_JOURNAL_IOPRIO; | ||
1881 | 2018 | ||
1882 | sbi = kzalloc(sizeof(*sbi), GFP_KERNEL); | 2019 | sbi = kzalloc(sizeof(*sbi), GFP_KERNEL); |
1883 | if (!sbi) | 2020 | if (!sbi) |
@@ -1958,31 +2095,22 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent) | |||
1958 | 2095 | ||
1959 | sbi->s_resuid = le16_to_cpu(es->s_def_resuid); | 2096 | sbi->s_resuid = le16_to_cpu(es->s_def_resuid); |
1960 | sbi->s_resgid = le16_to_cpu(es->s_def_resgid); | 2097 | sbi->s_resgid = le16_to_cpu(es->s_def_resgid); |
2098 | sbi->s_commit_interval = JBD2_DEFAULT_MAX_COMMIT_AGE * HZ; | ||
2099 | sbi->s_min_batch_time = EXT4_DEF_MIN_BATCH_TIME; | ||
2100 | sbi->s_max_batch_time = EXT4_DEF_MAX_BATCH_TIME; | ||
1961 | 2101 | ||
1962 | set_opt(sbi->s_mount_opt, RESERVATION); | 2102 | set_opt(sbi->s_mount_opt, RESERVATION); |
1963 | set_opt(sbi->s_mount_opt, BARRIER); | 2103 | set_opt(sbi->s_mount_opt, BARRIER); |
1964 | 2104 | ||
1965 | /* | 2105 | /* |
1966 | * turn on extents feature by default in ext4 filesystem | ||
1967 | * only if feature flag already set by mkfs or tune2fs. | ||
1968 | * Use -o noextents to turn it off | ||
1969 | */ | ||
1970 | if (EXT4_HAS_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_EXTENTS)) | ||
1971 | set_opt(sbi->s_mount_opt, EXTENTS); | ||
1972 | else | ||
1973 | ext4_warning(sb, __func__, | ||
1974 | "extents feature not enabled on this filesystem, " | ||
1975 | "use tune2fs.\n"); | ||
1976 | |||
1977 | /* | ||
1978 | * enable delayed allocation by default | 2106 | * enable delayed allocation by default |
1979 | * Use -o nodelalloc to turn it off | 2107 | * Use -o nodelalloc to turn it off |
1980 | */ | 2108 | */ |
1981 | set_opt(sbi->s_mount_opt, DELALLOC); | 2109 | set_opt(sbi->s_mount_opt, DELALLOC); |
1982 | 2110 | ||
1983 | 2111 | ||
1984 | if (!parse_options((char *) data, sb, &journal_inum, &journal_devnum, | 2112 | if (!parse_options((char *) data, sb, &journal_devnum, |
1985 | NULL, 0)) | 2113 | &journal_ioprio, NULL, 0)) |
1986 | goto failed_mount; | 2114 | goto failed_mount; |
1987 | 2115 | ||
1988 | sb->s_flags = (sb->s_flags & ~MS_POSIXACL) | | 2116 | sb->s_flags = (sb->s_flags & ~MS_POSIXACL) | |
@@ -2004,15 +2132,17 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent) | |||
2004 | features = EXT4_HAS_INCOMPAT_FEATURE(sb, ~EXT4_FEATURE_INCOMPAT_SUPP); | 2132 | features = EXT4_HAS_INCOMPAT_FEATURE(sb, ~EXT4_FEATURE_INCOMPAT_SUPP); |
2005 | if (features) { | 2133 | if (features) { |
2006 | printk(KERN_ERR "EXT4-fs: %s: couldn't mount because of " | 2134 | printk(KERN_ERR "EXT4-fs: %s: couldn't mount because of " |
2007 | "unsupported optional features (%x).\n", | 2135 | "unsupported optional features (%x).\n", sb->s_id, |
2008 | sb->s_id, le32_to_cpu(features)); | 2136 | (le32_to_cpu(EXT4_SB(sb)->s_es->s_feature_incompat) & |
2137 | ~EXT4_FEATURE_INCOMPAT_SUPP)); | ||
2009 | goto failed_mount; | 2138 | goto failed_mount; |
2010 | } | 2139 | } |
2011 | features = EXT4_HAS_RO_COMPAT_FEATURE(sb, ~EXT4_FEATURE_RO_COMPAT_SUPP); | 2140 | features = EXT4_HAS_RO_COMPAT_FEATURE(sb, ~EXT4_FEATURE_RO_COMPAT_SUPP); |
2012 | if (!(sb->s_flags & MS_RDONLY) && features) { | 2141 | if (!(sb->s_flags & MS_RDONLY) && features) { |
2013 | printk(KERN_ERR "EXT4-fs: %s: couldn't mount RDWR because of " | 2142 | printk(KERN_ERR "EXT4-fs: %s: couldn't mount RDWR because of " |
2014 | "unsupported optional features (%x).\n", | 2143 | "unsupported optional features (%x).\n", sb->s_id, |
2015 | sb->s_id, le32_to_cpu(features)); | 2144 | (le32_to_cpu(EXT4_SB(sb)->s_es->s_feature_ro_compat) & |
2145 | ~EXT4_FEATURE_RO_COMPAT_SUPP)); | ||
2016 | goto failed_mount; | 2146 | goto failed_mount; |
2017 | } | 2147 | } |
2018 | has_huge_files = EXT4_HAS_RO_COMPAT_FEATURE(sb, | 2148 | has_huge_files = EXT4_HAS_RO_COMPAT_FEATURE(sb, |
@@ -2117,6 +2247,18 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent) | |||
2117 | for (i = 0; i < 4; i++) | 2247 | for (i = 0; i < 4; i++) |
2118 | sbi->s_hash_seed[i] = le32_to_cpu(es->s_hash_seed[i]); | 2248 | sbi->s_hash_seed[i] = le32_to_cpu(es->s_hash_seed[i]); |
2119 | sbi->s_def_hash_version = es->s_def_hash_version; | 2249 | sbi->s_def_hash_version = es->s_def_hash_version; |
2250 | i = le32_to_cpu(es->s_flags); | ||
2251 | if (i & EXT2_FLAGS_UNSIGNED_HASH) | ||
2252 | sbi->s_hash_unsigned = 3; | ||
2253 | else if ((i & EXT2_FLAGS_SIGNED_HASH) == 0) { | ||
2254 | #ifdef __CHAR_UNSIGNED__ | ||
2255 | es->s_flags |= cpu_to_le32(EXT2_FLAGS_UNSIGNED_HASH); | ||
2256 | sbi->s_hash_unsigned = 3; | ||
2257 | #else | ||
2258 | es->s_flags |= cpu_to_le32(EXT2_FLAGS_SIGNED_HASH); | ||
2259 | #endif | ||
2260 | sb->s_dirt = 1; | ||
2261 | } | ||
2120 | 2262 | ||
2121 | if (sbi->s_blocks_per_group > blocksize * 8) { | 2263 | if (sbi->s_blocks_per_group > blocksize * 8) { |
2122 | printk(KERN_ERR | 2264 | printk(KERN_ERR |
@@ -2144,20 +2286,30 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent) | |||
2144 | if (EXT4_BLOCKS_PER_GROUP(sb) == 0) | 2286 | if (EXT4_BLOCKS_PER_GROUP(sb) == 0) |
2145 | goto cantfind_ext4; | 2287 | goto cantfind_ext4; |
2146 | 2288 | ||
2147 | /* ensure blocks_count calculation below doesn't sign-extend */ | 2289 | /* |
2148 | if (ext4_blocks_count(es) + EXT4_BLOCKS_PER_GROUP(sb) < | 2290 | * It makes no sense for the first data block to be beyond the end |
2149 | le32_to_cpu(es->s_first_data_block) + 1) { | 2291 | * of the filesystem. |
2150 | printk(KERN_WARNING "EXT4-fs: bad geometry: block count %llu, " | 2292 | */ |
2151 | "first data block %u, blocks per group %lu\n", | 2293 | if (le32_to_cpu(es->s_first_data_block) >= ext4_blocks_count(es)) { |
2152 | ext4_blocks_count(es), | 2294 | printk(KERN_WARNING "EXT4-fs: bad geometry: first data" |
2153 | le32_to_cpu(es->s_first_data_block), | 2295 | "block %u is beyond end of filesystem (%llu)\n", |
2154 | EXT4_BLOCKS_PER_GROUP(sb)); | 2296 | le32_to_cpu(es->s_first_data_block), |
2297 | ext4_blocks_count(es)); | ||
2155 | goto failed_mount; | 2298 | goto failed_mount; |
2156 | } | 2299 | } |
2157 | blocks_count = (ext4_blocks_count(es) - | 2300 | blocks_count = (ext4_blocks_count(es) - |
2158 | le32_to_cpu(es->s_first_data_block) + | 2301 | le32_to_cpu(es->s_first_data_block) + |
2159 | EXT4_BLOCKS_PER_GROUP(sb) - 1); | 2302 | EXT4_BLOCKS_PER_GROUP(sb) - 1); |
2160 | do_div(blocks_count, EXT4_BLOCKS_PER_GROUP(sb)); | 2303 | do_div(blocks_count, EXT4_BLOCKS_PER_GROUP(sb)); |
2304 | if (blocks_count > ((uint64_t)1<<32) - EXT4_DESC_PER_BLOCK(sb)) { | ||
2305 | printk(KERN_WARNING "EXT4-fs: groups count too large: %u " | ||
2306 | "(block count %llu, first data block %u, " | ||
2307 | "blocks per group %lu)\n", sbi->s_groups_count, | ||
2308 | ext4_blocks_count(es), | ||
2309 | le32_to_cpu(es->s_first_data_block), | ||
2310 | EXT4_BLOCKS_PER_GROUP(sb)); | ||
2311 | goto failed_mount; | ||
2312 | } | ||
2161 | sbi->s_groups_count = blocks_count; | 2313 | sbi->s_groups_count = blocks_count; |
2162 | db_count = (sbi->s_groups_count + EXT4_DESC_PER_BLOCK(sb) - 1) / | 2314 | db_count = (sbi->s_groups_count + EXT4_DESC_PER_BLOCK(sb) - 1) / |
2163 | EXT4_DESC_PER_BLOCK(sb); | 2315 | EXT4_DESC_PER_BLOCK(sb); |
@@ -2269,27 +2421,26 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent) | |||
2269 | EXT4_SB(sb)->s_mount_state |= EXT4_ERROR_FS; | 2421 | EXT4_SB(sb)->s_mount_state |= EXT4_ERROR_FS; |
2270 | es->s_state |= cpu_to_le16(EXT4_ERROR_FS); | 2422 | es->s_state |= cpu_to_le16(EXT4_ERROR_FS); |
2271 | ext4_commit_super(sb, es, 1); | 2423 | ext4_commit_super(sb, es, 1); |
2272 | printk(KERN_CRIT | ||
2273 | "EXT4-fs (device %s): mount failed\n", | ||
2274 | sb->s_id); | ||
2275 | goto failed_mount4; | 2424 | goto failed_mount4; |
2276 | } | 2425 | } |
2277 | } | 2426 | } |
2278 | } else if (journal_inum) { | 2427 | } else if (test_opt(sb, NOLOAD) && !(sb->s_flags & MS_RDONLY) && |
2279 | if (ext4_create_journal(sb, es, journal_inum)) | 2428 | EXT4_HAS_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_RECOVER)) { |
2280 | goto failed_mount3; | 2429 | printk(KERN_ERR "EXT4-fs: required journal recovery " |
2430 | "suppressed and not mounted read-only\n"); | ||
2431 | goto failed_mount4; | ||
2281 | } else { | 2432 | } else { |
2282 | if (!silent) | 2433 | clear_opt(sbi->s_mount_opt, DATA_FLAGS); |
2283 | printk(KERN_ERR | 2434 | set_opt(sbi->s_mount_opt, WRITEBACK_DATA); |
2284 | "ext4: No journal on filesystem on %s\n", | 2435 | sbi->s_journal = NULL; |
2285 | sb->s_id); | 2436 | needs_recovery = 0; |
2286 | goto failed_mount3; | 2437 | goto no_journal; |
2287 | } | 2438 | } |
2288 | 2439 | ||
2289 | if (ext4_blocks_count(es) > 0xffffffffULL && | 2440 | if (ext4_blocks_count(es) > 0xffffffffULL && |
2290 | !jbd2_journal_set_features(EXT4_SB(sb)->s_journal, 0, 0, | 2441 | !jbd2_journal_set_features(EXT4_SB(sb)->s_journal, 0, 0, |
2291 | JBD2_FEATURE_INCOMPAT_64BIT)) { | 2442 | JBD2_FEATURE_INCOMPAT_64BIT)) { |
2292 | printk(KERN_ERR "ext4: Failed to set 64-bit journal feature\n"); | 2443 | printk(KERN_ERR "EXT4-fs: Failed to set 64-bit journal feature\n"); |
2293 | goto failed_mount4; | 2444 | goto failed_mount4; |
2294 | } | 2445 | } |
2295 | 2446 | ||
@@ -2334,6 +2485,9 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent) | |||
2334 | default: | 2485 | default: |
2335 | break; | 2486 | break; |
2336 | } | 2487 | } |
2488 | set_task_ioprio(sbi->s_journal->j_task, journal_ioprio); | ||
2489 | |||
2490 | no_journal: | ||
2337 | 2491 | ||
2338 | if (test_opt(sb, NOBH)) { | 2492 | if (test_opt(sb, NOBH)) { |
2339 | if (!(test_opt(sb, DATA_FLAGS) == EXT4_MOUNT_WRITEBACK_DATA)) { | 2493 | if (!(test_opt(sb, DATA_FLAGS) == EXT4_MOUNT_WRITEBACK_DATA)) { |
@@ -2419,13 +2573,22 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent) | |||
2419 | EXT4_SB(sb)->s_mount_state |= EXT4_ORPHAN_FS; | 2573 | EXT4_SB(sb)->s_mount_state |= EXT4_ORPHAN_FS; |
2420 | ext4_orphan_cleanup(sb, es); | 2574 | ext4_orphan_cleanup(sb, es); |
2421 | EXT4_SB(sb)->s_mount_state &= ~EXT4_ORPHAN_FS; | 2575 | EXT4_SB(sb)->s_mount_state &= ~EXT4_ORPHAN_FS; |
2422 | if (needs_recovery) | 2576 | if (needs_recovery) { |
2423 | printk(KERN_INFO "EXT4-fs: recovery complete.\n"); | 2577 | printk(KERN_INFO "EXT4-fs: recovery complete.\n"); |
2424 | ext4_mark_recovery_complete(sb, es); | 2578 | ext4_mark_recovery_complete(sb, es); |
2425 | printk(KERN_INFO "EXT4-fs: mounted filesystem with %s data mode.\n", | 2579 | } |
2426 | test_opt(sb, DATA_FLAGS) == EXT4_MOUNT_JOURNAL_DATA ? "journal": | 2580 | if (EXT4_SB(sb)->s_journal) { |
2427 | test_opt(sb, DATA_FLAGS) == EXT4_MOUNT_ORDERED_DATA ? "ordered": | 2581 | if (test_opt(sb, DATA_FLAGS) == EXT4_MOUNT_JOURNAL_DATA) |
2428 | "writeback"); | 2582 | descr = " journalled data mode"; |
2583 | else if (test_opt(sb, DATA_FLAGS) == EXT4_MOUNT_ORDERED_DATA) | ||
2584 | descr = " ordered data mode"; | ||
2585 | else | ||
2586 | descr = " writeback data mode"; | ||
2587 | } else | ||
2588 | descr = "out journal"; | ||
2589 | |||
2590 | printk(KERN_INFO "EXT4-fs: mounted filesystem %s with%s\n", | ||
2591 | sb->s_id, descr); | ||
2429 | 2592 | ||
2430 | lock_kernel(); | 2593 | lock_kernel(); |
2431 | return 0; | 2594 | return 0; |
@@ -2437,8 +2600,11 @@ cantfind_ext4: | |||
2437 | goto failed_mount; | 2600 | goto failed_mount; |
2438 | 2601 | ||
2439 | failed_mount4: | 2602 | failed_mount4: |
2440 | jbd2_journal_destroy(sbi->s_journal); | 2603 | printk(KERN_ERR "EXT4-fs (device %s): mount failed\n", sb->s_id); |
2441 | sbi->s_journal = NULL; | 2604 | if (sbi->s_journal) { |
2605 | jbd2_journal_destroy(sbi->s_journal); | ||
2606 | sbi->s_journal = NULL; | ||
2607 | } | ||
2442 | failed_mount3: | 2608 | failed_mount3: |
2443 | percpu_counter_destroy(&sbi->s_freeblocks_counter); | 2609 | percpu_counter_destroy(&sbi->s_freeblocks_counter); |
2444 | percpu_counter_destroy(&sbi->s_freeinodes_counter); | 2610 | percpu_counter_destroy(&sbi->s_freeinodes_counter); |
@@ -2475,11 +2641,9 @@ static void ext4_init_journal_params(struct super_block *sb, journal_t *journal) | |||
2475 | { | 2641 | { |
2476 | struct ext4_sb_info *sbi = EXT4_SB(sb); | 2642 | struct ext4_sb_info *sbi = EXT4_SB(sb); |
2477 | 2643 | ||
2478 | if (sbi->s_commit_interval) | 2644 | journal->j_commit_interval = sbi->s_commit_interval; |
2479 | journal->j_commit_interval = sbi->s_commit_interval; | 2645 | journal->j_min_batch_time = sbi->s_min_batch_time; |
2480 | /* We could also set up an ext4-specific default for the commit | 2646 | journal->j_max_batch_time = sbi->s_max_batch_time; |
2481 | * interval here, but for now we'll just fall back to the jbd | ||
2482 | * default. */ | ||
2483 | 2647 | ||
2484 | spin_lock(&journal->j_state_lock); | 2648 | spin_lock(&journal->j_state_lock); |
2485 | if (test_opt(sb, BARRIER)) | 2649 | if (test_opt(sb, BARRIER)) |
@@ -2499,6 +2663,8 @@ static journal_t *ext4_get_journal(struct super_block *sb, | |||
2499 | struct inode *journal_inode; | 2663 | struct inode *journal_inode; |
2500 | journal_t *journal; | 2664 | journal_t *journal; |
2501 | 2665 | ||
2666 | BUG_ON(!EXT4_HAS_COMPAT_FEATURE(sb, EXT4_FEATURE_COMPAT_HAS_JOURNAL)); | ||
2667 | |||
2502 | /* First, test for the existence of a valid inode on disk. Bad | 2668 | /* First, test for the existence of a valid inode on disk. Bad |
2503 | * things happen if we iget() an unused inode, as the subsequent | 2669 | * things happen if we iget() an unused inode, as the subsequent |
2504 | * iput() will try to delete it. */ | 2670 | * iput() will try to delete it. */ |
@@ -2547,13 +2713,15 @@ static journal_t *ext4_get_dev_journal(struct super_block *sb, | |||
2547 | struct ext4_super_block *es; | 2713 | struct ext4_super_block *es; |
2548 | struct block_device *bdev; | 2714 | struct block_device *bdev; |
2549 | 2715 | ||
2716 | BUG_ON(!EXT4_HAS_COMPAT_FEATURE(sb, EXT4_FEATURE_COMPAT_HAS_JOURNAL)); | ||
2717 | |||
2550 | bdev = ext4_blkdev_get(j_dev); | 2718 | bdev = ext4_blkdev_get(j_dev); |
2551 | if (bdev == NULL) | 2719 | if (bdev == NULL) |
2552 | return NULL; | 2720 | return NULL; |
2553 | 2721 | ||
2554 | if (bd_claim(bdev, sb)) { | 2722 | if (bd_claim(bdev, sb)) { |
2555 | printk(KERN_ERR | 2723 | printk(KERN_ERR |
2556 | "EXT4: failed to claim external journal device.\n"); | 2724 | "EXT4-fs: failed to claim external journal device.\n"); |
2557 | blkdev_put(bdev, FMODE_READ|FMODE_WRITE); | 2725 | blkdev_put(bdev, FMODE_READ|FMODE_WRITE); |
2558 | return NULL; | 2726 | return NULL; |
2559 | } | 2727 | } |
@@ -2634,6 +2802,8 @@ static int ext4_load_journal(struct super_block *sb, | |||
2634 | int err = 0; | 2802 | int err = 0; |
2635 | int really_read_only; | 2803 | int really_read_only; |
2636 | 2804 | ||
2805 | BUG_ON(!EXT4_HAS_COMPAT_FEATURE(sb, EXT4_FEATURE_COMPAT_HAS_JOURNAL)); | ||
2806 | |||
2637 | if (journal_devnum && | 2807 | if (journal_devnum && |
2638 | journal_devnum != le32_to_cpu(es->s_journal_dev)) { | 2808 | journal_devnum != le32_to_cpu(es->s_journal_dev)) { |
2639 | printk(KERN_INFO "EXT4-fs: external journal device major/minor " | 2809 | printk(KERN_INFO "EXT4-fs: external journal device major/minor " |
@@ -2718,48 +2888,6 @@ static int ext4_load_journal(struct super_block *sb, | |||
2718 | return 0; | 2888 | return 0; |
2719 | } | 2889 | } |
2720 | 2890 | ||
2721 | static int ext4_create_journal(struct super_block *sb, | ||
2722 | struct ext4_super_block *es, | ||
2723 | unsigned int journal_inum) | ||
2724 | { | ||
2725 | journal_t *journal; | ||
2726 | int err; | ||
2727 | |||
2728 | if (sb->s_flags & MS_RDONLY) { | ||
2729 | printk(KERN_ERR "EXT4-fs: readonly filesystem when trying to " | ||
2730 | "create journal.\n"); | ||
2731 | return -EROFS; | ||
2732 | } | ||
2733 | |||
2734 | journal = ext4_get_journal(sb, journal_inum); | ||
2735 | if (!journal) | ||
2736 | return -EINVAL; | ||
2737 | |||
2738 | printk(KERN_INFO "EXT4-fs: creating new journal on inode %u\n", | ||
2739 | journal_inum); | ||
2740 | |||
2741 | err = jbd2_journal_create(journal); | ||
2742 | if (err) { | ||
2743 | printk(KERN_ERR "EXT4-fs: error creating journal.\n"); | ||
2744 | jbd2_journal_destroy(journal); | ||
2745 | return -EIO; | ||
2746 | } | ||
2747 | |||
2748 | EXT4_SB(sb)->s_journal = journal; | ||
2749 | |||
2750 | ext4_update_dynamic_rev(sb); | ||
2751 | EXT4_SET_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_RECOVER); | ||
2752 | EXT4_SET_COMPAT_FEATURE(sb, EXT4_FEATURE_COMPAT_HAS_JOURNAL); | ||
2753 | |||
2754 | es->s_journal_inum = cpu_to_le32(journal_inum); | ||
2755 | sb->s_dirt = 1; | ||
2756 | |||
2757 | /* Make sure we flush the recovery flag to disk. */ | ||
2758 | ext4_commit_super(sb, es, 1); | ||
2759 | |||
2760 | return 0; | ||
2761 | } | ||
2762 | |||
2763 | static void ext4_commit_super(struct super_block *sb, | 2891 | static void ext4_commit_super(struct super_block *sb, |
2764 | struct ext4_super_block *es, int sync) | 2892 | struct ext4_super_block *es, int sync) |
2765 | { | 2893 | { |
@@ -2776,20 +2904,23 @@ static void ext4_commit_super(struct super_block *sb, | |||
2776 | * be remapped. Nothing we can do but to retry the | 2904 | * be remapped. Nothing we can do but to retry the |
2777 | * write and hope for the best. | 2905 | * write and hope for the best. |
2778 | */ | 2906 | */ |
2779 | printk(KERN_ERR "ext4: previous I/O error to " | 2907 | printk(KERN_ERR "EXT4-fs: previous I/O error to " |
2780 | "superblock detected for %s.\n", sb->s_id); | 2908 | "superblock detected for %s.\n", sb->s_id); |
2781 | clear_buffer_write_io_error(sbh); | 2909 | clear_buffer_write_io_error(sbh); |
2782 | set_buffer_uptodate(sbh); | 2910 | set_buffer_uptodate(sbh); |
2783 | } | 2911 | } |
2784 | es->s_wtime = cpu_to_le32(get_seconds()); | 2912 | es->s_wtime = cpu_to_le32(get_seconds()); |
2785 | ext4_free_blocks_count_set(es, ext4_count_free_blocks(sb)); | 2913 | ext4_free_blocks_count_set(es, percpu_counter_sum_positive( |
2786 | es->s_free_inodes_count = cpu_to_le32(ext4_count_free_inodes(sb)); | 2914 | &EXT4_SB(sb)->s_freeblocks_counter)); |
2915 | es->s_free_inodes_count = cpu_to_le32(percpu_counter_sum_positive( | ||
2916 | &EXT4_SB(sb)->s_freeinodes_counter)); | ||
2917 | |||
2787 | BUFFER_TRACE(sbh, "marking dirty"); | 2918 | BUFFER_TRACE(sbh, "marking dirty"); |
2788 | mark_buffer_dirty(sbh); | 2919 | mark_buffer_dirty(sbh); |
2789 | if (sync) { | 2920 | if (sync) { |
2790 | sync_dirty_buffer(sbh); | 2921 | sync_dirty_buffer(sbh); |
2791 | if (buffer_write_io_error(sbh)) { | 2922 | if (buffer_write_io_error(sbh)) { |
2792 | printk(KERN_ERR "ext4: I/O error while writing " | 2923 | printk(KERN_ERR "EXT4-fs: I/O error while writing " |
2793 | "superblock for %s.\n", sb->s_id); | 2924 | "superblock for %s.\n", sb->s_id); |
2794 | clear_buffer_write_io_error(sbh); | 2925 | clear_buffer_write_io_error(sbh); |
2795 | set_buffer_uptodate(sbh); | 2926 | set_buffer_uptodate(sbh); |
@@ -2808,6 +2939,10 @@ static void ext4_mark_recovery_complete(struct super_block *sb, | |||
2808 | { | 2939 | { |
2809 | journal_t *journal = EXT4_SB(sb)->s_journal; | 2940 | journal_t *journal = EXT4_SB(sb)->s_journal; |
2810 | 2941 | ||
2942 | if (!EXT4_HAS_COMPAT_FEATURE(sb, EXT4_FEATURE_COMPAT_HAS_JOURNAL)) { | ||
2943 | BUG_ON(journal != NULL); | ||
2944 | return; | ||
2945 | } | ||
2811 | jbd2_journal_lock_updates(journal); | 2946 | jbd2_journal_lock_updates(journal); |
2812 | if (jbd2_journal_flush(journal) < 0) | 2947 | if (jbd2_journal_flush(journal) < 0) |
2813 | goto out; | 2948 | goto out; |
@@ -2837,6 +2972,8 @@ static void ext4_clear_journal_err(struct super_block *sb, | |||
2837 | int j_errno; | 2972 | int j_errno; |
2838 | const char *errstr; | 2973 | const char *errstr; |
2839 | 2974 | ||
2975 | BUG_ON(!EXT4_HAS_COMPAT_FEATURE(sb, EXT4_FEATURE_COMPAT_HAS_JOURNAL)); | ||
2976 | |||
2840 | journal = EXT4_SB(sb)->s_journal; | 2977 | journal = EXT4_SB(sb)->s_journal; |
2841 | 2978 | ||
2842 | /* | 2979 | /* |
@@ -2869,14 +3006,17 @@ static void ext4_clear_journal_err(struct super_block *sb, | |||
2869 | int ext4_force_commit(struct super_block *sb) | 3006 | int ext4_force_commit(struct super_block *sb) |
2870 | { | 3007 | { |
2871 | journal_t *journal; | 3008 | journal_t *journal; |
2872 | int ret; | 3009 | int ret = 0; |
2873 | 3010 | ||
2874 | if (sb->s_flags & MS_RDONLY) | 3011 | if (sb->s_flags & MS_RDONLY) |
2875 | return 0; | 3012 | return 0; |
2876 | 3013 | ||
2877 | journal = EXT4_SB(sb)->s_journal; | 3014 | journal = EXT4_SB(sb)->s_journal; |
2878 | sb->s_dirt = 0; | 3015 | if (journal) { |
2879 | ret = ext4_journal_force_commit(journal); | 3016 | sb->s_dirt = 0; |
3017 | ret = ext4_journal_force_commit(journal); | ||
3018 | } | ||
3019 | |||
2880 | return ret; | 3020 | return ret; |
2881 | } | 3021 | } |
2882 | 3022 | ||
@@ -2888,9 +3028,13 @@ int ext4_force_commit(struct super_block *sb) | |||
2888 | */ | 3028 | */ |
2889 | static void ext4_write_super(struct super_block *sb) | 3029 | static void ext4_write_super(struct super_block *sb) |
2890 | { | 3030 | { |
2891 | if (mutex_trylock(&sb->s_lock) != 0) | 3031 | if (EXT4_SB(sb)->s_journal) { |
2892 | BUG(); | 3032 | if (mutex_trylock(&sb->s_lock) != 0) |
2893 | sb->s_dirt = 0; | 3033 | BUG(); |
3034 | sb->s_dirt = 0; | ||
3035 | } else { | ||
3036 | ext4_commit_super(sb, EXT4_SB(sb)->s_es, 1); | ||
3037 | } | ||
2894 | } | 3038 | } |
2895 | 3039 | ||
2896 | static int ext4_sync_fs(struct super_block *sb, int wait) | 3040 | static int ext4_sync_fs(struct super_block *sb, int wait) |
@@ -2899,10 +3043,14 @@ static int ext4_sync_fs(struct super_block *sb, int wait) | |||
2899 | 3043 | ||
2900 | trace_mark(ext4_sync_fs, "dev %s wait %d", sb->s_id, wait); | 3044 | trace_mark(ext4_sync_fs, "dev %s wait %d", sb->s_id, wait); |
2901 | sb->s_dirt = 0; | 3045 | sb->s_dirt = 0; |
2902 | if (wait) | 3046 | if (EXT4_SB(sb)->s_journal) { |
2903 | ret = ext4_force_commit(sb); | 3047 | if (wait) |
2904 | else | 3048 | ret = ext4_force_commit(sb); |
2905 | jbd2_journal_start_commit(EXT4_SB(sb)->s_journal, NULL); | 3049 | else |
3050 | jbd2_journal_start_commit(EXT4_SB(sb)->s_journal, NULL); | ||
3051 | } else { | ||
3052 | ext4_commit_super(sb, EXT4_SB(sb)->s_es, wait); | ||
3053 | } | ||
2906 | return ret; | 3054 | return ret; |
2907 | } | 3055 | } |
2908 | 3056 | ||
@@ -2917,15 +3065,17 @@ static void ext4_write_super_lockfs(struct super_block *sb) | |||
2917 | if (!(sb->s_flags & MS_RDONLY)) { | 3065 | if (!(sb->s_flags & MS_RDONLY)) { |
2918 | journal_t *journal = EXT4_SB(sb)->s_journal; | 3066 | journal_t *journal = EXT4_SB(sb)->s_journal; |
2919 | 3067 | ||
2920 | /* Now we set up the journal barrier. */ | 3068 | if (journal) { |
2921 | jbd2_journal_lock_updates(journal); | 3069 | /* Now we set up the journal barrier. */ |
3070 | jbd2_journal_lock_updates(journal); | ||
2922 | 3071 | ||
2923 | /* | 3072 | /* |
2924 | * We don't want to clear needs_recovery flag when we failed | 3073 | * We don't want to clear needs_recovery flag when we |
2925 | * to flush the journal. | 3074 | * failed to flush the journal. |
2926 | */ | 3075 | */ |
2927 | if (jbd2_journal_flush(journal) < 0) | 3076 | if (jbd2_journal_flush(journal) < 0) |
2928 | return; | 3077 | return; |
3078 | } | ||
2929 | 3079 | ||
2930 | /* Journal blocked and flushed, clear needs_recovery flag. */ | 3080 | /* Journal blocked and flushed, clear needs_recovery flag. */ |
2931 | EXT4_CLEAR_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_RECOVER); | 3081 | EXT4_CLEAR_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_RECOVER); |
@@ -2939,7 +3089,7 @@ static void ext4_write_super_lockfs(struct super_block *sb) | |||
2939 | */ | 3089 | */ |
2940 | static void ext4_unlockfs(struct super_block *sb) | 3090 | static void ext4_unlockfs(struct super_block *sb) |
2941 | { | 3091 | { |
2942 | if (!(sb->s_flags & MS_RDONLY)) { | 3092 | if (EXT4_SB(sb)->s_journal && !(sb->s_flags & MS_RDONLY)) { |
2943 | lock_super(sb); | 3093 | lock_super(sb); |
2944 | /* Reser the needs_recovery flag before the fs is unlocked. */ | 3094 | /* Reser the needs_recovery flag before the fs is unlocked. */ |
2945 | EXT4_SET_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_RECOVER); | 3095 | EXT4_SET_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_RECOVER); |
@@ -2957,6 +3107,7 @@ static int ext4_remount(struct super_block *sb, int *flags, char *data) | |||
2957 | unsigned long old_sb_flags; | 3107 | unsigned long old_sb_flags; |
2958 | struct ext4_mount_options old_opts; | 3108 | struct ext4_mount_options old_opts; |
2959 | ext4_group_t g; | 3109 | ext4_group_t g; |
3110 | unsigned int journal_ioprio = DEFAULT_JOURNAL_IOPRIO; | ||
2960 | int err; | 3111 | int err; |
2961 | #ifdef CONFIG_QUOTA | 3112 | #ifdef CONFIG_QUOTA |
2962 | int i; | 3113 | int i; |
@@ -2968,16 +3119,21 @@ static int ext4_remount(struct super_block *sb, int *flags, char *data) | |||
2968 | old_opts.s_resuid = sbi->s_resuid; | 3119 | old_opts.s_resuid = sbi->s_resuid; |
2969 | old_opts.s_resgid = sbi->s_resgid; | 3120 | old_opts.s_resgid = sbi->s_resgid; |
2970 | old_opts.s_commit_interval = sbi->s_commit_interval; | 3121 | old_opts.s_commit_interval = sbi->s_commit_interval; |
3122 | old_opts.s_min_batch_time = sbi->s_min_batch_time; | ||
3123 | old_opts.s_max_batch_time = sbi->s_max_batch_time; | ||
2971 | #ifdef CONFIG_QUOTA | 3124 | #ifdef CONFIG_QUOTA |
2972 | old_opts.s_jquota_fmt = sbi->s_jquota_fmt; | 3125 | old_opts.s_jquota_fmt = sbi->s_jquota_fmt; |
2973 | for (i = 0; i < MAXQUOTAS; i++) | 3126 | for (i = 0; i < MAXQUOTAS; i++) |
2974 | old_opts.s_qf_names[i] = sbi->s_qf_names[i]; | 3127 | old_opts.s_qf_names[i] = sbi->s_qf_names[i]; |
2975 | #endif | 3128 | #endif |
3129 | if (sbi->s_journal && sbi->s_journal->j_task->io_context) | ||
3130 | journal_ioprio = sbi->s_journal->j_task->io_context->ioprio; | ||
2976 | 3131 | ||
2977 | /* | 3132 | /* |
2978 | * Allow the "check" option to be passed as a remount option. | 3133 | * Allow the "check" option to be passed as a remount option. |
2979 | */ | 3134 | */ |
2980 | if (!parse_options(data, sb, NULL, NULL, &n_blocks_count, 1)) { | 3135 | if (!parse_options(data, sb, NULL, &journal_ioprio, |
3136 | &n_blocks_count, 1)) { | ||
2981 | err = -EINVAL; | 3137 | err = -EINVAL; |
2982 | goto restore_opts; | 3138 | goto restore_opts; |
2983 | } | 3139 | } |
@@ -2990,7 +3146,10 @@ static int ext4_remount(struct super_block *sb, int *flags, char *data) | |||
2990 | 3146 | ||
2991 | es = sbi->s_es; | 3147 | es = sbi->s_es; |
2992 | 3148 | ||
2993 | ext4_init_journal_params(sb, sbi->s_journal); | 3149 | if (sbi->s_journal) { |
3150 | ext4_init_journal_params(sb, sbi->s_journal); | ||
3151 | set_task_ioprio(sbi->s_journal->j_task, journal_ioprio); | ||
3152 | } | ||
2994 | 3153 | ||
2995 | if ((*flags & MS_RDONLY) != (sb->s_flags & MS_RDONLY) || | 3154 | if ((*flags & MS_RDONLY) != (sb->s_flags & MS_RDONLY) || |
2996 | n_blocks_count > ext4_blocks_count(es)) { | 3155 | n_blocks_count > ext4_blocks_count(es)) { |
@@ -3019,17 +3178,20 @@ static int ext4_remount(struct super_block *sb, int *flags, char *data) | |||
3019 | * We have to unlock super so that we can wait for | 3178 | * We have to unlock super so that we can wait for |
3020 | * transactions. | 3179 | * transactions. |
3021 | */ | 3180 | */ |
3022 | unlock_super(sb); | 3181 | if (sbi->s_journal) { |
3023 | ext4_mark_recovery_complete(sb, es); | 3182 | unlock_super(sb); |
3024 | lock_super(sb); | 3183 | ext4_mark_recovery_complete(sb, es); |
3184 | lock_super(sb); | ||
3185 | } | ||
3025 | } else { | 3186 | } else { |
3026 | __le32 ret; | 3187 | int ret; |
3027 | if ((ret = EXT4_HAS_RO_COMPAT_FEATURE(sb, | 3188 | if ((ret = EXT4_HAS_RO_COMPAT_FEATURE(sb, |
3028 | ~EXT4_FEATURE_RO_COMPAT_SUPP))) { | 3189 | ~EXT4_FEATURE_RO_COMPAT_SUPP))) { |
3029 | printk(KERN_WARNING "EXT4-fs: %s: couldn't " | 3190 | printk(KERN_WARNING "EXT4-fs: %s: couldn't " |
3030 | "remount RDWR because of unsupported " | 3191 | "remount RDWR because of unsupported " |
3031 | "optional features (%x).\n", | 3192 | "optional features (%x).\n", sb->s_id, |
3032 | sb->s_id, le32_to_cpu(ret)); | 3193 | (le32_to_cpu(sbi->s_es->s_feature_ro_compat) & |
3194 | ~EXT4_FEATURE_RO_COMPAT_SUPP)); | ||
3033 | err = -EROFS; | 3195 | err = -EROFS; |
3034 | goto restore_opts; | 3196 | goto restore_opts; |
3035 | } | 3197 | } |
@@ -3046,7 +3208,7 @@ static int ext4_remount(struct super_block *sb, int *flags, char *data) | |||
3046 | if (!ext4_group_desc_csum_verify(sbi, g, gdp)) { | 3208 | if (!ext4_group_desc_csum_verify(sbi, g, gdp)) { |
3047 | printk(KERN_ERR | 3209 | printk(KERN_ERR |
3048 | "EXT4-fs: ext4_remount: " | 3210 | "EXT4-fs: ext4_remount: " |
3049 | "Checksum for group %lu failed (%u!=%u)\n", | 3211 | "Checksum for group %u failed (%u!=%u)\n", |
3050 | g, le16_to_cpu(ext4_group_desc_csum(sbi, g, gdp)), | 3212 | g, le16_to_cpu(ext4_group_desc_csum(sbi, g, gdp)), |
3051 | le16_to_cpu(gdp->bg_checksum)); | 3213 | le16_to_cpu(gdp->bg_checksum)); |
3052 | err = -EINVAL; | 3214 | err = -EINVAL; |
@@ -3075,7 +3237,8 @@ static int ext4_remount(struct super_block *sb, int *flags, char *data) | |||
3075 | * been changed by e2fsck since we originally mounted | 3237 | * been changed by e2fsck since we originally mounted |
3076 | * the partition.) | 3238 | * the partition.) |
3077 | */ | 3239 | */ |
3078 | ext4_clear_journal_err(sb, es); | 3240 | if (sbi->s_journal) |
3241 | ext4_clear_journal_err(sb, es); | ||
3079 | sbi->s_mount_state = le16_to_cpu(es->s_state); | 3242 | sbi->s_mount_state = le16_to_cpu(es->s_state); |
3080 | if ((err = ext4_group_extend(sb, es, n_blocks_count))) | 3243 | if ((err = ext4_group_extend(sb, es, n_blocks_count))) |
3081 | goto restore_opts; | 3244 | goto restore_opts; |
@@ -3083,6 +3246,9 @@ static int ext4_remount(struct super_block *sb, int *flags, char *data) | |||
3083 | sb->s_flags &= ~MS_RDONLY; | 3246 | sb->s_flags &= ~MS_RDONLY; |
3084 | } | 3247 | } |
3085 | } | 3248 | } |
3249 | if (sbi->s_journal == NULL) | ||
3250 | ext4_commit_super(sb, es, 1); | ||
3251 | |||
3086 | #ifdef CONFIG_QUOTA | 3252 | #ifdef CONFIG_QUOTA |
3087 | /* Release old quota file names */ | 3253 | /* Release old quota file names */ |
3088 | for (i = 0; i < MAXQUOTAS; i++) | 3254 | for (i = 0; i < MAXQUOTAS; i++) |
@@ -3097,6 +3263,8 @@ restore_opts: | |||
3097 | sbi->s_resuid = old_opts.s_resuid; | 3263 | sbi->s_resuid = old_opts.s_resuid; |
3098 | sbi->s_resgid = old_opts.s_resgid; | 3264 | sbi->s_resgid = old_opts.s_resgid; |
3099 | sbi->s_commit_interval = old_opts.s_commit_interval; | 3265 | sbi->s_commit_interval = old_opts.s_commit_interval; |
3266 | sbi->s_min_batch_time = old_opts.s_min_batch_time; | ||
3267 | sbi->s_max_batch_time = old_opts.s_max_batch_time; | ||
3100 | #ifdef CONFIG_QUOTA | 3268 | #ifdef CONFIG_QUOTA |
3101 | sbi->s_jquota_fmt = old_opts.s_jquota_fmt; | 3269 | sbi->s_jquota_fmt = old_opts.s_jquota_fmt; |
3102 | for (i = 0; i < MAXQUOTAS; i++) { | 3270 | for (i = 0; i < MAXQUOTAS; i++) { |
@@ -3359,7 +3527,8 @@ static int ext4_quota_on(struct super_block *sb, int type, int format_id, | |||
3359 | * When we journal data on quota file, we have to flush journal to see | 3527 | * When we journal data on quota file, we have to flush journal to see |
3360 | * all updates to the file when we bypass pagecache... | 3528 | * all updates to the file when we bypass pagecache... |
3361 | */ | 3529 | */ |
3362 | if (ext4_should_journal_data(path.dentry->d_inode)) { | 3530 | if (EXT4_SB(sb)->s_journal && |
3531 | ext4_should_journal_data(path.dentry->d_inode)) { | ||
3363 | /* | 3532 | /* |
3364 | * We don't need to lock updates but journal_flush() could | 3533 | * We don't need to lock updates but journal_flush() could |
3365 | * otherwise be livelocked... | 3534 | * otherwise be livelocked... |
@@ -3433,7 +3602,7 @@ static ssize_t ext4_quota_write(struct super_block *sb, int type, | |||
3433 | struct buffer_head *bh; | 3602 | struct buffer_head *bh; |
3434 | handle_t *handle = journal_current_handle(); | 3603 | handle_t *handle = journal_current_handle(); |
3435 | 3604 | ||
3436 | if (!handle) { | 3605 | if (EXT4_SB(sb)->s_journal && !handle) { |
3437 | printk(KERN_WARNING "EXT4-fs: Quota write (off=%llu, len=%llu)" | 3606 | printk(KERN_WARNING "EXT4-fs: Quota write (off=%llu, len=%llu)" |
3438 | " cancelled because transaction is not started.\n", | 3607 | " cancelled because transaction is not started.\n", |
3439 | (unsigned long long)off, (unsigned long long)len); | 3608 | (unsigned long long)off, (unsigned long long)len); |
@@ -3458,7 +3627,7 @@ static ssize_t ext4_quota_write(struct super_block *sb, int type, | |||
3458 | flush_dcache_page(bh->b_page); | 3627 | flush_dcache_page(bh->b_page); |
3459 | unlock_buffer(bh); | 3628 | unlock_buffer(bh); |
3460 | if (journal_quota) | 3629 | if (journal_quota) |
3461 | err = ext4_journal_dirty_metadata(handle, bh); | 3630 | err = ext4_handle_dirty_metadata(handle, NULL, bh); |
3462 | else { | 3631 | else { |
3463 | /* Always do at least ordered writes for quotas */ | 3632 | /* Always do at least ordered writes for quotas */ |
3464 | err = ext4_jbd2_file_inode(handle, inode); | 3633 | err = ext4_jbd2_file_inode(handle, inode); |
@@ -3512,18 +3681,15 @@ static int ext4_ui_proc_open(struct inode *inode, struct file *file) | |||
3512 | static ssize_t ext4_ui_proc_write(struct file *file, const char __user *buf, | 3681 | static ssize_t ext4_ui_proc_write(struct file *file, const char __user *buf, |
3513 | size_t cnt, loff_t *ppos) | 3682 | size_t cnt, loff_t *ppos) |
3514 | { | 3683 | { |
3515 | unsigned int *p = PDE(file->f_path.dentry->d_inode)->data; | 3684 | unsigned long *p = PDE(file->f_path.dentry->d_inode)->data; |
3516 | char str[32]; | 3685 | char str[32]; |
3517 | unsigned long value; | ||
3518 | 3686 | ||
3519 | if (cnt >= sizeof(str)) | 3687 | if (cnt >= sizeof(str)) |
3520 | return -EINVAL; | 3688 | return -EINVAL; |
3521 | if (copy_from_user(str, buf, cnt)) | 3689 | if (copy_from_user(str, buf, cnt)) |
3522 | return -EFAULT; | 3690 | return -EFAULT; |
3523 | value = simple_strtol(str, NULL, 0); | 3691 | |
3524 | if (value < 0) | 3692 | *p = simple_strtoul(str, NULL, 0); |
3525 | return -ERANGE; | ||
3526 | *p = value; | ||
3527 | return cnt; | 3693 | return cnt; |
3528 | } | 3694 | } |
3529 | 3695 | ||
@@ -3614,7 +3780,7 @@ static void __exit exit_ext4_fs(void) | |||
3614 | } | 3780 | } |
3615 | 3781 | ||
3616 | MODULE_AUTHOR("Remy Card, Stephen Tweedie, Andrew Morton, Andreas Dilger, Theodore Ts'o and others"); | 3782 | MODULE_AUTHOR("Remy Card, Stephen Tweedie, Andrew Morton, Andreas Dilger, Theodore Ts'o and others"); |
3617 | MODULE_DESCRIPTION("Fourth Extended Filesystem with extents"); | 3783 | MODULE_DESCRIPTION("Fourth Extended Filesystem"); |
3618 | MODULE_LICENSE("GPL"); | 3784 | MODULE_LICENSE("GPL"); |
3619 | module_init(init_ext4_fs) | 3785 | module_init(init_ext4_fs) |
3620 | module_exit(exit_ext4_fs) | 3786 | module_exit(exit_ext4_fs) |