[Ocfs2-tools-devel] [RFC 3/4] dx_dirs v1: add indexed dir code for extent_tree
Coly Li
coly.li at suse.de
Sun Dec 20 10:02:31 PST 2009
This patch adds indexed dirs related code to libocfs2/extent_tree.c and libocfs2/extent_tree.h.
Signed-off-by: Coly Li <coly.li at suse.de>
---
diff --git a/libocfs2/extent_tree.c b/libocfs2/extent_tree.c
index 499ce1b..e5d13f3 100644
--- a/libocfs2/extent_tree.c
+++ b/libocfs2/extent_tree.c
@@ -23,6 +23,7 @@
#include "ocfs2/byteorder.h"
#include "ocfs2/ocfs2.h"
#include "extent_tree.h"
+#include "dealloc.h"
static void ocfs2_dinode_set_last_eb_blk(struct ocfs2_extent_tree *et,
uint64_t blkno)
@@ -60,6 +61,49 @@ static struct ocfs2_extent_tree_operations ocfs2_dinode_et_ops = {
.eo_fill_root_el = ocfs2_dinode_fill_root_el,
};
+static void ocfs2_dx_root_set_last_eb_blk (struct ocfs2_extent_tree *et,
+ uint64_t blkno)
+{
+ struct ocfs2_dx_root_block *dx_root = et->et_object;
+ dx_root->dr_last_eb_blk = blkno;
+}
+
+static uint64_t ocfs2_dx_root_get_last_eb_blk (struct ocfs2_extent_tree *et)
+{
+ struct ocfs2_dx_root_block *dx_root = et->et_object;
+ return dx_root->dr_last_eb_blk;
+}
+
+static void ocfs2_dx_root_update_clusters(struct ocfs2_extent_tree *et,
+ uint32_t clusters)
+{
+ struct ocfs2_dx_root_block *dx_root = et->et_object;
+ dx_root->dr_clusters += clusters;
+}
+
+static int ocfs2_dx_root_sanity_check(struct ocfs2_extent_tree *et)
+{
+ struct ocfs2_dx_root_block *dx_root = (struct ocfs2_dx_root_block *)et->et_object;
+ assert(OCFS2_IS_VALID_DX_ROOT(dx_root));
+
+ return 0;
+}
+
+static void ocfs2_dx_root_fill_root_el (struct ocfs2_extent_tree *et)
+{
+ struct ocfs2_dx_root_block *dx_root = et->et_object;
+
+ et->et_root_el = &dx_root->dr_list;
+}
+
+static struct ocfs2_extent_tree_operations ocfs2_dx_root_et_ops = {
+ .eo_set_last_eb_blk = ocfs2_dx_root_set_last_eb_blk,
+ .eo_get_last_eb_blk = ocfs2_dx_root_get_last_eb_blk,
+ .eo_update_clusters = ocfs2_dx_root_update_clusters,
+ .eo_sanity_check = ocfs2_dx_root_sanity_check,
+ .eo_fill_root_el = ocfs2_dx_root_fill_root_el,
+};
+
static void __ocfs2_init_extent_tree(struct ocfs2_extent_tree *et,
ocfs2_filesys *fs,
char *buf,
@@ -90,6 +134,15 @@ void ocfs2_init_dinode_extent_tree(struct ocfs2_extent_tree *et,
buf, &ocfs2_dinode_et_ops);
}
+void ocfs2_init_dx_root_extent_tree(struct ocfs2_extent_tree *et,
+ ocfs2_filesys *fs,
+ char *buf, uint64_t blkno)
+{
+ __ocfs2_init_extent_tree(et, fs, buf, blkno,
+ NULL,
+ NULL, &ocfs2_dx_root_et_ops);
+}
+
static inline void ocfs2_et_set_last_eb_blk(struct ocfs2_extent_tree *et,
uint64_t new_last_eb_blk)
{
@@ -4072,3 +4125,53 @@ out:
ocfs2_free_path(path);
return ret;
}
+
+
+int ocfs2_remove_btree_range(ocfs2_filesys *fs, struct ocfs2_dinode *di,
+ struct ocfs2_extent_tree *et, uint32_t cpos,
+ uint32_t p_cpos, uint32_t len)
+{
+ int ret;
+ uint64_t p_blkno = ocfs2_clusters_to_blocks(fs, p_cpos);
+ uint64_t blkno;
+ char *tmp_di_buf = NULL;
+ struct ocfs2_truncate_log *tl;
+ struct ocfs2_dinode *tmp_di;
+
+ ret = ocfs2_lookup_system_inode(fs, TRUNCATE_LOG_SYSTEM_INODE,
+ di->i_suballoc_slot, &blkno);
+ if (ret)
+ goto out;
+ ret = ocfs2_malloc_block(fs->fs_io, &tmp_di_buf);
+ if (ret)
+ goto out;
+ ret = ocfs2_read_inode(fs, blkno, tmp_di_buf);
+ if (ret)
+ goto out;
+
+ tmp_di = (struct ocfs2_dinode *)tmp_di_buf;
+ tl = &tmp_di->id2.i_dealloc;
+
+ if (ocfs2_truncate_log_needs_flush(tl)) {
+ ret = ocfs2_flush_truncate_log(fs, tl);
+ if (ret) {
+ goto out;
+ }
+ }
+
+ ret = ocfs2_remove_extent(fs, et, cpos, len);
+ if (ret) {
+ printf ("error\n");
+ goto out;
+ }
+
+ ocfs2_et_update_clusters(et, -len);
+ ret = ocfs2_truncate_log_append(fs, tmp_di, tl, p_blkno, len);
+ if (ret)
+ printf("truncate_log_append error\n");
+out:
+ if (tmp_di_buf)
+ ocfs2_free(&tmp_di_buf);
+ return ret;
+}
+
diff --git a/libocfs2/extent_tree.h b/libocfs2/extent_tree.h
index 4e6e091..651d382 100644
--- a/libocfs2/extent_tree.h
+++ b/libocfs2/extent_tree.h
@@ -109,3 +109,10 @@ int ocfs2_change_extent_flag(ocfs2_filesys *fs,
int ocfs2_remove_extent(ocfs2_filesys *fs,
struct ocfs2_extent_tree *et,
uint32_t cpos, uint32_t len);
+void ocfs2_init_dx_root_extent_tree(struct ocfs2_extent_tree *et,
+ ocfs2_filesys *fs,
+ char *buf, uint64_t blkno);
+int ocfs2_remove_btree_range(ocfs2_filesys *fs, struct ocfs2_dinode *di,
+ struct ocfs2_extent_tree *et, uint32_t cpos,
+ uint32_t p_cpos, uint32_t len);
+
--
Coly Li
SuSE Labs
More information about the Ocfs2-tools-devel
mailing list