[Ocfs2-tools-commits] mfasheh commits r769 - trunk/mount.ocfs2

svn-commits at oss.oracle.com svn-commits at oss.oracle.com
Wed Mar 30 16:52:39 CST 2005


Author: mfasheh
Signed-off-by: zab
Date: 2005-03-30 16:52:37 -0600 (Wed, 30 Mar 2005)
New Revision: 769

Removed:
   trunk/mount.ocfs2/mount_hb.c
   trunk/mount.ocfs2/mount_hb.h
Modified:
   trunk/mount.ocfs2/Makefile
   trunk/mount.ocfs2/mount.ocfs2.c
   trunk/mount.ocfs2/mount.ocfs2.h
   trunk/mount.ocfs2/ocfs2_hb_ctl.c
Log:
* have mount.ocfs2 call ocfs_hb_ctl to start heartbeat rather than manually 
  doing it itself. This gives us the advantage that we can check to make sure
  the program is in the right place and error out early -- it's needed for  
  umount.

* Normalize the return codes of mount.ocfs2 and ocfs2_hb_ctl. 0 means
  success, 1 means failure.

Signed-off-by: zab



Modified: trunk/mount.ocfs2/Makefile
===================================================================
--- trunk/mount.ocfs2/Makefile	2005-03-30 17:44:51 UTC (rev 768)
+++ trunk/mount.ocfs2/Makefile	2005-03-30 22:52:37 UTC (rev 769)
@@ -25,7 +25,7 @@
 DEFINES = -DOCFS2_FLAT_INCLUDES -DO2DLM_FLAT_INCLUDES \
 		-DO2CB_FLAT_INCLUDES -DVERSION=\"$(VERSION)\"
 
-CFILES = opts.c mount.ocfs2.c mount_hb.c
+CFILES = opts.c mount.ocfs2.c
 CFILES += fstab.c mntent.c realpath.c sundries.c xmalloc.c
 
 HFILES = $(subst .c,.h,$(CFILES))
@@ -33,7 +33,7 @@
 
 OBJS = $(subst .c,.o,$(CFILES))
 
-HB_CTL_CFILES = mount_hb.c ocfs2_hb_ctl.c
+HB_CTL_CFILES = ocfs2_hb_ctl.c
 HB_CTL_HFILES = $(subst .c,.h,$(HB_CTL_CFILES))
 HB_CTL_OBJS = $(subst .c,.o,$(HB_CTL_CFILES))
 

Modified: trunk/mount.ocfs2/mount.ocfs2.c
===================================================================
--- trunk/mount.ocfs2/mount.ocfs2.c	2005-03-30 17:44:51 UTC (rev 768)
+++ trunk/mount.ocfs2/mount.ocfs2.c	2005-03-30 22:52:37 UTC (rev 769)
@@ -22,7 +22,6 @@
 
 #include "mount.ocfs2.h"
 #include "o2cb.h"
-#include "mount_hb.h"
 
 int verbose = 0;
 int mount_quiet = 0;
@@ -178,11 +177,83 @@
 	return 0;
 }
 
