Skip to content

Commit e5da4c9

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: "This merge window, we've added some performance improvements in how we handle inode locking in the read/write paths, and improving the performance of Direct I/O overwrites. We also now record the error code which caused the first and most recent ext4_error() report in the superblock, to make it easier to root cause problems in production systems. There are also many of the usual cleanups and miscellaneous bug fixes" * tag 'ext4_for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tytso/ext4: (49 commits) jbd2: clean __jbd2_journal_abort_hard() and __journal_abort_soft() jbd2: make sure ESHUTDOWN to be recorded in the journal superblock ext4, jbd2: ensure panic when aborting with zero errno jbd2: switch to use jbd2_journal_abort() when failed to submit the commit record jbd2_seq_info_next should increase position index jbd2: remove pointless assertion in __journal_remove_journal_head ext4,jbd2: fix comment and code style jbd2: delete the duplicated words in the comments ext4: fix extent_status trace points ext4: fix symbolic enum printing in trace output ext4: choose hardlimit when softlimit is larger than hardlimit in ext4_statfs_project() ext4: fix race conditions in ->d_compare() and ->d_hash() ext4: make dioread_nolock the default ext4: fix extent_status fragmentation for plain files jbd2: clear JBD2_ABORT flag before journal_reset to update log tail info when load journal ext4: drop ext4_kvmalloc() ext4: Add EXT4_IOC_FSGETXATTR/EXT4_IOC_FSSETXATTR to compat_ioctl ext4: remove unused macro MPAGE_DA_EXTENT_TAIL ext4: add missing braces in ext4_ext_drop_refs() ext4: fix some nonstandard indentation in extents.c ...
2 parents 9f68e36 + 7f6225e commit e5da4c9

32 files changed

+709
-432
lines changed

Documentation/admin-guide/ext4.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,8 @@ Currently Available
9292
* efficient new ordered mode in JBD2 and ext4 (avoid using buffer head to force
9393
the ordering)
9494
* Case-insensitive file name lookups
95+
* file-based encryption support (fscrypt)
96+
* file-based verity support (fsverity)
9597

9698
[1] Filesystems with a block size of 1k may see a limit imposed by the
9799
directory hash tree having a maximum depth of two.

Documentation/filesystems/fscrypt.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1016,9 +1016,9 @@ astute users may notice some differences in behavior:
10161016
- Direct I/O is not supported on encrypted files. Attempts to use
10171017
direct I/O on such files will fall back to buffered I/O.
10181018

1019-
- The fallocate operations FALLOC_FL_COLLAPSE_RANGE,
1020-
FALLOC_FL_INSERT_RANGE, and FALLOC_FL_ZERO_RANGE are not supported
1021-
on encrypted files and will fail with EOPNOTSUPP.
1019+
- The fallocate operations FALLOC_FL_COLLAPSE_RANGE and
1020+
FALLOC_FL_INSERT_RANGE are not supported on encrypted files and will
1021+
fail with EOPNOTSUPP.
10221022

10231023
- Online defragmentation of encrypted files is not supported. The
10241024
EXT4_IOC_MOVE_EXT and F2FS_IOC_MOVE_RANGE ioctls will fail with

fs/ext4/Kconfig

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,7 @@
44
# kernels after the removal of ext3 driver.
55
config EXT3_FS
66
tristate "The Extended 3 (ext3) filesystem"
7-
# These must match EXT4_FS selects...
87
select EXT4_FS
9-
select JBD2
10-
select CRC16
11-
select CRYPTO
12-
select CRYPTO_CRC32C
138
help
149
This config option is here only for backward compatibility. ext3
1510
filesystem is now handled by the ext4 driver.
@@ -33,7 +28,6 @@ config EXT3_FS_SECURITY
3328

3429
config EXT4_FS
3530
tristate "The Extended 4 (ext4) filesystem"
36-
# Please update EXT3_FS selects when changing these
3731
select JBD2
3832
select CRC16
3933
select CRYPTO

