linux-ext4.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/2] mke2fs: set free blocks accurately for groups has GDT
@ 2023-09-25  6:08 Li Dongyang
  2023-09-25  6:08 ` [PATCH 2/2] mke2fs: do not set the BLOCK_UNINIT on " Li Dongyang
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Li Dongyang @ 2023-09-25  6:08 UTC (permalink / raw)
  To: linux-ext4; +Cc: adilger

This patch is part of the preparation required to allow
GDT blocks expand beyond a single group,
it introduces 2 new interfaces:
- ext2fs_count_used_blocks(), to return the blocks used
in the bitmap range.
- ext2fs_reserve_super_and_bgd2() to return blocks used by
superblock/GDT blocks for every group, by looking up blocks used.

Signed-off-by: Li Dongyang <dongyangli@ddn.com>
---
 lib/ext2fs/alloc_sb.c     | 28 ++++++++++++++++++++++++++--
 lib/ext2fs/ext2fs.h       |  6 ++++++
 lib/ext2fs/gen_bitmap64.c | 17 +++++++++++++++--
 lib/ext2fs/initialize.c   | 30 ++++++++++++++++++++----------
 misc/mke2fs.c             |  2 +-
 5 files changed, 68 insertions(+), 15 deletions(-)

diff --git a/lib/ext2fs/alloc_sb.c b/lib/ext2fs/alloc_sb.c
index 8530b40f6..e92739ecc 100644
--- a/lib/ext2fs/alloc_sb.c
+++ b/lib/ext2fs/alloc_sb.c
@@ -46,8 +46,7 @@ int ext2fs_reserve_super_and_bgd(ext2_filsys fs,
 				 ext2fs_block_bitmap bmap)
 {
 	blk64_t	super_blk, old_desc_blk, new_desc_blk;
-	blk_t	used_blks;
-	int	old_desc_blocks, num_blocks;
+	blk_t	used_blks, old_desc_blocks, num_blocks;
 
 	ext2fs_super_and_bgd_loc2(fs, group, &super_blk,
 				  &old_desc_blk, &new_desc_blk, &used_blks);
@@ -79,3 +78,28 @@ int ext2fs_reserve_super_and_bgd(ext2_filsys fs,
 
 	return num_blocks  ;
 }
+
+/*
+ * This function reserves the superblock and block group descriptors
+ * for a given block group and returns the number of blocks used by the
+ * super block and group descriptors by looking up the block bitmap.
+ */
+errcode_t ext2fs_reserve_super_and_bgd2(ext2_filsys fs,
+				        dgrp_t group,
+				        ext2fs_block_bitmap bmap,
+				        blk_t *desc_blocks)
+{
+	blk64_t	num_blocks;
+	errcode_t retval = 0;
+
+	ext2fs_reserve_super_and_bgd(fs, group, bmap);
+
+	retval = ext2fs_count_used_blocks(fs,
+					ext2fs_group_first_block2(fs, group),
+					ext2fs_group_last_block2(fs, group),
+					&num_blocks);
+	if (!retval)
+		*desc_blocks = num_blocks;
+
+	return retval;
+}
diff --git a/lib/ext2fs/ext2fs.h b/lib/ext2fs/ext2fs.h
index 72c60d2b5..ae79a3443 100644
--- a/lib/ext2fs/ext2fs.h
+++ b/lib/ext2fs/ext2fs.h
@@ -795,6 +795,10 @@ errcode_t ext2fs_alloc_range(ext2_filsys fs, int flags, blk64_t goal,
 extern int ext2fs_reserve_super_and_bgd(ext2_filsys fs,
 					dgrp_t group,
 					ext2fs_block_bitmap bmap);
+extern errcode_t ext2fs_reserve_super_and_bgd2(ext2_filsys fs,
+					       dgrp_t group,
+					       ext2fs_block_bitmap bmap,
+					       blk_t *desc_blocks);
 extern void ext2fs_set_block_alloc_stats_callback(ext2_filsys fs,
 						  void (*func)(ext2_filsys fs,
 							       blk64_t blk,
@@ -1483,6 +1487,8 @@ errcode_t ext2fs_convert_subcluster_bitmap(ext2_filsys fs,
 					   ext2fs_block_bitmap *bitmap);
 errcode_t ext2fs_count_used_clusters(ext2_filsys fs, blk64_t start,
 				     blk64_t end, blk64_t *out);
+errcode_t ext2fs_count_used_blocks(ext2_filsys fs, blk64_t start,
+				   blk64_t end, blk64_t *out);
 
 /* get_num_dirs.c */
 extern errcode_t ext2fs_get_num_dirs(ext2_filsys fs, ext2_ino_t *ret_num_dirs);
diff --git a/lib/ext2fs/gen_bitmap64.c b/lib/ext2fs/gen_bitmap64.c
index 4289e8155..5936dcf53 100644
--- a/lib/ext2fs/gen_bitmap64.c
+++ b/lib/ext2fs/gen_bitmap64.c
@@ -945,8 +945,8 @@ errcode_t ext2fs_find_first_set_generic_bmap(ext2fs_generic_bitmap bitmap,
 	return ENOENT;
 }
 
-errcode_t ext2fs_count_used_clusters(ext2_filsys fs, blk64_t start,
-				     blk64_t end, blk64_t *out)
+errcode_t ext2fs_count_used_blocks(ext2_filsys fs, blk64_t start,
+				   blk64_t end, blk64_t *out)
 {
 	blk64_t		next;
 	blk64_t		tot_set = 0;
@@ -975,6 +975,19 @@ errcode_t ext2fs_count_used_clusters(ext2_filsys fs, blk64_t start,
 			break;
 	}
 
+	if (!retval)
+		*out = tot_set;
+	return retval;
+}
+
+errcode_t ext2fs_count_used_clusters(ext2_filsys fs, blk64_t start,
+				     blk64_t end, blk64_t *out)
+{
+	blk64_t		tot_set = 0;
+	errcode_t	retval = 0;
+
+	retval = ext2fs_count_used_blocks(fs, start, end, &tot_set);
+
 	if (!retval)
 		*out = EXT2FS_NUM_B2C(fs, tot_set);
 	return retval;
diff --git a/lib/ext2fs/initialize.c b/lib/ext2fs/initialize.c
index edd692bb9..90012f732 100644
--- a/lib/ext2fs/initialize.c
+++ b/lib/ext2fs/initialize.c
@@ -521,6 +521,15 @@ ipg_retry:
 	csum_flag = ext2fs_has_group_desc_csum(fs);
 	reserved_inos = super->s_first_ino;
 	for (i = 0; i < fs->group_desc_count; i++) {
+		blk_t grp_free_blocks;
+		ext2_ino_t inodes;
+
+		retval = ext2fs_reserve_super_and_bgd2(fs, i,
+						       fs->block_map,
+						       &numblocks);
+		if (retval)
+			goto cleanup;
+
 		/*
 		 * Don't set the BLOCK_UNINIT group for the last group
 		 * because the block bitmap needs to be padded.
@@ -530,24 +539,25 @@ ipg_retry:
 				ext2fs_bg_flags_set(fs, i,
 						    EXT2_BG_BLOCK_UNINIT);
 			ext2fs_bg_flags_set(fs, i, EXT2_BG_INODE_UNINIT);
-			numblocks = super->s_inodes_per_group;
+			inodes = super->s_inodes_per_group;
 			if (reserved_inos) {
-				if (numblocks > reserved_inos) {
-					numblocks -= reserved_inos;
+				if (inodes > reserved_inos) {
+					inodes -= reserved_inos;
 					reserved_inos = 0;
 				} else {
-					reserved_inos -= numblocks;
-					numblocks = 0;
+					reserved_inos -= inodes;
+					inodes = 0;
 				}
 			}
-			ext2fs_bg_itable_unused_set(fs, i, numblocks);
+			ext2fs_bg_itable_unused_set(fs, i, inodes);
 		}
-		numblocks = ext2fs_reserve_super_and_bgd(fs, i, fs->block_map);
-		if (fs->super->s_log_groups_per_flex)
+
+		if (!fs->super->s_log_groups_per_flex)
 			numblocks += 2 + fs->inode_blocks_per_group;
 
-		free_blocks += numblocks;
-		ext2fs_bg_free_blocks_count_set(fs, i, numblocks);
+		grp_free_blocks = ext2fs_group_blocks_count(fs, i) - numblocks;
+		free_blocks += grp_free_blocks;
+		ext2fs_bg_free_blocks_count_set(fs, i, grp_free_blocks);
 		ext2fs_bg_free_inodes_count_set(fs, i, fs->super->s_inodes_per_group);
 		ext2fs_bg_used_dirs_count_set(fs, i, 0);
 		ext2fs_group_desc_csum_set(fs, i);
diff --git a/misc/mke2fs.c b/misc/mke2fs.c
index 4a9c1b092..72c9da12e 100644
--- a/misc/mke2fs.c
+++ b/misc/mke2fs.c
@@ -3522,7 +3522,7 @@ no_journal:
 			       fs->super->s_mmp_update_interval);
 	}
 
-	overhead += fs->super->s_first_data_block;
+	overhead += EXT2FS_NUM_B2C(fs, fs->super->s_first_data_block);
 	if (!super_only)
 		fs->super->s_overhead_clusters = overhead;
 
-- 
2.41.0


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 2/2] mke2fs: do not set the BLOCK_UNINIT on groups has GDT
  2023-09-25  6:08 [PATCH 1/2] mke2fs: set free blocks accurately for groups has GDT Li Dongyang
@ 2023-09-25  6:08 ` Li Dongyang
  2023-09-26 20:46   ` Andreas Dilger
  2023-09-26 20:47 ` [PATCH 1/2] mke2fs: set free blocks accurately for " Andreas Dilger
  2024-04-17  2:03 ` Theodore Ts'o
  2 siblings, 1 reply; 5+ messages in thread
From: Li Dongyang @ 2023-09-25  6:08 UTC (permalink / raw)
  To: linux-ext4; +Cc: adilger

This patch prepares the expansion of GDT blocks beyond a
single group, by make mke2fs to not set BLOCK_UNINIT on
groups with GDT blocks, block/inode bitmaps, or inode table
blocks allocated.

Otherwise, we still rely on kernel side to initialize the
block bitmap if the groups has BLOCK_UNINIT set, and the
kernel doesn't know a group could have GDT blocks allocated,
so it would make an bad block bitmap.

As a result, expect output of several tests needs to be changed,
especially if the test uses dumpe2fs to print the group summary.

Signed-off-by: Li Dongyang <dongyangli@ddn.com>
---
 lib/ext2fs/initialize.c                        |  2 +-
 tests/j_ext_long_trans/expect                  |  2 +-
 tests/j_long_trans/expect                      |  2 +-
 tests/j_long_trans_mcsum_32bit/expect          |  2 +-
 tests/j_long_trans_mcsum_64bit/expect          |  2 +-
 tests/j_short_trans_mcsum_64bit/expect         |  2 +-
 tests/j_short_trans_recover_mcsum_64bit/expect |  2 +-
 tests/m_bigjournal/expect.1                    | 16 ++++++++--------
 tests/m_resize_inode_meta_bg/expect.1          |  6 +++---
 tests/m_uninit/expect.1                        | 10 +++++-----
 10 files changed, 23 insertions(+), 23 deletions(-)

diff --git a/lib/ext2fs/initialize.c b/lib/ext2fs/initialize.c
index 90012f732..5560cd3f8 100644
--- a/lib/ext2fs/initialize.c
+++ b/lib/ext2fs/initialize.c
@@ -535,7 +535,7 @@ ipg_retry:
 		 * because the block bitmap needs to be padded.
 		 */
 		if (csum_flag) {
-			if (i != fs->group_desc_count - 1)
+			if (i != fs->group_desc_count - 1 && numblocks == 0)
 				ext2fs_bg_flags_set(fs, i,
 						    EXT2_BG_BLOCK_UNINIT);
 			ext2fs_bg_flags_set(fs, i, EXT2_BG_INODE_UNINIT);
diff --git a/tests/j_ext_long_trans/expect b/tests/j_ext_long_trans/expect
index ea3c87fcb..b95aa9bc2 100644
--- a/tests/j_ext_long_trans/expect
+++ b/tests/j_ext_long_trans/expect
@@ -77,7 +77,7 @@ Root inode not allocated.  Allocate? yes
 
 Pass 4: Checking reference counts
 Pass 5: Checking group summary information
-Block bitmap differences:  +(1--259) +275 +(291--418) +2341
+Block bitmap differences:  +(1--260) +262 +264 +266 +268 +(275--276) +278 +280 +282 +284 +(291--546) +(675--802) +(931--1058) +(1187--1314) +(1443--1570) +2341 +(8193--8450) +(24577--24834) +(40961--41218) +(57345--57602) +(73729--73986)
 Fix? yes
 
 Free blocks count wrong for group #0 (5838, counted=5851).
diff --git a/tests/j_long_trans/expect b/tests/j_long_trans/expect
index 82b3caf17..ee7af96ab 100644
--- a/tests/j_long_trans/expect
+++ b/tests/j_long_trans/expect
@@ -72,7 +72,7 @@ Root inode not allocated.  Allocate? yes
 
 Pass 4: Checking reference counts
 Pass 5: Checking group summary information
-Block bitmap differences:  +(1--259) +273 +275 +289 +(291--418) +(2083--2210) +2341
+Block bitmap differences:  +(1--260) +262 +264 +266 +268 +273 +(275--276) +278 +280 +282 +284 +289 +(291--546) +(675--802) +(931--1058) +(1187--1314) +(1443--1570) +(2083--2210) +2341 +(8193--8450) +(24577--24834) +(40961--41218) +(57345--57602) +(73729--73986)
 Fix? yes
 
 Free blocks count wrong for group #0 (5838, counted=5851).
diff --git a/tests/j_long_trans_mcsum_32bit/expect b/tests/j_long_trans_mcsum_32bit/expect
index ffae07a69..0b6cf499c 100644
--- a/tests/j_long_trans_mcsum_32bit/expect
+++ b/tests/j_long_trans_mcsum_32bit/expect
@@ -108,7 +108,7 @@ Root inode not allocated.  Allocate? yes
 
 Pass 4: Checking reference counts
 Pass 5: Checking group summary information
-Block bitmap differences:  +(1--260) +276 +(292--419) +2342 -(139265--155648)
+Block bitmap differences:  +(1--261) +263 +265 +267 +269 +(276--277) +279 +281 +283 +285 +(292--547) +(676--803) +(932--1059) +(1188--1315) +(1444--1571) +2342 +(8193--8451) +(24577--24835) +(40961--41219) +(57345--57603) +(73729--73987) -(139265--155648)
 Fix? yes
 
 Free blocks count wrong for group #0 (5837, counted=5850).
diff --git a/tests/j_long_trans_mcsum_64bit/expect b/tests/j_long_trans_mcsum_64bit/expect
index e891def16..b520c91bc 100644
--- a/tests/j_long_trans_mcsum_64bit/expect
+++ b/tests/j_long_trans_mcsum_64bit/expect
@@ -107,7 +107,7 @@ Root inode not allocated.  Allocate? yes
 
 Pass 4: Checking reference counts
 Pass 5: Checking group summary information
-Block bitmap differences:  +(1--262) +278 +(294--421) +2344 -(139265--155648)
+Block bitmap differences:  +(1--263) +265 +267 +269 +271 +(278--279) +281 +283 +285 +287 +(294--549) +(678--805) +(934--1061) +(1190--1317) +(1446--1573) +2344 +(8193--8453) +(24577--24837) +(40961--41221) +(57345--57605) +(73729--73989) -(139265--155648)
 Fix? yes
 
 Free blocks count wrong for group #0 (5835, counted=5848).
diff --git a/tests/j_short_trans_mcsum_64bit/expect b/tests/j_short_trans_mcsum_64bit/expect
index d73e28297..5a4f5b94b 100644
--- a/tests/j_short_trans_mcsum_64bit/expect
+++ b/tests/j_short_trans_mcsum_64bit/expect
@@ -28,7 +28,7 @@ Pass 2: Checking directory structure
 Pass 3: Checking directory connectivity
 Pass 4: Checking reference counts
 Pass 5: Checking group summary information
-Block bitmap differences:  +(0--65) +(67--69) +(71--584) +(1097--2126) +(65536--69631) +(98304--98368)
+Block bitmap differences:  +(0--2126) +(32768--32832) +(65536--69631) +(98304--98368)
 Fix? yes
 
 Inode bitmap differences:  +(1--11)
diff --git a/tests/j_short_trans_recover_mcsum_64bit/expect b/tests/j_short_trans_recover_mcsum_64bit/expect
index 8c637f122..7139fd80a 100644
--- a/tests/j_short_trans_recover_mcsum_64bit/expect
+++ b/tests/j_short_trans_recover_mcsum_64bit/expect
@@ -30,7 +30,7 @@ Pass 2: Checking directory structure
 Pass 3: Checking directory connectivity
 Pass 4: Checking reference counts
 Pass 5: Checking group summary information
-Block bitmap differences:  +(0--65) +(67--69) +(71--584) +(1097--2126) +(65536--69631) +(98304--98368)
+Block bitmap differences:  +(0--2126) +(32768--32832) +(65536--69631) +(98304--98368)
 Fix? yes
 
 Inode bitmap differences:  +(1--11)
diff --git a/tests/m_bigjournal/expect.1 b/tests/m_bigjournal/expect.1
index eb0e3bc38..4e6674665 100644
--- a/tests/m_bigjournal/expect.1
+++ b/tests/m_bigjournal/expect.1
@@ -58,7 +58,7 @@ Group 0: (Blocks 0-32767)
   31837 free blocks, 5 free inodes, 2 directories, 5 unused inodes
   Free blocks: 931-32767
   Free inodes: 12-16
-Group 1: (Blocks 32768-65535) [INODE_UNINIT, BLOCK_UNINIT]
+Group 1: (Blocks 32768-65535) [INODE_UNINIT]
   Backup superblock at 32768, Group descriptors at 32769-32769
   Reserved GDT blocks at 32770-33440
   Block bitmap at 674 (bg #0 + 674), Inode bitmap at 758 (bg #0 + 758)
@@ -72,7 +72,7 @@ Group 2: (Blocks 65536-98303) [INODE_UNINIT, BLOCK_UNINIT]
   32768 free blocks, 16 free inodes, 0 directories, 16 unused inodes
   Free blocks: 65536-98303
   Free inodes: 33-48
-Group 3: (Blocks 98304-131071) [INODE_UNINIT, BLOCK_UNINIT]
+Group 3: (Blocks 98304-131071) [INODE_UNINIT]
   Backup superblock at 98304, Group descriptors at 98305-98305
   Reserved GDT blocks at 98306-98976
   Block bitmap at 676 (bg #0 + 676), Inode bitmap at 760 (bg #0 + 760)
@@ -86,7 +86,7 @@ Group 4: (Blocks 131072-163839) [INODE_UNINIT, BLOCK_UNINIT]
   32768 free blocks, 16 free inodes, 0 directories, 16 unused inodes
   Free blocks: 131072-163839
   Free inodes: 65-80
-Group 5: (Blocks 163840-196607) [INODE_UNINIT, BLOCK_UNINIT]
+Group 5: (Blocks 163840-196607) [INODE_UNINIT]
   Backup superblock at 163840, Group descriptors at 163841-163841
   Reserved GDT blocks at 163842-164512
   Block bitmap at 678 (bg #0 + 678), Inode bitmap at 762 (bg #0 + 762)
@@ -100,7 +100,7 @@ Group 6: (Blocks 196608-229375) [INODE_UNINIT, BLOCK_UNINIT]
   32768 free blocks, 16 free inodes, 0 directories, 16 unused inodes
   Free blocks: 196608-229375
   Free inodes: 97-112
-Group 7: (Blocks 229376-262143) [INODE_UNINIT, BLOCK_UNINIT]
+Group 7: (Blocks 229376-262143) [INODE_UNINIT]
   Backup superblock at 229376, Group descriptors at 229377-229377
   Reserved GDT blocks at 229378-230048
   Block bitmap at 680 (bg #0 + 680), Inode bitmap at 764 (bg #0 + 764)
@@ -114,7 +114,7 @@ Group 8: (Blocks 262144-294911) [INODE_UNINIT, BLOCK_UNINIT]
   32768 free blocks, 16 free inodes, 0 directories, 16 unused inodes
   Free blocks: 262144-294911
   Free inodes: 129-144
-Group 9: (Blocks 294912-327679) [INODE_UNINIT, BLOCK_UNINIT]
+Group 9: (Blocks 294912-327679) [INODE_UNINIT]
   Backup superblock at 294912, Group descriptors at 294913-294913
   Reserved GDT blocks at 294914-295584
   Block bitmap at 682 (bg #0 + 682), Inode bitmap at 766 (bg #0 + 766)
@@ -212,7 +212,7 @@ Group 24: (Blocks 786432-819199) [INODE_UNINIT, BLOCK_UNINIT]
   32768 free blocks, 16 free inodes, 0 directories, 16 unused inodes
   Free blocks: 786432-819199
   Free inodes: 385-400
-Group 25: (Blocks 819200-851967) [INODE_UNINIT, BLOCK_UNINIT]
+Group 25: (Blocks 819200-851967) [INODE_UNINIT]
   Backup superblock at 819200, Group descriptors at 819201-819201
   Reserved GDT blocks at 819202-819872
   Block bitmap at 698 (bg #0 + 698), Inode bitmap at 782 (bg #0 + 782)
@@ -226,7 +226,7 @@ Group 26: (Blocks 851968-884735) [INODE_UNINIT, BLOCK_UNINIT]
   32768 free blocks, 16 free inodes, 0 directories, 16 unused inodes
   Free blocks: 851968-884735
   Free inodes: 417-432
-Group 27: (Blocks 884736-917503) [INODE_UNINIT, BLOCK_UNINIT]
+Group 27: (Blocks 884736-917503) [INODE_UNINIT]
   Backup superblock at 884736, Group descriptors at 884737-884737
   Reserved GDT blocks at 884738-885408
   Block bitmap at 700 (bg #0 + 700), Inode bitmap at 784 (bg #0 + 784)
@@ -554,7 +554,7 @@ Group 80: (Blocks 2621440-2654207) [INODE_UNINIT, BLOCK_UNINIT]
   32768 free blocks, 16 free inodes, 0 directories, 16 unused inodes
   Free blocks: 2621440-2654207
   Free inodes: 1281-1296
-Group 81: (Blocks 2654208-2686975) [INODE_UNINIT, BLOCK_UNINIT]
+Group 81: (Blocks 2654208-2686975) [INODE_UNINIT]
   Backup superblock at 2654208, Group descriptors at 2654209-2654209
   Reserved GDT blocks at 2654210-2654880
   Block bitmap at 754 (bg #0 + 754), Inode bitmap at 838 (bg #0 + 838)
diff --git a/tests/m_resize_inode_meta_bg/expect.1 b/tests/m_resize_inode_meta_bg/expect.1
index 7feaed9d8..83c7bc57c 100644
--- a/tests/m_resize_inode_meta_bg/expect.1
+++ b/tests/m_resize_inode_meta_bg/expect.1
@@ -67,7 +67,7 @@ Group 0: (Blocks 0-255) [ITABLE_ZEROED]
   159 free blocks, 53 free inodes, 2 directories, 53 unused inodes
   Free blocks: 97-255
   Free inodes: 12-64
-Group 1: (Blocks 256-511) [INODE_UNINIT, BLOCK_UNINIT, ITABLE_ZEROED]
+Group 1: (Blocks 256-511) [INODE_UNINIT, ITABLE_ZEROED]
   Backup superblock at 256, Group descriptor at 257
   Block bitmap at 3 (bg #0 + 3)
   Inode bitmap at 18 (bg #0 + 18)
@@ -82,7 +82,7 @@ Group 2: (Blocks 512-767) [INODE_UNINIT, BLOCK_UNINIT, ITABLE_ZEROED]
   256 free blocks, 64 free inodes, 0 directories, 64 unused inodes
   Free blocks: 512-767
   Free inodes: 129-192
-Group 3: (Blocks 768-1023) [INODE_UNINIT, BLOCK_UNINIT, ITABLE_ZEROED]
+Group 3: (Blocks 768-1023) [INODE_UNINIT, ITABLE_ZEROED]
   Backup superblock at 768
   Block bitmap at 5 (bg #0 + 5)
   Inode bitmap at 20 (bg #0 + 20)
@@ -97,7 +97,7 @@ Group 4: (Blocks 1024-1279) [INODE_UNINIT, BLOCK_UNINIT, ITABLE_ZEROED]
   256 free blocks, 64 free inodes, 0 directories, 64 unused inodes
   Free blocks: 1024-1279
   Free inodes: 257-320
-Group 5: (Blocks 1280-1535) [INODE_UNINIT, BLOCK_UNINIT, ITABLE_ZEROED]
+Group 5: (Blocks 1280-1535) [INODE_UNINIT, ITABLE_ZEROED]
   Backup superblock at 1280
   Block bitmap at 7 (bg #0 + 7)
   Inode bitmap at 22 (bg #0 + 22)
diff --git a/tests/m_uninit/expect.1 b/tests/m_uninit/expect.1
index 3c2875527..2058de7a9 100644
--- a/tests/m_uninit/expect.1
+++ b/tests/m_uninit/expect.1
@@ -56,7 +56,7 @@ Group 0: (Blocks 1-8192) [ITABLE_ZEROED]
   7406 free blocks, 2037 free inodes, 2 directories, 2037 unused inodes
   Free blocks: 787-8192
   Free inodes: 12-2048
-Group 1: (Blocks 8193-16384) [INODE_UNINIT, BLOCK_UNINIT, ITABLE_ZEROED]
+Group 1: (Blocks 8193-16384) [INODE_UNINIT, ITABLE_ZEROED]
   Backup superblock at 8193, Group descriptors at 8194-8194
   Reserved GDT blocks at 8195-8450
   Block bitmap at 8451 (+258), Inode bitmap at 8452 (+259)
@@ -70,7 +70,7 @@ Group 2: (Blocks 16385-24576) [INODE_UNINIT, BLOCK_UNINIT, ITABLE_ZEROED]
   7678 free blocks, 2048 free inodes, 0 directories, 2048 unused inodes
   Free blocks: 16899-24576
   Free inodes: 4097-6144
-Group 3: (Blocks 24577-32768) [INODE_UNINIT, BLOCK_UNINIT, ITABLE_ZEROED]
+Group 3: (Blocks 24577-32768) [INODE_UNINIT, ITABLE_ZEROED]
   Backup superblock at 24577, Group descriptors at 24578-24578
   Reserved GDT blocks at 24579-24834
   Block bitmap at 24835 (+258), Inode bitmap at 24836 (+259)
@@ -84,7 +84,7 @@ Group 4: (Blocks 32769-40960) [INODE_UNINIT, BLOCK_UNINIT, ITABLE_ZEROED]
   7678 free blocks, 2048 free inodes, 0 directories, 2048 unused inodes
   Free blocks: 33283-40960
   Free inodes: 8193-10240
-Group 5: (Blocks 40961-49152) [INODE_UNINIT, BLOCK_UNINIT, ITABLE_ZEROED]
+Group 5: (Blocks 40961-49152) [INODE_UNINIT, ITABLE_ZEROED]
   Backup superblock at 40961, Group descriptors at 40962-40962
   Reserved GDT blocks at 40963-41218
   Block bitmap at 41219 (+258), Inode bitmap at 41220 (+259)
@@ -98,7 +98,7 @@ Group 6: (Blocks 49153-57344) [INODE_UNINIT, BLOCK_UNINIT, ITABLE_ZEROED]
   7678 free blocks, 2048 free inodes, 0 directories, 2048 unused inodes
   Free blocks: 49667-57344
   Free inodes: 12289-14336
-Group 7: (Blocks 57345-65536) [INODE_UNINIT, BLOCK_UNINIT, ITABLE_ZEROED]
+Group 7: (Blocks 57345-65536) [INODE_UNINIT, ITABLE_ZEROED]
   Backup superblock at 57345, Group descriptors at 57346-57346
   Reserved GDT blocks at 57347-57602
   Block bitmap at 57603 (+258), Inode bitmap at 57604 (+259)
@@ -112,7 +112,7 @@ Group 8: (Blocks 65537-73728) [INODE_UNINIT, BLOCK_UNINIT, ITABLE_ZEROED]
   7678 free blocks, 2048 free inodes, 0 directories, 2048 unused inodes
   Free blocks: 66051-73728
   Free inodes: 16385-18432
-Group 9: (Blocks 73729-81920) [INODE_UNINIT, BLOCK_UNINIT, ITABLE_ZEROED]
+Group 9: (Blocks 73729-81920) [INODE_UNINIT, ITABLE_ZEROED]
   Backup superblock at 73729, Group descriptors at 73730-73730
   Reserved GDT blocks at 73731-73986
   Block bitmap at 73987 (+258), Inode bitmap at 73988 (+259)
-- 
2.41.0


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH 2/2] mke2fs: do not set the BLOCK_UNINIT on groups has GDT
  2023-09-25  6:08 ` [PATCH 2/2] mke2fs: do not set the BLOCK_UNINIT on " Li Dongyang
