[Ocfs2-tools-devel] [PATCH 3/6] libocfs2: add ocfs2_new_xattr_block
Tiger Yang
tiger.yang at oracle.com
Wed Jul 29 00:01:46 PDT 2009
This function use to alloc and initialize xattr block.
when xattr in inode is full, then alloc a new xattr block,
when xattr block is full, we change xattr block to index block,
and mv all xattrs in block to new bucket.
Signed-off-by: Tiger Yang <tiger.yang at oracle.com>
---
include/ocfs2/ocfs2.h | 1 +
libocfs2/alloc.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 47 insertions(+), 0 deletions(-)
diff --git a/include/ocfs2/ocfs2.h b/include/ocfs2/ocfs2.h
index a171089..d1514db 100644
--- a/include/ocfs2/ocfs2.h
+++ b/include/ocfs2/ocfs2.h
@@ -1165,5 +1165,6 @@ errcode_t ocfs2_extent_iterate_xattr(ocfs2_filesys *fs,
void *priv_data,
int *changed);
errcode_t ocfs2_delete_xattr_block(ocfs2_filesys *fs, uint64_t blkno);
+errcode_t ocfs2_new_xattr_block(ocfs2_filesys *fs, uint64_t *blkno);
#endif /* _FILESYS_H */
diff --git a/libocfs2/alloc.c b/libocfs2/alloc.c
index e076bc5..9cf8f92 100644
--- a/libocfs2/alloc.c
+++ b/libocfs2/alloc.c
@@ -416,6 +416,52 @@ out:
return ret;
}
+errcode_t ocfs2_new_xattr_block(ocfs2_filesys *fs, uint64_t *blkno)
+{
+ errcode_t ret;
+ char *buf;
+ uint64_t gd_blkno;
+ struct ocfs2_xattr_block *xb;
+
+ ret = ocfs2_malloc_block(fs->fs_io, &buf);
+ if (ret)
+ return ret;
+
+ ret = ocfs2_load_allocator(fs, EXTENT_ALLOC_SYSTEM_INODE, 0,
+ &fs->fs_eb_allocs[0]);
+ if (ret)
+ goto out;
+
+ ret = ocfs2_chain_alloc_with_io(fs, fs->fs_eb_allocs[0],
+ &gd_blkno, 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);
+ if (ret)
+ goto out;
+ } else if (ret)
+ goto out;
+
+ memset(buf, 0, fs->fs_blocksize);
+ xb = (struct ocfs2_xattr_block *)buf;
+
+ strcpy((char *)xb->xb_signature, OCFS2_XATTR_BLOCK_SIGNATURE);
+ xb->xb_suballoc_slot = 0;
+ xb->xb_suballoc_bit = (uint16_t)(*blkno - gd_blkno);
+ xb->xb_fs_generation = fs->fs_super->i_fs_generation;
+ xb->xb_blkno = *blkno;
+
+ ret = ocfs2_write_xattr_block(fs, *blkno, buf);
+
+out:
+ ocfs2_free(&buf);
+
+ return ret;
+}
+
errcode_t ocfs2_delete_xattr_block(ocfs2_filesys *fs, uint64_t blkno)
{
errcode_t ret;
--
1.5.4.1
More information about the Ocfs2-tools-devel
mailing list