forked from ~ljy/RK356X_SDK_RELEASE

hc
2023-12-09 958e46acc8e900e8569dd467c1af9b8d2d019394
kernel/fs/ext4/super.c
....@@ -43,7 +43,7 @@
4343 #include <linux/uaccess.h>
4444 #include <linux/iversion.h>
4545 #include <linux/unicode.h>
46
-
46
+#include <linux/part_stat.h>
4747 #include <linux/kthread.h>
4848 #include <linux/freezer.h>
4949
....@@ -93,11 +93,11 @@
9393 * i_mmap_rwsem (inode->i_mmap_rwsem)!
9494 *
9595 * page fault path:
96
- * mmap_sem -> sb_start_pagefault -> i_mmap_sem (r) -> transaction start ->
96
+ * mmap_lock -> sb_start_pagefault -> i_mmap_sem (r) -> transaction start ->
9797 * page lock -> i_data_sem (rw)
9898 *
9999 * buffered write path:
100
- * sb_start_write -> i_mutex -> mmap_sem
100
+ * sb_start_write -> i_mutex -> mmap_lock
101101 * sb_start_write -> i_mutex -> transaction start -> page lock ->
102102 * i_data_sem (rw)
103103 *
....@@ -107,7 +107,7 @@
107107 * i_data_sem (rw)
108108 *
109109 * direct IO:
110
- * sb_start_write -> i_mutex -> mmap_sem
110
+ * sb_start_write -> i_mutex -> mmap_lock
111111 * sb_start_write -> i_mutex -> transaction start -> i_data_sem (rw)
112112 *
113113 * writepages:
....@@ -141,27 +141,109 @@
141141 MODULE_ALIAS("ext3");
142142 #define IS_EXT3_SB(sb) ((sb)->s_bdev->bd_holder == &ext3_fs_type)
143143
144
+
145
+static inline void __ext4_read_bh(struct buffer_head *bh, int op_flags,
146
+ bh_end_io_t *end_io)
147
+{
148
+ /*
149
+ * buffer's verified bit is no longer valid after reading from
150
+ * disk again due to write out error, clear it to make sure we
151
+ * recheck the buffer contents.
152
+ */
153
+ clear_buffer_verified(bh);
154
+
155
+ bh->b_end_io = end_io ? end_io : end_buffer_read_sync;
156
+ get_bh(bh);
157
+ submit_bh(REQ_OP_READ, op_flags, bh);
158
+}
159
+
160
+void ext4_read_bh_nowait(struct buffer_head *bh, int op_flags,
161
+ bh_end_io_t *end_io)
162
+{
163
+ BUG_ON(!buffer_locked(bh));
164
+
165
+ if (ext4_buffer_uptodate(bh)) {
166
+ unlock_buffer(bh);
167
+ return;
168
+ }
169
+ __ext4_read_bh(bh, op_flags, end_io);
170
+}
171
+
172
+int ext4_read_bh(struct buffer_head *bh, int op_flags, bh_end_io_t *end_io)
173
+{
174
+ BUG_ON(!buffer_locked(bh));
175
+
176
+ if (ext4_buffer_uptodate(bh)) {
177
+ unlock_buffer(bh);
178
+ return 0;
179
+ }
180
+
181
+ __ext4_read_bh(bh, op_flags, end_io);
182
+
183
+ wait_on_buffer(bh);
184
+ if (buffer_uptodate(bh))
185
+ return 0;
186
+ return -EIO;
187
+}
188
+
189
+int ext4_read_bh_lock(struct buffer_head *bh, int op_flags, bool wait)
190
+{
191
+ lock_buffer(bh);
192
+ if (!wait) {
193
+ ext4_read_bh_nowait(bh, op_flags, NULL);
194
+ return 0;
195
+ }
196
+ return ext4_read_bh(bh, op_flags, NULL);
197
+}
198
+
144199 /*
145
- * This works like sb_bread() except it uses ERR_PTR for error
200
+ * This works like __bread_gfp() except it uses ERR_PTR for error
146201 * returns. Currently with sb_bread it's impossible to distinguish
147202 * between ENOMEM and EIO situations (since both result in a NULL
148203 * return.
149204 */
150
-struct buffer_head *
151
-ext4_sb_bread(struct super_block *sb, sector_t block, int op_flags)
205
+static struct buffer_head *__ext4_sb_bread_gfp(struct super_block *sb,
206
+ sector_t block, int op_flags,
207
+ gfp_t gfp)
152208 {
153
- struct buffer_head *bh = sb_getblk(sb, block);
209
+ struct buffer_head *bh;
210
+ int ret;
154211
212
+ bh = sb_getblk_gfp(sb, block, gfp);
155213 if (bh == NULL)
156214 return ERR_PTR(-ENOMEM);
157
- if (buffer_uptodate(bh))
215
+ if (ext4_buffer_uptodate(bh))
158216 return bh;
159
- ll_rw_block(REQ_OP_READ, REQ_META | op_flags, 1, &bh);
160
- wait_on_buffer(bh);
161
- if (buffer_uptodate(bh))
162
- return bh;
163
- put_bh(bh);
164
- return ERR_PTR(-EIO);
217
+
218
+ ret = ext4_read_bh_lock(bh, REQ_META | op_flags, true);
219
+ if (ret) {
220
+ put_bh(bh);
221
+ return ERR_PTR(ret);
222
+ }
223
+ return bh;
224
+}
225
+
226
+struct buffer_head *ext4_sb_bread(struct super_block *sb, sector_t block,
227
+ int op_flags)
228
+{
229
+ return __ext4_sb_bread_gfp(sb, block, op_flags, __GFP_MOVABLE);
230
+}
231
+
232
+struct buffer_head *ext4_sb_bread_unmovable(struct super_block *sb,
233
+ sector_t block)
234
+{
235
+ return __ext4_sb_bread_gfp(sb, block, 0, 0);
236
+}
237
+
238
+void ext4_sb_breadahead_unmovable(struct super_block *sb, sector_t block)
239
+{
240
+ struct buffer_head *bh = sb_getblk_gfp(sb, block, 0);
241
+
242
+ if (likely(bh)) {
243
+ if (trylock_buffer(bh))
244
+ ext4_read_bh_nowait(bh, REQ_RAHEAD, NULL);
245
+ brelse(bh);
246
+ }
165247 }
166248
167249 static int ext4_verify_csum_type(struct super_block *sb,
....@@ -202,26 +284,6 @@
202284 return;
203285
204286 es->s_checksum = ext4_superblock_csum(sb, es);
205
-}
206
-
207
-void *ext4_kvmalloc(size_t size, gfp_t flags)
208
-{
209
- void *ret;
210
-
211
- ret = kmalloc(size, flags | __GFP_NOWARN);
212
- if (!ret)
213
- ret = __vmalloc(size, flags, PAGE_KERNEL);
214
- return ret;
215
-}
216
-
217
-void *ext4_kvzalloc(size_t size, gfp_t flags)
218
-{
219
- void *ret;
220
-
221
- ret = kzalloc(size, flags | __GFP_NOWARN);
222
- if (!ret)
223
- ret = __vmalloc(size, flags | __GFP_ZERO, PAGE_KERNEL);
224
- return ret;
225287 }
226288
227289 ext4_fsblk_t ext4_block_bitmap(struct super_block *sb,
....@@ -355,10 +417,12 @@
355417 #define ext4_get_tstamp(es, tstamp) \
356418 __ext4_get_tstamp(&(es)->tstamp, &(es)->tstamp ## _hi)
357419
358
-static void __save_error_info(struct super_block *sb, const char *func,
359
- unsigned int line)
420
+static void __save_error_info(struct super_block *sb, int error,
421
+ __u32 ino, __u64 block,
422
+ const char *func, unsigned int line)
360423 {
361424 struct ext4_super_block *es = EXT4_SB(sb)->s_es;
425
+ int err;
362426
363427 EXT4_SB(sb)->s_mount_state |= EXT4_ERROR_FS;
364428 if (bdev_read_only(sb->s_bdev))
....@@ -367,6 +431,62 @@
367431 ext4_update_tstamp(es, s_last_error_time);
368432 strncpy(es->s_last_error_func, func, sizeof(es->s_last_error_func));
369433 es->s_last_error_line = cpu_to_le32(line);
434
+ es->s_last_error_ino = cpu_to_le32(ino);
435
+ es->s_last_error_block = cpu_to_le64(block);
436
+ switch (error) {
437
+ case EIO:
438
+ err = EXT4_ERR_EIO;
439
+ break;
440
+ case ENOMEM:
441
+ err = EXT4_ERR_ENOMEM;
442
+ break;
443
+ case EFSBADCRC:
444
+ err = EXT4_ERR_EFSBADCRC;
445
+ break;
446
+ case 0:
447
+ case EFSCORRUPTED:
448
+ err = EXT4_ERR_EFSCORRUPTED;
449
+ break;
450
+ case ENOSPC:
451
+ err = EXT4_ERR_ENOSPC;
452
+ break;
453
+ case ENOKEY:
454
+ err = EXT4_ERR_ENOKEY;
455
+ break;
456
+ case EROFS:
457
+ err = EXT4_ERR_EROFS;
458
+ break;
459
+ case EFBIG:
460
+ err = EXT4_ERR_EFBIG;
461
+ break;
462
+ case EEXIST:
463
+ err = EXT4_ERR_EEXIST;
464
+ break;
465
+ case ERANGE:
466
+ err = EXT4_ERR_ERANGE;
467
+ break;
468
+ case EOVERFLOW:
469
+ err = EXT4_ERR_EOVERFLOW;
470
+ break;
471
+ case EBUSY:
472
+ err = EXT4_ERR_EBUSY;
473
+ break;
474
+ case ENOTDIR:
475
+ err = EXT4_ERR_ENOTDIR;
476
+ break;
477
+ case ENOTEMPTY:
478
+ err = EXT4_ERR_ENOTEMPTY;
479
+ break;
480
+ case ESHUTDOWN:
481
+ err = EXT4_ERR_ESHUTDOWN;
482
+ break;
483
+ case EFAULT:
484
+ err = EXT4_ERR_EFAULT;
485
+ break;
486
+ default:
487
+ err = EXT4_ERR_UNKNOWN;
488
+ }
489
+ es->s_last_error_errcode = err;
370490 if (!es->s_first_error_time) {
371491 es->s_first_error_time = es->s_last_error_time;
372492 es->s_first_error_time_hi = es->s_last_error_time_hi;
....@@ -375,6 +495,7 @@
375495 es->s_first_error_line = cpu_to_le32(line);
376496 es->s_first_error_ino = es->s_last_error_ino;
377497 es->s_first_error_block = es->s_last_error_block;
498
+ es->s_first_error_errcode = es->s_last_error_errcode;
378499 }
379500 /*
380501 * Start the daily error reporting function if it hasn't been
....@@ -385,10 +506,11 @@
385506 le32_add_cpu(&es->s_error_count, 1);
386507 }
387508
388
-static void save_error_info(struct super_block *sb, const char *func,
389
- unsigned int line)
509
+static void save_error_info(struct super_block *sb, int error,
510
+ __u32 ino, __u64 block,
511
+ const char *func, unsigned int line)
390512 {
391
- __save_error_info(sb, func, line);
513
+ __save_error_info(sb, error, ino, block, func, line);
392514 if (!bdev_read_only(sb->s_bdev))
393515 ext4_commit_super(sb, 1);
394516 }
....@@ -432,6 +554,89 @@
432554 spin_unlock(&sbi->s_md_lock);
433555 }
434556
557
+/*
558
+ * This writepage callback for write_cache_pages()
559
+ * takes care of a few cases after page cleaning.
560
+ *
561
+ * write_cache_pages() already checks for dirty pages
562
+ * and calls clear_page_dirty_for_io(), which we want,
563
+ * to write protect the pages.
564
+ *
565
+ * However, we may have to redirty a page (see below.)
566
+ */
567
+static int ext4_journalled_writepage_callback(struct page *page,
568
+ struct writeback_control *wbc,
569
+ void *data)
570
+{
571
+ transaction_t *transaction = (transaction_t *) data;
572
+ struct buffer_head *bh, *head;
573
+ struct journal_head *jh;
574
+
575
+ bh = head = page_buffers(page);
576
+ do {
577
+ /*
578
+ * We have to redirty a page in these cases:
579
+ * 1) If buffer is dirty, it means the page was dirty because it
580
+ * contains a buffer that needs checkpointing. So the dirty bit
581
+ * needs to be preserved so that checkpointing writes the buffer
582
+ * properly.
583
+ * 2) If buffer is not part of the committing transaction
584
+ * (we may have just accidentally come across this buffer because
585
+ * inode range tracking is not exact) or if the currently running
586
+ * transaction already contains this buffer as well, dirty bit
587
+ * needs to be preserved so that the buffer gets writeprotected
588
+ * properly on running transaction's commit.
589
+ */
590
+ jh = bh2jh(bh);
591
+ if (buffer_dirty(bh) ||
592
+ (jh && (jh->b_transaction != transaction ||
593
+ jh->b_next_transaction))) {
594
+ redirty_page_for_writepage(wbc, page);
595
+ goto out;
596
+ }
597
+ } while ((bh = bh->b_this_page) != head);
598
+
599
+out:
600
+ return AOP_WRITEPAGE_ACTIVATE;
601
+}
602
+
603
+static int ext4_journalled_submit_inode_data_buffers(struct jbd2_inode *jinode)
604
+{
605
+ struct address_space *mapping = jinode->i_vfs_inode->i_mapping;
606
+ struct writeback_control wbc = {
607
+ .sync_mode = WB_SYNC_ALL,
608
+ .nr_to_write = LONG_MAX,
609
+ .range_start = jinode->i_dirty_start,
610
+ .range_end = jinode->i_dirty_end,
611
+ };
612
+
613
+ return write_cache_pages(mapping, &wbc,
614
+ ext4_journalled_writepage_callback,
615
+ jinode->i_transaction);
616
+}
617
+
618
+static int ext4_journal_submit_inode_data_buffers(struct jbd2_inode *jinode)
619
+{
620
+ int ret;
621
+
622
+ if (ext4_should_journal_data(jinode->i_vfs_inode))
623
+ ret = ext4_journalled_submit_inode_data_buffers(jinode);
624
+ else
625
+ ret = jbd2_journal_submit_inode_data_buffers(jinode);
626
+
627
+ return ret;
628
+}
629
+
630
+static int ext4_journal_finish_inode_data_buffers(struct jbd2_inode *jinode)
631
+{
632
+ int ret = 0;
633
+
634
+ if (!ext4_should_journal_data(jinode->i_vfs_inode))
635
+ ret = jbd2_journal_finish_inode_data_buffers(jinode);
636
+
637
+ return ret;
638
+}
639
+
435640 static bool system_going_down(void)
436641 {
437642 return system_state == SYSTEM_HALT || system_state == SYSTEM_POWER_OFF
....@@ -463,7 +668,7 @@
463668 if (sb_rdonly(sb) || test_opt(sb, ERRORS_CONT))
464669 return;
465670
466
- EXT4_SB(sb)->s_mount_flags |= EXT4_MF_FS_ABORTED;
671
+ ext4_set_mount_flag(sb, EXT4_MF_FS_ABORTED);
467672 if (journal)
468673 jbd2_journal_abort(journal, -EIO);
469674 /*
....@@ -480,9 +685,6 @@
480685 smp_wmb();
481686 sb->s_flags |= SB_RDONLY;
482687 } else if (test_opt(sb, ERRORS_PANIC)) {
483
- if (EXT4_SB(sb)->s_journal &&
484
- !(EXT4_SB(sb)->s_journal->j_flags & JBD2_REC_ERR))
485
- return;
486688 panic("EXT4-fs (device %s): panic forced after error\n",
487689 sb->s_id);
488690 }
....@@ -493,7 +695,8 @@
493695 "EXT4-fs error")
494696
495697 void __ext4_error(struct super_block *sb, const char *function,
496
- unsigned int line, const char *fmt, ...)
698
+ unsigned int line, int error, __u64 block,
699
+ const char *fmt, ...)
497700 {
498701 struct va_format vaf;
499702 va_list args;
....@@ -511,24 +714,21 @@
511714 sb->s_id, function, line, current->comm, &vaf);
512715 va_end(args);
513716 }
514
- save_error_info(sb, function, line);
717
+ save_error_info(sb, error, 0, block, function, line);
515718 ext4_handle_error(sb);
516719 }
517720
518721 void __ext4_error_inode(struct inode *inode, const char *function,
519
- unsigned int line, ext4_fsblk_t block,
722
+ unsigned int line, ext4_fsblk_t block, int error,
520723 const char *fmt, ...)
521724 {
522725 va_list args;
523726 struct va_format vaf;
524
- struct ext4_super_block *es = EXT4_SB(inode->i_sb)->s_es;
525727
526728 if (unlikely(ext4_forced_shutdown(EXT4_SB(inode->i_sb))))
527729 return;
528730
529731 trace_ext4_error(inode->i_sb, function, line);
530
- es->s_last_error_ino = cpu_to_le32(inode->i_ino);
531
- es->s_last_error_block = cpu_to_le64(block);
532732 if (ext4_error_ratelimit(inode->i_sb)) {
533733 va_start(args, fmt);
534734 vaf.fmt = fmt;
....@@ -545,7 +745,8 @@
545745 current->comm, &vaf);
546746 va_end(args);
547747 }
548
- save_error_info(inode->i_sb, function, line);
748
+ save_error_info(inode->i_sb, error, inode->i_ino, block,
749
+ function, line);
549750 ext4_handle_error(inode->i_sb);
550751 }
551752
....@@ -555,7 +756,6 @@
555756 {
556757 va_list args;
557758 struct va_format vaf;
558
- struct ext4_super_block *es;
559759 struct inode *inode = file_inode(file);
560760 char pathname[80], *path;
561761
....@@ -563,8 +763,6 @@
563763 return;
564764
565765 trace_ext4_error(inode->i_sb, function, line);
566
- es = EXT4_SB(inode->i_sb)->s_es;
567
- es->s_last_error_ino = cpu_to_le32(inode->i_ino);
568766 if (ext4_error_ratelimit(inode->i_sb)) {
569767 path = file_path(file, pathname, sizeof(pathname));
570768 if (IS_ERR(path))
....@@ -586,7 +784,8 @@
586784 current->comm, path, &vaf);
587785 va_end(args);
588786 }
589
- save_error_info(inode->i_sb, function, line);
787
+ save_error_info(inode->i_sb, EFSCORRUPTED, inode->i_ino, block,
788
+ function, line);
590789 ext4_handle_error(inode->i_sb);
591790 }
592791
....@@ -654,7 +853,7 @@
654853 sb->s_id, function, line, errstr);
655854 }
656855
657
- save_error_info(sb, function, line);
856
+ save_error_info(sb, -errno, 0, 0, function, line);
658857 ext4_handle_error(sb);
659858 }
660859
....@@ -669,7 +868,7 @@
669868 */
670869
671870 void __ext4_abort(struct super_block *sb, const char *function,
672
- unsigned int line, const char *fmt, ...)
871
+ unsigned int line, int error, const char *fmt, ...)
673872 {
674873 struct va_format vaf;
675874 va_list args;
....@@ -677,7 +876,7 @@
677876 if (unlikely(ext4_forced_shutdown(EXT4_SB(sb))))
678877 return;
679878
680
- save_error_info(sb, function, line);
879
+ save_error_info(sb, error, 0, 0, function, line);
681880 va_start(args, fmt);
682881 vaf.fmt = fmt;
683882 vaf.va = &args;
....@@ -686,24 +885,20 @@
686885 va_end(args);
687886
688887 if (sb_rdonly(sb) == 0) {
888
+ ext4_set_mount_flag(sb, EXT4_MF_FS_ABORTED);
889
+ if (EXT4_SB(sb)->s_journal)
890
+ jbd2_journal_abort(EXT4_SB(sb)->s_journal, -EIO);
891
+
689892 ext4_msg(sb, KERN_CRIT, "Remounting filesystem read-only");
690
- EXT4_SB(sb)->s_mount_flags |= EXT4_MF_FS_ABORTED;
691893 /*
692894 * Make sure updated value of ->s_mount_flags will be visible
693895 * before ->s_flags update
694896 */
695897 smp_wmb();
696898 sb->s_flags |= SB_RDONLY;
697
- if (EXT4_SB(sb)->s_journal)
698
- jbd2_journal_abort(EXT4_SB(sb)->s_journal, -EIO);
699
- save_error_info(sb, function, line);
700899 }
701
- if (test_opt(sb, ERRORS_PANIC) && !system_going_down()) {
702
- if (EXT4_SB(sb)->s_journal &&
703
- !(EXT4_SB(sb)->s_journal->j_flags & JBD2_REC_ERR))
704
- return;
900
+ if (test_opt(sb, ERRORS_PANIC) && !system_going_down())
705901 panic("EXT4-fs panic from previous error\n");
706
- }
707902 }
708903
709904 void __ext4_msg(struct super_block *sb,
....@@ -712,6 +907,7 @@
712907 struct va_format vaf;
713908 va_list args;
714909
910
+ atomic_inc(&EXT4_SB(sb)->s_msg_count);
715911 if (!___ratelimit(&(EXT4_SB(sb)->s_msg_ratelimit_state), "EXT4-fs"))
716912 return;
717913
....@@ -722,9 +918,12 @@
722918 va_end(args);
723919 }
724920
725
-#define ext4_warning_ratelimit(sb) \
726
- ___ratelimit(&(EXT4_SB(sb)->s_warning_ratelimit_state), \
727
- "EXT4-fs warning")
921
+static int ext4_warning_ratelimit(struct super_block *sb)
922
+{
923
+ atomic_inc(&EXT4_SB(sb)->s_warning_count);
924
+ return ___ratelimit(&(EXT4_SB(sb)->s_warning_ratelimit_state),
925
+ "EXT4-fs warning");
926
+}
728927
729928 void __ext4_warning(struct super_block *sb, const char *function,
730929 unsigned int line, const char *fmt, ...)
....@@ -770,15 +969,12 @@
770969 {
771970 struct va_format vaf;
772971 va_list args;
773
- struct ext4_super_block *es = EXT4_SB(sb)->s_es;
774972
775973 if (unlikely(ext4_forced_shutdown(EXT4_SB(sb))))
776974 return;
777975
778976 trace_ext4_error(sb, function, line);
779
- es->s_last_error_ino = cpu_to_le32(ino);
780
- es->s_last_error_block = cpu_to_le64(block);
781
- __save_error_info(sb, function, line);
977
+ __save_error_info(sb, EFSCORRUPTED, ino, block, function, line);
782978
783979 if (ext4_error_ratelimit(sb)) {
784980 va_start(args, fmt);
....@@ -882,7 +1078,6 @@
8821078 static struct block_device *ext4_blkdev_get(dev_t dev, struct super_block *sb)
8831079 {
8841080 struct block_device *bdev;
885
- char b[BDEVNAME_SIZE];
8861081
8871082 bdev = blkdev_get_by_dev(dev, FMODE_READ|FMODE_WRITE|FMODE_EXCL, sb);
8881083 if (IS_ERR(bdev))
....@@ -890,8 +1085,9 @@
8901085 return bdev;
8911086
8921087 fail:
893
- ext4_msg(sb, KERN_ERR, "failed to open journal device %s: %ld",
894
- __bdevname(dev, b), PTR_ERR(bdev));
1088
+ ext4_msg(sb, KERN_ERR,
1089
+ "failed to open journal device unknown-block(%u,%u) %ld",
1090
+ MAJOR(dev), MINOR(dev), PTR_ERR(bdev));
8951091 return NULL;
8961092 }
8971093
....@@ -906,10 +1102,10 @@
9061102 static void ext4_blkdev_remove(struct ext4_sb_info *sbi)
9071103 {
9081104 struct block_device *bdev;
909
- bdev = sbi->journal_bdev;
1105
+ bdev = sbi->s_journal_bdev;
9101106 if (bdev) {
9111107 ext4_blkdev_put(bdev);
912
- sbi->journal_bdev = NULL;
1108
+ sbi->s_journal_bdev = NULL;
9131109 }
9141110 }
9151111
....@@ -974,6 +1170,18 @@
9741170 int aborted = 0;
9751171 int i, err;
9761172
1173
+ /*
1174
+ * Unregister sysfs before destroying jbd2 journal.
1175
+ * Since we could still access attr_journal_task attribute via sysfs
1176
+ * path which could have sbi->s_journal->j_task as NULL
1177
+ * Unregister sysfs before flush sbi->s_error_work.
1178
+ * Since user may read /proc/fs/ext4/xx/mb_groups during umount, If
1179
+ * read metadata verify failed then will queue error work.
1180
+ * flush_stashed_error_work will call start_this_handle may trigger
1181
+ * BUG_ON.
1182
+ */
1183
+ ext4_unregister_sysfs(sb);
1184
+
9771185 ext4_unregister_li_request(sb);
9781186 ext4_quota_off_umount(sb);
9791187
....@@ -983,11 +1191,11 @@
9831191 aborted = is_journal_aborted(sbi->s_journal);
9841192 err = jbd2_journal_destroy(sbi->s_journal);
9851193 sbi->s_journal = NULL;
986
- if ((err < 0) && !aborted)
987
- ext4_abort(sb, "Couldn't clean up the journal");
1194
+ if ((err < 0) && !aborted) {
1195
+ ext4_abort(sb, -err, "Couldn't clean up the journal");
1196
+ }
9881197 }
9891198
990
- ext4_unregister_sysfs(sb);
9911199 ext4_es_unregister_shrinker(sbi);
9921200 del_timer_sync(&sbi->s_err_report);
9931201 ext4_release_system_zone(sb);
....@@ -1017,6 +1225,7 @@
10171225 percpu_counter_destroy(&sbi->s_freeinodes_counter);
10181226 percpu_counter_destroy(&sbi->s_dirs_counter);
10191227 percpu_counter_destroy(&sbi->s_dirtyclusters_counter);
1228
+ percpu_counter_destroy(&sbi->s_sra_exceeded_retry_limit);
10201229 percpu_free_rwsem(&sbi->s_writepages_rwsem);
10211230 #ifdef CONFIG_QUOTA
10221231 for (i = 0; i < EXT4_MAXQUOTAS; i++)
....@@ -1033,26 +1242,25 @@
10331242
10341243 sync_blockdev(sb->s_bdev);
10351244 invalidate_bdev(sb->s_bdev);
1036
- if (sbi->journal_bdev && sbi->journal_bdev != sb->s_bdev) {
1245
+ if (sbi->s_journal_bdev && sbi->s_journal_bdev != sb->s_bdev) {
10371246 /*
10381247 * Invalidate the journal device's buffers. We don't want them
10391248 * floating about in memory - the physical journal device may
10401249 * hotswapped, and it breaks the `ro-after' testing code.
10411250 */
1042
- sync_blockdev(sbi->journal_bdev);
1043
- invalidate_bdev(sbi->journal_bdev);
1251
+ sync_blockdev(sbi->s_journal_bdev);
1252
+ invalidate_bdev(sbi->s_journal_bdev);
10441253 ext4_blkdev_remove(sbi);
10451254 }
1046
- if (sbi->s_ea_inode_cache) {
1047
- ext4_xattr_destroy_cache(sbi->s_ea_inode_cache);
1048
- sbi->s_ea_inode_cache = NULL;
1049
- }
1050
- if (sbi->s_ea_block_cache) {
1051
- ext4_xattr_destroy_cache(sbi->s_ea_block_cache);
1052
- sbi->s_ea_block_cache = NULL;
1053
- }
1054
- if (sbi->s_mmp_tsk)
1055
- kthread_stop(sbi->s_mmp_tsk);
1255
+
1256
+ ext4_xattr_destroy_cache(sbi->s_ea_inode_cache);
1257
+ sbi->s_ea_inode_cache = NULL;
1258
+
1259
+ ext4_xattr_destroy_cache(sbi->s_ea_block_cache);
1260
+ sbi->s_ea_block_cache = NULL;
1261
+
1262
+ ext4_stop_mmpd(sbi);
1263
+
10561264 brelse(sbi->s_sbh);
10571265 sb->s_fs_info = NULL;
10581266 /*
....@@ -1065,7 +1273,7 @@
10651273 crypto_free_shash(sbi->s_chksum_driver);
10661274 kfree(sbi->s_blockgroup_lock);
10671275 fs_put_dax(sbi->s_daxdev);
1068
- fscrypt_free_dummy_context(&sbi->s_dummy_enc_ctx);
1276
+ fscrypt_free_dummy_policy(&sbi->s_dummy_enc_policy);
10691277 #ifdef CONFIG_UNICODE
10701278 utf8_unload(sb->s_encoding);
10711279 #endif
....@@ -1088,6 +1296,7 @@
10881296 inode_set_iversion(&ei->vfs_inode, 1);
10891297 spin_lock_init(&ei->i_raw_lock);
10901298 INIT_LIST_HEAD(&ei->i_prealloc_list);
1299
+ atomic_set(&ei->i_prealloc_active, 0);
10911300 spin_lock_init(&ei->i_prealloc_lock);
10921301 ext4_es_init_tree(&ei->i_es_tree);
10931302 rwlock_init(&ei->i_es_lock);
....@@ -1096,9 +1305,8 @@
10961305 ei->i_es_shk_nr = 0;
10971306 ei->i_es_shrink_lblk = 0;
10981307 ei->i_reserved_data_blocks = 0;
1099
- ei->i_da_metadata_calc_len = 0;
1100
- ei->i_da_metadata_calc_last_lblock = 0;
11011308 spin_lock_init(&(ei->i_block_reservation_lock));
1309
+ ext4_init_pending_tree(&ei->i_pending_tree);
11021310 #ifdef CONFIG_QUOTA
11031311 ei->i_reserved_quota = 0;
11041312 memset(&ei->i_dquot, 0, sizeof(ei->i_dquot));
....@@ -1110,6 +1318,8 @@
11101318 ei->i_datasync_tid = 0;
11111319 atomic_set(&ei->i_unwritten, 0);
11121320 INIT_WORK(&ei->i_rsv_conversion_work, ext4_end_io_rsv_work);
1321
+ ext4_fc_init_inode(&ei->vfs_inode);
1322
+ mutex_init(&ei->i_fc_lock);
11131323 return &ei->vfs_inode;
11141324 }
11151325
....@@ -1124,12 +1334,13 @@
11241334 return drop;
11251335 }
11261336
1127
-static void ext4_i_callback(struct rcu_head *head)
1337
+static void ext4_free_in_core_inode(struct inode *inode)
11281338 {
1129
- struct inode *inode = container_of(head, struct inode, i_rcu);
1130
-
11311339 fscrypt_free_inode(inode);
1132
-
1340
+ if (!list_empty(&(EXT4_I(inode)->i_fc_list))) {
1341
+ pr_warn("%s: inode %ld still in fc list",
1342
+ __func__, inode->i_ino);
1343
+ }
11331344 kmem_cache_free(ext4_inode_cachep, EXT4_I(inode));
11341345 }
11351346
....@@ -1144,7 +1355,12 @@
11441355 true);
11451356 dump_stack();
11461357 }
1147
- call_rcu(&inode->i_rcu, ext4_i_callback);
1358
+
1359
+ if (EXT4_I(inode)->i_reserved_data_blocks)
1360
+ ext4_msg(inode->i_sb, KERN_ERR,
1361
+ "Inode %lu (%p): i_reserved_data_blocks (%u) not cleared!",
1362
+ inode->i_ino, EXT4_I(inode),
1363
+ EXT4_I(inode)->i_reserved_data_blocks);
11481364 }
11491365
11501366 static void init_once(void *foo)
....@@ -1156,6 +1372,7 @@
11561372 init_rwsem(&ei->i_data_sem);
11571373 init_rwsem(&ei->i_mmap_sem);
11581374 inode_init_once(&ei->vfs_inode);
1375
+ ext4_fc_init_inode(&ei->vfs_inode);
11591376 }
11601377
11611378 static int __init init_inodecache(void)
....@@ -1184,11 +1401,12 @@
11841401
11851402 void ext4_clear_inode(struct inode *inode)
11861403 {
1404
+ ext4_fc_del(inode);
11871405 invalidate_inode_buffers(inode);
11881406 clear_inode(inode);
1189
- dquot_drop(inode);
1190
- ext4_discard_preallocations(inode);
1407
+ ext4_discard_preallocations(inode, 0);
11911408 ext4_es_remove_extent(inode, 0, EXT_MAX_BLOCKS);
1409
+ dquot_drop(inode);
11921410 if (EXT4_I(inode)->jinode) {
11931411 jbd2_journal_release_jbd_inode(EXT4_JOURNAL(inode),
11941412 EXT4_I(inode)->jinode);
....@@ -1258,8 +1476,8 @@
12581476 if (!page_has_buffers(page))
12591477 return 0;
12601478 if (journal)
1261
- return jbd2_journal_try_to_free_buffers(journal, page,
1262
- wait & ~__GFP_DIRECT_RECLAIM);
1479
+ return jbd2_journal_try_to_free_buffers(journal, page);
1480
+
12631481 return try_to_free_buffers(page);
12641482 }
12651483
....@@ -1288,6 +1506,9 @@
12881506 if (WARN_ON_ONCE(IS_DAX(inode) && i_size_read(inode)))
12891507 return -EINVAL;
12901508
1509
+ if (ext4_test_inode_flag(inode, EXT4_INODE_DAX))
1510
+ return -EOPNOTSUPP;
1511
+
12911512 res = ext4_convert_inline_data(inode);
12921513 if (res)
12931514 return res;
....@@ -1313,7 +1534,7 @@
13131534 * Update inode->i_flags - S_ENCRYPTED will be enabled,
13141535 * S_DAX may be disabled
13151536 */
1316
- ext4_set_inode_flags(inode);
1537
+ ext4_set_inode_flags(inode, false);
13171538 }
13181539 return res;
13191540 }
....@@ -1340,7 +1561,7 @@
13401561 * Update inode->i_flags - S_ENCRYPTED will be enabled,
13411562 * S_DAX may be disabled
13421563 */
1343
- ext4_set_inode_flags(inode);
1564
+ ext4_set_inode_flags(inode, false);
13441565 res = ext4_mark_inode_dirty(handle, inode);
13451566 if (res)
13461567 EXT4_ERROR_INODE(inode, "Failed to mark inode dirty");
....@@ -1354,10 +1575,9 @@
13541575 return res;
13551576 }
13561577
1357
-static const union fscrypt_context *
1358
-ext4_get_dummy_context(struct super_block *sb)
1578
+static const union fscrypt_policy *ext4_get_dummy_policy(struct super_block *sb)
13591579 {
1360
- return EXT4_SB(sb)->s_dummy_enc_ctx.ctx;
1580
+ return EXT4_SB(sb)->s_dummy_enc_policy.policy;
13611581 }
13621582
13631583 static bool ext4_has_stable_inodes(struct super_block *sb)
....@@ -1372,21 +1592,15 @@
13721592 *lblk_bits_ret = 8 * sizeof(ext4_lblk_t);
13731593 }
13741594
1375
-static bool ext4_inline_crypt_enabled(struct super_block *sb)
1376
-{
1377
- return test_opt(sb, INLINECRYPT);
1378
-}
1379
-
13801595 static const struct fscrypt_operations ext4_cryptops = {
13811596 .key_prefix = "ext4:",
13821597 .get_context = ext4_get_context,
13831598 .set_context = ext4_set_context,
1384
- .get_dummy_context = ext4_get_dummy_context,
1599
+ .get_dummy_policy = ext4_get_dummy_policy,
13851600 .empty_dir = ext4_empty_dir,
13861601 .max_namelen = EXT4_NAME_LEN,
13871602 .has_stable_inodes = ext4_has_stable_inodes,
13881603 .get_ino_and_lblk_bits = ext4_get_ino_and_lblk_bits,
1389
- .inline_crypt_enabled = ext4_inline_crypt_enabled,
13901604 };
13911605 #endif
13921606
....@@ -1409,7 +1623,6 @@
14091623 static int ext4_quota_enable(struct super_block *sb, int type, int format_id,
14101624 unsigned int flags);
14111625 static int ext4_enable_quotas(struct super_block *sb);
1412
-static int ext4_get_next_id(struct super_block *sb, struct kqid *qid);
14131626
14141627 static struct dquot **ext4_get_dquots(struct inode *inode)
14151628 {
....@@ -1427,7 +1640,7 @@
14271640 .destroy_dquot = dquot_destroy,
14281641 .get_projid = ext4_get_projid,
14291642 .get_inode_usage = ext4_get_inode_usage,
1430
- .get_next_id = ext4_get_next_id,
1643
+ .get_next_id = dquot_get_next_id,
14311644 };
14321645
14331646 static const struct quotactl_ops ext4_qctl_operations = {
....@@ -1444,6 +1657,7 @@
14441657
14451658 static const struct super_operations ext4_sops = {
14461659 .alloc_inode = ext4_alloc_inode,
1660
+ .free_inode = ext4_free_in_core_inode,
14471661 .destroy_inode = ext4_destroy_inode,
14481662 .write_inode = ext4_write_inode,
14491663 .dirty_inode = ext4_dirty_inode,
....@@ -1485,7 +1699,8 @@
14851699 Opt_usrjquota, Opt_grpjquota, Opt_offusrjquota, Opt_offgrpjquota,
14861700 Opt_jqfmt_vfsold, Opt_jqfmt_vfsv0, Opt_jqfmt_vfsv1, Opt_quota,
14871701 Opt_noquota, Opt_barrier, Opt_nobarrier, Opt_err,
1488
- Opt_usrquota, Opt_grpquota, Opt_prjquota, Opt_i_version, Opt_dax,
1702
+ Opt_usrquota, Opt_grpquota, Opt_prjquota, Opt_i_version,
1703
+ Opt_dax, Opt_dax_always, Opt_dax_inode, Opt_dax_never,
14891704 Opt_stripe, Opt_delalloc, Opt_nodelalloc, Opt_warn_on_error,
14901705 Opt_nowarn_on_error, Opt_mblk_io_submit,
14911706 Opt_lazytime, Opt_nolazytime, Opt_debug_want_extra_isize,
....@@ -1494,6 +1709,10 @@
14941709 Opt_dioread_nolock, Opt_dioread_lock,
14951710 Opt_discard, Opt_nodiscard, Opt_init_itable, Opt_noinit_itable,
14961711 Opt_max_dir_size_kb, Opt_nojournal_checksum, Opt_nombcache,
1712
+ Opt_prefetch_block_bitmaps,
1713
+#ifdef CONFIG_EXT4_DEBUG
1714
+ Opt_fc_debug_max_replay, Opt_fc_debug_force
1715
+#endif
14971716 };
14981717
14991718 static const match_table_t tokens = {
....@@ -1552,6 +1771,9 @@
15521771 {Opt_nobarrier, "nobarrier"},
15531772 {Opt_i_version, "i_version"},
15541773 {Opt_dax, "dax"},
1774
+ {Opt_dax_always, "dax=always"},
1775
+ {Opt_dax_inode, "dax=inode"},
1776
+ {Opt_dax_never, "dax=never"},
15551777 {Opt_stripe, "stripe=%u"},
15561778 {Opt_delalloc, "delalloc"},
15571779 {Opt_warn_on_error, "warn_on_error"},
....@@ -1570,18 +1792,24 @@
15701792 {Opt_auto_da_alloc, "auto_da_alloc"},
15711793 {Opt_noauto_da_alloc, "noauto_da_alloc"},
15721794 {Opt_dioread_nolock, "dioread_nolock"},
1795
+ {Opt_dioread_lock, "nodioread_nolock"},
15731796 {Opt_dioread_lock, "dioread_lock"},
15741797 {Opt_discard, "discard"},
15751798 {Opt_nodiscard, "nodiscard"},
15761799 {Opt_init_itable, "init_itable=%u"},
15771800 {Opt_init_itable, "init_itable"},
15781801 {Opt_noinit_itable, "noinit_itable"},
1802
+#ifdef CONFIG_EXT4_DEBUG
1803
+ {Opt_fc_debug_force, "fc_debug_force"},
1804
+ {Opt_fc_debug_max_replay, "fc_debug_max_replay=%u"},
1805
+#endif
15791806 {Opt_max_dir_size_kb, "max_dir_size_kb=%u"},
15801807 {Opt_test_dummy_encryption, "test_dummy_encryption=%s"},
15811808 {Opt_test_dummy_encryption, "test_dummy_encryption"},
15821809 {Opt_inlinecrypt, "inlinecrypt"},
15831810 {Opt_nombcache, "nombcache"},
15841811 {Opt_nombcache, "no_mbcache"}, /* for backward compatibility */
1812
+ {Opt_prefetch_block_bitmaps, "prefetch_block_bitmaps"},
15851813 {Opt_removed, "check=none"}, /* mount option from ext2/3 */
15861814 {Opt_removed, "nocheck"}, /* mount option from ext2/3 */
15871815 {Opt_removed, "reservation"}, /* mount option from ext2/3 */
....@@ -1700,6 +1928,8 @@
17001928 #define MOPT_NO_EXT3 0x0200
17011929 #define MOPT_EXT4_ONLY (MOPT_NO_EXT2 | MOPT_NO_EXT3)
17021930 #define MOPT_STRING 0x0400
1931
+#define MOPT_SKIP 0x0800
1932
+#define MOPT_2 0x1000
17031933
17041934 static const struct mount_opts {
17051935 int token;
....@@ -1724,6 +1954,7 @@
17241954 MOPT_EXT4_ONLY | MOPT_CLEAR},
17251955 {Opt_warn_on_error, EXT4_MOUNT_WARN_ON_ERROR, MOPT_SET},
17261956 {Opt_nowarn_on_error, EXT4_MOUNT_WARN_ON_ERROR, MOPT_CLEAR},
1957
+ {Opt_commit, 0, MOPT_NO_EXT2},
17271958 {Opt_nojournal_checksum, EXT4_MOUNT_JOURNAL_CHECKSUM,
17281959 MOPT_EXT4_ONLY | MOPT_CLEAR},
17291960 {Opt_journal_checksum, EXT4_MOUNT_JOURNAL_CHECKSUM,
....@@ -1749,7 +1980,13 @@
17491980 {Opt_min_batch_time, 0, MOPT_GTE0},
17501981 {Opt_inode_readahead_blks, 0, MOPT_GTE0},
17511982 {Opt_init_itable, 0, MOPT_GTE0},
1752
- {Opt_dax, EXT4_MOUNT_DAX, MOPT_SET},
1983
+ {Opt_dax, EXT4_MOUNT_DAX_ALWAYS, MOPT_SET | MOPT_SKIP},
1984
+ {Opt_dax_always, EXT4_MOUNT_DAX_ALWAYS,
1985
+ MOPT_EXT4_ONLY | MOPT_SET | MOPT_SKIP},
1986
+ {Opt_dax_inode, EXT4_MOUNT2_DAX_INODE,
1987
+ MOPT_EXT4_ONLY | MOPT_SET | MOPT_SKIP},
1988
+ {Opt_dax_never, EXT4_MOUNT2_DAX_NEVER,
1989
+ MOPT_EXT4_ONLY | MOPT_SET | MOPT_SKIP},
17531990 {Opt_stripe, 0, MOPT_GTE0},
17541991 {Opt_resuid, 0, MOPT_GTE0},
17551992 {Opt_resgid, 0, MOPT_GTE0},
....@@ -1791,12 +2028,14 @@
17912028 {Opt_jqfmt_vfsv1, QFMT_VFS_V1, MOPT_QFMT},
17922029 {Opt_max_dir_size_kb, 0, MOPT_GTE0},
17932030 {Opt_test_dummy_encryption, 0, MOPT_STRING},
1794
-#ifdef CONFIG_FS_ENCRYPTION_INLINE_CRYPT
1795
- {Opt_inlinecrypt, EXT4_MOUNT_INLINECRYPT, MOPT_SET},
1796
-#else
1797
- {Opt_inlinecrypt, EXT4_MOUNT_INLINECRYPT, MOPT_NOSUPPORT},
1798
-#endif
17992031 {Opt_nombcache, EXT4_MOUNT_NO_MBCACHE, MOPT_SET},
2032
+ {Opt_prefetch_block_bitmaps, EXT4_MOUNT_PREFETCH_BLOCK_BITMAPS,
2033
+ MOPT_SET},
2034
+#ifdef CONFIG_EXT4_DEBUG
2035
+ {Opt_fc_debug_force, EXT4_MOUNT2_JOURNAL_FAST_COMMIT,
2036
+ MOPT_SET | MOPT_2 | MOPT_EXT4_ONLY},
2037
+ {Opt_fc_debug_max_replay, 0, MOPT_GTE0},
2038
+#endif
18002039 {Opt_err, 0, 0}
18012040 };
18022041
....@@ -1839,18 +2078,25 @@
18392078 struct ext4_sb_info *sbi = EXT4_SB(sb);
18402079 int err;
18412080
2081
+ if (!ext4_has_feature_encrypt(sb)) {
2082
+ ext4_msg(sb, KERN_WARNING,
2083
+ "test_dummy_encryption requires encrypt feature");
2084
+ return -1;
2085
+ }
2086
+
18422087 /*
18432088 * This mount option is just for testing, and it's not worthwhile to
18442089 * implement the extra complexity (e.g. RCU protection) that would be
18452090 * needed to allow it to be set or changed during remount. We do allow
18462091 * it to be specified during remount, but only if there is no change.
18472092 */
1848
- if (is_remount && !sbi->s_dummy_enc_ctx.ctx) {
2093
+ if (is_remount && !sbi->s_dummy_enc_policy.policy) {
18492094 ext4_msg(sb, KERN_WARNING,
18502095 "Can't set test_dummy_encryption on remount");
18512096 return -1;
18522097 }
1853
- err = fscrypt_set_test_dummy_encryption(sb, arg, &sbi->s_dummy_enc_ctx);
2098
+ err = fscrypt_set_test_dummy_encryption(sb, arg->from,
2099
+ &sbi->s_dummy_enc_policy);
18542100 if (err) {
18552101 if (err == -EEXIST)
18562102 ext4_msg(sb, KERN_WARNING,
....@@ -1865,11 +2111,13 @@
18652111 return -1;
18662112 }
18672113 ext4_msg(sb, KERN_WARNING, "Test dummy encryption mode enabled");
2114
+ return 1;
18682115 #else
18692116 ext4_msg(sb, KERN_WARNING,
1870
- "Test dummy encryption mount option ignored");
2117
+ "test_dummy_encryption option not supported");
2118
+ return -1;
2119
+
18712120 #endif
1872
- return 1;
18732121 }
18742122
18752123 static int handle_mount_opt(struct super_block *sb, char *opt, int token,
....@@ -1903,7 +2151,7 @@
19032151 ext4_msg(sb, KERN_WARNING, "Ignoring removed %s option", opt);
19042152 return 1;
19052153 case Opt_abort:
1906
- sbi->s_mount_flags |= EXT4_MF_FS_ABORTED;
2154
+ ext4_set_mount_flag(sb, EXT4_MF_FS_ABORTED);
19072155 return 1;
19082156 case Opt_i_version:
19092157 sb->s_flags |= SB_I_VERSION;
....@@ -1913,6 +2161,13 @@
19132161 return 1;
19142162 case Opt_nolazytime:
19152163 sb->s_flags &= ~SB_LAZYTIME;
2164
+ return 1;
2165
+ case Opt_inlinecrypt:
2166
+#ifdef CONFIG_FS_ENCRYPTION_INLINE_CRYPT
2167
+ sb->s_flags |= SB_INLINECRYPT;
2168
+#else
2169
+ ext4_msg(sb, KERN_ERR, "inline encryption not supported");
2170
+#endif
19162171 return 1;
19172172 }
19182173
....@@ -1962,6 +2217,13 @@
19622217 } else if (token == Opt_commit) {
19632218 if (arg == 0)
19642219 arg = JBD2_DEFAULT_MAX_COMMIT_AGE;
2220
+ else if (arg > INT_MAX / HZ) {
2221
+ ext4_msg(sb, KERN_ERR,
2222
+ "Invalid commit interval %d, "
2223
+ "must be smaller than %d",
2224
+ arg, INT_MAX / HZ);
2225
+ return -1;
2226
+ }
19652227 sbi->s_commit_interval = HZ * arg;
19662228 } else if (token == Opt_debug_want_extra_isize) {
19672229 if ((arg & 1) ||
....@@ -1991,6 +2253,10 @@
19912253 sbi->s_li_wait_mult = arg;
19922254 } else if (token == Opt_max_dir_size_kb) {
19932255 sbi->s_max_dir_size_kb = arg;
2256
+#ifdef CONFIG_EXT4_DEBUG
2257
+ } else if (token == Opt_fc_debug_max_replay) {
2258
+ sbi->s_fc_debug_max_replay = arg;
2259
+#endif
19942260 } else if (token == Opt_stripe) {
19952261 sbi->s_stripe = arg;
19962262 } else if (token == Opt_resuid) {
....@@ -2092,23 +2358,56 @@
20922358 }
20932359 sbi->s_jquota_fmt = m->mount_opt;
20942360 #endif
2095
- } else if (token == Opt_dax) {
2361
+ } else if (token == Opt_dax || token == Opt_dax_always ||
2362
+ token == Opt_dax_inode || token == Opt_dax_never) {
20962363 #ifdef CONFIG_FS_DAX
2097
- if (is_remount && test_opt(sb, DAX)) {
2098
- ext4_msg(sb, KERN_ERR, "can't mount with "
2099
- "both data=journal and dax");
2100
- return -1;
2364
+ switch (token) {
2365
+ case Opt_dax:
2366
+ case Opt_dax_always:
2367
+ if (is_remount &&
2368
+ (!(sbi->s_mount_opt & EXT4_MOUNT_DAX_ALWAYS) ||
2369
+ (sbi->s_mount_opt2 & EXT4_MOUNT2_DAX_NEVER))) {
2370
+ fail_dax_change_remount:
2371
+ ext4_msg(sb, KERN_ERR, "can't change "
2372
+ "dax mount option while remounting");
2373
+ return -1;
2374
+ }
2375
+ if (is_remount &&
2376
+ (test_opt(sb, DATA_FLAGS) ==
2377
+ EXT4_MOUNT_JOURNAL_DATA)) {
2378
+ ext4_msg(sb, KERN_ERR, "can't mount with "
2379
+ "both data=journal and dax");
2380
+ return -1;
2381
+ }
2382
+ ext4_msg(sb, KERN_WARNING,
2383
+ "DAX enabled. Warning: EXPERIMENTAL, use at your own risk");
2384
+ sbi->s_mount_opt |= EXT4_MOUNT_DAX_ALWAYS;
2385
+ sbi->s_mount_opt2 &= ~EXT4_MOUNT2_DAX_NEVER;
2386
+ break;
2387
+ case Opt_dax_never:
2388
+ if (is_remount &&
2389
+ (!(sbi->s_mount_opt2 & EXT4_MOUNT2_DAX_NEVER) ||
2390
+ (sbi->s_mount_opt & EXT4_MOUNT_DAX_ALWAYS)))
2391
+ goto fail_dax_change_remount;
2392
+ sbi->s_mount_opt2 |= EXT4_MOUNT2_DAX_NEVER;
2393
+ sbi->s_mount_opt &= ~EXT4_MOUNT_DAX_ALWAYS;
2394
+ break;
2395
+ case Opt_dax_inode:
2396
+ if (is_remount &&
2397
+ ((sbi->s_mount_opt & EXT4_MOUNT_DAX_ALWAYS) ||
2398
+ (sbi->s_mount_opt2 & EXT4_MOUNT2_DAX_NEVER) ||
2399
+ !(sbi->s_mount_opt2 & EXT4_MOUNT2_DAX_INODE)))
2400
+ goto fail_dax_change_remount;
2401
+ sbi->s_mount_opt &= ~EXT4_MOUNT_DAX_ALWAYS;
2402
+ sbi->s_mount_opt2 &= ~EXT4_MOUNT2_DAX_NEVER;
2403
+ /* Strictly for printing options */
2404
+ sbi->s_mount_opt2 |= EXT4_MOUNT2_DAX_INODE;
2405
+ break;
21012406 }
2102
- if (is_remount && !(sbi->s_mount_opt & EXT4_MOUNT_DAX)) {
2103
- ext4_msg(sb, KERN_ERR, "can't change "
2104
- "dax mount option while remounting");
2105
- return -1;
2106
- }
2107
- ext4_msg(sb, KERN_WARNING,
2108
- "DAX enabled. Warning: EXPERIMENTAL, use at your own risk");
2109
- sbi->s_mount_opt |= m->mount_opt;
21102407 #else
21112408 ext4_msg(sb, KERN_INFO, "dax option not supported");
2409
+ sbi->s_mount_opt2 |= EXT4_MOUNT2_DAX_NEVER;
2410
+ sbi->s_mount_opt &= ~EXT4_MOUNT_DAX_ALWAYS;
21122411 return -1;
21132412 #endif
21142413 } else if (token == Opt_data_err_abort) {
....@@ -2126,10 +2425,17 @@
21262425 WARN_ON(1);
21272426 return -1;
21282427 }
2129
- if (arg != 0)
2130
- sbi->s_mount_opt |= m->mount_opt;
2131
- else
2132
- sbi->s_mount_opt &= ~m->mount_opt;
2428
+ if (m->flags & MOPT_2) {
2429
+ if (arg != 0)
2430
+ sbi->s_mount_opt2 |= m->mount_opt;
2431
+ else
2432
+ sbi->s_mount_opt2 &= ~m->mount_opt;
2433
+ } else {
2434
+ if (arg != 0)
2435
+ sbi->s_mount_opt |= m->mount_opt;
2436
+ else
2437
+ sbi->s_mount_opt &= ~m->mount_opt;
2438
+ }
21332439 }
21342440 return 1;
21352441 }
....@@ -2139,7 +2445,7 @@
21392445 unsigned int *journal_ioprio,
21402446 int is_remount)
21412447 {
2142
- struct ext4_sb_info *sbi = EXT4_SB(sb);
2448
+ struct ext4_sb_info __maybe_unused *sbi = EXT4_SB(sb);
21432449 char *p, __maybe_unused *usr_qf_name, __maybe_unused *grp_qf_name;
21442450 substring_t args[MAX_OPT_ARGS];
21452451 int token;
....@@ -2196,12 +2502,10 @@
21962502 if (test_opt(sb, DIOREAD_NOLOCK)) {
21972503 int blocksize =
21982504 BLOCK_SIZE << le32_to_cpu(sbi->s_es->s_log_block_size);
2199
-
2200
- if (blocksize < PAGE_SIZE) {
2201
- ext4_msg(sb, KERN_ERR, "can't mount with "
2202
- "dioread_nolock if block size != PAGE_SIZE");
2203
- return 0;
2204
- }
2505
+ if (blocksize < PAGE_SIZE)
2506
+ ext4_msg(sb, KERN_WARNING, "Warning: mounting with an "
2507
+ "experimental mount option 'dioread_nolock' "
2508
+ "for blocksize < PAGE_SIZE");
22052509 }
22062510 return 1;
22072511 }
....@@ -2274,7 +2578,7 @@
22742578 for (m = ext4_mount_opts; m->token != Opt_err; m++) {
22752579 int want_set = m->flags & MOPT_SET;
22762580 if (((m->flags & (MOPT_SET|MOPT_CLEAR)) == 0) ||
2277
- (m->flags & MOPT_CLEAR_ERR))
2581
+ (m->flags & MOPT_CLEAR_ERR) || m->flags & MOPT_SKIP)
22782582 continue;
22792583 if (!nodefs && !(m->mount_opt & (sbi->s_mount_opt ^ def_mount_opt)))
22802584 continue; /* skip if same as the default */
....@@ -2334,6 +2638,19 @@
23342638
23352639 fscrypt_show_test_dummy_encryption(seq, sep, sb);
23362640
2641
+ if (sb->s_flags & SB_INLINECRYPT)
2642
+ SEQ_OPTS_PUTS("inlinecrypt");
2643
+
2644
+ if (test_opt(sb, DAX_ALWAYS)) {
2645
+ if (IS_EXT2_SB(sb))
2646
+ SEQ_OPTS_PUTS("dax");
2647
+ else
2648
+ SEQ_OPTS_PUTS("dax=always");
2649
+ } else if (test_opt2(sb, DAX_NEVER)) {
2650
+ SEQ_OPTS_PUTS("dax=never");
2651
+ } else if (test_opt2(sb, DAX_INODE)) {
2652
+ SEQ_OPTS_PUTS("dax=inode");
2653
+ }
23372654 ext4_show_quota_options(seq, sb);
23382655 return 0;
23392656 }
....@@ -2859,13 +3176,9 @@
28593176 loff_t res;
28603177 loff_t upper_limit = MAX_LFS_FILESIZE;
28613178
2862
- /* small i_blocks in vfs inode? */
2863
- if (!has_huge_files || sizeof(blkcnt_t) < sizeof(u64)) {
2864
- /*
2865
- * CONFIG_LBDAF is not enabled implies the inode
2866
- * i_block represent total blocks in 512 bytes
2867
- * 32 == size of vfs inode i_blocks * 8
2868
- */
3179
+ BUILD_BUG_ON(sizeof(blkcnt_t) < sizeof(u64));
3180
+
3181
+ if (!has_huge_files) {
28693182 upper_limit = (1LL << 32) - 1;
28703183
28713184 /* total blocks in file system block size */
....@@ -2895,22 +3208,22 @@
28953208 */
28963209 static loff_t ext4_max_bitmap_size(int bits, int has_huge_files)
28973210 {
2898
- loff_t res = EXT4_NDIR_BLOCKS;
3211
+ unsigned long long upper_limit, res = EXT4_NDIR_BLOCKS;
28993212 int meta_blocks;
2900
- loff_t upper_limit;
2901
- /* This is calculated to be the largest file size for a dense, block
3213
+
3214
+ /*
3215
+ * This is calculated to be the largest file size for a dense, block
29023216 * mapped file such that the file's total number of 512-byte sectors,
29033217 * including data and all indirect blocks, does not exceed (2^48 - 1).
29043218 *
29053219 * __u32 i_blocks_lo and _u16 i_blocks_high represent the total
29063220 * number of 512-byte sectors of the file.
29073221 */
2908
-
2909
- if (!has_huge_files || sizeof(blkcnt_t) < sizeof(u64)) {
3222
+ if (!has_huge_files) {
29103223 /*
2911
- * !has_huge_files or CONFIG_LBDAF not enabled implies that
2912
- * the inode i_block field represents total file blocks in
2913
- * 2^32 512-byte sectors == size of vfs inode i_blocks * 8
3224
+ * !has_huge_files or implies that the inode i_block field
3225
+ * represents total file blocks in 2^32 512-byte sectors ==
3226
+ * size of vfs inode i_blocks * 8
29143227 */
29153228 upper_limit = (1LL << 32) - 1;
29163229
....@@ -2948,7 +3261,7 @@
29483261 if (res > MAX_LFS_FILESIZE)
29493262 res = MAX_LFS_FILESIZE;
29503263
2951
- return res;
3264
+ return (loff_t)res;
29523265 }
29533266
29543267 static ext4_fsblk_t descriptor_loc(struct super_block *sb,
....@@ -3059,18 +3372,6 @@
30593372 ~EXT4_FEATURE_RO_COMPAT_SUPP));
30603373 return 0;
30613374 }
3062
- /*
3063
- * Large file size enabled file system can only be mounted
3064
- * read-write on 32-bit systems if kernel is built with CONFIG_LBDAF
3065
- */
3066
- if (ext4_has_feature_huge_file(sb)) {
3067
- if (sizeof(blkcnt_t) < sizeof(u64)) {
3068
- ext4_msg(sb, KERN_ERR, "Filesystem with huge files "
3069
- "cannot be mounted RDWR without "
3070
- "CONFIG_LBDAF");
3071
- return 0;
3072
- }
3073
- }
30743375 if (ext4_has_feature_bigalloc(sb) && !ext4_has_feature_extents(sb)) {
30753376 ext4_msg(sb, KERN_ERR,
30763377 "Can't support bigalloc feature without "
....@@ -3140,15 +3441,34 @@
31403441 static int ext4_run_li_request(struct ext4_li_request *elr)
31413442 {
31423443 struct ext4_group_desc *gdp = NULL;
3143
- ext4_group_t group, ngroups;
3144
- struct super_block *sb;
3444
+ struct super_block *sb = elr->lr_super;
3445
+ ext4_group_t ngroups = EXT4_SB(sb)->s_groups_count;
3446
+ ext4_group_t group = elr->lr_next_group;
3447
+ unsigned int prefetch_ios = 0;
31453448 int ret = 0;
31463449 u64 start_time;
31473450
3148
- sb = elr->lr_super;
3149
- ngroups = EXT4_SB(sb)->s_groups_count;
3451
+ if (elr->lr_mode == EXT4_LI_MODE_PREFETCH_BBITMAP) {
3452
+ elr->lr_next_group = ext4_mb_prefetch(sb, group,
3453
+ EXT4_SB(sb)->s_mb_prefetch, &prefetch_ios);
3454
+ if (prefetch_ios)
3455
+ ext4_mb_prefetch_fini(sb, elr->lr_next_group,
3456
+ prefetch_ios);
3457
+ trace_ext4_prefetch_bitmaps(sb, group, elr->lr_next_group,
3458
+ prefetch_ios);
3459
+ if (group >= elr->lr_next_group) {
3460
+ ret = 1;
3461
+ if (elr->lr_first_not_zeroed != ngroups &&
3462
+ !sb_rdonly(sb) && test_opt(sb, INIT_INODE_TABLE)) {
3463
+ elr->lr_next_group = elr->lr_first_not_zeroed;
3464
+ elr->lr_mode = EXT4_LI_MODE_ITABLE;
3465
+ ret = 0;
3466
+ }
3467
+ }
3468
+ return ret;
3469
+ }
31503470
3151
- for (group = elr->lr_next_group; group < ngroups; group++) {
3471
+ for (; group < ngroups; group++) {
31523472 gdp = ext4_get_group_desc(sb, group, NULL);
31533473 if (!gdp) {
31543474 ret = 1;
....@@ -3166,9 +3486,10 @@
31663486 start_time = ktime_get_real_ns();
31673487 ret = ext4_init_inode_table(sb, group,
31683488 elr->lr_timeout ? 0 : 1);
3489
+ trace_ext4_lazy_itable_init(sb, group);
31693490 if (elr->lr_timeout == 0) {
31703491 elr->lr_timeout = nsecs_to_jiffies((ktime_get_real_ns() - start_time) *
3171
- elr->lr_sbi->s_li_wait_mult);
3492
+ EXT4_SB(elr->lr_super)->s_li_wait_mult);
31723493 }
31733494 elr->lr_next_sched = jiffies + elr->lr_timeout;
31743495 elr->lr_next_group = group + 1;
....@@ -3182,15 +3503,11 @@
31823503 */
31833504 static void ext4_remove_li_request(struct ext4_li_request *elr)
31843505 {
3185
- struct ext4_sb_info *sbi;
3186
-
31873506 if (!elr)
31883507 return;
31893508
3190
- sbi = elr->lr_sbi;
3191
-
31923509 list_del(&elr->lr_request);
3193
- sbi->s_li_request = NULL;
3510
+ EXT4_SB(elr->lr_super)->s_li_request = NULL;
31943511 kfree(elr);
31953512 }
31963513
....@@ -3227,6 +3544,7 @@
32273544 unsigned long next_wakeup, cur;
32283545
32293546 BUG_ON(NULL == eli);
3547
+ set_freezable();
32303548
32313549 cont_thread:
32323550 while (true) {
....@@ -3399,7 +3717,6 @@
33993717 static struct ext4_li_request *ext4_li_request_new(struct super_block *sb,
34003718 ext4_group_t start)
34013719 {
3402
- struct ext4_sb_info *sbi = EXT4_SB(sb);
34033720 struct ext4_li_request *elr;
34043721
34053722 elr = kzalloc(sizeof(*elr), GFP_KERNEL);
....@@ -3407,8 +3724,13 @@
34073724 return NULL;
34083725
34093726 elr->lr_super = sb;
3410
- elr->lr_sbi = sbi;
3411
- elr->lr_next_group = start;
3727
+ elr->lr_first_not_zeroed = start;
3728
+ if (test_opt(sb, PREFETCH_BLOCK_BITMAPS))
3729
+ elr->lr_mode = EXT4_LI_MODE_PREFETCH_BBITMAP;
3730
+ else {
3731
+ elr->lr_mode = EXT4_LI_MODE_ITABLE;
3732
+ elr->lr_next_group = start;
3733
+ }
34123734
34133735 /*
34143736 * Randomize first schedule time of the request to
....@@ -3438,8 +3760,9 @@
34383760 goto out;
34393761 }
34403762
3441
- if (first_not_zeroed == ngroups || sb_rdonly(sb) ||
3442
- !test_opt(sb, INIT_INODE_TABLE))
3763
+ if (!test_opt(sb, PREFETCH_BLOCK_BITMAPS) &&
3764
+ (first_not_zeroed == ngroups || sb_rdonly(sb) ||
3765
+ !test_opt(sb, INIT_INODE_TABLE)))
34433766 goto out;
34443767
34453768 elr = ext4_li_request_new(sb, first_not_zeroed);
....@@ -3556,9 +3879,11 @@
35563879 ext4_fsblk_t first_block, last_block, b;
35573880 ext4_group_t i, ngroups = ext4_get_groups_count(sb);
35583881 int s, j, count = 0;
3882
+ int has_super = ext4_bg_has_super(sb, grp);
35593883
35603884 if (!ext4_has_feature_bigalloc(sb))
3561
- return (ext4_bg_has_super(sb, grp) + ext4_bg_num_gdb(sb, grp) +
3885
+ return (has_super + ext4_bg_num_gdb(sb, grp) +
3886
+ (has_super ? le16_to_cpu(sbi->s_es->s_reserved_gdt_blocks) : 0) +
35623887 sbi->s_itb_per_group + 2);
35633888
35643889 first_block = le32_to_cpu(sbi->s_es->s_first_data_block) +
....@@ -3650,8 +3975,8 @@
36503975 * Add the internal journal blocks whether the journal has been
36513976 * loaded or not
36523977 */
3653
- if (sbi->s_journal && !sbi->journal_bdev)
3654
- overhead += EXT4_NUM_B2C(sbi, sbi->s_journal->j_maxlen);
3978
+ if (sbi->s_journal && !sbi->s_journal_bdev)
3979
+ overhead += EXT4_NUM_B2C(sbi, sbi->s_journal->j_total_len);
36553980 else if (ext4_has_feature_journal(sb) && !sbi->s_journal && j_inum) {
36563981 /* j_inum for internal journal is non-zero */
36573982 j_inode = ext4_get_journal_inode(sb, j_inum);
....@@ -3719,7 +4044,7 @@
37194044 int blocksize, clustersize;
37204045 unsigned int db_count;
37214046 unsigned int i;
3722
- int needs_recovery, has_huge_files, has_bigalloc;
4047
+ int needs_recovery, has_huge_files;
37234048 __u64 blocks_count;
37244049 int err = 0;
37254050 unsigned int journal_ioprio = DEFAULT_JOURNAL_IOPRIO;
....@@ -3764,8 +4089,11 @@
37644089 logical_sb_block = sb_block;
37654090 }
37664091
3767
- if (!(bh = sb_bread_unmovable(sb, logical_sb_block))) {
4092
+ bh = ext4_sb_bread_unmovable(sb, logical_sb_block);
4093
+ if (IS_ERR(bh)) {
37684094 ext4_msg(sb, KERN_ERR, "unable to read superblock");
4095
+ ret = PTR_ERR(bh);
4096
+ bh = NULL;
37694097 goto out_fail;
37704098 }
37714099 /*
....@@ -3832,6 +4160,8 @@
38324160 #ifdef CONFIG_EXT4_FS_POSIX_ACL
38334161 set_opt(sb, POSIX_ACL);
38344162 #endif
4163
+ if (ext4_has_feature_fast_commit(sb))
4164
+ set_opt2(sb, JOURNAL_FAST_COMMIT);
38354165 /* don't forget to enable journal_csum when metadata_csum is enabled. */
38364166 if (ext4_has_metadata_csum(sb))
38374167 set_opt(sb, JOURNAL_CHECKSUM);
....@@ -3877,14 +4207,25 @@
38774207 */
38784208 sbi->s_li_wait_mult = EXT4_DEF_LI_WAIT_MULT;
38794209
3880
- blocksize = BLOCK_SIZE << le32_to_cpu(es->s_log_block_size);
3881
- if (blocksize < EXT4_MIN_BLOCK_SIZE ||
3882
- blocksize > EXT4_MAX_BLOCK_SIZE) {
4210
+ if (le32_to_cpu(es->s_log_block_size) >
4211
+ (EXT4_MAX_BLOCK_LOG_SIZE - EXT4_MIN_BLOCK_LOG_SIZE)) {
38834212 ext4_msg(sb, KERN_ERR,
3884
- "Unsupported filesystem blocksize %d (%d log_block_size)",
3885
- blocksize, le32_to_cpu(es->s_log_block_size));
4213
+ "Invalid log block size: %u",
4214
+ le32_to_cpu(es->s_log_block_size));
38864215 goto failed_mount;
38874216 }
4217
+ if (le32_to_cpu(es->s_log_cluster_size) >
4218
+ (EXT4_MAX_CLUSTER_LOG_SIZE - EXT4_MIN_BLOCK_LOG_SIZE)) {
4219
+ ext4_msg(sb, KERN_ERR,
4220
+ "Invalid log cluster size: %u",
4221
+ le32_to_cpu(es->s_log_cluster_size));
4222
+ goto failed_mount;
4223
+ }
4224
+
4225
+ blocksize = EXT4_MIN_BLOCK_SIZE << le32_to_cpu(es->s_log_block_size);
4226
+
4227
+ if (blocksize == PAGE_SIZE)
4228
+ set_opt(sb, DIOREAD_NOLOCK);
38884229
38894230 if (le32_to_cpu(es->s_rev_level) == EXT4_GOOD_OLD_REV) {
38904231 sbi->s_inode_size = EXT4_GOOD_OLD_INODE_SIZE;
....@@ -3915,9 +4256,12 @@
39154256 if (sbi->s_inode_size >= offsetof(struct ext4_inode, i_atime_extra) +
39164257 sizeof(((struct ext4_inode *)0)->i_atime_extra)) {
39174258 sb->s_time_gran = 1;
4259
+ sb->s_time_max = EXT4_EXTRA_TIMESTAMP_MAX;
39184260 } else {
39194261 sb->s_time_gran = NSEC_PER_SEC;
4262
+ sb->s_time_max = EXT4_NON_EXTRA_TIMESTAMP_MAX;
39204263 }
4264
+ sb->s_time_min = EXT4_TIMESTAMP_MIN;
39214265 }
39224266 if (sbi->s_inode_size > EXT4_GOOD_OLD_INODE_SIZE) {
39234267 sbi->s_want_extra_isize = sizeof(struct ext4_inode) -
....@@ -3997,20 +4341,16 @@
39974341 #endif
39984342
39994343 if (test_opt(sb, DATA_FLAGS) == EXT4_MOUNT_JOURNAL_DATA) {
4000
- printk_once(KERN_WARNING "EXT4-fs: Warning: mounting "
4001
- "with data=journal disables delayed "
4002
- "allocation and O_DIRECT support!\n");
4344
+ printk_once(KERN_WARNING "EXT4-fs: Warning: mounting with data=journal disables delayed allocation, dioread_nolock, O_DIRECT and fast_commit support!\n");
4345
+ /* can't mount with both data=journal and dioread_nolock. */
4346
+ clear_opt(sb, DIOREAD_NOLOCK);
4347
+ clear_opt2(sb, JOURNAL_FAST_COMMIT);
40034348 if (test_opt2(sb, EXPLICIT_DELALLOC)) {
40044349 ext4_msg(sb, KERN_ERR, "can't mount with "
40054350 "both data=journal and delalloc");
40064351 goto failed_mount;
40074352 }
4008
- if (test_opt(sb, DIOREAD_NOLOCK)) {
4009
- ext4_msg(sb, KERN_ERR, "can't mount with "
4010
- "both data=journal and dioread_nolock");
4011
- goto failed_mount;
4012
- }
4013
- if (test_opt(sb, DAX)) {
4353
+ if (test_opt(sb, DAX_ALWAYS)) {
40144354 ext4_msg(sb, KERN_ERR, "can't mount with "
40154355 "both data=journal and dax");
40164356 goto failed_mount;
....@@ -4098,21 +4438,6 @@
40984438 if (!ext4_feature_set_ok(sb, (sb_rdonly(sb))))
40994439 goto failed_mount;
41004440
4101
- if (le32_to_cpu(es->s_log_block_size) >
4102
- (EXT4_MAX_BLOCK_LOG_SIZE - EXT4_MIN_BLOCK_LOG_SIZE)) {
4103
- ext4_msg(sb, KERN_ERR,
4104
- "Invalid log block size: %u",
4105
- le32_to_cpu(es->s_log_block_size));
4106
- goto failed_mount;
4107
- }
4108
- if (le32_to_cpu(es->s_log_cluster_size) >
4109
- (EXT4_MAX_CLUSTER_LOG_SIZE - EXT4_MIN_BLOCK_LOG_SIZE)) {
4110
- ext4_msg(sb, KERN_ERR,
4111
- "Invalid log cluster size: %u",
4112
- le32_to_cpu(es->s_log_cluster_size));
4113
- goto failed_mount;
4114
- }
4115
-
41164441 if (le16_to_cpu(sbi->s_es->s_reserved_gdt_blocks) > (blocksize / 4)) {
41174442 ext4_msg(sb, KERN_ERR,
41184443 "Number of reserved GDT blocks insanely large: %d",
....@@ -4120,16 +4445,19 @@
41204445 goto failed_mount;
41214446 }
41224447
4123
- if (sbi->s_mount_opt & EXT4_MOUNT_DAX) {
4448
+ if (bdev_dax_supported(sb->s_bdev, blocksize))
4449
+ set_bit(EXT4_FLAGS_BDEV_IS_DAX, &sbi->s_ext4_flags);
4450
+
4451
+ if (sbi->s_mount_opt & EXT4_MOUNT_DAX_ALWAYS) {
41244452 if (ext4_has_feature_inline_data(sb)) {
41254453 ext4_msg(sb, KERN_ERR, "Cannot use DAX on a filesystem"
41264454 " that may contain inline data");
4127
- sbi->s_mount_opt &= ~EXT4_MOUNT_DAX;
4455
+ goto failed_mount;
41284456 }
4129
- if (!bdev_dax_supported(sb->s_bdev, blocksize)) {
4457
+ if (!test_bit(EXT4_FLAGS_BDEV_IS_DAX, &sbi->s_ext4_flags)) {
41304458 ext4_msg(sb, KERN_ERR,
4131
- "DAX unsupported by block device. Turning off DAX.");
4132
- sbi->s_mount_opt &= ~EXT4_MOUNT_DAX;
4459
+ "DAX unsupported by block device.");
4460
+ goto failed_mount;
41334461 }
41344462 }
41354463
....@@ -4140,20 +4468,28 @@
41404468 }
41414469
41424470 if (sb->s_blocksize != blocksize) {
4471
+ /*
4472
+ * bh must be released before kill_bdev(), otherwise
4473
+ * it won't be freed and its page also. kill_bdev()
4474
+ * is called by sb_set_blocksize().
4475
+ */
4476
+ brelse(bh);
41434477 /* Validate the filesystem blocksize */
41444478 if (!sb_set_blocksize(sb, blocksize)) {
41454479 ext4_msg(sb, KERN_ERR, "bad block size %d",
41464480 blocksize);
4481
+ bh = NULL;
41474482 goto failed_mount;
41484483 }
41494484
4150
- brelse(bh);
41514485 logical_sb_block = sb_block * EXT4_MIN_BLOCK_SIZE;
41524486 offset = do_div(logical_sb_block, blocksize);
4153
- bh = sb_bread_unmovable(sb, logical_sb_block);
4154
- if (!bh) {
4487
+ bh = ext4_sb_bread_unmovable(sb, logical_sb_block);
4488
+ if (IS_ERR(bh)) {
41554489 ext4_msg(sb, KERN_ERR,
41564490 "Can't read superblock on 2nd try");
4491
+ ret = PTR_ERR(bh);
4492
+ bh = NULL;
41574493 goto failed_mount;
41584494 }
41594495 es = (struct ext4_super_block *)(bh->b_data + offset);
....@@ -4199,7 +4535,7 @@
41994535 sbi->s_inodes_per_block;
42004536 sbi->s_desc_per_block = blocksize / EXT4_DESC_SIZE(sb);
42014537 sbi->s_sbh = bh;
4202
- sbi->s_mount_state = le16_to_cpu(es->s_state);
4538
+ sbi->s_mount_state = le16_to_cpu(es->s_state) & ~EXT4_FC_REPLAY;
42034539 sbi->s_addr_per_block_bits = ilog2(EXT4_ADDR_PER_BLOCK(sb));
42044540 sbi->s_desc_per_block_bits = ilog2(EXT4_DESC_PER_BLOCK(sb));
42054541
....@@ -4226,8 +4562,7 @@
42264562
42274563 /* Handle clustersize */
42284564 clustersize = BLOCK_SIZE << le32_to_cpu(es->s_log_cluster_size);
4229
- has_bigalloc = ext4_has_feature_bigalloc(sb);
4230
- if (has_bigalloc) {
4565
+ if (ext4_has_feature_bigalloc(sb)) {
42314566 if (clustersize < blocksize) {
42324567 ext4_msg(sb, KERN_ERR,
42334568 "cluster size (%d) smaller than "
....@@ -4283,8 +4618,6 @@
42834618 if (err) {
42844619 ext4_msg(sb, KERN_ERR, "filesystem"
42854620 " too large to mount safely on this system");
4286
- if (sizeof(sector_t) < 8)
4287
- ext4_msg(sb, KERN_WARNING, "CONFIG_LBDAF not enabled");
42884621 goto failed_mount;
42894622 }
42904623
....@@ -4368,18 +4701,20 @@
43684701 /* Pre-read the descriptors into the buffer cache */
43694702 for (i = 0; i < db_count; i++) {
43704703 block = descriptor_loc(sb, logical_sb_block, i);
4371
- sb_breadahead_unmovable(sb, block);
4704
+ ext4_sb_breadahead_unmovable(sb, block);
43724705 }
43734706
43744707 for (i = 0; i < db_count; i++) {
43754708 struct buffer_head *bh;
43764709
43774710 block = descriptor_loc(sb, logical_sb_block, i);
4378
- bh = sb_bread_unmovable(sb, block);
4379
- if (!bh) {
4711
+ bh = ext4_sb_bread_unmovable(sb, block);
4712
+ if (IS_ERR(bh)) {
43804713 ext4_msg(sb, KERN_ERR,
43814714 "can't read group descriptor %d", i);
43824715 db_count = i;
4716
+ ret = PTR_ERR(bh);
4717
+ bh = NULL;
43834718 goto failed_mount2;
43844719 }
43854720 rcu_read_lock();
....@@ -4426,6 +4761,26 @@
44264761
44274762 INIT_LIST_HEAD(&sbi->s_orphan); /* unlinked but open files */
44284763 mutex_init(&sbi->s_orphan_lock);
4764
+
4765
+ /* Initialize fast commit stuff */
4766
+ atomic_set(&sbi->s_fc_subtid, 0);
4767
+ atomic_set(&sbi->s_fc_ineligible_updates, 0);
4768
+ INIT_LIST_HEAD(&sbi->s_fc_q[FC_Q_MAIN]);
4769
+ INIT_LIST_HEAD(&sbi->s_fc_q[FC_Q_STAGING]);
4770
+ INIT_LIST_HEAD(&sbi->s_fc_dentry_q[FC_Q_MAIN]);
4771
+ INIT_LIST_HEAD(&sbi->s_fc_dentry_q[FC_Q_STAGING]);
4772
+ sbi->s_fc_bytes = 0;
4773
+ ext4_clear_mount_flag(sb, EXT4_MF_FC_INELIGIBLE);
4774
+ ext4_clear_mount_flag(sb, EXT4_MF_FC_COMMITTING);
4775
+ spin_lock_init(&sbi->s_fc_lock);
4776
+ memset(&sbi->s_fc_stats, 0, sizeof(sbi->s_fc_stats));
4777
+ sbi->s_fc_replay_state.fc_regions = NULL;
4778
+ sbi->s_fc_replay_state.fc_regions_size = 0;
4779
+ sbi->s_fc_replay_state.fc_regions_used = 0;
4780
+ sbi->s_fc_replay_state.fc_regions_valid = 0;
4781
+ sbi->s_fc_replay_state.fc_modified_inodes = NULL;
4782
+ sbi->s_fc_replay_state.fc_modified_inodes_size = 0;
4783
+ sbi->s_fc_replay_state.fc_modified_inodes_used = 0;
44294784
44304785 sb->s_root = NULL;
44314786
....@@ -4476,6 +4831,7 @@
44764831 sbi->s_def_mount_opt &= ~EXT4_MOUNT_JOURNAL_CHECKSUM;
44774832 clear_opt(sb, JOURNAL_CHECKSUM);
44784833 clear_opt(sb, DATA_FLAGS);
4834
+ clear_opt2(sb, JOURNAL_FAST_COMMIT);
44794835 sbi->s_journal = NULL;
44804836 needs_recovery = 0;
44814837 goto no_journal;
....@@ -4491,6 +4847,14 @@
44914847 if (!set_journal_csum_feature_set(sb)) {
44924848 ext4_msg(sb, KERN_ERR, "Failed to set journal checksum "
44934849 "feature set");
4850
+ goto failed_mount_wq;
4851
+ }
4852
+
4853
+ if (test_opt2(sb, JOURNAL_FAST_COMMIT) &&
4854
+ !jbd2_journal_set_features(EXT4_SB(sb)->s_journal, 0, 0,
4855
+ JBD2_FEATURE_INCOMPAT_FAST_COMMIT)) {
4856
+ ext4_msg(sb, KERN_ERR,
4857
+ "Failed to set fast commit journal feature");
44944858 goto failed_mount_wq;
44954859 }
44964860
....@@ -4533,7 +4897,10 @@
45334897
45344898 set_task_ioprio(sbi->s_journal->j_task, journal_ioprio);
45354899
4536
- sbi->s_journal->j_commit_callback = ext4_journal_commit_callback;
4900
+ sbi->s_journal->j_submit_inode_data_buffers =
4901
+ ext4_journal_submit_inode_data_buffers;
4902
+ sbi->s_journal->j_finish_inode_data_buffers =
4903
+ ext4_journal_finish_inode_data_buffers;
45374904
45384905 no_journal:
45394906 if (!test_opt(sb, NO_MBCACHE)) {
....@@ -4554,31 +4921,27 @@
45544921 }
45554922 }
45564923
4557
- if ((DUMMY_ENCRYPTION_ENABLED(sbi) || ext4_has_feature_encrypt(sb)) &&
4558
- (blocksize != PAGE_SIZE)) {
4559
- ext4_msg(sb, KERN_ERR,
4560
- "Unsupported blocksize for fs encryption");
4561
- goto failed_mount_wq;
4562
- }
4563
-
45644924 if (ext4_has_feature_verity(sb) && blocksize != PAGE_SIZE) {
45654925 ext4_msg(sb, KERN_ERR, "Unsupported blocksize for fs-verity");
45664926 goto failed_mount_wq;
4567
- }
4568
-
4569
- if (DUMMY_ENCRYPTION_ENABLED(sbi) && !sb_rdonly(sb) &&
4570
- !ext4_has_feature_encrypt(sb)) {
4571
- ext4_set_feature_encrypt(sb);
4572
- ext4_commit_super(sb, 1);
45734927 }
45744928
45754929 /*
45764930 * Get the # of file system overhead blocks from the
45774931 * superblock if present.
45784932 */
4579
- if (es->s_overhead_clusters)
4580
- sbi->s_overhead = le32_to_cpu(es->s_overhead_clusters);
4581
- else {
4933
+ sbi->s_overhead = le32_to_cpu(es->s_overhead_clusters);
4934
+ /* ignore the precalculated value if it is ridiculous */
4935
+ if (sbi->s_overhead > ext4_blocks_count(es))
4936
+ sbi->s_overhead = 0;
4937
+ /*
4938
+ * If the bigalloc feature is not enabled recalculating the
4939
+ * overhead doesn't take long, so we might as well just redo
4940
+ * it to make sure we are using the correct value.
4941
+ */
4942
+ if (!ext4_has_feature_bigalloc(sb))
4943
+ sbi->s_overhead = 0;
4944
+ if (sbi->s_overhead == 0) {
45824945 err = ext4_calculate_overhead(sb);
45834946 if (err)
45844947 goto failed_mount_wq;
....@@ -4638,6 +5001,7 @@
46385001 goto failed_mount4a;
46395002 }
46405003 }
5004
+ ext4_fc_replay_cleanup(sb);
46415005
46425006 ext4_ext_init(sb);
46435007 err = ext4_mb_init(sb);
....@@ -4646,6 +5010,14 @@
46465010 err);
46475011 goto failed_mount5;
46485012 }
5013
+
5014
+ /*
5015
+ * We can only set up the journal commit callback once
5016
+ * mballoc is initialized
5017
+ */
5018
+ if (sbi->s_journal)
5019
+ sbi->s_journal->j_commit_callback =
5020
+ ext4_journal_commit_callback;
46495021
46505022 block = ext4_count_free_clusters(sb);
46515023 ext4_free_blocks_count_set(sbi->s_es,
....@@ -4665,6 +5037,9 @@
46655037 ext4_count_dirs(sb), GFP_KERNEL);
46665038 if (!err)
46675039 err = percpu_counter_init(&sbi->s_dirtyclusters_counter, 0,
5040
+ GFP_KERNEL);
5041
+ if (!err)
5042
+ err = percpu_counter_init(&sbi->s_sra_exceeded_retry_limit, 0,
46685043 GFP_KERNEL);
46695044 if (!err)
46705045 err = percpu_init_rwsem(&sbi->s_writepages_rwsem);
....@@ -4700,6 +5075,14 @@
47005075 }
47015076 #endif /* CONFIG_QUOTA */
47025077
5078
+ /*
5079
+ * Save the original bdev mapping's wb_err value which could be
5080
+ * used to detect the metadata async write error.
5081
+ */
5082
+ spin_lock_init(&sbi->s_bdev_wb_lock);
5083
+ errseq_check_and_advance(&sb->s_bdev->bd_inode->i_mapping->wb_err,
5084
+ &sbi->s_bdev_wb_err);
5085
+ sb->s_bdev->bd_super = sb;
47035086 EXT4_SB(sb)->s_mount_state |= EXT4_ORPHAN_FS;
47045087 ext4_orphan_cleanup(sb, es);
47055088 EXT4_SB(sb)->s_mount_state &= ~EXT4_ORPHAN_FS;
....@@ -4741,6 +5124,8 @@
47415124 ratelimit_state_init(&sbi->s_err_ratelimit_state, 5 * HZ, 10);
47425125 ratelimit_state_init(&sbi->s_warning_ratelimit_state, 5 * HZ, 10);
47435126 ratelimit_state_init(&sbi->s_msg_ratelimit_state, 5 * HZ, 10);
5127
+ atomic_set(&sbi->s_warning_count, 0);
5128
+ atomic_set(&sbi->s_msg_count, 0);
47445129
47455130 kfree(orig_data);
47465131 return 0;
....@@ -4769,6 +5154,7 @@
47695154 percpu_counter_destroy(&sbi->s_freeinodes_counter);
47705155 percpu_counter_destroy(&sbi->s_dirs_counter);
47715156 percpu_counter_destroy(&sbi->s_dirtyclusters_counter);
5157
+ percpu_counter_destroy(&sbi->s_sra_exceeded_retry_limit);
47725158 percpu_free_rwsem(&sbi->s_writepages_rwsem);
47735159 failed_mount5:
47745160 ext4_ext_release(sb);
....@@ -4781,14 +5167,12 @@
47815167 if (EXT4_SB(sb)->rsv_conversion_wq)
47825168 destroy_workqueue(EXT4_SB(sb)->rsv_conversion_wq);
47835169 failed_mount_wq:
4784
- if (sbi->s_ea_inode_cache) {
4785
- ext4_xattr_destroy_cache(sbi->s_ea_inode_cache);
4786
- sbi->s_ea_inode_cache = NULL;
4787
- }
4788
- if (sbi->s_ea_block_cache) {
4789
- ext4_xattr_destroy_cache(sbi->s_ea_block_cache);
4790
- sbi->s_ea_block_cache = NULL;
4791
- }
5170
+ ext4_xattr_destroy_cache(sbi->s_ea_inode_cache);
5171
+ sbi->s_ea_inode_cache = NULL;
5172
+
5173
+ ext4_xattr_destroy_cache(sbi->s_ea_block_cache);
5174
+ sbi->s_ea_block_cache = NULL;
5175
+
47925176 if (sbi->s_journal) {
47935177 jbd2_journal_destroy(sbi->s_journal);
47945178 sbi->s_journal = NULL;
....@@ -4797,8 +5181,7 @@
47975181 ext4_es_unregister_shrinker(sbi);
47985182 failed_mount3:
47995183 del_timer_sync(&sbi->s_err_report);
4800
- if (sbi->s_mmp_tsk)
4801
- kthread_stop(sbi->s_mmp_tsk);
5184
+ ext4_stop_mmpd(sbi);
48025185 failed_mount2:
48035186 rcu_read_lock();
48045187 group_desc = rcu_dereference(sbi->s_group_desc);
....@@ -4816,11 +5199,12 @@
48165199
48175200 #ifdef CONFIG_QUOTA
48185201 for (i = 0; i < EXT4_MAXQUOTAS; i++)
4819
- kfree(sbi->s_qf_names[i]);
5202
+ kfree(get_qf_name(sb, sbi, i));
48205203 #endif
4821
- fscrypt_free_dummy_context(&sbi->s_dummy_enc_ctx);
4822
- ext4_blkdev_remove(sbi);
5204
+ fscrypt_free_dummy_policy(&sbi->s_dummy_enc_policy);
5205
+ /* ext4_blkdev_remove() calls kill_bdev(), release bh before it. */
48235206 brelse(bh);
5207
+ ext4_blkdev_remove(sbi);
48245208 out_fail:
48255209 sb->s_fs_info = NULL;
48265210 kfree(sbi->s_blockgroup_lock);
....@@ -4843,6 +5227,7 @@
48435227 journal->j_commit_interval = sbi->s_commit_interval;
48445228 journal->j_min_batch_time = sbi->s_min_batch_time;
48455229 journal->j_max_batch_time = sbi->s_max_batch_time;
5230
+ ext4_fc_init(sb, journal);
48465231
48475232 write_lock(&journal->j_state_lock);
48485233 if (test_opt(sb, BARRIER))
....@@ -4985,9 +5370,7 @@
49855370 goto out_bdev;
49865371 }
49875372 journal->j_private = sb;
4988
- ll_rw_block(REQ_OP_READ, REQ_META | REQ_PRIO, 1, &journal->j_sb_buffer);
4989
- wait_on_buffer(journal->j_sb_buffer);
4990
- if (!buffer_uptodate(journal->j_sb_buffer)) {
5373
+ if (ext4_read_bh_lock(journal->j_sb_buffer, REQ_META | REQ_PRIO, true)) {
49915374 ext4_msg(sb, KERN_ERR, "I/O error on journal device");
49925375 goto out_journal;
49935376 }
....@@ -4997,7 +5380,7 @@
49975380 be32_to_cpu(journal->j_superblock->s_nr_users));
49985381 goto out_journal;
49995382 }
5000
- EXT4_SB(sb)->journal_bdev = bdev;
5383
+ EXT4_SB(sb)->s_journal_bdev = bdev;
50015384 ext4_init_journal_params(sb, journal);
50025385 return journal;
50035386
....@@ -5323,7 +5706,7 @@
53235706 needs_barrier = true;
53245707 if (needs_barrier) {
53255708 int err;
5326
- err = blkdev_issue_flush(sb->s_bdev, GFP_KERNEL, NULL);
5709
+ err = blkdev_issue_flush(sb->s_bdev, GFP_KERNEL);
53275710 if (!ret)
53285711 ret = err;
53295712 }
....@@ -5502,8 +5885,8 @@
55025885 goto restore_opts;
55035886 }
55045887
5505
- if (sbi->s_mount_flags & EXT4_MF_FS_ABORTED)
5506
- ext4_abort(sb, "Abort forced by user");
5888
+ if (ext4_test_mount_flag(sb, EXT4_MF_FS_ABORTED))
5889
+ ext4_abort(sb, EXT4_ERR_ESHUTDOWN, "Abort forced by user");
55075890
55085891 sb->s_flags = (sb->s_flags & ~SB_POSIXACL) |
55095892 (test_opt(sb, POSIX_ACL) ? SB_POSIXACL : 0);
....@@ -5516,7 +5899,7 @@
55165899 }
55175900
55185901 if ((bool)(*flags & SB_RDONLY) != sb_rdonly(sb)) {
5519
- if (sbi->s_mount_flags & EXT4_MF_FS_ABORTED) {
5902
+ if (ext4_test_mount_flag(sb, EXT4_MF_FS_ABORTED)) {
55205903 err = -EROFS;
55215904 goto restore_opts;
55225905 }
....@@ -5551,8 +5934,6 @@
55515934 */
55525935 ext4_mark_recovery_complete(sb, es);
55535936 }
5554
- if (sbi->s_mmp_tsk)
5555
- kthread_stop(sbi->s_mmp_tsk);
55565937 } else {
55575938 /* Make sure we can mount this feature set readwrite */
55585939 if (ext4_has_feature_readonly(sb) ||
....@@ -5603,7 +5984,8 @@
56035984 if (err)
56045985 goto restore_opts;
56055986 }
5606
- sbi->s_mount_state = le16_to_cpu(es->s_state);
5987
+ sbi->s_mount_state = (le16_to_cpu(es->s_state) &
5988
+ ~EXT4_FC_REPLAY);
56075989
56085990 err = ext4_setup_super(sb, es, 0);
56095991 if (err)
....@@ -5637,7 +6019,7 @@
56376019 * Releasing of existing data is done when we are sure remount will
56386020 * succeed.
56396021 */
5640
- if (test_opt(sb, BLOCK_VALIDITY) && !sbi->system_blks) {
6022
+ if (test_opt(sb, BLOCK_VALIDITY) && !sbi->s_system_blks) {
56416023 err = ext4_setup_system_zone(sb);
56426024 if (err)
56436025 goto restore_opts;
....@@ -5663,8 +6045,11 @@
56636045 }
56646046 }
56656047 #endif
5666
- if (!test_opt(sb, BLOCK_VALIDITY) && sbi->system_blks)
6048
+ if (!test_opt(sb, BLOCK_VALIDITY) && sbi->s_system_blks)
56676049 ext4_release_system_zone(sb);
6050
+
6051
+ if (!ext4_has_feature_mmp(sb) || sb_rdonly(sb))
6052
+ ext4_stop_mmpd(sbi);
56686053
56696054 /*
56706055 * Some options can be enabled by ext4 and/or by VFS mount flag
....@@ -5686,7 +6071,7 @@
56866071 sbi->s_commit_interval = old_opts.s_commit_interval;
56876072 sbi->s_min_batch_time = old_opts.s_min_batch_time;
56886073 sbi->s_max_batch_time = old_opts.s_max_batch_time;
5689
- if (!test_opt(sb, BLOCK_VALIDITY) && sbi->system_blks)
6074
+ if (!test_opt(sb, BLOCK_VALIDITY) && sbi->s_system_blks)
56906075 ext4_release_system_zone(sb);
56916076 #ifdef CONFIG_QUOTA
56926077 sbi->s_jquota_fmt = old_opts.s_jquota_fmt;
....@@ -5698,6 +6083,8 @@
56986083 for (i = 0; i < EXT4_MAXQUOTAS; i++)
56996084 kfree(to_free[i]);
57006085 #endif
6086
+ if (!ext4_has_feature_mmp(sb) || sb_rdonly(sb))
6087
+ ext4_stop_mmpd(sbi);
57016088 kfree(orig_data);
57026089 return err;
57036090 }
....@@ -5717,9 +6104,10 @@
57176104 return PTR_ERR(dquot);
57186105 spin_lock(&dquot->dq_dqb_lock);
57196106
5720
- limit = (dquot->dq_dqb.dqb_bsoftlimit ?
5721
- dquot->dq_dqb.dqb_bsoftlimit :
5722
- dquot->dq_dqb.dqb_bhardlimit) >> sb->s_blocksize_bits;
6107
+ limit = min_not_zero(dquot->dq_dqb.dqb_bsoftlimit,
6108
+ dquot->dq_dqb.dqb_bhardlimit);
6109
+ limit >>= sb->s_blocksize_bits;
6110
+
57236111 if (limit && buf->f_blocks > limit) {
57246112 curblock = (dquot->dq_dqb.dqb_curspace +
57256113 dquot->dq_dqb.dqb_rsvspace) >> sb->s_blocksize_bits;
....@@ -5729,9 +6117,8 @@
57296117 (buf->f_blocks - curblock) : 0;
57306118 }
57316119
5732
- limit = dquot->dq_dqb.dqb_isoftlimit ?
5733
- dquot->dq_dqb.dqb_isoftlimit :
5734
- dquot->dq_dqb.dqb_ihardlimit;
6120
+ limit = min_not_zero(dquot->dq_dqb.dqb_isoftlimit,
6121
+ dquot->dq_dqb.dqb_ihardlimit);
57356122 if (limit && buf->f_files > limit) {
57366123 buf->f_files = limit;
57376124 buf->f_ffree =
....@@ -5774,8 +6161,7 @@
57746161 buf->f_namelen = EXT4_NAME_LEN;
57756162 fsid = le64_to_cpup((void *)es->s_uuid) ^
57766163 le64_to_cpup((void *)es->s_uuid + sizeof(u64));
5777
- buf->f_fsid.val[0] = fsid & 0xFFFFFFFFUL;
5778
- buf->f_fsid.val[1] = (fsid >> 32) & 0xFFFFFFFFUL;
6164
+ buf->f_fsid = u64_to_fsid(fsid);
57796165
57806166 #ifdef CONFIG_QUOTA
57816167 if (ext4_test_inode_flag(dentry->d_inode, EXT4_INODE_PROJINHERIT) &&
....@@ -5871,7 +6257,7 @@
58716257 handle_t *handle;
58726258
58736259 /* Data block + inode block */
5874
- handle = ext4_journal_start(d_inode(sb->s_root), EXT4_HT_QUOTA, 2);
6260
+ handle = ext4_journal_start_sb(sb, EXT4_HT_QUOTA, 2);
58756261 if (IS_ERR(handle))
58766262 return PTR_ERR(handle);
58776263 ret = dquot_commit_info(sb, type);
....@@ -5975,7 +6361,7 @@
59756361 EXT4_I(inode)->i_flags |= EXT4_NOATIME_FL | EXT4_IMMUTABLE_FL;
59766362 inode_set_flags(inode, S_NOATIME | S_IMMUTABLE,
59776363 S_NOATIME | S_IMMUTABLE);
5978
- ext4_mark_inode_dirty(handle, inode);
6364
+ err = ext4_mark_inode_dirty(handle, inode);
59796365 ext4_journal_stop(handle);
59806366 unlock_inode:
59816367 inode_unlock(inode);
....@@ -6013,7 +6399,7 @@
60136399 /* Don't account quota for quota files to avoid recursion */
60146400 qf_inode->i_flags |= S_NOQUOTA;
60156401 lockdep_set_quota_inode(qf_inode, I_DATA_SEM_QUOTA);
6016
- err = dquot_enable(qf_inode, type, format_id, flags);
6402
+ err = dquot_load_quota_inode(qf_inode, type, format_id, flags);
60176403 if (err)
60186404 lockdep_set_quota_inode(qf_inode, I_DATA_SEM_NORMAL);
60196405 iput(qf_inode);
....@@ -6093,12 +6479,14 @@
60936479 * this is not a hard failure and quotas are already disabled.
60946480 */
60956481 handle = ext4_journal_start(inode, EXT4_HT_QUOTA, 1);
6096
- if (IS_ERR(handle))
6482
+ if (IS_ERR(handle)) {
6483
+ err = PTR_ERR(handle);
60976484 goto out_unlock;
6485
+ }
60986486 EXT4_I(inode)->i_flags &= ~(EXT4_NOATIME_FL | EXT4_IMMUTABLE_FL);
60996487 inode_set_flags(inode, 0, S_NOATIME | S_IMMUTABLE);
61006488 inode->i_mtime = inode->i_ctime = current_time(inode);
6101
- ext4_mark_inode_dirty(handle, inode);
6489
+ err = ext4_mark_inode_dirty(handle, inode);
61026490 ext4_journal_stop(handle);
61036491 out_unlock:
61046492 inode_unlock(inode);
....@@ -6156,7 +6544,7 @@
61566544 {
61576545 struct inode *inode = sb_dqopt(sb)->files[type];
61586546 ext4_lblk_t blk = off >> EXT4_BLOCK_SIZE_BITS(sb);
6159
- int err, offset = off & (sb->s_blocksize - 1);
6547
+ int err = 0, err2 = 0, offset = off & (sb->s_blocksize - 1);
61606548 int retries = 0;
61616549 struct buffer_head *bh;
61626550 handle_t *handle = journal_current_handle();
....@@ -6182,7 +6570,7 @@
61826570 bh = ext4_bread(handle, inode, blk,
61836571 EXT4_GET_BLOCKS_CREATE |
61846572 EXT4_GET_BLOCKS_METADATA_NOFAIL);
6185
- } while (IS_ERR(bh) && (PTR_ERR(bh) == -ENOSPC) &&
6573
+ } while (PTR_ERR(bh) == -ENOSPC &&
61866574 ext4_should_retry_alloc(inode->i_sb, &retries));
61876575 if (IS_ERR(bh))
61886576 return PTR_ERR(bh);
....@@ -6204,21 +6592,11 @@
62046592 if (inode->i_size < off + len) {
62056593 i_size_write(inode, off + len);
62066594 EXT4_I(inode)->i_disksize = inode->i_size;
6207
- ext4_mark_inode_dirty(handle, inode);
6595
+ err2 = ext4_mark_inode_dirty(handle, inode);
6596
+ if (unlikely(err2 && !err))
6597
+ err = err2;
62086598 }
6209
- return len;
6210
-}
6211
-
6212
-static int ext4_get_next_id(struct super_block *sb, struct kqid *qid)
6213
-{
6214
- const struct quota_format_ops *ops;
6215
-
6216
- if (!sb_has_quota_loaded(sb, qid->type))
6217
- return -ESRCH;
6218
- ops = sb_dqopt(sb)->ops[qid->type];
6219
- if (!ops || !ops->get_next_id)
6220
- return -ENOSYS;
6221
- return dquot_get_next_id(sb, qid);
6599
+ return err ? err : len;
62226600 }
62236601 #endif
62246602
....@@ -6314,6 +6692,10 @@
63146692 if (err)
63156693 return err;
63166694
6695
+ err = ext4_init_pending();
6696
+ if (err)
6697
+ goto out7;
6698
+
63176699 err = ext4_init_post_read_processing();
63186700 if (err)
63196701 goto out6;
....@@ -6336,6 +6718,11 @@
63366718 err = init_inodecache();
63376719 if (err)
63386720 goto out1;
6721
+
6722
+ err = ext4_fc_init_dentry_cache();
6723
+ if (err)
6724
+ goto out05;
6725
+
63396726 register_as_ext3();
63406727 register_as_ext2();
63416728 err = register_filesystem(&ext4_fs_type);
....@@ -6346,6 +6733,8 @@
63466733 out:
63476734 unregister_as_ext2();
63486735 unregister_as_ext3();
6736
+ ext4_fc_destroy_dentry_cache();
6737
+out05:
63496738 destroy_inodecache();
63506739 out1:
63516740 ext4_exit_mballoc();
....@@ -6358,6 +6747,8 @@
63586747 out5:
63596748 ext4_exit_post_read_processing();
63606749 out6:
6750
+ ext4_exit_pending();
6751
+out7:
63616752 ext4_exit_es();
63626753
63636754 return err;
....@@ -6369,6 +6760,7 @@
63696760 unregister_as_ext2();
63706761 unregister_as_ext3();
63716762 unregister_filesystem(&ext4_fs_type);
6763
+ ext4_fc_destroy_dentry_cache();
63726764 destroy_inodecache();
63736765 ext4_exit_mballoc();
63746766 ext4_exit_sysfs();
....@@ -6376,11 +6768,13 @@
63766768 ext4_exit_pageio();
63776769 ext4_exit_post_read_processing();
63786770 ext4_exit_es();
6771
+ ext4_exit_pending();
63796772 }
63806773
63816774 MODULE_AUTHOR("Remy Card, Stephen Tweedie, Andrew Morton, Andreas Dilger, Theodore Ts'o and others");
63826775 MODULE_DESCRIPTION("Fourth Extended Filesystem");
63836776 MODULE_LICENSE("GPL");
6777
+MODULE_IMPORT_NS(ANDROID_GKI_VFS_EXPORT_ONLY);
63846778 MODULE_SOFTDEP("pre: crc32c");
63856779 module_init(ext4_init_fs)
63866780 module_exit(ext4_exit_fs)