aboutsummaryrefslogtreecommitdiffstats
path: root/tools/misc
diff options
context:
space:
mode:
authorKeir Fraser <keir.fraser@citrix.com>2010-06-04 11:35:23 +0100
committerKeir Fraser <keir.fraser@citrix.com>2010-06-04 11:35:23 +0100
commit78c8506e77b393c00001fce9e8b21eda22ed3007 (patch)
tree389ca22b5b3f4cb280364e264beca2974ce4b924 /tools/misc
parent77622d85cf3fd61e96b71750d75af58b60eddfc4 (diff)
downloadxen-78c8506e77b393c00001fce9e8b21eda22ed3007.tar.gz
xen-78c8506e77b393c00001fce9e8b21eda22ed3007.tar.bz2
xen-78c8506e77b393c00001fce9e8b21eda22ed3007.zip
Watchdog timers for domains
Each domain is allowed to set, reset and disable its timers; when any timer runs out the domain is killed. Patch from Christian Limpach <Christian.Limpach@citrix.com> Signed-off-by: Tim Deegan <Tim.Deegan@citrix.com>
Diffstat (limited to 'tools/misc')
-rw-r--r--tools/misc/Makefile8
-rw-r--r--tools/misc/xen-watchdog59
-rw-r--r--tools/misc/xenwatchdogd.c96
3 files changed, 160 insertions, 3 deletions
diff --git a/tools/misc/Makefile b/tools/misc/Makefile
index 01d4f4fbb9..72ebcd6b57 100644
--- a/tools/misc/Makefile
+++ b/tools/misc/Makefile
@@ -10,7 +10,7 @@ CFLAGS += $(INCLUDES)
HDRS = $(wildcard *.h)
-TARGETS-y := xenperf xenpm xen-tmem-list-parse gtraceview gtracestat xenlockprof xen-hptool
+TARGETS-y := xenperf xenpm xen-tmem-list-parse gtraceview gtracestat xenlockprof xen-hptool xenwatchdogd
TARGETS-$(CONFIG_X86) += xen-detect xen-hvmctx
TARGETS := $(TARGETS-y)
@@ -22,7 +22,7 @@ INSTALL_BIN-y := xencons
INSTALL_BIN-$(CONFIG_X86) += xen-detect
INSTALL_BIN := $(INSTALL_BIN-y)
-INSTALL_SBIN-y := xm xen-bugtool xen-python-path xend xenperf xsview xenpm xen-tmem-list-parse gtraceview gtracestat xenlockprof xen-hptool
+INSTALL_SBIN-y := xm xen-bugtool xen-python-path xend xenperf xsview xenpm xen-tmem-list-parse gtraceview gtracestat xenlockprof xen-hptool xenwatchdogd
INSTALL_SBIN-$(CONFIG_X86) += xen-hvmctx
INSTALL_SBIN := $(INSTALL_SBIN-y)
@@ -37,8 +37,10 @@ build: $(TARGETS)
install: build
$(INSTALL_DIR) $(DESTDIR)$(BINDIR)
$(INSTALL_DIR) $(DESTDIR)$(SBINDIR)
+ $(INSTALL_DIR) $(DESTDIR)$(CONFIG_DIR)/init.d
$(INSTALL_PYTHON_PROG) $(INSTALL_BIN) $(DESTDIR)$(BINDIR)
$(INSTALL_PYTHON_PROG) $(INSTALL_SBIN) $(DESTDIR)$(SBINDIR)
+ $(INSTALL_PROG) xen-watchdog $(DESTDIR)$(CONFIG_DIR)/init.d
set -e; for d in $(SUBDIRS); do $(MAKE) -C $$d install-recurse; done
.PHONY: clean
@@ -49,7 +51,7 @@ clean:
%.o: %.c $(HDRS) Makefile
$(CC) -c $(CFLAGS) -o $@ $<
-xen-hvmctx xenperf xenpm gtracestat xenlockprof xen-hptool: %: %.o Makefile
+xen-hvmctx xenperf xenpm gtracestat xenlockprof xen-hptool xenwatchdogd: %: %.o Makefile
$(CC) $(CFLAGS) -o $@ $< $(LDFLAGS) $(LDFLAGS_libxenctrl) $(LDFLAGS_libxenguest) $(LDFLAGS_libxenstore)
gtraceview: %: %.o Makefile
diff --git a/tools/misc/xen-watchdog b/tools/misc/xen-watchdog
new file mode 100644
index 0000000000..417b451922
--- /dev/null
+++ b/tools/misc/xen-watchdog
@@ -0,0 +1,59 @@
+#! /bin/bash
+#
+# xen-watchdog
+#
+# chkconfig: 2345 21 79
+# description: Run domain watchdog daemon
+#
+
+# Source function library.
+. /etc/init.d/functions
+
+start() {
+ local r
+ base="watchdogd"
+ echo -n $"Starting domain watchdog daemon: "
+
+ /usr/sbin/xenwatchdogd 30 15
+ r=$?
+ [ "$r" -eq 0 ] && success $"$base startup" || failure $"$base startup"
+ echo
+
+ return $r
+}
+
+stop() {
+ local r
+ base="watchdogd"
+ echo -n $"Stopping domain watchdog daemon: "
+
+ killall -USR1 watchdogd 2>/dev/null
+ r=$?
+ [ "$r" -eq 0 ] && success $"$base stop" || failure $"$base stop"
+ echo
+
+ return $r
+}
+
+case "$1" in
+ start)
+ start
+ ;;
+ stop)
+ stop
+ ;;
+ restart)
+ stop
+ start
+ ;;
+ status)
+ ;;
+ condrestart)
+ stop
+ start
+ ;;
+ *)
+ echo $"Usage: $0 {start|stop|status|restart|condrestart}"
+ exit 1
+esac
+
diff --git a/tools/misc/xenwatchdogd.c b/tools/misc/xenwatchdogd.c
new file mode 100644
index 0000000000..aa96834e5f
--- /dev/null
+++ b/tools/misc/xenwatchdogd.c
@@ -0,0 +1,96 @@
+
+#include <err.h>
+#include <limits.h>
+#include "xenctrl.h"
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <signal.h>
+#include <stdio.h>
+
+xc_interface *h;
+int id = 0;
+
+void daemonize(void)
+{
+ switch (fork()) {
+ case -1:
+ err(1, "fork");
+ case 0:
+ break;
+ default:
+ exit(0);
+ }
+ umask(0);
+ if (setsid() < 0)
+ err(1, "setsid");
+ if (chdir("/") < 0)
+ err(1, "chdir /");
+ freopen("/dev/null", "r", stdin);
+ freopen("/dev/null", "w", stdout);
+ freopen("/dev/null", "w", stderr);
+}
+
+void catch_exit(int sig)
+{
+ if (id)
+ xc_watchdog(h, id, 300);
+ exit(0);
+}
+
+void catch_usr1(int sig)
+{
+ if (id)
+ xc_watchdog(h, id, 0);
+ exit(0);
+}
+
+int main(int argc, char **argv)
+{
+ int t, s;
+ int ret;
+
+ if (argc < 2)
+ errx(1, "usage: %s <timeout> <sleep>", argv[0]);
+
+ daemonize();
+
+ h = xc_interface_open(NULL, NULL, 0);
+ if (h == NULL)
+ err(1, "xc_interface_open");
+
+ t = strtoul(argv[1], NULL, 0);
+ if (t == ULONG_MAX)
+ err(1, "strtoul");
+
+ s = t / 2;
+ if (argc == 3) {
+ s = strtoul(argv[2], NULL, 0);
+ if (s == ULONG_MAX)
+ err(1, "strtoul");
+ }
+
+ if (signal(SIGHUP, &catch_exit) == SIG_ERR)
+ err(1, "signal");
+ if (signal(SIGINT, &catch_exit) == SIG_ERR)
+ err(1, "signal");
+ if (signal(SIGQUIT, &catch_exit) == SIG_ERR)
+ err(1, "signal");
+ if (signal(SIGTERM, &catch_exit) == SIG_ERR)
+ err(1, "signal");
+ if (signal(SIGUSR1, &catch_usr1) == SIG_ERR)
+ err(1, "signal");
+
+ id = xc_watchdog(h, 0, t);
+ if (id <= 0)
+ err(1, "xc_watchdog setup");
+
+ for (;;) {
+ sleep(s);
+ ret = xc_watchdog(h, id, t);
+ if (ret != 0)
+ err(1, "xc_watchdog");
+ }
+}