[Ocfs2-tools-devel] [PATCH 6/7] tunefs.ocfs2: Turn on and off the extended slot map

Joel Becker joel.becker at oracle.com
Fri Mar 14 16:38:51 PDT 2008


Support for the extended slot map.  It can be enabled or disabled.

Signed-off-by: Joel Becker <joel.becker at oracle.com>
---
 tunefs.ocfs2/Makefile         |   10 ++++++-
 tunefs.ocfs2/features.c       |   14 +++++++--
 tunefs.ocfs2/format_slotmap.c |   60 +++++++++++++++++++++++++++++++++++++++++
 tunefs.ocfs2/tunefs.c         |   19 +++++++++---
 tunefs.ocfs2/tunefs.h         |    6 +++-
 5 files changed, 99 insertions(+), 10 deletions(-)
 create mode 100644 tunefs.ocfs2/format_slotmap.c

diff --git a/tunefs.ocfs2/Makefile b/tunefs.ocfs2/Makefile
index da0e674..f13383e 100644
--- a/tunefs.ocfs2/Makefile
+++ b/tunefs.ocfs2/Makefile
@@ -20,7 +20,15 @@ DEFINES = -DVERSION=\"$(VERSION)\"
 
 MANS = tunefs.ocfs2.8
 
-CFILES = tunefs.c query.c remove_slot.c sparse_file.c features.c resize.c
+CFILES =		\
+      tunefs.c		\
+	query.c		\
+	remove_slot.c	\
+	sparse_file.c	\
+	features.c	\
+	resize.c	\
+	format_slotmap.c
+
 HFILES = tunefs.h
 
 OBJS = $(subst .c,.o,$(CFILES))
