[Ocfs2-tools-devel] [PATCH 05/50] libocfs2: Add ocfs2_delete_refcount_block()

Tao Ma tao.ma at oracle.com
Mon Jan 11 07:30:51 PST 2010


The corresponding delete function.

Signed-off-by: Tao Ma <tao.ma at oracle.com>
---
 include/ocfs2/ocfs2.h |    1 +
 libocfs2/alloc.c      |   30 ++++++++++++++++++++++++++++++
 2 files changed, 31 insertions(+), 0 deletions(-)

diff --git a/include/ocfs2/ocfs2.h b/include/ocfs2/ocfs2.h
index 18c55cc..321a423 100644
--- a/include/ocfs2/ocfs2.h
+++ b/include/ocfs2/ocfs2.h
@@ -398,6 +398,7 @@ errcode_t ocfs2_read_refcount_block_nocheck(ocfs2_filesys *fs, uint64_t blkno,
 					    char *eb_buf);
 errcode_t ocfs2_write_refcount_block(ocfs2_filesys *fs, uint64_t blkno,
 				     char *rb_buf);
+errcode_t ocfs2_delete_refcount_block(ocfs2_filesys *fs, uint64_t blkno);
 errcode_t ocfs2_swap_dir_entries_from_cpu(void *buf, uint64_t bytes);
 errcode_t ocfs2_swap_dir_entries_to_cpu(void *buf, uint64_t bytes);
 void ocfs2_swap_dir_trailer(struct ocfs2_dir_block_trailer *trailer);
diff --git a/libocfs2/alloc.c b/libocfs2/alloc.c
index e076bc5..eb85510 100644
--- a/libocfs2/alloc.c
+++ b/libocfs2/alloc.c
@@ -483,6 +483,36 @@ out:
 	return ret;
 }
 
+errcode_t ocfs2_delete_refcount_block(ocfs2_filesys *fs, uint64_t blkno)
+{
+	errcode_t ret;
+	char *buf;
+	struct ocfs2_refcount_block *rb;
+	int slot;
+
+	ret = ocfs2_malloc_block(fs->fs_io, &buf);
+	if (ret)
+		return ret;
+
+	ret = ocfs2_read_refcount_block(fs, blkno, buf);
+	if (ret)
+		goto out;
+	rb = (struct ocfs2_refcount_block *)buf;
+	slot = rb->rf_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], blkno);
+
+out:
+	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
-- 
1.5.5




More information about the Ocfs2-tools-devel mailing list