Skip to contentSkip to conversation

online-ext2 patch for 2.4-test11-pre7

PATCH New Andreas Dilger 1 participant 1 message Nov 27, 2000

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 online-ext2 patch for 2.4-test11-pre7

Hello all,
attached is an updated patch for online ext2 resizing with the latest 2.4 kernel (2.4.0-test11-pre7). It is not significantly different from the 2.2 kernel patch or the previous 2.3 kernel patch, with the exception of some changes to where the superblock lock is held.

I've tested it some, but 2.4 kernels don't run well on my laptop, and my other systems are all running ext3 which doesn't work with 2.4 yet. Please report any problems to [email protected].

The online-ext2-2.4.0.diff kernel patch needs to be applied AFTER the linux-2.4.0-test11-ext2compat.diff patch, which fixes some problems with the kernel trying to mount filesystems it doesn't understand. These patches are attached here, and the latest versions are also available from CVS for the ext2resize project at http://sourceforge.net/projects/ext2resize/

As with previous versions of online resizing, you need to have the user tools from the ext2resize package (also at sourceforge). The latest version of the user tools is 1.1.15. These tools only work on i386 systems right now.

With the newest version of the LVM user tools, the e2fsadm tool will call ext2online if the filesystem is mounted when the LV is resized.

Cheers, Andreas

Signature · 1 line
Andreas Dilger                               TurboLabs filesystem development
fs/ext2/balloc.c +51 -23
diff -ru -x .[a-zA-Z1-9]* -x *flags linux-2.4.0-test11-pre7.orig/fs/ext2/balloc.c linux-2.4.0-test11-pre7.compat/fs/ext2/balloc.c
@@ -663,7 +663,7 @@
 			 EXT2_BLOCKS_PER_GROUP(sb), map);
 }
 
-static int test_root(int a, int b)
+static inline int test_root(int a, int b)
 {
 	if (a == 0)
 		return 1;
@@ -676,30 +676,63 @@
 	}
 }
 
-int ext2_group_sparse(int group)
+static inline int ext2_group_sparse(int group)
 {
 	return (test_root(group, 3) || test_root(group, 5) ||
 		test_root(group, 7));
 }
 
