Skip to contentSkip to conversation

ext3 enlarge blocksize

RFC In review [email protected] 2 participants 3 messages Apr 13, 2006 – Apr 26, 2006 ext2 file system

lore
Share & tools
lore
#0 lore raw

RFC 10/21 ext3 enlarge blocksize

Summary of this patch:
[10/21] enlarge block size(ext3)
- Add an incompat flag "EXT3_FEATURE_INCOMPAT_LARGE_BLOCK" which indicates that the filesystem is extended.

- Allow block size till pagesize in ext3.

---

fs/ext3/super.c +16 -6
diff -upNr -X linux-2.6.17-rc1.org/Documentation/dontdiff linux-2.6.17-rc1.org/fs/ext3/super.c linux-2.6.17-rc1.tmp/fs/ext3/super.c
@@ -1463,12 +1463,22 @@ static int ext3_fill_super (struct super
 	}
 	blocksize = BLOCK_SIZE << le32_to_cpu(es->s_log_block_size);
 
-	if (blocksize < EXT3_MIN_BLOCK_SIZE ||
-	    blocksize > EXT3_MAX_BLOCK_SIZE) {
-		printk(KERN_ERR 
-		       "EXT3-fs: Unsupported filesystem blocksize %d on %s.\n",
-		       blocksize, sb->s_id);
-		goto failed_mount;
+	if (EXT3_HAS_INCOMPAT_FEATURE(sb,
+	    EXT3_FEATURE_INCOMPAT_LARGE_BLOCK)) {
+		if (blocksize < EXT3_MIN_BLOCK_SIZE ||
+		    blocksize > PAGE_SIZE ||
+		    blocksize > EXT3_EXTENDED_MAX_BLOCK_SIZE) {
+			printk(KERN_ERR "EXT3-fs: Unsupported extended filesystem blocksize %d on %s.\n",
+				blocksize, sb->s_id);
+			goto failed_mount;
+		}
+	} else {
+		if (blocksize < EXT3_MIN_BLOCK_SIZE ||
+		    blocksize > EXT3_MAX_BLOCK_SIZE) {
+			printk(KERN_ERR "EXT3-fs: Unsupported filesystem blocksize %d on %s.\n",
+				blocksize, sb->s_id);
+			goto failed_mount;
+		}
 	}
 
 	hblock = bdev_hardsect_size(sb->s_bdev);
include/linux/ext2_fs.h +4 -1
diff -upNr -X linux-2.6.17-rc1.org/Documentation/dontdiff linux-2.6.17-rc1.org/include/linux/ext2_fs.h linux-2.6.17-rc1.tmp/include/linux/ext2_fs.h
@@ -91,6 +91,7 @@ static inline struct ext2_sb_info *EXT2_
  */
 #define EXT2_MIN_BLOCK_SIZE		1024
 #define	EXT2_MAX_BLOCK_SIZE		4096
+#define        EXT2_EXTENDED_MAX_BLOCK_SIZE    65536
 #define EXT2_MIN_BLOCK_LOG_SIZE		  10
 #ifdef __KERNEL__
 # define EXT2_BLOCK_SIZE(s)		((s)->s_blocksize)
@@ -471,11 +472,13 @@ struct ext2_super_block {
 #define EXT3_FEATURE_INCOMPAT_RECOVER		0x0004
 #define EXT3_FEATURE_INCOMPAT_JOURNAL_DEV	0x0008
 #define EXT2_FEATURE_INCOMPAT_META_BG		0x0010
+#define EXT2_FEATURE_INCOMPAT_LARGE_BLOCK      0x0080
 #define EXT2_FEATURE_INCOMPAT_ANY		0xffffffff
 
 #define EXT2_FEATURE_COMPAT_SUPP	EXT2_FEATURE_COMPAT_EXT_ATTR
 #define EXT2_FEATURE_INCOMPAT_SUPP	(EXT2_FEATURE_INCOMPAT_FILETYPE| \
-					 EXT2_FEATURE_INCOMPAT_META_BG)
+					 EXT2_FEATURE_INCOMPAT_META_BG| \
+					 EXT2_FEATURE_INCOMPAT_LARGE_BLOCK)
 #define EXT2_FEATURE_RO_COMPAT_SUPP	(EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER| \
 					 EXT2_FEATURE_RO_COMPAT_LARGE_FILE| \
 					 EXT2_FEATURE_RO_COMPAT_BTREE_DIR)
