Skip to contentSkip to conversation

cluster/cman qdisk/clulog.c qdisk/score.h qdis ...

Cluster-devel [email protected] 1 participant 1 message Jan 22, 2007

lore
Share & tools
lore
#0 lore raw

CVSROOT: /cvs/cluster
Module name: cluster
Changes by: lhh at sourceware.org 2007-01-22 22:51:05

Modified files:
cman/qdisk : clulog.c score.h score.c disk.h main.c Makefile
cman/man : qdisk.5 mkqdisk.8
Added files:
cman/qdisk : daemon_init.c

Log message:
Resolves bugzillas: #213533, #216092, #220211, #223002, #223234/#223240

Detailed comments:

* Lock in memory to prevent being swapped out
* Turn on RR scheduling for main + score threads
* Let qdiskd wait for CMAN to start
* Add option to qdiskd to stop CMAN if qdisk device is not available
* Make qdisk interval timings more accurate
* Add option to reboot node if qdiskd detects internal hang > failure time (e.g. interval*tko, in seconds)
* Add per-heuristic tko counts for unreliable heuristics (e.g. ping packets)
* Remove nodes from quorate mask immediately on eviction
* Update man pages with better examples
* Don't let >1 instance of qdiskd be started
* Clarify logging output.
* Improve data in status_file.
* Allow qdiskd to run with no defined heuristics (master-always-wins mode).
* Make fencing of nodes optional (default = on).
* Make sure CMAN is running before we try to talk to it at each point.

Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/cluster/cman/qdisk/daemon_init.c.diff?cvsroot=cluster&r1=1.1&r2=1.2
http://sourceware.org/cgi-bin/cvsweb.cgi/cluster/cman/qdisk/clulog.c.diff?cvsroot=cluster&r1=1.2&r2=1.3
http://sourceware.org/cgi-bin/cvsweb.cgi/cluster/cman/qdisk/score.h.diff?cvsroot=cluster&r1=1.2&r2=1.3
http://sourceware.org/cgi-bin/cvsweb.cgi/cluster/cman/qdisk/score.c.diff?cvsroot=cluster&r1=1.2&r2=1.3
http://sourceware.org/cgi-bin/cvsweb.cgi/cluster/cman/qdisk/disk.h.diff?cvsroot=cluster&r1=1.4&r2=1.5
http://sourceware.org/cgi-bin/cvsweb.cgi/cluster/cman/qdisk/main.c.diff?cvsroot=cluster&r1=1.6&r2=1.7
http://sourceware.org/cgi-bin/cvsweb.cgi/cluster/cman/qdisk/Makefile.diff?cvsroot=cluster&r1=1.6&r2=1.7
http://sourceware.org/cgi-bin/cvsweb.cgi/cluster/cman/man/qdisk.5.diff?cvsroot=cluster&r1=1.3&r2=1.4
http://sourceware.org/cgi-bin/cvsweb.cgi/cluster/cman/man/mkqdisk.8.diff?cvsroot=cluster&r1=1.2&r2=1.3