+/**
+ *	ext2_bg_has_super - number of blocks used by the superblock in group
+ *	@sb: superblock for filesystem
+ *	@group: group number to check
+ *
+ *	Return the number of blocks used by the superblock (primary or backup)
+ *	in this group.  Currently it this will be only 0 or 1.
+ */
+int ext2_bg_has_super(struct super_block * sb, int group)
+{
+	if (EXT2_HAS_RO_COMPAT_FEATURE(sb,EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER)&&
+	    !ext2_group_sparse(group))
+		return 0;
+	return 1;
+}
+
+/**
+ *	ext2_bg_num_gdb - number of blocks used by the group table in group
+ *	@sb: superblock for filesystem
+ *	@group: group number to check
+ *
+ *	Return the number of blocks used by the group descriptor table
+ *	(primary or backup) in this group.  In the future there may be a
+ *	different number of descriptor blocks in each group.
+ */
+unsigned long ext2_bg_num_gdb(struct super_block * sb, int group)
+{
+	if (EXT2_HAS_RO_COMPAT_FEATURE(sb,EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER)&&
+	    !ext2_group_sparse(group))
+		return 0;
+	return sb->u.ext2_sb.s_gdb_count;
+}
+
+
+
 #ifdef CONFIG_EXT2_CHECK
 /* Called at mount-time, super-block is locked */
 void ext2_check_blocks_bitmap (struct super_block * sb)
 {
 	struct buffer_head * bh;
 	struct ext2_super_block * es;
-	unsigned long desc_count, bitmap_count, x;
+	unsigned long desc_count, bitmap_count, x, j;
 	unsigned long desc_blocks;
 	int bitmap_nr;
 	struct ext2_group_desc * gdp;
-	int i, j;
+	int i;
 
 	es = sb->u.ext2_sb.s_es;
 	desc_count = 0;
 	bitmap_count = 0;
 	gdp = NULL;
-	desc_blocks = (sb->u.ext2_sb.s_groups_count + EXT2_DESC_PER_BLOCK(sb) - 1) /
-		      EXT2_DESC_PER_BLOCK(sb);
 	for (i = 0; i < sb->u.ext2_sb.s_groups_count; i++) {
 		gdp = ext2_get_group_desc (sb, i, NULL);
 		if (!gdp)
@@ -708,24 +741,19 @@
 		bitmap_nr = load_block_bitmap (sb, i);
 		if (bitmap_nr < 0)
 			continue;
-		
-		bh = sb->u.ext2_sb.s_block_bitmap[bitmap_nr];
 
-		if (!(sb->u.ext2_sb.s_feature_ro_compat &
-		     EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER) ||
-		    ext2_group_sparse(i)) {
-			if (!ext2_test_bit (0, bh->b_data))
-				ext2_error (sb, "ext2_check_blocks_bitmap",
-					    "Superblock in group %d "
-					    "is marked free", i);
-
-			for (j = 0; j < desc_blocks; j++)
-				if (!ext2_test_bit (j + 1, bh->b_data))
-					ext2_error (sb,
-					    "ext2_check_blocks_bitmap",
-					    "Descriptor block #%d in group "
-					    "%d is marked free", j, i);
-		}
+		bh = EXT2_SB(sb)->s_block_bitmap[bitmap_nr];
+
+		if (ext2_bg_has_super(sb, i) && !ext2_test_bit(0, bh->b_data))
+			ext2_error(sb, __FUNCTION__,
+				   "Superblock in group %d is marked free", i);
+
+		desc_blocks = ext2_bg_num_gdb(sb, i);
+		for (j = 0; j < desc_blocks; j++)
+			if (!ext2_test_bit(j + 1, bh->b_data))
+				ext2_error(sb, __FUNCTION__,
+					   "Descriptor block #%ld in group "
+					   "%d is marked free", j, i);
 
 		if (!block_in_use (le32_to_cpu(gdp->bg_block_bitmap), sb, bh->b_data))
 			ext2_error (sb, "ext2_check_blocks_bitmap",
fs/ext2/inode.c +7 -3
diff -ru -x .[a-zA-Z1-9]* -x *flags linux-2.4.0-test11-pre7.orig/fs/ext2/inode.c linux-2.4.0-test11-pre7.compat/fs/ext2/inode.c
@@ -1190,13 +1190,15 @@
 		raw_inode->i_size_high = cpu_to_le32(inode->i_size >> 32);
 		if (raw_inode->i_size_high) {
 			struct super_block *sb = inode->i_sb;
-			struct ext2_super_block *es = sb->u.ext2_sb.s_es;
-			if (!(es->s_feature_ro_compat & cpu_to_le32(EXT2_FEATURE_RO_COMPAT_LARGE_FILE))) {
+			if (!EXT2_HAS_RO_COMPAT_FEATURE(sb,
+					EXT2_FEATURE_RO_COMPAT_LARGE_FILE) ||
+			    EXT2_SB(sb)->s_es->s_rev_level ==
+					cpu_to_le32(EXT2_GOOD_OLD_REV)) {
 			       /* If this is the first large file
 				* created, add a flag to the superblock.
 				*/
 				lock_kernel();
-				es->s_feature_ro_compat |= cpu_to_le32(EXT2_FEATURE_RO_COMPAT_LARGE_FILE);
+				ext2_update_fs_rev(sb);
+				EXT2_SET_RO_COMPAT_FEATURE(sb,
+					EXT2_FEATURE_RO_COMPAT_LARGE_FILE);
 				unlock_kernel();

ext2_write_super(sb);
}

fs/ext2/super.c +70 -36

162 lines not on this page · raw message

include/linux/ext2_fs.h +18 -4
diff -ru -x .[a-zA-Z1-9]* -x *flags linux-2.4.0-test11-pre7.orig/include/linux/ext2_fs.h linux-2.4.0-test11-pre7.compat/include/linux/ext2_fs.h
@@ -429,11 +429,23 @@
  */
 
 #define EXT2_HAS_COMPAT_FEATURE(sb,mask)			\
-	( EXT2_SB(sb)->s_feature_compat & (mask) )
+	( EXT2_SB(sb)->s_es->s_feature_compat & cpu_to_le32(mask) )
 #define EXT2_HAS_RO_COMPAT_FEATURE(sb,mask)			\
-	( EXT2_SB(sb)->s_feature_ro_compat & (mask) )
+	( EXT2_SB(sb)->s_es->s_feature_ro_compat & cpu_to_le32(mask) )
 #define EXT2_HAS_INCOMPAT_FEATURE(sb,mask)			\
-	( EXT2_SB(sb)->s_feature_incompat & (mask) )
+	( EXT2_SB(sb)->s_es->s_feature_incompat & cpu_to_le32(mask) )
+#define EXT2_SET_COMPAT_FEATURE(sb,mask)			\
+	EXT2_SB(sb)->s_es->s_feature_compat |= cpu_to_le32(mask)
+#define EXT2_SET_RO_COMPAT_FEATURE(sb,mask)			\
+	EXT2_SB(sb)->s_es->s_feature_ro_compat |= cpu_to_le32(mask)
+#define EXT2_SET_INCOMPAT_FEATURE(sb,mask)			\
+	EXT2_SB(sb)->s_es->s_feature_incompat |= cpu_to_le32(mask)
+#define EXT2_CLEAR_COMPAT_FEATURE(sb,mask)			\
+	EXT2_SB(sb)->s_es->s_feature_compat &= ~cpu_to_le32(mask)
+#define EXT2_CLEAR_RO_COMPAT_FEATURE(sb,mask)			\
+	EXT2_SB(sb)->s_es->s_feature_ro_compat &= ~cpu_to_le32(mask)
+#define EXT2_CLEAR_INCOMPAT_FEATURE(sb,mask)			\
+	EXT2_SB(sb)->s_es->s_feature_incompat &= ~cpu_to_le32(mask)
 
 #define EXT2_FEATURE_COMPAT_DIR_PREALLOC	0x0001
 
@@ -524,7 +536,8 @@
 extern int ext2_permission (struct inode *, int);
 
 /* balloc.c */
-extern int ext2_group_sparse(int group);
+extern int ext2_bg_has_super(struct super_block *sb, int group);
+extern unsigned long ext2_bg_num_gdb(struct super_block *sb, int group);
 extern int ext2_new_block (const struct inode *, unsigned long,
 			   __u32 *, __u32 *, int *);
 extern void ext2_free_blocks (const struct inode *, unsigned long,
@@ -583,6 +596,7 @@
 	__attribute__ ((NORET_AND format (printf, 3, 4)));
 extern void ext2_warning (struct super_block *, const char *, const char *, ...)
 	__attribute__ ((format (printf, 3, 4)));
+extern void ext2_update_fs_rev (struct super_block *sb);
 extern void ext2_put_super (struct super_block *);
 extern void ext2_write_super (struct super_block *);
 extern int ext2_remount (struct super_block *, int *, char *);
include/linux/ext2_fs_sb.h +1 -4
diff -ru -x .[a-zA-Z1-9]* -x *flags linux-2.4.0-test11-pre7.orig/include/linux/ext2_fs_sb.h linux-2.4.0-test11-pre7.compat/include/linux/ext2_fs_sb.h
@@ -35,7 +35,7 @@
 	unsigned long s_blocks_per_group;/* Number of blocks in a group */
 	unsigned long s_inodes_per_group;/* Number of inodes in a group */
 	unsigned long s_itb_per_group;	/* Number of inode table blocks per group */
-	unsigned long s_db_per_group;	/* Number of descriptor blocks per group */
+	unsigned long s_gdb_count;	/* Number of descriptor blocks */
 	unsigned long s_desc_per_block;	/* Number of group descriptors per block */
 	unsigned long s_groups_count;	/* Number of groups in the fs */
 	struct buffer_head * s_sbh;	/* Buffer containing the super block */
@@ -56,9 +56,6 @@
 	int s_desc_per_block_bits;
 	int s_inode_size;
 	int s_first_ino;
-	int s_feature_compat;
-	int s_feature_incompat;
-	int s_feature_ro_compat;
 };
 
 #endif	/* _LINUX_EXT2_FS_SB */
CREDITS +9 -0
diff -ru linux-2.4.0-test11-pre7.compat/CREDITS linux-2.4.0-test11-pre7/CREDITS
@@ -606,6 +606,15 @@
 S: Warrendale, Pennsylvania 15086
 S: USA
 
+N: Andreas Dilger
+E: [email protected]
+W: http://www-mddsp.enel.ucalgary.ca/People/adilger/
+D: Ext2 filesystem online resize capability
+D: Ext3/LVM hacking
+S: 630 Schooner Cove N.W.
+S: Calgary, AB
+S: Canada   T3L 1Z1
+
 N: Alex deVries
 E: [email protected]
 D: Various SGI parts, bits of HAL2 and Newport, PA-RISC Linux.
Documentation/Configure.help +14 -0
diff -ru linux-2.4.0-test11-pre7.compat/Documentation/Configure.help linux-2.4.0-test11-pre7/Documentation/Configure.help
@@ -10681,6 +10681,20 @@
   compiled as a module, and so this could be dangerous. Most everyone
   wants to say Y here.
 
+Online resize for ext2 filesystems
+CONFIG_EXT2_RESIZE
+  This option gives you the ability to increase the size of an ext2
+  filesystem while it is mounted (in use).  In order to do this, you
+  must also be able to resize the underlying disk partition, probably
+  via a Logical Volume Manager (LVM), metadevice (MD), or hardware
+  RAID device - none of that capability is included in this feature.
+  If you don't know what any of these things are, or you haven't
+  configured your kernel for them, you should probably say N here.  If
+  you choose Y, then your kernel will be about 3k larger, and you need
+  to get some more software (http://ext2resize.sourceforge.net/) in
+  order to actually resize your filesystem, otherwise this feature
+  will just sit unused inside the kernel.
+
 BFS file system support (EXPERIMENTAL)
 CONFIG_BFS_FS
   Boot File System (BFS) is a file system used under SCO UnixWare to
fs/Config.in +1 -0
diff -ru linux-2.4.0-test11-pre7.compat/fs/Config.in linux-2.4.0-test11-pre7/fs/Config.in
@@ -59,6 +59,7 @@
 tristate 'ROM file system support' CONFIG_ROMFS_FS
 
 tristate 'Second extended fs support' CONFIG_EXT2_FS
+dep_mbool '  Online ext2 resize support (DANGEROUS)' CONFIG_EXT2_RESIZE $CONFIG_EXT2_FS $CONFIG_EXPERIMENTAL
 
 tristate 'System V and Coherent file system support (read only)' CONFIG_SYSV_FS
 dep_mbool '  SYSV file system write support (DANGEROUS)' CONFIG_SYSV_FS_WRITE $CONFIG_SYSV_FS $CONFIG_EXPERIMENTAL
fs/ext2/balloc.c +4 -5
diff -ru linux-2.4.0-test11-pre7.compat/fs/ext2/balloc.c linux-2.4.0-test11-pre7/fs/ext2/balloc.c
@@ -619,13 +619,13 @@
 
 unsigned long ext2_count_free_blocks (struct super_block * sb)
 {
-#ifdef EXT2FS_DEBUG
 	struct ext2_super_block * es;
 	unsigned long desc_count, bitmap_count, x;
 	int bitmap_nr;
 	struct ext2_group_desc * gdp;
 	int i;
-	
+
+	if (test_opt(sb, DEBUG) && test_opt(sb, CHECK)) {
 	lock_super (sb);
 	es = sb->u.ext2_sb.s_es;
 	desc_count = 0;
@@ -646,13 +646,12 @@
 			i, le16_to_cpu(gdp->bg_free_blocks_count), x);
 		bitmap_count += x;
 	}
-	printk("ext2_count_free_blocks: stored = %lu, computed = %lu, %lu\n",
+	printk(__FUNCTION__": stored = %u, computed gdt = %lu, bitmap = %lu\n",
 	       le32_to_cpu(es->s_free_blocks_count), desc_count, bitmap_count);
 	unlock_super (sb);
 	return bitmap_count;
-#else
+	} else
 	return le32_to_cpu(sb->u.ext2_sb.s_es->s_free_blocks_count);
-#endif
 }
 
 static inline int block_in_use (unsigned long block,
fs/ext2/super.c +330 -45

496 lines not on this page · raw message

include/linux/ext2_fs.h +1 -0
diff -ru linux-2.4.0-test11-pre7.compat/include/linux/ext2_fs.h linux-2.4.0-test11-pre7/include/linux/ext2_fs.h
@@ -61,6 +61,7 @@
 #define EXT2_ACL_DATA_INO	 4	/* ACL inode */
 #define EXT2_BOOT_LOADER_INO	 5	/* Boot loader inode */
 #define EXT2_UNDEL_DIR_INO	 6	/* Undelete directory inode */
+#define EXT2_RESIZE_INO		 7	/* Reserved group descriptors inode */
 
 /* First non-reserved inode for old ext2 filesystems */
 #define EXT2_GOOD_OLD_FIRST_INO	11