Skip to content

Commit d723b99

Browse files
committed
Merge tag 'ext4_for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tytso/ext4
Pull ext4 updates from Ted Ts'o: "Improvements to ext4's block allocator performance for very large file systems, especially when the file system or files which are highly fragmented. There is a new mount option, prefetch_block_bitmaps which will pull in the block bitmaps and set up the in-memory buddy bitmaps when the file system is initially mounted. Beyond that, a lot of bug fixes and cleanups. In particular, a number of changes to make ext4 more robust in the face of write errors or file system corruptions" * tag 'ext4_for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tytso/ext4: (46 commits) ext4: limit the length of per-inode prealloc list ext4: reorganize if statement of ext4_mb_release_context() ext4: add mb_debug logging when there are lost chunks ext4: Fix comment typo "the the". jbd2: clean up checksum verification in do_one_pass() ext4: change to use fallthrough macro ext4: remove unused parameter of ext4_generic_delete_entry function mballoc: replace seq_printf with seq_puts ext4: optimize the implementation of ext4_mb_good_group() ext4: delete invalid comments near ext4_mb_check_limits() ext4: fix typos in ext4_mb_regular_allocator() comment ext4: fix checking of directory entry validity for inline directories fs: prevent BUG_ON in submit_bh_wbc() ext4: correctly restore system zone info when remount fails ext4: handle add_system_zone() failure in ext4_setup_system_zone() ext4: fold ext4_data_block_valid_rcu() into the caller ext4: check journal inode extents more carefully ext4: don't allow overlapping system zones ext4: handle error of ext4_setup_system_zone() on remount ext4: delete the invalid BUGON in ext4_mb_load_buddy_gfp() ...
2 parents 5e0b17b + 27bc446 commit d723b99

File tree

28 files changed

+881
-424
lines changed

28 files changed

+881
-424
lines changed

Documentation/admin-guide/ext4.rst

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -489,6 +489,9 @@ Files in /sys/fs/ext4/<devname>:
489489
multiple of this tuning parameter if the stripe size is not set in the
490490
ext4 superblock
491491

492+
mb_max_inode_prealloc
493+
The maximum length of per-inode ext4_prealloc_space list.
494+
492495
mb_max_to_scan
493496
The maximum number of extents the multiblock allocator will search to
494497
find the best extent.
@@ -529,21 +532,21 @@ Files in /sys/fs/ext4/<devname>:
529532
Ioctls
530533
======
531534

532-
There is some Ext4 specific functionality which can be accessed by applications
533-
through the system call interfaces. The list of all Ext4 specific ioctls are
534-
shown in the table below.
535+
Ext4 implements various ioctls which can be used by applications to access
536+
ext4-specific functionality. An incomplete list of these ioctls is shown in the
537+
table below. This list includes truly ext4-specific ioctls (``EXT4_IOC_*``) as
538+
well as ioctls that may have been ext4-specific originally but are now supported
539+
by some other filesystem(s) too (``FS_IOC_*``).
535540

536-
Table of Ext4 specific ioctls
541+
Table of Ext4 ioctls
537542

538-
EXT4_IOC_GETFLAGS
543+
FS_IOC_GETFLAGS
539544
Get additional attributes associated with inode. The ioctl argument is
540-
an integer bitfield, with bit values described in ext4.h. This ioctl is
541-
an alias for FS_IOC_GETFLAGS.
545+
an integer bitfield, with bit values described in ext4.h.
542546

543-
EXT4_IOC_SETFLAGS
547+
FS_IOC_SETFLAGS
544548
Set additional attributes associated with inode. The ioctl argument is
545-
an integer bitfield, with bit values described in ext4.h. This ioctl is
546-
an alias for FS_IOC_SETFLAGS.
549+
an integer bitfield, with bit values described in ext4.h.
547550

548551
EXT4_IOC_GETVERSION, EXT4_IOC_GETVERSION_OLD
549552
Get the inode i_generation number stored for each inode. The

Documentation/filesystems/ext4/about.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,6 @@ entry.
3939
Other References
4040
----------------
4141

42-
Also see http://www.nongnu.org/ext2-doc/ for quite a collection of
42+
Also see https://www.nongnu.org/ext2-doc/ for quite a collection of
4343
information about ext2/3. Here's another old reference:
4444
http://wiki.osdev.org/Ext2