fs/ext4/balloc.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,8 @@ static int ext4_validate_block_bitmap(struct super_block *sb,
371371
if (buffer_verified(bh))
372372
goto verified;
373373
if (unlikely(!ext4_block_bitmap_csum_verify(sb, block_group,
374-
desc, bh))) {
374+
desc, bh) ||
375+
ext4_simulate_fail(sb, EXT4_SIM_BBITMAP_CRC))) {
375376
ext4_unlock_group(sb, block_group);
376377
ext4_error(sb, "bg %u: bad block bitmap checksum", block_group);
377378
ext4_mark_group_bitmap_corrupted(sb, block_group,
@@ -505,7 +506,9 @@ int ext4_wait_block_bitmap(struct super_block *sb, ext4_group_t block_group,
505506
if (!desc)
506507
return -EFSCORRUPTED;
507508
wait_on_buffer(bh);
509+
ext4_simulate_fail_bh(sb, bh, EXT4_SIM_BBITMAP_EIO);
508510
if (!buffer_uptodate(bh)) {
511+
ext4_set_errno(sb, EIO);
509512
ext4_error(sb, "Cannot read block bitmap - "
510513
"block_group = %u, block_bitmap = %llu",
511514
block_group, (unsigned long long) bh->b_blocknr);

fs/ext4/dir.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -462,7 +462,6 @@ int ext4_htree_store_dirent(struct file *dir_file, __u32 hash,
462462
new_fn->name_len = ent_name->len;
463463
new_fn->file_type = dirent->file_type;
464464
memcpy(new_fn->name, ent_name->name, ent_name->len);
465-
new_fn->name[ent_name->len] = 0;
466465

467466
while (*p) {
468467
parent = *p;
@@ -672,9 +671,11 @@ static int ext4_d_compare(const struct dentry *dentry, unsigned int len,
672671
const char *str, const struct qstr *name)
673672
{
674673
struct qstr qstr = {.name = str, .len = len };
675-
struct inode *inode = dentry->d_parent->d_inode;
674+
const struct dentry *parent = READ_ONCE(dentry->d_parent);
675+
const struct inode *inode = READ_ONCE(parent->d_inode);
676676

677-
if (!IS_CASEFOLDED(inode) || !EXT4_SB(inode->i_sb)->s_encoding) {
677+
if (!inode || !IS_CASEFOLDED(inode) ||
678+
!EXT4_SB(inode->i_sb)->s_encoding) {
678679
if (len != name->len)
679680
return -1;
680681
return memcmp(str, name->name, len);
@@ -687,10 +688,11 @@ static int ext4_d_hash(const struct dentry *dentry, struct qstr *str)
687688
{
688689
const struct ext4_sb_info *sbi = EXT4_SB(dentry->d_sb);
689690
const struct unicode_map *um = sbi->s_encoding;
691+
const struct inode *inode = READ_ONCE(dentry->d_inode);
690692
unsigned char *norm;
691693
int len, ret = 0;
692694

693-
if (!IS_CASEFOLDED(dentry->d_inode) || !um)
695+
if (!inode || !IS_CASEFOLDED(inode) || !um)
694696
return 0;
695697

696698
norm = kmalloc(PATH_MAX, GFP_ATOMIC);

fs/ext4/ext4.h

Lines changed: 67 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1052,8 +1052,6 @@ struct ext4_inode_info {
10521052
/* allocation reservation info for delalloc */
10531053
/* In case of bigalloc, this refer to clusters rather than blocks */
10541054
unsigned int i_reserved_data_blocks;
1055-
ext4_lblk_t i_da_metadata_calc_last_lblock;
1056-
int i_da_metadata_calc_len;
10571055

10581056
/* pending cluster reservations for bigalloc file systems */
10591057
struct ext4_pending_tree i_pending_tree;
@@ -1343,7 +1341,8 @@ struct ext4_super_block {
13431341
__u8 s_lastcheck_hi;
13441342
__u8 s_first_error_time_hi;
13451343
__u8 s_last_error_time_hi;
1346-
__u8 s_pad[2];
1344+
__u8 s_first_error_errcode;
1345+
__u8 s_last_error_errcode;
13471346
__le16 s_encoding; /* Filename charset encoding */
13481347
__le16 s_encoding_flags; /* Filename charset encoding flags */
13491348
__le32 s_reserved[95]; /* Padding to the end of the block */
@@ -1556,6 +1555,9 @@ struct ext4_sb_info {
15561555
/* Barrier between changing inodes' journal flags and writepages ops. */
15571556
struct percpu_rw_semaphore s_journal_flag_rwsem;
15581557
struct dax_device *s_daxdev;
1558+
#ifdef CONFIG_EXT4_DEBUG
1559+
unsigned long s_simulate_fail;
1560+
#endif
15591561
};
15601562

15611563
static inline struct ext4_sb_info *EXT4_SB(struct super_block *sb)
@@ -1574,6 +1576,66 @@ static inline int ext4_valid_inum(struct super_block *sb, unsigned long ino)
15741576
ino <= le32_to_cpu(EXT4_SB(sb)->s_es->s_inodes_count));
15751577
}
15761578

1579+
/*
1580+
* Simulate_fail codes
1581+
*/
1582+
#define EXT4_SIM_BBITMAP_EIO 1
1583+
#define EXT4_SIM_BBITMAP_CRC 2
1584+
#define EXT4_SIM_IBITMAP_EIO 3
1585+
#define EXT4_SIM_IBITMAP_CRC 4
1586+
#define EXT4_SIM_INODE_EIO 5
1587+
#define EXT4_SIM_INODE_CRC 6
1588+
#define EXT4_SIM_DIRBLOCK_EIO 7
1589+
#define EXT4_SIM_DIRBLOCK_CRC 8
1590+
1591+
static inline bool ext4_simulate_fail(struct super_block *sb,
1592+
unsigned long code)
1593+
{
1594+
#ifdef CONFIG_EXT4_DEBUG
1595+
struct ext4_sb_info *sbi = EXT4_SB(sb);
1596+
1597+
if (unlikely(sbi->s_simulate_fail == code)) {
1598+
sbi->s_simulate_fail = 0;
1599+
return true;
1600+
}
1601+
#endif
1602+
return false;
1603+
}
1604+
1605+
static inline void ext4_simulate_fail_bh(struct super_block *sb,
1606+
struct buffer_head *bh,
1607+
unsigned long code)
1608+
{
1609+
if (!IS_ERR(bh) && ext4_simulate_fail(sb, code))
1610+
clear_buffer_uptodate(bh);
1611+
}
1612+
1613+
/*
1614+
* Error number codes for s_{first,last}_error_errno
1615+
*
1616+
* Linux errno numbers are architecture specific, so we need to translate
1617+
* them into something which is architecture independent. We don't define
1618+
* codes for all errno's; just the ones which are most likely to be the cause
1619+
* of an ext4_error() call.
1620+
*/
1621+
#define EXT4_ERR_UNKNOWN 1
1622+
#define EXT4_ERR_EIO 2
1623+
#define EXT4_ERR_ENOMEM 3
1624+
#define EXT4_ERR_EFSBADCRC 4
1625+
#define EXT4_ERR_EFSCORRUPTED 5
1626+
#define EXT4_ERR_ENOSPC 6
1627+
#define EXT4_ERR_ENOKEY 7
1628+
#define EXT4_ERR_EROFS 8
1629+
#define EXT4_ERR_EFBIG 9
1630+
#define EXT4_ERR_EEXIST 10
1631+
#define EXT4_ERR_ERANGE 11
1632+
#define EXT4_ERR_EOVERFLOW 12
1633+
#define EXT4_ERR_EBUSY 13
1634+
#define EXT4_ERR_ENOTDIR 14
1635+
#define EXT4_ERR_ENOTEMPTY 15
1636+
#define EXT4_ERR_ESHUTDOWN 16
1637+
#define EXT4_ERR_EFAULT 17
1638+
15771639
/*
15781640
* Inode dynamic state flags
15791641
*/
@@ -2628,7 +2690,6 @@ extern int ext4_issue_zeroout(struct inode *inode, ext4_lblk_t lblk,
26282690
/* indirect.c */
26292691
extern int ext4_ind_map_blocks(handle_t *handle, struct inode *inode,
26302692
struct ext4_map_blocks *map, int flags);
2631-
extern int ext4_ind_calc_metadata_amount(struct inode *inode, sector_t lblock);
26322693
extern int ext4_ind_trans_blocks(struct inode *inode, int nrblocks);
26332694
extern void ext4_ind_truncate(handle_t *, struct inode *inode);
26342695
extern int ext4_ind_remove_space(handle_t *handle, struct inode *inode,
@@ -2679,15 +2740,14 @@ extern struct buffer_head *ext4_sb_bread(struct super_block *sb,
26792740
extern int ext4_seq_options_show(struct seq_file *seq, void *offset);
26802741
extern int ext4_calculate_overhead(struct super_block *sb);
26812742
extern void ext4_superblock_csum_set(struct super_block *sb);
2682-
extern void *ext4_kvmalloc(size_t size, gfp_t flags);
2683-
extern void *ext4_kvzalloc(size_t size, gfp_t flags);
26842743
extern int ext4_alloc_flex_bg_array(struct super_block *sb,
26852744
ext4_group_t ngroup);
26862745
extern const char *ext4_decode_error(struct super_block *sb, int errno,
26872746
char nbuf[16]);
26882747
extern void ext4_mark_group_bitmap_corrupted(struct super_block *sb,
26892748
ext4_group_t block_group,
26902749
unsigned int flags);
2750+
extern void ext4_set_errno(struct super_block *sb, int err);
26912751

26922752
extern __printf(4, 5)
26932753
void __ext4_error(struct super_block *, const char *, unsigned int,
@@ -3254,7 +3314,6 @@ struct ext4_extent;
32543314
#define EXT_MAX_BLOCKS 0xffffffff
32553315

32563316
extern int ext4_ext_tree_init(handle_t *handle, struct inode *);
3257-
extern int ext4_ext_writepage_trans_blocks(struct inode *, int);
32583317
extern int ext4_ext_index_trans_blocks(struct inode *inode, int extents);
32593318
extern int ext4_ext_map_blocks(handle_t *handle, struct inode *inode,
32603319
struct ext4_map_blocks *map, int flags);
@@ -3271,14 +3330,9 @@ extern int ext4_convert_unwritten_io_end_vec(handle_t *handle,
32713330
ext4_io_end_t *io_end);
32723331
extern int ext4_map_blocks(handle_t *handle, struct inode *inode,
32733332
struct ext4_map_blocks *map, int flags);
3274-
extern int ext4_ext_calc_metadata_amount(struct inode *inode,
3275-
ext4_lblk_t lblocks);
32763333
extern int ext4_ext_calc_credits_for_single_extent(struct inode *inode,
32773334
int num,
32783335
struct ext4_ext_path *path);
3279-
extern int ext4_can_extents_be_merged(struct inode *inode,
3280-
struct ext4_extent *ex1,
3281-
struct ext4_extent *ex2);
32823336
extern int ext4_ext_insert_extent(handle_t *, struct inode *,
32833337
struct ext4_ext_path **,
32843338
struct ext4_extent *, int);
@@ -3294,8 +3348,6 @@ extern int ext4_get_es_cache(struct inode *inode,
32943348
struct fiemap_extent_info *fieinfo,
32953349
__u64 start, __u64 len);
32963350
extern int ext4_ext_precache(struct inode *inode);
3297-
extern int ext4_collapse_range(struct inode *inode, loff_t offset, loff_t len);
3298-
extern int ext4_insert_range(struct inode *inode, loff_t offset, loff_t len);
32993351
extern int ext4_swap_extents(handle_t *handle, struct inode *inode1,
33003352
struct inode *inode2, ext4_lblk_t lblk1,
33013353
ext4_lblk_t lblk2, ext4_lblk_t count,
@@ -3390,6 +3442,7 @@ static inline void ext4_clear_io_unwritten_flag(ext4_io_end_t *io_end)
33903442
}
33913443

33923444
extern const struct iomap_ops ext4_iomap_ops;
3445+
extern const struct iomap_ops ext4_iomap_overwrite_ops;
33933446
extern const struct iomap_ops ext4_iomap_report_ops;
33943447

33953448
static inline int ext4_buffer_uptodate(struct buffer_head *bh)

fs/ext4/ext4_extents.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -267,10 +267,5 @@ static inline void ext4_idx_store_pblock(struct ext4_extent_idx *ix,
267267
0xffff);
268268
}
269269

270-
#define ext4_ext_dirty(handle, inode, path) \
271-
__ext4_ext_dirty(__func__, __LINE__, (handle), (inode), (path))
272-
int __ext4_ext_dirty(const char *where, unsigned int line, handle_t *handle,
273-
struct inode *inode, struct ext4_ext_path *path);
274-
275270
#endif /* _EXT4_EXTENTS */
276271

fs/ext4/ext4_jbd2.c

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,28 @@
77

88
#include <trace/events/ext4.h>
99

10+
int ext4_inode_journal_mode(struct inode *inode)
11+
{
12+
if (EXT4_JOURNAL(inode) == NULL)
13+
return EXT4_INODE_WRITEBACK_DATA_MODE; /* writeback */
14+
/* We do not support data journalling with delayed allocation */
15+
if (!S_ISREG(inode->i_mode) ||
16+
ext4_test_inode_flag(inode, EXT4_INODE_EA_INODE) ||
17+
test_opt(inode->i_sb, DATA_FLAGS) == EXT4_MOUNT_JOURNAL_DATA ||
18+
(ext4_test_inode_flag(inode, EXT4_INODE_JOURNAL_DATA) &&
19+
!test_opt(inode->i_sb, DELALLOC))) {
20+
/* We do not support data journalling for encrypted data */
21+
if (S_ISREG(inode->i_mode) && IS_ENCRYPTED(inode))
22+
return EXT4_INODE_ORDERED_DATA_MODE; /* ordered */
23+
return EXT4_INODE_JOURNAL_DATA_MODE; /* journal data */
24+
}
25+
if (test_opt(inode->i_sb, DATA_FLAGS) == EXT4_MOUNT_ORDERED_DATA)
26+
return EXT4_INODE_ORDERED_DATA_MODE; /* ordered */
27+
if (test_opt(inode->i_sb, DATA_FLAGS) == EXT4_MOUNT_WRITEBACK_DATA)
28+
return EXT4_INODE_WRITEBACK_DATA_MODE; /* writeback */
29+
BUG();
30+
}
31+
1032
/* Just increment the non-pointer handle value */
1133
static handle_t *ext4_get_nojournal(void)
1234
{
@@ -58,6 +80,7 @@ static int ext4_journal_check_start(struct super_block *sb)
5880
* take the FS itself readonly cleanly.
5981
*/
6082
if (journal && is_journal_aborted(journal)) {
83+
ext4_set_errno(sb, -journal->j_errno);
6184
ext4_abort(sb, "Detected aborted journal");
6285
return -EROFS;
6386
}
@@ -249,6 +272,7 @@ int __ext4_forget(const char *where, unsigned int line, handle_t *handle,
249272
if (err) {
250273
ext4_journal_abort_handle(where, line, __func__,
251274
bh, handle, err);
275+
ext4_set_errno(inode->i_sb, -err);
252276
__ext4_abort(inode->i_sb, where, line,
253277
"error %d when attempting revoke", err);
254278
}
@@ -320,6 +344,7 @@ int __ext4_handle_dirty_metadata(const char *where, unsigned int line,
320344
es = EXT4_SB(inode->i_sb)->s_es;
321345
es->s_last_error_block =
322346
cpu_to_le64(bh->b_blocknr);
347+
ext4_set_errno(inode->i_sb, EIO);
323348
ext4_error_inode(inode, where, line,
324349
bh->b_blocknr,
325350
"IO error syncing itable block");

fs/ext4/ext4_jbd2.h

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -463,27 +463,7 @@ int ext4_force_commit(struct super_block *sb);
463463
#define EXT4_INODE_ORDERED_DATA_MODE 0x02 /* ordered data mode */
464464
#define EXT4_INODE_WRITEBACK_DATA_MODE 0x04 /* writeback data mode */
465465

466-
static inline int ext4_inode_journal_mode(struct inode *inode)
467-
{
468-
if (EXT4_JOURNAL(inode) == NULL)
469-
return EXT4_INODE_WRITEBACK_DATA_MODE; /* writeback */
470-
/* We do not support data journalling with delayed allocation */
471-
if (!S_ISREG(inode->i_mode) ||
472-
ext4_test_inode_flag(inode, EXT4_INODE_EA_INODE) ||
473-
test_opt(inode->i_sb, DATA_FLAGS) == EXT4_MOUNT_JOURNAL_DATA ||
474-
(ext4_test_inode_flag(inode, EXT4_INODE_JOURNAL_DATA) &&
475-
!test_opt(inode->i_sb, DELALLOC))) {
476-
/* We do not support data journalling for encrypted data */
477-
if (S_ISREG(inode->i_mode) && IS_ENCRYPTED(inode))
478-
return EXT4_INODE_ORDERED_DATA_MODE; /* ordered */
479-
return EXT4_INODE_JOURNAL_DATA_MODE; /* journal data */
480-
}
481-
if (test_opt(inode->i_sb, DATA_FLAGS) == EXT4_MOUNT_ORDERED_DATA)
482-
return EXT4_INODE_ORDERED_DATA_MODE; /* ordered */
483-
if (test_opt(inode->i_sb, DATA_FLAGS) == EXT4_MOUNT_WRITEBACK_DATA)
484-
return EXT4_INODE_WRITEBACK_DATA_MODE; /* writeback */
485-
BUG();
486-
}
466+
int ext4_inode_journal_mode(struct inode *inode);
487467

488468
static inline int ext4_should_journal_data(struct inode *inode)
489469
{

0 commit comments

Comments
 (0)