Index: linux-stage/fs/ext4/ext4.h =================================================================== --- linux-stage.orig/fs/ext4/ext4.h 2011-05-20 11:01:37.000000000 +0300 +++ linux-stage/fs/ext4/ext4.h 2011-05-20 11:01:44.000000000 +0300 @@ -859,6 +859,7 @@ struct ext4_inode_info { #define EXT4_MOUNT_QUOTA 0x80000 /* Some quota option set */ #define EXT4_MOUNT_USRQUOTA 0x100000 /* "old" user quota */ #define EXT4_MOUNT_GRPQUOTA 0x200000 /* "old" group quota */ +#define EXT4_MOUNT_EXTENTS 0x400000 /* Extents support */ #define EXT4_MOUNT_JOURNAL_CHECKSUM 0x800000 /* Journal checksums */ #define EXT4_MOUNT_JOURNAL_ASYNC_COMMIT 0x1000000 /* Journal Async Commit */ #define EXT4_MOUNT_I_VERSION 0x2000000 /* i_version support */ Index: linux-stage/fs/ext4/ext4_jbd2.h =================================================================== --- linux-stage.orig/fs/ext4/ext4_jbd2.h 2011-05-20 11:00:01.000000000 +0300 +++ linux-stage/fs/ext4/ext4_jbd2.h 2011-05-20 11:01:44.000000000 +0300 @@ -33,7 +33,7 @@ #define EXT4_SINGLEDATA_TRANS_BLOCKS(sb) \ (EXT4_HAS_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_EXTENTS) \ - ? 27U : 8U) + || test_opt(sb, EXTENTS) ? 27U : 8U) #define ext4_journal_dirty_metadata(handle, bh) \ ext4_handle_dirty_metadata(handle, NULL, bh) Index: linux-stage/fs/ext4/extents.c =================================================================== --- linux-stage.orig/fs/ext4/extents.c 2011-05-20 11:00:01.000000000 +0300 +++ linux-stage/fs/ext4/extents.c 2011-05-20 11:01:44.000000000 +0300 @@ -2555,7 +2555,7 @@ void ext4_ext_init(struct super_block *s * possible initialization would be here */ - if (EXT4_HAS_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_EXTENTS)) { + if (test_opt(sb, EXTENTS)) { #if defined(AGGRESSIVE_TEST) || defined(CHECK_BINSEARCH) || defined(EXTENTS_STATS) printk(KERN_INFO "EXT4-fs: file extents enabled"); #ifdef AGGRESSIVE_TEST @@ -2582,7 +2582,7 @@ void ext4_ext_init(struct super_block *s */ void ext4_ext_release(struct super_block *sb) { - if (!EXT4_HAS_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_EXTENTS)) + if (!test_opt(sb, EXTENTS)) return; #ifdef EXTENTS_STATS Index: linux-stage/fs/ext4/ialloc.c =================================================================== --- linux-stage.orig/fs/ext4/ialloc.c 2011-05-20 11:01:36.000000000 +0300 +++ linux-stage/fs/ext4/ialloc.c 2011-05-20 11:01:44.000000000 +0300 @@ -1049,7 +1049,7 @@ got: if (err) goto fail_free_drop; - if (EXT4_HAS_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_EXTENTS)) { + if (test_opt(sb, EXTENTS)) { /* set extent flag only for directory, file and normal symlink*/ if (S_ISDIR(mode) || S_ISREG(mode) || S_ISLNK(mode)) { ext4_set_inode_flag(inode, EXT4_INODE_EXTENTS); Index: linux-stage/fs/ext4/migrate.c =================================================================== --- linux-stage.orig/fs/ext4/migrate.c 2011-05-20 10:59:29.000000000 +0300 +++ linux-stage/fs/ext4/migrate.c 2011-05-20 11:03:22.000000000 +0300 @@ -459,13 +459,10 @@ int ext4_ext_migrate(struct inode *inode unsigned long max_entries; __u32 goal; - /* - * If the filesystem does not support extents, or the inode - * already is extent-based, error out. - */ - if (!EXT4_HAS_INCOMPAT_FEATURE(inode->i_sb, - EXT4_FEATURE_INCOMPAT_EXTENTS) || - (ext4_test_inode_flag(inode, EXT4_INODE_EXTENTS))) + if (!test_opt(inode->i_sb, EXTENTS)) + /* + * if mounted with noextents we don't allow the migrate + */ return -EINVAL; if (S_ISLNK(inode->i_mode) && inode->i_blocks == 0) Index: linux-stage/fs/ext4/super.c =================================================================== --- linux-stage.orig/fs/ext4/super.c 2011-05-20 11:01:37.000000000 +0300 +++ linux-stage/fs/ext4/super.c 2011-05-20 11:01:44.000000000 +0300 @@ -945,6 +945,8 @@ static int ext4_show_options(struct seq_ seq_puts(seq, ",journal_async_commit"); if (test_opt(sb, NOBH)) seq_puts(seq, ",nobh"); + if (!test_opt(sb, EXTENTS)) + seq_puts(seq, ",noextents"); if (test_opt(sb, I_VERSION)) seq_puts(seq, ",i_version"); if (!test_opt(sb, DELALLOC)) @@ -1515,6 +1517,7 @@ enum { Opt_inode_readahead_blks, Opt_journal_ioprio, Opt_discard, Opt_nodiscard, Opt_mballoc, Opt_bigendian_extents, Opt_force_over_16tb, + Opt_extents, Opt_noextents, }; static const match_table_t tokens = { @@ -1589,6 +1592,8 @@ static const match_table_t tokens = { {Opt_mballoc, "mballoc"}, {Opt_discard, "discard"}, {Opt_nodiscard, "nodiscard"}, + {Opt_extents, "extents"}, + {Opt_noextents, "noextents"}, {Opt_err, NULL}, }; @@ -1631,6 +1636,7 @@ static int parse_options(char *options, int qtype, qfmt; char *qname; #endif + ext4_fsblk_t last_block; if (!options) return 1; @@ -2039,6 +2045,32 @@ set_qf_format: case Opt_force_over_16tb: force_over_16tb = 1; break; + case Opt_extents: + if (!EXT4_HAS_INCOMPAT_FEATURE(sb, + EXT4_FEATURE_INCOMPAT_EXTENTS)) { + ext4_warning(sb, "extents feature not enabled " + "on this filesystem, use tune2fs"); + return 0; + } + set_opt(sbi->s_mount_opt, EXTENTS); + break; + case Opt_noextents: + /* + * When e2fsprogs support resizing an already existing + * ext4 file system to greater than 2**32 we need to + * add support to block allocator to handle growing + * already existing block mapped inode so that blocks + * allocated for them fall within 2**32 + */ + last_block = ext4_blocks_count(sbi->s_es) - 1; + if (last_block > 0xffffffffULL) { + printk(KERN_ERR "EXT4-fs: Filesystem too " + "large to mount with " + "-o noextents options\n"); + return 0; + } + clear_opt(sbi->s_mount_opt, EXTENTS); + break; default: ext4_msg(sb, KERN_ERR, "Unrecognized mount option \"%s\" " @@ -2901,6 +2933,17 @@ static int ext4_fill_super(struct super_ set_opt(sbi->s_mount_opt, BARRIER); /* + * turn on extents feature by default in ext4 filesystem + * only if feature flag already set by mkfs or tune2fs. + * Use -o noextents to turn it off + */ + if (EXT4_HAS_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_EXTENTS)) + set_opt(sbi->s_mount_opt, EXTENTS); + else + ext4_warning(sb, "extents feature not enabled on this filesystem, " + "use tune2fs."); + + /* * enable delayed allocation by default * Use -o nodelalloc to turn it off */