[PATCH] fix up votequorum_qdevice_* man pages and improve test program

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 





Signed-Off-By: Christine Caulfield <ccaulfie@xxxxxxxxxx>
diff --git a/man/Makefile.am b/man/Makefile.am
index 9824524..41284cb 100644
--- a/man/Makefile.am
+++ b/man/Makefile.am
@@ -1,5 +1,5 @@
 # Copyright (c) 2004 MontaVista Software, Inc.
-# Copyright (c) 2009, 2012 Red Hat, Inc.
+# Copyright (c) 2009, 2012, 2014 Red Hat, Inc.
 #
 # Authors: Steven Dake (sdake@xxxxxxxxxx)
 #          Fabio M. Di Nitto (fdinitto@xxxxxxxxxx)
@@ -77,6 +77,11 @@ autogen_man		= cpg_context_get.3 \
 			  votequorum_setvotes.3 \
 			  votequorum_trackstart.3 \
 			  votequorum_trackstop.3 \
+			  votequorum_qdevice_register.3 \
+			  votequorum_qdevice_unregister.3 \
+			  votequorum_qdevice_update.3 \
+			  votequorum_qdevice_master_wins.3 \
+			  votequorum_qdevice_poll.3 \
 			  sam_data_getsize.3 \
 			  sam_data_restore.3 \
 			  sam_data_store.3 \
diff --git a/man/votequorum_qdevice_poll.3.in b/man/votequorum_qdevice_poll.3.in
index f13d1dc..348b84d 100644
--- a/man/votequorum_qdevice_poll.3.in
+++ b/man/votequorum_qdevice_poll.3.in
@@ -1,5 +1,5 @@
 .\"/*
-.\" * Copyright (c) 2009,2012 Red Hat, Inc.
+.\" * Copyright (c) 2009,2012,2014 Red Hat, Inc.
 .\" *
 .\" * All rights reserved.
 .\" *
@@ -37,7 +37,7 @@ votequorum_qdevice_poll \- Tells votequorum the result of the quorum device poll
 .SH SYNOPSIS
 .B #include <corosync/votequorum.h>
 .sp
-.BI "int votequorum_qdevice_poll(votequorum_handle_t " handle ", unsigned int " cast_vote ");"
+.BI "int votequorum_qdevice_poll(votequorum_handle_t " handle ", const char * " name ", unsigned int " cast_vote ");"
 .SH DESCRIPTION
 The
 .B votequorum_qdevice_poll
@@ -48,9 +48,9 @@ is 1 then the votes for the device are included in the quorum calculation, other
 This routine should be called at regular intervals to ensure that the device status
 is always known to votequorum. If
 .B votequorum_qdevice_poll
-is not called after (default) 10 seconds then the device will be deeded to be dead and
+is not called for (default) 10 seconds then the device will be deemed to be dead and
 its votes removed from the cluster. This does not unregister the device.
-The default poll time can be changed by setting the object database variable
+The default poll time can be changed by setting the cmap variable
 quorum.quorumdev_poll.
 .SH RETURN VALUE
 This call returns the CS_OK value if successful, otherwise an error is returned.
@@ -72,5 +72,6 @@ This call returns the CS_OK value if successful, otherwise an error is returned.
 .BR votequorum_setvotes (3),
 .BR votequorum_qdevice_register (3),
 .BR votequorum_qdevice_unregister (3),
-.BR votequorum_qdevice_get_info (3)
+.BR votequorum_qdevice_update (3),
+.BR votequorum_qdevice_master_wins (3),
 .PP
diff --git a/man/votequorum_qdevice_register.3.in b/man/votequorum_qdevice_register.3.in
index 8628d83..4ab248f 100644
--- a/man/votequorum_qdevice_register.3.in
+++ b/man/votequorum_qdevice_register.3.in
@@ -1,5 +1,5 @@
 .\"/*
-.\" * Copyright (c) 2009,2012 Red Hat, Inc.
+.\" * Copyright (c) 2009,2012,2014 Red Hat, Inc.
 .\" *
 .\" * All rights reserved.
 .\" *
@@ -37,7 +37,7 @@ votequorum_qdevice_register \- Registers a new quorum device
 .SH SYNOPSIS
 .B #include <corosync/votequorum.h>
 .sp
-.BI "int votequorum_qdevice_register(votequorum_handle_t " handle ", char * " name ", unsigned int " votes ");"
+.BI "int votequorum_qdevice_register(votequorum_handle_t " handle ", const char * " name ");"
 .SH DESCRIPTION
 The
 .B votequorum_qdevice_register
