[Ocfs2-tools-devel] [PATCH 02/20] libocfs2: Change ocfs2_group_bitmap_size.

Tao Ma tao.ma at oracle.com
Mon May 17 01:46:49 PDT 2010


Change ocfs2_group_bitmap_size to accept parameters suballocator
and feature_incompat.currently all the callers set suballocator
to 0. Some of them will be changed later.
As for feature_incompat, some functions like ocfs2.h don't have
a fs passed in, so we just use 0 and let it b a cluster group.

Signed-off-by: Tao Ma <tao.ma at oracle.com>
---
 debugfs.ocfs2/find_block_inode.c |    3 ++-
 extras/compute_groups.c          |    2 +-
 fsck.ocfs2/pass0.c               |    4 +++-
 fswreck/chain.c                  |    3 ++-
 fswreck/group.c                  |    3 ++-
 include/ocfs2-kernel/ocfs2_fs.h  |   36 ++++++++++++++++++++++++++++--------
 include/ocfs2/ocfs2.h            |    2 +-
 libocfs2/chainalloc.c            |    7 +++++--
 mkfs.ocfs2/mkfs.c                |    5 +++--
 9 files changed, 47 insertions(+), 18 deletions(-)

diff --git a/debugfs.ocfs2/find_block_inode.c b/debugfs.ocfs2/find_block_inode.c
index 293ce09..9bdf448 100644
--- a/debugfs.ocfs2/find_block_inode.c
+++ b/debugfs.ocfs2/find_block_inode.c
@@ -294,7 +294,8 @@ static void check_computed_blocks(ocfs2_filesys *fs, uint64_t gb_blkno,
 	if (*found >= count)
 		return;
 
-	cpg = ocfs2_group_bitmap_size(1 << fs->fs_blocksize) * 8;
+	cpg = ocfs2_group_bitmap_size(fs->fs_blocksize, 0,
+			OCFS2_RAW_SB(fs->fs_super)->s_feature_incompat) * 8;
 	bpg = ocfs2_clusters_to_blocks(fs, cpg);
 
 	for (i = 0; i < count; ++i) {
diff --git a/extras/compute_groups.c b/extras/compute_groups.c
index dd5b158..3dcfe34 100644
--- a/extras/compute_groups.c
+++ b/extras/compute_groups.c
@@ -62,7 +62,7 @@ int main (int argc, char **argv)
 	       "size %"PRIu64" bytes\n", max_size);
 
 	for (bs = 9; bs < 13; bs++) {
-		cpg = ocfs2_group_bitmap_size(1 << bs) * 8;
+		cpg = ocfs2_group_bitmap_size(1 << bs, 0, 0) * 8;
 		stringyfy((1 << bs), 'b', blkstr);
 		for (cs = 12; cs < 21; cs++) {
 			for (bytoff = 0, clsoff = 0; bytoff < max_size; ) {
diff --git a/fsck.ocfs2/pass0.c b/fsck.ocfs2/pass0.c
index a32bd18..dd9a109 100644
--- a/fsck.ocfs2/pass0.c
+++ b/fsck.ocfs2/pass0.c
@@ -991,7 +991,9 @@ static errcode_t verify_bitmap_descs(o2fsck_state *ost,
 		}
 
 		/* first some easy fields */
-		bg->bg_size = ocfs2_group_bitmap_size(ost->ost_fs->fs_blocksize);
+		bg->bg_size = ocfs2_group_bitmap_size(
+			ost->ost_fs->fs_blocksize, 0,
+			OCFS2_RAW_SB(ost->ost_fs->fs_super)->s_feature_incompat);
 		bg->bg_bits = bits;
 		bg->bg_parent_dinode = di->i_blkno;
 		bg->bg_blkno = blkno;
diff --git a/fswreck/chain.c b/fswreck/chain.c
index d49646b..6944210 100644
--- a/fswreck/chain.c
+++ b/fswreck/chain.c
@@ -286,7 +286,8 @@ static void mess_up_superblock_clusters(ocfs2_filesys *fs, int excess)
 
 	di = (struct ocfs2_dinode *)buf;
 
-	cpg= 8 * ocfs2_group_bitmap_size(fs->fs_blocksize);
+	cpg = 8 * ocfs2_group_bitmap_size(fs->fs_blocksize, 0,
+				OCFS2_RAW_SB(fs->fs_super)->s_feature_incompat);
 
 	/* make the wrong value to 2.5 times of cluster_per_group. */
 	wrong = cpg * 2 + cpg / 2;
diff --git a/fswreck/group.c b/fswreck/group.c
index 45a460b..6335201 100644
--- a/fswreck/group.c
+++ b/fswreck/group.c
@@ -268,7 +268,8 @@ void mess_up_cluster_group_desc(ocfs2_filesys *fs, enum fsck_type type,
 		FSWRK_COM_FATAL(progname, ret);
 
 	start_cluster = ocfs2_blocks_to_clusters(fs, start_blk);
-	cpg = ocfs2_group_bitmap_size(fs->fs_blocksize) * 8;
+	cpg = ocfs2_group_bitmap_size(fs->fs_blocksize, 0,
+		OCFS2_RAW_SB(fs->fs_super)->s_feature_incompat) * 8;
 	bg_blk = ocfs2_which_cluster_group(fs, cpg, start_cluster);
 
 	ret = ocfs2_malloc_block(fs->fs_io, &buf);
diff --git a/include/ocfs2-kernel/ocfs2_fs.h b/include/ocfs2-kernel/ocfs2_fs.h
index 90ff35a..a913f7c 100644
--- a/include/ocfs2-kernel/ocfs2_fs.h
+++ b/include/ocfs2-kernel/ocfs2_fs.h
@@ -1338,13 +1338,23 @@ static inline u16 ocfs2_local_alloc_size(struct super_block *sb)
 	return size;
 }
 
-static inline int ocfs2_group_bitmap_size(struct super_block *sb)
+static inline int ocfs2_group_bitmap_size(struct super_block *sb,
+					  int suballocator,
+					  u32 feature_incompat)
 {
-	int size;
-
-	size = sb->s_blocksize -
+	int size = sb->s_blocksize -
 		offsetof(struct ocfs2_group_desc, bg_bitmap);
 
+	/*
+	 * The cluster allocator uses the entire block.  Suballocators have
+	 * never used more than OCFS2_MAX_BG_BITMAP_SIZE.  Unfortunately, older
+	 * code expects bg_size set to the maximum.  Thus we must keep
+	 * bg_size as-is unless discontig_bg is enabled.
+	 */
+	if (suballocator &&
+	    (feature_incompat & OCFS2_FEATURE_INCOMPAT_DISCONTIG_BG))
+		size = OCFS2_MAX_BG_BITMAP_SIZE;
+
 	return size;
 }
 
@@ -1496,13 +1506,23 @@ static inline int ocfs2_local_alloc_size(int blocksize)
 	return size;
 }
 
-static inline int ocfs2_group_bitmap_size(int blocksize)
+static inline int ocfs2_group_bitmap_size(int blocksize,
+					  int suballocator,
+					  uint32_t feature_incompat)
 {
-	int size;
-
-	size = blocksize -
+	int size = blocksize -
 		offsetof(struct ocfs2_group_desc, bg_bitmap);
 
+	/*
+	 * The cluster allocator uses the entire block.  Suballocators have
+	 * never used more than OCFS2_MAX_BG_BITMAP_SIZE.  Unfortunately, older
+	 * code expects bg_size set to the maximum.  Thus we must keep
+	 * bg_size as-is unless discontig_bg is enabled.
+	 */
+	if (suballocator &&
+	    (feature_incompat & OCFS2_FEATURE_INCOMPAT_DISCONTIG_BG))
+		size = OCFS2_MAX_BG_BITMAP_SIZE;
+
 	return size;
 }
 
diff --git a/include/ocfs2/ocfs2.h b/include/ocfs2/ocfs2.h
index 582f4c2..3d6bc76 100644
--- a/include/ocfs2/ocfs2.h
+++ b/include/ocfs2/ocfs2.h
@@ -1164,7 +1164,7 @@ static inline void ocfs2_calc_cluster_groups(uint64_t clusters,
 					     uint64_t blocksize,
 				     struct ocfs2_cluster_group_sizes *cgs)
 {
-	uint16_t max_bits = 8 * ocfs2_group_bitmap_size(blocksize);
+	uint16_t max_bits = 8 * ocfs2_group_bitmap_size(blocksize, 0, 0);
 
 	cgs->cgs_cpg = max_bits;
 	if (max_bits > clusters)
diff --git a/libocfs2/chainalloc.c b/libocfs2/chainalloc.c
index 4287f69..72fd503 100644
--- a/libocfs2/chainalloc.c
+++ b/libocfs2/chainalloc.c
@@ -109,7 +109,9 @@ static int chainalloc_process_group(ocfs2_filesys *fs,
 	cr->cr_ag = (struct ocfs2_group_desc *)gd_buf;
 
 	cb->cb_errcode = OCFS2_ET_CORRUPT_GROUP_DESC;
-	if (cr->cr_ag->bg_size != ocfs2_group_bitmap_size(fs->fs_blocksize))
+	if (cr->cr_ag->bg_size !=
+	    ocfs2_group_bitmap_size(fs->fs_blocksize, 0,
+				OCFS2_RAW_SB(fs->fs_super)->s_feature_incompat))
 		goto out_free_cr;
 
 	if (gd_blkno == OCFS2_RAW_SB(fs->fs_super)->s_first_cluster_group)
@@ -487,7 +489,8 @@ void ocfs2_init_group_desc(ocfs2_filesys *fs,
 
 	strcpy((char *)gd->bg_signature, OCFS2_GROUP_DESC_SIGNATURE);
 	gd->bg_generation = generation;
-	gd->bg_size = ocfs2_group_bitmap_size(fs->fs_blocksize);
+	gd->bg_size = ocfs2_group_bitmap_size(fs->fs_blocksize, 0,
+			OCFS2_RAW_SB(fs->fs_super)->s_feature_incompat);
 	gd->bg_bits = bits;
 	gd->bg_chain = chain;
 	gd->bg_parent_dinode = parent_inode;
diff --git a/mkfs.ocfs2/mkfs.c b/mkfs.ocfs2/mkfs.c
index 5507872..4cf75f3 100644
--- a/mkfs.ocfs2/mkfs.c
+++ b/mkfs.ocfs2/mkfs.c
@@ -1711,7 +1711,8 @@ initialize_alloc_group(State *s, const char *name,
 
 	strcpy((char *)group->gd->bg_signature, OCFS2_GROUP_DESC_SIGNATURE);
 	group->gd->bg_generation = s->vol_generation;
-	group->gd->bg_size = (uint32_t)ocfs2_group_bitmap_size(s->blocksize);
+	group->gd->bg_size =
+			(uint32_t)ocfs2_group_bitmap_size(s->blocksize, 0, 0);
 	group->gd->bg_bits = cpg * bpc;
 	group->gd->bg_chain = chain;
 	group->gd->bg_parent_dinode = alloc_inode->fe_off >> 
@@ -2366,7 +2367,7 @@ format_file(State *s, SystemFileDiskRecord *rec)
 		di->id2.i_chain.cl_count = 
 			ocfs2_chain_recs_per_inode(s->blocksize);
 		di->id2.i_chain.cl_cpg =
-				 ocfs2_group_bitmap_size(s->blocksize) * 8;
+			 ocfs2_group_bitmap_size(s->blocksize, 0, 0) * 8;
 		di->id2.i_chain.cl_bpc = 1;
 		if (s->nr_cluster_groups > 
 		    ocfs2_chain_recs_per_inode(s->blocksize)) {
-- 
1.5.5




More information about the Ocfs2-tools-devel mailing list