forked from ~ljy/RK356X_SDK_RELEASE

hc
2023-12-09 958e46acc8e900e8569dd467c1af9b8d2d019394
kernel/fs/ext4/ext4.h
....@@ -27,7 +27,6 @@
2727 #include <linux/seqlock.h>
2828 #include <linux/mutex.h>
2929 #include <linux/timer.h>
30
-#include <linux/version.h>
3130 #include <linux/wait.h>
3231 #include <linux/sched/signal.h>
3332 #include <linux/blockgroup_lock.h>
....@@ -36,6 +35,7 @@
3635 #include <crypto/hash.h>
3736 #include <linux/falloc.h>
3837 #include <linux/percpu-rwsem.h>
38
+#include <linux/fiemap.h>
3939 #ifdef __KERNEL__
4040 #include <linux/compat.h>
4141 #endif
....@@ -44,15 +44,6 @@
4444 #include <linux/fsverity.h>
4545
4646 #include <linux/compiler.h>
47
-
48
-/* Until this gets included into linux/compiler-gcc.h */
49
-#ifndef __nonstring
50
-#if defined(GCC_VERSION) && (GCC_VERSION >= 80000)
51
-#define __nonstring __attribute__((nonstring))
52
-#else
53
-#define __nonstring
54
-#endif
55
-#endif
5647
5748 /*
5849 * The fourth extended filesystem constants/structures
....@@ -89,14 +80,22 @@
8980 #define ext4_debug(fmt, ...) no_printk(fmt, ##__VA_ARGS__)
9081 #endif
9182
92
-/*
93
- * Turn on EXT_DEBUG to get lots of info about extents operations.
94
- */
83
+ /*
84
+ * Turn on EXT_DEBUG to enable ext4_ext_show_path/leaf/move in extents.c
85
+ */
9586 #define EXT_DEBUG__
96
-#ifdef EXT_DEBUG
97
-#define ext_debug(fmt, ...) printk(fmt, ##__VA_ARGS__)
87
+
88
+/*
89
+ * Dynamic printk for controlled extents debugging.
90
+ */
91
+#ifdef CONFIG_EXT4_DEBUG
92
+#define ext_debug(ino, fmt, ...) \
93
+ pr_debug("[%s/%d] EXT4-fs (%s): ino %lu: (%s, %d): %s:" fmt, \
94
+ current->comm, task_pid_nr(current), \
95
+ ino->i_sb->s_id, ino->i_ino, __FILE__, __LINE__, \
96
+ __func__, ##__VA_ARGS__)
9897 #else
99
-#define ext_debug(fmt, ...) no_printk(fmt, ##__VA_ARGS__)
98
+#define ext_debug(ino, fmt, ...) no_printk(fmt, ##__VA_ARGS__)
10099 #endif
101100
102101 /* data type for block offset of block group */
....@@ -151,6 +150,8 @@
151150 #define EXT4_MB_USE_ROOT_BLOCKS 0x1000
152151 /* Use blocks from reserved pool */
153152 #define EXT4_MB_USE_RESERVED 0x2000
153
+/* Do strict check for free blocks while retrying block allocation */
154
+#define EXT4_MB_STRICT_CHECK 0x4000
154155
155156 struct ext4_allocation_request {
156157 /* target inode for block we're allocating */
....@@ -180,10 +181,10 @@
180181 * well as to store the information returned by ext4_map_blocks(). It
181182 * takes less room on the stack than a struct buffer_head.
182183 */
183
-#define EXT4_MAP_NEW (1 << BH_New)
184
-#define EXT4_MAP_MAPPED (1 << BH_Mapped)
185
-#define EXT4_MAP_UNWRITTEN (1 << BH_Unwritten)
186
-#define EXT4_MAP_BOUNDARY (1 << BH_Boundary)
184
+#define EXT4_MAP_NEW BIT(BH_New)
185
+#define EXT4_MAP_MAPPED BIT(BH_Mapped)
186
+#define EXT4_MAP_UNWRITTEN BIT(BH_Unwritten)
187
+#define EXT4_MAP_BOUNDARY BIT(BH_Boundary)
187188 #define EXT4_MAP_FLAGS (EXT4_MAP_NEW | EXT4_MAP_MAPPED |\
188189 EXT4_MAP_UNWRITTEN | EXT4_MAP_BOUNDARY)
189190
....@@ -207,6 +208,12 @@
207208 */
208209 #define EXT4_IO_END_UNWRITTEN 0x0001
209210
211
+struct ext4_io_end_vec {
212
+ struct list_head list; /* list of io_end_vec */
213
+ loff_t offset; /* offset in the file */
214
+ ssize_t size; /* size of the extent */
215
+};
216
+
210217 /*
211218 * For converting unwritten extents on a work queue. 'handle' is used for
212219 * buffered writeback.
....@@ -220,8 +227,7 @@
220227 * bios covering the extent */
221228 unsigned int flag; /* unwritten or not */
222229 atomic_t count; /* reference counter */
223
- loff_t offset; /* offset in the file */
224
- ssize_t size; /* size of the extent */
230
+ struct list_head list_vec; /* list of ext4_io_end_vec */
225231 } ext4_io_end_t;
226232
227233 struct ext4_io_submit {
....@@ -302,6 +308,9 @@
302308 ~((ext4_fsblk_t) (s)->s_cluster_ratio - 1))
303309 #define EXT4_LBLK_CMASK(s, lblk) ((lblk) & \
304310 ~((ext4_lblk_t) (s)->s_cluster_ratio - 1))
311
+/* Fill in the low bits to get the last block of the cluster */
312
+#define EXT4_LBLK_CFILL(sbi, lblk) ((lblk) | \
313
+ ((ext4_lblk_t) (sbi)->s_cluster_ratio - 1))
305314 /* Get the cluster offset */
306315 #define EXT4_PBLK_COFF(s, pblk) ((pblk) & \
307316 ((ext4_fsblk_t) (s)->s_cluster_ratio - 1))
....@@ -415,38 +424,74 @@
415424 #define EXT4_EXTENTS_FL 0x00080000 /* Inode uses extents */
416425 #define EXT4_VERITY_FL 0x00100000 /* Verity protected inode */
417426 #define EXT4_EA_INODE_FL 0x00200000 /* Inode used for large EA */
418
-#define EXT4_EOFBLOCKS_FL 0x00400000 /* Blocks allocated beyond EOF */
427
+/* 0x00400000 was formerly EXT4_EOFBLOCKS_FL */
428
+
429
+#define EXT4_DAX_FL 0x02000000 /* Inode is DAX */
430
+
419431 #define EXT4_INLINE_DATA_FL 0x10000000 /* Inode has inline data. */
420432 #define EXT4_PROJINHERIT_FL 0x20000000 /* Create with parents projid */
421
-#define EXT4_CASEFOLD_FL 0x40000000 /* Casefolded file */
433
+#define EXT4_CASEFOLD_FL 0x40000000 /* Casefolded directory */
422434 #define EXT4_RESERVED_FL 0x80000000 /* reserved for ext4 lib */
423435
424
-#define EXT4_FL_USER_VISIBLE 0x705BDFFF /* User visible flags */
425
-#define EXT4_FL_USER_MODIFIABLE 0x604BC0FF /* User modifiable flags */
436
+/* User modifiable flags */
437
+#define EXT4_FL_USER_MODIFIABLE (EXT4_SECRM_FL | \
438
+ EXT4_UNRM_FL | \
439
+ EXT4_COMPR_FL | \
440
+ EXT4_SYNC_FL | \
441
+ EXT4_IMMUTABLE_FL | \
442
+ EXT4_APPEND_FL | \
443
+ EXT4_NODUMP_FL | \
444
+ EXT4_NOATIME_FL | \
445
+ EXT4_JOURNAL_DATA_FL | \
446
+ EXT4_NOTAIL_FL | \
447
+ EXT4_DIRSYNC_FL | \
448
+ EXT4_TOPDIR_FL | \
449
+ EXT4_EXTENTS_FL | \
450
+ 0x00400000 /* EXT4_EOFBLOCKS_FL */ | \
451
+ EXT4_DAX_FL | \
452
+ EXT4_PROJINHERIT_FL | \
453
+ EXT4_CASEFOLD_FL)
426454
427
-/* Flags we can manipulate with through EXT4_IOC_FSSETXATTR */
455
+/* User visible flags */
456
+#define EXT4_FL_USER_VISIBLE (EXT4_FL_USER_MODIFIABLE | \
457
+ EXT4_DIRTY_FL | \
458
+ EXT4_COMPRBLK_FL | \
459
+ EXT4_NOCOMPR_FL | \
460
+ EXT4_ENCRYPT_FL | \
461
+ EXT4_INDEX_FL | \
462
+ EXT4_VERITY_FL | \
463
+ EXT4_INLINE_DATA_FL)
464
+
465
+/* Flags we can manipulate with through FS_IOC_FSSETXATTR */
428466 #define EXT4_FL_XFLAG_VISIBLE (EXT4_SYNC_FL | \
429467 EXT4_IMMUTABLE_FL | \
430468 EXT4_APPEND_FL | \
431469 EXT4_NODUMP_FL | \
432470 EXT4_NOATIME_FL | \
433
- EXT4_PROJINHERIT_FL)
471
+ EXT4_PROJINHERIT_FL | \
472
+ EXT4_DAX_FL)
434473
435474 /* Flags that should be inherited by new inodes from their parent. */
436475 #define EXT4_FL_INHERITED (EXT4_SECRM_FL | EXT4_UNRM_FL | EXT4_COMPR_FL |\
437476 EXT4_SYNC_FL | EXT4_NODUMP_FL | EXT4_NOATIME_FL |\
438477 EXT4_NOCOMPR_FL | EXT4_JOURNAL_DATA_FL |\
439478 EXT4_NOTAIL_FL | EXT4_DIRSYNC_FL |\
440
- EXT4_PROJINHERIT_FL | EXT4_CASEFOLD_FL)
479
+ EXT4_PROJINHERIT_FL | EXT4_CASEFOLD_FL |\
480
+ EXT4_DAX_FL)
441481
442482 /* Flags that are appropriate for regular files (all but dir-specific ones). */
443
-#define EXT4_REG_FLMASK (~(EXT4_DIRSYNC_FL | EXT4_TOPDIR_FL | EXT4_CASEFOLD_FL))
483
+#define EXT4_REG_FLMASK (~(EXT4_DIRSYNC_FL | EXT4_TOPDIR_FL | EXT4_CASEFOLD_FL |\
484
+ EXT4_PROJINHERIT_FL))
444485
445486 /* Flags that are appropriate for non-directories/regular files. */
446487 #define EXT4_OTHER_FLMASK (EXT4_NODUMP_FL | EXT4_NOATIME_FL)
447488
448489 /* The only flags that should be swapped */
449490 #define EXT4_FL_SHOULD_SWAP (EXT4_HUGE_FILE_FL | EXT4_EXTENTS_FL)
491
+
492
+/* Flags which are mutually exclusive to DAX */
493
+#define EXT4_DAX_MUT_EXCL (EXT4_VERITY_FL | EXT4_ENCRYPT_FL |\
494
+ EXT4_JOURNAL_DATA_FL | EXT4_INLINE_DATA_FL)
450495
451496 /* Mask out flags that are inappropriate for the given type of inode. */
452497 static inline __u32 ext4_mask_flags(umode_t mode, __u32 flags)
....@@ -487,9 +532,11 @@
487532 EXT4_INODE_EXTENTS = 19, /* Inode uses extents */
488533 EXT4_INODE_VERITY = 20, /* Verity protected inode */
489534 EXT4_INODE_EA_INODE = 21, /* Inode used for large EA */
490
- EXT4_INODE_EOFBLOCKS = 22, /* Blocks allocated beyond EOF */
535
+/* 22 was formerly EXT4_INODE_EOFBLOCKS */
536
+ EXT4_INODE_DAX = 25, /* Inode is DAX */
491537 EXT4_INODE_INLINE_DATA = 28, /* Data in inode. */
492538 EXT4_INODE_PROJINHERIT = 29, /* Create with parents projid */
539
+ EXT4_INODE_CASEFOLD = 30, /* Casefolded directory */
493540 EXT4_INODE_RESERVED = 31, /* reserved for ext4 lib */
494541 };
495542
....@@ -533,9 +580,9 @@
533580 CHECK_FLAG_VALUE(EXTENTS);
534581 CHECK_FLAG_VALUE(VERITY);
535582 CHECK_FLAG_VALUE(EA_INODE);
536
- CHECK_FLAG_VALUE(EOFBLOCKS);
537583 CHECK_FLAG_VALUE(INLINE_DATA);
538584 CHECK_FLAG_VALUE(PROJINHERIT);
585
+ CHECK_FLAG_VALUE(CASEFOLD);
539586 CHECK_FLAG_VALUE(RESERVED);
540587 }
541588
....@@ -610,8 +657,6 @@
610657 #define EXT4_GET_BLOCKS_METADATA_NOFAIL 0x0020
611658 /* Don't normalize allocation size (used for fallocate) */
612659 #define EXT4_GET_BLOCKS_NO_NORMALIZE 0x0040
613
- /* Request will not result in inode size update (user for fallocate) */
614
-#define EXT4_GET_BLOCKS_KEEP_SIZE 0x0080
615660 /* Convert written extents to unwritten */
616661 #define EXT4_GET_BLOCKS_CONVERT_UNWRITTEN 0x0100
617662 /* Write zeros to newly created written extents */
....@@ -633,6 +678,7 @@
633678 */
634679 #define EXT4_EX_NOCACHE 0x40000000
635680 #define EXT4_EX_FORCE_CACHE 0x20000000
681
+#define EXT4_EX_NOFAIL 0x10000000
636682
637683 /*
638684 * Flags used by ext4_free_blocks
....@@ -643,12 +689,11 @@
643689 #define EXT4_FREE_BLOCKS_NO_QUOT_UPDATE 0x0008
644690 #define EXT4_FREE_BLOCKS_NOFREE_FIRST_CLUSTER 0x0010
645691 #define EXT4_FREE_BLOCKS_NOFREE_LAST_CLUSTER 0x0020
692
+#define EXT4_FREE_BLOCKS_RERESERVE_CLUSTER 0x0040
646693
647694 /*
648695 * ioctl commands
649696 */
650
-#define EXT4_IOC_GETFLAGS FS_IOC_GETFLAGS
651
-#define EXT4_IOC_SETFLAGS FS_IOC_SETFLAGS
652697 #define EXT4_IOC_GETVERSION _IOR('f', 3, long)
653698 #define EXT4_IOC_SETVERSION _IOW('f', 4, long)
654699 #define EXT4_IOC_GETVERSION_OLD FS_IOC_GETVERSION
....@@ -665,12 +710,10 @@
665710 #define EXT4_IOC_RESIZE_FS _IOW('f', 16, __u64)
666711 #define EXT4_IOC_SWAP_BOOT _IO('f', 17)
667712 #define EXT4_IOC_PRECACHE_EXTENTS _IO('f', 18)
668
-#define EXT4_IOC_SET_ENCRYPTION_POLICY FS_IOC_SET_ENCRYPTION_POLICY
669
-#define EXT4_IOC_GET_ENCRYPTION_PWSALT FS_IOC_GET_ENCRYPTION_PWSALT
670
-#define EXT4_IOC_GET_ENCRYPTION_POLICY FS_IOC_GET_ENCRYPTION_POLICY
671
-
672
-#define EXT4_IOC_FSGETXATTR FS_IOC_FSGETXATTR
673
-#define EXT4_IOC_FSSETXATTR FS_IOC_FSSETXATTR
713
+/* ioctl codes 19--39 are reserved for fscrypt */
714
+#define EXT4_IOC_CLEAR_ES_CACHE _IO('f', 40)
715
+#define EXT4_IOC_GETSTATE _IOW('f', 41, __u32)
716
+#define EXT4_IOC_GET_ES_CACHE _IOWR('f', 42, struct fiemap)
674717
675718 #define EXT4_IOC_SHUTDOWN _IOR ('X', 125, __u32)
676719
....@@ -681,13 +724,21 @@
681724 #define EXT4_GOING_FLAGS_LOGFLUSH 0x1 /* flush log but not data */
682725 #define EXT4_GOING_FLAGS_NOLOGFLUSH 0x2 /* don't flush log nor data */
683726
727
+/*
728
+ * Flags returned by EXT4_IOC_GETSTATE
729
+ *
730
+ * We only expose to userspace a subset of the state flags in
731
+ * i_state_flags
732
+ */
733
+#define EXT4_STATE_FLAG_EXT_PRECACHED 0x00000001
734
+#define EXT4_STATE_FLAG_NEW 0x00000002
735
+#define EXT4_STATE_FLAG_NEWENTRY 0x00000004
736
+#define EXT4_STATE_FLAG_DA_ALLOC_CLOSE 0x00000008
684737
685738 #if defined(__KERNEL__) && defined(CONFIG_COMPAT)
686739 /*
687740 * ioctl commands in 32 bit emulation
688741 */
689
-#define EXT4_IOC32_GETFLAGS FS_IOC32_GETFLAGS
690
-#define EXT4_IOC32_SETFLAGS FS_IOC32_SETFLAGS
691742 #define EXT4_IOC32_GETVERSION _IOR('f', 3, int)
692743 #define EXT4_IOC32_SETVERSION _IOW('f', 4, int)
693744 #define EXT4_IOC32_GETRSVSZ _IOR('f', 5, int)
....@@ -698,11 +749,17 @@
698749 #define EXT4_IOC32_SETVERSION_OLD FS_IOC32_SETVERSION
699750 #endif
700751
752
+/*
753
+ * Returned by EXT4_IOC_GET_ES_CACHE as an additional possible flag.
754
+ * It indicates that the entry in extent status cache is for a hole.
755
+ */
756
+#define EXT4_FIEMAP_EXTENT_HOLE 0x08000000
757
+
701758 /* Max physical block we can address w/o extents */
702759 #define EXT4_MAX_BLOCK_FILE_PHYS 0xFFFFFFFF
703760
704761 /* Max logical block we can support */
705
-#define EXT4_MAX_LOGICAL_BLOCK 0xFFFFFFFF
762
+#define EXT4_MAX_LOGICAL_BLOCK 0xFFFFFFFE
706763
707764 /*
708765 * Structure of an inode on the disk
....@@ -827,31 +884,20 @@
827884 static inline void ext4_decode_extra_time(struct timespec64 *time,
828885 __le32 extra)
829886 {
830
- if (unlikely(extra & cpu_to_le32(EXT4_EPOCH_MASK))) {
831
-
832
-#if 1
833
- /* Handle legacy encoding of pre-1970 dates with epoch
834
- * bits 1,1. (This backwards compatibility may be removed
835
- * at the discretion of the ext4 developers.)
836
- */
837
- u64 extra_bits = le32_to_cpu(extra) & EXT4_EPOCH_MASK;
838
- if (extra_bits == 3 && ((time->tv_sec) & 0x80000000) != 0)
839
- extra_bits = 0;
840
- time->tv_sec += extra_bits << 32;
841
-#else
887
+ if (unlikely(extra & cpu_to_le32(EXT4_EPOCH_MASK)))
842888 time->tv_sec += (u64)(le32_to_cpu(extra) & EXT4_EPOCH_MASK) << 32;
843
-#endif
844
- }
845889 time->tv_nsec = (le32_to_cpu(extra) & EXT4_NSEC_MASK) >> EXT4_EPOCH_BITS;
846890 }
847891
848892 #define EXT4_INODE_SET_XTIME(xtime, inode, raw_inode) \
849893 do { \
850
- (raw_inode)->xtime = cpu_to_le32((inode)->xtime.tv_sec); \
851894 if (EXT4_FITS_IN_INODE(raw_inode, EXT4_I(inode), xtime ## _extra)) {\
895
+ (raw_inode)->xtime = cpu_to_le32((inode)->xtime.tv_sec); \
852896 (raw_inode)->xtime ## _extra = \
853897 ext4_encode_extra_time(&(inode)->xtime); \
854898 } \
899
+ else \
900
+ (raw_inode)->xtime = cpu_to_le32(clamp_t(int32_t, (inode)->xtime.tv_sec, S32_MIN, S32_MAX)); \
855901 } while (0)
856902
857903 #define EXT4_EINODE_SET_XTIME(xtime, einode, raw_inode) \
....@@ -917,6 +963,7 @@
917963 #endif /* defined(__KERNEL__) || defined(__linux__) */
918964
919965 #include "extents_status.h"
966
+#include "fast_commit.h"
920967
921968 /*
922969 * Lock subclasses for i_data_sem in the ext4_inode_info structure.
....@@ -974,6 +1021,28 @@
9741021
9751022 struct list_head i_orphan; /* unlinked but open inodes */
9761023
1024
+ /* Fast commit related info */
1025
+
1026
+ struct list_head i_fc_list; /*
1027
+ * inodes that need fast commit
1028
+ * protected by sbi->s_fc_lock.
1029
+ */
1030
+
1031
+ /* Start of lblk range that needs to be committed in this fast commit */
1032
+ ext4_lblk_t i_fc_lblk_start;
1033
+
1034
+ /* End of lblk range that needs to be committed in this fast commit */
1035
+ ext4_lblk_t i_fc_lblk_len;
1036
+
1037
+ /* Number of ongoing updates on this inode */
1038
+ atomic_t i_fc_updates;
1039
+
1040
+ /* Fast commit wait queue for this inode */
1041
+ wait_queue_head_t i_fc_wait;
1042
+
1043
+ /* Protect concurrent accesses on i_fc_lblk_start, i_fc_lblk_len */
1044
+ struct mutex i_fc_lock;
1045
+
9771046 /*
9781047 * i_disksize keeps track of what the inode size is ON DISK, not
9791048 * in memory. During truncate, i_size is set to the new size by
....@@ -1023,6 +1092,7 @@
10231092 struct timespec64 i_crtime;
10241093
10251094 /* mballoc */
1095
+ atomic_t i_prealloc_active;
10261096 struct list_head i_prealloc_list;
10271097 spinlock_t i_prealloc_lock;
10281098
....@@ -1042,8 +1112,9 @@
10421112 /* allocation reservation info for delalloc */
10431113 /* In case of bigalloc, this refer to clusters rather than blocks */
10441114 unsigned int i_reserved_data_blocks;
1045
- ext4_lblk_t i_da_metadata_calc_last_lblock;
1046
- int i_da_metadata_calc_len;
1115
+
1116
+ /* pending cluster reservations for bigalloc file systems */
1117
+ struct ext4_pending_tree i_pending_tree;
10471118
10481119 /* on-disk additional length */
10491120 __u16 i_extra_isize;
....@@ -1092,6 +1163,7 @@
10921163 #define EXT4_VALID_FS 0x0001 /* Unmounted cleanly */
10931164 #define EXT4_ERROR_FS 0x0002 /* Errors detected */
10941165 #define EXT4_ORPHAN_FS 0x0004 /* Orphans being recovered */
1166
+#define EXT4_FC_REPLAY 0x0020 /* Fast commit replay ongoing */
10951167
10961168 /*
10971169 * Misc. filesystem flags
....@@ -1113,9 +1185,9 @@
11131185 #define EXT4_MOUNT_MINIX_DF 0x00080 /* Mimics the Minix statfs */
11141186 #define EXT4_MOUNT_NOLOAD 0x00100 /* Don't use existing journal*/
11151187 #ifdef CONFIG_FS_DAX
1116
-#define EXT4_MOUNT_DAX 0x00200 /* Direct Access */
1188
+#define EXT4_MOUNT_DAX_ALWAYS 0x00200 /* Direct Access */
11171189 #else
1118
-#define EXT4_MOUNT_DAX 0
1190
+#define EXT4_MOUNT_DAX_ALWAYS 0
11191191 #endif
11201192 #define EXT4_MOUNT_DATA_FLAGS 0x00C00 /* Mode for data writes: */
11211193 #define EXT4_MOUNT_JOURNAL_DATA 0x00400 /* Write data to journal */
....@@ -1140,7 +1212,7 @@
11401212 #define EXT4_MOUNT_JOURNAL_CHECKSUM 0x800000 /* Journal checksums */
11411213 #define EXT4_MOUNT_JOURNAL_ASYNC_COMMIT 0x1000000 /* Journal Async Commit */
11421214 #define EXT4_MOUNT_WARN_ON_ERROR 0x2000000 /* Trigger WARN_ON on error */
1143
-#define EXT4_MOUNT_INLINECRYPT 0x4000000 /* Inline encryption support */
1215
+#define EXT4_MOUNT_PREFETCH_BLOCK_BITMAPS 0x4000000
11441216 #define EXT4_MOUNT_DELALLOC 0x8000000 /* Delalloc support */
11451217 #define EXT4_MOUNT_DATA_ERR_ABORT 0x10000000 /* Abort on file data write */
11461218 #define EXT4_MOUNT_BLOCK_VALIDITY 0x20000000 /* Block validity checking */
....@@ -1159,9 +1231,13 @@
11591231 blocks */
11601232 #define EXT4_MOUNT2_HURD_COMPAT 0x00000004 /* Support HURD-castrated
11611233 file systems */
1162
-
11631234 #define EXT4_MOUNT2_EXPLICIT_JOURNAL_CHECKSUM 0x00000008 /* User explicitly
11641235 specified journal checksum */
1236
+
1237
+#define EXT4_MOUNT2_JOURNAL_FAST_COMMIT 0x00000010 /* Journal fast commit */
1238
+#define EXT4_MOUNT2_DAX_NEVER 0x00000020 /* Do not allow Direct Access */
1239
+#define EXT4_MOUNT2_DAX_INODE 0x00000040 /* For printing options only */
1240
+
11651241
11661242 #define clear_opt(sb, opt) EXT4_SB(sb)->s_mount_opt &= \
11671243 ~EXT4_MOUNT_##opt
....@@ -1331,7 +1407,8 @@
13311407 __u8 s_lastcheck_hi;
13321408 __u8 s_first_error_time_hi;
13331409 __u8 s_last_error_time_hi;
1334
- __u8 s_pad[2];
1410
+ __u8 s_first_error_errcode;
1411
+ __u8 s_last_error_errcode;
13351412 __le16 s_encoding; /* Filename charset encoding */
13361413 __le16 s_encoding_flags; /* Filename charset encoding flags */
13371414 __le32 s_reserved[95]; /* Padding to the end of the block */
....@@ -1341,18 +1418,6 @@
13411418 #define EXT4_S_ERR_LEN (EXT4_S_ERR_END - EXT4_S_ERR_START)
13421419
13431420 #ifdef __KERNEL__
1344
-
1345
-/*
1346
- * run-time mount flags
1347
- */
1348
-#define EXT4_MF_MNTDIR_SAMPLED 0x0001
1349
-#define EXT4_MF_FS_ABORTED 0x0002 /* Fatal error detected */
1350
-
1351
-#ifdef CONFIG_FS_ENCRYPTION
1352
-#define DUMMY_ENCRYPTION_ENABLED(sbi) ((sbi)->s_dummy_enc_ctx.ctx != NULL)
1353
-#else
1354
-#define DUMMY_ENCRYPTION_ENABLED(sbi) (0)
1355
-#endif
13561421
13571422 /* Number of quota types we support */
13581423 #define EXT4_MAXQUOTAS 3
....@@ -1382,7 +1447,7 @@
13821447 struct buffer_head * __rcu *s_group_desc;
13831448 unsigned int s_mount_opt;
13841449 unsigned int s_mount_opt2;
1385
- unsigned int s_mount_flags;
1450
+ unsigned long s_mount_flags;
13861451 unsigned int s_def_mount_opt;
13871452 ext4_fsblk_t s_sb_block;
13881453 atomic64_t s_resv_clusters;
....@@ -1403,11 +1468,13 @@
14031468 struct percpu_counter s_freeinodes_counter;
14041469 struct percpu_counter s_dirs_counter;
14051470 struct percpu_counter s_dirtyclusters_counter;
1471
+ struct percpu_counter s_sra_exceeded_retry_limit;
14061472 struct blockgroup_lock *s_blockgroup_lock;
14071473 struct proc_dir_entry *s_proc;
14081474 struct kobject s_kobj;
14091475 struct completion s_kobj_unregister;
14101476 struct super_block *s_sb;
1477
+ struct buffer_head *s_mmp_bh;
14111478
14121479 /* Journaling */
14131480 struct journal_s *s_journal;
....@@ -1417,14 +1484,14 @@
14171484 unsigned long s_commit_interval;
14181485 u32 s_max_batch_time;
14191486 u32 s_min_batch_time;
1420
- struct block_device *journal_bdev;
1487
+ struct block_device *s_journal_bdev;
14211488 #ifdef CONFIG_QUOTA
14221489 /* Names of quota files with journalled quota */
14231490 char __rcu *s_qf_names[EXT4_MAXQUOTAS];
14241491 int s_jquota_fmt; /* Format of quota to use */
14251492 #endif
14261493 unsigned int s_want_extra_isize; /* New inodes should reserve # bytes */
1427
- struct ext4_system_blocks __rcu *system_blks;
1494
+ struct ext4_system_blocks __rcu *s_system_blks;
14281495
14291496 #ifdef EXTENTS_STATS
14301497 /* ext4 extents stats */
....@@ -1455,10 +1522,13 @@
14551522 unsigned int s_mb_stats;
14561523 unsigned int s_mb_order2_reqs;
14571524 unsigned int s_mb_group_prealloc;
1525
+ unsigned int s_mb_max_inode_prealloc;
14581526 unsigned int s_max_dir_size_kb;
14591527 /* where last allocation was done - for stream allocation */
14601528 unsigned long s_mb_last_group;
14611529 unsigned long s_mb_last_start;
1530
+ unsigned int s_mb_prefetch;
1531
+ unsigned int s_mb_prefetch_limit;
14621532
14631533 /* stats for buddy allocator */
14641534 atomic_t s_bal_reqs; /* number of reqs with len > 1 */
....@@ -1526,9 +1596,11 @@
15261596 struct ratelimit_state s_err_ratelimit_state;
15271597 struct ratelimit_state s_warning_ratelimit_state;
15281598 struct ratelimit_state s_msg_ratelimit_state;
1599
+ atomic_t s_warning_count;
1600
+ atomic_t s_msg_count;
15291601
1530
- /* Encryption context for '-o test_dummy_encryption' */
1531
- struct fscrypt_dummy_context s_dummy_enc_ctx;
1602
+ /* Encryption policy for '-o test_dummy_encryption' */
1603
+ struct fscrypt_dummy_policy s_dummy_enc_policy;
15321604
15331605 /*
15341606 * Barrier between writepages ops and changing any inode's JOURNAL_DATA
....@@ -1536,6 +1608,40 @@
15361608 */
15371609 struct percpu_rw_semaphore s_writepages_rwsem;
15381610 struct dax_device *s_daxdev;
1611
+#ifdef CONFIG_EXT4_DEBUG
1612
+ unsigned long s_simulate_fail;
1613
+#endif
1614
+ /* Record the errseq of the backing block device */
1615
+ errseq_t s_bdev_wb_err;
1616
+ spinlock_t s_bdev_wb_lock;
1617
+
1618
+ /* Ext4 fast commit stuff */
1619
+ atomic_t s_fc_subtid;
1620
+ atomic_t s_fc_ineligible_updates;
1621
+ /*
1622
+ * After commit starts, the main queue gets locked, and the further
1623
+ * updates get added in the staging queue.
1624
+ */
1625
+#define FC_Q_MAIN 0
1626
+#define FC_Q_STAGING 1
1627
+ struct list_head s_fc_q[2]; /* Inodes staged for fast commit
1628
+ * that have data changes in them.
1629
+ */
1630
+ struct list_head s_fc_dentry_q[2]; /* directory entry updates */
1631
+ unsigned int s_fc_bytes;
1632
+ /*
1633
+ * Main fast commit lock. This lock protects accesses to the
1634
+ * following fields:
1635
+ * ei->i_fc_list, s_fc_dentry_q, s_fc_q, s_fc_bytes, s_fc_bh.
1636
+ */
1637
+ spinlock_t s_fc_lock;
1638
+ struct buffer_head *s_fc_bh;
1639
+ struct ext4_fc_stats s_fc_stats;
1640
+ u64 s_fc_avg_commit_time;
1641
+#ifdef CONFIG_EXT4_DEBUG
1642
+ int s_fc_debug_max_replay;
1643
+#endif
1644
+ struct ext4_fc_replay_state s_fc_replay_state;
15391645 };
15401646
15411647 static inline struct ext4_sb_info *EXT4_SB(struct super_block *sb)
....@@ -1572,6 +1678,94 @@
15721678 })
15731679
15741680 /*
1681
+ * run-time mount flags
1682
+ */
1683
+enum {
1684
+ EXT4_MF_MNTDIR_SAMPLED,
1685
+ EXT4_MF_FS_ABORTED, /* Fatal error detected */
1686
+ EXT4_MF_FC_INELIGIBLE, /* Fast commit ineligible */
1687
+ EXT4_MF_FC_COMMITTING /* File system underoing a fast
1688
+ * commit.
1689
+ */
1690
+};
1691
+
1692
+static inline void ext4_set_mount_flag(struct super_block *sb, int bit)
1693
+{
1694
+ set_bit(bit, &EXT4_SB(sb)->s_mount_flags);
1695
+}
1696
+
1697
+static inline void ext4_clear_mount_flag(struct super_block *sb, int bit)
1698
+{
1699
+ clear_bit(bit, &EXT4_SB(sb)->s_mount_flags);
1700
+}
1701
+
1702
+static inline int ext4_test_mount_flag(struct super_block *sb, int bit)
1703
+{
1704
+ return test_bit(bit, &EXT4_SB(sb)->s_mount_flags);
1705
+}
1706
+
1707
+
1708
+/*
1709
+ * Simulate_fail codes
1710
+ */
1711
+#define EXT4_SIM_BBITMAP_EIO 1
1712
+#define EXT4_SIM_BBITMAP_CRC 2
1713
+#define EXT4_SIM_IBITMAP_EIO 3
1714
+#define EXT4_SIM_IBITMAP_CRC 4
1715
+#define EXT4_SIM_INODE_EIO 5
1716
+#define EXT4_SIM_INODE_CRC 6
1717
+#define EXT4_SIM_DIRBLOCK_EIO 7
1718
+#define EXT4_SIM_DIRBLOCK_CRC 8
1719
+
1720
+static inline bool ext4_simulate_fail(struct super_block *sb,
1721
+ unsigned long code)
1722
+{
1723
+#ifdef CONFIG_EXT4_DEBUG
1724
+ struct ext4_sb_info *sbi = EXT4_SB(sb);
1725
+
1726
+ if (unlikely(sbi->s_simulate_fail == code)) {
1727
+ sbi->s_simulate_fail = 0;
1728
+ return true;
1729
+ }
1730
+#endif
1731
+ return false;
1732
+}
1733
+
1734
+static inline void ext4_simulate_fail_bh(struct super_block *sb,
1735
+ struct buffer_head *bh,
1736
+ unsigned long code)
1737
+{
1738
+ if (!IS_ERR(bh) && ext4_simulate_fail(sb, code))
1739
+ clear_buffer_uptodate(bh);
1740
+}
1741
+
1742
+/*
1743
+ * Error number codes for s_{first,last}_error_errno
1744
+ *
1745
+ * Linux errno numbers are architecture specific, so we need to translate
1746
+ * them into something which is architecture independent. We don't define
1747
+ * codes for all errno's; just the ones which are most likely to be the cause
1748
+ * of an ext4_error() call.
1749
+ */
1750
+#define EXT4_ERR_UNKNOWN 1
1751
+#define EXT4_ERR_EIO 2
1752
+#define EXT4_ERR_ENOMEM 3
1753
+#define EXT4_ERR_EFSBADCRC 4
1754
+#define EXT4_ERR_EFSCORRUPTED 5
1755
+#define EXT4_ERR_ENOSPC 6
1756
+#define EXT4_ERR_ENOKEY 7
1757
+#define EXT4_ERR_EROFS 8
1758
+#define EXT4_ERR_EFBIG 9
1759
+#define EXT4_ERR_EEXIST 10
1760
+#define EXT4_ERR_ERANGE 11
1761
+#define EXT4_ERR_EOVERFLOW 12
1762
+#define EXT4_ERR_EBUSY 13
1763
+#define EXT4_ERR_ENOTDIR 14
1764
+#define EXT4_ERR_ENOTEMPTY 15
1765
+#define EXT4_ERR_ESHUTDOWN 16
1766
+#define EXT4_ERR_EFAULT 17
1767
+
1768
+/*
15751769 * Inode dynamic state flags
15761770 */
15771771 enum {
....@@ -1581,12 +1775,12 @@
15811775 EXT4_STATE_NO_EXPAND, /* No space for expansion */
15821776 EXT4_STATE_DA_ALLOC_CLOSE, /* Alloc DA blks on close */
15831777 EXT4_STATE_EXT_MIGRATE, /* Inode is migrating */
1584
- EXT4_STATE_DIO_UNWRITTEN, /* need convert on dio done*/
15851778 EXT4_STATE_NEWENTRY, /* File just added to dir */
15861779 EXT4_STATE_MAY_INLINE_DATA, /* may have in-inode data */
15871780 EXT4_STATE_EXT_PRECACHED, /* extents have been precached */
15881781 EXT4_STATE_LUSTRE_EA_INODE, /* Lustre-style ea_inode */
15891782 EXT4_STATE_VERITY_IN_PROGRESS, /* building fs-verity Merkle tree */
1783
+ EXT4_STATE_FC_COMMITTING, /* Fast commit ongoing */
15901784 };
15911785
15921786 #define EXT4_INODE_BIT_FNS(name, field, offset) \
....@@ -1665,6 +1859,10 @@
16651859
16661860 #define EXT4_GOOD_OLD_INODE_SIZE 128
16671861
1862
+#define EXT4_EXTRA_TIMESTAMP_MAX (((s64)1 << 34) - 1 + S32_MIN)
1863
+#define EXT4_NON_EXTRA_TIMESTAMP_MAX S32_MAX
1864
+#define EXT4_TIMESTAMP_MIN S32_MIN
1865
+
16681866 /*
16691867 * Feature set definitions
16701868 */
....@@ -1676,6 +1874,14 @@
16761874 #define EXT4_FEATURE_COMPAT_RESIZE_INODE 0x0010
16771875 #define EXT4_FEATURE_COMPAT_DIR_INDEX 0x0020
16781876 #define EXT4_FEATURE_COMPAT_SPARSE_SUPER2 0x0200
1877
+/*
1878
+ * The reason why "FAST_COMMIT" is a compat feature is that, FS becomes
1879
+ * incompatible only if fast commit blocks are present in the FS. Since we
1880
+ * clear the journal (and thus the fast commit blocks), we don't mark FS as
1881
+ * incompatible. We also have a JBD2 incompat feature, which gets set when
1882
+ * there are fast commit blocks present in the journal.
1883
+ */
1884
+#define EXT4_FEATURE_COMPAT_FAST_COMMIT 0x0400
16791885 #define EXT4_FEATURE_COMPAT_STABLE_INODES 0x0800
16801886
16811887 #define EXT4_FEATURE_RO_COMPAT_SPARSE_SUPER 0x0001
....@@ -1778,6 +1984,7 @@
17781984 EXT4_FEATURE_COMPAT_FUNCS(resize_inode, RESIZE_INODE)
17791985 EXT4_FEATURE_COMPAT_FUNCS(dir_index, DIR_INDEX)
17801986 EXT4_FEATURE_COMPAT_FUNCS(sparse_super2, SPARSE_SUPER2)
1987
+EXT4_FEATURE_COMPAT_FUNCS(fast_commit, FAST_COMMIT)
17811988 EXT4_FEATURE_COMPAT_FUNCS(stable_inodes, STABLE_INODES)
17821989
17831990 EXT4_FEATURE_RO_COMPAT_FUNCS(sparse_super, SPARSE_SUPER)
....@@ -1892,6 +2099,7 @@
18922099 */
18932100 #define EXT4_FLAGS_RESIZING 0
18942101 #define EXT4_FLAGS_SHUTDOWN 1
2102
+#define EXT4_FLAGS_BDEV_IS_DAX 2
18952103
18962104 static inline int ext4_forced_shutdown(struct ext4_sb_info *sbi)
18972105 {
....@@ -1945,6 +2153,10 @@
19452153 * Structure of a directory entry
19462154 */
19472155 #define EXT4_NAME_LEN 255
2156
+/*
2157
+ * Base length of the ext4 directory entry excluding the name length
2158
+ */
2159
+#define EXT4_BASE_DIR_LEN (sizeof(struct ext4_dir_entry_2) - EXT4_NAME_LEN)
19482160
19492161 struct ext4_dir_entry {
19502162 __le32 inode; /* Inode number */
....@@ -1974,7 +2186,7 @@
19742186 __le32 inode; /* Inode number */
19752187 __le16 rec_len; /* Directory entry length */
19762188 __u8 name_len; /* Name length */
1977
- __u8 file_type;
2189
+ __u8 file_type; /* See file type macros EXT4_FT_* below */
19782190 char name[EXT4_NAME_LEN]; /* File name */
19792191 };
19802192
....@@ -2122,7 +2334,6 @@
21222334 BUG_ON(crypto_shash_descsize(sbi->s_chksum_driver)!=sizeof(desc.ctx));
21232335
21242336 desc.shash.tfm = sbi->s_chksum_driver;
2125
- desc.shash.flags = 0;
21262337 *(u32 *)desc.ctx = crc;
21272338
21282339 BUG_ON(crypto_shash_update(&desc.shash, address, length));
....@@ -2244,9 +2455,15 @@
22442455 struct mutex li_list_mtx;
22452456 };
22462457
2458
+enum ext4_li_mode {
2459
+ EXT4_LI_MODE_PREFETCH_BBITMAP,
2460
+ EXT4_LI_MODE_ITABLE,
2461
+};
2462
+
22472463 struct ext4_li_request {
22482464 struct super_block *lr_super;
2249
- struct ext4_sb_info *lr_sbi;
2465
+ enum ext4_li_mode lr_mode;
2466
+ ext4_group_t lr_first_not_zeroed;
22502467 ext4_group_t lr_next_group;
22512468 struct list_head lr_request;
22522469 unsigned long lr_next_sched;
....@@ -2377,7 +2594,8 @@
23772594 extern int ext4_should_retry_alloc(struct super_block *sb, int *retries);
23782595
23792596 extern struct buffer_head *ext4_read_block_bitmap_nowait(struct super_block *sb,
2380
- ext4_group_t block_group);
2597
+ ext4_group_t block_group,
2598
+ bool ignore_locked);
23812599 extern int ext4_wait_block_bitmap(struct super_block *sb,
23822600 ext4_group_t block_group,
23832601 struct buffer_head *bh);
....@@ -2551,6 +2769,7 @@
25512769 struct dx_hash_info *hinfo);
25522770
25532771 /* ialloc.c */
2772
+extern int ext4_mark_inode_used(struct super_block *sb, int ino);
25542773 extern struct inode *__ext4_new_inode(handle_t *, struct inode *, umode_t,
25552774 const struct qstr *qstr, __u32 goal,
25562775 uid_t *owner, __u32 i_flags,
....@@ -2576,6 +2795,37 @@
25762795 ext4_group_t group, int barrier);
25772796 extern void ext4_end_bitmap_read(struct buffer_head *bh, int uptodate);
25782797
2798
+/* fast_commit.c */
2799
+int ext4_fc_info_show(struct seq_file *seq, void *v);
2800
+void ext4_fc_init(struct super_block *sb, journal_t *journal);
2801
+void ext4_fc_init_inode(struct inode *inode);
2802
+void ext4_fc_track_range(handle_t *handle, struct inode *inode, ext4_lblk_t start,
2803
+ ext4_lblk_t end);
2804
+void __ext4_fc_track_unlink(handle_t *handle, struct inode *inode,
2805
+ struct dentry *dentry);
2806
+void __ext4_fc_track_link(handle_t *handle, struct inode *inode,
2807
+ struct dentry *dentry);
2808
+void ext4_fc_track_unlink(handle_t *handle, struct dentry *dentry);
2809
+void ext4_fc_track_link(handle_t *handle, struct dentry *dentry);
2810
+void __ext4_fc_track_create(handle_t *handle, struct inode *inode,
2811
+ struct dentry *dentry);
2812
+void ext4_fc_track_create(handle_t *handle, struct dentry *dentry);
2813
+void ext4_fc_track_inode(handle_t *handle, struct inode *inode);
2814
+void ext4_fc_mark_ineligible(struct super_block *sb, int reason);
2815
+void ext4_fc_start_ineligible(struct super_block *sb, int reason);
2816
+void ext4_fc_stop_ineligible(struct super_block *sb);
2817
+void ext4_fc_start_update(struct inode *inode);
2818
+void ext4_fc_stop_update(struct inode *inode);
2819
+void ext4_fc_del(struct inode *inode);
2820
+bool ext4_fc_replay_check_excluded(struct super_block *sb, ext4_fsblk_t block);
2821
+void ext4_fc_replay_cleanup(struct super_block *sb);
2822
+int ext4_fc_commit(journal_t *journal, tid_t commit_tid);
2823
+int __init ext4_fc_init_dentry_cache(void);
2824
+void ext4_fc_destroy_dentry_cache(void);
2825
+int ext4_fc_record_regions(struct super_block *sb, int ino,
2826
+ ext4_lblk_t lblk, ext4_fsblk_t pblk,
2827
+ int len, int replay);
2828
+
25792829 /* mballoc.c */
25802830 extern const struct seq_operations ext4_mb_seq_groups_ops;
25812831 extern long ext4_mb_stats;
....@@ -2585,9 +2835,15 @@
25852835 extern ext4_fsblk_t ext4_mb_new_blocks(handle_t *,
25862836 struct ext4_allocation_request *, int *);
25872837 extern int ext4_mb_reserve_blocks(struct super_block *, int);
2588
-extern void ext4_discard_preallocations(struct inode *);
2838
+extern void ext4_discard_preallocations(struct inode *, unsigned int);
25892839 extern int __init ext4_init_mballoc(void);
25902840 extern void ext4_exit_mballoc(void);
2841
+extern ext4_group_t ext4_mb_prefetch(struct super_block *sb,
2842
+ ext4_group_t group,
2843
+ unsigned int nr, int *cnt);
2844
+extern void ext4_mb_prefetch_fini(struct super_block *sb, ext4_group_t group,
2845
+ unsigned int nr);
2846
+
25912847 extern void ext4_free_blocks(handle_t *handle, struct inode *inode,
25922848 struct buffer_head *bh, ext4_fsblk_t block,
25932849 unsigned long count, int flags);
....@@ -2599,8 +2855,12 @@
25992855 ext4_fsblk_t block, unsigned long count);
26002856 extern int ext4_trim_fs(struct super_block *, struct fstrim_range *);
26012857 extern void ext4_process_freed_data(struct super_block *sb, tid_t commit_tid);
2858
+extern void ext4_mb_mark_bb(struct super_block *sb, ext4_fsblk_t block,
2859
+ int len, int state);
26022860
26032861 /* inode.c */
2862
+void ext4_inode_csum_set(struct inode *inode, struct ext4_inode *raw,
2863
+ struct ext4_inode_info *ei);
26042864 int ext4_inode_is_fast_symlink(struct inode *inode);
26052865 struct buffer_head *ext4_getblk(handle_t *, struct inode *, ext4_lblk_t, int);
26062866 struct buffer_head *ext4_bread(handle_t *, struct inode *, ext4_lblk_t, int);
....@@ -2610,8 +2870,6 @@
26102870 struct buffer_head *bh_result, int create);
26112871 int ext4_get_block(struct inode *inode, sector_t iblock,
26122872 struct buffer_head *bh_result, int create);
2613
-int ext4_dio_get_block(struct inode *inode, sector_t iblock,
2614
- struct buffer_head *bh_result, int create);
26152873 int ext4_da_get_block_prep(struct inode *inode, sector_t iblock,
26162874 struct buffer_head *bh, int create);
26172875 int ext4_walk_page_buffers(handle_t *handle,
....@@ -2649,23 +2907,25 @@
26492907 extern void ext4_dirty_inode(struct inode *, int);
26502908 extern int ext4_change_inode_journal_flag(struct inode *, int);
26512909 extern int ext4_get_inode_loc(struct inode *, struct ext4_iloc *);
2910
+extern int ext4_get_fc_inode_loc(struct super_block *sb, unsigned long ino,
2911
+ struct ext4_iloc *iloc);
26522912 extern int ext4_inode_attach_jinode(struct inode *inode);
26532913 extern int ext4_can_truncate(struct inode *inode);
26542914 extern int ext4_truncate(struct inode *);
26552915 extern int ext4_break_layouts(struct inode *);
2656
-extern int ext4_punch_hole(struct inode *inode, loff_t offset, loff_t length);
2657
-extern int ext4_truncate_restart_trans(handle_t *, struct inode *, int nblocks);
2658
-extern void ext4_set_inode_flags(struct inode *);
2916
+extern int ext4_punch_hole(struct file *file, loff_t offset, loff_t length);
2917
+extern void ext4_set_inode_flags(struct inode *, bool init);
26592918 extern int ext4_alloc_da_blocks(struct inode *inode);
26602919 extern void ext4_set_aops(struct inode *inode);
26612920 extern int ext4_writepage_trans_blocks(struct inode *);
26622921 extern int ext4_chunk_trans_blocks(struct inode *, int nrblocks);
26632922 extern int ext4_zero_partial_blocks(handle_t *handle, struct inode *inode,
26642923 loff_t lstart, loff_t lend);
2665
-extern int ext4_page_mkwrite(struct vm_fault *vmf);
2666
-extern int ext4_filemap_fault(struct vm_fault *vmf);
2924
+extern vm_fault_t ext4_page_mkwrite(struct vm_fault *vmf);
2925
+extern vm_fault_t ext4_filemap_fault(struct vm_fault *vmf);
26672926 extern qsize_t *ext4_get_reserved_space(struct inode *inode);
26682927 extern int ext4_get_projid(struct inode *inode, kprojid_t *projid);
2928
+extern void ext4_da_release_space(struct inode *inode, int to_free);
26692929 extern void ext4_da_update_reserve_space(struct inode *inode,
26702930 int used, int quota_claim);
26712931 extern int ext4_issue_zeroout(struct inode *inode, ext4_lblk_t lblk,
....@@ -2674,7 +2934,6 @@
26742934 /* indirect.c */
26752935 extern int ext4_ind_map_blocks(handle_t *handle, struct inode *inode,
26762936 struct ext4_map_blocks *map, int flags);
2677
-extern int ext4_ind_calc_metadata_amount(struct inode *inode, sector_t lblock);
26782937 extern int ext4_ind_trans_blocks(struct inode *inode, int nrblocks);
26792938 extern void ext4_ind_truncate(handle_t *, struct inode *inode);
26802939 extern int ext4_ind_remove_space(handle_t *handle, struct inode *inode,
....@@ -2683,14 +2942,17 @@
26832942 /* ioctl.c */
26842943 extern long ext4_ioctl(struct file *, unsigned int, unsigned long);
26852944 extern long ext4_compat_ioctl(struct file *, unsigned int, unsigned long);
2945
+extern void ext4_reset_inode_seed(struct inode *inode);
26862946
26872947 /* migrate.c */
26882948 extern int ext4_ext_migrate(struct inode *);
26892949 extern int ext4_ind_migrate(struct inode *inode);
26902950
26912951 /* namei.c */
2692
-extern int ext4_dirent_csum_verify(struct inode *inode,
2693
- struct ext4_dir_entry *dirent);
2952
+extern int ext4_init_new_dir(handle_t *handle, struct inode *dir,
2953
+ struct inode *inode);
2954
+extern int ext4_dirblock_csum_verify(struct inode *inode,
2955
+ struct buffer_head *bh);
26942956 extern int ext4_orphan_add(handle_t *, struct inode *);
26952957 extern int ext4_orphan_del(handle_t *, struct inode *);
26962958 extern int ext4_htree_fill_tree(struct file *dir_file, __u32 start_hash,
....@@ -2702,8 +2964,7 @@
27022964 struct ext4_filename *fname,
27032965 ext4_lblk_t lblk, unsigned int offset,
27042966 struct ext4_dir_entry_2 **res_dir);
2705
-extern int ext4_generic_delete_entry(handle_t *handle,
2706
- struct inode *dir,
2967
+extern int ext4_generic_delete_entry(struct inode *dir,
27072968 struct ext4_dir_entry_2 *de_del,
27082969 ext4_lblk_t lblk,
27092970 struct buffer_head *bh,
....@@ -2724,11 +2985,17 @@
27242985 /* super.c */
27252986 extern struct buffer_head *ext4_sb_bread(struct super_block *sb,
27262987 sector_t block, int op_flags);
2988
+extern struct buffer_head *ext4_sb_bread_unmovable(struct super_block *sb,
2989
+ sector_t block);
2990
+extern void ext4_read_bh_nowait(struct buffer_head *bh, int op_flags,
2991
+ bh_end_io_t *end_io);
2992
+extern int ext4_read_bh(struct buffer_head *bh, int op_flags,
2993
+ bh_end_io_t *end_io);
2994
+extern int ext4_read_bh_lock(struct buffer_head *bh, int op_flags, bool wait);
2995
+extern void ext4_sb_breadahead_unmovable(struct super_block *sb, sector_t block);
27272996 extern int ext4_seq_options_show(struct seq_file *seq, void *offset);
27282997 extern int ext4_calculate_overhead(struct super_block *sb);
27292998 extern void ext4_superblock_csum_set(struct super_block *sb);
2730
-extern void *ext4_kvmalloc(size_t size, gfp_t flags);
2731
-extern void *ext4_kvzalloc(size_t size, gfp_t flags);
27322999 extern int ext4_alloc_flex_bg_array(struct super_block *sb,
27333000 ext4_group_t ngroup);
27343001 extern const char *ext4_decode_error(struct super_block *sb, int errno,
....@@ -2737,19 +3004,19 @@
27373004 ext4_group_t block_group,
27383005 unsigned int flags);
27393006
2740
-extern __printf(4, 5)
2741
-void __ext4_error(struct super_block *, const char *, unsigned int,
3007
+extern __printf(6, 7)
3008
+void __ext4_error(struct super_block *, const char *, unsigned int, int, __u64,
27423009 const char *, ...);
2743
-extern __printf(5, 6)
2744
-void __ext4_error_inode(struct inode *, const char *, unsigned int, ext4_fsblk_t,
2745
- const char *, ...);
3010
+extern __printf(6, 7)
3011
+void __ext4_error_inode(struct inode *, const char *, unsigned int,
3012
+ ext4_fsblk_t, int, const char *, ...);
27463013 extern __printf(5, 6)
27473014 void __ext4_error_file(struct file *, const char *, unsigned int, ext4_fsblk_t,
27483015 const char *, ...);
27493016 extern void __ext4_std_error(struct super_block *, const char *,
27503017 unsigned int, int);
2751
-extern __printf(4, 5)
2752
-void __ext4_abort(struct super_block *, const char *, unsigned int,
3018
+extern __printf(5, 6)
3019
+void __ext4_abort(struct super_block *, const char *, unsigned int, int,
27533020 const char *, ...);
27543021 extern __printf(4, 5)
27553022 void __ext4_warning(struct super_block *, const char *, unsigned int,
....@@ -2770,8 +3037,12 @@
27703037 #define EXT4_ERROR_INODE(inode, fmt, a...) \
27713038 ext4_error_inode((inode), __func__, __LINE__, 0, (fmt), ## a)
27723039
2773
-#define EXT4_ERROR_INODE_BLOCK(inode, block, fmt, a...) \
2774
- ext4_error_inode((inode), __func__, __LINE__, (block), (fmt), ## a)
3040
+#define EXT4_ERROR_INODE_ERR(inode, err, fmt, a...) \
3041
+ __ext4_error_inode((inode), __func__, __LINE__, 0, (err), (fmt), ## a)
3042
+
3043
+#define ext4_error_inode_block(inode, block, err, fmt, a...) \
3044
+ __ext4_error_inode((inode), __func__, __LINE__, (block), (err), \
3045
+ (fmt), ## a)
27753046
27763047 #define EXT4_ERROR_FILE(file, block, fmt, a...) \
27773048 ext4_error_file((file), __func__, __LINE__, (block), (fmt), ## a)
....@@ -2779,13 +3050,18 @@
27793050 #ifdef CONFIG_PRINTK
27803051
27813052 #define ext4_error_inode(inode, func, line, block, fmt, ...) \
2782
- __ext4_error_inode(inode, func, line, block, fmt, ##__VA_ARGS__)
3053
+ __ext4_error_inode(inode, func, line, block, 0, fmt, ##__VA_ARGS__)
3054
+#define ext4_error_inode_err(inode, func, line, block, err, fmt, ...) \
3055
+ __ext4_error_inode((inode), (func), (line), (block), \
3056
+ (err), (fmt), ##__VA_ARGS__)
27833057 #define ext4_error_file(file, func, line, block, fmt, ...) \
27843058 __ext4_error_file(file, func, line, block, fmt, ##__VA_ARGS__)
27853059 #define ext4_error(sb, fmt, ...) \
2786
- __ext4_error(sb, __func__, __LINE__, fmt, ##__VA_ARGS__)
2787
-#define ext4_abort(sb, fmt, ...) \
2788
- __ext4_abort(sb, __func__, __LINE__, fmt, ##__VA_ARGS__)
3060
+ __ext4_error((sb), __func__, __LINE__, 0, 0, (fmt), ##__VA_ARGS__)
3061
+#define ext4_error_err(sb, err, fmt, ...) \
3062
+ __ext4_error((sb), __func__, __LINE__, (err), 0, (fmt), ##__VA_ARGS__)
3063
+#define ext4_abort(sb, err, fmt, ...) \
3064
+ __ext4_abort((sb), __func__, __LINE__, (err), (fmt), ##__VA_ARGS__)
27893065 #define ext4_warning(sb, fmt, ...) \
27903066 __ext4_warning(sb, __func__, __LINE__, fmt, ##__VA_ARGS__)
27913067 #define ext4_warning_inode(inode, fmt, ...) \
....@@ -2803,7 +3079,12 @@
28033079 #define ext4_error_inode(inode, func, line, block, fmt, ...) \
28043080 do { \
28053081 no_printk(fmt, ##__VA_ARGS__); \
2806
- __ext4_error_inode(inode, "", 0, block, " "); \
3082
+ __ext4_error_inode(inode, "", 0, block, 0, " "); \
3083
+} while (0)
3084
+#define ext4_error_inode_err(inode, func, line, block, err, fmt, ...) \
3085
+do { \
3086
+ no_printk(fmt, ##__VA_ARGS__); \
3087
+ __ext4_error_inode(inode, "", 0, block, err, " "); \
28073088 } while (0)
28083089 #define ext4_error_file(file, func, line, block, fmt, ...) \
28093090 do { \
....@@ -2813,12 +3094,17 @@
28133094 #define ext4_error(sb, fmt, ...) \
28143095 do { \
28153096 no_printk(fmt, ##__VA_ARGS__); \
2816
- __ext4_error(sb, "", 0, " "); \
3097
+ __ext4_error(sb, "", 0, 0, 0, " "); \
28173098 } while (0)
2818
-#define ext4_abort(sb, fmt, ...) \
3099
+#define ext4_error_err(sb, err, fmt, ...) \
28193100 do { \
28203101 no_printk(fmt, ##__VA_ARGS__); \
2821
- __ext4_abort(sb, "", 0, " "); \
3102
+ __ext4_error(sb, "", 0, err, 0, " "); \
3103
+} while (0)
3104
+#define ext4_abort(sb, err, fmt, ...) \
3105
+do { \
3106
+ no_printk(fmt, ##__VA_ARGS__); \
3107
+ __ext4_abort(sb, "", 0, err, " "); \
28223108 } while (0)
28233109 #define ext4_warning(sb, fmt, ...) \
28243110 do { \
....@@ -2845,12 +3131,6 @@
28453131
28463132 #endif
28473133
2848
-extern int ext4_update_compat_feature(handle_t *handle, struct super_block *sb,
2849
- __u32 compat);
2850
-extern int ext4_update_rocompat_feature(handle_t *handle,
2851
- struct super_block *sb, __u32 rocompat);
2852
-extern int ext4_update_incompat_feature(handle_t *handle,
2853
- struct super_block *sb, __u32 incompat);
28543134 extern ext4_fsblk_t ext4_block_bitmap(struct super_block *sb,
28553135 struct ext4_group_desc *bg);
28563136 extern ext4_fsblk_t ext4_inode_bitmap(struct super_block *sb,
....@@ -2901,22 +3181,24 @@
29013181 return ext4_has_feature_gdt_csum(sb) || ext4_has_metadata_csum(sb);
29023182 }
29033183
3184
+#define ext4_read_incompat_64bit_val(es, name) \
3185
+ (((es)->s_feature_incompat & cpu_to_le32(EXT4_FEATURE_INCOMPAT_64BIT) \
3186
+ ? (ext4_fsblk_t)le32_to_cpu(es->name##_hi) << 32 : 0) | \
3187
+ le32_to_cpu(es->name##_lo))
3188
+
29043189 static inline ext4_fsblk_t ext4_blocks_count(struct ext4_super_block *es)
29053190 {
2906
- return ((ext4_fsblk_t)le32_to_cpu(es->s_blocks_count_hi) << 32) |
2907
- le32_to_cpu(es->s_blocks_count_lo);
3191
+ return ext4_read_incompat_64bit_val(es, s_blocks_count);
29083192 }
29093193
29103194 static inline ext4_fsblk_t ext4_r_blocks_count(struct ext4_super_block *es)
29113195 {
2912
- return ((ext4_fsblk_t)le32_to_cpu(es->s_r_blocks_count_hi) << 32) |
2913
- le32_to_cpu(es->s_r_blocks_count_lo);
3196
+ return ext4_read_incompat_64bit_val(es, s_r_blocks_count);
29143197 }
29153198
29163199 static inline ext4_fsblk_t ext4_free_blocks_count(struct ext4_super_block *es)
29173200 {
2918
- return ((ext4_fsblk_t)le32_to_cpu(es->s_free_blocks_count_hi) << 32) |
2919
- le32_to_cpu(es->s_free_blocks_count_lo);
3201
+ return ext4_read_incompat_64bit_val(es, s_free_blocks_count);
29203202 }
29213203
29223204 static inline void ext4_blocks_count_set(struct ext4_super_block *es,
....@@ -3042,6 +3324,9 @@
30423324
30433325 struct ext4_group_info {
30443326 unsigned long bb_state;
3327
+#ifdef AGGRESSIVE_CHECK
3328
+ unsigned long bb_check_counter;
3329
+#endif
30453330 struct rb_root bb_free_root;
30463331 ext4_grpblk_t bb_first_free; /* first free block */
30473332 ext4_grpblk_t bb_free; /* total free blocks */
....@@ -3066,6 +3351,7 @@
30663351 (1 << EXT4_GROUP_INFO_BBITMAP_CORRUPT_BIT)
30673352 #define EXT4_GROUP_INFO_IBITMAP_CORRUPT \
30683353 (1 << EXT4_GROUP_INFO_IBITMAP_CORRUPT_BIT)
3354
+#define EXT4_GROUP_INFO_BBITMAP_READ_BIT 4
30693355
30703356 #define EXT4_MB_GRP_NEED_INIT(grp) \
30713357 (test_bit(EXT4_GROUP_INFO_NEED_INIT_BIT, &((grp)->bb_state)))
....@@ -3080,6 +3366,8 @@
30803366 (set_bit(EXT4_GROUP_INFO_WAS_TRIMMED_BIT, &((grp)->bb_state)))
30813367 #define EXT4_MB_GRP_CLEAR_TRIMMED(grp) \
30823368 (clear_bit(EXT4_GROUP_INFO_WAS_TRIMMED_BIT, &((grp)->bb_state)))
3369
+#define EXT4_MB_GRP_TEST_AND_SET_READ(grp) \
3370
+ (test_and_set_bit(EXT4_GROUP_INFO_BBITMAP_READ_BIT, &((grp)->bb_state)))
30833371
30843372 #define EXT4_MAX_CONTENTION 8
30853373 #define EXT4_CONTENTION_THRESHOLD 2
....@@ -3145,10 +3433,6 @@
31453433 /* dir.c */
31463434 extern const struct file_operations ext4_dir_operations;
31473435
3148
-#ifdef CONFIG_UNICODE
3149
-extern const struct dentry_operations ext4_dentry_ops;
3150
-#endif
3151
-
31523436 /* file.c */
31533437 extern const struct inode_operations ext4_file_inode_operations;
31543438 extern const struct file_operations ext4_file_operations;
....@@ -3193,11 +3477,11 @@
31933477 extern int ext4_read_inline_dir(struct file *filp,
31943478 struct dir_context *ctx,
31953479 int *has_inline_data);
3196
-extern int htree_inlinedir_to_tree(struct file *dir_file,
3197
- struct inode *dir, ext4_lblk_t block,
3198
- struct dx_hash_info *hinfo,
3199
- __u32 start_hash, __u32 start_minor_hash,
3200
- int *has_inline_data);
3480
+extern int ext4_inlinedir_to_tree(struct file *dir_file,
3481
+ struct inode *dir, ext4_lblk_t block,
3482
+ struct dx_hash_info *hinfo,
3483
+ __u32 start_hash, __u32 start_minor_hash,
3484
+ int *has_inline_data);
32013485 extern struct buffer_head *ext4_find_inline_entry(struct inode *dir,
32023486 struct ext4_filename *fname,
32033487 struct ext4_dir_entry_2 **res_dir,
....@@ -3236,11 +3520,14 @@
32363520 struct ext4_dir_entry_2 *de,
32373521 int blocksize, int csum_size,
32383522 unsigned int parent_ino, int dotdot_real_len);
3239
-extern void initialize_dirent_tail(struct ext4_dir_entry_tail *t,
3240
- unsigned int blocksize);
3241
-extern int ext4_handle_dirty_dirent_node(handle_t *handle,
3242
- struct inode *inode,
3243
- struct buffer_head *bh);
3523
+extern void ext4_initialize_dirent_tail(struct buffer_head *bh,
3524
+ unsigned int blocksize);
3525
+extern int ext4_handle_dirty_dirblock(handle_t *handle, struct inode *inode,
3526
+ struct buffer_head *bh);
3527
+extern int __ext4_unlink(handle_t *handle, struct inode *dir, const struct qstr *d_name,
3528
+ struct inode *inode);
3529
+extern int __ext4_link(struct inode *dir, struct inode *inode,
3530
+ struct dentry *dentry);
32443531
32453532 #define S_SHIFT 12
32463533 static const unsigned char ext4_type_by_mode[(S_IFMT >> S_SHIFT) + 1] = {
....@@ -3261,9 +3548,8 @@
32613548 }
32623549
32633550 /* readpages.c */
3264
-extern int ext4_mpage_readpages(struct address_space *mapping,
3265
- struct list_head *pages, struct page *page,
3266
- unsigned nr_pages, bool is_readahead);
3551
+extern int ext4_mpage_readpages(struct inode *inode,
3552
+ struct readahead_control *rac, struct page *page);
32673553 extern int __init ext4_init_post_read_processing(void);
32683554 extern void ext4_exit_post_read_processing(void);
32693555
....@@ -3299,8 +3585,7 @@
32993585 */
33003586 #define EXT_MAX_BLOCKS 0xffffffff
33013587
3302
-extern int ext4_ext_tree_init(handle_t *handle, struct inode *);
3303
-extern int ext4_ext_writepage_trans_blocks(struct inode *, int);
3588
+extern void ext4_ext_tree_init(handle_t *handle, struct inode *inode);
33043589 extern int ext4_ext_index_trans_blocks(struct inode *inode, int extents);
33053590 extern int ext4_ext_map_blocks(handle_t *handle, struct inode *inode,
33063591 struct ext4_map_blocks *map, int flags);
....@@ -3313,16 +3598,13 @@
33133598 loff_t len);
33143599 extern int ext4_convert_unwritten_extents(handle_t *handle, struct inode *inode,
33153600 loff_t offset, ssize_t len);
3601
+extern int ext4_convert_unwritten_io_end_vec(handle_t *handle,
3602
+ ext4_io_end_t *io_end);
33163603 extern int ext4_map_blocks(handle_t *handle, struct inode *inode,
33173604 struct ext4_map_blocks *map, int flags);
3318
-extern int ext4_ext_calc_metadata_amount(struct inode *inode,
3319
- ext4_lblk_t lblocks);
33203605 extern int ext4_ext_calc_credits_for_single_extent(struct inode *inode,
33213606 int num,
33223607 struct ext4_ext_path *path);
3323
-extern int ext4_can_extents_be_merged(struct inode *inode,
3324
- struct ext4_extent *ex1,
3325
- struct ext4_extent *ex2);
33263608 extern int ext4_ext_insert_extent(handle_t *, struct inode *,
33273609 struct ext4_ext_path **,
33283610 struct ext4_extent *, int);
....@@ -3331,20 +3613,27 @@
33313613 int flags);
33323614 extern void ext4_ext_drop_refs(struct ext4_ext_path *);
33333615 extern int ext4_ext_check_inode(struct inode *inode);
3334
-extern int ext4_find_delalloc_range(struct inode *inode,
3335
- ext4_lblk_t lblk_start,
3336
- ext4_lblk_t lblk_end);
3337
-extern int ext4_find_delalloc_cluster(struct inode *inode, ext4_lblk_t lblk);
33383616 extern ext4_lblk_t ext4_ext_next_allocated_block(struct ext4_ext_path *path);
33393617 extern int ext4_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
33403618 __u64 start, __u64 len);
3619
+extern int ext4_get_es_cache(struct inode *inode,
3620
+ struct fiemap_extent_info *fieinfo,
3621
+ __u64 start, __u64 len);
33413622 extern int ext4_ext_precache(struct inode *inode);
3342
-extern int ext4_collapse_range(struct inode *inode, loff_t offset, loff_t len);
3343
-extern int ext4_insert_range(struct inode *inode, loff_t offset, loff_t len);
33443623 extern int ext4_swap_extents(handle_t *handle, struct inode *inode1,
33453624 struct inode *inode2, ext4_lblk_t lblk1,
33463625 ext4_lblk_t lblk2, ext4_lblk_t count,
33473626 int mark_unwritten,int *err);
3627
+extern int ext4_clu_mapped(struct inode *inode, ext4_lblk_t lclu);
3628
+extern int ext4_datasem_ensure_credits(handle_t *handle, struct inode *inode,
3629
+ int check_cred, int restart_cred,
3630
+ int revoke_cred);
3631
+extern void ext4_ext_replay_shrink_inode(struct inode *inode, ext4_lblk_t end);
3632
+extern int ext4_ext_replay_set_iblocks(struct inode *inode);
3633
+extern int ext4_ext_replay_update_ex(struct inode *inode, ext4_lblk_t start,
3634
+ int len, int unwritten, ext4_fsblk_t pblk);
3635
+extern int ext4_ext_clear_bb(struct inode *inode);
3636
+
33483637
33493638 /* move_extent.c */
33503639 extern void ext4_double_down_write_data_sem(struct inode *first,
....@@ -3371,9 +3660,14 @@
33713660 int len,
33723661 struct writeback_control *wbc,
33733662 bool keep_towrite);
3663
+extern struct ext4_io_end_vec *ext4_alloc_io_end_vec(ext4_io_end_t *io_end);
3664
+extern struct ext4_io_end_vec *ext4_last_io_end_vec(ext4_io_end_t *io_end);
33743665
33753666 /* mmp.c */
33763667 extern int ext4_multi_mount_protect(struct super_block *, ext4_fsblk_t);
3668
+
3669
+/* mmp.c */
3670
+extern void ext4_stop_mmpd(struct ext4_sb_info *sbi);
33773671
33783672 /* verity.c */
33793673 extern const struct fsverity_operations ext4_verityops;
....@@ -3428,6 +3722,21 @@
34283722 }
34293723
34303724 extern const struct iomap_ops ext4_iomap_ops;
3725
+extern const struct iomap_ops ext4_iomap_overwrite_ops;
3726
+extern const struct iomap_ops ext4_iomap_report_ops;
3727
+
3728
+static inline int ext4_buffer_uptodate(struct buffer_head *bh)
3729
+{
3730
+ /*
3731
+ * If the buffer has the write error flag, we have failed
3732
+ * to write out data in the block. In this case, we don't
3733
+ * have to read the block because we may read the old data
3734
+ * successfully.
3735
+ */
3736
+ if (!buffer_uptodate(bh) && buffer_write_io_error(bh))
3737
+ set_buffer_uptodate(bh);
3738
+ return buffer_uptodate(bh);
3739
+}
34313740
34323741 #endif /* __KERNEL__ */
34333742