+static int check_for_hb_ctl(const char *hb_ctl_path)
+{
+	int ret;
+	struct stat hb_stats;
+
+	ret = lstat(hb_ctl_path, &hb_stats);
+	if (ret < 0) {
+		ret = errno;
+		return ret;
+	}
+
+	/* The kernel can't follow a symbolic link for this so lets
+	 * not get stuck in the 1st place. */
+	if (S_ISLNK(hb_stats.st_mode))
+		ret = ELOOP;
+
+	return ret;
+}
+
+static int run_hb_ctl(const char *hb_ctl_path,
+		      const char *device)
+{
+	int ret = 0;
+	int child_status;
+	char * argv[5];
+	pid_t child;
+
+	child = fork();
+	if (child < 0) {
+		ret = errno;
+		goto bail;
+	}
+
+	if (!child) {
+		argv[0] = (char *) hb_ctl_path;
+		argv[1] = "-S";
+		argv[2] = "-d";
+		argv[3] = (char *) device;
+		argv[4] = NULL;
+
+		ret = execv(argv[0], argv);
+
+		ret = errno;
+		exit(ret);
+	} else {
+		ret = waitpid(child, &child_status, 0);
+		if (ret < 0) {
+			ret = errno;
+			goto bail;
+		}
+
+		ret = WEXITSTATUS(child_status);
+	}
+
+bail:
+	return ret;
+}
+
+static int start_heartbeat(const char *hb_ctl_path,
+			   const char *device)
+{
+	int ret;
+
+	ret = check_for_hb_ctl(hb_ctl_path);
+	if (ret)
+		return ret;
+
+	ret = run_hb_ctl(hb_ctl_path, device);
+
+	return ret;
+}
+
 int main(int argc, char **argv)
 {
 	errcode_t ret = 0;
 	struct mount_options mo;
-	char hbuuid[33];
+	const char *hb_ctl_path = "/sbin/ocfs2_hb_ctl";
 
 	initialize_ocfs_error_table();
 	initialize_o2dl_error_table();
@@ -195,18 +266,13 @@
 	if (ret)
 		goto bail;
 
-	ret = get_uuid(mo.dev, hbuuid);
-	if (ret) {
-		com_err(progname, ret, "while opening the file system");
-		goto bail;
-	}
-
 	if (verbose)
-		printf("device=%s hbuuid=%s\n", mo.dev, hbuuid);
+		printf("device=%s\n", mo.dev);
 
-	ret = start_heartbeat(mo.dev);
-	if (ret < 0) {
-		com_err(progname, ret, "while starting heartbeat");
+	ret = start_heartbeat(hb_ctl_path, mo.dev);
+	if (ret) {
+		com_err(progname, 0, "Error when attempting to run %s: "
+			"\"%s\"\n", hb_ctl_path, strerror(ret));
 		goto bail;
 	}
 
@@ -225,5 +291,5 @@
 	free(mo.opts);
 	free(mo.xtra_opts);
 
-	return ret;
+	return ret ? 1 : 0;
 }

Modified: trunk/mount.ocfs2/mount.ocfs2.h
===================================================================
--- trunk/mount.ocfs2/mount.ocfs2.h	2005-03-30 17:44:51 UTC (rev 768)
+++ trunk/mount.ocfs2/mount.ocfs2.h	2005-03-30 22:52:37 UTC (rev 769)
@@ -37,6 +37,7 @@
 #include <linux/fd.h>
 #include <string.h>
 #include <sys/stat.h>
+#include <sys/wait.h>
 
 #include "fstab.h"
 #include "nls.h"

Deleted: trunk/mount.ocfs2/mount_hb.c
===================================================================
--- trunk/mount.ocfs2/mount_hb.c	2005-03-30 17:44:51 UTC (rev 768)
+++ trunk/mount.ocfs2/mount_hb.c	2005-03-30 22:52:37 UTC (rev 769)
@@ -1,82 +0,0 @@
-/*
- * mount_heartbeat.c  Common heartbeat functions
- *
- * Copyright (C) 2005 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 <sys/types.h>
-#include <inttypes.h>
-
-#include <stdio.h>
-#include <unistd.h>
-#include <errno.h>
-#include <fcntl.h>
-#include <string.h>
-#include <sys/stat.h>
-
-#include <ocfs2.h>
-#include <ocfs2_fs.h>
-#include <ocfs1_fs_compat.h>
-
-#include "o2cb.h"
-#include "mount_hb.h"
-
-errcode_t get_uuid(char *dev, char *uuid)
-{
-	ocfs2_filesys *fs = NULL;
-	errcode_t ret;
-
-	ret = ocfs2_open(dev, OCFS2_FLAG_RO, 0, 0, &fs);
-	if (ret)
-		goto out;
-
-	strcpy(uuid, fs->uuid_str);
-
-	ocfs2_close(fs);
-
-out:
-	return ret;
-}
-
-errcode_t start_heartbeat(char *device)
-{
-	errcode_t err;
-	ocfs2_filesys *fs = NULL;
-
-	err = ocfs2_open(device, OCFS2_FLAG_RO, 0, 0, &fs);
-	if (err)
-		goto bail;
-
-	err = ocfs2_start_heartbeat(fs);
-
-bail:
-	if (fs)
-		ocfs2_close(fs);
-
-	return err;
-}
-
-errcode_t stop_heartbeat(const char *hbuuid)
-{
-	errcode_t err;
-
-	err = o2cb_remove_heartbeat_region_disk(NULL, hbuuid);
-
-	return err;
-}

Deleted: trunk/mount.ocfs2/mount_hb.h
===================================================================
--- trunk/mount.ocfs2/mount_hb.h	2005-03-30 17:44:51 UTC (rev 768)
+++ trunk/mount.ocfs2/mount_hb.h	2005-03-30 22:52:37 UTC (rev 769)
@@ -1,27 +0,0 @@
-/*
- * heartbeat.h  Definitions, etc.
- *
- * Copyright (C) 2004 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.
- *
- */
-
-extern char *progname;
-
-errcode_t start_heartbeat(char *device);
-errcode_t stop_heartbeat(const char *hbuuid);
-errcode_t get_uuid(char *dev, char *uuid);

Modified: trunk/mount.ocfs2/ocfs2_hb_ctl.c
===================================================================
--- trunk/mount.ocfs2/ocfs2_hb_ctl.c	2005-03-30 17:44:51 UTC (rev 768)
+++ trunk/mount.ocfs2/ocfs2_hb_ctl.c	2005-03-30 22:52:37 UTC (rev 769)
@@ -24,10 +24,53 @@
 #include "ocfs2_hb_ctl.h"
 
 #include "o2cb.h"
-#include "mount_hb.h"
 
 char *progname = "ocfs2_hb_ctl";
 
+static errcode_t get_uuid(char *dev, char *uuid)
+{
+	ocfs2_filesys *fs = NULL;
+	errcode_t ret;
+
+	ret = ocfs2_open(dev, OCFS2_FLAG_RO, 0, 0, &fs);
+	if (ret)
+		goto out;
+
+	strcpy(uuid, fs->uuid_str);
+
+	ocfs2_close(fs);
+
+out:
+	return ret;
+}
+
+static errcode_t start_heartbeat(char *device)
+{
+	errcode_t err;
+	ocfs2_filesys *fs = NULL;
+
+	err = ocfs2_open(device, OCFS2_FLAG_RO, 0, 0, &fs);
+	if (err)
+		goto bail;
+
+	err = ocfs2_start_heartbeat(fs);
+
+bail:
+	if (fs)
+		ocfs2_close(fs);
+
+	return err;
+}
+
+static errcode_t stop_heartbeat(const char *hbuuid)
+{
+	errcode_t err;
+
+	err = o2cb_remove_heartbeat_region_disk(NULL, hbuuid);
+
+	return err;
+}
+
 enum hb_ctl_action {
 	HB_ACTION_UKNOWN,
 	HB_ACTION_USAGE,
@@ -179,5 +222,5 @@
 	}
 
 bail:
-	return ret;
+	return ret ? 1 : 0;
 }



More information about the Ocfs2-tools-commits mailing list