@ 2023-09-26 20:46   ` Andreas Dilger
  0 siblings, 0 replies; 5+ messages in thread
From: Andreas Dilger @ 2023-09-26 20:46 UTC (permalink / raw)
  To: Li Dongyang; +Cc: Ext4 Developers List

[-- Attachment #1: Type: text/plain, Size: 15468 bytes --]

On Sep 25, 2023, at 12:08 AM, Li Dongyang <dongyangli@ddn.com> wrote:
> 
> This patch prepares the expansion of GDT blocks beyond a
> single group, by make mke2fs to not set BLOCK_UNINIT on
> groups with GDT blocks, block/inode bitmaps, or inode table
> blocks allocated.
> 
> Otherwise, we still rely on kernel side to initialize the
> block bitmap if the groups has BLOCK_UNINIT set, and the
> kernel doesn't know a group could have GDT blocks allocated,
> so it would make an bad block bitmap.
> 
> As a result, expect output of several tests needs to be changed,
> especially if the test uses dumpe2fs to print the group summary.
> 
> Signed-off-by: Li Dongyang <dongyangli@ddn.com>

AFAIK, this patch is totally fine to use even in the absence
of the large GDT functionality.  It just avoids setting the
BLOCK_UNINIT on any groups that have GDT blocks allocated, and
is making life a bit simpler for the kernel online resize.

At most this is 45 groups' block bitmaps, even for a 576PB
filesystem that is maxing out the 32-bit group descriptor limit.

Reviewed-by: Andreas Dilger <adilger@dilger.ca>

> ---
> lib/ext2fs/initialize.c                        |  2 +-
> tests/j_ext_long_trans/expect                  |  2 +-
> tests/j_long_trans/expect                      |  2 +-
> tests/j_long_trans_mcsum_32bit/expect          |  2 +-
> tests/j_long_trans_mcsum_64bit/expect          |  2 +-
> tests/j_short_trans_mcsum_64bit/expect         |  2 +-
> tests/j_short_trans_recover_mcsum_64bit/expect |  2 +-
> tests/m_bigjournal/expect.1                    | 16 ++++++++--------
> tests/m_resize_inode_meta_bg/expect.1          |  6 +++---
> tests/m_uninit/expect.1                        | 10 +++++-----
> 10 files changed, 23 insertions(+), 23 deletions(-)
> 
> diff --git a/lib/ext2fs/initialize.c b/lib/ext2fs/initialize.c
> index 90012f732..5560cd3f8 100644
> --- a/lib/ext2fs/initialize.c
> +++ b/lib/ext2fs/initialize.c
> @@ -535,7 +535,7 @@ ipg_retry:
> 		 * because the block bitmap needs to be padded.
> 		 */
> 		if (csum_flag) {
> -			if (i != fs->group_desc_count - 1)
> +			if (i != fs->group_desc_count - 1 && numblocks == 0)
> 				ext2fs_bg_flags_set(fs, i,
> 						    EXT2_BG_BLOCK_UNINIT);
> 			ext2fs_bg_flags_set(fs, i, EXT2_BG_INODE_UNINIT);
> diff --git a/tests/j_ext_long_trans/expect b/tests/j_ext_long_trans/expect
> index ea3c87fcb..b95aa9bc2 100644
> --- a/tests/j_ext_long_trans/expect
> +++ b/tests/j_ext_long_trans/expect
> @@ -77,7 +77,7 @@ Root inode not allocated.  Allocate? yes
> 
> Pass 4: Checking reference counts
> Pass 5: Checking group summary information
> -Block bitmap differences:  +(1--259) +275 +(291--418) +2341
> +Block bitmap differences:  +(1--260) +262 +264 +266 +268 +(275--276) +278 +280 +282 +284 +(291--546) +(675--802) +(931--1058) +(1187--1314) +(1443--1570) +2341 +(8193--8450) +(24577--24834) +(40961--41218) +(57345--57602) +(73729--73986)
> Fix? yes
> 
> Free blocks count wrong for group #0 (5838, counted=5851).
> diff --git a/tests/j_long_trans/expect b/tests/j_long_trans/expect
> index 82b3caf17..ee7af96ab 100644
> --- a/tests/j_long_trans/expect
> +++ b/tests/j_long_trans/expect
> @@ -72,7 +72,7 @@ Root inode not allocated.  Allocate? yes
> 
> Pass 4: Checking reference counts
> Pass 5: Checking group summary information
> -Block bitmap differences:  +(1--259) +273 +275 +289 +(291--418) +(2083--2210) +2341
> +Block bitmap differences:  +(1--260) +262 +264 +266 +268 +273 +(275--276) +278 +280 +282 +284 +289 +(291--546) +(675--802) +(931--1058) +(1187--1314) +(1443--1570) +(2083--2210) +2341 +(8193--8450) +(24577--24834) +(40961--41218) +(57345--57602) +(73729--73986)
> Fix? yes
> 
> Free blocks count wrong for group #0 (5838, counted=5851).
> diff --git a/tests/j_long_trans_mcsum_32bit/expect b/tests/j_long_trans_mcsum_32bit/expect
> index ffae07a69..0b6cf499c 100644
> --- a/tests/j_long_trans_mcsum_32bit/expect
> +++ b/tests/j_long_trans_mcsum_32bit/expect
> @@ -108,7 +108,7 @@ Root inode not allocated.  Allocate? yes
> 
> Pass 4: Checking reference counts
> Pass 5: Checking group summary information
> -Block bitmap differences:  +(1--260) +276 +(292--419) +2342 -(139265--155648)
> +Block bitmap differences:  +(1--261) +263 +265 +267 +269 +(276--277) +279 +281 +283 +285 +(292--547) +(676--803) +(932--1059) +(1188--1315) +(1444--1571) +2342 +(8193--8451) +(24577--24835) +(40961--41219) +(57345--57603) +(73729--73987) -(139265--155648)
> Fix? yes
> 
> Free blocks count wrong for group #0 (5837, counted=5850).
> diff --git a/tests/j_long_trans_mcsum_64bit/expect b/tests/j_long_trans_mcsum_64bit/expect
> index e891def16..b520c91bc 100644
> --- a/tests/j_long_trans_mcsum_64bit/expect
> +++ b/tests/j_long_trans_mcsum_64bit/expect
> @@ -107,7 +107,7 @@ Root inode not allocated.  Allocate? yes
> 
> Pass 4: Checking reference counts
> Pass 5: Checking group summary information
> -Block bitmap differences:  +(1--262) +278 +(294--421) +2344 -(139265--155648)
> +Block bitmap differences:  +(1--263) +265 +267 +269 +271 +(278--279) +281 +283 +285 +287 +(294--549) +(678--805) +(934--1061) +(1190--1317) +(1446--1573) +2344 +(8193--8453) +(24577--24837) +(40961--41221) +(57345--57605) +(73729--73989) -(139265--155648)
> Fix? yes
> 
> Free blocks count wrong for group #0 (5835, counted=5848).
> diff --git a/tests/j_short_trans_mcsum_64bit/expect b/tests/j_short_trans_mcsum_64bit/expect
> index d73e28297..5a4f5b94b 100644
> --- a/tests/j_short_trans_mcsum_64bit/expect
> +++ b/tests/j_short_trans_mcsum_64bit/expect
> @@ -28,7 +28,7 @@ Pass 2: Checking directory structure
> Pass 3: Checking directory connectivity
> Pass 4: Checking reference counts
> Pass 5: Checking group summary information
> -Block bitmap differences:  +(0--65) +(67--69) +(71--584) +(1097--2126) +(65536--69631) +(98304--98368)
> +Block bitmap differences:  +(0--2126) +(32768--32832) +(65536--69631) +(98304--98368)
> Fix? yes
> 
> Inode bitmap differences:  +(1--11)
> diff --git a/tests/j_short_trans_recover_mcsum_64bit/expect b/tests/j_short_trans_recover_mcsum_64bit/expect
> index 8c637f122..7139fd80a 100644
> --- a/tests/j_short_trans_recover_mcsum_64bit/expect
> +++ b/tests/j_short_trans_recover_mcsum_64bit/expect
> @@ -30,7 +30,7 @@ Pass 2: Checking directory structure
> Pass 3: Checking directory connectivity
> Pass 4: Checking reference counts
> Pass 5: Checking group summary information
> -Block bitmap differences:  +(0--65) +(67--69) +(71--584) +(1097--2126) +(65536--69631) +(98304--98368)
> +Block bitmap differences:  +(0--2126) +(32768--32832) +(65536--69631) +(98304--98368)
> Fix? yes
> 
> Inode bitmap differences:  +(1--11)
> diff --git a/tests/m_bigjournal/expect.1 b/tests/m_bigjournal/expect.1
> index eb0e3bc38..4e6674665 100644
> --- a/tests/m_bigjournal/expect.1
> +++ b/tests/m_bigjournal/expect.1
> @@ -58,7 +58,7 @@ Group 0: (Blocks 0-32767)
>   31837 free blocks, 5 free inodes, 2 directories, 5 unused inodes
>   Free blocks: 931-32767
>   Free inodes: 12-16
> -Group 1: (Blocks 32768-65535) [INODE_UNINIT, BLOCK_UNINIT]
> +Group 1: (Blocks 32768-65535) [INODE_UNINIT]
>   Backup superblock at 32768, Group descriptors at 32769-32769
>   Reserved GDT blocks at 32770-33440
>   Block bitmap at 674 (bg #0 + 674), Inode bitmap at 758 (bg #0 + 758)
> @@ -72,7 +72,7 @@ Group 2: (Blocks 65536-98303) [INODE_UNINIT, BLOCK_UNINIT]
>   32768 free blocks, 16 free inodes, 0 directories, 16 unused inodes
>   Free blocks: 65536-98303
>   Free inodes: 33-48
> -Group 3: (Blocks 98304-131071) [INODE_UNINIT, BLOCK_UNINIT]
> +Group 3: (Blocks 98304-131071) [INODE_UNINIT]
>   Backup superblock at 98304, Group descriptors at 98305-98305
>   Reserved GDT blocks at 98306-98976
>   Block bitmap at 676 (bg #0 + 676), Inode bitmap at 760 (bg #0 + 760)
> @@ -86,7 +86,7 @@ Group 4: (Blocks 131072-163839) [INODE_UNINIT, BLOCK_UNINIT]
>   32768 free blocks, 16 free inodes, 0 directories, 16 unused inodes
>   Free blocks: 131072-163839
>   Free inodes: 65-80
> -Group 5: (Blocks 163840-196607) [INODE_UNINIT, BLOCK_UNINIT]
> +Group 5: (Blocks 163840-196607) [INODE_UNINIT]
>   Backup superblock at 163840, Group descriptors at 163841-163841
>   Reserved GDT blocks at 163842-164512
>   Block bitmap at 678 (bg #0 + 678), Inode bitmap at 762 (bg #0 + 762)
> @@ -100,7 +100,7 @@ Group 6: (Blocks 196608-229375) [INODE_UNINIT, BLOCK_UNINIT]
>   32768 free blocks, 16 free inodes, 0 directories, 16 unused inodes
>   Free blocks: 196608-229375
>   Free inodes: 97-112
> -Group 7: (Blocks 229376-262143) [INODE_UNINIT, BLOCK_UNINIT]
> +Group 7: (Blocks 229376-262143) [INODE_UNINIT]
>   Backup superblock at 229376, Group descriptors at 229377-229377
>   Reserved GDT blocks at 229378-230048
>   Block bitmap at 680 (bg #0 + 680), Inode bitmap at 764 (bg #0 + 764)
> @@ -114,7 +114,7 @@ Group 8: (Blocks 262144-294911) [INODE_UNINIT, BLOCK_UNINIT]
>   32768 free blocks, 16 free inodes, 0 directories, 16 unused inodes
>   Free blocks: 262144-294911
>   Free inodes: 129-144
> -Group 9: (Blocks 294912-327679) [INODE_UNINIT, BLOCK_UNINIT]
> +Group 9: (Blocks 294912-327679) [INODE_UNINIT]
>   Backup superblock at 294912, Group descriptors at 294913-294913
>   Reserved GDT blocks at 294914-295584
>   Block bitmap at 682 (bg #0 + 682), Inode bitmap at 766 (bg #0 + 766)
> @@ -212,7 +212,7 @@ Group 24: (Blocks 786432-819199) [INODE_UNINIT, BLOCK_UNINIT]
>   32768 free blocks, 16 free inodes, 0 directories, 16 unused inodes
>   Free blocks: 786432-819199
>   Free inodes: 385-400
> -Group 25: (Blocks 819200-851967) [INODE_UNINIT, BLOCK_UNINIT]
> +Group 25: (Blocks 819200-851967) [INODE_UNINIT]
>   Backup superblock at 819200, Group descriptors at 819201-819201
>   Reserved GDT blocks at 819202-819872
>   Block bitmap at 698 (bg #0 + 698), Inode bitmap at 782 (bg #0 + 782)
> @@ -226,7 +226,7 @@ Group 26: (Blocks 851968-884735) [INODE_UNINIT, BLOCK_UNINIT]
>   32768 free blocks, 16 free inodes, 0 directories, 16 unused inodes
>   Free blocks: 851968-884735
>   Free inodes: 417-432
> -Group 27: (Blocks 884736-917503) [INODE_UNINIT, BLOCK_UNINIT]
> +Group 27: (Blocks 884736-917503) [INODE_UNINIT]
>   Backup superblock at 884736, Group descriptors at 884737-884737
>   Reserved GDT blocks at 884738-885408
>   Block bitmap at 700 (bg #0 + 700), Inode bitmap at 784 (bg #0 + 784)
> @@ -554,7 +554,7 @@ Group 80: (Blocks 2621440-2654207) [INODE_UNINIT, BLOCK_UNINIT]
>   32768 free blocks, 16 free inodes, 0 directories, 16 unused inodes
>   Free blocks: 2621440-2654207
>   Free inodes: 1281-1296
> -Group 81: (Blocks 2654208-2686975) [INODE_UNINIT, BLOCK_UNINIT]
> +Group 81: (Blocks 2654208-2686975) [INODE_UNINIT]
>   Backup superblock at 2654208, Group descriptors at 2654209-2654209
>   Reserved GDT blocks at 2654210-2654880
>   Block bitmap at 754 (bg #0 + 754), Inode bitmap at 838 (bg #0 + 838)
> diff --git a/tests/m_resize_inode_meta_bg/expect.1 b/tests/m_resize_inode_meta_bg/expect.1
> index 7feaed9d8..83c7bc57c 100644
> --- a/tests/m_resize_inode_meta_bg/expect.1
> +++ b/tests/m_resize_inode_meta_bg/expect.1
> @@ -67,7 +67,7 @@ Group 0: (Blocks 0-255) [ITABLE_ZEROED]
>   159 free blocks, 53 free inodes, 2 directories, 53 unused inodes
>   Free blocks: 97-255
>   Free inodes: 12-64
> -Group 1: (Blocks 256-511) [INODE_UNINIT, BLOCK_UNINIT, ITABLE_ZEROED]
> +Group 1: (Blocks 256-511) [INODE_UNINIT, ITABLE_ZEROED]
>   Backup superblock at 256, Group descriptor at 257
>   Block bitmap at 3 (bg #0 + 3)
>   Inode bitmap at 18 (bg #0 + 18)
> @@ -82,7 +82,7 @@ Group 2: (Blocks 512-767) [INODE_UNINIT, BLOCK_UNINIT, ITABLE_ZEROED]
>   256 free blocks, 64 free inodes, 0 directories, 64 unused inodes
>   Free blocks: 512-767
>   Free inodes: 129-192
> -Group 3: (Blocks 768-1023) [INODE_UNINIT, BLOCK_UNINIT, ITABLE_ZEROED]
> +Group 3: (Blocks 768-1023) [INODE_UNINIT, ITABLE_ZEROED]
>   Backup superblock at 768
>   Block bitmap at 5 (bg #0 + 5)
>   Inode bitmap at 20 (bg #0 + 20)
> @@ -97,7 +97,7 @@ Group 4: (Blocks 1024-1279) [INODE_UNINIT, BLOCK_UNINIT, ITABLE_ZEROED]
>   256 free blocks, 64 free inodes, 0 directories, 64 unused inodes
>   Free blocks: 1024-1279
>   Free inodes: 257-320
> -Group 5: (Blocks 1280-1535) [INODE_UNINIT, BLOCK_UNINIT, ITABLE_ZEROED]
> +Group 5: (Blocks 1280-1535) [INODE_UNINIT, ITABLE_ZEROED]
>   Backup superblock at 1280
>   Block bitmap at 7 (bg #0 + 7)
>   Inode bitmap at 22 (bg #0 + 22)
> diff --git a/tests/m_uninit/expect.1 b/tests/m_uninit/expect.1
> index 3c2875527..2058de7a9 100644
> --- a/tests/m_uninit/expect.1
> +++ b/tests/m_uninit/expect.1
> @@ -56,7 +56,7 @@ Group 0: (Blocks 1-8192) [ITABLE_ZEROED]
>   7406 free blocks, 2037 free inodes, 2 directories, 2037 unused inodes
>   Free blocks: 787-8192
>   Free inodes: 12-2048
> -Group 1: (Blocks 8193-16384) [INODE_UNINIT, BLOCK_UNINIT, ITABLE_ZEROED]
> +Group 1: (Blocks 8193-16384) [INODE_UNINIT, ITABLE_ZEROED]
>   Backup superblock at 8193, Group descriptors at 8194-8194
>   Reserved GDT blocks at 8195-8450
>   Block bitmap at 8451 (+258), Inode bitmap at 8452 (+259)
> @@ -70,7 +70,7 @@ Group 2: (Blocks 16385-24576) [INODE_UNINIT, BLOCK_UNINIT, ITABLE_ZEROED]
>   7678 free blocks, 2048 free inodes, 0 directories, 2048 unused inodes
>   Free blocks: 16899-24576
>   Free inodes: 4097-6144
> -Group 3: (Blocks 24577-32768) [INODE_UNINIT, BLOCK_UNINIT, ITABLE_ZEROED]
> +Group 3: (Blocks 24577-32768) [INODE_UNINIT, ITABLE_ZEROED]
>   Backup superblock at 24577, Group descriptors at 24578-24578
>   Reserved GDT blocks at 24579-24834
>   Block bitmap at 24835 (+258), Inode bitmap at 24836 (+259)
> @@ -84,7 +84,7 @@ Group 4: (Blocks 32769-40960) [INODE_UNINIT, BLOCK_UNINIT, ITABLE_ZEROED]
>   7678 free blocks, 2048 free inodes, 0 directories, 2048 unused inodes
>   Free blocks: 33283-40960
>   Free inodes: 8193-10240
> -Group 5: (Blocks 40961-49152) [INODE_UNINIT, BLOCK_UNINIT, ITABLE_ZEROED]
> +Group 5: (Blocks 40961-49152) [INODE_UNINIT, ITABLE_ZEROED]
>   Backup superblock at 40961, Group descriptors at 40962-40962
>   Reserved GDT blocks at 40963-41218
>   Block bitmap at 41219 (+258), Inode bitmap at 41220 (+259)
> @@ -98,7 +98,7 @@ Group 6: (Blocks 49153-57344) [INODE_UNINIT, BLOCK_UNINIT, ITABLE_ZEROED]
>   7678 free blocks, 2048 free inodes, 0 directories, 2048 unused inodes
>   Free blocks: 49667-57344
>   Free inodes: 12289-14336
> -Group 7: (Blocks 57345-65536) [INODE_UNINIT, BLOCK_UNINIT, ITABLE_ZEROED]
> +Group 7: (Blocks 57345-65536) [INODE_UNINIT, ITABLE_ZEROED]
>   Backup superblock at 57345, Group descriptors at 57346-57346
>   Reserved GDT blocks at 57347-57602
>   Block bitmap at 57603 (+258), Inode bitmap at 57604 (+259)
> @@ -112,7 +112,7 @@ Group 8: (Blocks 65537-73728) [INODE_UNINIT, BLOCK_UNINIT, ITABLE_ZEROED]
>   7678 free blocks, 2048 free inodes, 0 directories, 2048 unused inodes
>   Free blocks: 66051-73728
>   Free inodes: 16385-18432
> -Group 9: (Blocks 73729-81920) [INODE_UNINIT, BLOCK_UNINIT, ITABLE_ZEROED]
> +Group 9: (Blocks 73729-81920) [INODE_UNINIT, ITABLE_ZEROED]
>   Backup superblock at 73729, Group descriptors at 73730-73730
>   Reserved GDT blocks at 73731-73986
>   Block bitmap at 73987 (+258), Inode bitmap at 73988 (+259)
> --
> 2.41.0
> 


Cheers, Andreas






[-- Attachment #2: Message signed with OpenPGP --]
[-- Type: application/pgp-signature, Size: 873 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH 1/2] mke2fs: set free blocks accurately for groups has GDT
  2023-09-25  6:08 [PATCH 1/2] mke2fs: set free blocks accurately for groups has GDT Li Dongyang
  2023-09-25  6:08 ` [PATCH 2/2] mke2fs: do not set the BLOCK_UNINIT on " Li Dongyang
