[Ocfs2-tools-devel] [PATCH 24/25] mount.ocfs2: Add support for o2cb global heartbeat
Sunil Mushran
sunil.mushran at oracle.com
Wed Jun 23 11:44:34 PDT 2010
mount.ocfs2 is now o2cb global heartbeat-aware. It appends heartbeat=global
when mounting an ocfs2 volume in global heartbeat mode. It relies on the
o2cb framework to validate the heartbeat mode.
Signed-off-by: Sunil Mushran <sunil.mushran at oracle.com>
---
include/ocfs2-kernel/ocfs2_fs.h | 1 +
mount.ocfs2/mount.ocfs2.c | 91 ++++++++++++++++++++++++++-------------
2 files changed, 62 insertions(+), 30 deletions(-)
diff --git a/include/ocfs2-kernel/ocfs2_fs.h b/include/ocfs2-kernel/ocfs2_fs.h
index e6b4da1..3429150 100644
--- a/include/ocfs2-kernel/ocfs2_fs.h
+++ b/include/ocfs2-kernel/ocfs2_fs.h
@@ -373,6 +373,7 @@ static struct ocfs2_system_inode_info ocfs2_system_inodes[NUM_SYSTEM_INODES] = {
/* Parameter passed from mount.ocfs2 to module */
#define OCFS2_HB_NONE "heartbeat=none"
#define OCFS2_HB_LOCAL "heartbeat=local"
+#define OCFS2_HB_GLOBAL "heartbeat=global"
/*
* OCFS2 directory file types. Only the low 3 bits are used. The
diff --git a/mount.ocfs2/mount.ocfs2.c b/mount.ocfs2/mount.ocfs2.c
index f820a30..c104172 100644
--- a/mount.ocfs2/mount.ocfs2.c
+++ b/mount.ocfs2/mount.ocfs2.c
@@ -99,6 +99,54 @@ static void read_options(int argc, char **argv, struct mount_options *mo)
}
/*
+ * For local mounts, add heartbeat=none.
+ * For userspace clusterstack, add cluster_stack=xxxx.
+ * For o2cb with local heartbeat, add heartbeat=local.
+ * For o2cb with global heartbeat, add heartbeat=global.
+ */
+static errcode_t add_mount_options(ocfs2_filesys *fs,
+ struct o2cb_cluster_desc *cluster,
+ char **optstr)
+{
+ char *add, *extra = NULL;
+ char stackstr[strlen(OCFS2_CLUSTER_STACK_ARG) + OCFS2_STACK_LABEL_LEN + 1] = "";
+ struct ocfs2_super_block *sb = OCFS2_RAW_SB(fs->fs_super);
+
+ if (ocfs2_mount_local(fs)) {
+ add = OCFS2_HB_NONE;
+ goto addit;
+ }
+
+ if (cluster->c_stack &&
+ strcmp(cluster->c_stack, OCFS2_CLASSIC_CLUSTER_STACK)) {
+ snprintf(stackstr, sizeof(stackstr), "%s%s",
+ OCFS2_CLUSTER_STACK_ARG, cluster->c_stack);
+ add = stackstr;
+ goto addit;
+ }
+
+ if (ocfs2_cluster_o2cb_global_heartbeat(sb))
+ add = OCFS2_HB_GLOBAL;
+ else
+ add = OCFS2_HB_LOCAL;
+
+addit:
+ if (optstr && *optstr) {
+ extra = xstrndup(*optstr, strlen(*optstr) + strlen(add) + 1);
+ if (extra)
+ extra = xstrconcat3(extra, ",", add);
+ } else
+ extra = xstrndup(add, strlen(add));
+
+ if (!extra)
+ return OCFS2_ET_NO_MEMORY;
+
+ *optstr = extra;
+
+ return 0;
+}
+
+/*
* Code based on similar function in util-linux-2.12p/mount/mount.c
*
*/
@@ -252,21 +300,17 @@ bail:
return ret;
}
-
int main(int argc, char **argv)
{
errcode_t ret = 0;
struct mount_options mo;
char hb_ctl_path[PATH_MAX];
- char *extra = NULL;
int dev_ro = 0;
- char *hbstr = NULL;
- char stackstr[strlen(OCFS2_CLUSTER_STACK_ARG) + OCFS2_STACK_LABEL_LEN + 1] = "";
ocfs2_filesys *fs = NULL;
struct o2cb_cluster_desc cluster;
struct o2cb_region_desc desc;
int clustered = 1;
- int hb_started = 0;
+ int group_join = 0;
struct stat statbuf;
initialize_ocfs_error_table();
@@ -317,9 +361,6 @@ int main(int argc, char **argv)
"while trying to determine cluster information");
goto bail;
}
- if (cluster.c_stack)
- snprintf(stackstr, sizeof(stackstr), "%s%s",
- OCFS2_CLUSTER_STACK_ARG, cluster.c_stack);
ret = ocfs2_fill_heartbeat_desc(fs, &desc);
if (ret) {
@@ -346,6 +387,12 @@ int main(int argc, char **argv)
}
}
+ ret = add_mount_options(fs, &cluster, &mo.xtra_opts);
+ if (ret) {
+ com_err(progname, ret, "while adding mount options");
+ goto bail;
+ }
+
block_signals (SIG_BLOCK);
if (!(mo.flags & MS_REMOUNT) && !dev_ro && clustered) {
@@ -356,27 +403,14 @@ int main(int argc, char **argv)
"while trying to join the group");
goto bail;
}
- hb_started = 1;
+ group_join = 1;
}
- if (dev_ro || !clustered)
- hbstr = OCFS2_HB_NONE;
- else if (strlen(stackstr))
- hbstr = stackstr;
- else
- hbstr = OCFS2_HB_LOCAL;
-
- if (mo.xtra_opts && *mo.xtra_opts) {
- extra = xstrndup(mo.xtra_opts,
- strlen(mo.xtra_opts) + strlen(hbstr) + 1);
- extra = xstrconcat3(extra, ",", hbstr);
- } else
- extra = xstrndup(hbstr, strlen(hbstr));
-
- ret = mount(mo.dev, mo.dir, OCFS2_FS_NAME, mo.flags & ~MS_NOSYS, extra);
+ ret = mount(mo.dev, mo.dir, OCFS2_FS_NAME, mo.flags & ~MS_NOSYS,
+ mo.xtra_opts);
if (ret) {
ret = errno;
- if (hb_started) {
+ if (group_join) {
/* We ignore the return code because the mount
* failure is the important error.
* complete_group_join() will handle cleaning up */
@@ -400,7 +434,7 @@ int main(int argc, char **argv)
"error.", mo.dev, mo.dir);
goto bail;
}
- if (hb_started) {
+ if (group_join) {
ret = o2cb_complete_group_join(&cluster, &desc, 0);
if (ret) {
com_err(progname, ret,
@@ -414,11 +448,10 @@ int main(int argc, char **argv)
}
}
- run_hb_ctl (hb_ctl_path, mo.dev, "-P");
update_mtab_entry(mo.dev, mo.dir, OCFS2_FS_NAME,
fix_opts_string(((mo.flags & ~MS_NOMTAB) |
(clustered ? MS_NETDEV : 0)),
- extra, NULL),
+ mo.xtra_opts, NULL),
mo.flags, 0, 0);
block_signals (SIG_UNBLOCK);
@@ -426,8 +459,6 @@ int main(int argc, char **argv)
bail:
if (fs)
ocfs2_close(fs);
- if (extra)
- free(extra);
if (mo.dev)
free(mo.dev);
if (mo.dir)
--
1.7.0.4
More information about the Ocfs2-tools-devel
mailing list