POPT_CFLAGS = @POPT_CFLAGS@
POPT_OBJ = @POPT_OBJ@
+PMDA_LIBS = -lpcp -lpcp_pmda
+PMDA_INSTALL = @CTDB_PMDA_INSTALL@
+PMDA_DEST_DIR = /var/lib/pcp/pmdas
+
CFLAGS=-g -I$(srcdir)/include -Iinclude -Ilib -Ilib/util -I$(srcdir) \
-I@tallocdir@ -I@tdbdir@/include -I@libreplacedir@ \
-DVARDIR=\"$(localstatedir)\" -DETCDIR=\"$(etcdir)\" \
tests/bin/ctdb_takeover_tests tests/bin/ctdb_update_record \
@INFINIBAND_BINS@
-BINS = bin/ctdb @CTDB_SCSI_IO@ bin/smnotify bin/ping_pong bin/ltdbtool
+BINS = bin/ctdb @CTDB_SCSI_IO@ bin/smnotify bin/ping_pong bin/ltdbtool @CTDB_PMDA@
+
SBINS = bin/ctdbd
DIRS = lib bin tests/bin
@echo Linking $@
@$(CC) $(CFLAGS) -o $@ utils/ping_pong/ping_pong.o
+bin/pmdactdb: $(CTDB_CLIENT_OBJ) utils/pmda/pmda_ctdb.o
+ @echo Linking $@
+ @$(CC) $(CFLAGS) -o $@ utils/pmda/pmda_ctdb.o $(CTDB_CLIENT_OBJ) $(LIB_FLAGS) $(PMDA_LIBS)
tests/bin/rb_test: $(CTDB_CLIENT_OBJ) tests/src/rb_test.o
@echo Linking $@
tests/bin/ctdb_fetch_lock_once: libctdb/libctdb.a tests/src/ctdb_fetch_lock_once.o
@echo Linking $@
- @$(CC) $(CFLAGS) -o $@ tests/src/ctdb_fetch_lock_once.o libctdb/libctdb.a -ltdb $(LIB_FLAGS)
+ @$(CC) $(CFLAGS) -o $@ tests/src/ctdb_fetch_lock_once.o @TDB_OBJ@ @POPT_OBJ@ libctdb/libctdb.a $(LIB_FLAGS)
tests/bin/ctdb_fetch_readonly_once: $(CTDB_CLIENT_OBJ) tests/src/ctdb_fetch_readonly_once.o
@echo Linking $@
rm -f config.log config.status config.cache config.h
rm -f Makefile
-install: all
+install: all $(PMDA_INSTALL)
mkdir -p $(DESTDIR)$(libdir)/pkgconfig
mkdir -p $(DESTDIR)$(bindir)
mkdir -p $(DESTDIR)$(sbindir)
if [ ! -f $(DESTDIR)$(etcdir)/ctdb/notify.sh ];then ${INSTALLCMD} -m 755 config/notify.sh $(DESTDIR)$(etcdir)/ctdb; fi
if [ ! -f $(DESTDIR)$(etcdir)/ctdb/ctdb-crash-cleanup.sh ];then ${INSTALLCMD} -m 755 config/ctdb-crash-cleanup.sh $(DESTDIR)$(etcdir)/ctdb; fi
+install_pmda:
+ $(INSTALLCMD) -m 755 -d $(PMDA_DEST_DIR)
+ $(INSTALLCMD) -m 755 pmda/Install pmda/Remove $(PMDA_DEST_DIR)
+ $(INSTALLCMD) -m 644 pmda/pmns pmda/domain.h pmda/help pmda/README $(PMDA_DEST_DIR)
+ $(INSTALLCMD) -m 755 bin/pmdactdb $(PMDA_DEST_DIR)
+
test: all
tests/run_tests.sh
/*
this is called in the client, when data comes in from the daemon
*/
-static void ctdb_client_read_cb(uint8_t *data, size_t cnt, void *args)
+void ctdb_client_read_cb(uint8_t *data, size_t cnt, void *args)
{
struct ctdb_context *ctdb = talloc_get_type(args, struct ctdb_context);
struct ctdb_req_header *hdr = (struct ctdb_req_header *)data;
/*
attach to a specific database - client call
*/
-struct ctdb_db_context *ctdb_attach(struct ctdb_context *ctdb, const char *name, bool persistent, uint32_t tdb_flags)
+struct ctdb_db_context *ctdb_attach(struct ctdb_context *ctdb,
+ struct timeval timeout,
+ const char *name,
+ bool persistent,
+ uint32_t tdb_flags)
{
struct ctdb_db_context *ctdb_db;
TDB_DATA data;
ctdb_db->db_id = *(uint32_t *)data.dptr;
talloc_free(data.dptr);
- ret = ctdb_ctrl_getdbpath(ctdb, timeval_current_ofs(2, 0), CTDB_CURRENT_NODE, ctdb_db->db_id, ctdb_db, &ctdb_db->db_path);
+ ret = ctdb_ctrl_getdbpath(ctdb, timeout, CTDB_CURRENT_NODE, ctdb_db->db_id, ctdb_db, &ctdb_db->db_path);
if (ret != 0) {
DEBUG(DEBUG_ERR,("Failed to get dbpath for database '%s'\n", name));
talloc_free(ctdb_db);
/*
startup a client only ctdb context
*/
-struct ctdb_context *ctdb_cmdline_client(struct event_context *ev)
+struct ctdb_context *ctdb_cmdline_client(struct tevent_context *ev,
+ struct timeval req_timeout)
{
struct ctdb_context *ctdb;
char *socket_name;
}
/* get our pnn */
- ctdb->pnn = ctdb_ctrl_getpnn(ctdb, timeval_current_ofs(3, 0), CTDB_CURRENT_NODE);
+ ctdb->pnn = ctdb_ctrl_getpnn(ctdb, req_timeout, CTDB_CURRENT_NODE);
if (ctdb->pnn == (uint32_t)-1) {
DEBUG(DEBUG_CRIT,(__location__ " Failed to get ctdb pnn\n"));
talloc_free(ctdb);
}
+bool ctdb_sys_check_iface_exists(const char *iface)
+{
+ return true;
+}
close(s);
return ret == 0;
}
+
+
}
+bool ctdb_sys_check_iface_exists(const char *iface)
+{
+ int s;
+ struct ifreq ifr;
+
+ s = socket(PF_PACKET, SOCK_RAW, 0);
+ if (s == -1){
+ /* We dont know if the interface exists, so assume yes */
+ DEBUG(DEBUG_CRIT,(__location__ " failed to open raw socket\n"));
+ return true;
+ }
+
+ strncpy(ifr.ifr_name, iface, sizeof(ifr.ifr_name));
+ if (ioctl(s, SIOCGIFINDEX, &ifr) < 0 && errno == ENODEV) {
+ DEBUG(DEBUG_CRIT,(__location__ " interface '%s' not found\n", iface));
+ close(s);
+ return false;
+ }
+ close(s);
+
+ return true;
+}
# above 90%
# CTDB_CHECK_FS_USE="/:90 /var:90"
+# Should CTDB automatically start and stop services when it is told to
+# newly manage or no longer manage them?
+CTDB_SERVICE_AUTOSTARTSTOP=yes
+
#
#
# set any default tuning options for ctdb
fi
}
+ctdb_check_args "$@"
+
case "$1" in
init)
# make sure we have a blank state directory for the scripts to work with
return 1
}
+ctdb_check_args "$@"
+
case "$1" in
#############################
# called when ctdbd starts up
################################################
# called when ctdbd wants to claim an IP address
takeip)
- if [ $# != 4 ]; then
- echo "ERROR: must supply interface, IP and maskbits"
- exit 1
- fi
iface=$2
ip=$3
maskbits=$4
##################################################
# called when ctdbd wants to release an IP address
releaseip)
- if [ $# != 4 ]; then
- echo "ERROR: must supply interface, IP and maskbits"
- exit 1
- fi
-
# releasing an IP is a bit more complex than it seems. Once the IP
# is released, any open tcp connections to that IP on this host will end
# up being stuck. Some of them (such as NFS connections) will be unkillable
##################################################
# called when ctdbd wants to update an IP address
updateip)
- if [ $# != 5 ]; then
- echo "ERROR: must supply old interface, new interface, IP and maskbits"
- exit 1
- fi
-
# moving an IP is a bit more complex than it seems.
# First we drop all traffic on the old interface.
# Then we try to add the ip to the new interface and before
return $?;
}
+ctdb_check_args "$@"
+
case "$1" in
#############################
# called when ctdbd starts up
################################################
# called when ctdbd wants to claim an IP address
takeip)
- if [ $# != 4 ]; then
- echo "must supply interface, IP and maskbits"
- exit 1
- fi
iface=$2
ip=$3
maskbits=$4
################################################
# called when ctdbd wants to claim an IP address
updateip)
- if [ $# != 5 ]; then
- echo "must supply old interface, new interface, IP and maskbits"
- exit 1
- fi
oiface=$2
niface=$3
ip=$4
##################################################
# called when ctdbd wants to release an IP address
releaseip)
- if [ $# != 4 ]; then
- echo "must supply interface, IP and maskbits"
- exit 1
- fi
-
iface=$2
ip=$3
maskbits=$4
[ "$CTDB_NFS_SKIP_SHARE_CHECK" = "yes" ] || {
exportfs -v | grep '^/' |
sed -r -e 's@[[:space:]]+[^[:space:]()]+\([^[:space:]()]+\)$@@' |
+ sort -u |
ctdb_check_directories
} || exit $?
fi
}
+##############################################################
+# check number of args for different events
+ctdb_check_args ()
+{
+ case "$1" in
+ takeip|releaseip)
+ if [ $# != 4 ]; then
+ echo "ERROR: must supply interface, IP and maskbits"
+ exit 1
+ fi
+ ;;
+ updateip)
+ if [ $# != 5 ]; then
+ echo "ERROR: must supply old interface, new interface, IP and maskbits"
+ exit 1
+ fi
+ ;;
+ esac
+}
+
##############################################################
# determine on what type of system (init style) we are running
detect_init_style() {
ctdb_check_tcp_ports_$_c "$@"
case "$?" in
0)
+ _ctdb_check_tcp_common
rm -f "$_ctdb_service_started_file"
return 0
;;
for _p ; do # process each function argument (port)
_cmd="ctdb checktcpport $_p"
_out=$($_cmd 2>&1)
- case "$?" in
+ _ret=$?
+ case "$_ret" in
0)
ctdb_check_tcp_ports_debug="\"$_cmd\" was able to bind to port"
return 1
continue
;;
*)
- ctdb_check_tcp_ports_debug="$_cmd (exited with $?) with output:
+ ctdb_check_tcp_ports_debug="$_cmd (exited with $_ret) with output:
$_out"
# assume not implemented
return 127
ctdb_service_reconfigure ()
{
- echo "Reconfiguring service \"$service_name\"..."
+ echo "Reconfiguring service \"$@\"..."
ctdb_service_unset_reconfigure "$@"
service_reconfigure "$@" || return $?
ctdb_counter_init "$@"
service "${1:-$service_name}" restart
}
-ctdb_service_check_reconfigure ()
+ctdb_reconfigure_try_lock ()
{
- # Only do this for certain events.
- case "$event_name" in
- monitor|ipreallocated) : ;;
- *) return 0
+
+ _ctdb_service_reconfigure_common "$@"
+ _lock="${_d}/reconfigure_lock"
+ touch "$_lock"
+
+ (
+ flock 0
+ # This is overkill but will work if we need to extend this to
+ # allow certain events to run multiple times in parallel
+ # (e.g. takeip) and write multiple PIDs to the file.
+ read _locker_event
+ if [ -n "$_locker_event" ] ; then
+ while read _pid ; do
+ if [ -n "$_pid" -a "$_pid" != $$ ] && \
+ kill -0 "$_pid" 2>/dev/null ; then
+ exit 1
+ fi
+ done
+ fi
+
+ printf "%s\n%s\n" "$event_name" $$ >"$_lock"
+ exit 0
+ ) <"$_lock"
+}
+
+ctdb_replay_monitor_status ()
+{
+ echo "Replaying previous status for this script due to reconfigure..."
+ # Leading colon (':') is missing in some versions...
+ _out=$(ctdb scriptstatus -Y | grep -E "^:?monitor:${script_name}:")
+ # Output looks like this:
+ # :monitor:60.nfs:1:ERROR:1314764004.030861:1314764004.035514:foo bar:
+ # This is the cheapest way of getting fields in the middle.
+ set -- $(IFS=":" ; echo $_out)
+ _code="$3"
+ _status="$4"
+ # The error output field can include colons so we'll try to
+ # preserve them. The weak checking at the beginning tries to make
+ # this work for both broken (no leading ':') and fixed output.
+ _out="${_out%:}"
+ _err_out="${_out#*monitor:${script_name}:*:*:*:*:}"
+ case "$_status" in
+ OK) : ;; # Do nothing special.
+ TIMEDOUT)
+ # Recast this as an error, since we can't exit with the
+ # correct negative number.
+ _code=1
+ _err_out="[Replay of TIMEDOUT scriptstatus - note incorrect return code.] ${_err_out}"
+ ;;
+ DISABLED)
+ # Recast this as an OK, since we can't exit with the
+ # correct negative number.
+ _code=0
+ _err_out="[Replay of DISABLED scriptstatus - note incorrect return code.] ${_err_out}"
+ ;;
+ *) : ;; # Must be ERROR, do nothing special.
esac
+ echo "$_err_out"
+ exit $_code
+}
- if ctdb_service_needs_reconfigure "$@" ; then
- ctdb_service_reconfigure "$@"
+ctdb_service_check_reconfigure ()
+{
+ [ -n "$1" ] || set -- "$service_name"
- # Fall through to non-monitor events.
- [ "$event_name" = "monitor" ] || return 0
+ # We only care about some events in this function. For others we
+ # return now.
+ case "$event_name" in
+ monitor|ipreallocated|reconfigure) : ;;
+ *) return 0 ;;
+ esac
- # We don't want to proceed with the rest of the monitor event
- # here, so we exit. However, if we exit 0 then, if the
- # service was previously broken, we might return a false
- # positive. So we simply retrieve the status of this script
- # from the previous monitor loop and exit with that status.
- ctdb scriptstatus | \
- grep -q -E "^${script_name}[[:space:]]+Status:OK[[:space:]]"
- exit $?
+ if ctdb_reconfigure_try_lock "$@" ; then
+ # No events covered by this function are running, so proceed
+ # with gay abandon.
+ case "$event_name" in
+ reconfigure)
+ (ctdb_service_reconfigure "$@")
+ exit $?
+ ;;
+ ipreallocated)
+ if ctdb_service_needs_reconfigure "$@" ; then
+ ctdb_service_reconfigure "$@"
+ fi
+ ;;
+ monitor)
+ if ctdb_service_needs_reconfigure "$@" ; then
+ ctdb_service_reconfigure "$@"
+ # Given that the reconfigure might not have
+ # resulted in the service being stable yet, we
+ # replay the previous status since that's the best
+ # information we have.
+ ctdb_replay_monitor_status
+ fi
+ ;;
+ esac
+ else
+ # Somebody else is running an event we don't want to collide
+ # with. We proceed with caution.
+ case "$event_name" in
+ reconfigure)
+ # Tell whoever called us to retry.
+ exit 2
+ ;;
+ ipreallocated)
+ # Defer any scheduled reconfigure and just run the
+ # rest of the ipreallocated event, as per the
+ # eventscript. There's an assumption here that the
+ # event doesn't depend on any scheduled reconfigure.
+ # This is true in the current code.
+ return 0
+ ;;
+ monitor)
+ # There is most likely a reconfigure in progress so
+ # the service is possibly unstable. As above, we
+ # defer any scheduled reconfigured. We also replay
+ # the previous monitor status since that's the best
+ # information we have.
+ ctdb_replay_monitor_status
+ ;;
+ esac
fi
}
ctdb_start_stop_service ()
{
+ # Do nothing unless configured to...
+ [ "$CTDB_SERVICE_AUTOSTARTSTOP" = "yes" ] || return 0
+
_service_name="${1:-${service_name}}"
[ "$event_name" = "monitor" ] || return 0
m4_include(lib/util/fault.m4)
AC_CHECK_HEADERS(sched.h)
+AC_CHECK_HEADERS(pcp/pmapi.h pcp/impl.h pcp/pmda.h, [], [],
+[[#ifdef HAVE_PCP_PMAPI_H
+# include <pcp/pmapi.h>
+#endif
+#ifdef HAVE_PCP_IMPL_H
+# include <pcp/impl.h>
+#endif
+]])
+
AC_CHECK_FUNCS(sched_setscheduler)
AC_CHECK_FUNCS(mlockall)
AC_DEFINE(HAVE_SOCK_SIN_LEN,1,[Whether the sockaddr_in struct has a sin_len property])
fi
+if test x"$ac_cv_header_pcp_pmda_h" = x"yes"; then
+ CTDB_PMDA=bin/pmdactdb
+ CTDB_PMDA_INSTALL=install_pmda
+else
+ CTDB_PMDA=
+ CTDB_PMDA_INSTALL=
+fi
+
+
AC_SUBST(EXTRA_OBJ)
AC_SUBST(CTDB_SYSTEM_OBJ)
AC_SUBST(CTDB_SCSI_IO)
AC_SUBST(CTDB_PCAP_LDFLAGS)
+AC_SUBST(CTDB_PMDA)
+AC_SUBST(CTDB_PMDA_INSTALL)
AC_OUTPUT(Makefile ctdb.pc)
*
***/
+/**
+ * ctdb_num_active - get the number of active commands
+ * @ctdb: the ctdb_connection from ctdb_connect.
+ *
+ * This command can be used to find the number of active commands we have
+ * issued. An active command is a command we have queued, or sent
+ * to the ctdb daemon but which we have not yet received a reply to.
+ *
+ * See Also:
+ * ctdb_num_in_flight(), ctdb_num_out_queue()
+ */
+int ctdb_num_active(struct ctdb_connection *ctdb);
+
+/**
+ * ctdb_num_in_flight - get the number of commands in flight.
+ * @ctdb: the ctdb_connection from ctdb_connect.
+ *
+ * This command can be used to find the number of commands we have
+ * sent to the ctdb daemon to which we have not yet received/processed
+ * the reply.
+ *
+ * See Also:
+ * ctdb_num_out_queue(), ctdb_num_active()
+ */
+int ctdb_num_in_flight(struct ctdb_connection *ctdb);
+
+/**
+ * ctdb_num_out_queue - get the number of commands in the out queue
+ * @ctdb: the ctdb_connection from ctdb_connect.
+ *
+ * This command can be used to find the number of commands we have
+ * queued for delivery to the ctdb daemon but have not yet been
+ * written to the domain socket.
+ *
+ * See Also:
+ * ctdb_num_in_flight(), ctdb_num_active()
+ */
+int ctdb_num_out_queue(struct ctdb_connection *ctdb);
+
/**
* ctdb_get_fd - get the filedescriptor to select/poll on
* @ctdb: the ctdb_connection from ctdb_connect.
/*
attach to a ctdb database
*/
-struct ctdb_db_context *ctdb_attach(struct ctdb_context *ctdb, const char *name, bool persistent, uint32_t tdb_flags);
+struct ctdb_db_context *ctdb_attach(struct ctdb_context *ctdb,
+ struct timeval timeout,
+ const char *name,
+ bool persistent,
+ uint32_t tdb_flags);
+
/*
find an attached ctdb_db handle given a name
struct ctdb_db_context *find_ctdb_db(struct ctdb_context *ctdb, uint32_t id);
-struct ctdb_context *ctdb_cmdline_client(struct tevent_context *ev);
+struct ctdb_context *ctdb_cmdline_client(struct tevent_context *ev,
+ struct timeval req_timeout);
struct ctdb_statistics;
int ctdb_ctrl_statistics(struct ctdb_context *ctdb, uint32_t destnode, struct ctdb_statistics *status);
uint32_t deferred_attach_timeout;
uint32_t vacuum_fast_path_count;
uint32_t lcp2_public_ip_assignment;
+ uint32_t allow_client_db_attach;
};
/*
uint32_t recovery_mode;
TALLOC_CTX *tickle_update_context;
TALLOC_CTX *keepalive_ctx;
+ TALLOC_CTX *check_public_ifaces_ctx;
struct ctdb_tunable tunable;
enum ctdb_freeze_mode freeze_mode[NUM_DB_PRIORITIES+1];
struct ctdb_freeze_handle *freeze_handles[NUM_DB_PRIORITIES+1];
void ctdb_recv_raw_pkt(void *p, uint8_t *data, uint32_t length);
int ctdb_socket_connect(struct ctdb_context *ctdb);
+void ctdb_client_read_cb(uint8_t *data, size_t cnt, void *args);
#define CTDB_BAD_REQID ((uint32_t)-1)
uint32_t ctdb_reqid_new(struct ctdb_context *ctdb, void *state);
uint32_t uint16_checksum(uint16_t *data, size_t n);
int ctdb_sys_send_arp(const ctdb_sock_addr *addr, const char *iface);
bool ctdb_sys_have_ip(ctdb_sock_addr *addr);
+bool ctdb_sys_check_iface_exists(const char *iface);
int ctdb_sys_send_tcp(const ctdb_sock_addr *dest,
const ctdb_sock_addr *src,
uint32_t seq, uint32_t ack, int rst);
struct ctdb_log_state *ctdb_fork_with_logging(TALLOC_CTX *mem_ctx,
struct ctdb_context *ctdb,
+ const char *log_prefix,
void (*logfn)(const char *, uint16_t, void *),
void *logfn_private, pid_t *pid);
if (!tevent_timeval_is_zero(&tevent_after_wait_ts)) {
diff = tevent_timeval_until(&tevent_after_wait_ts, &now);
if (diff.tv_sec > 3) {
- tevent_debug(ev, TEVENT_DEBUG_FATAL, __location__
+ tevent_debug(ev, TEVENT_DEBUG_ERROR, __location__
" Handling event took %d seconds!",
(int) diff.tv_sec);
}
return true;
}
+
+int ctdb_num_out_queue(struct ctdb_connection *ctdb)
+{
+ struct ctdb_request *req;
+ int i;
+
+ for (i = 0, req = ctdb->outq; req; req = req->next, i++)
+ ;
+
+ return i;
+}
+
+int ctdb_num_in_flight(struct ctdb_connection *ctdb)
+{
+ struct ctdb_request *req;
+ int i;
+
+ for (i = 0, req = ctdb->doneq; req; req = req->next, i++)
+ ;
+
+ return i;
+}
+
+int ctdb_num_active(struct ctdb_connection *ctdb)
+{
+ return ctdb_num_out_queue(ctdb)
+ + ctdb_num_in_flight(ctdb);
+}
+
%{_libdir}/libctdb.a
%changelog
+* Thu Sep 1 2011 : Version 1.11
+ - Major updates.
* Tue May 25 2010 : Version 1.10
- New version 1.10
* Tue May 25 2010 : Version 1.9
struct ctdb_log_state {
struct ctdb_context *ctdb;
+ const char *prefix;
int fd, pfd;
char buf[1024];
uint16_t buf_used;
const char *buf, unsigned int len)
{
if (script_log_level <= LogLevel) {
- do_debug("%*.*s\n", len, len, buf);
+ if (log != NULL && log->prefix != NULL) {
+ do_debug("%s: %*.*s\n", log->prefix, len, len, buf);
+ } else {
+ do_debug("%*.*s\n", len, len, buf);
+ }
/* log it in the eventsystem as well */
if (log->logfn)
log->logfn(log->buf, len, log->logfn_private);
if (!(flags & EVENT_FD_READ)) {
return;
}
-
+
n = read(log->pfd, &log->buf[log->buf_used],
sizeof(log->buf) - log->buf_used);
if (n > 0) {
*/
struct ctdb_log_state *ctdb_fork_with_logging(TALLOC_CTX *mem_ctx,
struct ctdb_context *ctdb,
+ const char *log_prefix,
void (*logfn)(const char *, uint16_t, void *),
void *logfn_private, pid_t *pid)
{
log = talloc_zero(mem_ctx, struct ctdb_log_state);
CTDB_NO_MEMORY_NULL(ctdb, log);
log->ctdb = ctdb;
+ log->prefix = log_prefix;
log->logfn = logfn;
log->logfn_private = (void *)logfn_private;
struct ctdb_node *node = ctdb->nodes[ctdb->pnn];
struct ctdb_client *client = NULL;
+ if (ctdb->tunable.allow_client_db_attach == 0) {
+ DEBUG(DEBUG_ERR, ("DB Attach to database %s denied by tunable "
+ "AllowClientDBAccess == 0\n", db_name));
+ return -1;
+ }
+
/* dont allow any local clients to attach while we are in recovery mode
* except for the recovery daemon.
* allow all attach from the network since these are always from remote
}
/* attach to it */
- ctdb_db = ctdb_attach(ctdb, name, persistent, 0);
+ ctdb_db = ctdb_attach(ctdb, CONTROL_TIMEOUT(), name, persistent, 0);
if (ctdb_db == NULL) {
DEBUG(DEBUG_ERR,(__location__ " Failed to attach to database '%s'\n", name));
talloc_free(tmp_ctx);
int i;
int ret;
+ tmp = talloc_strdup(vnn, ifaces);
+ for (iface = strtok(tmp, ","); iface; iface = strtok(NULL, ",")) {
+ if (!ctdb_sys_check_iface_exists(iface)) {
+ DEBUG(DEBUG_CRIT,("Interface %s does not exist. Can not add public-address : %s\n", iface, ctdb_addr_to_str(addr)));
+ talloc_free(tmp);
+ return -1;
+ }
+ }
+ talloc_free(tmp);
+
/* Verify that we dont have an entry for this ip yet */
for (vnn=ctdb->vnn;vnn;vnn=vnn->next) {
if (ctdb_same_sockaddr(addr, &vnn->public_address)) {
return 0;
}
+static void ctdb_check_interfaces_event(struct event_context *ev, struct timed_event *te,
+ struct timeval t, void *private_data)
+{
+ struct ctdb_context *ctdb = talloc_get_type(private_data,
+ struct ctdb_context);
+ struct ctdb_vnn *vnn;
+
+ for (vnn=ctdb->vnn;vnn;vnn=vnn->next) {
+ int i;
+
+ for (i=0; vnn->ifaces[i] != NULL; i++) {
+ if (!ctdb_sys_check_iface_exists(vnn->ifaces[i])) {
+ DEBUG(DEBUG_CRIT,("Interface %s does not exist but is used by public ip %s\n",
+ vnn->ifaces[i],
+ ctdb_addr_to_str(&vnn->public_address)));
+ }
+ }
+ }
+
+ event_add_timed(ctdb->ev, ctdb->check_public_ifaces_ctx,
+ timeval_current_ofs(30, 0),
+ ctdb_check_interfaces_event, ctdb);
+}
+
+
+static int ctdb_start_monitoring_interfaces(struct ctdb_context *ctdb)
+{
+ if (ctdb->check_public_ifaces_ctx != NULL) {
+ talloc_free(ctdb->check_public_ifaces_ctx);
+ ctdb->check_public_ifaces_ctx = NULL;
+ }
+
+ ctdb->check_public_ifaces_ctx = talloc_new(ctdb);
+ if (ctdb->check_public_ifaces_ctx == NULL) {
+ ctdb_fatal(ctdb, "failed to allocate context for checking interfaces");
+ }
+
+ event_add_timed(ctdb->ev, ctdb->check_public_ifaces_ctx,
+ timeval_current_ofs(30, 0),
+ ctdb_check_interfaces_event, ctdb);
+
+ return 0;
+}
+
+
/*
setup the public address lists from a file
*/
}
}
+
+ ctdb_start_monitoring_interfaces(ctdb);
+
talloc_free(lines);
return 0;
}
{ "UseStatusEvents", 0, offsetof(struct ctdb_tunable, use_status_events_for_monitoring) },
{ "AllowUnhealthyDBRead", 0, offsetof(struct ctdb_tunable, allow_unhealthy_db_read) },
{ "StatHistoryInterval", 1, offsetof(struct ctdb_tunable, stat_history_interval) },
- { "DeferredAttachTO", 120, offsetof(struct ctdb_tunable, deferred_attach_timeout) }
+ { "DeferredAttachTO", 120, offsetof(struct ctdb_tunable, deferred_attach_timeout) },
+ { "AllowClientDBAttach", 1, offsetof(struct ctdb_tunable, allow_client_db_attach) }
};
/*
return -errno;
}
- if (!ctdb_fork_with_logging(state, ctdb, log_event_script_output,
+ if (!ctdb_fork_with_logging(state, ctdb, current->name, log_event_script_output,
state, &state->child)) {
r = -errno;
close(state->fd[0]);
# Hey Emacs, this is a -*- shell-script -*- !!! :-)
+# Print a message and exit.
+die () { echo "$@" >&2 ; exit 1 ; }
+
# Augment PATH with relevant stubs/ directories. We do this by actually
# setting PATH, and also by setting $EVENTSCRIPTS_PATH and then
# prepending that to $PATH in rc.local to avoid the PATH reset in
elif [ -d "${EVENTSCRIPTS_TESTS_DIR}/etc" ] ; then
CTDB_ETCDIR="${EVENTSCRIPTS_TESTS_DIR}/etc"
else
- echo "Unable to set \$CTDB_ETCDIR" >&2
- exit 1
+ die "Unable to set \$CTDB_ETCDIR"
fi
export CTDB_ETCDIR
elif [ -d "${EVENTSCRIPTS_TESTS_DIR}/etc-ctdb" ] ; then
CTDB_BASE="${EVENTSCRIPTS_TESTS_DIR}/etc-ctdb"
else
- echo "Unable to set \$CTDB_BASE" >&2
- exit 1
+ die "Unable to set \$CTDB_BASE"
fi
export CTDB_BASE
{
for _i ; do
debug "Marking TCP port \"${_i}\" as not listening"
- FAKE_NETSTAT_TCP_LISTEN=$(echo "$FAKE_NETSTAT_TCP_LISTEN" | sed -r -e "s@[[:space:]]*[\.0-9]+:${_i}@@g")
+ FAKE_TCP_LISTEN=$(echo "$FAKE_TCP_LISTEN" | sed -r -e "s@[[:space:]]*[\.0-9]+:${_i}@@g")
done
}
done
}
+setup_nmap_output_filter ()
+{
+ OUT_FILTER="-e 's@^(DEBUG: # Nmap 5.21 scan initiated) .+ (as:)@\1 DATE \2@' -e 's@^(DEBUG: # Nmap done at) .+ (--)@\1 DATE \2@'"
+}
+
######################################################################
# CTDB fakery
export FAKE_CTDB_NODES_DOWN="$EVENTSCRIPTS_TESTS_VAR_DIR/nodes-down"
mkdir -p "$FAKE_CTDB_NODES_DOWN"
rm -f "$FAKE_CTDB_NODES_DOWN"/*
+
+ export FAKE_CTDB_SCRIPTSTATUS="$EVENTSCRIPTS_TESTS_VAR_DIR/scriptstatus"
+ mkdir -p "$FAKE_CTDB_SCRIPTSTATUS"
+ rm -f "$FAKE_CTDB_SCRIPTSTATUS"/*
}
echo "${_addrs%% *}" | sed -r -e 's#(.*)/(.*)@(.*)#\3 \1 \2#g'
}
+ctdb_not_implemented ()
+{
+ export CTDB_NOT_IMPLEMENTED="$1"
+ ctdb_not_implemented="\
+DEBUG: ctdb: command \"$1\" not implemented in stub"
+}
+
+ctdb_fake_scriptstatus ()
+{
+ _code="$1"
+ _status="$2"
+ _err_out="$3"
+
+ _d1=$(date '+%s.%N')
+ _d2=$(date '+%s.%N')
+
+ echo "$_code $_status $_err_out" >"$FAKE_CTDB_SCRIPTSTATUS/$script"
+}
+
######################################################################
# Samba fakery
export CTDB_SAMBA_SKIP_SHARE_CHECK="no"
export CTDB_MANAGED_SERVICES="foo samba winbind bar"
- export FAKE_NETSTAT_TCP_LISTEN="0.0.0.0:445 0.0.0.0:139"
+ export FAKE_TCP_LISTEN="0.0.0.0:445 0.0.0.0:139"
export FAKE_WBINFO_FAIL="no"
+
+ # Some things in 50.samba are backgrounded and waited for. If
+ # we don't sleep at all then timeouts can happen. This avoids
+ # that... :-)
+ export FAKE_SLEEP_FORCE=0.1
else
debug "Marking Samba services as down, not listening and not managed by CTDB"
# Get into known state.
unset CTDB_MANAGES_SAMBA
unset CTDB_MANAGES_WINBIND
- export FAKE_NETSTAT_TCP_LISTEN=""
+ export FAKE_TCP_LISTEN=""
export FAKE_WBINFO_FAIL="yes"
fi
rquotad) _t="1:2" ;;
nlockmgr) _t="3:4" ;;
status) _t="1:1" ;;
- *)
- echo "Internal error - unsupported RPC service \"${_i}\""
- exit 1
+ *) die "Internal error - unsupported RPC service \"${_i}\"" ;;
esac
FAKE_RPCINFO_SERVICES="${FAKE_RPCINFO_SERVICES}${FAKE_RPCINFO_SERVICES:+ }${_i}:${_t}"
setup_vsftpd ()
{
if [ "$1" != "down" ] ; then
- echo "setup_vsftpd up not implemented!!!"
- exit 1
+ die "setup_vsftpd up not implemented!!!"
else
debug "Setting up VSFTPD environment: service down, not managed by CTDB"
setup_httpd ()
{
if [ "$1" != "down" ] ; then
- echo "setup_httpd up not implemented!!!"
- exit 1
+ die "setup_httpd up not implemented!!!"
else
debug "Setting up HTTPD environment: service down, not managed by CTDB"
desc="$1"
_f="$0"
- _f="${_f#./}" # strip leading ./
- _f="${_f#simple/}" # strip leading simple/
- _f="${_f%%/*}" # if subdir, strip off file
- _f="${_f%.sh}" # strip off .sh suffix if any
+ _f="${_f#./}" # strip leading ./
+ _f="${_f#simple/}" # strip leading simple/
+ _f="${_f#multievent/}" # strip leading multievent/
+ _f="${_f%%/*}" # if subdir, strip off file
+ _f="${_f%.sh}" # strip off .sh suffix if any
- # Remaining format should be NN.service.event.NNN:
+ # Remaining format should be NN.service.event.NNN or NN.service.NNN:
_num="${_f##*.}"
_f="${_f%.*}"
- event="${_f##*.}"
- script="${_f%.*}"
+ case "$_f" in
+ *.*.*)
+ script="${_f%.*}"
+ event="${_f##*.}"
+ ;;
+ *.*)
+ script="$_f"
+ unset event
+ ;;
+ *)
+ die "Internal error - unknown testcase filename format"
+ esac
printf "%-14s %-10s %-4s - %s\n\n" "$script" "$event" "$_num" "$desc"
}
if [ -n "$_iteration" ] ; then
cat <<EOF
-##################################################
-##################################################
+==================================================
Iteration $_iteration
EOF
fi
cat <<EOF
-##################################################
+--------------------------------------------------
Output (Exit status: ${_rc}):
-##################################################
+--------------------------------------------------
$_out
EOF
fi
if ! $_passed ; then
cat <<EOF
-##################################################
+--------------------------------------------------
Required output (Exit status: ${required_rc}):
-##################################################
+--------------------------------------------------
$required_output
EOF
fi
if [ "$EVENTSCRIPT_TESTS_VERBOSE" = "yes" ] || ! $_passed ; then
cat <<EOF
-##################################################
+--------------------------------------------------
CTDB_BASE="$CTDB_BASE"
CTDB_ETCDIR="$CTDB_ETCDIR"
ctdb client is "$(which ctdb)"
-##################################################
+--------------------------------------------------
EOF
fi
- echo
-
if $_passed ; then
echo "PASSED"
return 0
else
+ echo
echo "FAILED"
return 1
fi
# useful for debugging.
simple_test ()
{
- echo "Running \"${CTDB_BASE}/events.d/$script $event\""
+ [ -n "$event" ] || die 'simple_test: $event not set'
+
+ echo "Running \"$script $event${1:+ }$*\""
_out=$($EVENTSCRIPTS_TESTS_TRACE "${CTDB_BASE}/events.d/$script" "$event" "$@" 2>&1)
_rc=$?
- if [ "$_out" = "$required_output" -a $_rc = $required_rc ] ; then
+ if [ -n "$OUT_FILTER" ] ; then
+ _fout=$(echo "$_out" | eval sed -r $OUT_FILTER)
+ else
+ _fout="$_out"
+ fi
+
+ if [ "$_fout" = "$required_output" -a $_rc = $required_rc ] ; then
_passed=true
else
_passed=false
result_footer "$_passed"
}
+simple_test_event ()
+{
+ # If something has previously failed then don't continue.
+ : ${_passed:=true}
+ $_passed || return 1
+
+ event="$1" ; shift
+ echo "##################################################"
+ simple_test "$@"
+}
+
# Run an eventscript iteratively.
# - 1st argument is the number of iterations.
# - 2nd argument is something to eval to do setup for every iteration.
# iteration.
iterate_test ()
{
+ [ -n "$event" ] || die 'simple_test: $event not set'
+
args=""
if [ "$1" = "--" ] ; then
shift
_setup_default="$2"
shift 2
- echo "Running $_repeats iterations of \"${CTDB_BASE}/events.d/$script $event\" $args"
+ echo "Running $_repeats iterations of \"$script $event\" $args"
_result=true
_out=$($EVENTSCRIPTS_TESTS_TRACE "${CTDB_BASE}/events.d/$script" "$event" $args 2>&1)
_rc=$?
- if [ "$_out" = "$required_output" -a $_rc = $required_rc ] ; then
+ if [ -n "$OUT_FILTER" ] ; then
+ _fout=$(echo "$_out" | eval sed -r $OUT_FILTER)
+ else
+ _fout="$_out"
+ fi
+
+ if [ "$_fout" = "$required_output" -a $_rc = $required_rc ] ; then
_passed=true
else
_passed=false
--- /dev/null
+../../../../config/ctdb.sysconfig
\ No newline at end of file
--- /dev/null
+#!/bin/sh
+
+. "${EVENTSCRIPTS_TESTS_DIR}/common.sh"
+
+define_test "takeip, removeip"
+
+setup_ctdb
+
+public_address=$(ctdb_get_1_public_address)
+
+ok_null
+
+simple_test_event "takeip" $public_address
+simple_test_event "releaseip" $public_address
--- /dev/null
+#!/bin/sh
+
+. "${EVENTSCRIPTS_TESTS_DIR}/common.sh"
+
+define_test "takeip, ipreallocated -> reconfigure"
+
+setup_nfs
+
+public_address=$(ctdb_get_1_public_address)
+
+ok_null
+
+simple_test_event "takeip" $public_address
+
+ok <<EOF
+Reconfiguring service "nfs"...
+Starting nfslock: OK
+Starting nfs: OK
+EOF
+
+simple_test_event "ipreallocated"
--- /dev/null
+#!/bin/sh
+
+. "${EVENTSCRIPTS_TESTS_DIR}/common.sh"
+
+define_test "takeip, monitor -> reconfigure"
+
+setup_nfs
+
+public_address=$(ctdb_get_1_public_address)
+
+ok_null
+
+simple_test_event "takeip" $public_address
+
+# This currently assumes that ctdb scriptstatus will always return a
+# good status (when replaying). That should change and we will need
+# to split this into 2 tests.
+ok <<EOF
+Reconfiguring service "nfs"...
+Starting nfslock: OK
+Starting nfs: OK
+Replaying previous status for this script due to reconfigure...
+EOF
+
+simple_test_event "monitor"
--- /dev/null
+#!/bin/sh
+
+. "${EVENTSCRIPTS_TESTS_DIR}/common.sh"
+
+define_test "takeip, monitor -> reconfigure, replay error"
+
+setup_nfs
+
+public_address=$(ctdb_get_1_public_address)
+
+err="foo: bar error occurred"
+
+ok_null
+
+simple_test_event "takeip" $public_address
+
+ctdb_fake_scriptstatus 1 "ERROR" "$err"
+
+required_result 1 <<EOF
+Reconfiguring service "nfs"...
+Starting nfslock: OK
+Starting nfs: OK
+Replaying previous status for this script due to reconfigure...
+$err
+EOF
+
+simple_test_event "monitor"
--- /dev/null
+#!/bin/sh
+
+. "${EVENTSCRIPTS_TESTS_DIR}/common.sh"
+
+define_test "takeip, monitor -> reconfigure, replay timedout"
+
+setup_nfs
+
+public_address=$(ctdb_get_1_public_address)
+
+err="waiting, waiting..."
+
+ok_null
+
+simple_test_event "takeip" $public_address
+
+ctdb_fake_scriptstatus -62 "TIMEDOUT" "$err"
+
+required_result 1 <<EOF
+Reconfiguring service "nfs"...
+Starting nfslock: OK
+Starting nfs: OK
+Replaying previous status for this script due to reconfigure...
+[Replay of TIMEDOUT scriptstatus - note incorrect return code.] $err
+EOF
+
+simple_test_event "monitor"
--- /dev/null
+#!/bin/sh
+
+. "${EVENTSCRIPTS_TESTS_DIR}/common.sh"
+
+define_test "takeip, monitor -> reconfigure, replay disabled"
+
+setup_nfs
+
+public_address=$(ctdb_get_1_public_address)
+
+err=""
+
+ok_null
+
+simple_test_event "takeip" $public_address
+
+ctdb_fake_scriptstatus -8 "DISABLED" "$err"
+
+ok <<EOF
+Reconfiguring service "nfs"...
+Starting nfslock: OK
+Starting nfs: OK
+Replaying previous status for this script due to reconfigure...
+[Replay of DISABLED scriptstatus - note incorrect return code.] $err
+EOF
+
+simple_test_event "monitor"
--- /dev/null
+#!/bin/sh
+
+. "${EVENTSCRIPTS_TESTS_DIR}/common.sh"
+
+define_test "reconfigure (synthetic), twice"
+# This checks that the lock is released...
+
+setup_nfs
+
+public_address=$(ctdb_get_1_public_address)
+
+err=""
+
+ok <<EOF
+Reconfiguring service "nfs"...
+Starting nfslock: OK
+Starting nfs: OK
+EOF
+
+simple_test_event "reconfigure"
+simple_test_event "reconfigure"
export EVENTSCRIPT_TESTS_VERBOSE="yes"
shift
;;
+ -T)
+ # This will cause tests to fail but is good for debugging
+ # individual tests when they fail.
+ export EVENTSCRIPTS_TESTS_TRACE="sh -x"
+ shift
+ ;;
-*)
opts="$opts $i"
shift
ok_null
-simple_test $cmd
+simple_test
ok_null
-simple_test $cmd
+simple_test
--- /dev/null
+#!/bin/sh
+
+. "${EVENTSCRIPTS_TESTS_DIR}/common.sh"
+
+define_test "port 139 down, default tcp checker, debug"
+
+# This has to go before the setup, otherwise it will write a dud file.
+export CTDB_DEBUGLEVEL=4
+
+setup_samba
+tcp_port_down 139
+
+required_result 1 <<EOF
+ERROR: samba tcp port 139 is not responding
+DEBUG: "ctdb checktcpport 139" was able to bind to port
+EOF
+
+simple_test
--- /dev/null
+#!/bin/sh
+
+. "${EVENTSCRIPTS_TESTS_DIR}/common.sh"
+
+define_test "port 139 down, ctdb checktcpport not implemented"
+
+# TODO: create nmap stub
+export CTDB_NOT_IMPLEMENTED="checktcpport"
+
+setup_samba
+tcp_port_down 139
+
+required_result 1 "ERROR: samba tcp port 139 is not responding"
+
+simple_test
--- /dev/null
+#!/bin/sh
+
+. "${EVENTSCRIPTS_TESTS_DIR}/common.sh"
+
+define_test "port 139 down, ctdb checktcpport not implemented, debug"
+
+ctdb_not_implemented "checktcpport"
+
+# This has to go before the setup, otherwise it will write a dud file.
+export CTDB_DEBUGLEVEL=4
+
+setup_nmap_output_filter
+
+setup_samba
+tcp_port_down 139
+
+required_result 1 <<EOF
+DEBUG: ctdb_check_ports - checker ctdb not implemented
+DEBUG: output from checker was:
+DEBUG: ctdb checktcpport 445 (exited with 1) with output:
+$ctdb_not_implemented
+ERROR: samba tcp port 139 is not responding
+DEBUG: nmap -n -oG - -PS 127.0.0.1 -p 445,139 shows this output:
+DEBUG: # Nmap 5.21 scan initiated DATE as: nmap -n -oG - -PS 127.0.0.1 -p 445,139
+DEBUG: Host: 127.0.0.1 () Status: Up
+DEBUG: Host: 127.0.0.1 () Ports: 445/open/tcp//microsoft-ds///, 139/closed/tcp//netbios-ssn///
+DEBUG: # Nmap done at DATE -- 1 IP address (1 host up) scanned in 0.04 seconds
+EOF
+
+simple_test
--- /dev/null
+#!/bin/sh
+
+. "${EVENTSCRIPTS_TESTS_DIR}/common.sh"
+
+define_test "port 139 down, ctdb checktcpport/nmap not implemented, debug"
+
+ctdb_not_implemented "checktcpport"
+export FAKE_NMAP_NOT_FOUND="yes"
+
+# This has to go before the setup, otherwise it will write a dud file.
+export CTDB_DEBUGLEVEL=4
+
+setup_nmap_output_filter
+
+setup_samba
+tcp_port_down 139
+
+required_result 1 <<EOF
+DEBUG: ctdb_check_ports - checker ctdb not implemented
+DEBUG: output from checker was:
+DEBUG: ctdb checktcpport 445 (exited with 1) with output:
+$ctdb_not_implemented
+DEBUG: ctdb_check_ports - checker nmap not implemented
+DEBUG: output from checker was:
+DEBUG: sh: nmap: command not found
+ERROR: samba tcp port 139 is not responding
+DEBUG: netstat -l -t -n shows this output:
+DEBUG: Active Internet connections (servers only)
+DEBUG: Proto Recv-Q Send-Q Local Address Foreign Address State
+DEBUG: tcp 0 0 0.0.0.0:445 0.0.0.0:* LISTEN
+EOF
+
+simple_test
--- /dev/null
+#!/bin/sh
+
+. "${EVENTSCRIPTS_TESTS_DIR}/common.sh"
+
+define_test "port 139 down, ctdb checktcpport/nmap/netstat not implemented"
+
+ctdb_not_implemented "checktcpport"
+export FAKE_NMAP_NOT_FOUND="yes"
+export FAKE_NETSTAT_NOT_FOUND="yes"
+
+setup_nmap_output_filter
+
+setup_samba
+tcp_port_down 139
+
+required_result 127 <<EOF
+INTERNAL ERROR: ctdb_check_ports - no working checkers in CTDB_TCP_PORT_CHECKERS="ctdb nmap netstat"
+EOF
+
+simple_test
--- /dev/null
+#!/bin/sh
+
+. "${EVENTSCRIPTS_TESTS_DIR}/common.sh"
+
+define_test "2nd share missing"
+
+setup_nfs
+
+shares_missing "ERROR: nfs directory \"%s\" not available" 2
+
+required_result 1 "$MISSING_SHARES_TEXT"
+
+simple_test
--- /dev/null
+#!/bin/sh
+
+. "${EVENTSCRIPTS_TESTS_DIR}/common.sh"
+
+define_test "2nd share missing, skipping share checks"
+
+setup_nfs
+export CTDB_NFS_SKIP_SHARE_CHECK="yes"
+
+shares_missing "ERROR: nfs directory \"%s\" not available" 2
+
+ok_null
+
+simple_test
prog="ctdb"
+not_implemented_exit_code=1
+
usage ()
{
cat >&2 <<EOF
A fake CTDB stub that prints items depending on the variables
FAKE_CTDB_PNN (default 0) depending on command-line options.
-
-Note that -Y is ignored.
-
EOF
exit 1
}
-# $POSIXLY_CORRECT means that the command passed to onnode can take
-# options and getopt won't reorder things to make them options to this
-# script.
+not_implemented ()
+{
+ echo "${prog}: command \"$1\" not implemented in stub" >&2
+ exit $not_implemented_exit_code
+}
+
+# Don't set $POSIXLY_CORRECT here.
_temp=$(getopt -n "$prog" -o "Yvh" -l help -- "$@") || \
usage
eval set -- "$_temp"
verbose=false
+machine_readable=false
while true ; do
case "$1" in
- -Y) shift ;;
+ -Y) machine_readable=true ; shift ;;
-v) verbose=true ; shift ;;
--) shift ; break ;;
-h|--help|*) usage ;; # * shouldn't happen, so this is reasonable.
mkdir -p "$pstore_dir"
}
+# For testing backward compatibility...
+for i in $CTDB_NOT_IMPLEMENTED ; do
+ if [ "$i" = "$1" ] ; then
+ not_implemented "$i"
+ fi
+done
+
case "$1" in
ip)
# NOTE: all nodes share the same public addresses file.
exit 1
esac
;;
+ getdebug)
+ case "${CTDB_DEBUGLEVEL:-0}" in
+ -3) _t="EMERG" ;;
+ -2) _t="ALERT" ;;
+ -1) _t="CRIT" ;;
+ 0) _t="ERR" ;;
+ 1) _t="WARNING" ;;
+ 2) _t="NOTICE" ;;
+ 3) _t="INFO" ;;
+ 4) _t="DEBUG" ;;
+ *) _t="ERR" ;;
+ esac
+
+ cat<<EOF
+:Name:Level:
+:${_t}:${CTDB_DEBUGLEVEL}:
+EOF
+ ;;
+ checktcpport)
+ for _i in $FAKE_TCP_LISTEN ; do
+ if [ "$2" = "${_i##*:}" ] ; then
+ exit 98
+ fi
+ done
+
+ exit 0
+ ;;
+ scriptstatus)
+ $machine_readable || not_implemented "$1, without -Y"
+ [ "$2" != "all" ] || not_implemented "scriptstatus all"
+ # For now just assume everything is good.
+ echo ":Type:Name:Code:Status:Start:End:Error Output...:"
+ for _i in "$CTDB_BASE/events.d/"*.* ; do
+ _d1=$(date '+%s.%N')
+ _b="${_i##*/}" # basename
+
+ _f="$FAKE_CTDB_SCRIPTSTATUS/$_b"
+ if [ -r "$_f" ] ; then
+ read _code _status _err_out <"$_f"
+ else
+ _code="0"
+ _status="OK"
+ if [ ! -x "$_i" ] ; then
+ _status="DISABLED"
+ _code="-8"
+ fi
+ _err_out=""
+ fi
+ _d2=$(date '+%s.%N')
+ echo ":${2:-monitor}:${_b}:${_code}:${_status}:${_d1}:${_d2}:${_err_out}:"
+ done
+ ;;
*)
- echo "${prog}: command \"$1\" not implemented in stub"
- exit 1
+ not_implemented "$1"
esac
-
opts="10.0.0.0/16(rw,async,insecure,no_root_squash,no_subtree_check)"
for i in $FAKE_SHARES ; do
- echo "${i} ${opts}"
+ # Directories longer than 15 characters are printed on their own
+ # line.
+ if [ ${#i} -ge 15 ] ; then
+ printf '%s\n\t\t%s\n' "$i" "$opts"
+ else
+ printf '%s\t%s\n' "$i" "$opts"
+ fi
done
prog="netstat"
+# Pretty that we're the shell and that this command could not be
+# found.
+if [ "$FAKE_NETSTAT_NOT_FOUND" = "yes" ] ; then
+ echo "sh: ${prog}: command not found" >&2
+ exit 127
+fi
+
usage ()
{
cat >&2 <<EOF
Usage: $prog [ -t | --unix ] [ -n ] [ -a ] [ -l ]
A fake netstat stub that prints items depending on the variables
-FAKE_NETSTAT_TCP_ESTABLISHED, FAKE_NETSTAT_TCP_LISTEN,
+FAKE_NETSTAT_TCP_ESTABLISHED, FAKE_TCP_LISTEN,
FAKE_NETSTAT_UNIX_LISTEN, depending on command-line options.
Note that -n is ignored.
done
if $all || $listen ; then
- for i in $FAKE_NETSTAT_TCP_LISTEN ; do
+ for i in $FAKE_TCP_LISTEN ; do
printf "$tcp_fmt" $i "0.0.0.0:*" "LISTEN"
done
fi
--- /dev/null
+#!/bin/bash
+
+prog="nmap"
+
+# Pretty that we're the shell and that this command could not be
+# found.
+if [ "$FAKE_NMAP_NOT_FOUND" = "yes" ] ; then
+ echo "sh: ${prog}: command not found" >&2
+ exit 127
+fi
+
+usage ()
+{
+ cat >&2 <<EOF
+Usage: $prog -n -oG - -PS 127.0.0.1 -p <port>[,<port> ...]
+
+A fake nmap stub that prints items depending on the variable
+FAKE_TCP_LISTEN and the ports specified.
+
+Note that all options apart from -p are ignored.
+
+EOF
+ exit 1
+}
+
+ports=""
+
+parse_options ()
+{
+ _temp=$(getopt -n "$prog" -a -o "np:" -l help -l PS: -l oG: -- "$@")
+
+ [ $? != 0 ] && usage
+
+ eval set -- "$_temp"
+
+ while true ; do
+ case "$1" in
+ -n) shift ;;
+ --oG|--PS) shift 2 ;;
+ -p) ports="${ports}${ports:+ }${2//,/ }" ; shift 2 ;;
+ --) shift ; break ;;
+ -h|--help|*) usage ;; # * shouldn't happen, so this is reasonable.
+ esac
+ done
+
+ [ $# -gt 0 ] && usage
+
+ [ -n "$ports" ] || usage
+}
+
+# For printing out...
+args="$*"
+
+parse_options "$@"
+
+port_states=""
+
+for p in $ports ; do
+ pn=$(getent services "$p" | sed -e 's@[[:space:]].*@@')
+ for i in $FAKE_TCP_LISTEN ; do
+ lp="${i##*:}"
+ if [ "$p" = "$lp" ] ; then
+ port_states="${port_states}${port_states:+, }${p}/open/tcp//${pn}///"
+ continue 2
+ fi
+ done
+ port_states="${port_states}${port_states:+, }${p}/closed/tcp//${pn}///"
+done
+
+cat <<EOF
+# Nmap 5.21 scan initiated $(date) as: nmap $args
+Host: 127.0.0.1 () Status: Up
+Host: 127.0.0.1 () Ports: $port_states
+# Nmap done at $(date) -- 1 IP address (1 host up) scanned in 0.04 seconds
+EOF
--- /dev/null
+#!/bin/sh
+
+if [ "$FAKE_SLEEP_REALLY" = "yes" ] ; then
+ /bin/sleep "$@"
+elif [ -n "$FAKE_SLEEP_FORCE" ] ; then
+ /bin/sleep "$FAKE_SLEEP_FORCE"
+else
+ :
+fi
ev = event_context_init(NULL);
/* initialise ctdb */
- ctdb = ctdb_cmdline_client(ev);
+ ctdb = ctdb_cmdline_client(ev, timeval_current_ofs(3, 0));
/* attach to a specific database */
- ctdb_db = ctdb_attach(ctdb, "test.tdb", false, 0);
+ ctdb_db = ctdb_attach(ctdb, timeval_current_ofs(2, 0), "test.tdb",
+ false, 0);
if (!ctdb_db) {
printf("ctdb_attach failed - %s\n", ctdb_errstr(ctdb));
exit(1);
ev = event_context_init(NULL);
- ctdb = ctdb_cmdline_client(ev);
+ ctdb = ctdb_cmdline_client(ev, timeval_current_ofs(3, 0));
if (ctdb == NULL) {
printf("failed to connect to ctdb daemon.\n");
&cluster_ready);
/* attach to a specific database */
- ctdb_db = ctdb_attach(ctdb, "test.tdb", false, 0);
+ ctdb_db = ctdb_attach(ctdb, timeval_current_ofs(2, 0), "test.tdb",
+ false, 0);
if (!ctdb_db) {
printf("ctdb_attach failed - %s\n", ctdb_errstr(ctdb));
exit(1);
ev = event_context_init(NULL);
- ctdb = ctdb_cmdline_client(ev);
+ ctdb = ctdb_cmdline_client(ev, timeval_current_ofs(3, 0));
if (ctdb == NULL) {
printf("failed to connect to ctdb deamon.\n");
}
/* attach to a specific database */
- ctdb_db = ctdb_attach(ctdb, "test.tdb", false, 0);
+ ctdb_db = ctdb_attach(ctdb, timeval_current_ofs(2, 0), "test.tdb",
+ false, 0);
if (!ctdb_db) {
printf("ctdb_attach failed - %s\n", ctdb_errstr(ctdb));
exit(1);
ev = event_context_init(NULL);
- ctdb = ctdb_cmdline_client(ev);
+ ctdb = ctdb_cmdline_client(ev, timeval_current_ofs(3, 0));
if (ctdb == NULL) {
printf("Could not attach to daemon\n");
return 1;
/* attach to a specific database */
if (unsafe_writes == 1) {
- ctdb_db = ctdb_attach(ctdb, "persistent.tdb", true, TDB_NOSYNC);
+ ctdb_db = ctdb_attach(ctdb, timeval_current_ofs(2, 0),
+ "persistent.tdb", true, TDB_NOSYNC);
} else {
- ctdb_db = ctdb_attach(ctdb, "persistent.tdb", true, 0);
+ ctdb_db = ctdb_attach(ctdb, timeval_current_ofs(2, 0),
+ "persistent.tdb", true, 0);
}
if (!ctdb_db) {
ev = event_context_init(NULL);
- ctdb = ctdb_cmdline_client(ev);
+ ctdb = ctdb_cmdline_client(ev, timeval_current_ofs(3, 0));
if (ctdb == NULL) {
printf("failed to connect to daemon\n");
}
/* attach to a specific database */
- ctdb_db = ctdb_attach(ctdb, "test.tdb", false, 0);
+ ctdb_db = ctdb_attach(ctdb, timeval_current_ofs(2, 0), "test.tdb",
+ false, 0);
if (!ctdb_db) {
printf("ctdb_attach failed - %s\n", ctdb_errstr(ctdb));
exit(1);
ev = event_context_init(NULL);
- ctdb = ctdb_cmdline_client(ev);
+ ctdb = ctdb_cmdline_client(ev, timeval_current_ofs(3, 0));
if (ctdb == NULL) {
printf("failed to connect to ctdb daemon.\n");
}
/* attach to a specific database */
- ctdb_db = ctdb_attach(ctdb, "test.tdb", false, 0);
+ ctdb_db = ctdb_attach(ctdb, timeval_current_ofs(2, 0), "test.tdb", false, 0);
if (!ctdb_db) {
printf("ctdb_attach failed - %s\n", ctdb_errstr(ctdb));
exit(1);
ev = event_context_init(NULL);
- ctdb = ctdb_cmdline_client(ev);
+ ctdb = ctdb_cmdline_client(ev, timeval_current_ofs(3, 0));
if (ctdb == NULL) {
DEBUG(DEBUG_ERR, ("Could not attach to daemon\n"));
return 1;
/* attach to a specific database */
if (unsafe_writes == 1) {
- ctdb_db = ctdb_attach(ctdb, "transaction.tdb", true, TDB_NOSYNC);
+ ctdb_db = ctdb_attach(ctdb, timeval_current_ofs(2, 0),
+ "transaction.tdb", true, TDB_NOSYNC);
} else {
- ctdb_db = ctdb_attach(ctdb, "transaction.tdb", true, 0);
+ ctdb_db = ctdb_attach(ctdb, timeval_current_ofs(2, 0),
+ "transaction.tdb", true, 0);
}
if (!ctdb_db) {
ev = event_context_init(NULL);
- ctdb = ctdb_cmdline_client(ev);
+ ctdb = ctdb_cmdline_client(ev, timeval_current_ofs(3, 0));
/* attach to a specific database */
- ctdb_db = ctdb_attach(ctdb, dbname, false, 0);
+ ctdb_db = ctdb_attach(ctdb, timeval_current_ofs(2, 0), dbname, false, 0);
if (!ctdb_db) {
printf("ctdb_attach failed - %s\n", ctdb_errstr(ctdb));
exit(1);
return ret;
}
- if(options.machinereadable){
- printf(":Node:IP:Disconnected:Banned:Disabled:Unhealthy:Stopped:Inactive:PartiallyOnline:\n");
- for(i=0;i<nodemap->num;i++){
+ if (options.machinereadable) {
+ printf(":Node:IP:Disconnected:Banned:Disabled:Unhealthy:Stopped"
+ ":Inactive:PartiallyOnline:ThisNode:\n");
+ for (i=0;i<nodemap->num;i++) {
int partially_online = 0;
int j;
talloc_free(ifaces);
}
}
- printf(":%d:%s:%d:%d:%d:%d:%d:%d:%d:\n", nodemap->nodes[i].pnn,
+ printf(":%d:%s:%d:%d:%d:%d:%d:%d:%d:%d:\n", nodemap->nodes[i].pnn,
ctdb_addr_to_str(&nodemap->nodes[i].addr),
!!(nodemap->nodes[i].flags&NODE_FLAGS_DISCONNECTED),
!!(nodemap->nodes[i].flags&NODE_FLAGS_BANNED),
!!(nodemap->nodes[i].flags&NODE_FLAGS_UNHEALTHY),
!!(nodemap->nodes[i].flags&NODE_FLAGS_STOPPED),
!!(nodemap->nodes[i].flags&NODE_FLAGS_INACTIVE),
- partially_online);
+ partially_online,
+ (nodemap->nodes[i].pnn == mypnn));
}
return 0;
}
printf("hash:%d lmaster:%d\n", i, vnnmap->map[i]);
}
- ret = ctdb_ctrl_getrecmode(ctdb, ctdb, TIMELIMIT(), options.pnn, &recmode);
- if (ret != 0) {
+ if (!ctdb_getrecmode(ctdb_connection, options.pnn, &recmode)) {
DEBUG(DEBUG_ERR, ("Unable to get recmode from node %u\n", options.pnn));
- return ret;
+ return -1;
}
printf("Recovery mode:%s (%d)\n",recmode==CTDB_RECOVERY_NORMAL?"NORMAL":"RECOVERY",recmode);
- ret = ctdb_ctrl_getrecmaster(ctdb, ctdb, TIMELIMIT(), options.pnn, &recmaster);
- if (ret != 0) {
+ if (!ctdb_getrecmaster(ctdb_connection, options.pnn, &recmaster)) {
DEBUG(DEBUG_ERR, ("Unable to get recmaster from node %u\n", options.pnn));
- return ret;
+ return -1;
}
printf("Recovery master:%d\n",recmaster);
break;
}
if (options.machinereadable) {
- printf("%s:%s:%i:%s:%lu.%06lu:%lu.%06lu:%s:\n",
+ printf(":%s:%s:%i:%s:%lu.%06lu:%lu.%06lu:%s:\n",
ctdb_eventscript_call_names[type],
script_status->scripts[i].name,
script_status->scripts[i].status,
*/
static int control_recmaster(struct ctdb_context *ctdb, int argc, const char **argv)
{
- int ret;
uint32_t recmaster;
- ret = ctdb_ctrl_getrecmaster(ctdb, ctdb, TIMELIMIT(), options.pnn, &recmaster);
- if (ret != 0) {
+ if (!ctdb_getrecmaster(ctdb_connection, options.pnn, &recmaster)) {
DEBUG(DEBUG_ERR, ("Unable to get recmaster from node %u\n", options.pnn));
- return ret;
+ return -1;
}
printf("%d\n",recmaster);
}
- ret = ctdb_ctrl_getrecmaster(ctdb, ctdb, TIMELIMIT(), options.pnn, &recmaster);
- if (ret != 0) {
+ if (!ctdb_getrecmaster(ctdb_connection, options.pnn, &recmaster)) {
DEBUG(DEBUG_ERR, ("Unable to get recmaster from node %u\n", options.pnn));
- return ret;
+ return -1;
}
/* verify the node exists */
}
/* get the recmaster */
- ret = ctdb_ctrl_getrecmaster(ctdb, ctdb, TIMELIMIT(), CTDB_CURRENT_NODE, &recmaster);
- if (ret != 0) {
+ if (!ctdb_getrecmaster(ctdb_connection, CTDB_CURRENT_NODE, &recmaster)) {
DEBUG(DEBUG_ERR, ("Unable to get recmaster from node %u\n", options.pnn));
exit(10);
}
/* get recovery mode */
- ret = ctdb_ctrl_getrecmode(ctdb, ctdb, TIMELIMIT(), recmaster, &recmode);
- if (ret != 0) {
+ if (!ctdb_getrecmode(ctdb_connection, recmaster, &recmode)) {
DEBUG(DEBUG_ERR, ("Unable to get recmode from node %u\n", options.pnn));
exit(10);
}
return -1;
}
- ctdb_db = ctdb_attach(ctdb, db_name, persistent, 0);
+ ctdb_db = ctdb_attach(ctdb, TIMELIMIT(), db_name, persistent, 0);
if (ctdb_db == NULL) {
DEBUG(DEBUG_ERR,("Unable to attach to database '%s'\n", db_name));
return -1;
}
- ctdb_db = ctdb_attach(ctdb, db_name, false, 0);
+ ctdb_db = ctdb_attach(ctdb, TIMELIMIT(), db_name, false, 0);
if (ctdb_db == NULL) {
DEBUG(DEBUG_ERR,("Unable to attach to database '%s'\n", db_name));
return -1;
}
- ctdb_db = ctdb_attach(ctdb, db_name, persistent, 0);
+ ctdb_db = ctdb_attach(ctdb, TIMELIMIT(), db_name, persistent, 0);
if (ctdb_db == NULL) {
DEBUG(DEBUG_ERR,("Unable to attach to database '%s'\n", db_name));
return -1;
}
- ctdb_db = ctdb_attach(ctdb, db_name, persistent, 0);
+ ctdb_db = ctdb_attach(ctdb, TIMELIMIT(), db_name, persistent, 0);
if (ctdb_db == NULL) {
DEBUG(DEBUG_ERR,("Unable to attach to database '%s'\n", db_name));
return -1;
}
- ctdb_db = ctdb_attach(ctdb, db_name, persistent, 0);
+ ctdb_db = ctdb_attach(ctdb, TIMELIMIT(), db_name, persistent, 0);
if (ctdb_db == NULL) {
DEBUG(DEBUG_ERR,("Unable to attach to database '%s'\n", db_name));
db_name = argv[0];
- ctdb_db = ctdb_attach(ctdb, db_name, true, 0);
-
+ ctdb_db = ctdb_attach(ctdb, TIMELIMIT(), db_name, true, 0);
if (ctdb_db == NULL) {
DEBUG(DEBUG_ERR,("Unable to attach to database '%s'\n", db_name));
talloc_free(tmp_ctx);
static int control_isnotrecmaster(struct ctdb_context *ctdb, int argc, const char **argv)
{
uint32_t mypnn, recmaster;
- int ret;
mypnn = ctdb_ctrl_getpnn(ctdb, TIMELIMIT(), options.pnn);
if (mypnn == -1) {
return 1;
}
- ret = ctdb_ctrl_getrecmaster(ctdb, ctdb, TIMELIMIT(), options.pnn, &recmaster);
- if (ret != 0) {
+ if (!ctdb_getrecmaster(ctdb_connection, options.pnn, &recmaster)) {
printf("Failed to get the recmaster\n");
return 1;
}
persistent = true;
}
- ctdb_db = ctdb_attach(ctdb, db_name, persistent, 0);
+ ctdb_db = ctdb_attach(ctdb, TIMELIMIT(), db_name, persistent, 0);
if (ctdb_db == NULL) {
DEBUG(DEBUG_ERR,("Unable to attach to database '%s'\n", db_name));
return -1;
DEBUG(DEBUG_ERR,("database '%s' is unhealthy: %s\n",
argv[0], reason));
- DEBUG(DEBUG_ERR,("disallow backup : tunnable AllowUnhealthyDBRead = %u\n",
+ DEBUG(DEBUG_ERR,("disallow backup : tunable AllowUnhealthyDBRead = %u\n",
allow_unhealthy));
talloc_free(tmp_ctx);
return -1;
allow_unhealthy));
}
- ctdb_db = ctdb_attach(ctdb, argv[0], dbmap->dbs[i].flags & CTDB_DB_FLAGS_PERSISTENT, 0);
+ ctdb_db = ctdb_attach(ctdb, TIMELIMIT(), argv[0], dbmap->dbs[i].flags & CTDB_DB_FLAGS_PERSISTENT, 0);
if (ctdb_db == NULL) {
DEBUG(DEBUG_ERR,("Unable to attach to database '%s'\n", argv[0]));
talloc_free(tmp_ctx);
dbname, tbuf);
- ctdb_db = ctdb_attach(ctdb, dbname, dbhdr.persistent, 0);
+ ctdb_db = ctdb_attach(ctdb, TIMELIMIT(), dbname, dbhdr.persistent, 0);
if (ctdb_db == NULL) {
DEBUG(DEBUG_ERR,("Unable to attach to database '%s'\n", dbname));
talloc_free(tmp_ctx);
return -1;
}
- ctdb_db = ctdb_attach(ctdb, argv[0], dbmap->dbs[i].flags & CTDB_DB_FLAGS_PERSISTENT, 0);
+ ctdb_db = ctdb_attach(ctdb, TIMELIMIT(), argv[0], dbmap->dbs[i].flags & CTDB_DB_FLAGS_PERSISTENT, 0);
if (ctdb_db == NULL) {
DEBUG(DEBUG_ERR, ("Unable to attach to database '%s'\n",
argv[0]));
}
/* initialise ctdb */
- ctdb = ctdb_cmdline_client(ev);
+ ctdb = ctdb_cmdline_client(ev, TIMELIMIT());
if (ctdb_commands[i].without_daemon == false) {
const char *socket_name;
return -1;
}
- ctdb_db = ctdb_attach(ctdb, name, persistent, 0);
+ ctdb_db = ctdb_attach(ctdb, TIMELIMIT(), name, persistent, 0);
if (ctdb_db == NULL) {
DEBUG(DEBUG_ERR,(__location__ " Failed to attach to database '%s'\n", name));
talloc_free(vdata);
return -1;
}
- ctdb_db = ctdb_attach(ctdb, name, persistent, 0);
+ ctdb_db = ctdb_attach(ctdb, TIMELIMIT(), name, persistent, 0);
if (ctdb_db == NULL) {
DEBUG(DEBUG_ERR,(__location__ " Failed to attach to database '%s'\n", name));
return -1;
--- /dev/null
+#! /bin/sh
+#
+# Copyright (c) 1997 Silicon Graphics, Inc. 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 02111-1307 USA
+#
+# Install the ctdb PMDA and/or PMNS
+#
+
+. $PCP_DIR/etc/pcp.env
+. $PCP_SHARE_DIR/lib/pmdaproc.sh
+
+iam=ctdb
+pmda_interface=2
+
+# runs as daemon and only supports pipe IPC
+daemon_opt=true
+dso_opt=false
+pipe_opt=true
+socket_opt=false
+
+pmdaSetup
+pmdaInstall
+exit 0
--- /dev/null
+CTDB PMDA
+===========
+
+This PMDA extracts metrics from the locally running ctdbd daemon for
+export to PMCD.
+
+Note:
+ This PMDA may be remade from source and hence requires IDO (or
+ more specifically a C compiler) to be installed.
+
+ Uses of make(1) may fail (without removing or clobbering files)
+ if the C compiler cannot be found. This is most likely to
+ happen when running the PMDA ./Install script.
+
+ The only remedial action is to install the C compiler, or
+ hand-craft changes to the Makefile.
+
+Metrics
+=======
+
+The file ./help contains descriptions for all of the metrics exported
+by this PMDA.
+
+Once the PMDA has been installed, the following command will list all
+the available metrics and their explanatory "help" text:
+
+ $ pminfo -fT ctdb
+
+Installation
+============
+
+ + # cd $PCP_PMDAS_DIR/ctdb
+
+ + Check that there is no clash in the Performance Metrics Domain
+ defined in ./domain.h and the other PMDAs currently in use (see
+ $PCP_PMCDCONF_PATH). If there is, edit ./domain.h to choose another
+ domain number.
+
+ + Then simply use
+
+ # ./Install
+
+ and choose both the "collector" and "monitor" installation
+ configuration options.
+
+ You will be prompted to choose either a daemon implementation
+ or a DSO implementation of the PMDA, and in the case of the daemon
+ variant to select an IPC method -- everything else is automated
+
+De-installation
+===============
+
+ + Simply use
+
+ # cd $PCP_PMDAS_DIR/ctdb
+ # ./Remove
+
+Troubleshooting
+===============
+
+ + After installing or restarting the agent, the PMCD log file
+ ($PCP_LOG_DIR/pmcd/pmcd.log) and the PMDA log file
+ ($PCP_LOG_DIR/pmcd/pmda_ctdb.log) should be checked for any warnings
+ or errors.
+
+
+Adding a New Metric
+===================
+
+This section walks through the development task of adding a new metric to the
+CTDB PMDA.
+
+ + Define the metric in the pmns file with a unique metric id. See the pmns(4)
+ man page for details.
+
+ + Add a description of the metric to the help file.
+
+ + Taking note of the previously assigned metric id, add a new entry to the
+ metrictab structure in pmda_ctdb.c. See the pmdaInit(3) man page for
+ details.
+
+ + Ensure the counter is already a member of the ctdb_statistics structure.
+ Finally, add code to pmda_ctdb_fetch_cb() to handle fetch requests for the
+ newly defined metric.
--- /dev/null
+#! /bin/sh
+#
+# Copyright (c) 1997 Silicon Graphics, Inc. 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 02111-1307 USA
+#
+# Remove the ctdb PMDA
+#
+
+. $PCP_DIR/etc/pcp.env
+. $PCP_SHARE_DIR/lib/pmdaproc.sh
+
+iam=ctdb
+
+pmdaSetup
+pmdaRemove
+exit 0
--- /dev/null
+/* domain.h
+ *
+ * Copyright (c) 2004-2009 Silicon Graphics, Inc. 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 02111-1307 USA
+ */
+#define CTDB 155
--- /dev/null
+#
+# Copyright (c) 2000-2004 Silicon Graphics, Inc. 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 02111-1307 USA
+#
+# ctdb PMDA help file in the ASCII format
+#
+# lines beginning with a # are ignored
+# lines beginning @ introduce a new entry of the form
+# @ metric_name oneline-text
+# help test goes
+# here over multiple lines
+# ...
+#
+# the metric_name is decoded against the default PMNS -- as a special case,
+# a name of the form NNN.MM (for numeric NNN and MM) is interpreted as an
+# instance domain identification, and the text describes the instance domain
+#
+# blank lines before the @ line are ignored
+#
+
+@ ctdb.num_clients number of clients connected to ctdbd
+
+@ ctdb.frozen whether any databases are frozen
+
+@ ctdb.recovering whether recovery is active
+
+@ ctdb.client_packets_sent number of packets sent to all clients
+
+@ ctdb.client_packets_recv number of packets received from all clients
+
+@ ctdb.node_packets_sent number of packets sent to other nodes
+
+@ ctdb.node_packets_recv number of packets received from other nodes
+
+@ ctdb.keepalive_packets_sent number of keepalive packets sent to other nodes
+
+@ ctdb.keepalive_packets_recv number of keepalive packets received from other nodes
+
+@ ctdb.node.req_call number of node CTDB_REQ_CALL packets handled
+
+@ ctdb.node.reply_call number of node CTDB_REPLY_CALL packets handled
+
+@ ctdb.node.req_dmaster number of node CTDB_REQ_DMASTER packets handled
+
+@ ctdb.node.reply_dmaster number of node CTDB_REPLY_DMASTER packets handled
+
+@ ctdb.node.reply_error number of node CTDB_REPLY_ERROR packets handled
+
+@ ctdb.node.req_message number of node CTDB_REQ_MESSAGE packets handled
+
+@ ctdb.node.req_control number of node CTDB_REQ_CONTROL packets handled
+
+@ ctdb.node.reply_control number of node CTDB_REPLY_CONTROL packets handled
+
+@ ctdb.client.req_call number of client CTDB_REQ_CALL packets handled
+
+@ ctdb.client.req_message number of client CTDB_REQ_MESSAGE packets handled
+
+@ ctdb.client.req_control number of client CTDB_REQ_CONTROL packets handled
+
+@ ctdb.timeouts.call (counter not implemented) number of call timeouts
+
+@ ctdb.timeouts.control number of node control message request timeouts awaiting reply
+
+@ ctdb.timeouts.traverse number of database traversal timeouts
+
+@ ctdb.total_calls total number of client ctdb request calls received
+
+@ ctdb.pending_calls total number of client ctdb request calls in progress
+
+@ ctdb.lockwait_calls number of tdb chainlock lockwait calls
+
+@ ctdb.pending_lockwait_calls number of lockwait calls waiting for a lock
+
+@ ctdb.childwrite_calls number of childwrite calls
+
+@ ctdb.pending_childwrite_calls number of childwrite calls in progress
+
+@ ctdb.memory_used total size of the ctdbd null talloc pool
+
+@ ctdb.max_hop_count maximum hops performed by a CTDB_REQ_CALL packet
+
+@ ctdb.max_reclock_ctdbd maximum recovery lock latency during setrecmode
+
+@ ctdb.max_reclock_recd maximum recovery lock latency as reported by the recovery process
+
+@ ctdb.max_call_latency maximum time spent handling a client request call
+
+@ ctdb.max_lockwait_latency maximum time spent waiting for a tdb chainlock
+
+@ ctdb.max_childwrite_latency maximum time spent performing a childwrite
+
+@ ctdb.num_recoveries number of recoveries finished
--- /dev/null
+/*
+ * CTDB Performance Metrics Domain Agent (PMDA) for Performance Co-Pilot (PCP)
+ *
+ * Copyright (c) 1995,2004 Silicon Graphics, Inc. All Rights Reserved.
+ * Copyright (c) 2011 David Disseldorp
+ *
+ * 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 02111-1307 USA
+ */
+
+#include <pcp/pmapi.h>
+#include <pcp/impl.h>
+#include <pcp/pmda.h>
+#include "../../include/includes.h"
+#include "../../lib/tevent/tevent.h"
+#include "../../include/ctdb.h"
+#include "../../include/ctdb_private.h"
+#include "../../include/ctdb_protocol.h"
+#include "domain.h"
+
+/*
+ * CTDB PMDA
+ *
+ * This PMDA connects to the locally running ctdbd daemon and pulls
+ * statistics for export via PCP. The ctdbd Unix domain socket path can be
+ * specified with the CTDB_SOCKET environment variable, otherwise the default
+ * path is used.
+ */
+
+/*
+ * All metrics supported in this PMDA - one table entry for each.
+ * The 4th field specifies the serial number of the instance domain
+ * for the metric, and must be either PM_INDOM_NULL (denoting a
+ * metric that only ever has a single value), or the serial number
+ * of one of the instance domains declared in the instance domain table
+ * (i.e. in indomtab, above).
+ */
+static pmdaMetric metrictab[] = {
+ /* num_clients */
+ { NULL, { PMDA_PMID(0,0), PM_TYPE_U32, PM_INDOM_NULL, PM_SEM_INSTANT,
+ PMDA_PMUNITS(0,0,0,0,0,0) }, },
+ /* frozen */
+ { NULL, { PMDA_PMID(1,2), PM_TYPE_U32, PM_INDOM_NULL, PM_SEM_INSTANT,
+ PMDA_PMUNITS(0,0,0,0,0,0) }, },
+ /* recovering */
+ { NULL, { PMDA_PMID(3,3), PM_TYPE_U32, PM_INDOM_NULL, PM_SEM_INSTANT,
+ PMDA_PMUNITS(0,0,0,0,0,0) }, },
+ /* client_packets_sent */
+ { NULL, { PMDA_PMID(4,4), PM_TYPE_U32, PM_INDOM_NULL, PM_SEM_COUNTER,
+ PMDA_PMUNITS(0,0,1,0,0,PM_COUNT_ONE) }, },
+ /* client_packets_recv */
+ { NULL, { PMDA_PMID(5,5), PM_TYPE_U32, PM_INDOM_NULL, PM_SEM_COUNTER,
+ PMDA_PMUNITS(0,0,1,0,0,PM_COUNT_ONE) }, },
+ /* node_packets_sent */
+ { NULL, { PMDA_PMID(6,6), PM_TYPE_U32, PM_INDOM_NULL, PM_SEM_COUNTER,
+ PMDA_PMUNITS(0,0,1,0,0,PM_COUNT_ONE) }, },
+ /* node_packets_recv */
+ { NULL, { PMDA_PMID(7,7), PM_TYPE_U32, PM_INDOM_NULL, PM_SEM_COUNTER,
+ PMDA_PMUNITS(0,0,1,0,0,PM_COUNT_ONE) }, },
+ /* keepalive_packets_sent */
+ { NULL, { PMDA_PMID(8,8), PM_TYPE_U32, PM_INDOM_NULL, PM_SEM_COUNTER,
+ PMDA_PMUNITS(0,0,1,0,0,PM_COUNT_ONE) }, },
+ /* keepalive_packets_recv */
+ { NULL, { PMDA_PMID(9,9), PM_TYPE_U32, PM_INDOM_NULL, PM_SEM_COUNTER,
+ PMDA_PMUNITS(0,0,1,0,0,PM_COUNT_ONE) }, },
+ /* req_call */
+ { NULL, { PMDA_PMID(10,10), PM_TYPE_U32, PM_INDOM_NULL, PM_SEM_COUNTER,
+ PMDA_PMUNITS(0,0,1,0,0,PM_COUNT_ONE) }, },
+ /* reply_call */
+ { NULL, { PMDA_PMID(10,11), PM_TYPE_U32, PM_INDOM_NULL, PM_SEM_COUNTER,
+ PMDA_PMUNITS(0,0,1,0,0,PM_COUNT_ONE) }, },
+ /* req_dmaster */
+ { NULL, { PMDA_PMID(10,12), PM_TYPE_U32, PM_INDOM_NULL, PM_SEM_COUNTER,
+ PMDA_PMUNITS(0,0,1,0,0,PM_COUNT_ONE) }, },
+ /* reply_dmaster */
+ { NULL, { PMDA_PMID(10,13), PM_TYPE_U32, PM_INDOM_NULL, PM_SEM_COUNTER,
+ PMDA_PMUNITS(0,0,1,0,0,PM_COUNT_ONE) }, },
+ /* reply_error */
+ { NULL, { PMDA_PMID(10,14), PM_TYPE_U32, PM_INDOM_NULL, PM_SEM_COUNTER,
+ PMDA_PMUNITS(0,0,1,0,0,PM_COUNT_ONE) }, },
+ /* req_message */
+ { NULL, { PMDA_PMID(10,15), PM_TYPE_U32, PM_INDOM_NULL, PM_SEM_COUNTER,
+ PMDA_PMUNITS(0,0,1,0,0,PM_COUNT_ONE) }, },
+ /* req_control */
+ { NULL, { PMDA_PMID(10,16), PM_TYPE_U32, PM_INDOM_NULL, PM_SEM_COUNTER,
+ PMDA_PMUNITS(0,0,1,0,0,PM_COUNT_ONE) }, },
+ /* reply_control */
+ { NULL, { PMDA_PMID(10,17), PM_TYPE_U32, PM_INDOM_NULL, PM_SEM_COUNTER,
+ PMDA_PMUNITS(0,0,1,0,0,PM_COUNT_ONE) }, },
+ /* req_call */
+ { NULL, { PMDA_PMID(11,18), PM_TYPE_U32, PM_INDOM_NULL, PM_SEM_COUNTER,
+ PMDA_PMUNITS(0,0,1,0,0,PM_COUNT_ONE) }, },
+ /* req_message */
+ { NULL, { PMDA_PMID(11,19), PM_TYPE_U32, PM_INDOM_NULL, PM_SEM_COUNTER,
+ PMDA_PMUNITS(0,0,1,0,0,PM_COUNT_ONE) }, },
+ /* req_control */
+ { NULL, { PMDA_PMID(11,20), PM_TYPE_U32, PM_INDOM_NULL, PM_SEM_COUNTER,
+ PMDA_PMUNITS(0,0,1,0,0,PM_COUNT_ONE) }, },
+ /* call */
+ { NULL, { PMDA_PMID(12,21), PM_TYPE_U32, PM_INDOM_NULL, PM_SEM_COUNTER,
+ PMDA_PMUNITS(0,0,1,0,0,0) }, },
+ /* control */
+ { NULL, { PMDA_PMID(12,22), PM_TYPE_U32, PM_INDOM_NULL, PM_SEM_COUNTER,
+ PMDA_PMUNITS(0,0,1,0,0,0) }, },
+ /* traverse */
+ { NULL, { PMDA_PMID(12,23), PM_TYPE_U32, PM_INDOM_NULL, PM_SEM_COUNTER,
+ PMDA_PMUNITS(0,0,1,0,0,0) }, },
+ /* total_calls */
+ { NULL, { PMDA_PMID(13,24), PM_TYPE_U32, PM_INDOM_NULL, PM_SEM_COUNTER,
+ PMDA_PMUNITS(0,0,1,0,0,PM_COUNT_ONE) }, },
+ /* pending_calls */
+ { NULL, { PMDA_PMID(14,25), PM_TYPE_U32, PM_INDOM_NULL, PM_SEM_INSTANT,
+ PMDA_PMUNITS(0,0,0,0,0,0) }, },
+ /* lockwait_calls */
+ { NULL, { PMDA_PMID(15,27), PM_TYPE_U32, PM_INDOM_NULL, PM_SEM_COUNTER,
+ PMDA_PMUNITS(0,0,1,0,0,PM_COUNT_ONE) }, },
+ /* pending_lockwait_calls */
+ { NULL, { PMDA_PMID(16,27), PM_TYPE_U32, PM_INDOM_NULL, PM_SEM_INSTANT,
+ PMDA_PMUNITS(0,0,0,0,0,0) }, },
+ /* childwrite_calls */
+ { NULL, { PMDA_PMID(17,28), PM_TYPE_U32, PM_INDOM_NULL, PM_SEM_COUNTER,
+ PMDA_PMUNITS(0,0,1,0,0,PM_COUNT_ONE) }, },
+ /* pending_childwrite_calls */
+ { NULL, { PMDA_PMID(18,29), PM_TYPE_U32, PM_INDOM_NULL, PM_SEM_INSTANT,
+ PMDA_PMUNITS(0,0,0,0,0,0) }, },
+ /* memory_used */
+ { NULL, { PMDA_PMID(19,30), PM_TYPE_U32, PM_INDOM_NULL, PM_SEM_INSTANT,
+ PMDA_PMUNITS(1,0,0,PM_SPACE_BYTE,0,0) }, },
+ /* max_hop_count */
+ { NULL, { PMDA_PMID(20,31), PM_TYPE_U32, PM_INDOM_NULL, PM_SEM_INSTANT,
+ PMDA_PMUNITS(0,0,0,0,0,0) }, },
+ /* max_reclock_ctdbd */
+ { NULL, { PMDA_PMID(21,32), PM_TYPE_DOUBLE, PM_INDOM_NULL, PM_SEM_INSTANT,
+ PMDA_PMUNITS(0,1,0,0,PM_TIME_SEC,0) }, },
+ /* max_reclock_recd */
+ { NULL, { PMDA_PMID(22,33), PM_TYPE_DOUBLE, PM_INDOM_NULL, PM_SEM_INSTANT,
+ PMDA_PMUNITS(0,1,0,0,PM_TIME_SEC,0) }, },
+ /* max_call_latency */
+ { NULL, { PMDA_PMID(23,34), PM_TYPE_DOUBLE, PM_INDOM_NULL, PM_SEM_INSTANT,
+ PMDA_PMUNITS(0,1,0,0,PM_TIME_SEC,0) }, },
+ /* max_lockwait_latency */
+ { NULL, { PMDA_PMID(24,35), PM_TYPE_DOUBLE, PM_INDOM_NULL, PM_SEM_INSTANT,
+ PMDA_PMUNITS(0,1,0,0,PM_TIME_SEC,0) }, },
+ /* max_childwrite_latency */
+ { NULL, { PMDA_PMID(25,36), PM_TYPE_DOUBLE, PM_INDOM_NULL, PM_SEM_INSTANT,
+ PMDA_PMUNITS(0,1,0,0,PM_TIME_SEC,0) }, },
+ /* num_recoveries */
+ { NULL, { PMDA_PMID(26,37), PM_TYPE_U32, PM_INDOM_NULL, PM_SEM_INSTANT,
+ PMDA_PMUNITS(0,0,0,0,0,0) }, },
+};
+
+static struct event_context *ev;
+static struct ctdb_context *ctdb;
+static struct ctdb_statistics *stats;
+
+static void
+pmda_ctdb_q_read_cb(uint8_t *data, size_t cnt, void *args)
+{
+ if (cnt == 0) {
+ fprintf(stderr, "ctdbd unreachable\n");
+ /* cleanup on request timeout */
+ return;
+ }
+
+ ctdb_client_read_cb(data, cnt, args);
+}
+
+
+static int
+pmda_ctdb_daemon_connect(void)
+{
+ const char *socket_name;
+ int ret;
+ struct sockaddr_un addr;
+
+ ev = event_context_init(NULL);
+ if (ev == NULL) {
+ fprintf(stderr, "Failed to init event ctx\n");
+ return -1;
+ }
+
+ ctdb = ctdb_init(ev);
+ if (ctdb == NULL) {
+ fprintf(stderr, "Failed to init ctdb\n");
+ goto err_ev;
+ }
+
+ socket_name = getenv("CTDB_SOCKET");
+ if (socket_name == NULL) {
+ socket_name = CTDB_PATH;
+ }
+
+ ret = ctdb_set_socketname(ctdb, socket_name);
+ if (ret == -1) {
+ fprintf(stderr, "ctdb_set_socketname failed - %s\n",
+ ctdb_errstr(ctdb));
+ goto err_ctdb;
+ }
+
+ /*
+ * ctdb_socket_connect() sets a default queue callback handler that
+ * calls exit() if ctdbd is unavailable on recv, use our own wrapper to
+ * work around this
+ */
+
+ memset(&addr, 0, sizeof(addr));
+ addr.sun_family = AF_UNIX;
+ strncpy(addr.sun_path, ctdb->daemon.name, sizeof(addr.sun_path));
+
+ ctdb->daemon.sd = socket(AF_UNIX, SOCK_STREAM, 0);
+ if (ctdb->daemon.sd == -1) {
+ fprintf(stderr, "Failed to open client socket\n");
+ goto err_ctdb;
+ }
+
+ set_nonblocking(ctdb->daemon.sd);
+ set_close_on_exec(ctdb->daemon.sd);
+
+ if (connect(ctdb->daemon.sd, (struct sockaddr *)&addr, sizeof(addr)) == -1) {
+ fprintf(stderr, "Failed to connect to ctdb daemon via %s\n",
+ ctdb->daemon.name);
+ goto err_sd;
+ }
+
+ ctdb->daemon.queue = ctdb_queue_setup(ctdb, ctdb, ctdb->daemon.sd,
+ CTDB_DS_ALIGNMENT,
+ pmda_ctdb_q_read_cb, ctdb,
+ "to-ctdbd");
+ if (ctdb->daemon.queue == NULL) {
+ fprintf(stderr, "Failed to setup queue\n");
+ goto err_sd;
+ }
+
+ ctdb->pnn = ctdb_ctrl_getpnn(ctdb, timeval_current_ofs(3, 0),
+ CTDB_CURRENT_NODE);
+ if (ctdb->pnn == (uint32_t)-1) {
+ fprintf(stderr, "Failed to get ctdb pnn\n");
+ goto err_sd;
+ }
+
+ return 0;
+err_sd:
+ close(ctdb->daemon.sd);
+err_ctdb:
+ talloc_free(ctdb);
+err_ev:
+ talloc_free(ev);
+ ctdb = NULL;
+ return -1;
+}
+
+static void
+pmda_ctdb_daemon_disconnect(void)
+{
+ if (ctdb->methods) {
+ ctdb->methods->shutdown(ctdb);
+ }
+
+ if (ctdb->daemon.sd != -1) {
+ close(ctdb->daemon.sd);
+ }
+
+ talloc_free(ctdb);
+ talloc_free(ev);
+ ctdb = NULL;
+}
+
+static int
+fill_node(unsigned int item, pmAtomValue *atom)
+{
+ switch (item) {
+ case 10:
+ atom->ul = stats->node.req_call;
+ break;
+ case 11:
+ atom->ul = stats->node.reply_call;
+ break;
+ case 12:
+ atom->ul = stats->node.req_dmaster;
+ break;
+ case 13:
+ atom->ul = stats->node.reply_dmaster;
+ break;
+ case 14:
+ atom->ul = stats->node.reply_error;
+ break;
+ case 15:
+ atom->ul = stats->node.req_message;
+ break;
+ case 16:
+ atom->ul = stats->node.req_control;
+ break;
+ case 17:
+ atom->ul = stats->node.reply_control;
+ break;
+ default:
+ return PM_ERR_PMID;
+ }
+
+ return 0;
+}
+
+static int
+fill_client(unsigned int item, pmAtomValue *atom)
+{
+ switch (item) {
+ case 18:
+ atom->ul = stats->client.req_call;
+ break;
+ case 19:
+ atom->ul = stats->client.req_message;
+ break;
+ case 20:
+ atom->ul = stats->client.req_control;
+ break;
+ default:
+ return PM_ERR_PMID;
+ }
+
+ return 0;
+}
+
+static int
+fill_timeout(unsigned int item, pmAtomValue *atom)
+{
+ switch (item) {
+ case 21:
+ atom->ul = stats->timeouts.call;
+ break;
+ case 22:
+ atom->ul = stats->timeouts.control;
+ break;
+ case 23:
+ atom->ul = stats->timeouts.traverse;
+ break;
+ default:
+ return PM_ERR_PMID;
+ }
+
+ return 0;
+}
+
+/*
+ * callback provided to pmdaFetch
+ */
+static int
+pmda_ctdb_fetch_cb(pmdaMetric *mdesc, unsigned int inst, pmAtomValue *atom)
+{
+ int ret;
+ __pmID_int *id = (__pmID_int *)&(mdesc->m_desc.pmid);
+
+ if (inst != PM_IN_NULL) {
+ return PM_ERR_INST;
+ }
+
+ if (stats == NULL) {
+ fprintf(stderr, "stats not available\n");
+ ret = PM_ERR_VALUE;
+ goto err_out;
+ }
+
+
+ switch (id->cluster) {
+ case 0:
+ atom->ul = stats->num_clients;
+ break;
+ case 1:
+ atom->ul = stats->frozen;
+ break;
+ case 3:
+ atom->ul = stats->recovering;
+ break;
+ case 4:
+ atom->ul = stats->client_packets_sent;
+ break;
+ case 5:
+ atom->ul = stats->client_packets_recv;
+ break;
+ case 6:
+ atom->ul = stats->node_packets_sent;
+ break;
+ case 7:
+ atom->ul = stats->node_packets_recv;
+ break;
+ case 8:
+ atom->ul = stats->keepalive_packets_sent;
+ break;
+ case 9:
+ atom->ul = stats->keepalive_packets_recv;
+ break;
+ case 10:
+ ret = fill_node(id->item, atom);
+ if (ret) {
+ goto err_out;
+ }
+ break;
+ case 11:
+ ret = fill_client(id->item, atom);
+ if (ret) {
+ goto err_out;
+ }
+ break;
+ case 12:
+ ret = fill_timeout(id->item, atom);
+ if (ret) {
+ goto err_out;
+ }
+ break;
+ case 13:
+ atom->ul = stats->total_calls;
+ break;
+ case 14:
+ atom->ul = stats->pending_calls;
+ break;
+ case 15:
+ atom->ul = stats->lockwait_calls;
+ break;
+ case 16:
+ atom->ul = stats->pending_lockwait_calls;
+ break;
+ case 17:
+ atom->ul = stats->childwrite_calls;
+ break;
+ case 18:
+ atom->ul = stats->pending_childwrite_calls;
+ break;
+ case 19:
+ atom->ul = stats->memory_used;
+ break;
+ case 20:
+ atom->ul = stats->max_hop_count;
+ break;
+ case 21:
+ atom->d = stats->reclock.ctdbd.max;
+ break;
+ case 22:
+ atom->d = stats->reclock.recd.max;
+ break;
+ case 23:
+ atom->d = stats->call_latency.max;
+ break;
+ case 24:
+ atom->d = stats->lockwait_latency.max;
+ break;
+ case 25:
+ atom->d = stats->childwrite_latency.max;
+ break;
+ case 26:
+ atom->d = stats->num_recoveries;
+ break;
+ default:
+ return PM_ERR_PMID;
+ }
+
+ ret = 0;
+err_out:
+ return ret;
+}
+
+/*
+ * This routine is called once for each pmFetch(3) operation, so is a
+ * good place to do once-per-fetch functions, such as value caching or
+ * instance domain evaluation.
+ */
+static int
+pmda_ctdb_fetch(int numpmid, pmID pmidlist[], pmResult **resp, pmdaExt *pmda)
+{
+ int ret;
+ TDB_DATA data;
+ int32_t res;
+ struct timeval ctdb_timeout;
+
+ if (ctdb == NULL) {
+ fprintf(stderr, "attempting reconnect to ctdbd\n");
+ ret = pmda_ctdb_daemon_connect();
+ if (ret < 0) {
+ fprintf(stderr, "reconnect failed\n");
+ return PM_ERR_VALUE;
+ }
+ }
+
+ ctdb_timeout = timeval_current_ofs(1, 0);
+ ret = ctdb_control(ctdb, ctdb->pnn, 0,
+ CTDB_CONTROL_STATISTICS, 0, tdb_null,
+ ctdb, &data, &res, &ctdb_timeout, NULL);
+
+ if (ret != 0 || res != 0) {
+ fprintf(stderr, "ctdb control for statistics failed, reconnecting\n");
+ pmda_ctdb_daemon_disconnect();
+ ret = PM_ERR_VALUE;
+ goto err_out;
+ }
+
+ stats = (struct ctdb_statistics *)data.dptr;
+
+ if (data.dsize != sizeof(struct ctdb_statistics)) {
+ fprintf(stderr, "incorrect statistics size %zu - not %zu\n",
+ data.dsize, sizeof(struct ctdb_statistics));
+ ret = PM_ERR_VALUE;
+ goto err_stats;
+ }
+
+ ret = pmdaFetch(numpmid, pmidlist, resp, pmda);
+
+err_stats:
+ talloc_free(stats);
+err_out:
+ return ret;
+}
+
+/*
+ * Initialise the agent
+ */
+void
+pmda_ctdb_init(pmdaInterface *dp)
+{
+ if (dp->status != 0) {
+ return;
+ }
+
+ dp->version.two.fetch = pmda_ctdb_fetch;
+ pmdaSetFetchCallBack(dp, pmda_ctdb_fetch_cb);
+
+ pmdaInit(dp, NULL, 0, metrictab,
+ (sizeof(metrictab) / sizeof(metrictab[0])));
+}
+
+static char *
+helpfile(void)
+{
+ static char buf[MAXPATHLEN];
+
+ if (!buf[0]) {
+ snprintf(buf, sizeof(buf), "%s/ctdb/help",
+ pmGetConfig("PCP_PMDAS_DIR"));
+ }
+ return buf;
+}
+
+static void
+usage(void)
+{
+ fprintf(stderr, "Usage: %s [options]\n\n", pmProgname);
+ fputs("Options:\n"
+ " -d domain use domain (numeric) for metrics domain of PMDA\n"
+ " -l logfile write log into logfile rather than using default log name\n"
+ "\nExactly one of the following options may appear:\n"
+ " -i port expect PMCD to connect on given inet port (number or name)\n"
+ " -p expect PMCD to supply stdin/stdout (pipe)\n"
+ " -u socket expect PMCD to connect on given unix domain socket\n",
+ stderr);
+ exit(1);
+}
+
+/*
+ * Set up the agent if running as a daemon.
+ */
+int
+main(int argc, char **argv)
+{
+ int err = 0;
+ char log_file[] = "pmda_ctdb.log";
+ pmdaInterface dispatch;
+
+ __pmSetProgname(argv[0]);
+
+ pmdaDaemon(&dispatch, PMDA_INTERFACE_2, pmProgname, CTDB,
+ log_file, helpfile());
+
+ if (pmdaGetOpt(argc, argv, "d:i:l:pu:?", &dispatch, &err) != EOF) {
+ err++;
+ }
+
+ if (err) {
+ usage();
+ }
+
+ pmdaOpenLog(&dispatch);
+ pmda_ctdb_init(&dispatch);
+ pmdaConnect(&dispatch);
+ pmdaMain(&dispatch);
+
+ exit(0);
+}
+
--- /dev/null
+/*
+ * Metrics for CTDB PMDA
+ *
+ * Copyright (c) 2000-2004 Silicon Graphics, Inc. All Rights Reserved.
+ * Copyright (c) 2011 David Disseldorp
+ *
+ * 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 02111-1307 USA
+ */
+
+ctdb {
+ num_clients CTDB:0:0
+ frozen CTDB:1:2
+ recovering CTDB:3:3
+ client_packets_sent CTDB:4:4
+ client_packets_recv CTDB:5:5
+ node_packets_sent CTDB:6:6
+ node_packets_recv CTDB:7:7
+ keepalive_packets_sent CTDB:8:8
+ keepalive_packets_recv CTDB:9:9
+ node
+ client
+ timeouts
+ total_calls CTDB:13:24
+ pending_calls CTDB:14:25
+ lockwait_calls CTDB:15:27
+ pending_lockwait_calls CTDB:16:27
+ childwrite_calls CTDB:17:28
+ pending_childwrite_calls CTDB:18:29
+ memory_used CTDB:19:30
+ max_hop_count CTDB:20:31
+ max_reclock_ctdbd CTDB:21:32
+ max_reclock_recd CTDB:22:33
+ max_call_latency CTDB:23:34
+ max_lockwait_latency CTDB:24:35
+ max_childwrite_latency CTDB:25:36
+ num_recoveries CTDB:26:37
+}
+
+ctdb.node {
+ req_call CTDB:10:10
+ reply_call CTDB:10:11
+ req_dmaster CTDB:10:12
+ reply_dmaster CTDB:10:13
+ reply_error CTDB:10:14
+ req_message CTDB:10:15
+ req_control CTDB:10:16
+ reply_control CTDB:10:17
+}
+
+ctdb.client {
+ req_call CTDB:11:18
+ req_message CTDB:11:19
+ req_control CTDB:11:20
+}
+
+ctdb.timeouts {
+ call CTDB:12:21
+ control CTDB:12:22
+ traverse CTDB:12:23
+}
+
--- /dev/null
+/*
+ * fake "root" for validating the local PMNS subtree
+ */
+
+#include <stdpmid>
+
+root { ctdb }
+
+#include "pmns"
+