fs/buffer.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3157,6 +3157,15 @@ int __sync_dirty_buffer(struct buffer_head *bh, int op_flags)
31573157
WARN_ON(atomic_read(&bh->b_count) < 1);
31583158
lock_buffer(bh);
31593159
if (test_clear_buffer_dirty(bh)) {
3160+
/*
3161+
* The bh should be mapped, but it might not be if the
3162+
* device was hot-removed. Not much we can do but fail the I/O.
3163+
*/
3164+
if (!buffer_mapped(bh)) {
3165+
unlock_buffer(bh);
3166+
return -EIO;
3167+
}
3168+
31603169
get_bh(bh);
31613170
bh->b_end_io = end_buffer_write_sync;
31623171
ret = submit_bh(REQ_OP_WRITE, op_flags, bh);

fs/ext4/Kconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ config EXT4_KUNIT_TESTS
110110
This builds the ext4 KUnit tests.
111111

112112
KUnit tests run during boot and output the results to the debug log
113-
in TAP format (http://testanything.org/). Only useful for kernel devs
113+
in TAP format (https://testanything.org/). Only useful for kernel devs
114114
running KUnit test harness and are not for inclusion into a production
115115
build.
116116

fs/ext4/balloc.c

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,8 @@ static int ext4_validate_block_bitmap(struct super_block *sb,
413413
* Return buffer_head on success or an ERR_PTR in case of failure.
414414
*/
415415
struct buffer_head *
416-
ext4_read_block_bitmap_nowait(struct super_block *sb, ext4_group_t block_group)
416+
ext4_read_block_bitmap_nowait(struct super_block *sb, ext4_group_t block_group,
417+
bool ignore_locked)
417418
{
418419
struct ext4_group_desc *desc;
419420
struct ext4_sb_info *sbi = EXT4_SB(sb);
@@ -441,6 +442,12 @@ ext4_read_block_bitmap_nowait(struct super_block *sb, ext4_group_t block_group)
441442
return ERR_PTR(-ENOMEM);
442443
}
443444

445+
if (ignore_locked && buffer_locked(bh)) {
446+
/* buffer under IO already, return if called for prefetching */
447+
put_bh(bh);
448+
return NULL;
449+
}
450+
444451
if (bitmap_uptodate(bh))
445452
goto verify;
446453

@@ -487,10 +494,11 @@ ext4_read_block_bitmap_nowait(struct super_block *sb, ext4_group_t block_group)
487494
* submit the buffer_head for reading
488495
*/
489496
set_buffer_new(bh);
490-
trace_ext4_read_block_bitmap_load(sb, block_group);
497+
trace_ext4_read_block_bitmap_load(sb, block_group, ignore_locked);
491498
bh->b_end_io = ext4_end_bitmap_read;
492499
get_bh(bh);
493-
submit_bh(REQ_OP_READ, REQ_META | REQ_PRIO, bh);
500+
submit_bh(REQ_OP_READ, REQ_META | REQ_PRIO |
501+
(ignore_locked ? REQ_RAHEAD : 0), bh);
494502
return bh;
495503
verify:
496504
err = ext4_validate_block_bitmap(sb, desc, block_group, bh);
@@ -534,7 +542,7 @@ ext4_read_block_bitmap(struct super_block *sb, ext4_group_t block_group)
534542
struct buffer_head *bh;
535543
int err;
536544

537-
bh = ext4_read_block_bitmap_nowait(sb, block_group);
545+
bh = ext4_read_block_bitmap_nowait(sb, block_group, false);
538546
if (IS_ERR(bh))
539547
return bh;
540548
err = ext4_wait_block_bitmap(sb, block_group, bh);

fs/ext4/block_validity.c

Lines changed: 69 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ struct ext4_system_zone {
2424
struct rb_node node;
2525
ext4_fsblk_t start_blk;
2626
unsigned int count;
27+
u32 ino;
2728
};
2829

2930
static struct kmem_cache *ext4_system_zone_cachep;
@@ -45,7 +46,8 @@ void ext4_exit_system_zone(void)
4546
static inline int can_merge(struct ext4_system_zone *entry1,
4647
struct ext4_system_zone *entry2)
4748
{
48-
if ((entry1->start_blk + entry1->count) == entry2->start_blk)
49+
if ((entry1->start_blk + entry1->count) == entry2->start_blk &&
50+
entry1->ino == entry2->ino)
4951
return 1;
5052
return 0;
5153
}
@@ -66,9 +68,9 @@ static void release_system_zone(struct ext4_system_blocks *system_blks)
6668
*/
6769
static int add_system_zone(struct ext4_system_blocks *system_blks,
6870
ext4_fsblk_t start_blk,
69-
unsigned int count)
71+
unsigned int count, u32 ino)
7072
{
71-
struct ext4_system_zone *new_entry = NULL, *entry;
73+
struct ext4_system_zone *new_entry, *entry;
7274
struct rb_node **n = &system_blks->root.rb_node, *node;
7375
struct rb_node *parent = NULL, *new_node = NULL;
7476

@@ -79,30 +81,21 @@ static int add_system_zone(struct ext4_system_blocks *system_blks,
7981
n = &(*n)->rb_left;
8082
else if (start_blk >= (entry->start_blk + entry->count))
8183
n = &(*n)->rb_right;
82-
else {
83-
if (start_blk + count > (entry->start_blk +
84-
entry->count))
85-
entry->count = (start_blk + count -
86-
entry->start_blk);
87-
new_node = *n;
88-
new_entry = rb_entry(new_node, struct ext4_system_zone,
89-
node);
90-
break;
91-
}
84+
else /* Unexpected overlap of system zones. */
85+
return -EFSCORRUPTED;
9286
}
9387

94-
if (!new_entry) {
95-
new_entry = kmem_cache_alloc(ext4_system_zone_cachep,
96-
GFP_KERNEL);
97-
if (!new_entry)
98-
return -ENOMEM;
99-
new_entry->start_blk = start_blk;
100-
new_entry->count = count;
101-
new_node = &new_entry->node;
102-
103-
rb_link_node(new_node, parent, n);
104-
rb_insert_color(new_node, &system_blks->root);
105-
}
88+
new_entry = kmem_cache_alloc(ext4_system_zone_cachep,
89+
GFP_KERNEL);
90+
if (!new_entry)
91+
return -ENOMEM;
92+
new_entry->start_blk = start_blk;
93+
new_entry->count = count;
94+
new_entry->ino = ino;
95+
new_node = &new_entry->node;
96+
97+
rb_link_node(new_node, parent, n);
98+
rb_insert_color(new_node, &system_blks->root);
10699

107100
/* Can we merge to the left? */
108101
node = rb_prev(new_node);
@@ -151,40 +144,6 @@ static void debug_print_tree(struct ext4_sb_info *sbi)
151144
printk(KERN_CONT "\n");
152145
}
153146

154-
/*
155-
* Returns 1 if the passed-in block region (start_blk,
156-
* start_blk+count) is valid; 0 if some part of the block region
157-
* overlaps with filesystem metadata blocks.
158-
*/
159-
static int ext4_data_block_valid_rcu(struct ext4_sb_info *sbi,
160-
struct ext4_system_blocks *system_blks,
161-
ext4_fsblk_t start_blk,
162-
unsigned int count)
163-
{
164-
struct ext4_system_zone *entry;
165-
struct rb_node *n;
166-
167-
if ((start_blk <= le32_to_cpu(sbi->s_es->s_first_data_block)) ||
168-
(start_blk + count < start_blk) ||
169-
(start_blk + count > ext4_blocks_count(sbi->s_es)))
170-
return 0;
171-
172-
if (system_blks == NULL)
173-
return 1;
174-
175-
n = system_blks->root.rb_node;
176-
while (n) {
177-
entry = rb_entry(n, struct ext4_system_zone, node);
178-
if (start_blk + count - 1 < entry->start_blk)
179-
n = n->rb_left;
180-
else if (start_blk >= (entry->start_blk + entry->count))
181-
n = n->rb_right;
182-
else
183-
return 0;
184-
}
185-
return 1;
186-
}
187-
188147
static int ext4_protect_reserved_inode(struct super_block *sb,
189148
struct ext4_system_blocks *system_blks,
190149
u32 ino)
@@ -214,19 +173,18 @@ static int ext4_protect_reserved_inode(struct super_block *sb,
214173
if (n == 0) {
215174
i++;
216175
} else {
217-
if (!ext4_data_block_valid_rcu(sbi, system_blks,
218-
map.m_pblk, n)) {
219-
err = -EFSCORRUPTED;
220-
__ext4_error(sb, __func__, __LINE__, -err,
221-
map.m_pblk, "blocks %llu-%llu "
222-
"from inode %u overlap system zone",
223-
map.m_pblk,
224-
map.m_pblk + map.m_len - 1, ino);
176+
err = add_system_zone(system_blks, map.m_pblk, n, ino);
177+
if (err < 0) {
178+
if (err == -EFSCORRUPTED) {
179+
__ext4_error(sb, __func__, __LINE__,
180+
-err, map.m_pblk,
181+
"blocks %llu-%llu from inode %u overlap system zone",
182+
map.m_pblk,
183+
map.m_pblk + map.m_len - 1,
184+
ino);
185+
}
225186
break;
226187
}
227-
err = add_system_zone(system_blks, map.m_pblk, n);
228-
if (err < 0)
229-
break;
230188
i += n;
231189
}
232190
}
@@ -262,37 +220,32 @@ int ext4_setup_system_zone(struct super_block *sb)
262220
int flex_size = ext4_flex_bg_size(sbi);
263221
int ret;
264222

265-
if (!test_opt(sb, BLOCK_VALIDITY)) {
266-
if (sbi->system_blks)
267-
ext4_release_system_zone(sb);
268-
return 0;
269-
}
270-
if (sbi->system_blks)
271-
return 0;
272-
273223
system_blks = kzalloc(sizeof(*system_blks), GFP_KERNEL);
274224
if (!system_blks)
275225
return -ENOMEM;
276226

277227
for (i=0; i < ngroups; i++) {
278228
cond_resched();
279229
if (ext4_bg_has_super(sb, i) &&
280-
((i < 5) || ((i % flex_size) == 0)))
281-
add_system_zone(system_blks,
230+
((i < 5) || ((i % flex_size) == 0))) {
231+
ret = add_system_zone(system_blks,
282232
ext4_group_first_block_no(sb, i),
283-
ext4_bg_num_gdb(sb, i) + 1);
233+
ext4_bg_num_gdb(sb, i) + 1, 0);
234+
if (ret)
235+
goto err;
236+
}
284237
gdp = ext4_get_group_desc(sb, i, NULL);
285238
ret = add_system_zone(system_blks,
286-
ext4_block_bitmap(sb, gdp), 1);
239+
ext4_block_bitmap(sb, gdp), 1, 0);
287240
if (ret)
288241
goto err;
289242
ret = add_system_zone(system_blks,
290-
ext4_inode_bitmap(sb, gdp), 1);
243+
ext4_inode_bitmap(sb, gdp), 1, 0);
291244
if (ret)
292245
goto err;
293246
ret = add_system_zone(system_blks,
294247
ext4_inode_table(sb, gdp),
295-
sbi->s_itb_per_group);
248+
sbi->s_itb_per_group, 0);
296249
if (ret)
297250
goto err;
298251
}
@@ -341,11 +294,24 @@ void ext4_release_system_zone(struct super_block *sb)
341294
call_rcu(&system_blks->rcu, ext4_destroy_system_zone);
342295
}
343296