@@ -48,7 +48,14 @@ external device, usually a shared disk partition or perhaps a network router.
 This call creates the device but does not mark it active.
 .B votequorum_qdevice_poll
 must be called for the votes to be included in the quorum calculation.
-.BR
+.br
+.B name
+is string containing an informative name for the quorum device. It is simply stored
+by votequorum and used in the display of corosync-quorumtool, it can be a maximum of 254 characters.
+.br
+The number of votes contributed by the quorum device is already known to votequorum, it is set in cmap
+quorum.device.votes and not by the device.
+.br
 Note that it is the responsibility of the quorum device subsystem (not provided as part of votequorum)
 to keep all nodes informed of the quorum device status.
 .SH RETURN VALUE
@@ -71,5 +78,6 @@ This call returns the CS_OK value if successful, otherwise an error is returned.
 .BR votequorum_setvotes (3),
 .BR votequorum_qdevice_unregister (3),
 .BR votequorum_qdevice_poll (3),
-.BR votequorum_qdevice_get_info (3)
+.BR votequorum_qdevice_update (3),
+.BR votequorum_qdevice_master_wins (3)
 .PP
diff --git a/man/votequorum_qdevice_unregister.3.in b/man/votequorum_qdevice_unregister.3.in
index 8ea1514..8741dac 100644
--- a/man/votequorum_qdevice_unregister.3.in
+++ b/man/votequorum_qdevice_unregister.3.in
@@ -1,5 +1,5 @@
 .\"/*
-.\" * Copyright (c) 2009,2012 Red Hat, Inc.
+.\" * Copyright (c) 2009,2012,2014 Red Hat, Inc.
 .\" *
 .\" * All rights reserved.
 .\" *
@@ -37,7 +37,7 @@ votequorum_qdevice_unregister \- Unregisters a new quorum device
 .SH SYNOPSIS
 .B #include <corosync/votequorum.h>
 .sp
-.BI "int votequorum_qdevice_unregister(votequorum_handle_t " handle ");"
+.BI "int votequorum_qdevice_unregister(votequorum_handle_t " handle ", const char * " name ");"
 .SH DESCRIPTION
 The
 .B votequorum_qdevice_unregister
@@ -63,5 +63,6 @@ This call returns the CS_OK value if successful, otherwise an error is returned.
 .BR votequorum_setvotes (3),
 .BR votequorum_qdevice_register (3),
 .BR votequorum_qdevice_poll (3),
-.BR votequorum_qdevice_get_info (3)
+.BR votequorum_qdevice_update (3),
+.BR votequorum_qdevice_master_wins (3)
 .PP
diff --git a/test/testvotequorum2.c b/test/testvotequorum2.c
index 7198029..3e4bd34 100644
--- a/test/testvotequorum2.c
+++ b/test/testvotequorum2.c
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2009 Red Hat, Inc.
+ * Copyright (c) 2009-2014 Red Hat, Inc.
  *
  * All rights reserved.
  *
@@ -37,6 +37,7 @@
 #include <sys/types.h>
 #include <stdio.h>
 #include <stdint.h>
+#include <string.h>
 #include <stdlib.h>
 #include <unistd.h>
 #include <corosync/corotypes.h>
@@ -44,86 +45,132 @@
 
 static votequorum_handle_t handle;
 
