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

svn-commits at oss.oracle.com svn-commits at oss.oracle.com
Fri Mar 18 20:51:50 CST 2005


Author: mfasheh
Signed-off-by: jlbec
Date: 2005-03-18 20:51:47 -0600 (Fri, 18 Mar 2005)
New Revision: 699

Added:
   trunk/mount.ocfs2/mount_hb.c
   trunk/mount.ocfs2/mount_hb.h
   trunk/mount.ocfs2/ocfs2_hb_ctl.c
   trunk/mount.ocfs2/ocfs2_hb_ctl.h
Modified:
   trunk/mount.ocfs2/Makefile
   trunk/mount.ocfs2/mount.ocfs2.c
Log:
* add ocfs2_hb_ctl, a program for starting / stopping heartbeat on demand.

Signed-off-by: jlbec



Modified: trunk/mount.ocfs2/Makefile
===================================================================
--- trunk/mount.ocfs2/Makefile	2005-03-19 01:58:03 UTC (rev 698)
+++ trunk/mount.ocfs2/Makefile	2005-03-19 02:51:47 UTC (rev 699)
@@ -2,7 +2,7 @@
 
 include $(TOPDIR)/Preamble.make
 
-SBIN_PROGRAMS = mount.ocfs2
+SBIN_PROGRAMS = mount.ocfs2 ocfs2_hb_ctl
 
 INCLUDES = -Iinclude -I$(TOPDIR)/libocfs2/include \
 	    -I$(TOPDIR)/libo2cb/include -I$(TOPDIR)/libo2dlm/include
@@ -25,7 +25,7 @@
 DEFINES = -DOCFS2_FLAT_INCLUDES -DO2DLM_FLAT_INCLUDES \
 		-DO2CB_FLAT_INCLUDES -DVERSION=\"$(VERSION)\"
 
-CFILES = opts.c mount.ocfs2.c
+CFILES = opts.c mount.ocfs2.c mount_hb.c
 CFILES += fstab.c mntent.c realpath.c sundries.c xmalloc.c
 
 HFILES = $(subst .c,.h,$(CFILES))
@@ -33,12 +33,21 @@
 
 OBJS = $(subst .c,.o,$(CFILES))
 
-DIST_FILES = $(CFILES) $(HFILES)
+HB_CTL_CFILES = mount_hb.c ocfs2_hb_ctl.c
+HB_CTL_HFILES = $(subst .c,.h,$(HB_CTL_CFILES))
+HB_CTL_OBJS = $(subst .c,.o,$(HB_CTL_CFILES))
 
+DIST_FILES = $(CFILES) $(HFILES) $(HB_CTL_CFILES) $(HB_CTL_HFILES)
+
+all: mount.ocfs2 ocfs2_hb_ctl
+
 mount.ocfs2: $(OBJS) $(LIBOCFS2_DEPS) $(LIBO2DLM_DEPS) $(LIBO2CB_DEPS)
 	$(LINK) $(LIBOCFS2_LIBS) $(LIBO2DLM_LIBS) $(LIBO2CB_LIBS) $(COM_ERR_LIBS)
 
 group: group.o $(LIBOCFS2_DEPS)
 	$(LINK) $(LIBOCFS2_LIBS) $(COM_ERR_LIBS)
 
+ocfs2_hb_ctl: $(HB_CTL_OBJS) $(LIBOCFS2_DEPS) $(LIBO2DLM_DEPS) $(LIBO2CB_DEPS)
+	$(LINK) $(LIBOCFS2_LIBS) $(LIBO2DLM_LIBS) $(LIBO2CB_LIBS) $(COM_ERR_LIBS)
+
 include $(TOPDIR)/Postamble.make