include/linux/ext3_fs.h +4 -1
diff -upNr -X linux-2.6.17-rc1.org/Documentation/dontdiff linux-2.6.17-rc1.org/include/linux/ext3_fs.h linux-2.6.17-rc1.tmp/include/linux/ext3_fs.h
@@ -86,6 +86,7 @@ struct statfs;
  */
 #define EXT3_MIN_BLOCK_SIZE		1024
 #define	EXT3_MAX_BLOCK_SIZE		4096
+#define        EXT3_EXTENDED_MAX_BLOCK_SIZE    65536
 #define EXT3_MIN_BLOCK_LOG_SIZE		  10
 #ifdef __KERNEL__
 # define EXT3_BLOCK_SIZE(s)		((s)->s_blocksize)
@@ -563,11 +564,13 @@ static inline struct ext3_inode_info *EX
 #define EXT3_FEATURE_INCOMPAT_RECOVER		0x0004 /* Needs recovery */
 #define EXT3_FEATURE_INCOMPAT_JOURNAL_DEV	0x0008 /* Journal device */
 #define EXT3_FEATURE_INCOMPAT_META_BG		0x0010
+#define EXT3_FEATURE_INCOMPAT_LARGE_BLOCK      0x0080
 
 #define EXT3_FEATURE_COMPAT_SUPP	EXT2_FEATURE_COMPAT_EXT_ATTR
 #define EXT3_FEATURE_INCOMPAT_SUPP	(EXT3_FEATURE_INCOMPAT_FILETYPE| \
 					 EXT3_FEATURE_INCOMPAT_RECOVER| \
-					 EXT3_FEATURE_INCOMPAT_META_BG)
+					 EXT3_FEATURE_INCOMPAT_META_BG| \
+					 EXT3_FEATURE_INCOMPAT_LARGE_BLOCK)
 #define EXT3_FEATURE_RO_COMPAT_SUPP	(EXT3_FEATURE_RO_COMPAT_SPARSE_SUPER| \
 					 EXT3_FEATURE_RO_COMPAT_LARGE_FILE| \
 					 EXT3_FEATURE_RO_COMPAT_BTREE_DIR)
#1 lore raw

RFC 11/21 ext3 enlarge file size

Summary of this patch:
[11/21] enlarge file size(ext3)
- If the flag is set to super block, i_blocks of disk inode (ext3_inode) is filesystem-block unit, and i_blocks of VFS inode is sector unit.

- If the flag is set to super block, max file size is set to (FS blocksize) * (2^32 -1).

---