cman/qdisk/daemon_init.c +238 -0
@@ -0,0 +1,238 @@
+/*
+  Copyright Red Hat, Inc. 2002, 2007
+  Copyright Mission Critical Linux, 2000
+
+  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, 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; see the file COPYING.  If not, write to the
+  Free Software Foundation, Inc.,  675 Mass Ave, Cambridge, 
+  MA 02139, USA.
+*/
+/** @file
+ * daemon_init function, does sanity checks and calls daemon().
+ *
+ * Author: Jeff Moyer <[email protected]>
+ */
+/*
+ * TODO: Clean this up so that only one function constructs the 
+ *       pidfile /var/run/loggerd.PID, and perhaps only one function
+ *       forms the /proc/PID/ path.
+ *
+ *       Also need to add file locking for the pid file.
+ */
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <string.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <sys/param.h>
+#include <fcntl.h>
+#include <dirent.h>
+#include <sys/mman.h>
+#include <sys/errno.h>
+#include <libgen.h>
+#include <signal.h>
+
+/*
+ * This should ultimately go in a header file.
+ */
+void daemon_init(char *prog);
+int check_pid_valid(pid_t pid, char *prog);
+int check_process_running(char *prog, pid_t * pid);
+
+/*
+ * Local prototypes.
+ */
+static void update_pidfile(char *prog);
+static int setup_sigmask(void);
+
+
+int
+check_pid_valid(pid_t pid, char *prog)
+{
+	FILE *fp;
+	DIR *dir;
+	char filename[PATH_MAX];
+	char dirpath[PATH_MAX];
+	char proc_cmdline[64];	/* yank this from kernel somewhere */
+	char *s = NULL;
+
+	memset(filename, 0, PATH_MAX);
+	memset(dirpath, 0, PATH_MAX);
+
+	snprintf(dirpath, sizeof (dirpath), "/proc/%d", pid);
+	if ((dir = opendir(dirpath)) == NULL) {
+		closedir(dir);
+		return 0;	/* Pid has gone away. */
+	}
+	closedir(dir);
+
+	/*
+	 * proc-pid directory exists.  Now check to see if this
+	 * PID corresponds to the daemon we want to start.
+	 */
+	snprintf(filename, sizeof (filename), "/proc/%d/cmdline", pid);
+	fp = fopen(filename, "r");
+	if (fp == NULL) {
+		perror("check_pid_valid");
+		return 0;	/* Who cares.... Let's boogy on. */
+	}
+
+	if (!fgets(proc_cmdline, sizeof (proc_cmdline) - 1, fp)) {
+		/*
+		 * Okay, we've seen processes keep a reference to a
+		 * /proc/PID/stat file and not let go.  Then when
+		 * you try to read /proc/PID/cmline, you get either
+		 * \000 or -1.  In either case, we can safely assume
+		 * the process has gone away.
+		 */
+		fclose(fp);
+		return 0;
+	}
+	fclose(fp);
+
+	s = &(proc_cmdline[strlen(proc_cmdline)]);
+	if (*s == '\n')
+		*s = 0;
+
+	/*
+	 * Check to see if this is the same executable.
+	 */
+	if ((s = strstr(proc_cmdline, prog)) == NULL) {
+		return 0;
+	} else {
+		return 1;
+	}
+}
+
+
+int
+check_process_running(char *prog, pid_t * pid)
+{
+	pid_t oldpid;
+	FILE *fp;
+	char filename[PATH_MAX];
+	char *cmd;
+	int ret;
+	struct stat st;
+
+	*pid = -1;
+
+	/*
+	 * Now see if there is a pidfile associated with this cmd in /var/run
+	 */
+	fp = NULL;
+	memset(filename, 0, PATH_MAX);
+
+	cmd = basename(prog);
+	snprintf(filename, sizeof (filename), "/var/run/%s.pid", cmd);
+
+	ret = stat(filename, &st);
+	if ((ret < 0) || (!st.st_size))
+		return 0;
+
+	/*
+	 * Read the pid from the file.
+	 */
+	fp = fopen(filename, "r");
+	if (fp == NULL) {	/* error */
+		return 0;
+	}
+	fscanf(fp, "%d\n", &oldpid);
+	fclose(fp);
+	if (check_pid_valid(oldpid, cmd)) {
+		*pid = oldpid;
+		return 1;
+	}
+	return 0;
+}
+
+
+static void
+update_pidfile(char *prog)
+{
+	FILE *fp = NULL;
+	char *cmd;
+	char filename[PATH_MAX];
+
+	memset(filename, 0, PATH_MAX);
+
+	cmd = basename(prog);
+	snprintf(filename, sizeof (filename), "/var/run/%s.pid", cmd);
+
+	fp = fopen(filename, "w");
+	if (fp == NULL) {
+		exit(1);
+	}
+
+	fprintf(fp, "%d", getpid());
+	fclose(fp);
+}
+
+
+static int
+setup_sigmask(void)
+{
+	sigset_t set;
+
+	sigfillset(&set);
+
+	/*
+	 * Dont't block signals which would cause us to dump core.
+	 */
+	sigdelset(&set, SIGQUIT);
+	sigdelset(&set, SIGILL);
+	sigdelset(&set, SIGTRAP);
+	sigdelset(&set, SIGABRT);
+	sigdelset(&set, SIGFPE);
+	sigdelset(&set, SIGSEGV);
+	sigdelset(&set, SIGBUS);
+
+	/*
+	 * Don't block SIGTERM or SIGCHLD
+	 */
+	sigdelset(&set, SIGTERM);
+	sigdelset(&set, SIGCHLD);
+
+	return (sigprocmask(SIG_BLOCK, &set, NULL));
+}
+
+
+void
+daemon_init(char *prog)
+{
+	uid_t uid;
+	pid_t pid;
+
+	uid = getuid();
+	if (uid) {
+		fprintf(stderr,
+			"daemon_init: Sorry, only root wants to run this.\n");
+		exit(1);
+	}
+
+	if (check_process_running(prog, &pid) && (pid != getpid())) {
+		fprintf(stderr,
+			"daemon_init: Process \"%s\" already running.\n",
+			prog);
+		exit(1);
+	}
+	if (setup_sigmask() < 0) {
+		fprintf(stderr, "daemon_init: Unable to set signal mask.\n");
+		exit(1);
+	}
+
+	daemon(0, 0);
+
+	update_pidfile(prog);
+}
cman/qdisk/clulog.c +1 -6
@@ -20,8 +20,6 @@
 /** @file
  * Library routines for communicating with the logging daemon.
  *
- *  $Id: clulog.c,v 1.2 2006/05/19 14:41:35 lhh Exp $
- *
  *  Author: Jeff Moyer <[email protected]>
  */
 #include <stdio.h>
