[Ocfs2-tools-devel] [PATCH 2/2] ocfs2-tools: convert fixed metadata file with tunefs
Tiger Yang
tiger.yang at oracle.com
Wed Jan 19 01:26:59 PST 2011
This patch implement a tunefs operation to convert fixed metadata
file. As a fixed metadata file can not be changed, we need this
operation to convert it to a modifiable file, and we can also use
this operation to convert a common file to a fixed metadata file.
Signed-off-by: Tiger Yang <tiger.yang at oracle.com>
---
tunefs.ocfs2/Makefile | 3 +-
tunefs.ocfs2/ocfs2ne.c | 13 +++
tunefs.ocfs2/op_toggle_fixed_metadata.c | 123 +++++++++++++++++++++++++++++++
3 files changed, 138 insertions(+), 1 deletions(-)
create mode 100644 tunefs.ocfs2/op_toggle_fixed_metadata.c
diff --git a/tunefs.ocfs2/Makefile b/tunefs.ocfs2/Makefile
index 885cdce..4d52979 100644
--- a/tunefs.ocfs2/Makefile
+++ b/tunefs.ocfs2/Makefile
@@ -42,7 +42,8 @@ OCFS2NE_OPERATIONS = \
op_set_slot_count \
op_update_cluster_stack \
op_set_quota_sync_interval \
- op_create_fixed_metadata
+ op_create_fixed_metadata \
+ op_toggle_fixed_metadata
sbindir = $(root_sbindir)
SBIN_PROGRAMS = tunefs.ocfs2
diff --git a/tunefs.ocfs2/ocfs2ne.c b/tunefs.ocfs2/ocfs2ne.c
index dbe67ac..9678430 100644
--- a/tunefs.ocfs2/ocfs2ne.c
+++ b/tunefs.ocfs2/ocfs2ne.c
@@ -101,6 +101,7 @@ extern struct tunefs_operation cloned_volume_op;
extern struct tunefs_operation set_usrquota_sync_interval_op;
extern struct tunefs_operation set_grpquota_sync_interval_op;
extern struct tunefs_operation create_fixedmeta_op;
+extern struct tunefs_operation toggle_fixedmeta_op;
/* List of operations we're going to run */
static LIST_HEAD(tunefs_run_list);
@@ -621,6 +622,17 @@ static struct tunefs_option create_fixedmeta_option = {
.opt_op = &create_fixedmeta_op,
};
+static struct tunefs_option toggle_fixedmeta_option = {
+ .opt_option = {
+ .name = "toggle-fixedmeta",
+ .val = CHAR_MAX,
+ .has_arg = 1,
+ },
+ .opt_help = " --toggle-fixedmeta <filename>",
+ .opt_handle = &generic_handle_arg,
+ .opt_op = &toggle_fixedmeta_op,
+};
+
/* The order here creates the order in print_usage() */
static struct tunefs_option *options[] = {
&help_option,
@@ -644,6 +656,7 @@ static struct tunefs_option *options[] = {
&set_usrquota_sync_interval_option,
&set_grpquota_sync_interval_option,
&create_fixedmeta_option,
+ &toggle_fixedmeta_option,
&yes_option,
&no_option,
NULL,
diff --git a/tunefs.ocfs2/op_toggle_fixed_metadata.c b/tunefs.ocfs2/op_toggle_fixed_metadata.c
new file mode 100644
index 0000000..1ffe26a
--- /dev/null
+++ b/tunefs.ocfs2/op_toggle_fixed_metadata.c
@@ -0,0 +1,123 @@
+/* -*- mode: c; c-basic-offset: 8; -*-
+ * vim: noexpandtab sw=8 ts=8 sts=0:
+ *
+ * op_toggle_fixed_metadata.c
+ *
+ * ocfs2 tune utility to create the fixed metadada file.
+ *
+ * Copyright (C) 2010 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 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 <string.h>
+#include <ctype.h>
+#include <inttypes.h>
+#include <uuid/uuid.h>
+
+#include "ocfs2/ocfs2.h"
+#include "libocfs2ne.h"
+
+static errcode_t toggle_fixed_metadata_file(ocfs2_filesys *fs, char *name)
+{
+ errcode_t err;
+ uint64_t blkno = 0;
+ char *buf = NULL;
+ struct tools_progress *prog = NULL;
+ struct ocfs2_dinode *di = NULL;
+ struct ocfs2_super_block *sb = OCFS2_RAW_SB(fs->fs_super);
+
+ err = ocfs2_malloc_block(fs->fs_io, &buf);
+ if (err)
+ return err;
+
+ err = ocfs2_lookup(fs, sb->s_root_blkno, name, strlen(name),
+ NULL, &blkno);
+ if (err)
+ goto bail;
+
+ errorf("blkno = %"PRIu64"\n", blkno);
+ err = ocfs2_read_inode(fs, blkno, buf);
+ if (err)
+ goto bail;
+ di = (struct ocfs2_dinode *)buf;
+ if (di->i_attr & OCFS2_FIXEDMETA_FL) {
+ if (!tools_interact("Change the fixed metadata file %s "
+ "to common file on device \"%s\"? ", name,
+ fs->fs_devname))
+ return 0;
+ di->i_attr &= ~(OCFS2_FIXEDMETA_FL);
+ } else {
+ if (!tools_interact("Change file %s to the fixed metadata file"
+ " on device \"%s\"? ", name,
+ fs->fs_devname))
+ return 0;
+ di->i_attr |= OCFS2_FIXEDMETA_FL;
+ }
+
+ prog = tools_progress_start("toggle fixed metadata file",
+ "toggle fixedmeta", 1);
+ if (!prog)
+ return TUNEFS_ET_NO_MEMORY;
+
+ err = ocfs2_write_inode(fs, blkno, buf);
+
+ tools_progress_step(prog, 1);
+ tools_progress_stop(prog);
+
+bail:
+ if (buf)
+ ocfs2_free(&buf);
+ return err;
+}
+
+static int toggle_fixedmeta_parse_option(struct tunefs_operation *op,
+ char *arg)
+{
+ if (arg == NULL) {
+ errorf("Invalid filename.\n");
+ return 1;
+ }
+ op->to_private = arg;
+
+ return 0;
+}
+
+static int toggle_fixedmeta_run(struct tunefs_operation *op, ocfs2_filesys *fs,
+ int flags)
+{
+ int rc = 0;
+ errcode_t ret;
+
+ ret = toggle_fixed_metadata_file(fs, op->to_private);
+ if (ret) {
+ tcom_err(ret, "- unable to change file %s"
+ " on device \"%s\"",
+ (char *)op->to_private, fs->fs_devname);
+ rc = 1;
+ }
+ op->to_private = NULL;
+
+ return rc;
+}
+
+DEFINE_TUNEFS_OP(toggle_fixedmeta,
+ "Usage: op_toggle_fixedmeta [opts] <device>\n",
+ TUNEFS_FLAG_RW,
+ toggle_fixedmeta_parse_option,
+ toggle_fixedmeta_run);
+
+#ifdef DEBUG_EXE
+int main(int argc, char *argv[])
+{
+ return tunefs_op_main(argc, argv, &toggle_fixedmeta_op);
+}
+#endif
--
1.5.4.3
More information about the Ocfs2-tools-devel
mailing list