Re: [Cluster-devel] [PATCH] dlm_stonith_{off, reboot} aliases for fence helper

2012-11-05 Thread Jacek Konieczny
On Mon, Nov 05, 2012 at 02:30:33PM -0500, David Teigland wrote:
> On Mon, Nov 05, 2012 at 07:05:22PM +0100, Jacek Konieczny wrote:
> > -   rv = stonith_api_kick_helper(nodeid, 300, 1);
> > +   rv = stonith_api_kick_helper(nodeid, 300, turn_off);
> 
> I'd like it to be "reboot", but seeing the arg as "bool off" I figured the
> opposite would be "on" ... if you're saying that the opposite of off is
> actually reboot, then I'll just make it 0.

If it is 'off' by mistake and not for any better reason, then I think
this will be the best – to make this '0' by default. I have verified the
Pacemaker sources twice – 'off=0' means 'reboot'.

Effort to make this configurable may be postponed until anybody is
interested in fencing by power-off.

Greets,
Jacek



Re: [Cluster-devel] [PATCH] dlm_stonith_{off, reboot} aliases for fence helper

2012-11-05 Thread David Teigland
On Mon, Nov 05, 2012 at 07:05:22PM +0100, Jacek Konieczny wrote:
> - rv = stonith_api_kick_helper(nodeid, 300, 1);
> + rv = stonith_api_kick_helper(nodeid, 300, turn_off);

I'd like it to be "reboot", but seeing the arg as "bool off" I figured the
opposite would be "on" ... if you're saying that the opposite of off is
actually reboot, then I'll just make it 0.




[Cluster-devel] [PATCH] dlm_stonith_{off, reboot} aliases for fence helper

2012-11-05 Thread Jacek Konieczny
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 
---
 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