[Ocfs2-tools-devel] [PATCH 12/22] libocfs2: Set suballoc_bit properly for discontig block group.

Tao Ma tao.ma at oracle.com
Wed Mar 31 21:41:16 PDT 2010


The old ocfs2_chain_alloc_with_io returns gb_blkno properly
for us, that is cool for us. So we only need to pass back
the proper suballoc_bit. And that's done for discontig
block group.

Signed-off-by: Tao Ma <tao.ma at oracle.com>
---
 include/ocfs2/ocfs2.h |    3 ++-
 libocfs2/alloc.c      |   48 ++++++++++++++++++++++++++++++------------------
 libocfs2/chainalloc.c |   11 ++++++++---
 3 files changed, 40 insertions(+), 22 deletions(-)

diff --git a/include/ocfs2/ocfs2.h b/include/ocfs2/ocfs2.h
index b9251b8..3dc8df4 100644
--- a/include/ocfs2/ocfs2.h
+++ b/include/ocfs2/ocfs2.h
@@ -592,7 +592,8 @@ errcode_t ocfs2_write_chain_allocator(ocfs2_filesys *fs,
 errcode_t ocfs2_chain_alloc(ocfs2_filesys *fs,
 			    ocfs2_cached_inode *cinode,
 			    uint64_t *gd_blkno,
-			    uint64_t *bitno);
+			    uint64_t *bitno,
+			    uint16_t *suballoc_bit);
 errcode_t ocfs2_chain_free(ocfs2_filesys *fs,
 			   ocfs2_cached_inode *cinode,
 			   uint64_t bitno);
