[Ocfs2-tools-commits] jlbec commits r1392 - in branches/cman-based: libo2cb/include mount.ocfs2 ocfs2_controld

svn-commits at oss.oracle.com svn-commits at oss.oracle.com
Thu Aug 16 18:19:12 PDT 2007


Author: jlbec
Date: 2007-08-16 18:19:10 -0700 (Thu, 16 Aug 2007)
New Revision: 1392

Added:
   branches/cman-based/mount.ocfs2/umount.ocfs2.c
Modified:
   branches/cman-based/libo2cb/include/o2cb.h
   branches/cman-based/libo2cb/include/o2cb_client_proto.h
   branches/cman-based/mount.ocfs2/
   branches/cman-based/mount.ocfs2/Makefile
   branches/cman-based/mount.ocfs2/mount.ocfs2.c
   branches/cman-based/ocfs2_controld/test_client.c
Log:

We now have mount and umount in pair.  This still is only support for
the o2cb disk heartbeat, but the refactor allows us to start working on
other heartbeats.

- Remove OCFS2_FSTYPE and promote OCFS2_FS_NAME to the o2cb header
- Remove ocfs2_hb_ctl calls from mount.ocfs2.  It now calls
  ocfs2_start_heartbeat() directly.
- Add umount.ocfs2 to call ocfs2_stop_heartbeat().



Modified: branches/cman-based/libo2cb/include/o2cb.h
===================================================================
--- branches/cman-based/libo2cb/include/o2cb.h	2007-08-16 20:46:48 UTC (rev 1391)
+++ branches/cman-based/libo2cb/include/o2cb.h	2007-08-17 01:19:10 UTC (rev 1392)
@@ -61,6 +61,8 @@
 
 #endif
 
+#define OCFS2_FS_NAME		"ocfs2"
+
 errcode_t o2cb_init(void);
 
 errcode_t o2cb_create_cluster(const char *cluster_name);

Modified: branches/cman-based/libo2cb/include/o2cb_client_proto.h
===================================================================
--- branches/cman-based/libo2cb/include/o2cb_client_proto.h	2007-08-16 20:46:48 UTC (rev 1391)
+++ branches/cman-based/libo2cb/include/o2cb_client_proto.h	2007-08-17 01:19:10 UTC (rev 1392)
@@ -31,7 +31,6 @@
 #define OCFS2_CONTROLD_MAXLINE		256
 #define OCFS2_CONTROLD_MAXARGS		16
 #define OCFS2_CONTROLD_SOCK_PATH	"ocfs2_controld_sock"
