Skip to content

Commit f287a1a

Browse files
committed
ext4: Remove automatic enabling of the HUGE_FILE feature flag
If the HUGE_FILE feature flag is not set, don't allow the creation of large files, instead of automatically enabling the feature flag. Recent versions of mke2fs will set the HUGE_FILE flag automatically anyway for ext4 filesystems. Signed-off-by: "Theodore Ts'o" <[email protected]>
1 parent 3e624fc commit f287a1a

File tree

2 files changed

+21
-88
lines changed

2 files changed

+21
-88
lines changed

fs/ext4/inode.c

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4194,7 +4194,6 @@ static int ext4_inode_blocks_set(handle_t *handle,
41944194
struct inode *inode = &(ei->vfs_inode);
41954195
u64 i_blocks = inode->i_blocks;
41964196
struct super_block *sb = inode->i_sb;
4197-
int err = 0;
41984197

41994198
if (i_blocks <= ~0U) {
42004199
/*
@@ -4204,36 +4203,27 @@ static int ext4_inode_blocks_set(handle_t *handle,
42044203
raw_inode->i_blocks_lo = cpu_to_le32(i_blocks);
42054204
raw_inode->i_blocks_high = 0;
42064205
ei->i_flags &= ~EXT4_HUGE_FILE_FL;
4207-
} else if (i_blocks <= 0xffffffffffffULL) {
4206+
return 0;
4207+
}
4208+
if (!EXT4_HAS_RO_COMPAT_FEATURE(sb, EXT4_FEATURE_RO_COMPAT_HUGE_FILE))
4209+
return -EFBIG;
4210+
4211+
if (i_blocks <= 0xffffffffffffULL) {
42084212
/*
42094213
* i_blocks can be represented in a 48 bit variable
42104214
* as multiple of 512 bytes
42114215
*/
4212-
err = ext4_update_rocompat_feature(handle, sb,
4213-
EXT4_FEATURE_RO_COMPAT_HUGE_FILE);
4214-
if (err)
4215-
goto err_out;
4216-
/* i_block is stored in the split 48 bit fields */
42174216
raw_inode->i_blocks_lo = cpu_to_le32(i_blocks);
42184217
raw_inode->i_blocks_high = cpu_to_le16(i_blocks >> 32);
42194218
ei->i_flags &= ~EXT4_HUGE_FILE_FL;
42204219
} else {
4221-
/*
4222-
* i_blocks should be represented in a 48 bit variable
4223-
* as multiple of file system block size
4224-
*/
4225-
err = ext4_update_rocompat_feature(handle, sb,
4226-
EXT4_FEATURE_RO_COMPAT_HUGE_FILE);
4227-
if (err)
4228-
goto err_out;
42294220
ei->i_flags |= EXT4_HUGE_FILE_FL;
42304221
/* i_block is stored in file system block size */
42314222
i_blocks = i_blocks >> (inode->i_blkbits - 9);
42324223
raw_inode->i_blocks_lo = cpu_to_le32(i_blocks);
42334224
raw_inode->i_blocks_high = cpu_to_le16(i_blocks >> 32);
42344225
}
4235-
err_out:
4236-
return err;
4226+
return 0;
42374227
}
42384228

42394229
/*

fs/ext4/super.c

Lines changed: 14 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -374,66 +374,6 @@ void ext4_update_dynamic_rev(struct super_block *sb)
374374
*/
375375
}
376376

