This is the mail archive of the
cluster-cvs@sourceware.org
mailing list for the cluster.
cluster: master - qdiskd: Misc. cleanups, esp. loop cleanups in main.c
- From: Lon Hohberger <lon at fedoraproject dot org>
- To: cluster-cvs-relay at redhat dot com
- Date: Mon, 24 Nov 2008 20:36:36 +0000 (UTC)
- Subject: cluster: master - qdiskd: Misc. cleanups, esp. loop cleanups in main.c
Gitweb: http://git.fedorahosted.org/git/cluster.git?p=cluster.git;a=commitdiff;h=2bc87e3b553300722638327f5571ebdd98d97b9b
Commit: 2bc87e3b553300722638327f5571ebdd98d97b9b
Parent: b0db0bad3e6a8996fcaecbb93bfe9f8de97b7508
Author: Lon Hohberger <lhh@redhat.com>
AuthorDate: Mon Nov 24 13:17:38 2008 -0500
Committer: Lon Hohberger <lhh@redhat.com>
CommitterDate: Mon Nov 24 13:17:38 2008 -0500
qdiskd: Misc. cleanups, esp. loop cleanups in main.c
Also use the ../../common/liblogthread API for now at
least until logsys v2 stabilizes
---
cman/qdisk/Makefile | 6 +-
cman/qdisk/daemon_init.c | 10 +-
cman/qdisk/disk.c | 66 ++++----
cman/qdisk/disk_util.c | 4 +-
cman/qdisk/main.c | 425 ++++++++++++++++++----------------------------
cman/qdisk/mkqdisk.c | 11 +-
cman/qdisk/proc.c | 42 +++---
cman/qdisk/score.c | 18 +-
8 files changed, 237 insertions(+), 345 deletions(-)
diff --git a/cman/qdisk/Makefile b/cman/qdisk/Makefile
index 47bfc61..1f1e9fb 100644
--- a/cman/qdisk/Makefile
+++ b/cman/qdisk/Makefile
@@ -13,12 +13,12 @@ include $(OBJDIR)/make/uninstall.mk
CFLAGS += -D_GNU_SOURCE
CFLAGS += -Werror -Wstrict-prototypes -Wshadow
-CFLAGS += -I${ccsincdir} -I${cmanincdir}
-CFLAGS += -I${zlibincdir} -I${corosyncincdir}
+CFLAGS += -I${ccsincdir} -I${cmanincdir} -I${logtincdir}
+CFLAGS += -I${zlibincdir}
CFLAGS += -I$(S)
CFLAGS += -I${incdir}
-LDFLAGS += -L${corosynclibdir} -llogsys -lpthread
+LDFLAGS += -L${logtlibdir} -llogthread -lpthread
LDFLAGS += -L${zliblibdir} -lz
LDFLAGS += -L${libdir}
diff --git a/cman/qdisk/daemon_init.c b/cman/qdisk/daemon_init.c
index cc6f90e..7a24733 100644
--- a/cman/qdisk/daemon_init.c
+++ b/cman/qdisk/daemon_init.c
@@ -23,7 +23,7 @@
#include <sys/errno.h>
#include <libgen.h>
#include <signal.h>
-#include <corosync/engine/logsys.h>
+#include <liblogthread.h>
/*
* This should ultimately go in a header file.
@@ -201,24 +201,24 @@ daemon_init(char *prog)
uid = getuid();
if (uid) {
- log_printf(LOG_ERR,
+ logt_print(LOG_ERR,
"daemon_init: Sorry, only root wants to run this.\n");
exit(1);
}
if (check_process_running(prog, &pid) && (pid != getpid())) {
- log_printf(LOG_ERR,
+ logt_print(LOG_ERR,
"daemon_init: Process \"%s\" already running.\n",
prog);
exit(1);
}
if (setup_sigmask() < 0) {
- log_printf(LOG_ERR, "daemon_init: Unable to set signal mask.\n");
+ logt_print(LOG_ERR, "daemon_init: Unable to set signal mask.\n");
exit(1);
}
if(daemon(0, 0)) {
- log_printf(LOG_ERR, "daemon_init: Unable to daemonize.\n");
+ logt_print(LOG_ERR, "daemon_init: Unable to daemonize.\n");
exit(1);
}
diff --git a/cman/qdisk/disk.c b/cman/qdisk/disk.c
index 972bbf6..e838688 100644
--- a/cman/qdisk/disk.c
+++ b/cman/qdisk/disk.c
@@ -25,7 +25,7 @@
#include <unistd.h>
#include <time.h>
#include <linux/fs.h>
-#include <corosync/engine/logsys.h>
+#include <liblogthread.h>
static int diskRawRead(target_info_t *disk, char *buf, int len);
uint32_t clu_crc32(const char *data, size_t count);
@@ -100,7 +100,7 @@ header_generate(shared_header_t *hdr, const char *data, size_t count)
hdr->h_length = (uint32_t)count;
if (hdr->h_dcrc == 0) {
- log_printf(LOG_ERR, "Invalid CRC32 generated on data!\n");
+ logt_print(LOG_ERR, "Invalid CRC32 generated on data!\n");
return -1;
}
}
@@ -109,7 +109,7 @@ header_generate(shared_header_t *hdr, const char *data, size_t count)
hdr->h_hcrc = clu_crc32((char *)hdr, sizeof(*hdr));
if (hdr->h_hcrc == 0) {
- log_printf(LOG_ERR, "Invalid CRC32 generated on header!\n");
+ logt_print(LOG_ERR, "Invalid CRC32 generated on header!\n");
return -1;
}
@@ -146,7 +146,7 @@ header_verify(shared_header_t *hdr, const char *data, size_t count)
crc = clu_crc32((char *)hdr, sizeof(*hdr));
hdr->h_hcrc = bkupcrc;
if (bkupcrc != crc) {
- log_printf(LOG_DEBUG, "Header CRC32 mismatch; Exp: 0x%08x "
+ logt_print(LOG_DEBUG, "Header CRC32 mismatch; Exp: 0x%08x "
"Got: 0x%08x\n", bkupcrc, crc);
return -1;
}
@@ -155,7 +155,7 @@ header_verify(shared_header_t *hdr, const char *data, size_t count)
* Verify the magic number.
*/
if (hdr->h_magic != SHARED_HEADER_MAGIC) {
- log_printf(LOG_DEBUG, "Magic mismatch; Exp: 0x%08x "
+ logt_print(LOG_DEBUG, "Magic mismatch; Exp: 0x%08x "
"Got: 0x%08x\n", SHARED_HEADER_MAGIC, hdr->h_magic);
return -1;
}
@@ -171,7 +171,7 @@ header_verify(shared_header_t *hdr, const char *data, size_t count)
hdr->h_length : count);
if (hdr->h_dcrc != crc) {
- log_printf(LOG_DEBUG, "Data CRC32 mismatch; Exp: 0x%08x "
+ logt_print(LOG_DEBUG, "Data CRC32 mismatch; Exp: 0x%08x "
"Got: 0x%08x\n", hdr->h_dcrc, crc);
return -1;
}
@@ -202,7 +202,7 @@ qdisk_open(char *name, target_info_t *disk)
ret = ioctl(disk->d_fd, BLKSSZGET, &ssz);
if (ret < 0) {
- log_printf(LOG_ERR, "qdisk_open: ioctl(BLKSSZGET)");
+ logt_print(LOG_ERR, "qdisk_open: ioctl(BLKSSZGET)");
close(disk->d_fd);
return -1;
}
@@ -213,13 +213,13 @@ qdisk_open(char *name, target_info_t *disk)
/* Check to verify that the partition is large enough.*/
ret = lseek(disk->d_fd, END_OF_DISK(disk->d_blksz), SEEK_SET);
if (ret < 0) {
- log_printf(LOG_DEBUG, "open_partition: seek");
+ logt_print(LOG_DEBUG, "open_partition: seek");
close(disk->d_fd);
return -1;
}
if (ret < END_OF_DISK(disk->d_blksz)) {
- log_printf(LOG_ERR, "Partition %s too small\n", name);
+ logt_print(LOG_ERR, "Partition %s too small\n", name);
errno = EINVAL;
close(disk->d_fd);
return -1;
@@ -228,14 +228,14 @@ qdisk_open(char *name, target_info_t *disk)
/* Set close-on-exec bit */
ret = fcntl(disk->d_fd, F_GETFD, 0);
if (ret < 0) {
- log_printf(LOG_ERR, "open_partition: fcntl(F_GETFD)");
+ logt_print(LOG_ERR, "open_partition: fcntl(F_GETFD)");
close(disk->d_fd);
return -1;
}
ret |= FD_CLOEXEC;
if (fcntl(disk->d_fd, F_SETFD, ret) < 0) {
- log_printf(LOG_ERR, "open_partition: fcntl(F_SETFD)");
+ logt_print(LOG_ERR, "open_partition: fcntl(F_SETFD)");
close(disk->d_fd);
return -1;
}
@@ -279,7 +279,7 @@ qdisk_validate(char *name)
stat_ptr = &stat_st;
if (stat(name, stat_ptr) < 0) {
- log_printf(LOG_ERR, "stat");
+ logt_print(LOG_ERR, "stat");
return -1;
}
/*
@@ -290,7 +290,7 @@ qdisk_validate(char *name)
errno = EINVAL;
return -1;
*/
- log_printf(LOG_WARNING, "Warning: %s is not a block device\n",
+ logt_print(LOG_WARNING, "Warning: %s is not a block device\n",
name);
}
@@ -298,7 +298,7 @@ qdisk_validate(char *name)
* Verify read/write permission.
*/
if (qdisk_open(name, &disk) < 0) {
- log_printf(LOG_DEBUG, "%s: open of %s for RDWR failed: %s\n",
+ logt_print(LOG_DEBUG, "%s: open of %s for RDWR failed: %s\n",
__FUNCTION__, name, strerror(errno));
return -1;
}
@@ -317,7 +317,7 @@ diskRawReadShadow(target_info_t *disk, off_t readOffset, char *buf, int len)
ret = lseek(disk->d_fd, readOffset, SEEK_SET);
if (ret != readOffset) {
- log_printf(LOG_DEBUG,
+ logt_print(LOG_DEBUG,
"diskRawReadShadow: can't seek to offset %d.\n",
(int) readOffset);
errno = ENODATA;
@@ -326,7 +326,7 @@ diskRawReadShadow(target_info_t *disk, off_t readOffset, char *buf, int len)
ret = diskRawRead(disk, buf, len);
if (ret != len) {
- log_printf(LOG_DEBUG, "diskRawReadShadow: aligned read "
+ logt_print(LOG_DEBUG, "diskRawReadShadow: aligned read "
"returned %d, not %d.\n", ret, len);
errno = ENODATA;
return -1;
@@ -339,7 +339,7 @@ diskRawReadShadow(target_info_t *disk, off_t readOffset, char *buf, int len)
datalen = hdrp->h_length;
if (header_verify(hdrp, data, len)) {
- log_printf(LOG_DEBUG, "diskRawReadShadow: bad CRC32, "
+ logt_print(LOG_DEBUG, "diskRawReadShadow: bad CRC32, "
"offset = %d len = %d\n",
(int) readOffset, len);
errno = EPROTO;
@@ -378,7 +378,7 @@ diskRawRead(target_info_t *disk, char *buf, int len)
}
if (len > disk->d_blksz) {
- log_printf(LOG_ERR,
+ logt_print(LOG_ERR,
"diskRawRead: not setup for reads larger than %d.\n",
(int)disk->d_blksz);
return (-1);
@@ -415,7 +415,7 @@ diskRawRead(target_info_t *disk, char *buf, int len)
free(alignedBuf);
if (readret != len) {
- log_printf(LOG_ERR, "diskRawRead: read err, len=%d, readret=%d\n",
+ logt_print(LOG_ERR, "diskRawRead: read err, len=%d, readret=%d\n",
len, readret);
}
@@ -450,7 +450,7 @@ diskRawWrite(target_info_t *disk, char *buf, int len)
}
if (len > disk->d_blksz) {
- log_printf(LOG_ERR,
+ logt_print(LOG_ERR,
"diskRawRead: not setup for reads larger than %d.\n",
(int)disk->d_blksz);
return (-1);
@@ -476,7 +476,7 @@ diskRawWrite(target_info_t *disk, char *buf, int len)
}
if (len > disk->d_blksz) {
- log_printf(LOG_ERR,
+ logt_print(LOG_ERR,
"diskRawWrite: not setup for larger than %d.\n",
(int)disk->d_blksz);
return (-1);
@@ -490,7 +490,7 @@ diskRawWrite(target_info_t *disk, char *buf, int len)
free(alignedBuf);
if (ret != len) {
- log_printf(LOG_ERR, "diskRawWrite: write err, len=%d, ret=%dn",
+ logt_print(LOG_ERR, "diskRawWrite: write err, len=%d, ret=%dn",
len, ret);
}
@@ -505,7 +505,7 @@ diskRawWriteShadow(target_info_t *disk, __off64_t writeOffset, char *buf, int le
ssize_t retval_write;
if ((writeOffset < 0) || (len < 0)) {
- log_printf(LOG_ERR,
+ logt_print(LOG_ERR,
"diskRawWriteShadow: writeOffset=%08x, "
"len=%08x.\n", (int)writeOffset, len);
return (-1);
@@ -513,7 +513,7 @@ diskRawWriteShadow(target_info_t *disk, __off64_t writeOffset, char *buf, int le
retval_seek = lseek(disk->d_fd, writeOffset, SEEK_SET);
if (retval_seek != writeOffset) {
- log_printf(LOG_ERR,
+ logt_print(LOG_ERR,
"diskRawWriteShadow: can't seek to offset %d\n",
(int) writeOffset);
return (-1);
@@ -522,10 +522,10 @@ diskRawWriteShadow(target_info_t *disk, __off64_t writeOffset, char *buf, int le
retval_write = diskRawWrite(disk, buf, len);
if (retval_write != len) {
if (retval_write == -1) {
- log_printf(LOG_ERR, "%s: %s\n", __FUNCTION__,
+ logt_print(LOG_ERR, "%s: %s\n", __FUNCTION__,
strerror(errno));
}
- log_printf(LOG_ERR,
+ logt_print(LOG_ERR,
"diskRawWriteShadow: aligned write returned %d"
", not %d\n", (int)retval_write, (int)len);
return (-1);
@@ -598,7 +598,7 @@ qdisk_write(target_info_t *disk, __off64_t offset, const void *buf, int count)
maxsize = psz - (sizeof(shared_header_t));
if (count >= (maxsize + sizeof(shared_header_t))) {
- log_printf(LOG_ERR, "error: count %d >= (%d + %d)\n", (int)count,
+ logt_print(LOG_ERR, "error: count %d >= (%d + %d)\n", (int)count,
(int)maxsize, (int)sizeof(shared_header_t));
errno = ENOSPC;
return -1;
@@ -618,7 +618,7 @@ qdisk_write(target_info_t *disk, __off64_t offset, const void *buf, int count)
ptr = NULL;
rv = posix_memalign((void **)&ptr, disk->d_pagesz, total);
if (rv < 0) {
- log_printf(LOG_ERR, "posix_memalign");
+ logt_print(LOG_ERR, "posix_memalign");
return -1;
}
@@ -643,7 +643,7 @@ qdisk_write(target_info_t *disk, __off64_t offset, const void *buf, int count)
rv = diskRawWriteShadow(disk, offset, (char *)hdrp, psz);
if (rv == -1)
- log_printf(LOG_ERR, "diskRawWriteShadow");
+ logt_print(LOG_ERR, "diskRawWriteShadow");
free((char *)hdrp);
if (rv == -1)
@@ -669,7 +669,7 @@ header_init(target_info_t *disk, char *label)
}
if (gethostname(qh.qh_updatehost, sizeof(qh.qh_updatehost)) < 0) {
- log_printf(LOG_ERR, "gethostname");
+ logt_print(LOG_ERR, "gethostname");
return -1;
}
@@ -678,7 +678,7 @@ header_init(target_info_t *disk, char *label)
qh.qh_version = VERSION_MAGIC_V2;
if ((qh.qh_timestamp = (uint64_t)time(NULL)) <= 0) {
- log_printf(LOG_ERR, "time");
+ logt_print(LOG_ERR, "time");
return -1;
}
@@ -705,13 +705,13 @@ qdisk_init(char *partname, char *label)
ret = qdisk_validate(partname);
if (ret < 0) {
- log_printf(LOG_DEBUG, "qdisk_verify");
+ logt_print(LOG_DEBUG, "qdisk_verify");
return -1;
}
ret = qdisk_open(partname, &disk);
if (ret < 0) {
- log_printf(LOG_ERR, "qdisk_open");
+ logt_print(LOG_ERR, "qdisk_open");
return -1;
}
diff --git a/cman/qdisk/disk_util.c b/cman/qdisk/disk_util.c
index ec8f04f..3743618 100644
--- a/cman/qdisk/disk_util.c
+++ b/cman/qdisk/disk_util.c
@@ -15,7 +15,7 @@
#include <unistd.h>
#include <sys/time.h>
#include <time.h>
-#include <corosync/engine/logsys.h>
+#include <liblogthread.h>
inline void
_diff_tv(struct timeval *dest, struct timeval *start, struct timeval *end)
@@ -184,7 +184,7 @@ qd_write_status(qd_ctx *ctx, int nid, disk_node_state_t state,
if (qdisk_write(&ctx->qc_disk,
qdisk_nodeid_offset(nid, ctx->qc_disk.d_blksz),
&ps, sizeof(ps)) < 0) {
- log_printf(LOG_ERR, "Error writing node ID block %d\n", nid);
+ logt_print(LOG_ERR, "Error writing node ID block %d\n", nid);
return -1;
}
if (utime_ok && (get_time(&end, ctx->qc_flags&RF_UPTIME) < 0))
diff --git a/cman/qdisk/main.c b/cman/qdisk/main.c
index e8654e2..a43e8f6 100644
--- a/cman/qdisk/main.c
+++ b/cman/qdisk/main.c
@@ -21,9 +21,12 @@
#include <sched.h>
#include <signal.h>
#include <ccs.h>
-#include <corosync/engine/logsys.h>
+#include <liblogthread.h>
#include "score.h"
+
+#define DAEMON_NAME "QDISKD"
+
/* from daemon_init.c */
int daemon_init(char *);
int check_process_running(char *, pid_t *);
@@ -48,10 +51,15 @@ inline void _diff_tv(struct timeval *dest, struct timeval *start,
struct timeval *end);
static int _running = 1, _reconfig = 0;
+static int _debug = 0, _foreground = 0;
+
+/* */
+#define DEBUG_CONF 0x1
+#define DEBUG_CMDLINE 0x2
+
static void update_local_status(qd_ctx *ctx, node_info_t *ni, int max, int score,
int score_req, int score_max);
-static int get_config_data(qd_ctx *ctx, struct h_data *h, int maxh, int *cfh,
- int debug, int trylater);
+static int get_config_data(qd_ctx *ctx, struct h_data *h, int maxh, int *cfh);
static void
@@ -68,6 +76,17 @@ hup_handler(int sig)
}
+static void
+usr1_handler(int sig)
+{
+ if (_debug)
+ /* Shut up debug mode */
+ _debug = 0;
+ else
+ _debug = DEBUG_CMDLINE;
+}
+
+
/**
Simple thing to see if a node is running.
*/
@@ -116,7 +135,7 @@ check_self(qd_ctx *ctx, status_block_t *sb)
/* Someone told us to die. */
reboot(RB_AUTOBOOT);
default:
- log_printf(LOG_EMERG, "Unhandled state: %d\n", sb->ps_state);
+ logt_print(LOG_EMERG, "Unhandled state: %d\n", sb->ps_state);
raise(SIGSTOP);
}
}
@@ -140,7 +159,7 @@ read_node_blocks(qd_ctx *ctx, node_info_t *ni, int max)
if (qdisk_read(&ctx->qc_disk,
qdisk_nodeid_offset(x+1, ctx->qc_disk.d_blksz),
sb, sizeof(*sb)) < 0) {
- log_printf(LOG_WARNING,"Error reading node ID block %d\n",
+ logt_print(LOG_WARNING,"Error reading node ID block %d\n",
x+1);
++errors;
continue;
@@ -166,7 +185,7 @@ read_node_blocks(qd_ctx *ctx, node_info_t *ni, int max)
/* XXX check for average + allow grace */
ni[x].ni_misses++;
if (ni[x].ni_misses > 1) {
- log_printf(LOG_DEBUG,
+ logt_print(LOG_DEBUG,
"Node %d missed an update (%d/%d)\n",
x+1, ni[x].ni_misses, ctx->qc_tko);
}
@@ -211,11 +230,11 @@ check_transitions(qd_ctx *ctx, node_info_t *ni, int max, memb_mask_t mask)
ni[x].ni_status.ps_incarnation))) {
if (ni[x].ni_status.ps_state == S_EVICT) {
- log_printf(LOG_NOTICE, "Node %d evicted\n",
+ logt_print(LOG_NOTICE, "Node %d evicted\n",
ni[x].ni_status.ps_nodeid);
} else {
/* State == S_NONE or incarnation change */
- log_printf(LOG_INFO, "Node %d shutdown\n",
+ logt_print(LOG_INFO, "Node %d shutdown\n",
ni[x].ni_status.ps_nodeid);
ni[x].ni_evil_incarnation = 0;
}
@@ -252,7 +271,7 @@ check_transitions(qd_ctx *ctx, node_info_t *ni, int max, memb_mask_t mask)
*/
if (ni[x].ni_status.ps_state >= S_RUN &&
ni[x].ni_seen) {
- log_printf(LOG_DEBUG, "Node %d DOWN\n",
+ logt_print(LOG_DEBUG, "Node %d DOWN\n",
ni[x].ni_status.ps_nodeid);
ni[x].ni_seen = 0;
}
@@ -266,13 +285,13 @@ check_transitions(qd_ctx *ctx, node_info_t *ni, int max, memb_mask_t mask)
Write eviction notice if we're the master.
*/
if (ctx->qc_status == S_MASTER) {
- log_printf(LOG_NOTICE,
+ logt_print(LOG_NOTICE,
"Writing eviction notice for node %d\n",
ni[x].ni_status.ps_nodeid);
qd_write_status(ctx, ni[x].ni_status.ps_nodeid,
S_EVICT, NULL, NULL, NULL);
if (ctx->qc_flags & RF_ALLOW_KILL) {
- log_printf(LOG_DEBUG, "Telling CMAN to "
+ logt_print(LOG_DEBUG, "Telling CMAN to "
"kill the node\n");
cman_kill_node(ctx->qc_cman_admin,
ni[x].ni_status.ps_nodeid);
@@ -296,10 +315,10 @@ check_transitions(qd_ctx *ctx, node_info_t *ni, int max, memb_mask_t mask)
if (ni[x].ni_evil_incarnation &&
(ni[x].ni_evil_incarnation ==
ni[x].ni_status.ps_incarnation)) {
- log_printf(LOG_CRIT, "Node %d is undead.\n",
+ logt_print(LOG_CRIT, "Node %d is undead.\n",
ni[x].ni_status.ps_nodeid);
- log_printf(LOG_ALERT,
+ logt_print(LOG_ALERT,
"Writing eviction notice for node %d\n",
ni[x].ni_status.ps_nodeid);
qd_write_status(ctx, ni[x].ni_status.ps_nodeid,
@@ -308,7 +327,7 @@ check_transitions(qd_ctx *ctx, node_info_t *ni, int max, memb_mask_t mask)
/* XXX Need to fence it again */
if (ctx->qc_flags & RF_ALLOW_KILL) {
- log_printf(LOG_DEBUG, "Telling CMAN to "
+ logt_print(LOG_DEBUG, "Telling CMAN to "
"kill the node\n");
cman_kill_node(ctx->qc_cman_admin,
ni[x].ni_status.ps_nodeid);
@@ -331,7 +350,7 @@ check_transitions(qd_ctx *ctx, node_info_t *ni, int max, memb_mask_t mask)
right now.
*/
ni[x].ni_state = S_RUN;
- log_printf(LOG_DEBUG, "Node %d is UP\n",
+ logt_print(LOG_DEBUG, "Node %d is UP\n",
ni[x].ni_status.ps_nodeid);
ni[x].ni_incarnation =
ni[x].ni_status.ps_incarnation;
@@ -348,7 +367,7 @@ check_transitions(qd_ctx *ctx, node_info_t *ni, int max, memb_mask_t mask)
*/
if (ni[x].ni_state == S_RUN &&
ni[x].ni_status.ps_state == S_MASTER) {
- log_printf(LOG_INFO, "Node %d is the master\n",
+ logt_print(LOG_INFO, "Node %d is the master\n",
ni[x].ni_status.ps_nodeid);
ni[x].ni_state = S_MASTER;
if (mask)
@@ -409,7 +428,7 @@ master_exists(qd_ctx *ctx, node_info_t *ni, int max, int *low_id, int *count)
/* Look for dead master */
if (ni[x].ni_state < S_RUN &&
ni[x].ni_status.ps_state == S_MASTER) {
- log_printf(LOG_DEBUG,
+ logt_print(LOG_DEBUG,
"Node %d is marked master, but is dead.\n",
ni[x].ni_status.ps_nodeid);
continue;
@@ -447,28 +466,28 @@ quorum_init(qd_ctx *ctx, node_info_t *ni, int max, struct h_data *h, int maxh)
{
int x = 0, score, maxscore, score_req = 0;
- log_printf(LOG_INFO, "Quorum Daemon Initializing\n");
+ logt_print(LOG_INFO, "Quorum Daemon Initializing\n");
if (mlockall(MCL_CURRENT|MCL_FUTURE) != 0) {
- log_printf(LOG_ERR, "Unable to mlockall()\n");
+ logt_print(LOG_ERR, "Unable to mlockall()\n");
}
if (qdisk_validate(ctx->qc_device) < 0)
return -1;
if (qdisk_open(ctx->qc_device, &ctx->qc_disk) < 0) {
- log_printf(LOG_CRIT, "Failed to open %s: %s\n", ctx->qc_device,
+ logt_print(LOG_CRIT, "Failed to open %s: %s\n", ctx->qc_device,
strerror(errno));
return -1;
}
- log_printf(LOG_DEBUG, "I/O Size: %lu Page Size: %lu\n",
+ logt_print(LOG_DEBUG, "I/O Size: %lu Page Size: %lu\n",
(unsigned long)ctx->qc_disk.d_blksz, (unsigned long)ctx->qc_disk.d_pagesz);
if (h && maxh) {
start_score_thread(ctx, h, maxh);
} else {
- log_printf(LOG_DEBUG, "Permanently setting score to 1/1\n");
+ logt_print(LOG_DEBUG, "Permanently setting score to 1/1\n");
fudge_scoring();
}
@@ -476,7 +495,7 @@ quorum_init(qd_ctx *ctx, node_info_t *ni, int max, struct h_data *h, int maxh)
ctx->qc_status = S_INIT;
if (qd_write_status(ctx, ctx->qc_my_id,
S_INIT, NULL, NULL, NULL) != 0) {
- log_printf(LOG_CRIT, "Could not initialize status block!\n");
+ logt_print(LOG_CRIT, "Could not initialize status block!\n");
return -1;
}
@@ -486,7 +505,7 @@ quorum_init(qd_ctx *ctx, node_info_t *ni, int max, struct h_data *h, int maxh)
if (qd_write_status(ctx, ctx->qc_my_id,
S_INIT, NULL, NULL, NULL) != 0) {
- log_printf(LOG_CRIT, "Initialization failed\n");
+ logt_print(LOG_CRIT, "Initialization failed\n");
return -1;
}
@@ -500,10 +519,10 @@ quorum_init(qd_ctx *ctx, node_info_t *ni, int max, struct h_data *h, int maxh)
}
get_my_score(&score, &maxscore);
- log_printf(LOG_INFO, "Initial score %d/%d\n", score, maxscore);
+ logt_print(LOG_INFO, "Initial score %d/%d\n", score, maxscore);
if ((ctx->qc_flags & RF_STOP_CMAN) && (score < score_req))
return -1;
- log_printf(LOG_INFO, "Initialization complete\n");
+ logt_print(LOG_INFO, "Initialization complete\n");
return 0;
}
@@ -779,7 +798,7 @@ set_priority(int queue, int prio)
}
if (ret < 0 && errno) {
- log_printf(LOG_WARNING, "set_priority [%s] failed: %s\n", func,
+ logt_print(LOG_WARNING, "set_priority [%s] failed: %s\n", func,
strerror(errno));
}
}
@@ -824,8 +843,7 @@ process_cman_event(cman_handle_t handle, void *private, int reason, int arg)
_running = 0;
break;
case CMAN_REASON_CONFIG_UPDATE:
- get_config_data(ctx, NULL, 0, NULL,
- !!(ctx->qc_flags&RF_DEBUG), 1);
+ get_config_data(ctx, NULL, 0, NULL);
break;
case CMAN_REASON_PORTCLOSED:
break;
@@ -855,7 +873,7 @@ quorum_loop(qd_ctx *ctx, node_info_t *ni, int max)
get_my_score(&score, &score_max);
if (score_max < ctx->qc_scoremin) {
- log_printf(LOG_WARNING, "Minimum score (%d) is impossible to "
+ logt_print(LOG_WARNING, "Minimum score (%d) is impossible to "
"achieve (heuristic total = %d)\n",
ctx->qc_scoremin, score_max);
}
@@ -863,8 +881,7 @@ quorum_loop(qd_ctx *ctx, node_info_t *ni, int max)
_running = 1;
while (_running) {
if (_reconfig) {
- get_config_data(ctx, NULL, 0, NULL,
- !!(ctx->qc_flags&RF_DEBUG), 1);
+ get_config_data(ctx, NULL, 0, NULL);
_reconfig = 0;
}
@@ -891,7 +908,7 @@ quorum_loop(qd_ctx *ctx, node_info_t *ni, int max)
if (score < score_req) {
clear_bit(mask, (ctx->qc_my_id-1), sizeof(mask));
if (ctx->qc_status > S_NONE) {
- log_printf(LOG_NOTICE,
+ logt_print(LOG_NOTICE,
"Score insufficient for master "
"operation (%d/%d; required=%d); "
"downgrading\n",
@@ -901,7 +918,7 @@ quorum_loop(qd_ctx *ctx, node_info_t *ni, int max)
++msg.m_seq;
bid_pending = 0;
if (cman_wait(ctx->qc_cman_user, NULL) < 0) {
- log_printf(LOG_ERR, "cman: %s\n",
+ logt_print(LOG_ERR, "cman: %s\n",
strerror(errno));
} else {
cman_poll_quorum_device(ctx->qc_cman_admin, 0);
@@ -912,7 +929,7 @@ quorum_loop(qd_ctx *ctx, node_info_t *ni, int max)
} else {
set_bit(mask, (ctx->qc_my_id-1), sizeof(mask));
if (ctx->qc_status == S_NONE) {
- log_printf(LOG_NOTICE,
+ logt_print(LOG_NOTICE,
"Score sufficient for master "
"operation (%d/%d; required=%d); "
"upgrading\n",
@@ -931,7 +948,7 @@ quorum_loop(qd_ctx *ctx, node_info_t *ni, int max)
/* Resolve master conflict, if one exists */
if (count >= 1 && ctx->qc_status == S_MASTER &&
ctx->qc_master != ctx->qc_my_id) {
- log_printf(LOG_WARNING, "Master conflict: abdicating\n");
+ logt_print(LOG_WARNING, "Master conflict: abdicating\n");
/* Handle just like a recent upgrade */
ctx->qc_status = S_RUN;
@@ -954,7 +971,7 @@ quorum_loop(qd_ctx *ctx, node_info_t *ni, int max)
upgraded.
*/
- log_printf(LOG_DEBUG,"Making bid for master\n");
+ logt_print(LOG_DEBUG,"Making bid for master\n");
msg.m_msg = M_BID;
++msg.m_seq;
bid_pending = 1;
@@ -981,7 +998,7 @@ quorum_loop(qd_ctx *ctx, node_info_t *ni, int max)
if (bid_pending < (ctx->qc_master_wait))
break;
- log_printf(LOG_INFO,
+ logt_print(LOG_INFO,
"Assuming master role\n");
ctx->qc_status = S_MASTER;
case 2:
@@ -997,7 +1014,7 @@ quorum_loop(qd_ctx *ctx, node_info_t *ni, int max)
/* We think we're master, but someone else claims
that they are master. */
- log_printf(LOG_CRIT,
+ logt_print(LOG_CRIT,
"A master exists, but it's not me?!\n");
/* XXX Handle this how? Should not happen*/
/* reboot(RB_AUTOBOOT); */
@@ -1009,9 +1026,9 @@ quorum_loop(qd_ctx *ctx, node_info_t *ni, int max)
We can't be the master unless we score high
enough on our heuristics. */
if (cman_wait(ctx->qc_cman_user, NULL) < 0) {
- log_printf(LOG_ERR, "cman_dispatch: %s\n",
+ logt_print(LOG_ERR, "cman_dispatch: %s\n",
strerror(errno));
- log_printf(LOG_ERR,
+ logt_print(LOG_ERR,
"Halting qdisk operations\n");
return -1;
}
@@ -1030,9 +1047,9 @@ quorum_loop(qd_ctx *ctx, node_info_t *ni, int max)
ctx->qc_my_id-1,
sizeof(memb_mask_t))) {
if (cman_wait(ctx->qc_cman_user, NULL) < 0) {
- log_printf(LOG_ERR, "cman_dispatch: %s\n",
+ logt_print(LOG_ERR, "cman_dispatch: %s\n",
strerror(errno));
- log_printf(LOG_ERR,
+ logt_print(LOG_ERR,
"Halting qdisk operations\n");
return -1;
}
@@ -1044,7 +1061,7 @@ quorum_loop(qd_ctx *ctx, node_info_t *ni, int max)
/* Write out our status */
if (qd_write_status(ctx, ctx->qc_my_id, ctx->qc_status,
&msg, mask, master_mask) != 0) {
- log_printf(LOG_ERR, "Error writing to quorum disk\n");
+ logt_print(LOG_ERR, "Error writing to quorum disk\n");
errors++; /* this value isn't really used
at this point */
}
@@ -1062,7 +1079,7 @@ quorum_loop(qd_ctx *ctx, node_info_t *ni, int max)
*/
if (_cmp_tv(&maxtime, &diff) == 1 &&
ctx->qc_flags & RF_PARANOID) {
- log_printf(LOG_EMERG, "Failed to complete a cycle within "
+ logt_print(LOG_EMERG, "Failed to complete a cycle within "
"%d second%s (%d.%06d) - REBOOTING\n",
(int)maxtime.tv_sec,
maxtime.tv_sec==1?"":"s",
@@ -1081,7 +1098,7 @@ quorum_loop(qd_ctx *ctx, node_info_t *ni, int max)
if (_cmp_tv(&diff, &interval) == 1) {
_diff_tv(&sleeptime, &diff, &interval);
} else {
- log_printf(LOG_WARNING, "qdisk cycle took more "
+ logt_print(LOG_WARNING, "qdisk cycle took more "
"than %d second%s to complete (%d.%06d)\n",
ctx->qc_interval, ctx->qc_interval==1?"":"s",
(int)diff.tv_sec, (int)diff.tv_usec);
@@ -1091,7 +1108,7 @@ quorum_loop(qd_ctx *ctx, node_info_t *ni, int max)
if (errors && ctx->qc_max_error_cycles) {
++error_cycles;
if (error_cycles >= ctx->qc_max_error_cycles) {
- log_printf(LOG_ALERT,
+ logt_print(LOG_ALERT,
"Too many I/O errors; giving up.\n");
_running = 0;
}
@@ -1118,171 +1135,64 @@ quorum_logout(qd_ctx *ctx)
/* Write out our status */
if (qd_write_status(ctx, ctx->qc_my_id, S_NONE,
NULL, NULL, NULL) != 0) {
- log_printf(LOG_WARNING,
+ logt_print(LOG_WARNING,
"Error writing to quorum disk during logout\n");
}
return 0;
}
+void
+conf_logging(int debug, int logmode, int facility, int loglevel,
+ int filelevel, char *fname)
+{
+ static int _log_config = 0;
+
+ if (debug)
+ _debug |= DEBUG_CONF;
+ else
+ _debug &= ~DEBUG_CONF;
+ if (_debug)
+ loglevel = LOG_DEBUG;
+ if (_foreground)
+ logmode |= LOG_MODE_OUTPUT_STDERR;
+ if (!_log_config)
+ logt_init(DAEMON_NAME, logmode, facility, loglevel,
+ filelevel, fname);
+ else
+ logt_conf(DAEMON_NAME, logmode, facility, loglevel,
+ filelevel, fname);
+ _log_config = 1;
+}
+
+
/**
Grab logsys configuration data from libccs
*/
static int
-get_logsys_config_data(int *debug)
+get_log_config_data(int ccsfd)
{
- int ccsfd = -1, loglevel = SYSLOGLEVEL, facility = SYSLOGFACILITY;
- char *val = NULL, *error = NULL;
- unsigned int logmode;
- int global_debug = 0;
+ char fname[PATH_MAX];
+ int debug, logmode, facility, loglevel, filelevel, need_close = 0;
- log_printf(LOG_DEBUG, "Loading logsys configuration information\n");
+ logt_print(LOG_DEBUG, "Loading logsys configuration information\n");
- ccsfd = ccs_connect();
if (ccsfd < 0) {
- log_printf(LOG_CRIT, "Connection to CCSD failed; cannot start\n");
- return -1;
- }
-
- logmode = logsys_config_mode_get();
-
- if (!*debug) {
- if (ccs_get(ccsfd, "/cluster/logging/@debug", &val) == 0) {
- if(!strcmp(val, "on")) {
- global_debug = 1;
- } else
- if(!strcmp(val, "off")) {
- global_debug = 0;
- } else
- log_printf(LOG_ERR, "global debug: unknown value\n");
- free(val);
- val = NULL;
- }
-
- if (ccs_get(ccsfd, "/cluster/logging/logger_subsys[@subsys=\"QDISK\"]/@debug", &val) == 0) {
- if(!strcmp(val, "on")) {
- *debug = 1;
- } else
- if(!strcmp(val, "off")) { /* debug from cmdline/envvars override config */
- *debug = 0;
- } else
- log_printf(LOG_ERR, "subsys debug: unknown value: %s\n", val);
- free(val);
- val = NULL;
- } else
- *debug = global_debug; /* global debug overrides subsystem only if latter is not specified */
-
- if (ccs_get(ccsfd, "/cluster/logging/logger_subsys[@subsys=\"QDISK\"]/@syslog_level", &val) == 0) {
- loglevel = logsys_priority_id_get (val);
- if (loglevel < 0)
- loglevel = SYSLOGLEVEL;
-
- if (!*debug) {
- if (loglevel == LOG_LEVEL_DEBUG)
- *debug = 1;
-
- logsys_config_priority_set (loglevel);
- }
-
- free(val);
- val = NULL;
- } else
- if (ccs_get(ccsfd, "/cluster/quorumd/@log_level", &val) == 0) { /* check backward compat options */
- loglevel = logsys_priority_id_get (val);
- if (loglevel < 0)
- loglevel = SYSLOGLEVEL;
-
- log_printf(LOG_ERR, "<quorumd log_level=\"%s\".. option is depracated\n", val);
-
- if (!*debug) {
- if (loglevel == LOG_LEVEL_DEBUG)
- *debug = 1;
-
- logsys_config_priority_set (loglevel);
- }
-
- free(val);
- val = NULL;
- }
- } else
- logsys_config_priority_set (LOG_LEVEL_DEBUG);
-
- if (ccs_get(ccsfd, "/cluster/logging/@to_stderr", &val) == 0) {
- if(!strcmp(val, "yes")) {
- logmode |= LOG_MODE_OUTPUT_STDERR;
- } else
- if(!strcmp(val, "no")) {
- logmode &= ~LOG_MODE_OUTPUT_STDERR;
- } else
- log_printf(LOG_ERR, "to_stderr: unknown value\n");
- free(val);
- val = NULL;
- }
-
- if (ccs_get(ccsfd, "/cluster/logging/@to_syslog", &val) == 0) {
- if(!strcmp(val, "yes")) {
- logmode |= LOG_MODE_OUTPUT_SYSLOG_THREADED;
- } else
- if(!strcmp(val, "no")) {
- logmode &= ~LOG_MODE_OUTPUT_SYSLOG_THREADED;
- } else
- log_printf(LOG_ERR, "to_syslog: unknown value\n");
- free(val);
- val = NULL;
- }
-
- if (ccs_get(ccsfd, "/cluster/logging/@to_file", &val) == 0) {
- if(!strcmp(val, "yes")) {
- logmode |= LOG_MODE_OUTPUT_FILE;
- } else
- if(!strcmp(val, "no")) {
- logmode &= ~LOG_MODE_OUTPUT_FILE;
- } else
- log_printf(LOG_ERR, "to_file: unknown value\n");
- free(val);
- val = NULL;
- }
-
- if (ccs_get(ccsfd, "/cluster/logging/@logfile", &val) == 0) {
- if(logsys_config_file_set(&error, val))
- log_printf(LOG_ERR, "logfile: unable to open %s for logging\n", val);
- free(val);
- val = NULL;
- } else
- log_printf(LOG_DEBUG, "logfile: use default built-in log file: %s\n", LOGDIR "/qdisk.log");
-
- if (ccs_get(ccsfd, "/cluster/logging/@syslog_facility", &val) == 0) {
- facility = logsys_facility_id_get (val);
- if (facility < 0) {
- log_printf(LOG_ERR, "syslog_facility: unknown value\n");
- facility = SYSLOGFACILITY;
- }
-
- logsys_config_facility_set ("QDISK", facility);
- free(val);
- } else
- if (ccs_get(ccsfd, "/cluster/quorumd/@log_facility", &val) == 0) {
- facility = logsys_facility_id_get (val);
- if (facility < 0) {
- log_printf(LOG_ERR, "syslog_facility: unknown value\n");
- facility = SYSLOGFACILITY;
+ ccsfd = ccs_connect();
+ if (ccsfd < 0) {
+ logt_print(LOG_CRIT, "Connection to CCSD failed; cannot start\n");
+ return -1;
}
-
- log_printf(LOG_ERR, "<quorumd log_facility=\"%s\".. option is depracated\n", val);
-
- logsys_config_facility_set ("QDISK", facility);
- free(val);
- val = NULL;
+ need_close = 1;
}
- if(logmode & LOG_MODE_BUFFER_BEFORE_CONFIG) {
- log_printf(LOG_DEBUG, "logsys config enabled from get_logsys_config_data\n");
- logmode &= ~LOG_MODE_BUFFER_BEFORE_CONFIG;
- logmode |= LOG_MODE_FLUSH_AFTER_CONFIG;
- logsys_config_mode_set (logmode);
- }
+ snprintf(fname, sizeof(fname)-1, LOGDIR "/qdisk.log");
+ ccs_read_logging(ccsfd, (char *)"QDISKD", &debug, &logmode,
+ &facility, &loglevel, &filelevel, (char *)fname);
+ conf_logging(debug, logmode, facility, loglevel, filelevel, fname);
- ccs_disconnect(ccsfd);
+ if (need_close)
+ ccs_disconnect(ccsfd);
return 0;
}
@@ -1291,25 +1201,23 @@ get_logsys_config_data(int *debug)
Grab all our configuration data from libccs
*/
static int
-get_config_data(qd_ctx *ctx, struct h_data *h, int maxh,
- int *cfh, int debug, int trylater)
+get_config_data(qd_ctx *ctx, struct h_data *h, int maxh, int *cfh)
{
int ccsfd = -1;
char query[256];
char *val;
- log_printf(LOG_DEBUG, "Loading configuration information\n");
+ logt_print(LOG_DEBUG, "Loading configuration information\n");
- if (trylater)
- if(get_logsys_config_data(&debug))
- return -1;
ccsfd = ccs_connect();
if (ccsfd < 0) {
- log_printf(LOG_CRIT, "Connection to CCSD failed; cannot start\n");
+ logt_print(LOG_CRIT, "Connection to CCSD failed; cannot start\n");
return -1;
}
+ get_log_config_data(ccsfd);
+
/* Initialize defaults if we are not reconfiguring */
if (ctx->qc_config == 0) {
ctx->qc_interval = 1;
@@ -1317,7 +1225,7 @@ get_config_data(qd_ctx *ctx, struct h_data *h, int maxh,
ctx->qc_scoremin = 0;
ctx->qc_flags = RF_REBOOT | RF_ALLOW_KILL | RF_UPTIME;
/* | RF_STOP_CMAN;*/
- if (debug)
+ if (_debug)
ctx->qc_flags |= RF_DEBUG;
ctx->qc_sched = SCHED_RR;
@@ -1350,7 +1258,7 @@ get_config_data(qd_ctx *ctx, struct h_data *h, int maxh,
ctx->qc_sched = SCHED_OTHER;
break;
default:
- log_printf(LOG_WARNING, "Invalid scheduling queue '%s'\n",
+ logt_print(LOG_WARNING, "Invalid scheduling queue '%s'\n",
val);
break;
}
@@ -1541,11 +1449,11 @@ get_config_data(qd_ctx *ctx, struct h_data *h, int maxh,
*cfh = configure_heuristics(ccsfd, h, maxh);
- log_printf(LOG_DEBUG,
+ logt_print(LOG_DEBUG,
"Quorum Daemon: %d heuristics, %d interval, %d tko, %d votes\n",
*cfh, ctx->qc_interval, ctx->qc_tko, ctx->qc_votes);
out:
- log_printf(LOG_DEBUG, "Run Flags: %08x\n", ctx->qc_flags);
+ logt_print(LOG_DEBUG, "Run Flags: %08x\n", ctx->qc_flags);
ccs_disconnect(ccsfd);
@@ -1559,10 +1467,10 @@ check_stop_cman(qd_ctx *ctx)
if (!(ctx->qc_flags & RF_STOP_CMAN))
return;
- log_printf(LOG_WARNING, "Telling CMAN to leave the cluster; qdisk is not"
+ logt_print(LOG_WARNING, "Telling CMAN to leave the cluster; qdisk is not"
" available\n");
if (cman_shutdown(ctx->qc_cman_admin, 0) < 0) {
- log_printf(LOG_CRIT, "Could not leave the cluster - rebooting\n");
+ logt_print(LOG_CRIT, "Could not leave the cluster - rebooting\n");
sleep(5);
if (ctx->qc_flags & RF_DEBUG)
return;
@@ -1571,23 +1479,24 @@ check_stop_cman(qd_ctx *ctx)
}
+#define logt_print_once(level, fmt, args...) \
+do { static int _logged=0; if (!_logged) { _logged=1; logt_print(level, fmt, ##args); } } while(0)
+
+
int
main(int argc, char **argv)
{
cman_node_t me;
- int cfh = 0, rv, forked = 0, nfd = -1, ret = -1;
+ int cfh = 0, rv, nfd = -1, ret = -1, active;
qd_ctx ctx;
cman_handle_t ch_admin = NULL;
cman_handle_t ch_user = NULL;
node_info_t ni[MAX_NODES_DISK];
struct h_data h[10];
- int debug = 0, foreground = 0, trylater = 0;
char device[128];
pid_t pid;
quorum_header_t qh;
- logsys_init("QDISK", LOG_MODE_OUTPUT_STDERR | LOG_MODE_OUTPUT_SYSLOG_THREADED | LOG_MODE_OUTPUT_FILE | LOG_MODE_FILTER_DEBUG_FROM_SYSLOG | LOG_MODE_BUFFER_BEFORE_CONFIG, SYSLOGFACILITY, SYSLOGLEVEL, LOGDIR "/qdisk.log");
-
if (check_process_running(argv[0], &pid) && pid !=getpid()) {
printf("QDisk services already running\n");
return 0;
@@ -1596,10 +1505,10 @@ main(int argc, char **argv)
while ((rv = getopt(argc, argv, "fdQs")) != EOF) {
switch (rv) {
case 'd':
- debug = 1;
+ _debug = DEBUG_CMDLINE;
break;
case 'f':
- foreground = 1;
+ _foreground = 1;
break;
case 'Q':
/* Make qdisk very quiet */
@@ -1618,55 +1527,49 @@ main(int argc, char **argv)
}
if(getenv("QDISK_DEBUGLOG"))
- debug = 1;
-
- if(debug)
- logsys_config_priority_set (LOG_LEVEL_DEBUG);
+ _debug = 1;
- trylater = get_logsys_config_data(&debug);
+ if (!_foreground && daemon_init(argv[0]) < 0) {
+ fprintf(stderr, "Could not fork: %s\n", strerror(errno));
+ goto out;
+ }
- if (trylater)
- logsys_config_mode_set (LOG_MODE_OUTPUT_STDERR | LOG_MODE_OUTPUT_SYSLOG_THREADED | LOG_MODE_OUTPUT_FILE | LOG_MODE_FLUSH_AFTER_CONFIG);
+ conf_logging(0, LOG_MODE_OUTPUT_SYSLOG, SYSLOGFACILITY,
+ SYSLOGLEVEL, 0, NULL);
- ch_admin = cman_admin_init(NULL);
+ while (_running && (ch_admin = cman_admin_init(NULL)) == NULL) {
+ logt_print_once(LOG_INFO, "Waiting for CMAN to start\n");
+ sleep(1);
+ }
- if (!ch_admin) {
- if (!foreground && !forked) {
- if (daemon_init(argv[0]) < 0)
- goto out;
- else
- forked = 1;
+ while (_running && (active = cman_is_active(ch_admin)) <= 0) {
+ logt_print_once(LOG_INFO,
+ "Waiting for CMAN to become active\n");
+ if (active < 0) {
+ logt_print(LOG_CRIT, "cman_is_active: %s\n",
+ strerror(errno));
+ goto out;
}
-
- log_printf(LOG_INFO, "Waiting for CMAN to start\n");
-
- do {
- sleep(5);
- ch_admin = cman_admin_init(NULL);
- } while (!ch_admin);
+ sleep(1);
}
+ if (!_running)
+ goto out;
+
/* For cman notifications we need two sockets - one for events,
one for config change callbacks */
ch_user = cman_init(&ctx);
-
if (cman_start_notification(ch_user, process_cman_event) != 0) {
- log_printf(LOG_CRIT, "Could not register with CMAN: %s\n",
+ logt_print(LOG_CRIT, "Could not register with CMAN: %s\n",
strerror(errno));
- cman_finish(ch_user);
- cman_finish(ch_admin);
- return -1;
+ goto out;
}
memset(&me, 0, sizeof(me));
- while (cman_get_node(ch_admin, CMAN_NODEID_US, &me) < 0) {
- if (!foreground && !forked) {
- if (daemon_init(argv[0]) < 0)
- goto out;
- else
- forked = 1;
- }
- sleep(5);
+ if (cman_get_node(ch_admin, CMAN_NODEID_US, &me) < 0) {
+ logt_print(LOG_CRIT, "Could not determine local node ID: %s\n",
+ strerror(errno));
+ goto out;
}
qd_init(&ctx, ch_admin, ch_user, me.cn_nodeid);
@@ -1674,9 +1577,10 @@ main(int argc, char **argv)
signal(SIGINT, int_handler);
signal(SIGTERM, int_handler);
signal(SIGHUP, hup_handler);
+ signal(SIGUSR1, usr1_handler);
- if (get_config_data(&ctx, h, 10, &cfh, debug, trylater) < 0) {
- log_printf(LOG_CRIT, "Configuration failed\n");
+ if (get_config_data(&ctx, h, 10, &cfh) < 0) {
+ logt_print(LOG_CRIT, "Configuration failed\n");
check_stop_cman(&ctx);
goto out;
}
@@ -1684,24 +1588,24 @@ main(int argc, char **argv)
if (ctx.qc_label) {
ret = find_partitions(ctx.qc_label, device, sizeof(device), 0);
if (ret < 0) {
- log_printf(LOG_CRIT, "Unable to match label"
+ logt_print(LOG_CRIT, "Unable to match label"
" '%s' to any device\n",
ctx.qc_label);
check_stop_cman(&ctx);
goto out;
}
- /* XXX Multiple matches: do we care? */
if (ctx.qc_device)
free(ctx.qc_device);
-
ctx.qc_device = strdup(device);
- log_printf(LOG_INFO, "Quorum Partition: %s Label: %s\n",
+ logt_print(LOG_INFO, "Quorum Partition: %s Label: %s\n",
ctx.qc_device, ctx.qc_label);
+
+ logt_print(LOG_NOTICE, "WTF\n");
} else if (ctx.qc_device) {
if (check_device(ctx.qc_device, NULL, &qh, 0) != 0) {
- log_printf(LOG_CRIT,
+ logt_print(LOG_CRIT,
"Specified partition %s does not have a "
"qdisk label\n", ctx.qc_device);
check_stop_cman(&ctx);
@@ -1710,7 +1614,7 @@ main(int argc, char **argv)
if (qh.qh_version == VERSION_MAGIC_V2 &&
qh.qh_blksz != qh.qh_kernsz) {
- log_printf(LOG_CRIT,
+ logt_print(LOG_CRIT,
"Specified device %s does not match kernel's "
"reported sector size (%lu != %lu)\n",
ctx.qc_device,
@@ -1721,13 +1625,8 @@ main(int argc, char **argv)
}
}
- if (!foreground && !forked) {
- if (daemon_init(argv[0]) < 0)
- goto out;
- }
-
if (quorum_init(&ctx, ni, MAX_NODES_DISK, h, cfh) < 0) {
- log_printf(LOG_CRIT, "Initialization failed\n");
+ logt_print(LOG_CRIT, "Initialization failed\n");
check_stop_cman(&ctx);
goto out;
}
@@ -1747,7 +1646,7 @@ main(int argc, char **argv)
if ((rv = cman_register_quorum_device(ctx.qc_cman_admin, ctx.qc_device,
ctx.qc_votes)) < 0) {
- log_printf(LOG_CRIT,
+ logt_print(LOG_CRIT,
"Could not register %s with CMAN; "
"return = %d; error = %s\n",
ctx.qc_device, rv, strerror(errno));
@@ -1763,7 +1662,7 @@ out:
cman_finish(ch_admin);
cman_finish(ch_user);
qd_destroy(&ctx);
- logsys_exit();
+ logt_exit();
return ret;
}
diff --git a/cman/qdisk/mkqdisk.c b/cman/qdisk/mkqdisk.c
index e1afe6c..3244feb 100644
--- a/cman/qdisk/mkqdisk.c
+++ b/cman/qdisk/mkqdisk.c
@@ -10,7 +10,7 @@
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
-#include <corosync/engine/logsys.h>
+#include <liblogthread.h>
int
main(int argc, char **argv)
@@ -19,7 +19,7 @@ main(int argc, char **argv)
char *newdev = NULL, *newlabel = NULL;
int rv, verbose_level = 1;
- logsys_init("QDISK", LOG_MODE_OUTPUT_STDERR | LOG_MODE_NOSUBSYS, SYSLOGFACILITY, SYSLOGLEVEL, NULL);
+ logt_init("MKQDISK", LOG_MODE_OUTPUT_STDERR, 0, 0, 0, NULL);
printf("mkqdisk v" RELEASE_VERSION "\n\n");
@@ -30,13 +30,6 @@ main(int argc, char **argv)
switch (rv) {
case 'd':
++verbose_level;
- /* Workaround a bug in logsys new API.
- * logsys segfaults if our first operation is to set the priority
- * because the logsys_config_priority_set is buggy.
- * Temporary use the direct call while fix is applied upstream and propagated
- */
- // logsys_config_priority_set(LOG_LEVEL_DEBUG);
- _logsys_config_priority_set(0, LOG_LEVEL_DEBUG);
break;
}
}
diff --git a/cman/qdisk/proc.c b/cman/qdisk/proc.c
index ae99216..812c69a 100644
--- a/cman/qdisk/proc.c
+++ b/cman/qdisk/proc.c
@@ -9,7 +9,7 @@
#include <platform.h>
#include <stdlib.h>
#include <string.h>
-#include <corosync/engine/logsys.h>
+#include <liblogthread.h>
#include "scandisk.h"
struct device_args {
@@ -34,13 +34,13 @@ check_device(char *device, char *label, quorum_header_t *qh,
ret = qdisk_validate(device);
if (ret < 0) {
- log_printf(LOG_DEBUG, "qdisk_verify");
+ logt_print(LOG_DEBUG, "qdisk_verify");
return -1;
}
ret = qdisk_open(device, &disk);
if (ret < 0) {
- log_printf(LOG_ERR, "qdisk_open");
+ logt_print(LOG_ERR, "qdisk_open");
return -1;
}
@@ -130,17 +130,17 @@ print_status_block(status_block_t *sb)
if (sb->ps_state == S_NONE)
return;
- log_printf(LOG_INFO, "Status block for node %d\n", sb->ps_nodeid);
- log_printf(LOG_INFO, "\tLast updated by node %d\n", sb->ps_updatenode);
- log_printf(LOG_INFO, "\tLast updated on %s", ctime((time_t *)×tamp));
- log_printf(LOG_INFO, "\tState: %s\n", state_str(sb->ps_state));
- log_printf(LOG_INFO, "\tFlags: %04x\n", sb->ps_flags);
- log_printf(LOG_INFO, "\tScore: %d/%d\n", sb->ps_score, sb->ps_scoremax);
- log_printf(LOG_INFO, "\tAverage Cycle speed: %d.%06d seconds\n",
+ logt_print(LOG_INFO, "Status block for node %d\n", sb->ps_nodeid);
+ logt_print(LOG_INFO, "\tLast updated by node %d\n", sb->ps_updatenode);
+ logt_print(LOG_INFO, "\tLast updated on %s", ctime((time_t *)×tamp));
+ logt_print(LOG_INFO, "\tState: %s\n", state_str(sb->ps_state));
+ logt_print(LOG_INFO, "\tFlags: %04x\n", sb->ps_flags);
+ logt_print(LOG_INFO, "\tScore: %d/%d\n", sb->ps_score, sb->ps_scoremax);
+ logt_print(LOG_INFO, "\tAverage Cycle speed: %d.%06d seconds\n",
sb->ps_ca_sec, sb->ps_ca_usec);
- log_printf(LOG_INFO, "\tLast Cycle speed: %d.%06d seconds\n",
+ logt_print(LOG_INFO, "\tLast Cycle speed: %d.%06d seconds\n",
sb->ps_lc_sec, sb->ps_lc_usec);
- log_printf(LOG_INFO, "\tIncarnation: %08x%08x\n",
+ logt_print(LOG_INFO, "\tIncarnation: %08x%08x\n",
(int)(sb->ps_incarnation>>32&0xffffffff),
(int)(sb->ps_incarnation&0xffffffff));
@@ -155,7 +155,7 @@ read_info(char *dev)
status_block_t sb;
if (qdisk_open(dev, &ti) < 0) {
- log_printf(LOG_ERR, "Could not read from %s: %s\n",
+ logt_print(LOG_ERR, "Could not read from %s: %s\n",
dev, strerror(errno));
return;
}
@@ -165,7 +165,7 @@ read_info(char *dev)
if (qdisk_read(&ti,
qdisk_nodeid_offset(x+1, ti.d_blksz),
&sb, sizeof(sb)) < 0) {
- log_printf(LOG_ERR, "Error reading node ID block %d\n",
+ logt_print(LOG_ERR, "Error reading node ID block %d\n",
x+1);
continue;
}
@@ -185,14 +185,14 @@ print_qdisk_info(struct devnode *dn)
time_t timestamp = (time_t)qh->qh_timestamp;
for (dp = dn->devpath; dp; dp = dp->next)
- log_printf(LOG_INFO, "%s:\n", dp->path);
- log_printf(LOG_INFO, "\tMagic: %08x\n", qh->qh_magic);
- log_printf(LOG_INFO, "\tLabel: %s\n", qh->qh_cluster);
- log_printf(LOG_INFO, "\tCreated: %s", ctime(×tamp));
- log_printf(LOG_INFO, "\tHost: %s\n", qh->qh_updatehost);
- log_printf(LOG_INFO, "\tKernel Sector Size: %d\n", qh->qh_kernsz);
+ logt_print(LOG_INFO, "%s:\n", dp->path);
+ logt_print(LOG_INFO, "\tMagic: %08x\n", qh->qh_magic);
+ logt_print(LOG_INFO, "\tLabel: %s\n", qh->qh_cluster);
+ logt_print(LOG_INFO, "\tCreated: %s", ctime(×tamp));
+ logt_print(LOG_INFO, "\tHost: %s\n", qh->qh_updatehost);
+ logt_print(LOG_INFO, "\tKernel Sector Size: %d\n", qh->qh_kernsz);
if (qh->qh_version == VERSION_MAGIC_V2) {
- log_printf(LOG_INFO, "\tRecorded Sector Size: %d\n\n", (int)qh->qh_blksz);
+ logt_print(LOG_INFO, "\tRecorded Sector Size: %d\n\n", (int)qh->qh_blksz);
}
}
diff --git a/cman/qdisk/score.c b/cman/qdisk/score.c
index dc59553..1ba1506 100644
--- a/cman/qdisk/score.c
+++ b/cman/qdisk/score.c
@@ -11,7 +11,7 @@
#include <pthread.h>
#include <string.h>
#include <ccs.h>
-#include <corosync/engine/logsys.h>
+#include <liblogthread.h>
#include <sched.h>
#include <sys/mman.h>
#include "disk.h"
@@ -125,7 +125,7 @@ fork_heuristic(struct h_data *h)
execv("/bin/sh", argv);
- log_printf(LOG_ERR, "Execv failed\n");
+ logt_print(LOG_ERR, "Execv failed\n");
return 0;
}
@@ -141,7 +141,7 @@ total_score(struct h_data *h, int max, int *score, int *maxscore)
*score = 0;
*maxscore = 0;
- log_printf(LOG_DEBUG, "max = %d\n", max);
+ logt_print(LOG_DEBUG, "max = %d\n", max);
/* Allow operation w/o any heuristics */
if (!max) {
*score = *maxscore = 1;
@@ -190,7 +190,7 @@ check_heuristic(struct h_data *h, int block)
/* Returned 0 and was not killed */
if (!h->available) {
h->available = 1;
- log_printf(LOG_INFO, "Heuristic: '%s' UP\n", h->program);
+ logt_print(LOG_INFO, "Heuristic: '%s' UP\n", h->program);
}
h->misses = 0;
return 0;
@@ -199,12 +199,12 @@ miss:
if (h->available) {
h->misses++;
if (h->misses >= h->tko) {
- log_printf(LOG_INFO,
+ logt_print(LOG_INFO,
"Heuristic: '%s' DOWN (%d/%d)\n",
h->program, h->misses, h->tko);
h->available = 0;
} else {
- log_printf(LOG_DEBUG,
+ logt_print(LOG_DEBUG,
"Heuristic: '%s' missed (%d/%d)\n",
h->program, h->misses, h->tko);
}
@@ -303,13 +303,13 @@ configure_heuristics(int ccsfd, struct h_data *h, int max)
h[x].tko = 1;
}
- log_printf(LOG_DEBUG,
+ logt_print(LOG_DEBUG,
"Heuristic: '%s' score=%d interval=%d tko=%d\n",
h[x].program, h[x].score, h[x].interval, h[x].tko);
} while (++x < max);
- log_printf(LOG_DEBUG, "%d heuristics loaded\n", x);
+ logt_print(LOG_DEBUG, "%d heuristics loaded\n", x);
return x;
}
@@ -371,7 +371,7 @@ score_thread_main(void *arg)
free(args->h);
free(args);
- log_printf(LOG_INFO, "Score thread going away\n");
+ logt_print(LOG_INFO, "Score thread going away\n");
return (NULL);
}