[Ocfs2-tools-devel] [PATCH] Make tunefs.ocfs2 understand all journal options.

Michal Srb msrb at suse.cz
Tue Nov 22 04:06:29 PST 2011


The manual page of tunefs.ocfs2 says that tunefs can understand the same -J
options as mkfs.ocfs2 does. That is: size,[no]block32,[no]block64. However
tunefs.ocfs2 understands only the size. This adds the ability to change the
block option too.
---
 tunefs.ocfs2/Makefile               |    1 +
 tunefs.ocfs2/libocfs2ne.c           |   18 +++++-
 tunefs.ocfs2/libocfs2ne.h           |    2 +-
 tunefs.ocfs2/ocfs2ne.c              |   30 ++++++++++
 tunefs.ocfs2/op_set_journal_block.c |  109 +++++++++++++++++++++++++++++++++++
 tunefs.ocfs2/op_set_journal_size.c  |    6 +-
 tunefs.ocfs2/op_set_slot_count.c    |    5 +-
 7 files changed, 164 insertions(+), 7 deletions(-)
 create mode 100644 tunefs.ocfs2/op_set_journal_block.c

diff --git a/tunefs.ocfs2/Makefile b/tunefs.ocfs2/Makefile
index 3847d0f..995d717 100644
--- a/tunefs.ocfs2/Makefile
+++ b/tunefs.ocfs2/Makefile
@@ -40,6 +40,7 @@ OCFS2NE_OPERATIONS =			\
 	op_resize_volume		\
 	op_set_label			\
 	op_set_journal_size		\
+	op_set_journal_block		\
 	op_set_slot_count		\
 	op_update_cluster_stack		\
 	op_set_quota_sync_interval	\
diff --git a/tunefs.ocfs2/libocfs2ne.c b/tunefs.ocfs2/libocfs2ne.c
index 8e814e7..7965727 100644
--- a/tunefs.ocfs2/libocfs2ne.c
+++ b/tunefs.ocfs2/libocfs2ne.c
@@ -331,7 +331,7 @@ errcode_t tunefs_clear_in_progress(ocfs2_filesys *fs, int flag)
 	return ocfs2_write_primary_super(fs);
 }
 
