[Ocfs2-tools-devel] [RFC 2/4] dx_dirs v2: delete dx_root in libocfs2/alloc.c
Coly Li
coly.li at suse.de
Fri Dec 25 11:23:04 PST 2009
This patch uses ocfs2_chain_free_with_io() to release the block allocated for dx_root.
Signed-off-by: Coly Li <coly.li at suse.de>
---
diff --git a/include/ocfs2/ocfs2.h b/include/ocfs2/ocfs2.h
index 8d677f0..648b8b8 100644
--- a/include/ocfs2/ocfs2.h
+++ b/include/ocfs2/ocfs2.h
@@ -405,7 +405,7 @@ errcode_t ocfs2_read_dx_root(ocfs2_filesys *fs, uint64_t block,
errcode_t ocfs2_read_dx_leaf(ocfs2_filesys *fs, uint64_t block,
void *buf);
int ocfs2_dir_indexed(struct ocfs2_dinode *di);
-
+int ocfs2_dx_dir_truncate(ocfs2_filesys *fs, struct ocfs2_dinode *di);
errcode_t ocfs2_dir_iterate2(ocfs2_filesys *fs,
uint64_t dir,
int flags,
@@ -603,6 +603,8 @@ errcode_t ocfs2_new_system_inode(ocfs2_filesys *fs, uint64_t *ino, int mode, int
errcode_t ocfs2_delete_inode(ocfs2_filesys *fs, uint64_t ino);
errcode_t ocfs2_new_extent_block(ocfs2_filesys *fs, uint64_t *blkno);
errcode_t ocfs2_delete_extent_block(ocfs2_filesys *fs, uint64_t blkno);
+errcode_t ocfs2_delete_dx_root(ocfs2_filesys *fs, uint64_t dr_blkno);
+
/*
* Allocate the blocks and insert them to the file.
* only i_clusters of dinode will be updated accordingly, i_size not changed.
@@ -1256,6 +1258,10 @@ static inline int ocfs2_supports_indexed_dirs(struct ocfs2_super_block *osb)
#define OCFS2_BLOCK_ABORT 0x02
#define OCFS2_BLOCK_ERROR 0x04
+
+#define OCFS2_IS_VALID_DX_ROOT(ptr) \
+ (!strcmp((char *)(ptr)->dr_signature, OCFS2_DX_ROOT_SIGNATURE))
+
/*
* Block iterate flags
*
@@ -1382,5 +1388,8 @@ 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_dir_indexed_tree_truncate(ocfs2_filesys *fs,
+ struct ocfs2_dx_root_block *dx_root);
+
#endif /* _FILESYS_H */
diff --git a/libocfs2/Makefile b/libocfs2/Makefile
index 8e94cc3..6d3b563 100644
--- a/libocfs2/Makefile
+++ b/libocfs2/Makefile
@@ -76,7 +76,8 @@ CFILES = \
quota.c \
image.c \
xattr.c \
- extent_tree.c
+ extent_tree.c \
+ dir_indexed.c
HFILES = \
bitmap.h \
diff --git a/libocfs2/alloc.c b/libocfs2/alloc.c
index e076bc5..bc27eff 100644
--- a/libocfs2/alloc.c
+++ b/libocfs2/alloc.c
@@ -483,6 +483,38 @@ out:
return ret;
}
+errcode_t ocfs2_delete_dx_root(ocfs2_filesys *fs, uint64_t dr_blkno)
+{
+ errcode_t ret;
+ char *buf = NULL;
+ struct ocfs2_dx_root_block *dx_root;
+ int slot;
+
+ ret = ocfs2_malloc_block(fs->fs_io, &buf);
+ if (ret)
+ goto out;
+
+ ret = ocfs2_read_dx_root(fs, dr_blkno, buf);
+ if (ret)
+ goto out;
+
+ dx_root = (struct ocfs2_dx_root_block *)buf;
+ slot = dx_root->dr_suballoc_slot;
+
+ ret = ocfs2_load_allocator(fs, EXTENT_ALLOC_SYSTEM_INODE, slot,
+ &fs->fs_eb_allocs[slot]);
+ if (ret)
+ goto out;
+
+ ret = ocfs2_chain_free_with_io(fs, fs->fs_eb_allocs[slot], dr_blkno);
+
+out:
+ if (buf)
+ ocfs2_free(&buf);
+
+ return ret;
+}
+
/* XXX what to do about local allocs?
* XXX Well, we shouldn't use local allocs to allocate, as we are
* userspace and we have the entire bitmap in memory. However, this
@@ -627,6 +659,7 @@ out:
return ret;
}
+
#ifdef DEBUG_EXE
#include <stdio.h>
--
Coly Li
SuSE Labs
More information about the Ocfs2-tools-devel
mailing list