Skip to content

Commit 3ef96fc

Browse files
committed
Merge tag 'ext4_for_linus-6.6-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/tytso/ext4
Pull ext4 updates from Ted Ts'o: "Many ext4 and jbd2 cleanups and bug fixes: - Cleanups in the ext4 remount code when going to and from read-only - Cleanups in ext4's multiblock allocator - Cleanups in the jbd2 setup/mounting code paths - Performance improvements when appending to a delayed allocation file - Miscellaneous syzbot and other bug fixes" * tag 'ext4_for_linus-6.6-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/tytso/ext4: (60 commits) ext4: fix slab-use-after-free in ext4_es_insert_extent() libfs: remove redundant checks of s_encoding ext4: remove redundant checks of s_encoding ext4: reject casefold inode flag without casefold feature ext4: use LIST_HEAD() to initialize the list_head in mballoc.c ext4: do not mark inode dirty every time when appending using delalloc ext4: rename s_error_work to s_sb_upd_work ext4: add periodic superblock update check ext4: drop dio overwrite only flag and associated warning ext4: add correct group descriptors and reserved GDT blocks to system zone ext4: remove unused function declaration ext4: mballoc: avoid garbage value from err ext4: use sbi instead of EXT4_SB(sb) in ext4_mb_new_blocks_simple() ext4: change the type of blocksize in ext4_mb_init_cache() ext4: fix unttached inode after power cut with orphan file feature enabled jbd2: correct the end of the journal recovery scan range ext4: ext4_get_{dev}_journal return proper error value ext4: cleanup ext4_get_dev_journal() and ext4_get_journal() jbd2: jbd2_journal_init_{dev,inode} return proper error return value jbd2: drop useless error tag in jbd2_journal_wipe() ...
2 parents 659b361 + 768d612 commit 3ef96fc

26 files changed

+717
-678
lines changed

fs/ext4/balloc.c

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -913,11 +913,11 @@ unsigned long ext4_bg_num_gdb(struct super_block *sb, ext4_group_t group)
913913
}
914914

915915
/*
916-
* This function returns the number of file system metadata clusters at
916+
* This function returns the number of file system metadata blocks at
917917
* the beginning of a block group, including the reserved gdt blocks.
918918
*/
919-
static unsigned ext4_num_base_meta_clusters(struct super_block *sb,
920-
ext4_group_t block_group)
919+
unsigned int ext4_num_base_meta_blocks(struct super_block *sb,
920+
ext4_group_t block_group)
921921
{
922922
struct ext4_sb_info *sbi = EXT4_SB(sb);
923923
unsigned num;
@@ -935,8 +935,15 @@ static unsigned ext4_num_base_meta_clusters(struct super_block *sb,
935935
} else { /* For META_BG_BLOCK_GROUPS */
936936
num += ext4_bg_num_gdb_meta(sb, block_group);
937937
}
938-
return EXT4_NUM_B2C(sbi, num);
938+
return num;
939939
}
940+
941+
static unsigned int ext4_num_base_meta_clusters(struct super_block *sb,
942+
ext4_group_t block_group)
943+
{
944+
return EXT4_NUM_B2C(EXT4_SB(sb), ext4_num_base_meta_blocks(sb, block_group));
945+
}
946+
940947
/**
941948
* ext4_inode_to_goal_block - return a hint for block allocation
942949
* @inode: inode for block allocation

fs/ext4/block_validity.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -215,20 +215,20 @@ int ext4_setup_system_zone(struct super_block *sb)
215215
struct ext4_system_blocks *system_blks;
216216
struct ext4_group_desc *gdp;
217217
ext4_group_t i;
218-
int flex_size = ext4_flex_bg_size(sbi);
219218
int ret;
220219

221220
system_blks = kzalloc(sizeof(*system_blks), GFP_KERNEL);
222221
if (!system_blks)
223222
return -ENOMEM;
224223

225224
for (i=0; i < ngroups; i++) {
225+
unsigned int meta_blks = ext4_num_base_meta_blocks(sb, i);
226+
226227
cond_resched();
227-
if (ext4_bg_has_super(sb, i) &&
228-
((i < 5) || ((i % flex_size) == 0))) {
228+
if (meta_blks != 0) {
229229
ret = add_system_zone(system_blks,
230230
ext4_group_first_block_no(sb, i),
231-
ext4_bg_num_gdb(sb, i) + 1, 0);
231+
meta_blks, 0);
232232
if (ret)
233233
goto err;
234234
}

fs/ext4/crypto.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ int ext4_fname_setup_filename(struct inode *dir, const struct qstr *iname,
3333

3434
#if IS_ENABLED(CONFIG_UNICODE)
3535
err = ext4_fname_setup_ci_filename(dir, iname, fname);
36+
if (err)
37+
ext4_fname_free_filename(fname);
3638
#endif
3739
return err;
3840
}
@@ -51,6 +53,8 @@ int ext4_fname_prepare_lookup(struct inode *dir, struct dentry *dentry,
5153

5254
#if IS_ENABLED(CONFIG_UNICODE)
5355
err = ext4_fname_setup_ci_filename(dir, &dentry->d_name, fname);
56+
if (err)
57+
ext4_fname_free_filename(fname);
5458
#endif
5559
return err;
5660
}

fs/ext4/ext4.h

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -176,9 +176,6 @@ enum criteria {
176176
EXT4_MB_NUM_CRS
177177
};
178178

179-
/* criteria below which we use fast block scanning and avoid unnecessary IO */
180-
#define CR_FAST CR_GOAL_LEN_SLOW
181-
182179
/*
183180
* Flags used in mballoc's allocation_context flags field.
184181
*
@@ -1241,6 +1238,7 @@ struct ext4_inode_info {
12411238
#define EXT4_MOUNT2_MB_OPTIMIZE_SCAN 0x00000080 /* Optimize group
12421239
* scanning in mballoc
12431240
*/
1241+
#define EXT4_MOUNT2_ABORT 0x00000100 /* Abort filesystem */
12441242