-errcode_t tunefs_set_journal_size(ocfs2_filesys *fs, uint64_t new_size)
+errcode_t tunefs_set_journal_size(ocfs2_filesys *fs, uint64_t new_size, ocfs2_fs_options mask, ocfs2_fs_options options)
 {
 	errcode_t ret = 0;
 	char jrnl_file[OCFS2_MAX_FILENAME_LEN];
@@ -343,6 +343,8 @@ errcode_t tunefs_set_journal_size(ocfs2_filesys *fs, uint64_t new_size)
 	struct ocfs2_dinode *di;
 	struct tunefs_filesystem_state *state = tunefs_get_state(fs);
 	struct tools_progress *prog;
+	ocfs2_fs_options new_features;
+	int features_change;
 
 	num_clusters =
 		ocfs2_clusters_in_blocks(fs,
@@ -379,6 +381,16 @@ errcode_t tunefs_set_journal_size(ocfs2_filesys *fs, uint64_t new_size)
 		return ret;
 	}
 
+	new_features.opt_compat = (state->ts_journal_features.opt_compat & ~mask.opt_compat)
+				  | (options.opt_compat & mask.opt_compat);
+	new_features.opt_incompat = (state->ts_journal_features.opt_incompat & ~mask.opt_incompat)
+				    | (options.opt_incompat & mask.opt_incompat);
+	new_features.opt_ro_compat = (state->ts_journal_features.opt_ro_compat & ~mask.opt_ro_compat)
+				    | (options.opt_ro_compat & mask.opt_ro_compat);
+	features_change = (new_features.opt_compat ^ state->ts_journal_features.opt_compat) ||
+			  (new_features.opt_incompat ^ state->ts_journal_features.opt_incompat) ||
+			  (new_features.opt_ro_compat ^ state->ts_journal_features.opt_ro_compat);
+
 	for (i = 0; i < max_slots; ++i) {
 		ocfs2_sprintf_system_inode_name(jrnl_file,
 						OCFS2_MAX_FILENAME_LEN,
@@ -404,7 +416,7 @@ errcode_t tunefs_set_journal_size(ocfs2_filesys *fs, uint64_t new_size)
 		}
 
 		di = (struct ocfs2_dinode *)buf;
-		if (num_clusters == di->i_clusters) {
+		if (num_clusters == di->i_clusters && !features_change) {
 			tools_progress_step(prog, 1);
 			continue;
 		}
@@ -413,7 +425,7 @@ errcode_t tunefs_set_journal_size(ocfs2_filesys *fs, uint64_t new_size)
 			 "Resizing journal \"%s\" to %"PRIu32" clusters\n",
 			 jrnl_file, num_clusters);
 		ret = ocfs2_make_journal(fs, blkno, num_clusters,
-					 &state->ts_journal_features);
+					 &new_features);
 		if (ret) {
 			verbosef(VL_LIB,
 				 "%s while resizing \"%s\" at block "
diff --git a/tunefs.ocfs2/libocfs2ne.h b/tunefs.ocfs2/libocfs2ne.h
index 15d0ec6..1b75158 100644
--- a/tunefs.ocfs2/libocfs2ne.h
+++ b/tunefs.ocfs2/libocfs2ne.h
@@ -220,7 +220,7 @@ errcode_t tunefs_get_number(char *arg, uint64_t *res);
  * Set all journals to new_size.  If new_size is 0, it will set all
  * journals to the size of the largest existing journal.
  */
-errcode_t tunefs_set_journal_size(ocfs2_filesys *fs, uint64_t new_size);
+errcode_t tunefs_set_journal_size(ocfs2_filesys *fs, uint64_t new_size, ocfs2_fs_options mask, ocfs2_fs_options options);
 
 /* Determine how many clusters the filesystem has free */
 errcode_t tunefs_get_free_clusters(ocfs2_filesys *fs, uint32_t *clusters);
diff --git a/tunefs.ocfs2/ocfs2ne.c b/tunefs.ocfs2/ocfs2ne.c
index df4beb9..32cdb61 100644
--- a/tunefs.ocfs2/ocfs2ne.c
+++ b/tunefs.ocfs2/ocfs2ne.c
@@ -94,6 +94,8 @@ extern struct tunefs_operation reset_uuid_op;
 extern struct tunefs_operation features_op;
 extern struct tunefs_operation resize_volume_op;
 extern struct tunefs_operation set_journal_size_op;
+extern struct tunefs_operation set_journal_block32_op;
+extern struct tunefs_operation set_journal_block64_op;
 extern struct tunefs_operation set_label_op;
 extern struct tunefs_operation set_slot_count_op;
 extern struct tunefs_operation update_cluster_stack_op;
@@ -115,9 +117,37 @@ static struct tunefs_journal_option set_journal_size_option = {
 	.jo_op		= &set_journal_size_op,
 };
 
+static struct tunefs_journal_option set_journal_block64_option = {
+	.jo_name        = "block64",
+	.jo_help        = "block64",
+	.jo_op          = &set_journal_block64_op,
+};
+
+static struct tunefs_journal_option set_journal_block32_option = {
+	.jo_name        = "block32",
+	.jo_help        = "block32",
+	.jo_op          = &set_journal_block32_op,
+};
+
+static struct tunefs_journal_option set_journal_noblock64_option = {
+	.jo_name        = "noblock64",
+	.jo_help        = "noblock64",
+	.jo_op          = &set_journal_block32_op,
+};
+
+static struct tunefs_journal_option set_journal_noblock32_option = {
+	.jo_name        = "noblock32",
+	.jo_help        = "noblock32",
+	.jo_op          = &set_journal_block64_op,
+};
+
 /* The list of all supported journal options */
 static struct tunefs_journal_option *tunefs_journal_options[] = {
 	&set_journal_size_option,
+	&set_journal_block64_option,
+	&set_journal_block32_option,
+	&set_journal_noblock64_option,
+	&set_journal_noblock32_option,
 	NULL,
 };
 
diff --git a/tunefs.ocfs2/op_set_journal_block.c b/tunefs.ocfs2/op_set_journal_block.c
new file mode 100644
index 0000000..9484d14
--- /dev/null
+++ b/tunefs.ocfs2/op_set_journal_block.c
@@ -0,0 +1,109 @@
+/* -*- mode: c; c-basic-offset: 8; -*-
+* vim: noexpandtab sw=8 ts=8 sts=0:
+*
+* op_set_journal_block.c
+*
+* ocfs2 tune utility for updating the block attribute of all journals.
+*
+* Copyright (C) 2004, 2008 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 "ocfs2/ocfs2.h"
+
+#include "libocfs2ne.h"
+
+
+static int set_journal_block32_run(struct tunefs_operation *op,
+				ocfs2_filesys *fs, int flags)
+{
+	errcode_t err;
+	int rc = 0;
+	ocfs2_fs_options mask, options;
+
+	memset(&mask,    0, sizeof(ocfs2_fs_options));
+	memset(&options, 0, sizeof(ocfs2_fs_options));
+	mask.opt_incompat |= JBD2_FEATURE_INCOMPAT_64BIT;
+
+	if (!tools_interact("Set journals on device \"%s\" to "
+			    "block32? ",
+			    fs->fs_devname))
+		goto out;
+
+	tunefs_block_signals();
+	err = tunefs_set_journal_size(fs, 0, mask, options);
+	tunefs_unblock_signals();
+	if (err) {
+		rc = 1;
+		tcom_err(err,
+			"- unable to set block32 to journals on device \"%s\"",
+			fs->fs_devname);
+	}
+
+out:
+	return rc;
+}
+
+static int set_journal_block64_run(struct tunefs_operation *op,
+				ocfs2_filesys *fs, int flags)
+{
+	errcode_t err;
+	int rc = 0;
+	ocfs2_fs_options mask, options;
+
+	memset(&mask,    0, sizeof(ocfs2_fs_options));
+	memset(&options, 0, sizeof(ocfs2_fs_options));
+	mask.opt_incompat |= JBD2_FEATURE_INCOMPAT_64BIT;
+	options.opt_incompat |= JBD2_FEATURE_INCOMPAT_64BIT;
+
+	if (!tools_interact("Set journals on device \"%s\" to "
+			    "block64? ",
+			    fs->fs_devname))
+		goto out;
+
+	tunefs_block_signals();
+	err = tunefs_set_journal_size(fs, 0, mask, options);
+	tunefs_unblock_signals();
+	if (err) {
+		rc = 1;
+		tcom_err(err,
+			"- unable to set block32 to journals on device \"%s\"",
+			fs->fs_devname);
+	}
+
+out:
+	return rc;
+}
+
+
+DEFINE_TUNEFS_OP(set_journal_block32,
+		"Usage: op_set_journal_block32 <device>\n",
+		TUNEFS_FLAG_RW | TUNEFS_FLAG_ALLOCATION,
+		0,
+		set_journal_block32_run);
+
+DEFINE_TUNEFS_OP(set_journal_block64,
+		"Usage: op_set_journal_block64 <device>\n",
+		TUNEFS_FLAG_RW | TUNEFS_FLAG_ALLOCATION,
+		0,
+		set_journal_block64_run);
+
+#ifdef DEBUG_EXE
+int main(int argc, char *argv[])
+{
+	return tunefs_op_main(argc, argv, &set_journal_block32_op);
+}
+#endif
diff --git a/tunefs.ocfs2/op_set_journal_size.c b/tunefs.ocfs2/op_set_journal_size.c
index b671950..045170c 100644
--- a/tunefs.ocfs2/op_set_journal_size.c
+++ b/tunefs.ocfs2/op_set_journal_size.c
@@ -34,7 +34,6 @@ static int set_journal_size_parse_option(struct tunefs_operation *op,
 	errcode_t err;
 	uint64_t *new_size;
 
-
 	if (!arg) {
 		errorf("No size specified\n");
 		goto out;
@@ -66,6 +65,7 @@ static int set_journal_size_run(struct tunefs_operation *op,
 	int rc = 0;
 	uint64_t *argp = (uint64_t *)op->to_private;
 	uint64_t new_size = *argp;
+	ocfs2_fs_options null_options;
 
 	ocfs2_free(&argp);
 	op->to_private = NULL;
@@ -75,8 +75,10 @@ static int set_journal_size_run(struct tunefs_operation *op,
 			    fs->fs_devname, new_size))
 		goto out;
 
+	memset(&null_options, 0, sizeof(ocfs2_fs_options));
+
 	tunefs_block_signals();
-	err = tunefs_set_journal_size(fs, new_size);
+	err = tunefs_set_journal_size(fs, new_size, null_options, null_options);
 	tunefs_unblock_signals();
 	if (err) {
 		rc = 1;
diff --git a/tunefs.ocfs2/op_set_slot_count.c b/tunefs.ocfs2/op_set_slot_count.c
index cdd4f1a..a409087 100644
--- a/tunefs.ocfs2/op_set_slot_count.c
+++ b/tunefs.ocfs2/op_set_slot_count.c
@@ -1071,6 +1071,9 @@ static errcode_t update_slot_count(ocfs2_filesys *fs, int num_slots)
 {
 	errcode_t ret = 0;
 	int orig_slots = OCFS2_RAW_SB(fs->fs_super)->s_max_slots;
+	ocfs2_fs_options null_options;
+
+	memset(&null_options, 0, sizeof(ocfs2_fs_options));
 
 	if (num_slots == orig_slots) {
 		verbosef(VL_APP,
@@ -1099,7 +1102,7 @@ static errcode_t update_slot_count(ocfs2_filesys *fs, int num_slots)
 		/* Grow the new journals to match the first slot */
 		verbosef(VL_APP,
 			 "Allocating space for the new journals\n");
-		ret = tunefs_set_journal_size(fs, 0);
+		ret = tunefs_set_journal_size(fs, 0, null_options, null_options);
 		if (!ret)
 			verbosef(VL_APP, "Journal space allocated\n");
 		else {
-- 
1.7.3.4




More information about the Ocfs2-tools-devel mailing list