Not so pretty hack to allow rebooting instead of halting
the node fenced by dlm_stonith.

'dlm_stonith_reboot' can be now used instead of 'dlm_stonith'
in the dlm.conf file to request node reboot.

'dlm_stonith_off' alias is also provided to explicitly request
power-off.

Signed-off-by: Jacek Konieczny <[email protected]>
---
 fence/Makefile         |   10 +++++++++-
 fence/stonith_helper.c |    8 +++++++-
 2 files changed, 16 insertions(+), 2 deletions(-)

diff --git a/fence/Makefile b/fence/Makefile
index b4c59dd..2f24677 100644
--- a/fence/Makefile
+++ b/fence/Makefile
@@ -6,6 +6,8 @@ BINDIR=$(PREFIX)/sbin
 BIN_TARGET = dlm_stonith
 #MAN_TARGET = dlm_stonith.8
 
+SYMLINKS = dlm_stonith_off dlm_stonith_reboot
+
 BIN_SOURCE = stonith_helper.c
 
 BIN_CFLAGS += -D_GNU_SOURCE -O2 -ggdb \
@@ -37,11 +39,14 @@ BIN_LDFLAGS += -Wl,-z,now -Wl,-z,relro -pie
 BIN_LDFLAGS += `xml2-config --libs`
 BIN_LDFLAGS += -ldl
 
-all: $(BIN_TARGET)
+all: $(BIN_TARGET) $(SYMLINKS)
 
 $(BIN_TARGET): $(BIN_SOURCE)
        $(CC) $(BIN_SOURCE) $(BIN_CFLAGS) $(BIN_LDFLAGS) -o $@ -L.
 
+$(SYMLINKS): $(BIN_TARGET)
+       for link in $(SYMLINKS) ; do ln -sf $(BIN_TARGET) $$link ; done
+
 clean:
        rm -f *.o *.so *.so.* $(BIN_TARGET)
 
@@ -53,5 +58,8 @@ install: all
        $(INSTALL) -d $(DESTDIR)/$(BINDIR)
        $(INSTALL) -d $(DESTDIR)/$(MANDIR)/man8
        $(INSTALL) -c -m 755 $(BIN_TARGET) $(DESTDIR)/$(BINDIR)
+       for link in $(SYMLINKS) ; do \
+               ln -sf $(BIN_TARGET) $(DESTDIR)/$(BINDIR)/$$link ; \
+       done
 #      $(INSTALL) -m 644 $(MAN_TARGET) $(DESTDIR)/$(MANDIR)/man8/
 
diff --git a/fence/stonith_helper.c b/fence/stonith_helper.c
index 5b384c1..73a2245 100644
--- a/fence/stonith_helper.c
+++ b/fence/stonith_helper.c
@@ -16,6 +16,7 @@
 
 int nodeid;
 uint64_t fail_time;
+int turn_off = 1;
 
 #define MAX_ARG_LEN 1024
 
@@ -26,6 +27,11 @@ static int get_options(int argc, char *argv[])
        char val[MAX_ARG_LEN];
        char c;
        int rv;
+       int arg0_l;
+
+       arg0_l = strlen(argv[0]);
+       if (arg0_l>7 && !strcmp(argv[0] + arg0_l - 7, "_reboot")) turn_off = 0;
+       else if (arg0_l>4 && !strcmp(argv[0] + arg0_l - 4, "_off")) turn_off = 
1;
 
        if (argc > 1) {
                while ((c = getopt(argc, argv, "n:t:")) != -1) {
@@ -77,7 +83,7 @@ int main(int argc, char *argv[])
        if (t >= fail_time)
                return 0;
 
-       rv = stonith_api_kick_helper(nodeid, 300, 1);
+       rv = stonith_api_kick_helper(nodeid, 300, turn_off);
        if (rv) {
                fprintf(stderr, "kick_helper error %d nodeid %d\n", rv, nodeid);
                openlog("stonith_helper", LOG_CONS | LOG_PID, LOG_DAEMON);
-- 
1.7.7.4

Reply via email to