@ 2023-09-26 20:47 ` Andreas Dilger
  2024-04-17  2:03 ` Theodore Ts'o
  2 siblings, 0 replies; 5+ messages in thread
From: Andreas Dilger @ 2023-09-26 20:47 UTC (permalink / raw)
  To: Li Dongyang; +Cc: Ext4 Developers List

[-- Attachment #1: Type: text/plain, Size: 6993 bytes --]

On Sep 25, 2023, at 12:08 AM, Li Dongyang <dongyangli@ddn.com> wrote:
> 
> This patch is part of the preparation required to allow
> GDT blocks expand beyond a single group,
> it introduces 2 new interfaces:
> - ext2fs_count_used_blocks(), to return the blocks used
> in the bitmap range.
> - ext2fs_reserve_super_and_bgd2() to return blocks used by
> superblock/GDT blocks for every group, by looking up blocks used.
> 
> Signed-off-by: Li Dongyang <dongyangli@ddn.com>

Reviewed-by: Andreas Dilger <adilger@dilger.ca>

> ---
> lib/ext2fs/alloc_sb.c     | 28 ++++++++++++++++++++++++++--
> lib/ext2fs/ext2fs.h       |  6 ++++++
> lib/ext2fs/gen_bitmap64.c | 17 +++++++++++++++--
> lib/ext2fs/initialize.c   | 30 ++++++++++++++++++++----------
> misc/mke2fs.c             |  2 +-
> 5 files changed, 68 insertions(+), 15 deletions(-)
> 
> diff --git a/lib/ext2fs/alloc_sb.c b/lib/ext2fs/alloc_sb.c
> index 8530b40f6..e92739ecc 100644
> --- a/lib/ext2fs/alloc_sb.c
> +++ b/lib/ext2fs/alloc_sb.c
> @@ -46,8 +46,7 @@ int ext2fs_reserve_super_and_bgd(ext2_filsys fs,
> 				 ext2fs_block_bitmap bmap)
> {
> 	blk64_t	super_blk, old_desc_blk, new_desc_blk;
> -	blk_t	used_blks;
> -	int	old_desc_blocks, num_blocks;
> +	blk_t	used_blks, old_desc_blocks, num_blocks;
> 
> 	ext2fs_super_and_bgd_loc2(fs, group, &super_blk,
> 				  &old_desc_blk, &new_desc_blk, &used_blks);
> @@ -79,3 +78,28 @@ int ext2fs_reserve_super_and_bgd(ext2_filsys fs,
> 
> 	return num_blocks  ;
> }
> +
> +/*
> + * This function reserves the superblock and block group descriptors
> + * for a given block group and returns the number of blocks used by the
> + * super block and group descriptors by looking up the block bitmap.
> + */
> +errcode_t ext2fs_reserve_super_and_bgd2(ext2_filsys fs,
> +				        dgrp_t group,
> +				        ext2fs_block_bitmap bmap,
> +				        blk_t *desc_blocks)
> +{
> +	blk64_t	num_blocks;
> +	errcode_t retval = 0;
> +
> +	ext2fs_reserve_super_and_bgd(fs, group, bmap);
> +
> +	retval = ext2fs_count_used_blocks(fs,
> +					ext2fs_group_first_block2(fs, group),
> +					ext2fs_group_last_block2(fs, group),
> +					&num_blocks);
> +	if (!retval)
> +		*desc_blocks = num_blocks;
> +
> +	return retval;
> +}
> diff --git a/lib/ext2fs/ext2fs.h b/lib/ext2fs/ext2fs.h
> index 72c60d2b5..ae79a3443 100644
> --- a/lib/ext2fs/ext2fs.h
> +++ b/lib/ext2fs/ext2fs.h
> @@ -795,6 +795,10 @@ errcode_t ext2fs_alloc_range(ext2_filsys fs, int flags, blk64_t goal,
> extern int ext2fs_reserve_super_and_bgd(ext2_filsys fs,
> 					dgrp_t group,
> 					ext2fs_block_bitmap bmap);
> +extern errcode_t ext2fs_reserve_super_and_bgd2(ext2_filsys fs,
> +					       dgrp_t group,
> +					       ext2fs_block_bitmap bmap,
> +					       blk_t *desc_blocks);
> extern void ext2fs_set_block_alloc_stats_callback(ext2_filsys fs,
> 						  void (*func)(ext2_filsys fs,
> 							       blk64_t blk,
> @@ -1483,6 +1487,8 @@ errcode_t ext2fs_convert_subcluster_bitmap(ext2_filsys fs,
> 					   ext2fs_block_bitmap *bitmap);
> errcode_t ext2fs_count_used_clusters(ext2_filsys fs, blk64_t start,
> 				     blk64_t end, blk64_t *out);
> +errcode_t ext2fs_count_used_blocks(ext2_filsys fs, blk64_t start,
> +				   blk64_t end, blk64_t *out);
> 
> /* get_num_dirs.c */
> extern errcode_t ext2fs_get_num_dirs(ext2_filsys fs, ext2_ino_t *ret_num_dirs);
> diff --git a/lib/ext2fs/gen_bitmap64.c b/lib/ext2fs/gen_bitmap64.c
> index 4289e8155..5936dcf53 100644
> --- a/lib/ext2fs/gen_bitmap64.c
> +++ b/lib/ext2fs/gen_bitmap64.c
> @@ -945,8 +945,8 @@ errcode_t ext2fs_find_first_set_generic_bmap(ext2fs_generic_bitmap bitmap,
> 	return ENOENT;
> }
> 
> -errcode_t ext2fs_count_used_clusters(ext2_filsys fs, blk64_t start,
> -				     blk64_t end, blk64_t *out)
> +errcode_t ext2fs_count_used_blocks(ext2_filsys fs, blk64_t start,
> +				   blk64_t end, blk64_t *out)
> {
> 	blk64_t		next;
> 	blk64_t		tot_set = 0;
> @@ -975,6 +975,19 @@ errcode_t ext2fs_count_used_clusters(ext2_filsys fs, blk64_t start,
> 			break;
> 	}
> 
> +	if (!retval)
> +		*out = tot_set;
> +	return retval;
> +}
> +
> +errcode_t ext2fs_count_used_clusters(ext2_filsys fs, blk64_t start,
> +				     blk64_t end, blk64_t *out)
> +{
> +	blk64_t		tot_set = 0;
> +	errcode_t	retval = 0;
> +
> +	retval = ext2fs_count_used_blocks(fs, start, end, &tot_set);
> +
> 	if (!retval)
> 		*out = EXT2FS_NUM_B2C(fs, tot_set);
> 	return retval;
> diff --git a/lib/ext2fs/initialize.c b/lib/ext2fs/initialize.c
> index edd692bb9..90012f732 100644
> --- a/lib/ext2fs/initialize.c
> +++ b/lib/ext2fs/initialize.c
> @@ -521,6 +521,15 @@ ipg_retry:
> 	csum_flag = ext2fs_has_group_desc_csum(fs);
> 	reserved_inos = super->s_first_ino;
> 	for (i = 0; i < fs->group_desc_count; i++) {
> +		blk_t grp_free_blocks;
> +		ext2_ino_t inodes;
> +
> +		retval = ext2fs_reserve_super_and_bgd2(fs, i,
> +						       fs->block_map,
> +						       &numblocks);
> +		if (retval)
> +			goto cleanup;
> +
> 		/*
> 		 * Don't set the BLOCK_UNINIT group for the last group
> 		 * because the block bitmap needs to be padded.
> @@ -530,24 +539,25 @@ ipg_retry:
> 				ext2fs_bg_flags_set(fs, i,
> 						    EXT2_BG_BLOCK_UNINIT);
> 			ext2fs_bg_flags_set(fs, i, EXT2_BG_INODE_UNINIT);
> -			numblocks = super->s_inodes_per_group;
> +			inodes = super->s_inodes_per_group;
> 			if (reserved_inos) {
> -				if (numblocks > reserved_inos) {
> -					numblocks -= reserved_inos;
> +				if (inodes > reserved_inos) {
> +					inodes -= reserved_inos;
> 					reserved_inos = 0;
> 				} else {
> -					reserved_inos -= numblocks;
> -					numblocks = 0;
> +					reserved_inos -= inodes;
> +					inodes = 0;
> 				}
> 			}
> -			ext2fs_bg_itable_unused_set(fs, i, numblocks);
> +			ext2fs_bg_itable_unused_set(fs, i, inodes);
> 		}
> -		numblocks = ext2fs_reserve_super_and_bgd(fs, i, fs->block_map);
> -		if (fs->super->s_log_groups_per_flex)
> +
> +		if (!fs->super->s_log_groups_per_flex)
> 			numblocks += 2 + fs->inode_blocks_per_group;
> 
> -		free_blocks += numblocks;
> -		ext2fs_bg_free_blocks_count_set(fs, i, numblocks);
> +		grp_free_blocks = ext2fs_group_blocks_count(fs, i) - numblocks;
> +		free_blocks += grp_free_blocks;
> +		ext2fs_bg_free_blocks_count_set(fs, i, grp_free_blocks);
> 		ext2fs_bg_free_inodes_count_set(fs, i, fs->super->s_inodes_per_group);
> 		ext2fs_bg_used_dirs_count_set(fs, i, 0);
> 		ext2fs_group_desc_csum_set(fs, i);
> diff --git a/misc/mke2fs.c b/misc/mke2fs.c
> index 4a9c1b092..72c9da12e 100644
> --- a/misc/mke2fs.c
> +++ b/misc/mke2fs.c
> @@ -3522,7 +3522,7 @@ no_journal:
> 			       fs->super->s_mmp_update_interval);
> 	}
> 
> -	overhead += fs->super->s_first_data_block;
> +	overhead += EXT2FS_NUM_B2C(fs, fs->super->s_first_data_block);
> 	if (!super_only)
> 		fs->super->s_overhead_clusters = overhead;
> 
> --
> 2.41.0
> 


Cheers, Andreas






[-- Attachment #2: Message signed with OpenPGP --]
[-- Type: application/pgp-signature, Size: 873 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH 1/2] mke2fs: set free blocks accurately for groups has GDT
  2023-09-25  6:08 [PATCH 1/2] mke2fs: set free blocks accurately for groups has GDT Li Dongyang
  2023-09-25  6:08 ` [PATCH 2/2] mke2fs: do not set the BLOCK_UNINIT on " Li Dongyang
  2023-09-26 20:47 ` [PATCH 1/2] mke2fs: set free blocks accurately for " Andreas Dilger
@ 2024-04-17  2:03 ` Theodore Ts'o
  2 siblings, 0 replies; 5+ messages in thread
From: Theodore Ts'o @ 2024-04-17  2:03 UTC (permalink / raw)
  To: linux-ext4, Li Dongyang; +Cc: Theodore Ts'o, adilger


On Mon, 25 Sep 2023 16:08:00 +1000, Li Dongyang wrote:
> This patch is part of the preparation required to allow
> GDT blocks expand beyond a single group,
> it introduces 2 new interfaces:
> - ext2fs_count_used_blocks(), to return the blocks used
> in the bitmap range.
> - ext2fs_reserve_super_and_bgd2() to return blocks used by
> superblock/GDT blocks for every group, by looking up blocks used.
> 
> [...]

Applied, thanks!

[1/2] mke2fs: set free blocks accurately for groups has GDT
      commit: ecb37fe311cd67fe7c86eae069551ad15fb20c03
[2/2] mke2fs: do not set the BLOCK_UNINIT on groups has GDT
      commit: 7150bea307a30f393d184d81a80d9a3ae2e78638

Best regards,
-- 
Theodore Ts'o <tytso@mit.edu>

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2024-04-17  2:03 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-09-25  6:08 [PATCH 1/2] mke2fs: set free blocks accurately for groups has GDT Li Dongyang
2023-09-25  6:08 ` [PATCH 2/2] mke2fs: do not set the BLOCK_UNINIT on " Li Dongyang
2023-09-26 20:46   ` Andreas Dilger
2023-09-26 20:47 ` [PATCH 1/2] mke2fs: set free blocks accurately for " Andreas Dilger
2024-04-17  2:03 ` Theodore Ts'o

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).