[Ocfs2-tools-devel] [PATCH 12/20] libocfs2: Set suballoc_bit properly for discontig block group.
Tao Ma
tao.ma at oracle.com
Mon May 17 01:46:59 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 | 1 +
libocfs2/alloc.c | 65 +++++++++++++++++++++++++++++++-----------------
libocfs2/chainalloc.c | 9 +++++-
3 files changed, 50 insertions(+), 25 deletions(-)
diff --git a/include/ocfs2/ocfs2.h b/include/ocfs2/ocfs2.h
index 787ad09..07ab375 100644
--- a/include/ocfs2/ocfs2.h
+++ b/include/ocfs2/ocfs2.h
@@ -639,6 +639,7 @@ 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,
+ uint16_t *suballoc_bit,
uint64_t *bitno);
errcode_t ocfs2_chain_free(ocfs2_filesys *fs,
ocfs2_cached_inode *cinode,
diff --git a/libocfs2/alloc.c b/libocfs2/alloc.c
index 7f85a34..ca1a13a 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, suballoc_bit, bitno);
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,8 @@ 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_loc = 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 +218,15 @@ 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_loc = gd_blkno;
+ eb->h_suballoc_bit = suballoc_bit;
eb->h_list.l_count = ocfs2_extent_recs_per_eb(fs->fs_blocksize);
}
@@ -230,6 +235,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 +248,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 +262,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 +281,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 +294,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);
@@ -390,6 +398,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);
@@ -402,13 +411,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)
@@ -416,7 +426,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);
@@ -525,14 +535,16 @@ 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_loc = gd_blkno;
+ rb->rf_suballoc_bit = suballoc_bit;
rb->rf_parent = root_blkno;
if (root_blkno)
rb->rf_flags = OCFS2_REFCOUNT_LEAF_FL;
@@ -546,6 +558,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);
@@ -558,13 +571,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)
@@ -573,7 +587,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);
@@ -631,13 +646,15 @@ out:
*/
static void init_dx_root(ocfs2_filesys *fs,
struct ocfs2_dx_root_block *dx_root,
- int slot, uint64_t gd_blkno, uint64_t dr_blkno)
+ int slot, uint64_t gd_blkno,
+ uint16_t suballoc_bit, uint64_t dr_blkno)
{
memset(dx_root, 0, fs->fs_blocksize);
strcpy((char *)dx_root->dr_signature, OCFS2_DX_ROOT_SIGNATURE);
dx_root->dr_suballoc_slot = slot;
- dx_root->dr_suballoc_bit = (uint16_t)(dr_blkno - gd_blkno);
+ dx_root->dr_suballoc_loc = gd_blkno;
+ dx_root->dr_suballoc_bit = suballoc_bit;
dx_root->dr_fs_generation = fs->fs_super->i_fs_generation;
dx_root->dr_blkno = dr_blkno;
dx_root->dr_flags |= OCFS2_DX_FLAG_INLINE;
@@ -650,6 +667,7 @@ errcode_t ocfs2_new_dx_root(ocfs2_filesys *fs,
errcode_t ret;
char *buf = NULL;
uint64_t gd_blkno;
+ uint16_t suballoc_bit;
struct ocfs2_dx_root_block *dx_root;
int slot;
@@ -667,20 +685,21 @@ errcode_t ocfs2_new_dx_root(ocfs2_filesys *fs,
goto out;
ret = ocfs2_chain_alloc_with_io(fs, fs->fs_eb_allocs[slot],
- &gd_blkno, dr_blkno);
+ &gd_blkno, &suballoc_bit, dr_blkno);
if (ret == OCFS2_ET_BIT_NOT_FOUND) {
ret = ocfs2_chain_add_group(fs, fs->fs_eb_allocs[slot]);
if (ret)
goto out;
ret = ocfs2_chain_alloc_with_io(fs, fs->fs_eb_allocs[slot],
- &gd_blkno, dr_blkno);
+ &gd_blkno, &suballoc_bit,
+ dr_blkno);
if (ret)
goto out;
} else if (ret)
goto out;
dx_root = (struct ocfs2_dx_root_block *)buf;
- init_dx_root(fs, dx_root, slot, gd_blkno, *dr_blkno);
+ init_dx_root(fs, dx_root, slot, gd_blkno, suballoc_bit, *dr_blkno);
ret = ocfs2_write_dx_root(fs, *dr_blkno, (char *)dx_root);
out:
diff --git a/libocfs2/chainalloc.c b/libocfs2/chainalloc.c
index 8980607..6ee353d 100644
--- a/libocfs2/chainalloc.c
+++ b/libocfs2/chainalloc.c
@@ -501,6 +501,7 @@ struct find_gd_state {
ocfs2_filesys *fs;
uint64_t bitno;
uint64_t gd_blkno;
+ uint64_t suballoc_bit;
int found;
};
@@ -514,6 +515,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;
@@ -525,6 +528,7 @@ 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,
+ uint16_t *suballoc_bit,
uint64_t *bitno)
{
errcode_t ret;
@@ -551,9 +555,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