fs/ext3/inode.c +16 -2
diff -upNr -X linux-2.6.17-rc1/Documentation/dontdiff linux-2.6.17-rc1.tmp/fs/ext3/inode.c linux-2.6.17-rc1.tmp2/fs/ext3/inode.c
@@ -2578,6 +2578,7 @@ void ext3_read_inode(struct inode * inod
 	struct ext3_inode *raw_inode;
 	struct ext3_inode_info *ei = EXT3_I(inode);
 	struct buffer_head *bh;
+	struct super_block *sb = inode->i_sb;
 	int block;
 
 #ifdef CONFIG_EXT3_FS_POSIX_ACL
@@ -2627,7 +2628,13 @@ void ext3_read_inode(struct inode * inod
 	inode->i_blksize = PAGE_SIZE;	/* This is the optimal IO size
 					 * (for stat), not the fs block
 					 * size */  
-	inode->i_blocks = le32_to_cpu(raw_inode->i_blocks);
+	if (EXT3_HAS_INCOMPAT_FEATURE(sb,
+	    EXT3_FEATURE_INCOMPAT_LARGE_BLOCK)) {
+		inode->i_blocks = (blkcnt_t)le32_to_cpu(raw_inode->i_blocks)
+			<< (inode->i_blkbits - EXT3_SECTOR_BITS);
+	} else {
+		inode->i_blocks = le32_to_cpu(raw_inode->i_blocks);
+	} 
 	ei->i_flags = le32_to_cpu(raw_inode->i_flags);
 #ifdef EXT3_FRAGMENTS
 	ei->i_faddr = le32_to_cpu(raw_inode->i_faddr);
@@ -2723,6 +2730,7 @@ static int ext3_do_update_inode(handle_t
 	struct ext3_inode *raw_inode = ext3_raw_inode(iloc);
 	struct ext3_inode_info *ei = EXT3_I(inode);
 	struct buffer_head *bh = iloc->bh;
+	struct super_block *sb = inode->i_sb;
 	int err = 0, rc, block;
 
 	/* For fields not not tracking in the in-memory inode,
@@ -2760,7 +2768,13 @@ static int ext3_do_update_inode(handle_t
 	raw_inode->i_atime = cpu_to_le32(inode->i_atime.tv_sec);
 	raw_inode->i_ctime = cpu_to_le32(inode->i_ctime.tv_sec);
 	raw_inode->i_mtime = cpu_to_le32(inode->i_mtime.tv_sec);
-	raw_inode->i_blocks = cpu_to_le32(inode->i_blocks);
+	if (EXT3_HAS_INCOMPAT_FEATURE(sb,
+	    EXT3_FEATURE_INCOMPAT_LARGE_BLOCK)) {
+		raw_inode->i_blocks = cpu_to_le32((inode->i_blocks)
+			>> (inode->i_blkbits - EXT3_SECTOR_BITS));
+	} else {
+		raw_inode->i_blocks = cpu_to_le32(inode->i_blocks);
+	}
 	raw_inode->i_dtime = cpu_to_le32(ei->i_dtime);
 	raw_inode->i_flags = cpu_to_le32(ei->i_flags);
 #ifdef EXT3_FRAGMENTS
fs/ext3/super.c +18 -3
diff -upNr -X linux-2.6.17-rc1/Documentation/dontdiff linux-2.6.17-rc1.tmp/fs/ext3/super.c linux-2.6.17-rc1.tmp2/fs/ext3/super.c
@@ -1297,14 +1297,20 @@ static void ext3_orphan_cleanup (struct 
  * block limit, and also a limit of (2^32 - 1) 512-byte sectors in i_blocks.
  * We need to be 1 filesystem block less than the 2^32 sector limit.
  */
-static loff_t ext3_max_size(int bits)
+static loff_t ext3_max_size(int bits, struct super_block *sb)
 {
 	loff_t res = EXT3_NDIR_BLOCKS;
 	/* This constant is calculated to be the largest file size for a
 	 * dense, 4k-blocksize file such that the total number of
 	 * sectors in the file, including data and all indirect blocks,
 	 * does not exceed 2^32. */
-	const loff_t upper_limit = 0x1ff7fffd000LL;
+	loff_t upper_limit;
+	if(EXT3_HAS_INCOMPAT_FEATURE(sb, 
+	   EXT3_FEATURE_INCOMPAT_LARGE_BLOCK)) {
+		upper_limit = (1LL << (bits + 32)) - 1;
+	} else {
+		upper_limit = 0x1ff7fffd000LL;
+	}
 
 	res += 1LL << (bits-2);
 	res += 1LL << (2*(bits-2));
@@ -1512,7 +1518,7 @@ static int ext3_fill_super (struct super
 		}
 	}
 
-	sb->s_maxbytes = ext3_max_size(sb->s_blocksize_bits);
+	sb->s_maxbytes = ext3_max_size(sb->s_blocksize_bits, sb);
 
 	if (le32_to_cpu(es->s_rev_level) == EXT3_GOOD_OLD_REV) {
 		sbi->s_inode_size = EXT3_GOOD_OLD_INODE_SIZE;
@@ -1703,6 +1709,15 @@ static int ext3_fill_super (struct super
 	 */
 
 	root = iget(sb, EXT3_ROOT_INO);
+	/* To appoint -O large block option, LSF needs to be enabled */
+	if (EXT3_HAS_INCOMPAT_FEATURE(sb,
+	    EXT3_FEATURE_INCOMPAT_LARGE_BLOCK)) {
+		if (sizeof(root->i_blocks) < sizeof(u64)) {
+			printk(KERN_ERR "EXT3-fs: %s: Unsupported large block option"\
+				"with LSF disabled.\n", sb->s_id);
+			goto failed_mount;
+		}
+	}
 	sb->s_root = d_alloc_root(root);
 	if (!sb->s_root) {
 		printk(KERN_ERR "EXT3-fs: get root inode failed\n");
include/linux/ext3_fs.h +1 -0
diff -upNr -X linux-2.6.17-rc1/Documentation/dontdiff linux-2.6.17-rc1.tmp/include/linux/ext3_fs.h linux-2.6.17-rc1.tmp2/include/linux/ext3_fs.h
@@ -99,6 +99,7 @@ struct statfs;
 #else
 # define EXT3_BLOCK_SIZE_BITS(s)	((s)->s_log_block_size + 10)
 #endif
+#define EXT3_SECTOR_BITS        9       /* log2(SECTOR_SIZE) */
 #ifdef __KERNEL__
 #define	EXT3_ADDR_PER_BLOCK_BITS(s)	(EXT3_SB(s)->s_addr_per_block_bits)
 #define EXT3_INODE_SIZE(s)		(EXT3_SB(s)->s_inode_size)
#2 lore raw
Quoted 5 lines · On Apr 13, 2006 16:07 +0900, [email protected] wrote:

- Add an incompat flag "EXT3_FEATURE_INCOMPAT_LARGE_BLOCK" which indicates that the filesystem is extended.
- Allow block size till pagesize in ext3.

(quoted diff) +0 -1
-	if (blocksize < EXT3_MIN_BLOCK_SIZE ||

Review

Quoted 10 lines
(quoted diff) +5 -5
-	    blocksize > EXT3_MAX_BLOCK_SIZE) {
-		printk(KERN_ERR 
-		       "EXT3-fs: Unsupported filesystem blocksize %d on %s.\n",
-		       blocksize, sb->s_id);
-		goto failed_mount;
+	if (EXT3_HAS_INCOMPAT_FEATURE(sb,
+	    EXT3_FEATURE_INCOMPAT_LARGE_BLOCK)) {
+		if (blocksize < EXT3_MIN_BLOCK_SIZE ||
+		    blocksize > PAGE_SIZE ||
+		    blocksize > EXT3_EXTENDED_MAX_BLOCK_SIZE) {

This in itself doesn't need an incompatible flag, since old kernels will prevent the mount for filesystems with blocksize > EXT3_MAX_BLOCK_SIZE anyways. It is already incompatible with older kernels, and isn't really related to the other use of this flag - changing the i_blocks field to handle files > 2TB.

Review

Quoted 2 lines
(quoted diff) +2 -0
+			printk(KERN_ERR "EXT3-fs: Unsupported extended filesystem blocksize %d on %s.\n",
+				blocksize, sb->s_id);

May be better to have:

+ printk(KERN_ERR "EXT3-fs: cannot mount filesystem with "
+ "blocksize %u larger than PAGE_SIZE %u on %s\n",
+ blocksize, PAGE_SIZE, sb->s_id);

Quoted 7 lines · On Apr 13, 2006 16:08 +0900, [email protected] wrote:

[11/21] enlarge file size(ext3)
- If the flag is set to super block, i_blocks of disk inode (ext3_inode) is filesystem-block unit, and i_blocks of VFS inode is sector unit.

- If the flag is set to super block, max file size is set to (FS blocksize) * (2^32 -1).

I like this patch, but prefer if we maintain as much compatibility as possible. There is not really a reason to make a filesystem incompatible unless there are actually files > 2TB stored in it (just like we didn't make filesystems incompatible for large_file unless there were files over 2GB in the filesystem).

fs/ext3/inode.c void ext3_read_inode(struct inode * inod · line 2634

Quoted 8 lines
fs/ext3/inode.c +7 -0
@@ -2627,7 +2628,13 @@ void ext3_read_inode(struct inode * inod
+	if (EXT3_HAS_INCOMPAT_FEATURE(sb,
+	    EXT3_FEATURE_INCOMPAT_LARGE_BLOCK)) {
+		inode->i_blocks = (blkcnt_t)le32_to_cpu(raw_inode->i_blocks)
+			<< (inode->i_blkbits - EXT3_SECTOR_BITS);
+	} else {
+		inode->i_blocks = le32_to_cpu(raw_inode->i_blocks);
+	} 

In particular, if INCOMPAT_LARGE_BLOCK is set on the filesystem, we could check a flag (a new EXT3_LARGE_BLOCK_FL = 0x40000, or whatever Ted would want there) in the inode to determine if the i_blocks is in fs blocksize units, or the default sector units.

fs/ext3/inode.c static int ext3_do_update_inode(handle_t · line 2774

Quoted 8 lines
fs/ext3/inode.c +7 -0
@@ -2760,7 +2768,13 @@ static int ext3_do_update_inode(handle_t
+	if (EXT3_HAS_INCOMPAT_FEATURE(sb,
+	    EXT3_FEATURE_INCOMPAT_LARGE_BLOCK)) {
+		raw_inode->i_blocks = cpu_to_le32((inode->i_blocks)
+			>> (inode->i_blkbits - EXT3_SECTOR_BITS));
+	} else {
+		raw_inode->i_blocks = cpu_to_le32(inode->i_blocks);
+	}

In this case, we would only set EXT3_LARGE_BLOCK_FL if the i_blocks count was over 2^32 sectors, and set the EXT3_FEATURE_INCOMPAT_LARGE_BLOCK flag in the superblock. It would probably be best if this was implemented in a small helper function like ext3_set_feature(sb, compat, rocompat, incompat) that takes the code to check/set EXT3_FEATURE_RO_COMPAT_LARGE_FILE and update dynamic_rev.

That way you get maximum compatibility, and only break compatibility for the very few cases where such large files are acutally needed. It would also allow ext3 to handle > 2TB sparse files without being incompatible, since we don't need to know a-priori whether the file will have a lot of blocks allocated to it.

I guess the only other question is whether this should be an INCOMPAT flag, or an ROCOMPAT one, since there is very little harm in getting the i_blocks count wrong on a read-only filesystem, and having it ROCOMPAT at least allows some form of system recovery if this flag is set by error.

The flag for large files was also ROCOMPAT, and one could argue that the file size is 1000x more important than the number of blocks, since the size affects actually reading the file, while the blocks count is used by almost nothing.

fs/ext3/super.c static void ext3_orphan_cleanup (struct · line 1310

Quoted 6 lines
fs/ext3/super.c +5 -0
+static loff_t ext3_max_size(int bits, struct super_block *sb)
 {
+	loff_t upper_limit;
+	if(EXT3_HAS_INCOMPAT_FEATURE(sb, 
+	   EXT3_FEATURE_INCOMPAT_LARGE_BLOCK)) {
+		upper_limit = (1LL << (bits + 32)) - 1;

With the above changes, the upper limit could always be the higher value.

fs/ext3/super.c static int ext3_fill_super (struct super · line 1719

Quoted 12 lines
fs/ext3/super.c +8 -0
@@ -1703,6 +1709,15 @@ static int ext3_fill_super (struct super
 	 */
 
 	root = iget(sb, EXT3_ROOT_INO);
+	/* To appoint -O large block option, LSF needs to be enabled */
+	if (EXT3_HAS_INCOMPAT_FEATURE(sb,
+	    EXT3_FEATURE_INCOMPAT_LARGE_BLOCK)) {
+		if (sizeof(root->i_blocks) < sizeof(u64)) {
+			printk(KERN_ERR "EXT3-fs: %s: Unsupported large block option"\
+				"with LSF disabled.\n", sb->s_id);
+			goto failed_mount;
+		}

This could be considered a failure only for write mounts, and not readonly.

Cheers, Andreas
--
Andreas Dilger
Principal Software Engineer
Cluster File Systems, Inc.