[Ocfs2-tools-devel] [PATCH] Option to skip cluster checking in tunefs.ocfs2
Jan Kara
jack at suse.cz
Wed Oct 14 09:21:17 PDT 2009
Sometimes, ocfs2-tools do not properly support the cluster stack
used and thus it is necessary to skip cluster locking. Implement
an option --force for tunefs.ocfs2 that allows this.
Signed-off-by: Jan Kara <jack at suse.cz>
---
tunefs.ocfs2/libocfs2ne.c | 45 ++++++++++++++++++++++++---------------
tunefs.ocfs2/ocfs2ne.c | 18 ++++++++++++++++
tunefs.ocfs2/tunefs.ocfs2.8.in | 7 ++++++
3 files changed, 53 insertions(+), 17 deletions(-)
We (SLE11 HAE) need this as a temporary workaround until we properly
support all userspace lock management. I think the patch is useful also
for upstream. Any opinions?
diff --git a/tunefs.ocfs2/libocfs2ne.c b/tunefs.ocfs2/libocfs2ne.c
index 174fef0..89f555a 100644
--- a/tunefs.ocfs2/libocfs2ne.c
+++ b/tunefs.ocfs2/libocfs2ne.c
@@ -678,6 +678,22 @@ void tunefs_init(const char *argv0)
}
/*
+ * Return true if this error code is a special (non-fatal) ocfs2ne
+ * error code.
+ */
+static int tunefs_special_errorp(errcode_t err)
+{
+ if (err == TUNEFS_ET_CLUSTER_SKIPPED)
+ return 1;
+ if (err == TUNEFS_ET_INVALID_STACK_NAME)
+ return 1;
+ if (err == TUNEFS_ET_PERFORM_ONLINE)
+ return 1;
+
+ return 0;
+}
+
+/*
* Single-node filesystems need to prevent mount(8) from happening
* while tunefs.ocfs2 is running. bd_claim does this for us when we
* open O_EXCL.
@@ -856,6 +872,8 @@ out:
return err;
}
+extern int cluster_check_disable;
+
/*
* We try to lock the filesystem in *this* ocfs2_filesys. We get the
* state off of the master, but the filesystem may have changed since
@@ -872,11 +890,21 @@ static errcode_t tunefs_lock_filesystem(ocfs2_filesys *fs, int flags)
{
errcode_t err = 0;
+ if (cluster_check_disable)
+ return 0;
+
if (ocfs2_mount_local(fs))
err = tunefs_lock_local(fs, flags);
else
err = tunefs_lock_cluster(fs, flags);
+ if (err && !tunefs_special_errorp(err)) {
+ fprintf(stderr,
+ "Cannot lock the filesystem. If you are sure the "
+ "filesystem is not mounted on any node, you can use "
+ "--force or -F to skip this check.\n");
+ }
+
return err;
}
@@ -1413,23 +1441,6 @@ static void tunefs_remove_fs(ocfs2_filesys *fs)
}
}
-
-/*
- * Return true if this error code is a special (non-fatal) ocfs2ne
- * error code.
- */
-static int tunefs_special_errorp(errcode_t err)
-{
- if (err == TUNEFS_ET_CLUSTER_SKIPPED)
- return 1;
- if (err == TUNEFS_ET_INVALID_STACK_NAME)
- return 1;
- if (err == TUNEFS_ET_PERFORM_ONLINE)
- return 1;
-
- return 0;
-}
-
errcode_t tunefs_open(const char *device, int flags,
ocfs2_filesys **ret_fs)
{
diff --git a/tunefs.ocfs2/ocfs2ne.c b/tunefs.ocfs2/ocfs2ne.c
index 48760c6..42aa269 100644
--- a/tunefs.ocfs2/ocfs2ne.c
+++ b/tunefs.ocfs2/ocfs2ne.c
@@ -241,6 +241,14 @@ static int handle_answer(struct tunefs_option *opt, char *arg)
return rc;
}
+int cluster_check_disable = 0;
+
+static int handle_force(struct tunefs_option *opt, char *arg)
+{
+ cluster_check_disable = 1;
+ return 0;
+}
+
/*
* Plain operations just want to have their ->to_parse_option() called.
* Their tunefs_option can use this function if they set opt_op to the
@@ -468,6 +476,15 @@ static struct tunefs_option no_option = {
.opt_handle = handle_answer,
};
+static struct tunefs_option force_option = {
+ .opt_option = {
+ .name = "force",
+ .val = 'F',
+ },
+ .opt_help = "-F|--force (skip cluster locking)",
+ .opt_handle = handle_force,
+};
+
static struct tunefs_option query_option = {
.opt_option = {
.name = "query",
@@ -615,6 +632,7 @@ static struct tunefs_option *options[] = {
&progress_option,
&verbose_option,
&quiet_option,
+ &force_option,
&set_label_option,
&set_slot_count_option,
&resize_volume_option,
diff --git a/tunefs.ocfs2/tunefs.ocfs2.8.in b/tunefs.ocfs2/tunefs.ocfs2.8.in
index 8a9954c..d5d9ec1 100644
--- a/tunefs.ocfs2/tunefs.ocfs2.8.in
+++ b/tunefs.ocfs2/tunefs.ocfs2.8.in
@@ -98,6 +98,13 @@ Always answer Yes in interactive command line.
Always answer No in interactive command line.
.TP
+\fB\-f, \-\-force\fR
+Skip any locking of the filesystem. Use this option with care! You have to make
+sure that the filesystem is not mounted on this or any other node of the
+cluster. Making changes by tunefs.ocfs2 while the filesystem is mounted can
+cause filesystem corruption.
+
+.TP
\fB\-\-backup\-super\fR
Backs up the superblock to fixed offsets (1G, 4G, 16G, 64G, 256G and 1T)
on disk. This option is useful for users to backup the superblock on volumes
--
1.6.0.2
Jan Kara <jack at suse.cz>
SUSE Labs, CR
More information about the Ocfs2-tools-devel
mailing list