@@ -50,8 +48,6 @@
 #include <string.h>
 
 
-static const char *version __attribute__ ((unused)) = "$Revision: 1.2 $";
-
 #ifdef DEBUG
 #include <assert.h>
 #define Dprintf(fmt,args...) printf(fmt,##args)
@@ -135,7 +131,7 @@
 	}
 	
 	pthread_mutex_unlock(&log_mutex);
-	return "local4";
+	return "daemon";
 }
 
 
@@ -156,7 +152,6 @@
 	for (; facilitynames[x].c_name; x++) {
 		if (strcmp(facilityname, facilitynames[x].c_name))
 			continue;
-
 		syslog_facility = facilitynames[x].c_val;
 		break;
 	}
cman/qdisk/score.h +3 -1
@@ -32,7 +32,9 @@
 	char *	program;
 	int	score;
 	int	available;
+	int	tko;
 	int	interval;
+	int	misses;
 	pid_t	childpid;
 	time_t	nextrun;
 };
@@ -50,7 +52,7 @@
 /*
    Start the thread which runs the scoring applets
  */
-int start_score_thread(struct h_data *h, int count);
+int start_score_thread(qd_ctx *ctx, struct h_data *h, int count);
 
 /* 
    Get our score + maxscore
cman/qdisk/score.c +83 -10

168 lines not on this page · raw message

cman/qdisk/disk.h +7 -1
@@ -67,7 +67,11 @@
 
 
 typedef enum {
-	RF_REBOOT = 0x1		/* Reboot if we go from master->none */
+	RF_REBOOT = 0x1,		/* Reboot if we go from master->none */
+	RF_STOP_CMAN = 0x2,
+	RF_DEBUG = 0x4,
+	RF_PARANOID = 0x8,
+	RF_ALLOW_KILL = 0x10
 } run_flag_t;
 
 
@@ -237,6 +241,8 @@
 	int qc_tko;
 	int qc_votes;
 	int qc_scoremin;
+	int qc_sched;
+	int qc_sched_prio;
 	disk_node_state_t qc_disk_status;
 	disk_node_state_t qc_status;
 	int qc_master;		/* Master?! */
cman/qdisk/main.c +420 -47

736 lines not on this page · raw message

cman/qdisk/Makefile +1 -1
@@ -28,7 +28,7 @@
 	install ${TARGET} ${sbindir}
 
 qdiskd: disk.o crc32.o disk_util.o main.o score.o bitmap.o clulog.o \
-	gettid.o proc.o ../lib/libcman.a
+	gettid.o proc.o daemon_init.o  ../lib/libcman.a
 	gcc -o $@ $^ -lpthread -L../lib -L${ccslibdir} -lccs
 
 mkqdisk: disk.o crc32.o disk_util.o \
cman/man/qdisk.5 +116 -17

207 lines not on this page · raw message

cman/man/mkqdisk.8 +8 -3
@@ -13,11 +13,16 @@
 .IP "\-c device \-l label"
 Initialize a new cluster quorum disk.  This will destroy all data on the given
 device.  If a cluster is currently using that device as a quorum disk, the
-entire cluster will malfunction.  Do not ru
+entire cluster will malfunction.  Do not run this on an active cluster when
+qdiskd is running.  Only one device on the SAN should ever have the given
+label; using multiple different devices is currently not supported (it is
+expected a RAID array is used for quorum disk redundancy).  The label can be
+any textual string up to 127 characters - and is therefore enough space to hold
+a UUID created with uuidgen(1).
 .IP "\-f label"
-Find the cluster quorum disk with the given label and display information about it..
+Find the cluster quorum disk with the given label and display information about it.
 .IP "\-L"
 Display information on all accessible cluster quorum disks.
 
 .SH "SEE ALSO"
-qdisk(5) qdiskd(8)
+qdisk(5), qdiskd(8), uuidgen(1)