[Ocfs2-tools-devel] [PATCH 04/10] dx_dirs v6: Add tunefs.ocfs2 feature for indexed directories

Coly Li coly.li at suse.de
Thu Jan 28 12:41:09 PST 2010


This only enables them for now. Disabling is a bit more involved, and will come later.

Signed-off-by: Mark Fasheh <mfasheh at suse.com>
Signed-off-by: Coly Li <coly.li at suse.de>
---
 tunefs.ocfs2/Makefile               |    1 +
 tunefs.ocfs2/feature_indexed_dirs.c |   89 +++++++++++++++++++++++++++++++++++
 tunefs.ocfs2/op_features.c          |    2 +
 3 files changed, 92 insertions(+), 0 deletions(-)
 create mode 100644 tunefs.ocfs2/feature_indexed_dirs.c

diff --git a/tunefs.ocfs2/Makefile b/tunefs.ocfs2/Makefile
index 8806f52..80cacfb 100644
--- a/tunefs.ocfs2/Makefile
+++ b/tunefs.ocfs2/Makefile
@@ -25,6 +25,7 @@ OCFS2NE_FEATURES =			\
 	feature_sparse_files		\
 	feature_unwritten_extents	\
 	feature_xattr			\
+	feature_indexed_dirs		\
 	feature_quota

 OCFS2NE_OPERATIONS =			\
diff --git a/tunefs.ocfs2/feature_indexed_dirs.c b/tunefs.ocfs2/feature_indexed_dirs.c
new file mode 100644
index 0000000..368eb87
--- /dev/null
+++ b/tunefs.ocfs2/feature_indexed_dirs.c
@@ -0,0 +1,89 @@
+/* -*- mode: c; c-basic-offset: 8; -*-
+ * vim: noexpandtab sw=8 ts=8 sts=0:
+ *
+ * feature_indexed_dirs.c
+ *
+ * ocfs2 tune utility for enabling and disabling the directory indexing
+ * feature.
+ *
+ * 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.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/stat.h>
+#include <ctype.h>
+#include <inttypes.h>
+#include <assert.h>
+
+#include "ocfs2/ocfs2.h"
+
+#include "libocfs2ne.h"
+
+
+static int enable_indexed_dirs(ocfs2_filesys *fs, int flags)
+{
+	errcode_t ret = 0;
+	struct ocfs2_super_block *super = OCFS2_RAW_SB(fs->fs_super);
+	struct tools_progress *prog;
+
+	if (ocfs2_supports_indexed_dirs(super)) {
+		verbosef(VL_APP,
+			 "Directory indexing feature is already enabled; "
+			 "nothing to enable\n");
+		goto out;
+	}
+
+
+	if (!tools_interact("Enable the directory indexing feature on "
+			    "device \"%s\"? ",
+			    fs->fs_devname))
+		goto out;
+
+	prog = tools_progress_start("Enable directory indexing", "dir idx", 1);
+	if (!prog) {
+		ret = TUNEFS_ET_NO_MEMORY;
+		tcom_err(ret, "while initializing the progress display");
+		goto out;
+	}
+
+	OCFS2_SET_INCOMPAT_FEATURE(super,
+				   OCFS2_FEATURE_INCOMPAT_INDEXED_DIRS);
+	tunefs_block_signals();
+	ret = ocfs2_write_super(fs);
+	tunefs_unblock_signals();
+	if (ret)
+		tcom_err(ret, "while writing out the superblock");
+
+	tools_progress_step(prog, 1);
+	tools_progress_stop(prog);
+out:
+	return ret;
+}
+
+/*
+ * TUNEFS_FLAG_ALLOCATION because disabling will want to dealloc
+ * blocks.
+ */
+DEFINE_TUNEFS_FEATURE_INCOMPAT(indexed_dirs,
+			       OCFS2_FEATURE_INCOMPAT_INDEXED_DIRS,
+			       TUNEFS_FLAG_RW | TUNEFS_FLAG_ALLOCATION,
+			       enable_indexed_dirs,
+			       NULL);
+
+#ifdef DEBUG_EXE
+int main(int argc, char *argv[])
+{
+	return tunefs_feature_main(argc, argv, &indexed_dirs_feature);
+}
+#endif
diff --git a/tunefs.ocfs2/op_features.c b/tunefs.ocfs2/op_features.c
index afcc1f4..7a6aabd 100644
--- a/tunefs.ocfs2/op_features.c
+++ b/tunefs.ocfs2/op_features.c
@@ -41,6 +41,7 @@ extern struct tunefs_feature metaecc_feature;
 extern struct tunefs_feature sparse_files_feature;
 extern struct tunefs_feature unwritten_extents_feature;
 extern struct tunefs_feature xattr_feature;
+extern struct tunefs_feature indexed_dirs_feature;
 extern struct tunefs_feature usrquota_feature;
 extern struct tunefs_feature grpquota_feature;

@@ -54,6 +55,7 @@ static struct tunefs_feature *features[] = {
 	&sparse_files_feature,
 	&unwritten_extents_feature,
 	&xattr_feature,
+	&indexed_dirs_feature,
 	&usrquota_feature,
 	&grpquota_feature,
 	NULL,
-- 
1.6.4.2

-- 
Coly Li
SuSE Labs



More information about the Ocfs2-tools-devel mailing list