@@ -278,7 +278,10 @@ struct ext4_system_blocks {
278
278
/*
279
279
* Flags for ext4_io_end->flags
280
280
*/
281
- #define EXT4_IO_END_UNWRITTEN 0x0001
281
+ #define EXT4_IO_END_UNWRITTEN 0x0001
282
+ #define EXT4_IO_END_FAILED 0x0002
283
+
284
+ #define EXT4_IO_END_DEFER_COMPLETION (EXT4_IO_END_UNWRITTEN | EXT4_IO_END_FAILED)
282
285
283
286
struct ext4_io_end_vec {
284
287
struct list_head list ; /* list of io_end_vec */
@@ -367,6 +370,8 @@ struct ext4_io_submit {
367
370
#define EXT4_MAX_BLOCKS (size , offset , blkbits ) \
368
371
((EXT4_BLOCK_ALIGN(size + offset, blkbits) >> blkbits) - (offset >> \
369
372
blkbits))
373
+ #define EXT4_B_TO_LBLK (inode , offset ) \
374
+ (round_up((offset), i_blocksize(inode)) >> (inode)->i_blkbits)
370
375
371
376
/* Translate a block number to a cluster number */
372
377
#define EXT4_B2C (sbi , blk ) ((blk) >> (sbi)->s_cluster_bits)
@@ -1058,7 +1063,8 @@ struct ext4_inode_info {
1058
1063
1059
1064
/* Number of ongoing updates on this inode */
1060
1065
atomic_t i_fc_updates ;
1061
- atomic_t i_unwritten ; /* Nr. of inflight conversions pending */
1066
+
1067
+ spinlock_t i_raw_lock ; /* protects updates to the raw inode */
1062
1068
1063
1069
/* Fast commit wait queue for this inode */
1064
1070
wait_queue_head_t i_fc_wait ;
@@ -1097,8 +1103,6 @@ struct ext4_inode_info {
1097
1103
struct inode vfs_inode ;
1098
1104
struct jbd2_inode * jinode ;
1099
1105
1100
- spinlock_t i_raw_lock ; /* protects updates to the raw inode */
1101
-
1102
1106
/*
1103
1107
* File creation time. Its function is same as that of
1104
1108
* struct timespec64 i_{a,c,m}time in the generic inode.
@@ -1141,6 +1145,7 @@ struct ext4_inode_info {
1141
1145
/* quota space reservation, managed internally by quota code */
1142
1146
qsize_t i_reserved_quota ;
1143
1147
#endif
1148
+ spinlock_t i_block_reservation_lock ;
1144
1149
1145
1150
/* Lock protecting lists below */
1146
1151
spinlock_t i_completed_io_lock ;
@@ -1151,8 +1156,6 @@ struct ext4_inode_info {
1151
1156
struct list_head i_rsv_conversion_list ;
1152
1157
struct work_struct i_rsv_conversion_work ;
1153
1158
1154
- spinlock_t i_block_reservation_lock ;
1155
-
1156
1159
/*
1157
1160
* Transactions that contain inode's metadata needed to complete
1158
1161
* fsync and fdatasync, respectively.
@@ -1606,6 +1609,8 @@ struct ext4_sb_info {
1606
1609
unsigned int s_mb_prefetch ;
1607
1610
unsigned int s_mb_prefetch_limit ;
1608
1611
unsigned int s_mb_best_avail_max_trim_order ;
1612
+ unsigned int s_sb_update_sec ;
1613
+ unsigned int s_sb_update_kb ;
1609
1614
1610
1615
/* stats for buddy allocator */
1611
1616
atomic_t s_bal_reqs ; /* number of reqs with len > 1 */
@@ -1821,7 +1826,8 @@ static inline int ext4_valid_inum(struct super_block *sb, unsigned long ino)
1821
1826
*/
1822
1827
enum {
1823
1828
EXT4_MF_MNTDIR_SAMPLED ,
1824
- EXT4_MF_FC_INELIGIBLE /* Fast commit ineligible */
1829
+ EXT4_MF_FC_INELIGIBLE , /* Fast commit ineligible */
1830
+ EXT4_MF_JOURNAL_DESTROY /* Journal is in process of destroying */
1825
1831
};
1826
1832
1827
1833
static inline void ext4_set_mount_flag (struct super_block * sb , int bit )
@@ -2232,15 +2238,32 @@ extern int ext4_feature_set_ok(struct super_block *sb, int readonly);
2232
2238
/*
2233
2239
* Superblock flags
2234
2240
*/
2235
- #define EXT4_FLAGS_RESIZING 0
2236
- #define EXT4_FLAGS_SHUTDOWN 1
2237
- #define EXT4_FLAGS_BDEV_IS_DAX 2
2241
+ enum {
2242
+ EXT4_FLAGS_RESIZING , /* Avoid superblock update and resize race */
2243
+ EXT4_FLAGS_SHUTDOWN , /* Prevent access to the file system */
2244
+ EXT4_FLAGS_BDEV_IS_DAX , /* Current block device support DAX */
2245
+ EXT4_FLAGS_EMERGENCY_RO ,/* Emergency read-only due to fs errors */
2246
+ };
2238
2247
2239
2248
static inline int ext4_forced_shutdown (struct super_block * sb )
2240
2249
{
2241
2250
return test_bit (EXT4_FLAGS_SHUTDOWN , & EXT4_SB (sb )-> s_ext4_flags );
2242
2251
}
2243
2252
2253
+ static inline int ext4_emergency_ro (struct super_block * sb )
2254
+ {
2255
+ return test_bit (EXT4_FLAGS_EMERGENCY_RO , & EXT4_SB (sb )-> s_ext4_flags );
2256
+ }
2257
+
2258
+ static inline int ext4_emergency_state (struct super_block * sb )
2259
+ {
2260
+ if (unlikely (ext4_forced_shutdown (sb )))
2261
+ return - EIO ;
2262
+ if (unlikely (ext4_emergency_ro (sb )))
2263
+ return - EROFS ;
2264
+ return 0 ;
2265
+ }
2266
+
2244
2267
/*
2245
2268
* Default values for user and/or group using reserved blocks
2246
2269
*/
@@ -2277,6 +2300,13 @@ static inline int ext4_forced_shutdown(struct super_block *sb)
2277
2300
#define EXT4_DEF_MIN_BATCH_TIME 0
2278
2301
#define EXT4_DEF_MAX_BATCH_TIME 15000 /* 15ms */
2279
2302
2303
+ /*
2304
+ * Default values for superblock update
2305
+ */
2306
+ #define EXT4_DEF_SB_UPDATE_INTERVAL_SEC (3600) /* seconds (1 hour) */
2307
+ #define EXT4_DEF_SB_UPDATE_INTERVAL_KB (16384) /* kilobytes (16MB) */
2308
+
2309
+
2280
2310
/*
2281
2311
* Minimum number of groups in a flexgroup before we separate out
2282
2312
* directories into the first block group of a flexgroup
@@ -2810,8 +2840,7 @@ extern int ext4_htree_store_dirent(struct file *dir_file, __u32 hash,
2810
2840
struct ext4_dir_entry_2 * dirent ,
2811
2841
struct fscrypt_str * ent_name );
2812
2842
extern void ext4_htree_free_dir_info (struct dir_private_info * p );
2813
- extern int ext4_find_dest_de (struct inode * dir , struct inode * inode ,
2814
- struct buffer_head * bh ,
2843
+ extern int ext4_find_dest_de (struct inode * dir , struct buffer_head * bh ,
2815
2844
void * buf , int buf_size ,
2816
2845
struct ext4_filename * fname ,
2817
2846
struct ext4_dir_entry_2 * * dest_de );
@@ -3001,6 +3030,8 @@ extern int ext4_inode_attach_jinode(struct inode *inode);
3001
3030
extern int ext4_can_truncate (struct inode * inode );
3002
3031
extern int ext4_truncate (struct inode * );
3003
3032
extern int ext4_break_layouts (struct inode * );
3033
+ extern int ext4_truncate_page_cache_block_range (struct inode * inode ,
3034
+ loff_t start , loff_t end );
3004
3035
extern int ext4_punch_hole (struct file * file , loff_t offset , loff_t length );
3005
3036
extern void ext4_set_inode_flags (struct inode * , bool init );
3006
3037
extern int ext4_alloc_da_blocks (struct inode * inode );
@@ -3259,14 +3290,10 @@ extern void ext4_group_desc_csum_set(struct super_block *sb, __u32 group,
3259
3290
extern int ext4_register_li_request (struct super_block * sb ,
3260
3291
ext4_group_t first_not_zeroed );
3261
3292
3262
- static inline int ext4_has_metadata_csum (struct super_block * sb )
3263
- {
3264
- return ext4_has_feature_metadata_csum (sb );
3265
- }
3266
-
3267
3293
static inline int ext4_has_group_desc_csum (struct super_block * sb )
3268
3294
{
3269
- return ext4_has_feature_gdt_csum (sb ) || ext4_has_metadata_csum (sb );
3295
+ return ext4_has_feature_gdt_csum (sb ) ||
3296
+ ext4_has_feature_metadata_csum (sb );
3270
3297
}
3271
3298
3272
3299
#define ext4_read_incompat_64bit_val (es , name ) \
@@ -3546,11 +3573,11 @@ extern int ext4_try_to_write_inline_data(struct address_space *mapping,
3546
3573
struct folio * * foliop );
3547
3574
int ext4_write_inline_data_end (struct inode * inode , loff_t pos , unsigned len ,
3548
3575
unsigned copied , struct folio * folio );
3549
- extern int ext4_da_write_inline_data_begin (struct address_space * mapping ,
3550
- struct inode * inode ,
3551
- loff_t pos , unsigned len ,
3552
- struct folio * * foliop ,
3553
- void * * fsdata );
3576
+ extern int ext4_generic_write_inline_data (struct address_space * mapping ,
3577
+ struct inode * inode ,
3578
+ loff_t pos , unsigned len ,
3579
+ struct folio * * foliop ,
3580
+ void * * fsdata , bool da );
3554
3581
extern int ext4_try_add_inline_entry (handle_t * handle ,
3555
3582
struct ext4_filename * fname ,
3556
3583
struct inode * dir , struct inode * inode );
@@ -3785,34 +3812,19 @@ static inline void set_bitmap_uptodate(struct buffer_head *bh)
3785
3812
set_bit (BH_BITMAP_UPTODATE , & (bh )-> b_state );
3786
3813
}
3787
3814
3788
- /* For ioend & aio unwritten conversion wait queues */
3789
- #define EXT4_WQ_HASH_SZ 37
3790
- #define ext4_ioend_wq (v ) (&ext4__ioend_wq[((unsigned long)(v)) %\
3791
- EXT4_WQ_HASH_SZ])
3792
- extern wait_queue_head_t ext4__ioend_wq [EXT4_WQ_HASH_SZ ];
3793
-
3794
3815
extern int ext4_resize_begin (struct super_block * sb );
3795
3816
extern int ext4_resize_end (struct super_block * sb , bool update_backups );
3796
3817
3797
- static inline void ext4_set_io_unwritten_flag (struct inode * inode ,
3798
- struct ext4_io_end * io_end )
3818
+ static inline void ext4_set_io_unwritten_flag (struct ext4_io_end * io_end )
3799
3819
{
3800
- if (!(io_end -> flag & EXT4_IO_END_UNWRITTEN )) {
3820
+ if (!(io_end -> flag & EXT4_IO_END_UNWRITTEN ))
3801
3821
io_end -> flag |= EXT4_IO_END_UNWRITTEN ;
3802
- atomic_inc (& EXT4_I (inode )-> i_unwritten );
3803
- }
3804
3822
}
3805
3823
3806
3824
static inline void ext4_clear_io_unwritten_flag (ext4_io_end_t * io_end )
3807
3825
{
3808
- struct inode * inode = io_end -> inode ;
3809
-
3810
- if (io_end -> flag & EXT4_IO_END_UNWRITTEN ) {
3826
+ if (io_end -> flag & EXT4_IO_END_UNWRITTEN )
3811
3827
io_end -> flag &= ~EXT4_IO_END_UNWRITTEN ;
3812
- /* Wake up anyone waiting on unwritten extent conversion */
3813
- if (atomic_dec_and_test (& EXT4_I (inode )-> i_unwritten ))
3814
- wake_up_all (ext4_ioend_wq (inode ));
3815
- }
3816
3828
}
3817
3829
3818
3830
extern const struct iomap_ops ext4_iomap_ops ;
0 commit comments