[Cluster-devel] cluster/fence/agents/xvm Makefile fence_xvm.c ...

lhh at sourceware.org lhh at sourceware.org
Fri Nov 3 15:58:58 UTC 2006


CVSROOT:	/cvs/cluster
Module name:	cluster
Changes by:	lhh at sourceware.org	2006-11-03 15:58:56

Modified files:
	fence/agents/xvm: Makefile fence_xvm.c fence_xvmd.c options.c 
	                  virt.c 

Log message:
	Fix bugzillas #212444, #212433

Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/cluster/fence/agents/xvm/Makefile.diff?cvsroot=cluster&r1=1.2&r2=1.3
http://sourceware.org/cgi-bin/cvsweb.cgi/cluster/fence/agents/xvm/fence_xvm.c.diff?cvsroot=cluster&r1=1.2&r2=1.3
http://sourceware.org/cgi-bin/cvsweb.cgi/cluster/fence/agents/xvm/fence_xvmd.c.diff?cvsroot=cluster&r1=1.3&r2=1.4
http://sourceware.org/cgi-bin/cvsweb.cgi/cluster/fence/agents/xvm/options.c.diff?cvsroot=cluster&r1=1.1&r2=1.2
http://sourceware.org/cgi-bin/cvsweb.cgi/cluster/fence/agents/xvm/virt.c.diff?cvsroot=cluster&r1=1.2&r2=1.3

--- cluster/fence/agents/xvm/Makefile	2006/10/05 22:57:47	1.2
+++ cluster/fence/agents/xvm/Makefile	2006/11/03 15:58:56	1.3
@@ -27,10 +27,10 @@
 	-I../../../cman/lib
 
 CFLAGS+=-DFENCE_RELEASE_NAME=\"${RELEASE}\" \
-	-Wall -Werror -Wstrict-prototypes -Wshadow -ggdb
+	-Wall -Werror -Wstrict-prototypes -Wshadow -ggdb -D_GNU_SOURCE
 
 LIBS+=-L../../../cman/lib -L../../../ccs/lib -L${libdir}/openais \
-      -L../../../dlm/lib -lccs -lcman -ldlm -lnss3 -lvirt -lSaCkpt
+      -L../../../dlm/lib -lnss3
 
 all: ${TARGETS}
 
@@ -38,7 +38,7 @@
 	gcc -o $@ $^ $(LIBS)
 
 fence_xvmd: ${fence_xvmd_SOURCE:.c=.o}
-	gcc -o $@ $^ $(LIBS)
+	gcc -o $@ $^ $(LIBS) -lvirt -lccs -lcman -lSaCkpt
 
 %.o: %.c
 	gcc $(CFLAGS) -c -o $@ $^ $(INCLUDES)
--- cluster/fence/agents/xvm/fence_xvm.c	2006/10/05 18:48:58	1.2
+++ cluster/fence/agents/xvm/fence_xvm.c	2006/11/03 15:58:56	1.3
@@ -47,7 +47,7 @@
 #include <nss.h>
 
 /* Local includes */
-#include "virt.h"
+#include "xvm.h"
 #include "ip_lookup.h"
 #include "simple_auth.h"
 #include "options.h"
--- cluster/fence/agents/xvm/fence_xvmd.c	2006/10/05 22:57:47	1.3
+++ cluster/fence/agents/xvm/fence_xvmd.c	2006/11/03 15:58:56	1.4
@@ -24,6 +24,7 @@
 #include <string.h>
 #include <unistd.h>
 #include <signal.h>
+#include <string.h>
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <sys/wait.h>
@@ -164,6 +165,45 @@
 }
 
 
+/*
+   Nuke the OS block if this domain was booted using a bootloader.
+   XXX We probably should use libxml2 to do this, but this is very fast
+ */
+void
+cleanup_xmldesc(char *xmldesc)
+{
+	char *start = NULL;
+	char *end = NULL;
+
+#define STARTBOOTTAG "<bootloader>"
+#define ENDBOOTTAG   "</bootloader>"
+#define STARTOSTAG   "<os>"
+#define ENDOSTAG     "</os>"
+
+	/* Part 1: Check for a boot loader */
+	start = strcasestr(xmldesc, STARTBOOTTAG);
+	if (start) {
+		start += strlen(STARTBOOTTAG);
+		end = strcasestr(start, ENDBOOTTAG);
+		if (end == start) {
+			/* Empty bootloader tag -> return */
+			return;
+		}
+	}
+
+	/* Part 2: Nuke the <os> tag */
+	start = strcasestr(xmldesc, STARTOSTAG);
+	if (!start)
+		return;
+	end = strcasestr(start, ENDOSTAG);
+	if (!end)
+		return;
+	end += strlen(ENDOSTAG);
+
+	memset(start, ' ', end-start);
+}
+
+
 int
 do_fence_request_tcp(fence_req_t *req, fence_auth_type_t auth,
 		     void *key, size_t key_len, virConnectPtr vp)
@@ -211,6 +251,9 @@
 		printf("Rebooting domain %s...\n",
 		       (char *)req->domain);
 		domain_desc = virDomainGetXMLDesc(vdp, 0);
+
+		if (domain_desc)
+			cleanup_xmldesc(domain_desc);
 		ret = virDomainDestroy(vdp);
 		if (ret < 0) {
 			if (domain_desc)
@@ -218,7 +261,7 @@
 			break;
 		} else {
 			/* Give it time for the operation to complete */
-			sleep(1);
+			sleep(3);
 		}
 
 		/* Check domain liveliness.  If the domain is still here,
--- cluster/fence/agents/xvm/options.c	2006/10/05 16:11:36	1.1
+++ cluster/fence/agents/xvm/options.c	2006/11/03 15:58:56	1.2
@@ -299,7 +299,7 @@
 	  assign_key },
 
 	{ 'o', "-o <operation>", "option",
-	  "Fencing operation (null, [off], reboot)",
+	  "Fencing operation (null, off, [reboot])",
 	  assign_op },
 
 	{ 'H', "-H <domain>", "domain",
@@ -375,7 +375,7 @@
 	args->addr = NULL;
 	args->domain = NULL;
 	args->key_file = DEFAULT_KEY_FILE;
-	args->op = FENCE_OFF;
+	args->op = FENCE_REBOOT;
 	args->hash = DEFAULT_HASH;
 	args->auth = DEFAULT_AUTH;
 	args->port = 1229;
--- cluster/fence/agents/xvm/virt.c	2006/10/05 22:57:47	1.2
+++ cluster/fence/agents/xvm/virt.c	2006/11/03 15:58:56	1.3
@@ -176,25 +176,15 @@
 virt_state_t *
 vl_find_name(virt_list_t *vl, char *name)
 {
-	int b,e,x,y;
+	int x;
 
 	if (!vl || !name || !vl->vm_count)
 		return NULL;
 
-	b = 0;
-	e = vl->vm_count;
-
-	do {
-		x = (b + e) / 2;
-		y = strcasecmp(vl->vm_states[x].v_name, name);
-		if (y == 0) {
+	for (x = 0; x < vl->vm_count; x++) {
+		if (!strcasecmp(vl->vm_states[x].v_name, name))
 			return &vl->vm_states[x];
-		} else if (y < 0) {
-			e = x;
-		} else {
-			b = x;
-		}
-	} while (b != e);
+	}
 
 	return NULL;
 }




More information about the Cluster-devel mailing list