[Ocfs2-tools-devel] [PATCH 1/7] libocfs2: allocate and initialize new xattr block

Tiger Yang tiger.yang at oracle.com
Tue Oct 20 01:41:06 PDT 2009


This patch add ocfs2_new_xattr_block for allocating and initializing
xattr block. We always try to put new xattr in inode, but if no space
for xattr in inode, will allocate a xattr block for them.
Further, if xattr block is full, will reformat xattr block to index block
and move all xattrs from block to new allocated buckets.

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 58d09f7..ee22fe3 100644
--- a/include/ocfs2/ocfs2.h
+++ b/include/ocfs2/ocfs2.h
@@ -1320,5 +1320,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