diff --git a/libocfs2/alloc.c b/libocfs2/alloc.c
index 96c4fc1..3b91c24 100644
--- a/libocfs2/alloc.c
+++ b/libocfs2/alloc.c
@@ -34,6 +34,7 @@
 static errcode_t ocfs2_chain_alloc_with_io(ocfs2_filesys *fs,
 					   ocfs2_cached_inode *cinode,
 					   uint64_t *gd_blkno,
+					   uint16_t *suballoc_bit,
 					   uint64_t *bitno)
 {
 	errcode_t ret;
@@ -44,7 +45,7 @@ static errcode_t ocfs2_chain_alloc_with_io(ocfs2_filesys *fs,
 			return ret;
 	}
 
-	ret = ocfs2_chain_alloc(fs, cinode, gd_blkno, bitno);
+	ret = ocfs2_chain_alloc(fs, cinode, gd_blkno, bitno, suballoc_bit);
 	if (ret)
 		return ret;
 
@@ -158,6 +159,7 @@ void ocfs2_set_inode_data_inline(ocfs2_filesys *fs, struct ocfs2_dinode *di)
 
 static void ocfs2_init_inode(ocfs2_filesys *fs, struct ocfs2_dinode *di,
 			     int16_t slot, uint64_t gd_blkno,
+			     uint16_t suballoc_bit,
 			     uint64_t blkno, uint16_t mode,
 			     uint32_t flags)
 {
@@ -168,7 +170,7 @@ static void ocfs2_init_inode(ocfs2_filesys *fs, struct ocfs2_dinode *di,
 	di->i_fs_generation = fs->fs_super->i_fs_generation;
 	di->i_blkno = blkno;
 	di->i_suballoc_slot = slot;
-	di->i_suballoc_bit = (uint16_t)(blkno - gd_blkno);
+	di->i_suballoc_bit = suballoc_bit;
 	di->i_uid = di->i_gid = 0;
 	di->i_mode = mode;
 	if (S_ISDIR(di->i_mode))
@@ -215,13 +217,14 @@ static void ocfs2_init_inode(ocfs2_filesys *fs, struct ocfs2_dinode *di,
 
 static void ocfs2_init_eb(ocfs2_filesys *fs,
 			  struct ocfs2_extent_block *eb,
-			  uint64_t gd_blkno, uint64_t blkno)
+			  uint64_t gd_blkno, uint16_t suballoc_bit,
+			  uint64_t blkno)
 {
 	strcpy((char *)eb->h_signature, OCFS2_EXTENT_BLOCK_SIGNATURE);
 	eb->h_fs_generation = fs->fs_super->i_fs_generation;
 	eb->h_blkno = blkno;
 	eb->h_suballoc_slot = 0;
-	eb->h_suballoc_bit = (uint16_t)(blkno - gd_blkno);
+	eb->h_suballoc_bit = suballoc_bit;
 	eb->h_list.l_count = ocfs2_extent_recs_per_eb(fs->fs_blocksize);
 }
 
@@ -230,6 +233,7 @@ errcode_t ocfs2_new_inode(ocfs2_filesys *fs, uint64_t *ino, int mode)
 	errcode_t ret;
 	char *buf;
 	uint64_t gd_blkno;
+	uint16_t suballoc_bit;
 	struct ocfs2_dinode *di;
 
 	ret = ocfs2_malloc_block(fs->fs_io, &buf);
@@ -242,13 +246,13 @@ errcode_t ocfs2_new_inode(ocfs2_filesys *fs, uint64_t *ino, int mode)
 		goto out;
 
 	ret = ocfs2_chain_alloc_with_io(fs, fs->fs_inode_allocs[0],
-					&gd_blkno, ino);
+					&gd_blkno, &suballoc_bit, ino);
 	if (ret == OCFS2_ET_BIT_NOT_FOUND) {
 		ret = ocfs2_chain_add_group(fs, fs->fs_inode_allocs[0]);
 		if (ret)
 			goto out;
 		ret = ocfs2_chain_alloc_with_io(fs, fs->fs_inode_allocs[0],
-						&gd_blkno, ino);
+						&gd_blkno, &suballoc_bit, ino);
 		if (ret)
 			goto out;
 	} else if (ret)
@@ -256,7 +260,8 @@ errcode_t ocfs2_new_inode(ocfs2_filesys *fs, uint64_t *ino, int mode)
 
 	memset(buf, 0, fs->fs_blocksize);
 	di = (struct ocfs2_dinode *)buf;
-	ocfs2_init_inode(fs, di, 0, gd_blkno, *ino, mode, OCFS2_VALID_FL);
+	ocfs2_init_inode(fs, di, 0, gd_blkno, suballoc_bit,
+			 *ino, mode, OCFS2_VALID_FL);
 
 	ret = ocfs2_write_inode(fs, *ino, buf);
 	if (ret)
@@ -274,6 +279,7 @@ errcode_t ocfs2_new_system_inode(ocfs2_filesys *fs, uint64_t *ino,
 	errcode_t ret;
 	char *buf;
 	uint64_t gd_blkno;
+	uint16_t suballoc_bit;
 	struct ocfs2_dinode *di;
 
 	ret = ocfs2_malloc_block(fs->fs_io, &buf);
@@ -286,20 +292,20 @@ errcode_t ocfs2_new_system_inode(ocfs2_filesys *fs, uint64_t *ino,
 		goto out;
 
 	ret = ocfs2_chain_alloc_with_io(fs, fs->fs_system_inode_alloc,
-					&gd_blkno, ino);
+					&gd_blkno, &suballoc_bit, ino);
 	if (ret == OCFS2_ET_BIT_NOT_FOUND) {
 		ret = ocfs2_chain_add_group(fs, fs->fs_system_inode_alloc);
 		if (ret)
 			goto out;
 		ret = ocfs2_chain_alloc_with_io(fs, fs->fs_system_inode_alloc,
-						&gd_blkno, ino);
+						&gd_blkno, &suballoc_bit, ino);
 		if (ret)
 			goto out;
 	}
 
 	memset(buf, 0, fs->fs_blocksize);
 	di = (struct ocfs2_dinode *)buf;
-	ocfs2_init_inode(fs, di, -1, gd_blkno, *ino, mode,
+	ocfs2_init_inode(fs, di, -1, gd_blkno, suballoc_bit, *ino, mode,
 			 (flags | OCFS2_VALID_FL | OCFS2_SYSTEM_FL));
 
 	ret = ocfs2_write_inode(fs, *ino, buf);
@@ -389,6 +395,7 @@ errcode_t ocfs2_new_extent_block(ocfs2_filesys *fs, uint64_t *blkno)
 	errcode_t ret;
 	char *buf;
 	uint64_t gd_blkno;
+	uint16_t suballoc_bit;
 	struct ocfs2_extent_block *eb;
 
 	ret = ocfs2_malloc_block(fs->fs_io, &buf);
@@ -401,13 +408,14 @@ errcode_t ocfs2_new_extent_block(ocfs2_filesys *fs, uint64_t *blkno)
 		goto out;
 
 	ret = ocfs2_chain_alloc_with_io(fs, fs->fs_eb_allocs[0],
-					&gd_blkno, blkno);
+					&gd_blkno, &suballoc_bit, blkno);
 	if (ret == OCFS2_ET_BIT_NOT_FOUND) {
 		ret = ocfs2_chain_add_group(fs, fs->fs_eb_allocs[0]);
 		if (ret)
 			goto out;
 		ret = ocfs2_chain_alloc_with_io(fs, fs->fs_eb_allocs[0],
-						&gd_blkno, blkno);
+						&gd_blkno, &suballoc_bit,
+						blkno);
 		if (ret)
 			goto out;
 	} else if (ret)
@@ -415,7 +423,7 @@ errcode_t ocfs2_new_extent_block(ocfs2_filesys *fs, uint64_t *blkno)
 
 	memset(buf, 0, fs->fs_blocksize);
 	eb = (struct ocfs2_extent_block *)buf;
-	ocfs2_init_eb(fs, eb, gd_blkno, *blkno);
+	ocfs2_init_eb(fs, eb, gd_blkno, suballoc_bit, *blkno);
 
 	ret = ocfs2_write_extent_block(fs, *blkno, buf);
 