Modified: trunk/mount.ocfs2/mount.ocfs2.c
===================================================================
--- trunk/mount.ocfs2/mount.ocfs2.c	2005-03-19 01:58:03 UTC (rev 698)
+++ trunk/mount.ocfs2/mount.ocfs2.c	2005-03-19 02:51:47 UTC (rev 699)
@@ -22,6 +22,7 @@
 
 #include "mount.ocfs2.h"
 #include "o2cb.h"
+#include "mount_hb.h"
 
 int verbose = 0;
 int mount_quiet = 0;
@@ -37,30 +38,6 @@
 	char *xtra_opts;
 };
 
-static int get_uuid(char *dev, char *uuid)
-{
-	ocfs2_filesys *fs = NULL;
-	errcode_t ret = 0;
-	int i;
-	char *p;
-	uint8_t *s_uuid;
-
-	ret = ocfs2_open(dev, OCFS2_FLAG_RO, 0, 0, &fs);
-	if (ret)
-		goto out;
-
-	s_uuid = OCFS2_RAW_SB(fs->fs_super)->s_uuid;
-
-	for (i = 0, p = uuid; i < 16; i++, p += 2)
-		sprintf(p, "%02X", s_uuid[i]);
-	*p = '\0';
-
-	ocfs2_close(fs);
-
-out:
-	return ret;
-}
-
 static void read_options(int argc, char **argv, struct mount_options *mo)
 {
 	int c;
@@ -183,103 +160,6 @@
 	my_free(mnt.mnt_dir);
 }
 