344-
int ext4_data_block_valid(struct ext4_sb_info *sbi, ext4_fsblk_t start_blk,
297+
/*
298+
* Returns 1 if the passed-in block region (start_blk,
299+
* start_blk+count) is valid; 0 if some part of the block region
300+
* overlaps with some other filesystem metadata blocks.
301+
*/
302+
int ext4_inode_block_valid(struct inode *inode, ext4_fsblk_t start_blk,
345303
unsigned int count)
346304
{
305+
struct ext4_sb_info *sbi = EXT4_SB(inode->i_sb);
347306
struct ext4_system_blocks *system_blks;
348-
int ret;
307+
struct ext4_system_zone *entry;
308+
struct rb_node *n;
309+
int ret = 1;
310+
311+
if ((start_blk <= le32_to_cpu(sbi->s_es->s_first_data_block)) ||
312+
(start_blk + count < start_blk) ||
313+
(start_blk + count > ext4_blocks_count(sbi->s_es)))
314+
return 0;
349315

350316
/*
351317
* Lock the system zone to prevent it being released concurrently
@@ -354,8 +320,22 @@ int ext4_data_block_valid(struct ext4_sb_info *sbi, ext4_fsblk_t start_blk,
354320
*/
355321
rcu_read_lock();
356322
system_blks = rcu_dereference(sbi->system_blks);
357-
ret = ext4_data_block_valid_rcu(sbi, system_blks, start_blk,
358-
count);
323+
if (system_blks == NULL)
324+
goto out_rcu;
325+
326+
n = system_blks->root.rb_node;
327+
while (n) {
328+
entry = rb_entry(n, struct ext4_system_zone, node);
329+
if (start_blk + count - 1 < entry->start_blk)
330+
n = n->rb_left;
331+
else if (start_blk >= (entry->start_blk + entry->count))
332+
n = n->rb_right;
333+
else {
334+
ret = (entry->ino == inode->i_ino);
335+
break;
336+
}
337+
}
338+
out_rcu:
359339
rcu_read_unlock();
360340
return ret;
361341
}
@@ -374,8 +354,7 @@ int ext4_check_blockref(const char *function, unsigned int line,
374354
while (bref < p+max) {
375355
blk = le32_to_cpu(*bref++);
376356
if (blk &&
377-
unlikely(!ext4_data_block_valid(EXT4_SB(inode->i_sb),
378-
blk, 1))) {
357+
unlikely(!ext4_inode_block_valid(inode, blk, 1))) {
379358
ext4_error_inode(inode, function, line, blk,
380359
"invalid block");
381360
return -EFSCORRUPTED;

0 commit comments

Comments
 (0)