[Ocfs2-tools-devel] [RFC 3/4] dx_dirs v2: truncate dx_dir

Coly Li coly.li at suse.de
Fri Dec 25 11:23:23 PST 2009


Removed most of the redundant code and use already existed code.

Signed-off-by: Coly Li <coly.li at suse.de>
---
diff --git a/libocfs2/dir_indexed.c b/libocfs2/dir_indexed.c
new file mode 100644
index 0000000..11925f0
--- /dev/null
+++ b/libocfs2/dir_indexed.c
@@ -0,0 +1,61 @@
+/* -*- mode: c; c-basic-offset: 8; -*-
+ * vim: noexpandtab sw=8 ts=8 sts=0:
+ *
+ * Copyright (C) 2009 Novell.  All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public
+ * License, version 2,  as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with this program; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 021110-1307, USA.
+ */
+#include <assert.h>
+#include <ocfs2/ocfs2.h>
+#include <ocfs2/bitops.h>
+#include <ocfs2/kernel-rbtree.h>
+#include "extent_tree.h"
+#include "dir_indexed.h"
+
+
+int ocfs2_dx_dir_truncate(ocfs2_filesys *fs,
+			struct ocfs2_dinode *di)
+{
+	struct ocfs2_dx_root_block *dx_root;
+	char *buf = NULL;
+	int ret;
+
+	if (!(di->i_dyn_features & OCFS2_INDEXED_DIR_FL))
+		return 0;
+
+	ret = ocfs2_malloc_block(fs->fs_io, &buf);
+	if (ret)
+		goto bail;
+	ret = ocfs2_read_dx_root(fs, (uint64_t)di->i_dx_root, buf);
+	if (ret)
+		goto bail;
+	dx_root = (struct ocfs2_dx_root_block *)buf;
+	
+	if (dx_root->dr_flags & OCFS2_DX_FLAG_INLINE)
+		goto remove_index;
+
+	ret = ocfs2_dir_indexed_tree_truncate(fs, dx_root);
+
+remove_index:
+	ret = ocfs2_delete_dx_root(fs, dx_root->dr_blkno);
+
+	di->i_dyn_features &= ~OCFS2_INDEXED_DIR_FL;
+	di->i_dx_root = 0;
+bail:
+	if (buf)
+		ocfs2_free(&buf);
+	return ret;
+}
+
diff --git a/libocfs2/truncate.c b/libocfs2/truncate.c
index 680fca5..2a39543 100644
--- a/libocfs2/truncate.c
+++ b/libocfs2/truncate.c
@@ -331,6 +331,21 @@ errcode_t ocfs2_xattr_tree_truncate(ocfs2_filesys *fs,
 					&ctxt, &changed);
 }

+
+errcode_t ocfs2_dir_indexed_tree_truncate(ocfs2_filesys *fs,
+					struct ocfs2_dx_root_block *dx_root)
+{
+	struct truncate_ctxt ctxt;
+
+	ctxt.new_i_clusters = dx_root->dr_clusters;
+	ctxt.new_size_in_clusters = 0;
+
+	return ocfs2_extent_iterate_dx_root(fs, dx_root,
+					OCFS2_EXTENT_FLAG_DEPTH_TRAVERSE,
+		       			NULL, truncate_iterate,	&ctxt);
+}
+
+
 #ifdef DEBUG_EXE
 #include <stdlib.h>
 #include <getopt.h>
-- 
Coly Li
SuSE Labs



More information about the Ocfs2-tools-devel mailing list