12451243
#define clear_opt(sb, opt) EXT4_SB(sb)->s_mount_opt &= \
12461244
~EXT4_MOUNT_##opt
@@ -1258,10 +1256,8 @@ struct ext4_inode_info {
12581256

12591257
#define ext4_test_and_set_bit __test_and_set_bit_le
12601258
#define ext4_set_bit __set_bit_le
1261-
#define ext4_set_bit_atomic ext2_set_bit_atomic
12621259
#define ext4_test_and_clear_bit __test_and_clear_bit_le
12631260
#define ext4_clear_bit __clear_bit_le
1264-
#define ext4_clear_bit_atomic ext2_clear_bit_atomic
12651261
#define ext4_test_bit test_bit_le
12661262
#define ext4_find_next_zero_bit find_next_zero_bit_le
12671263
#define ext4_find_next_bit find_next_bit_le
@@ -1708,10 +1704,13 @@ struct ext4_sb_info {
17081704
const char *s_last_error_func;
17091705
time64_t s_last_error_time;
17101706
/*
1711-
* If we are in a context where we cannot update error information in
1712-
* the on-disk superblock, we queue this work to do it.
1707+
* If we are in a context where we cannot update the on-disk
1708+
* superblock, we queue the work here. This is used to update
1709+
* the error information in the superblock, and for periodic
1710+
* updates of the superblock called from the commit callback
1711+
* function.
17131712
*/
1714-
struct work_struct s_error_work;
1713+
struct work_struct s_sb_upd_work;
17151714

17161715
/* Ext4 fast commit sub transaction ID */
17171716
atomic_t s_fc_subtid;
@@ -1804,7 +1803,6 @@ static inline int ext4_valid_inum(struct super_block *sb, unsigned long ino)
18041803
*/
18051804
enum {
18061805
EXT4_MF_MNTDIR_SAMPLED,
1807-
EXT4_MF_FS_ABORTED, /* Fatal error detected */
18081806
EXT4_MF_FC_INELIGIBLE /* Fast commit ineligible */
18091807
};
18101808

@@ -2228,9 +2226,9 @@ extern int ext4_feature_set_ok(struct super_block *sb, int readonly);
22282226
#define EXT4_FLAGS_SHUTDOWN 1
22292227
#define EXT4_FLAGS_BDEV_IS_DAX 2
22302228

2231-
static inline int ext4_forced_shutdown(struct ext4_sb_info *sbi)
2229+
static inline int ext4_forced_shutdown(struct super_block *sb)
22322230
{
2233-
return test_bit(EXT4_FLAGS_SHUTDOWN, &sbi->s_ext4_flags);
2231+
return test_bit(EXT4_FLAGS_SHUTDOWN, &EXT4_SB(sb)->s_ext4_flags);
22342232
}
22352233

22362234
/*
@@ -2708,7 +2706,6 @@ extern ext4_fsblk_t ext4_new_meta_blocks(handle_t *handle, struct inode *inode,
27082706
extern int ext4_claim_free_clusters(struct ext4_sb_info *sbi,
27092707
s64 nclusters, unsigned int flags);
27102708
extern ext4_fsblk_t ext4_count_free_clusters(struct super_block *);
2711-
extern void ext4_check_blocks_bitmap(struct super_block *);
27122709
extern struct ext4_group_desc * ext4_get_group_desc(struct super_block * sb,
27132710
ext4_group_t block_group,
27142711
struct buffer_head ** bh);
@@ -2864,7 +2861,6 @@ extern void ext4_free_inode(handle_t *, struct inode *);
28642861
extern struct inode * ext4_orphan_get(struct super_block *, unsigned long);
28652862
extern unsigned long ext4_count_free_inodes(struct super_block *);
28662863
extern unsigned long ext4_count_dirs(struct super_block *);
2867-
extern void ext4_check_inodes_bitmap(struct super_block *);
28682864
extern void ext4_mark_bitmap_end(int start_bit, int end_bit, char *bitmap);
28692865
extern int ext4_init_inode_table(struct super_block *sb,
28702866
ext4_group_t group, int barrier);
@@ -2907,7 +2903,6 @@ extern int ext4_mb_init(struct super_block *);
29072903
extern int ext4_mb_release(struct super_block *);
29082904
extern ext4_fsblk_t ext4_mb_new_blocks(handle_t *,
29092905
struct ext4_allocation_request *, int *);
2910-
extern int ext4_mb_reserve_blocks(struct super_block *, int);
29112906
extern void ext4_discard_preallocations(struct inode *, unsigned int);
29122907
extern int __init ext4_init_mballoc(void);
29132908
extern void ext4_exit_mballoc(void);
@@ -2930,6 +2925,10 @@ extern int ext4_trim_fs(struct super_block *, struct fstrim_range *);
29302925
extern void ext4_process_freed_data(struct super_block *sb, tid_t commit_tid);
29312926
extern void ext4_mb_mark_bb(struct super_block *sb, ext4_fsblk_t block,
29322927
int len, int state);
2928+
static inline bool ext4_mb_cr_expensive(enum criteria cr)
2929+
{
2930+
return cr >= CR_GOAL_LEN_SLOW;
2931+
}
29332932

29342933
/* inode.c */
29352934
void ext4_inode_csum_set(struct inode *inode, struct ext4_inode *raw,
@@ -2983,7 +2982,6 @@ extern void ext4_evict_inode(struct inode *);
29832982
extern void ext4_clear_inode(struct inode *);
29842983
extern int ext4_file_getattr(struct mnt_idmap *, const struct path *,
29852984
struct kstat *, u32, unsigned int);
2986-
extern int ext4_sync_inode(handle_t *, struct inode *);
29872985
extern void ext4_dirty_inode(struct inode *, int);
29882986
extern int ext4_change_inode_journal_flag(struct inode *, int);
29892987
extern int ext4_get_inode_loc(struct inode *, struct ext4_iloc *);
@@ -3090,6 +3088,8 @@ extern const char *ext4_decode_error(struct super_block *sb, int errno,
30903088
extern void ext4_mark_group_bitmap_corrupted(struct super_block *sb,
30913089
ext4_group_t block_group,
30923090
unsigned int flags);
3091+
extern unsigned int ext4_num_base_meta_blocks(struct super_block *sb,
3092+
ext4_group_t block_group);
30933093

30943094
extern __printf(7, 8)
30953095
void __ext4_error(struct super_block *, const char *, unsigned int, bool,
@@ -3531,8 +3531,6 @@ extern loff_t ext4_llseek(struct file *file, loff_t offset, int origin);
35313531
/* inline.c */
35323532
extern int ext4_get_max_inline_size(struct inode *inode);
35333533
extern int ext4_find_inline_data_nolock(struct inode *inode);
3534-
extern int ext4_init_inline_data(handle_t *handle, struct inode *inode,
3535-
unsigned int len);
35363534
extern int ext4_destroy_inline_data(handle_t *handle, struct inode *inode);
35373535

35383536
int ext4_readpage_inline(struct inode *inode, struct folio *folio);

fs/ext4/ext4_jbd2.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,12 @@ static int ext4_journal_check_start(struct super_block *sb)
6767

6868
might_sleep();
6969

70-
if (unlikely(ext4_forced_shutdown(EXT4_SB(sb))))
70+
if (unlikely(ext4_forced_shutdown(sb)))
7171
return -EIO;
7272

73-
if (sb_rdonly(sb))
73+
if (WARN_ON_ONCE(sb_rdonly(sb)))
7474
return -EROFS;
75+
7576
WARN_ON(sb->s_writers.frozen == SB_FREEZE_COMPLETE);
7677
journal = EXT4_SB(sb)->s_journal;
7778
/*

fs/ext4/extents_status.c

Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -878,23 +878,29 @@ void ext4_es_insert_extent(struct inode *inode, ext4_lblk_t lblk,
878878
err1 = __es_remove_extent(inode, lblk, end, NULL, es1);
879879
if (err1 != 0)
880880
goto error;
881+
/* Free preallocated extent if it didn't get used. */
882+
if (es1) {
883+
if (!es1->es_len)
884+
__es_free_extent(es1);
885+
es1 = NULL;
886+
}
881887

882888
err2 = __es_insert_extent(inode, &newes, es2);
883889
if (err2 == -ENOMEM && !ext4_es_must_keep(&newes))
884890
err2 = 0;
885891
if (err2 != 0)
886892
goto error;
893+
/* Free preallocated extent if it didn't get used. */
894+
if (es2) {
895+
if (!es2->es_len)
896+
__es_free_extent(es2);
897+
es2 = NULL;
898+
}
887899

888900
if (sbi->s_cluster_ratio > 1 && test_opt(inode->i_sb, DELALLOC) &&
889901
(status & EXTENT_STATUS_WRITTEN ||
890902
status & EXTENT_STATUS_UNWRITTEN))
891903
__revise_pending(inode, lblk, len);
892-
893-
/* es is pre-allocated but not used, free it. */
894-
if (es1 && !es1->es_len)
895-
__es_free_extent(es1);
896-
if (es2 && !es2->es_len)
897-
__es_free_extent(es2);
898904
error:
899905
write_unlock(&EXT4_I(inode)->i_es_lock);
900906
if (err1 || err2)
@@ -1491,8 +1497,12 @@ void ext4_es_remove_extent(struct inode *inode, ext4_lblk_t lblk,
14911497
*/
14921498
write_lock(&EXT4_I(inode)->i_es_lock);
14931499
err = __es_remove_extent(inode, lblk, end, &reserved, es);
1494-
if (es && !es->es_len)
1495-
__es_free_extent(es);
1500+
/* Free preallocated extent if it didn't get used. */
1501+
if (es) {
1502+
if (!es->es_len)
1503+
__es_free_extent(es);
1504+
es = NULL;
1505+
}
14961506
write_unlock(&EXT4_I(inode)->i_es_lock);
14971507
if (err)
14981508
goto retry;
@@ -2047,19 +2057,25 @@ void ext4_es_insert_delayed_block(struct inode *inode, ext4_lblk_t lblk,
20472057
err1 = __es_remove_extent(inode, lblk, lblk, NULL, es1);
20482058
if (err1 != 0)
20492059
goto error;
2060+
/* Free preallocated extent if it didn't get used. */
2061+
if (es1) {
2062+
if (!es1->es_len)
2063+
__es_free_extent(es1);
2064+
es1 = NULL;
2065+
}
20502066

20512067
err2 = __es_insert_extent(inode, &newes, es2);
20522068
if (err2 != 0)
20532069
goto error;
2070+
/* Free preallocated extent if it didn't get used. */
2071+
if (es2) {
2072+
if (!es2->es_len)
2073+
__es_free_extent(es2);
2074+
es2 = NULL;
2075+
}
20542076

20552077
if (allocated)
20562078
__insert_pending(inode, lblk);
2057-
2058-
/* es is pre-allocated but not used, free it. */
2059-
if (es1 && !es1->es_len)
2060-
__es_free_extent(es1);
2061-
if (es2 && !es2->es_len)
2062-
__es_free_extent(es2);
20632079
error:
20642080
write_unlock(&EXT4_I(inode)->i_es_lock);
20652081
if (err1 || err2)

fs/ext4/file.c

Lines changed: 16 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ static ssize_t ext4_file_read_iter(struct kiocb *iocb, struct iov_iter *to)
131131
{
132132
struct inode *inode = file_inode(iocb->ki_filp);
133133

134-
if (unlikely(ext4_forced_shutdown(EXT4_SB(inode->i_sb))))
134+
if (unlikely(ext4_forced_shutdown(inode->i_sb)))
135135
return -EIO;
136136

137137
if (!iov_iter_count(to))
@@ -153,7 +153,7 @@ static ssize_t ext4_file_splice_read(struct file *in, loff_t *ppos,
153153
{
154154
struct inode *inode = file_inode(in);
155155

156-
if (unlikely(ext4_forced_shutdown(EXT4_SB(inode->i_sb))))
156+
if (unlikely(ext4_forced_shutdown(inode->i_sb)))
157157
return -EIO;
158158
return filemap_splice_read(in, ppos, pipe, len, flags);
159159
}
@@ -476,6 +476,11 @@ static ssize_t ext4_dio_write_checks(struct kiocb *iocb, struct iov_iter *from,
476476
* required to change security info in file_modified(), for extending
477477
* I/O, any form of non-overwrite I/O, and unaligned I/O to unwritten
478478
* extents (as partial block zeroing may be required).
479+
*
480+
* Note that unaligned writes are allowed under shared lock so long as
481+
* they are pure overwrites. Otherwise, concurrent unaligned writes risk
482+
* data corruption due to partial block zeroing in the dio layer, and so
483+
* the I/O must occur exclusively.
479484
*/
480485
if (*ilock_shared &&
481486
((!IS_NOSEC(inode) || *extend || !overwrite ||
@@ -492,21 +497,12 @@ static ssize_t ext4_dio_write_checks(struct kiocb *iocb, struct iov_iter *from,
492497

493498
/*
494499
* Now that locking is settled, determine dio flags and exclusivity
495-
* requirements. Unaligned writes are allowed under shared lock so long
496-
* as they are pure overwrites. Set the iomap overwrite only flag as an
497-
* added precaution in this case. Even though this is unnecessary, we
498-
* can detect and warn on unexpected -EAGAIN if an unsafe unaligned
499-
* write is ever submitted.
500-
*
501-
* Otherwise, concurrent unaligned writes risk data corruption due to
502-
* partial block zeroing in the dio layer, and so the I/O must occur
503-
* exclusively. The inode lock is already held exclusive if the write is
504-
* non-overwrite or extending, so drain all outstanding dio and set the
505-
* force wait dio flag.
500+
* requirements. We don't use DIO_OVERWRITE_ONLY because we enforce
501+
* behavior already. The inode lock is already held exclusive if the
502+
* write is non-overwrite or extending, so drain all outstanding dio and
503+
* set the force wait dio flag.
506504
*/
507-
if (*ilock_shared && unaligned_io) {
508-
*dio_flags = IOMAP_DIO_OVERWRITE_ONLY;
509-
} else if (!*ilock_shared && (unaligned_io || *extend)) {
505+
if (!*ilock_shared && (unaligned_io || *extend)) {
510506
if (iocb->ki_flags & IOCB_NOWAIT) {
511507
ret = -EAGAIN;
512508
goto out;
@@ -608,7 +604,6 @@ static ssize_t ext4_dio_write_iter(struct kiocb *iocb, struct iov_iter *from)
608604
iomap_ops = &ext4_iomap_overwrite_ops;
609605
ret = iomap_dio_rw(iocb, from, iomap_ops, &ext4_dio_write_ops,
610606
dio_flags, NULL, 0);
611-
WARN_ON_ONCE(ret == -EAGAIN && !(iocb->ki_flags & IOCB_NOWAIT));
612607
if (ret == -ENOTBLK)
613608
ret = 0;
614609

@@ -709,7 +704,7 @@ ext4_file_write_iter(struct kiocb *iocb, struct iov_iter *from)
709704
{
710705
struct inode *inode = file_inode(iocb->ki_filp);
711706

712-
if (unlikely(ext4_forced_shutdown(EXT4_SB(inode->i_sb))))
707+
if (unlikely(ext4_forced_shutdown(inode->i_sb)))
713708
return -EIO;
714709

715710
#ifdef CONFIG_FS_DAX
@@ -806,10 +801,9 @@ static const struct vm_operations_struct ext4_file_vm_ops = {
806801
static int ext4_file_mmap(struct file *file, struct vm_area_struct *vma)
807802
{
808803
struct inode *inode = file->f_mapping->host;
809-
struct ext4_sb_info *sbi = EXT4_SB(inode->i_sb);
810-
struct dax_device *dax_dev = sbi->s_daxdev;
804+
struct dax_device *dax_dev = EXT4_SB(inode->i_sb)->s_daxdev;
811805

812-
if (unlikely(ext4_forced_shutdown(sbi)))
806+
if (unlikely(ext4_forced_shutdown(inode->i_sb)))
813807
return -EIO;
814808

815809
/*
@@ -885,7 +879,7 @@ static int ext4_file_open(struct inode *inode, struct file *filp)
885879
{
886880
int ret;
887881

888-
if (unlikely(ext4_forced_shutdown(EXT4_SB(inode->i_sb))))
882+
if (unlikely(ext4_forced_shutdown(inode->i_sb)))
889883
return -EIO;
890884

891885
ret = ext4_sample_last_mounted(inode->i_sb, filp->f_path.mnt);

0 commit comments

Comments
 (0)