diff --git a/tunefs.ocfs2/features.c b/tunefs.ocfs2/features.c
index 2208269..36307c8 100644
--- a/tunefs.ocfs2/features.c
+++ b/tunefs.ocfs2/features.c
@@ -1,4 +1,6 @@
-/*
+/* -*- mode: c; c-basic-offset: 8; -*-
+ * vim: noexpandtab sw=8 ts=8 sts=0:
+ *
  * features.c
  *
  * source file for adding or removing features for tunefs.
@@ -33,8 +35,10 @@ extern ocfs2_tune_opts opts;
 #define TUNEFS_COMPAT_CLEAR	0
 #define TUNEFS_RO_COMPAT_SET	OCFS2_FEATURE_RO_COMPAT_UNWRITTEN
 #define TUNEFS_RO_COMPAT_CLEAR	OCFS2_FEATURE_RO_COMPAT_UNWRITTEN
-#define TUNEFS_INCOMPAT_SET	OCFS2_FEATURE_INCOMPAT_SPARSE_ALLOC
-#define TUNEFS_INCOMPAT_CLEAR	OCFS2_FEATURE_INCOMPAT_SPARSE_ALLOC
+#define TUNEFS_INCOMPAT_SET	(OCFS2_FEATURE_INCOMPAT_SPARSE_ALLOC | \
+				 OCFS2_FEATURE_INCOMPAT_EXTENDED_SLOT_MAP)
+#define TUNEFS_INCOMPAT_CLEAR	(OCFS2_FEATURE_INCOMPAT_SPARSE_ALLOC | \
+				 OCFS2_FEATURE_INCOMPAT_EXTENDED_SLOT_MAP)
 
 /*
  * Check whether we can add or remove a feature.
@@ -141,6 +145,10 @@ errcode_t update_feature(ocfs2_filesys *fs)
 	if (opts.set_feature.ro_compat & OCFS2_FEATURE_RO_COMPAT_UNWRITTEN)
 		set_unwritten_extents_flag(fs);
 
+	if ((opts.set_feature.incompat | opts.clear_feature.incompat) &
+	    OCFS2_FEATURE_INCOMPAT_EXTENDED_SLOT_MAP)
+		ret = reformat_slot_map(fs);
+
 bail:
 	return ret;
 }
diff --git a/tunefs.ocfs2/format_slotmap.c b/tunefs.ocfs2/format_slotmap.c
new file mode 100644
index 0000000..99c8f25
--- /dev/null
+++ b/tunefs.ocfs2/format_slotmap.c
@@ -0,0 +1,60 @@
+/* -*- mode: c; c-basic-offset: 8; -*-
+ * vim: noexpandtab sw=8 ts=8 sts=0:
+ *
+ * format_slotmap.c
+ *
+ * Switch between slot map formats.
+ *
+ * Copyright (C) 2007 Oracle.  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 as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * 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 "ocfs2/ocfs2.h"
+
+#include <assert.h>
+
+#include <tunefs.h>
+
+extern ocfs2_tune_opts opts;
+
+errcode_t reformat_slot_map(ocfs2_filesys *fs)
+{
+	errcode_t ret = 0;
+	struct ocfs2_super_block *super = OCFS2_RAW_SB(fs->fs_super);
+	int extended = ocfs2_uses_extended_slot_map(super);
+
+	if (opts.set_feature.incompat &
+	    OCFS2_FEATURE_INCOMPAT_EXTENDED_SLOT_MAP) {
+		if (extended) {
+			printf("Feature \"extended-slotmap\" is already enabled, skipping\n");
+			goto out;
+		}
+		OCFS2_SET_INCOMPAT_FEATURE(super, OCFS2_FEATURE_INCOMPAT_EXTENDED_SLOT_MAP);
+	} else if (opts.clear_feature.incompat &
+		   OCFS2_FEATURE_INCOMPAT_EXTENDED_SLOT_MAP) {
+		if (!extended) {
+			printf("Feature \"extended-slotmap\" is not enabled, skipping\n");
+			goto out;
+		}
+		OCFS2_CLEAR_INCOMPAT_FEATURE(super, OCFS2_FEATURE_INCOMPAT_EXTENDED_SLOT_MAP);
+	}
+
+	ret = ocfs2_format_slot_map(fs);
+
+out:
+	return ret;
+}
diff --git a/tunefs.ocfs2/tunefs.c b/tunefs.ocfs2/tunefs.c
index 2a51343..5614396 100644
--- a/tunefs.ocfs2/tunefs.c
+++ b/tunefs.ocfs2/tunefs.c
@@ -1,4 +1,6 @@
-/*
+/* -*- mode: c; c-basic-offset: 8; -*-
+ * vim: noexpandtab sw=8 ts=8 sts=0:
+ *
  * tune.c
  *
  * ocfs2 tune utility
@@ -854,18 +856,25 @@ static void update_mount_type(ocfs2_filesys *fs, int *changed)
 static errcode_t update_slots(ocfs2_filesys *fs, int *changed)
 {
 	errcode_t ret = 0;
+	int orig_slots = OCFS2_RAW_SB(fs->fs_super)->s_max_slots;
 
 	block_signals(SIG_BLOCK);
-	if (opts.num_slots > OCFS2_RAW_SB(fs->fs_super)->s_max_slots)
+	if (opts.num_slots > orig_slots)
 		ret = add_slots(fs);
 	else
 		ret = remove_slots(fs);
-	block_signals(SIG_UNBLOCK);
 	if (ret)
-		return ret;
+		goto unblock;
 
 	OCFS2_RAW_SB(fs->fs_super)->s_max_slots = opts.num_slots;
-	*changed = 1;
+	ret = ocfs2_format_slot_map(fs);
+	if (!ret)
+		*changed = 1;
+	else
+		OCFS2_RAW_SB(fs->fs_super)->s_max_slots = orig_slots;
+
+unblock:
+	block_signals(SIG_UNBLOCK);
 
 	return ret;
 }
diff --git a/tunefs.ocfs2/tunefs.h b/tunefs.ocfs2/tunefs.h
index a2caa96..401be80 100644
--- a/tunefs.ocfs2/tunefs.h
+++ b/tunefs.ocfs2/tunefs.h
@@ -1,4 +1,6 @@
-/*
+/* -*- mode: c; c-basic-offset: 8; -*-
+ * vim: noexpandtab sw=8 ts=8 sts=0:
+ *
  * tune.h
  *
  * ocfs2 tune utility
@@ -107,6 +109,8 @@ errcode_t clear_sparse_file_flag(ocfs2_filesys *fs, char *progname);
 void set_unwritten_extents_flag(ocfs2_filesys *fs);
 void free_clear_ctxt(void);
 
+errcode_t reformat_slot_map(ocfs2_filesys *fs);
+
 errcode_t feature_check(ocfs2_filesys *fs);
 errcode_t update_feature(ocfs2_filesys *fs);
 
-- 
1.5.3.8




More information about the Ocfs2-tools-devel mailing list