377-
int ext4_update_compat_feature(handle_t *handle,
378-
struct super_block *sb, __u32 compat)
379-
{
380-
int err = 0;
381-
if (!EXT4_HAS_COMPAT_FEATURE(sb, compat)) {
382-
err = ext4_journal_get_write_access(handle,
383-
EXT4_SB(sb)->s_sbh);
384-
if (err)
385-
return err;
386-
EXT4_SET_COMPAT_FEATURE(sb, compat);
387-
sb->s_dirt = 1;
388-
handle->h_sync = 1;
389-
BUFFER_TRACE(EXT4_SB(sb)->s_sbh,
390-
"call ext4_journal_dirty_met adata");
391-
err = ext4_journal_dirty_metadata(handle,
392-
EXT4_SB(sb)->s_sbh);
393-
}
394-
return err;
395-
}
396-
397-
int ext4_update_rocompat_feature(handle_t *handle,
398-
struct super_block *sb, __u32 rocompat)
399-
{
400-
int err = 0;
401-
if (!EXT4_HAS_RO_COMPAT_FEATURE(sb, rocompat)) {
402-
err = ext4_journal_get_write_access(handle,
403-
EXT4_SB(sb)->s_sbh);
404-
if (err)
405-
return err;
406-
EXT4_SET_RO_COMPAT_FEATURE(sb, rocompat);
407-
sb->s_dirt = 1;
408-
handle->h_sync = 1;
409-
BUFFER_TRACE(EXT4_SB(sb)->s_sbh,
410-
"call ext4_journal_dirty_met adata");
411-
err = ext4_journal_dirty_metadata(handle,
412-
EXT4_SB(sb)->s_sbh);
413-
}
414-
return err;
415-
}
416-
417-
int ext4_update_incompat_feature(handle_t *handle,
418-
struct super_block *sb, __u32 incompat)
419-
{
420-
int err = 0;
421-
if (!EXT4_HAS_INCOMPAT_FEATURE(sb, incompat)) {
422-
err = ext4_journal_get_write_access(handle,
423-
EXT4_SB(sb)->s_sbh);
424-
if (err)
425-
return err;
426-
EXT4_SET_INCOMPAT_FEATURE(sb, incompat);
427-
sb->s_dirt = 1;
428-
handle->h_sync = 1;
429-
BUFFER_TRACE(EXT4_SB(sb)->s_sbh,
430-
"call ext4_journal_dirty_met adata");
431-
err = ext4_journal_dirty_metadata(handle,
432-
EXT4_SB(sb)->s_sbh);
433-
}
434-
return err;
435-
}
436-
437377
/*
438378
* Open the external journal device
439379
*/
@@ -1771,13 +1711,13 @@ static void ext4_orphan_cleanup(struct super_block *sb,
17711711
*
17721712
* Note, this does *not* consider any metadata overhead for vfs i_blocks.
17731713
*/
1774-
static loff_t ext4_max_size(int blkbits)
1714+
static loff_t ext4_max_size(int blkbits, int has_huge_files)
17751715
{
17761716
loff_t res;
17771717
loff_t upper_limit = MAX_LFS_FILESIZE;
17781718

17791719
/* small i_blocks in vfs inode? */
1780-
if (sizeof(blkcnt_t) < sizeof(u64)) {
1720+
if (!has_huge_files || sizeof(blkcnt_t) < sizeof(u64)) {
17811721
/*
17821722
* CONFIG_LSF is not enabled implies the inode
17831723
* i_block represent total blocks in 512 bytes
@@ -1807,7 +1747,7 @@ static loff_t ext4_max_size(int blkbits)
18071747
* block limit, and also a limit of (2^48 - 1) 512-byte sectors in i_blocks.
18081748
* We need to be 1 filesystem block less than the 2^48 sector limit.
18091749
*/
1810-
static loff_t ext4_max_bitmap_size(int bits)
1750+
static loff_t ext4_max_bitmap_size(int bits, int has_huge_files)
18111751
{
18121752
loff_t res = EXT4_NDIR_BLOCKS;
18131753
int meta_blocks;
@@ -1820,11 +1760,11 @@ static loff_t ext4_max_bitmap_size(int bits)
18201760
* total number of 512 bytes blocks of the file
18211761
*/
18221762

1823-
if (sizeof(blkcnt_t) < sizeof(u64)) {
1763+
if (!has_huge_files || sizeof(blkcnt_t) < sizeof(u64)) {
18241764
/*
1825-
* CONFIG_LSF is not enabled implies the inode
1826-
* i_block represent total blocks in 512 bytes
1827-
* 32 == size of vfs inode i_blocks * 8
1765+
* !has_huge_files or CONFIG_LSF is not enabled
1766+
* implies the inode i_block represent total blocks in
1767+
* 512 bytes 32 == size of vfs inode i_blocks * 8
18281768
*/
18291769
upper_limit = (1LL << 32) - 1;
18301770

@@ -1933,7 +1873,7 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent)
19331873
int blocksize;
19341874
int db_count;
19351875
int i;
1936-
int needs_recovery;
1876+
int needs_recovery, has_huge_files;
19371877
__le32 features;
19381878
__u64 blocks_count;
19391879
int err;
@@ -2074,7 +2014,9 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent)
20742014
sb->s_id, le32_to_cpu(features));
20752015
goto failed_mount;
20762016
}
2077-
if (EXT4_HAS_RO_COMPAT_FEATURE(sb, EXT4_FEATURE_RO_COMPAT_HUGE_FILE)) {
2017+
has_huge_files = EXT4_HAS_RO_COMPAT_FEATURE(sb,
2018+
EXT4_FEATURE_RO_COMPAT_HUGE_FILE);
2019+
if (has_huge_files) {
20782020
/*
20792021
* Large file size enabled file system can only be
20802022
* mount if kernel is build with CONFIG_LSF
@@ -2124,8 +2066,9 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent)
21242066
}
21252067
}
21262068

2127-
sbi->s_bitmap_maxbytes = ext4_max_bitmap_size(sb->s_blocksize_bits);
2128-
sb->s_maxbytes = ext4_max_size(sb->s_blocksize_bits);
2069+
sbi->s_bitmap_maxbytes = ext4_max_bitmap_size(sb->s_blocksize_bits,
2070+
has_huge_files);
2071+
sb->s_maxbytes = ext4_max_size(sb->s_blocksize_bits, has_huge_files);
21292072

21302073
if (le32_to_cpu(es->s_rev_level) == EXT4_GOOD_OLD_REV) {
21312074
sbi->s_inode_size = EXT4_GOOD_OLD_INODE_SIZE;

0 commit comments

Comments
 (0)