-static int get_ocfs2_disk_hb_params(char *group_dev, uint32_t *block_bits, uint32_t *cluster_bits,
-			     uint64_t *start_block, uint32_t *num_clusters)
-{
-	int status = -EINVAL;
-	errcode_t ret = 0;
-	uint64_t blkno;
-	char *buf = NULL;
-	char *heartbeat_filename;
-	ocfs2_dinode *di;
-	ocfs2_extent_rec *rec;
-	ocfs2_filesys *fs = NULL;
-
-	ret = ocfs2_open(group_dev, OCFS2_FLAG_RO, 0, 0, &fs);
-	if (ret) {
-		com_err(progname, ret, "while opening the device.");
-		return status;
-	}
-
-	heartbeat_filename = ocfs2_system_inodes[HEARTBEAT_SYSTEM_INODE].si_name;
-	ret = ocfs2_lookup(fs, fs->fs_sysdir_blkno, heartbeat_filename,
-			   strlen(heartbeat_filename),  NULL, &blkno);
-	if (ret) {
-		com_err(progname, ret, "while looking up the hb system inode.");
-		goto leave;
-	}
-
-	ret = ocfs2_malloc_block(fs->fs_io, &buf);
-	if (ret) {
-		com_err(progname, ret, "while allocating a block for hb.");
-		goto leave;
-	}
-	
-	ret = ocfs2_read_inode(fs, blkno, buf);
-	if (ret) {
-		com_err(progname, ret, "while reading hb inode.");
-		goto leave;
-	}
-
-	di = (ocfs2_dinode *)buf;
-	if (di->id2.i_list.l_tree_depth || 
-	    di->id2.i_list.l_next_free_rec != 1) {
-		com_err(progname, 0, "when checking for contiguous hb.");
-		goto leave;
-	}
-	rec = &(di->id2.i_list.l_recs[0]);
-	
-	*block_bits = OCFS2_RAW_SB(fs->fs_super)->s_blocksize_bits;
-	*cluster_bits = OCFS2_RAW_SB(fs->fs_super)->s_clustersize_bits;
-	*start_block = rec->e_blkno;
-	*num_clusters = rec->e_clusters;
-	status = 0;
-
-leave:
-	if (buf)
-		ocfs2_free(&buf);
-	if (fs)
-		ocfs2_close(fs);
-	return status;
-}
-
-static int start_heartbeat(char *hbuuid, char *device)
-{
-	int ret;
-	char *cluster = NULL;
-	errcode_t err;
-	uint32_t block_bits, cluster_bits, num_clusters;
-	uint64_t start_block, num_blocks;
-
-	ret = get_ocfs2_disk_hb_params(device, &block_bits, &cluster_bits, 
-				       &start_block, &num_clusters);
-	if (ret < 0) {
-		printf("hb_params failed\n");
-		return ret;
-	}
-
-	num_blocks = num_clusters << cluster_bits;
-	num_blocks >>= block_bits;
-
-	/* clamp to NM_MAX_NODES */
-	if (num_blocks > 254)
-		num_blocks = 254;
-
-        /* XXX: NULL cluster is a hack for right now */
-	err = o2cb_create_heartbeat_region_disk(NULL,
-						hbuuid,
-						device,
-						1 << block_bits,
-						start_block,
-						num_blocks);
-	if (err) {
-		com_err(progname, err, "while creating hb region with o2cb.");
-		return -EINVAL;
-	}
-
-	return 0;
-}
-
 static int process_options(struct mount_options *mo)
 {
 	if (!mo->dev) {

Added: trunk/mount.ocfs2/mount_hb.c
===================================================================
--- trunk/mount.ocfs2/mount_hb.c	2005-03-19 01:58:03 UTC (rev 698)
+++ trunk/mount.ocfs2/mount_hb.c	2005-03-19 02:51:47 UTC (rev 699)
@@ -0,0 +1,171 @@
+/*
+ * 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"
+
+int get_uuid(char *dev, char *uuid)
+{
+	ocfs2_filesys *fs = NULL;
+	errcode_t ret = 0;
+	int i;
+	char *p;
+	uint8_t *s_uuid;
+
+	ret = ocfs2_open(dev, OCFS2_FLAG_RO, 0, 0, &fs);
+	if (ret)
+		goto out;
+
+	s_uuid = OCFS2_RAW_SB(fs->fs_super)->s_uuid;
+
+	for (i = 0, p = uuid; i < 16; i++, p += 2)
+		sprintf(p, "%02X", s_uuid[i]);
+	*p = '\0';
+
+	ocfs2_close(fs);
+
+out:
+	return ret;
+}
+
+static int get_ocfs2_disk_hb_params(char *group_dev, uint32_t *block_bits, uint32_t *cluster_bits,
+			     uint64_t *start_block, uint32_t *num_clusters)
+{
+	int status = -EINVAL;
+	errcode_t ret = 0;
+	uint64_t blkno;
+	char *buf = NULL;
+	char *heartbeat_filename;
+	ocfs2_dinode *di;
+	ocfs2_extent_rec *rec;
+	ocfs2_filesys *fs = NULL;
+
+	ret = ocfs2_open(group_dev, OCFS2_FLAG_RO, 0, 0, &fs);
+	if (ret) {
+		com_err(progname, ret, "while opening the device.");
+		return status;
+	}
+
+	heartbeat_filename = ocfs2_system_inodes[HEARTBEAT_SYSTEM_INODE].si_name;
+	ret = ocfs2_lookup(fs, fs->fs_sysdir_blkno, heartbeat_filename,
+			   strlen(heartbeat_filename),  NULL, &blkno);
+	if (ret) {
+		com_err(progname, ret, "while looking up the hb system inode.");
+		goto leave;
+	}
+
+	ret = ocfs2_malloc_block(fs->fs_io, &buf);
+	if (ret) {
+		com_err(progname, ret, "while allocating a block for hb.");
+		goto leave;
+	}
+	
+	ret = ocfs2_read_inode(fs, blkno, buf);
+	if (ret) {
+		com_err(progname, ret, "while reading hb inode.");
+		goto leave;
+	}
+
+	di = (ocfs2_dinode *)buf;
+	if (di->id2.i_list.l_tree_depth || 
+	    di->id2.i_list.l_next_free_rec != 1) {
+		com_err(progname, 0, "when checking for contiguous hb.");
+		goto leave;
+	}
+	rec = &(di->id2.i_list.l_recs[0]);
+	
+	*block_bits = OCFS2_RAW_SB(fs->fs_super)->s_blocksize_bits;
+	*cluster_bits = OCFS2_RAW_SB(fs->fs_super)->s_clustersize_bits;
+	*start_block = rec->e_blkno;
+	*num_clusters = rec->e_clusters;
+	status = 0;
+
+leave:
+	if (buf)
+		ocfs2_free(&buf);
+	if (fs)
+		ocfs2_close(fs);
+	return status;
+}
+
+int start_heartbeat(char *hbuuid, char *device)
+{
+	int ret;
+	char *cluster = NULL;
+	errcode_t err;
+	uint32_t block_bits, cluster_bits, num_clusters;
+	uint64_t start_block, num_blocks;
+
+	ret = get_ocfs2_disk_hb_params(device, &block_bits, &cluster_bits, 
+				       &start_block, &num_clusters);
+	if (ret < 0) {
+		printf("hb_params failed\n");
+		return ret;
+	}
+
+	num_blocks = num_clusters << cluster_bits;
+	num_blocks >>= block_bits;
+
+	/* clamp to NM_MAX_NODES */
+	if (num_blocks > 254)
+		num_blocks = 254;
+
+        /* XXX: NULL cluster is a hack for right now */
+	err = o2cb_create_heartbeat_region_disk(NULL,
+						hbuuid,
+						device,
+						1 << block_bits,
+						start_block,
+						num_blocks);
+	if (err) {
+		com_err(progname, err, "while creating hb region with o2cb.");
+		return -EINVAL;
+	}
+
+	return 0;
+}
+
+int stop_heartbeat(const char *hbuuid)
+{
+	errcode_t err;
+
+	err = o2cb_remove_heartbeat_region_disk(NULL, hbuuid);
+	if (err) {
+		com_err(progname, err, "while creating hb region with o2cb.");
+		return -EINVAL;
+	}
+	return 0;
+}

Added: trunk/mount.ocfs2/mount_hb.h
===================================================================
--- trunk/mount.ocfs2/mount_hb.h	2005-03-19 01:58:03 UTC (rev 698)
+++ trunk/mount.ocfs2/mount_hb.h	2005-03-19 02:51:47 UTC (rev 699)
@@ -0,0 +1,27 @@
+/*
+ * 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;
+
+int start_heartbeat(char *hbuuid, char *device);
+int stop_heartbeat(const char *hbuuid);
+int get_uuid(char *dev, char *uuid);

Added: trunk/mount.ocfs2/ocfs2_hb_ctl.c
===================================================================
--- trunk/mount.ocfs2/ocfs2_hb_ctl.c	2005-03-19 01:58:03 UTC (rev 698)
+++ trunk/mount.ocfs2/ocfs2_hb_ctl.c	2005-03-19 02:51:47 UTC (rev 699)
@@ -0,0 +1,181 @@
+/*
+ * ocfs2_hb_ctl.c  Utility to start / stop heartbeat on demand
+ *
+ * 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 "ocfs2_hb_ctl.h"
+
+#include "o2cb.h"
+#include "mount_hb.h"
+
+char *progname = "ocfs2_hb_ctl";
+
+enum hb_ctl_action {
+	HB_ACTION_UKNOWN,
+	HB_ACTION_USAGE,
+	HB_ACTION_START,
+	HB_ACTION_STOP,
+};
+
+struct hb_ctl_options {
+	enum hb_ctl_action action;
+	char *dev_str;
+	char *uuid_str;
+};
+
+static void read_options(int argc, char **argv, struct hb_ctl_options *hbo)
+{
+	int c;
+
+	if (argc < 4)
+		return;
+
+	while(1) {
+		c = getopt(argc, argv, "SKd:u:h");
+		if (c == -1)
+			break;
+
+		switch (c) {
+		case 'h':
+			hbo->action = HB_ACTION_USAGE;
+			break;
+
+		case 'K':
+			hbo->action = HB_ACTION_STOP;
+			break;
+
+		case 'S':
+			hbo->action = HB_ACTION_START;
+			break;
+
+		case 'd':
+			if (optarg)
+				hbo->dev_str = strdup(optarg);
+			break;
+
+		case 'u':
+			if (optarg)
+				hbo->uuid_str = strdup(optarg);
+			break;
+
+		default:
+			break;
+		}
+	}
+}
+
+static int process_options(struct hb_ctl_options *hbo)
+{
+	int ret = 0;
+
+	switch (hbo->action) {
+	case HB_ACTION_START:
+		/* We can't start by uuid yet. */
+		if (hbo->uuid_str || !hbo->dev_str)
+			ret = -EINVAL;
+		break;
+
+	case HB_ACTION_STOP:
+		/* For stop must specify exactly one of uuid or device. */
+		if ((hbo->uuid_str && hbo->dev_str) ||
+		    (!hbo->uuid_str && !hbo->dev_str))
+			ret = -EINVAL;
+		break;
+
+	case HB_ACTION_UKNOWN:
+		ret = -EINVAL;
+		break;
+
+	case HB_ACTION_USAGE:
+	default:
+		break;
+	}
+
+	return ret;
+}
+
+static void print_usage(int err)
+{
+	FILE *output = err ? stderr : stdout;
+
+	fprintf(output, "Usage: %s -S -d <device>\n", progname);
+	fprintf(output, "       %s -K -d <device>\n", progname);
+	fprintf(output, "       %s -K -u <uuid>\n", progname);
+	fprintf(output, "       %s -h\n", progname);
+}
+
+int main(int argc, char **argv)
+{
+	errcode_t err = 0;
+	int ret = 0;
+	struct hb_ctl_options hbo = { HB_ACTION_UKNOWN, NULL, NULL };
+	char hbuuid[33];
+
+	initialize_ocfs_error_table();
+	initialize_o2dl_error_table();
+
+	read_options(argc, argv, &hbo);
+
+	ret = process_options(&hbo);
+	if (ret) {
+		print_usage(1);
+		goto bail;
+	}
+
+	if (!hbo.uuid_str) {
+		err = get_uuid(hbo.dev_str, hbuuid);
+		if (err) {
+			com_err(progname, err, "while reading uuid");
+			ret = -EINVAL;
+			goto bail;
+		}
+
+		hbo.uuid_str = hbuuid;
+	}
+
+	switch(hbo.action) {
+	case HB_ACTION_USAGE:
+		ret = 0;
+		print_usage(0);
+		break;
+
+	case HB_ACTION_START:
+		err = start_heartbeat(hbo.uuid_str, hbo.dev_str);
+		if (err) {
+			com_err(progname, err, "while starting heartbeat");
+			ret = -EINVAL;
+		}
+		break;
+
+	case HB_ACTION_STOP:
+		err = stop_heartbeat(hbo.uuid_str);
+		if (err) {
+			com_err(progname, err, "while stopping heartbeat");
+			ret = -EINVAL;
+		}
+		break;
+
+	default:
+		abort();
+	}
+
+bail:
+	return ret;
+}

Added: trunk/mount.ocfs2/ocfs2_hb_ctl.h
===================================================================
--- trunk/mount.ocfs2/ocfs2_hb_ctl.h	2005-03-19 01:58:03 UTC (rev 698)
+++ trunk/mount.ocfs2/ocfs2_hb_ctl.h	2005-03-19 02:51:47 UTC (rev 699)
@@ -0,0 +1,38 @@
+/*
+ * ocfs2_hb_ctl.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.
+ *
+ */
+
+#define _LARGEFILE64_SOURCE
+#define _GNU_SOURCE /* Because libc really doesn't want us using O_DIRECT? */
+
+#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>



More information about the Ocfs2-tools-commits mailing list