-#define OCFS2_FSTYPE "ocfs2"
 
 /* Client messages */
 typedef enum {


Property changes on: branches/cman-based/mount.ocfs2
___________________________________________________________________
Name: svn:ignore
   - .*.sw?
mount.ocfs2
mount.ocfs2.8
*.d
cscope.*

   + .*.sw?
mount.ocfs2
umount.ocfs2
mount.ocfs2.8
*.d
cscope.*


Modified: branches/cman-based/mount.ocfs2/Makefile
===================================================================
--- branches/cman-based/mount.ocfs2/Makefile	2007-08-16 20:46:48 UTC (rev 1391)
+++ branches/cman-based/mount.ocfs2/Makefile	2007-08-17 01:19:10 UTC (rev 1392)
@@ -3,7 +3,7 @@
 include $(TOPDIR)/Preamble.make
 
 sbindir = $(root_sbindir)
-SBIN_PROGRAMS = mount.ocfs2
+SBIN_PROGRAMS = mount.ocfs2 umount.ocfs2
 
 INCLUDES = -Iinclude -I$(TOPDIR)/libocfs2/include \
 	    -I$(TOPDIR)/libo2cb/include -I$(TOPDIR)/libo2dlm/include
@@ -26,20 +26,24 @@
 DEFINES = -DOCFS2_FLAT_INCLUDES -DO2DLM_FLAT_INCLUDES \
 		-DO2CB_FLAT_INCLUDES -DVERSION=\"$(VERSION)\"
 
-CFILES = opts.c mount.ocfs2.c
-CFILES += fstab.c mntent.c realpath.c sundries.c xmalloc.c
+CORE_CFILES = fstab.c mntent.c realpath.c sundries.c xmalloc.c opts.c
+MOUNT_CFILES = mount.ocfs2.c
+UMOUNT_CFILES = umount.ocfs2.c
 
-HFILES = $(subst .c,.h,$(CFILES))
+HFILES = $(subst .c,.h,$(MOUNT_CFILES) $(CORE_CFILES))
 HFILES += mount_constants.h nls.h paths.h
 
-OBJS = $(subst .c,.o,$(CFILES))
+MOUNT_OBJS = $(subst .c,.o,$(MOUNT_CFILES) $(CORE_CFILES))
+UMOUNT_OBJS = $(subst .c,.o,$(UMOUNT_CFILES) $(CORE_CFILES))
 MANS = mount.ocfs2.8
 
-DIST_FILES = $(CFILES) $(HFILES) $(addsuffix .in,$(MANS))
+DIST_FILES = $(CORE_CFILES) $(MOUNT_CFILES) $(UMOUNT_CFILES) \
+	     $(HFILES) $(addsuffix .in,$(MANS))
 
-all: mount.ocfs2
+mount.ocfs2: $(MOUNT_OBJS) $(LIBOCFS2_DEPS) $(LIBO2DLM_DEPS) $(LIBO2CB_DEPS)
+	$(LINK) $(LIBOCFS2_LIBS) $(LIBO2DLM_LIBS) $(LIBO2CB_LIBS) $(COM_ERR_LIBS)
 
-mount.ocfs2: $(OBJS) $(LIBOCFS2_DEPS) $(LIBO2DLM_DEPS) $(LIBO2CB_DEPS)
+umount.ocfs2: $(UMOUNT_OBJS) $(LIBOCFS2_DEPS) $(LIBO2DLM_DEPS) $(LIBO2CB_DEPS)
 	$(LINK) $(LIBOCFS2_LIBS) $(LIBO2DLM_LIBS) $(LIBO2CB_LIBS) $(COM_ERR_LIBS)
 
 include $(TOPDIR)/Postamble.make

Modified: branches/cman-based/mount.ocfs2/mount.ocfs2.c
===================================================================
--- branches/cman-based/mount.ocfs2/mount.ocfs2.c	2007-08-16 20:46:48 UTC (rev 1391)
+++ branches/cman-based/mount.ocfs2/mount.ocfs2.c	2007-08-17 01:19:10 UTC (rev 1392)
@@ -1,4 +1,6 @@
-/*
+/* -*- mode: c; c-basic-offset: 8; -*-
+ * vim: noexpandtab sw=8 ts=8 sts=0:
+ *
  * mount.ocfs2.c  Mounts ocfs2 volume
  *
  * Copyright (C) 2005 Oracle.  All rights reserved.
@@ -23,8 +25,6 @@
 #include "mount.ocfs2.h"
 #include "o2cb.h"
 
-#define OCFS2_FS_NAME		"ocfs2"
-
 int verbose = 0;
 int mount_quiet = 0;
 char *progname = NULL;
@@ -212,19 +212,6 @@
 	return 0;
 }
 
-static int check_for_hb_ctl(const char *hb_ctl_path)
-{
-	int ret;
-
-	ret = access(hb_ctl_path, X_OK);
-	if (ret < 0) {
-		ret = errno;
-		return ret;
-	}
-
-	return ret;
-}
-
 static int run_hb_ctl(const char *hb_ctl_path,
 		      const char *device, const char *arg)
 {
@@ -264,26 +251,7 @@
 	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, "-S");
-
-	return ret;
-}
-
-static int stop_heartbeat(const char *hb_ctl_path,
-			  const char *device)
-{
-	return run_hb_ctl(hb_ctl_path, device, "-K");
-}
-
 int main(int argc, char **argv)
 {
 	errcode_t ret = 0;
@@ -321,15 +289,13 @@
 		goto bail;
 
 	ret = ocfs2_open(mo.dev, OCFS2_FLAG_RO, 0, 0, &fs); //O_EXCL?
-	if (!ret) {
-		clustered = (0 == ocfs2_mount_local(fs));
-		ocfs2_close(fs);
-		fs = NULL;
-	} else {
+	if (ret) {
 		com_err(progname, ret, "while opening device %s", mo.dev);
 		goto bail;
 	}
 
+	clustered = (0 == ocfs2_mount_local(fs));
+
 	if (verbose)
 		printf("device=%s\n", mo.dev);
 
@@ -359,11 +325,11 @@
 	block_signals (SIG_BLOCK);
 
 	if (!(mo.flags & MS_REMOUNT) && !dev_ro && clustered) {
-		ret = start_heartbeat(hb_ctl_path, mo.dev);
+		ret = ocfs2_start_heartbeat(fs);
 		if (ret) {
 			block_signals (SIG_UNBLOCK);
-			com_err(progname, 0, "Error when attempting to run %s: "
-				"\"%s\"", hb_ctl_path, strerror(ret));
+			com_err(progname, ret,
+				"while trying to start heartbeat");
 			goto bail;
 		}
 		hb_started = 1;
@@ -385,7 +351,7 @@
 	if (ret) {
 		ret = errno;
 		if (hb_started)
-			stop_heartbeat(hb_ctl_path, mo.dev);
+			ocfs2_stop_heartbeat(fs);
 		block_signals (SIG_UNBLOCK);
 		com_err(progname, ret, "while mounting %s on %s. "
 			"Check 'dmesg' for more information on this error.",
@@ -403,6 +369,8 @@
 	block_signals (SIG_UNBLOCK);
 
 bail:
+	if (fs)
+		ocfs2_close(fs);
 	if (extra)
 		free(extra);
 	if (mo.dev)

Added: branches/cman-based/mount.ocfs2/umount.ocfs2.c
===================================================================
--- branches/cman-based/mount.ocfs2/umount.ocfs2.c	2007-08-16 20:46:48 UTC (rev 1391)
+++ branches/cman-based/mount.ocfs2/umount.ocfs2.c	2007-08-17 01:19:10 UTC (rev 1392)
@@ -0,0 +1,234 @@
+/* -*- mode: c; c-basic-offset: 8; -*-
+ * vim: noexpandtab sw=8 ts=8 sts=0:
+ *
+ * umount.ocfs2.c  Unounts ocfs2 volume
+ *
+ * Copyright (C) 2007 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 "mount.ocfs2.h"
+#include "o2cb.h"
+
+/* Do not try to include <linux/mount.h> -- lots of errors */
+#if !defined(MNT_DETACH)
+# define MNT_DETACH 2
+#endif
+
+int verbose = 0;
+int mount_quiet = 0;
+char *progname = NULL;
+
+static int nomtab = 0;
+
+struct mount_options {
+	char *dir;
+	char *dev;
+	int flags;
+};
+
+static void handle_signal(int sig)
+{
+	switch (sig) {
+	case SIGTERM:
+	case SIGINT:
+		printf("\numount interrupted\n");
+		exit(1);
+	}
+}
+
+static void read_options(int argc, char **argv, struct mount_options *mo)
+{
+	int c;
+
+	progname = basename(argv[0]);
+
+	if (argc < 2)
+		return;
+
+	while(1) {
+		c = getopt(argc, argv, "flvn");
+		if (c == -1)
+			break;
+
+		switch (c) {
+		case 'v':
+			++verbose;
+			break;
+
+		case 'n':
+			++nomtab;
+			break;
+
+		case 'f':
+			/*
+			 * Do nothing, as we don't support MNT_FORCE.  We
+			 * need to handle this option for autofs
+			 */
+			break;
+
+		case 'l':
+			mo->flags |= MNT_DETACH;
+			break;
+
+		default:
+			break;
+		}
+	}
+
+	if (optind < argc && argv[optind])
+		mo->dir = xstrdup(argv[optind]);
+}
+
+static int process_options(struct mount_options *mo)
+{
+	struct mntentchn *mc;
+
+	if (!mo->dir) {
+		com_err(progname, OCFS2_ET_INVALID_ARGUMENT, "no mountpoint specified");
+		return -1;
+	}
+
+	/*
+	 * We need the device to read heartbeat information, etc.  Find
+	 * the *last* entry matching our mo->dir.  This may be a mountpoint
+	 * or a device, so we try a mountpoint first (the usual case).
+	 */
+	mc = getmntdirbackward(mo->dir, NULL);
+	if (mc) {
+		mo->dev = xstrdup(mc->m.mnt_fsname);
+	} else {
+		mc = getmntdevbackward(mo->dir, NULL);
+		if (!mc) {
+			fprintf(stderr, "Unable to find %s in mount list\n",
+				mo->dir);
+			return -1;
+		}
+		mo->dev = mo->dir;
+		mo->dir = xstrdup(mc->m.mnt_dir);
+	}
+
+	return 0;
+}
+
+static int check_dev_readonly(const char *dev, int *dev_ro)
+{
+	int fd;
+	int ret;
+
+	fd = open(dev, O_RDONLY);
+	if (fd < 0)
+		return errno;
+
+	ret = ioctl(fd, BLKROGET, dev_ro);
+	if (ret < 0)
+		return errno;
+
+	close(fd);
+
+	return 0;
+}
+
+int main(int argc, char **argv)
+{
+	int rc;
+	errcode_t ret = 0;
+	struct mount_options mo;
+	ocfs2_filesys *fs = NULL;
+	int clustered = 1;
+
+	initialize_ocfs_error_table();
+	initialize_o2dl_error_table();
+	initialize_o2cb_error_table();
+
+	setbuf(stdout, NULL);
+	setbuf(stderr, NULL);
+
+	if (signal(SIGTERM, handle_signal) == SIG_ERR) {
+		fprintf(stderr, "Could not set SIGTERM\n");
+		exit(1);
+	}
+
+	if (signal(SIGINT, handle_signal) == SIG_ERR) {
+		fprintf(stderr, "Could not set SIGINT\n");
+		exit(1);
+	}
+
+	memset(&mo, 0, sizeof(mo));
+	read_options (argc, argv, &mo);
+
+	ret = process_options(&mo);
+	if (ret)
+		goto bail;
+
+	ret = ocfs2_open(mo.dev, OCFS2_FLAG_RO, 0, 0, &fs); //O_EXCL?
+	if (ret) {
+		com_err(progname, ret, "while opening device %s", mo.dev);
+		goto bail;
+	}
+
+	clustered = (0 == ocfs2_mount_local(fs));
+
+	if (verbose)
+		printf("device=%s\n", mo.dev);
+
+	if (clustered) {
+		ret = o2cb_init();
+		if (ret) {
+			com_err(progname, ret, "Cannot initialize cluster");
+			goto bail;
+		}
+	}
+
+	block_signals (SIG_BLOCK);
+
+	rc = -ENOSYS;
+	if (mo.flags) {
+		rc = umount2(mo.dir, mo.flags);
+		if (rc) {
+			rc = -errno;
+			fprintf(stderr, "Error calling umount2(): %s",
+				strerror(-rc));
+			if ((rc == -ENOSYS) && verbose)
+				fprintf(stdout,
+					"No umount2(), trying umount()...\n");
+		}
+	}
+	if (rc == -ENOSYS) {
+		rc = umount(mo.dir);
+		if (rc) {
+			rc = -errno;
+			fprintf(stderr, "Error unmounting %s: %s\n", mo.dir,
+				strerror(-rc));
+		}
+	}
+
+	if (rc)
+		goto unblock;
+
+	ocfs2_stop_heartbeat(fs);
+
+	if (!nomtab)
+		update_mtab(mo.dir, NULL);
+
+unblock:
+	block_signals (SIG_UNBLOCK);
+
+bail:
+	if (fs)
+		ocfs2_close(fs);
+	if (mo.dev)
+		free(mo.dev);
+	if (mo.dir)
+		free(mo.dir);
+
+	return ret ? 1 : 0;
+}

Modified: branches/cman-based/ocfs2_controld/test_client.c
===================================================================
--- branches/cman-based/ocfs2_controld/test_client.c	2007-08-16 20:46:48 UTC (rev 1391)
+++ branches/cman-based/ocfs2_controld/test_client.c	2007-08-17 01:19:10 UTC (rev 1392)
@@ -75,7 +75,7 @@
 	char *argv[OCFS2_CONTROLD_MAXARGS + 1];
 	char buf[OCFS2_CONTROLD_MAXLINE];
 
-	rc = send_message(fd, CM_MOUNT, OCFS2_FSTYPE, uuid, cluster,
+	rc = send_message(fd, CM_MOUNT, OCFS2_FS_NAME, uuid, cluster,
 			  device, mountpoint);
 	if (rc) {
 		fprintf(stderr, "Unable to send MOUNT message: %s\n",
@@ -120,7 +120,7 @@
 	/* rc = mount(...); */
 	rc = 0;
 
-	rc = send_message(fd, CM_MRESULT, OCFS2_FSTYPE, uuid, rc,
+	rc = send_message(fd, CM_MRESULT, OCFS2_FS_NAME, uuid, rc,
 			  mountpoint);
 	if (rc) {
 		fprintf(stderr, "Unable to send MRESULT message: %s\n",
@@ -213,7 +213,7 @@
 	}
 #endif
 
-	rc = send_message(fd, CM_UNMOUNT, OCFS2_FSTYPE, uuid, mountpoint);
+	rc = send_message(fd, CM_UNMOUNT, OCFS2_FS_NAME, uuid, mountpoint);
 	if (rc) {
 		fprintf(stderr, "Unable to send UNMOUNT message: %s\n",
 			strerror(-rc));




More information about the Ocfs2-tools-commits mailing list