-static void print_info(int ok_to_fail)
+static int print_info(int ok_to_fail)
 {
 	struct votequorum_info info;
 	int err;
 
-	if ( (err=votequorum_getinfo(handle, VOTEQUORUM_QDEVICE_NODEID, &info)) != CS_OK)
+	if ( (err=votequorum_getinfo(handle, VOTEQUORUM_QDEVICE_NODEID, &info)) != CS_OK) {
 		fprintf(stderr, "votequorum_getinfo error %d: %s\n", err, ok_to_fail?"OK":"FAILED");
+		return -1;
+	}
 	else {
 		printf("name           %s\n", info.qdevice_name);
 		printf("qdevice votes  %d\n", info.qdevice_votes);
 		if (info.flags & VOTEQUORUM_INFO_QDEVICE_ALIVE) {
-			printf("alive\n");
+			printf("alive ");
 		}
 		if (info.flags & VOTEQUORUM_INFO_QDEVICE_CAST_VOTE) {
-			printf("cast vote\n");
+			printf("cast-vote ");
 		}
 		if (info.flags & VOTEQUORUM_INFO_QDEVICE_MASTER_WINS) {
-			printf("master wins\n");
+			printf("master-wins");
 		}
-		printf("\n");
+		printf("\n\n");
 	}
+	return 0;
+}
+
+static void usage(const char *command)
+{
+  printf("%s [-p <num>] [-t <time>] [-n <name>] [-c] [-m]\n", command);
+        printf("      -p <num>  Number of times to poll qdevice (default 0=infinte)\n");
+        printf("      -t <secs> Time (in seconds) to wait between polls (default=1)\n");
+        printf("      -n <name> Name of quorum device (default QDEVICE)\n");
+        printf("      -c        Cast vote (default yes)\n");
+        printf("      -q        Don't print device status every poll time (default=will print)\n");
+        printf("      -m        Master wins (default no)\n");
+        printf("      -1        Print status once and exit\n");
 }
 
 int main(int argc, char *argv[])
 {
 	int ret = 0;
-	int cast_vote = 1, master_wins = 1;
-	int pollcount=0, polltime=1;
+	int cast_vote = 1, master_wins = 0;
+	int pollcount=0, polltime=1, quiet=0, once=0;
 	int err;
+	int opt;
+	const char *devicename = "QDEVICE";
+	const char *options = "n:p:t:cmq1h";
+	
+	while ((opt = getopt(argc, argv, options)) != -1) {
+		switch (opt) {
+		case 'm':
+		        master_wins = 1;
+			break;
+		case 'c':
+		        cast_vote = 1;
+			break;
+		case '1':
+		        once = 1;
+			break;
+		case 'q':
+		        quiet = 1;
+			break;
+		case 'p':
+		        pollcount = atoi(optarg)+1;
+			break;
+		case 'n':
+		        devicename = strdup(optarg);
+			break;
+		case 't':
+		        polltime = atoi(optarg);
+			break;
+		case 'h':
+		        usage(argv[0]);
+			exit(0);
+		}
+	}
 
 	if ( (err=votequorum_initialize(&handle, NULL)) != CS_OK) {
 		fprintf(stderr, "votequorum_initialize FAILED: %d\n", err);
 		return -1;
 	}
 
-	print_info(1);
-
-	if (argc >= 2 && atoi(argv[1])) {
-		pollcount = atoi(argv[1]);
-	}
-	if (argc >= 3 && atoi(argv[2])) {
-		polltime = atoi(argv[2]);
+	if (quiet && once) {
+	        fprintf(stderr, "setting both -q (quet) and -1 (once) makes no sense\n");
+		usage(argv[0]);
+		exit(1);
 	}
-	if (argc >= 4) {
-		cast_vote = atoi(argv[3]);
+
+	if (!quiet) {
+	        print_info(1);
 	}
-	if (argc >= 5) {
-		master_wins = atoi(argv[4]);
+	if (once) {
+	        exit(0);
 	}
 
 	if (argc >= 2) {
-		if ( (err=votequorum_qdevice_register(handle, "QDEVICE")) != CS_OK) {
+		if ( (err=votequorum_qdevice_register(handle, devicename)) != CS_OK) {
 			fprintf(stderr, "qdevice_register FAILED: %d\n", err);
 			ret = -1;
 			goto out;
 		}
 
-		if ( (err=votequorum_qdevice_master_wins(handle, "QDEVICE", master_wins)) != CS_OK) {
+		if ( (err=votequorum_qdevice_master_wins(handle, devicename, master_wins)) != CS_OK) {
 			fprintf(stderr, "qdevice_master_wins FAILED: %d\n", err);
 			ret = -1;
 			goto out;
 		}
 
-		while (pollcount--) {
-			print_info(0);
-			if ((err=votequorum_qdevice_poll(handle, "QDEVICE", cast_vote)) != CS_OK) {
+		while (--pollcount) {
+		        if (!quiet) print_info(0);
+			if ((err=votequorum_qdevice_poll(handle, devicename, cast_vote)) != CS_OK) {
 				fprintf(stderr, "qdevice poll FAILED: %d\n", err);
 				ret = -1;
 				goto out;
 			}
-			print_info(0);
+			if (!quiet) print_info(0);
 			sleep(polltime);
 		}
-		if ((err= votequorum_qdevice_unregister(handle, "QDEVICE")) != CS_OK) {
+		if ((err= votequorum_qdevice_unregister(handle, devicename)) != CS_OK) {
 			fprintf(stderr, "qdevice unregister FAILED: %d\n", err);
 			ret = -1;
 			goto out;
 		}
 	}
-	print_info(1);
+
+        if (!quiet) print_info(1);
 
 out:
 	votequorum_finalize(handle);
_______________________________________________
discuss mailing list
discuss@xxxxxxxxxxxx
http://lists.corosync.org/mailman/listinfo/discuss

[Index of Archives]     [Linux Clusters]     [Corosync Project]     [Linux USB Devel]     [Linux Audio Users]     [Photo]     [Yosemite News]    [Yosemite Photos]    [Linux Kernel]     [Linux SCSI]     [X.Org]

  Powered by Linux