@@ -524,14 +532,15 @@ out:
 
 static void ocfs2_init_rb(ocfs2_filesys *fs,
 			  struct ocfs2_refcount_block *rb,
-			  uint64_t gd_blkno, uint64_t blkno,
+			  uint64_t gd_blkno, uint16_t suballoc_bit,
+			  uint64_t blkno,
 			  uint64_t root_blkno, uint32_t rf_generation)
 {
 	strcpy((void *)rb, OCFS2_REFCOUNT_BLOCK_SIGNATURE);
 	rb->rf_fs_generation = fs->fs_super->i_fs_generation;
 	rb->rf_blkno = blkno;
 	rb->rf_suballoc_slot = 0;
-	rb->rf_suballoc_bit = (uint16_t)(blkno - gd_blkno);
+	rb->rf_suballoc_bit = suballoc_bit;
 	rb->rf_parent = root_blkno;
 	if (root_blkno)
 		rb->rf_flags = OCFS2_REFCOUNT_LEAF_FL;
@@ -545,6 +554,7 @@ errcode_t ocfs2_new_refcount_block(ocfs2_filesys *fs, uint64_t *blkno,
 	errcode_t ret;
 	char *buf;
 	uint64_t gd_blkno;
+	uint16_t suballoc_bit;
 	struct ocfs2_refcount_block *rb;
 
 	ret = ocfs2_malloc_block(fs->fs_io, &buf);
@@ -557,13 +567,14 @@ errcode_t ocfs2_new_refcount_block(ocfs2_filesys *fs, uint64_t *blkno,
 		goto out;
 
 	ret = ocfs2_chain_alloc_with_io(fs, fs->fs_eb_allocs[0],
-					&gd_blkno, blkno);
+					&gd_blkno, &suballoc_bit, blkno);
 	if (ret == OCFS2_ET_BIT_NOT_FOUND) {
 		ret = ocfs2_chain_add_group(fs, fs->fs_eb_allocs[0]);
 		if (ret)
 			goto out;
 		ret = ocfs2_chain_alloc_with_io(fs, fs->fs_eb_allocs[0],
-						&gd_blkno, blkno);
+						&gd_blkno, &suballoc_bit,
+						blkno);
 		if (ret)
 			goto out;
 	} else if (ret)
@@ -572,7 +583,8 @@ errcode_t ocfs2_new_refcount_block(ocfs2_filesys *fs, uint64_t *blkno,
 	memset(buf, 0, fs->fs_blocksize);
 	rb = (struct ocfs2_refcount_block *)buf;
 
-	ocfs2_init_rb(fs, rb, gd_blkno, *blkno, root_blkno, rf_generation);
+	ocfs2_init_rb(fs, rb, gd_blkno, suballoc_bit,
+		      *blkno, root_blkno, rf_generation);
 
 	ret = ocfs2_write_refcount_block(fs, *blkno, buf);
 
diff --git a/libocfs2/chainalloc.c b/libocfs2/chainalloc.c
index b1fad0f..43a6516 100644
--- a/libocfs2/chainalloc.c
+++ b/libocfs2/chainalloc.c
@@ -503,6 +503,7 @@ struct find_gd_state {
 	ocfs2_filesys *fs;
 	uint64_t bitno;
 	uint64_t gd_blkno;
+	uint64_t suballoc_bit;
 	int found;
 };
 
@@ -516,6 +517,8 @@ static errcode_t chainalloc_find_gd(struct ocfs2_bitmap_region *br,
 	    (state->bitno < (br->br_start_bit + br->br_valid_bits))) {
 		state->found = 1;
 		state->gd_blkno = cr->cr_ag->bg_blkno;
+		state->suballoc_bit = state->bitno - br->br_start_bit
+					+ cr->bit_offset;
 		if (state->gd_blkno == OCFS2_RAW_SB(state->fs->fs_super)->s_first_cluster_group)
 			state->gd_blkno = 0;
 		return OCFS2_ET_ITERATION_COMPLETE;
@@ -527,7 +530,8 @@ static errcode_t chainalloc_find_gd(struct ocfs2_bitmap_region *br,
 errcode_t ocfs2_chain_alloc(ocfs2_filesys *fs,
 			    ocfs2_cached_inode *cinode,
 			    uint64_t *gd_blkno,
-			    uint64_t *bitno)
+			    uint64_t *bitno,
+			    uint16_t *suballoc_bit)
 {
 	errcode_t ret;
 	int oldval;
@@ -553,9 +557,10 @@ errcode_t ocfs2_chain_alloc(ocfs2_filesys *fs,
 	ret = ocfs2_bitmap_foreach_region(cinode->ci_chains,
 					  chainalloc_find_gd, &state);
 	if (!ret) {
-		if (state.found)
+		if (state.found) {
 			*gd_blkno = state.gd_blkno;
-		else
+			*suballoc_bit = state.suballoc_bit;
+		} else
 			ret = OCFS2_ET_INTERNAL_FAILURE;
 	}
 	return ret;
-- 
1.5.5




More information about the Ocfs2-tools-devel mailing list