Blame SOURCES/bz1140921-3-fence_zvm.patch

3340af
commit c5ed2256e572bd06e8bf4ca00d6c891424ae4b00
3340af
Author: Marek 'marx' Grac <mgrac@redhat.com>
3340af
Date:   Thu Oct 23 16:33:26 2014 +0200
3340af
3340af
    fence_zvm: Add support for 'monitor'
3340af
    
3340af
    Author: Neale Ferguson
3340af
3340af
diff --git a/fence/agents/zvm/fence_zvm.c b/fence/agents/zvm/fence_zvm.c
3340af
index 524e21e..2f82e25 100644
3340af
--- a/fence/agents/zvm/fence_zvm.c
3340af
+++ b/fence/agents/zvm/fence_zvm.c
3340af
@@ -51,6 +51,15 @@
3340af
 #define DEFAULT_TIMEOUT 300
3340af
 #define DEFAULT_DELAY   0
3340af
 
3340af
+#define ACT_OFFON 	0
3340af
+#define ACT_OFF		1
3340af
+#define ACT_ON		2
3340af
+#define ACT_METADATA	3
3340af
+#define ACT_STATUS	4
3340af
+#define ACT_MONITOR	5
3340af
+#define ACT_LIST	6
3340af
+#define ACT_HELP	7
3340af
+
3340af
 static int zvm_smapi_reportError(void *, void *);
3340af
 
3340af
 static struct option longopts[] = {
3340af
@@ -64,7 +73,7 @@ static struct option longopts[] = {
3340af
 	{NULL,		0,			NULL, 0}
3340af
 };
3340af
 
3340af
-static char *optString = "a:ho:n:T:";
3340af
+static const char *optString = "a:ho:n:T:";
3340af
 
3340af
 static int zvm_metadata(void);
3340af
 static int usage(void);
3340af
@@ -323,8 +332,7 @@ zvm_smapi_imageActivate(zvm_driver_t *zvm)
3340af
 					rc = 0;
3340af
 				} else {
3340af
 					if ((outPlist->hdr.rc == RCERR_IMAGEOP) &
3340af
-					    ((outPlist->hdr.reason == RS_NOT_ACTIVE) |
3340af
-					     (outPlist->hdr.reason == RS_BEING_DEACT))) {
3340af
+					     (outPlist->hdr.reason == RS_ALREADY_ACTIVE)) {
3340af
 						syslog(LOG_INFO, "Activation of %s successful",
3340af
 						       zvm->target);
3340af
 						rc = 0;
3340af
@@ -649,8 +657,11 @@ zvm_metadata()
3340af
 
3340af
 	fprintf (stdout, "<actions>\n");
3340af
 	fprintf (stdout, "\t<action name=\"off\" />\n");
3340af
-	fprintf (stdout, "\t<action name=\"on\" />\n");
3340af
+	fprintf (stdout, "\t<action name=\"on\" automatic=\"0\" />\n");
3340af
+	fprintf (stdout, "\t<action name=\"list\" />\n");
3340af
 	fprintf (stdout, "\t<action name=\"metadata\" />\n");
3340af
+	fprintf (stdout, "\t<action name=\"monitor\" />\n");
3340af
+	fprintf (stdout, "\t<action name=\"reboot\" />\n");
3340af
 	fprintf (stdout, "\t<action name=\"status\" />\n");
3340af
 	fprintf (stdout, "</actions>\n");
3340af
 
3340af
@@ -675,7 +686,7 @@ get_options_stdin (zvm_driver_t *zvm)
3340af
 	int32_t lSrvName,
3340af
 		lSrvNode,
3340af
 		lTarget;
3340af
-	int	fence = 0;
3340af
+	int	fence = ACT_OFFON;
3340af
 
3340af
 	while (fgets (buf, sizeof (buf), stdin) != 0) {
3340af
 		if (trim(buf) == 0) {
3340af
@@ -698,16 +709,22 @@ get_options_stdin (zvm_driver_t *zvm)
3340af
 			continue;
3340af
 
3340af
 		if (!strcasecmp (opt, "action")) {
3340af
-			if (strcasecmp(arg, "off") == 0) {
3340af
-				fence = 1;
3340af
+			if (strcasecmp(arg, "reboot") == 0) {
3340af
+				fence = ACT_OFFON;
3340af
+			} else if (strcasecmp(arg, "off") == 0) {
3340af
+				fence = ACT_OFF;
3340af
 			} else if (strcasecmp(arg, "on") == 0) {
3340af
-				fence = 2;
3340af
+				fence = ACT_ON;
3340af
 			} else if (strcasecmp(arg, "metadata") == 0) {
3340af
-				fence = 3;
3340af
+				fence = ACT_METADATA;
3340af
 			} else if (strcasecmp(arg, "status") == 0) {
3340af
-				fence = 4;
3340af
+				fence = ACT_STATUS;
3340af
+			} else if (strcasecmp(arg, "monitor") == 0) {
3340af
+				fence = ACT_MONITOR;
3340af
+			} else if (strcasecmp(arg, "list") == 0) {
3340af
+				fence = ACT_LIST;
3340af
 			} else {
3340af
-				fence = 5;
3340af
+				fence = ACT_HELP;
3340af
 			}
3340af
 		} else if (!strcasecmp (opt, "ipaddr")) {
3340af
 			lSrvName = MIN(strlen(arg), sizeof(zvm->smapiSrv));
3340af
@@ -738,7 +755,7 @@ get_options_stdin (zvm_driver_t *zvm)
3340af
 				zvm->delay = DEFAULT_DELAY;
3340af
 			}
3340af
 		} else if (!strcasecmp (opt, "help")) {
3340af
-			fence = 5;
3340af
+			fence = ACT_HELP;
3340af
 		}
3340af
 	}
3340af
 	return(fence);
3340af
@@ -755,7 +772,7 @@ static int
3340af
 get_options(int argc, char **argv, zvm_driver_t *zvm)
3340af
 {
3340af
 	int	c,
3340af
-		fence = 0;
3340af
+		fence = ACT_OFFON;
3340af
 	int32_t	lSrvName,
3340af
 		lSrvNode,
3340af
 		lTarget;
3340af
@@ -768,16 +785,22 @@ get_options(int argc, char **argv, zvm_driver_t *zvm)
3340af
 			memcpy(zvm->target, optarg, lTarget);
3340af
 			break;
3340af
 		case 'o' :
3340af
-			if (strcasecmp(optarg, "off") == 0) {
3340af
-				fence = 1;
3340af
+			if (strcasecmp(optarg, "reboot") == 0) {
3340af
+				fence = ACT_OFFON;
3340af
+			} else if (strcasecmp(optarg, "off") == 0) {
3340af
+				fence = ACT_OFF;
3340af
 			} else if (strcasecmp(optarg, "on") == 0) {
3340af
-				fence = 2;
3340af
+				fence = ACT_ON;
3340af
 			} else if (strcasecmp(optarg, "metadata") == 0) {
3340af
-				fence = 3;
3340af
+				fence = ACT_METADATA;
3340af
 			} else if (strcasecmp(optarg, "status") == 0) {
3340af
-				fence = 4;
3340af
+				fence = ACT_STATUS;
3340af
+			} else if (strcasecmp(optarg, "monitor") == 0) {
3340af
+				fence = ACT_MONITOR;
3340af
+			} else if (strcasecmp(optarg, "list") == 0) {
3340af
+				fence = ACT_LIST;
3340af
 			} else {
3340af
-				fence = 5;
3340af
+				fence = ACT_HELP;
3340af
 			}
3340af
 			break;
3340af
 		case 'a' :
3340af
@@ -807,7 +830,7 @@ get_options(int argc, char **argv, zvm_driver_t *zvm)
3340af
 			memcpy(zvm->node, optarg, lSrvNode);
3340af
 			break;
3340af
 		default :
3340af
-			fence = 5;
3340af
+			fence = ACT_HELP;
3340af
 		}
3340af
 	}
3340af
 	return(fence);
3340af
@@ -822,7 +845,8 @@ usage()
3340af
 {
3340af
 	fprintf(stderr,"Usage: fence_zvm [options]\n\n"
3340af
 		"\tWhere [options] =\n"
3340af
-		"\t-o --action [action] - \"off\", \"on\", \"metadata\", \"status\"\n"
3340af
+		"\t-o --action [action] - \"off\", \"on\", \"list\", \"metadata\", "
3340af
+					 "\"monitor\", \"reboot\", \"status\"\n"
3340af
 		"\t--delay [seconds]    - Time to delay fencing action in seconds\n"
3340af
 		"\t-n --plug [target]   - Name of virtual machine to fence\n"
3340af
 		"\t-a --ip [server]     - Name of SMAPI IUCV Request server\n"
3340af
@@ -874,26 +898,33 @@ main(int argc, char **argv)
3340af
 		fence = get_options_stdin(&zvm);
3340af
 
3340af
 	switch(fence) {
3340af
-		case 0 :	// OFFON
3340af
+		case ACT_OFFON :	// OFFON
3340af
 			if ((rc = check_parm(&zvm)) == 0) 
3340af
 				rc = zvm_smapi_imageRecycle(&zvm);
3340af
 			break;
3340af
-		case 1 :	// OFF
3340af
+		case ACT_OFF :		// OFF
3340af
 			if ((rc = check_parm(&zvm)) == 0)
3340af
 				rc = zvm_smapi_imageDeactivate(&zvm);
3340af
 			break;
3340af
-		case 2 :	// ON
3340af
+		case ACT_ON :		// ON
3340af
 			if ((rc = check_parm(&zvm)) == 0)
3340af
 				rc = zvm_smapi_imageActivate(&zvm);
3340af
 			break;
3340af
-		case 3 :	// METADATA
3340af
+		case ACT_METADATA :	// METADATA
3340af
 			rc = zvm_metadata();
3340af
 			break;
3340af
-		case 4 :	// STATUS
3340af
+		case ACT_STATUS :	// STATUS
3340af
 			if ((rc = check_parm(&zvm)) == 0)
3340af
 				rc = zvm_smapi_imageQuery(&zvm);
3340af
 			break;
3340af
-		case 5 :
3340af
+		case ACT_MONITOR :	// MONITOR
3340af
+			rc = 0;
3340af
+			break;
3340af
+		case ACT_LIST :		// LIST
3340af
+			printf("N/A");
3340af
+			rc = 0;
3340af
+			break;
3340af
+		case ACT_HELP :
3340af
 			rc = usage();
3340af
 	}
3340af
 	closelog();
3340af
diff --git a/fence/agents/zvm/fence_zvmip.c b/fence/agents/zvm/fence_zvmip.c
3340af
index bd7c536..b16de48 100644
3340af
--- a/fence/agents/zvm/fence_zvmip.c
3340af
+++ b/fence/agents/zvm/fence_zvmip.c
3340af
@@ -50,6 +50,15 @@
3340af
 #define DEFAULT_TIMEOUT 300
3340af
 #define DEFAULT_DELAY	0
3340af
 
3340af
+#define ACT_OFFON 	0
3340af
+#define ACT_OFF		1
3340af
+#define ACT_ON		2
3340af
+#define ACT_METADATA	3
3340af
+#define ACT_STATUS	4
3340af
+#define ACT_MONITOR	5
3340af
+#define ACT_LIST	6
3340af
+#define ACT_HELP	7
3340af
+
3340af
 static int zvm_smapi_reportError(void *, void *);
3340af
 
3340af
 static struct option longopts[] = {
3340af
@@ -64,7 +73,7 @@ static struct option longopts[] = {
3340af
 	{NULL,		0,			NULL, 0}
3340af
 };
3340af
 
3340af
-static char *optString = "a:o:hn:p:t:u:";
3340af
+static const char *optString = "a:o:hn:p:t:u:";
3340af
 
3340af
 static int zvm_metadata(void);
3340af
 static int usage(void);
3340af
@@ -376,8 +385,7 @@ zvm_smapi_imageActivate(zvm_driver_t *zvm)
3340af
 					rc = 0;
3340af
 				} else {
3340af
 					if ((outPlist->hdr.rc == RCERR_IMAGEOP) &
3340af
-					    ((outPlist->hdr.reason == RS_NOT_ACTIVE) |
3340af
-					     (outPlist->hdr.reason == RS_BEING_DEACT))) {
3340af
+					     (outPlist->hdr.reason == RS_ALREADY_ACTIVE)) {
3340af
 						syslog(LOG_INFO, "Activation of %s successful",
3340af
 						       zvm->target);
3340af
 						rc = 0;
3340af
@@ -653,7 +661,7 @@ get_options_stdin (zvm_driver_t *zvm)
3340af
 		*arg;
3340af
 	int32_t lSrvName,
3340af
 		lTarget;
3340af
-	int	fence = 0;
3340af
+	int	fence = ACT_OFFON;
3340af
 
3340af
 	while (fgets (buf, sizeof (buf), stdin) != 0) {
3340af
 		if (trim(buf) == 0) {
3340af
@@ -676,16 +684,22 @@ get_options_stdin (zvm_driver_t *zvm)
3340af
 			continue;
3340af
 
3340af
 		if (!strcasecmp (opt, "action")) {
3340af
-			if (strcasecmp(arg, "off") == 0) {
3340af
-				fence = 1;
3340af
+			if (strcasecmp(arg, "reboot") == 0) {
3340af
+				fence = ACT_OFFON;
3340af
+			} else if (strcasecmp(arg, "off") == 0) {
3340af
+				fence = ACT_OFF;
3340af
 			} else if (strcasecmp(arg, "on") == 0) {
3340af
-				fence = 2;
3340af
+				fence = ACT_ON;
3340af
 			} else if (strcasecmp(arg, "metadata") == 0) {
3340af
-				fence = 3;
3340af
+				fence = ACT_METADATA;
3340af
 			} else if (strcasecmp(arg, "status") == 0) {
3340af
-				fence = 4;
3340af
+				fence = ACT_STATUS;
3340af
+			} else if (strcasecmp(arg, "monitor") == 0) {
3340af
+				fence = ACT_MONITOR;
3340af
+			} else if (strcasecmp(arg, "list") == 0) {
3340af
+				fence = ACT_LIST;
3340af
 			} else {
3340af
-				fence = 5;
3340af
+				fence = ACT_HELP;
3340af
 			}
3340af
 		} else if (!strcasecmp (opt, "ipaddr")) {
3340af
 			lSrvName = MIN(strlen(arg), sizeof(zvm->smapiSrv)-1);
3340af
@@ -712,7 +726,7 @@ get_options_stdin (zvm_driver_t *zvm)
3340af
 				zvm->timeOut = DEFAULT_TIMEOUT;
3340af
 			}
3340af
 		} else if (!strcasecmp (opt, "help")) {
3340af
-			fence = 5;
3340af
+			fence = ACT_HELP;
3340af
 		}
3340af
 	}
3340af
 	return(fence);
3340af
@@ -729,7 +743,7 @@ static int
3340af
 get_options(int argc, char **argv, zvm_driver_t *zvm)
3340af
 {
3340af
 	int	c,
3340af
-		fence = 0;
3340af
+		fence = ACT_OFFON;
3340af
 	int32_t	lSrvName,
3340af
 		lTarget;
3340af
 	char	*endPtr;
3340af
@@ -745,16 +759,22 @@ get_options(int argc, char **argv, zvm_driver_t *zvm)
3340af
 			memcpy(zvm->target, optarg, lTarget);
3340af
 			break;
3340af
 		case 'o' :
3340af
-			if (strcasecmp(optarg, "off") == 0) {
3340af
-				fence = 1;
3340af
+			if (strcasecmp(optarg, "reboot") == 0) {
3340af
+				fence = ACT_OFFON;
3340af
+			} else if (strcasecmp(optarg, "off") == 0) {
3340af
+				fence = ACT_OFF;
3340af
 			} else if (strcasecmp(optarg, "on") == 0) {
3340af
-				fence = 2;
3340af
+				fence = ACT_ON;
3340af
 			} else if (strcasecmp(optarg, "metadata") == 0) {
3340af
-				fence = 3;
3340af
+				fence = ACT_METADATA;
3340af
 			} else if (strcasecmp(optarg, "status") == 0) {
3340af
-				fence = 4;
3340af
+				fence = ACT_STATUS;
3340af
+			} else if (strcasecmp(optarg, "monitor") == 0) {
3340af
+				fence = ACT_MONITOR;
3340af
+			} else if (strcasecmp(optarg, "list") == 0) {
3340af
+				fence = ACT_LIST;
3340af
 			} else {
3340af
-				fence = 5;
3340af
+				fence = ACT_HELP;
3340af
 			}
3340af
 			break;
3340af
 		case 'p' :
3340af
@@ -784,7 +804,7 @@ get_options(int argc, char **argv, zvm_driver_t *zvm)
3340af
 			}
3340af
 			break;
3340af
 		default :
3340af
-			fence = 5;
3340af
+			fence = ACT_HELP;
3340af
 		}
3340af
 	}
3340af
 	return(fence);
3340af
@@ -861,9 +881,12 @@ zvm_metadata()
3340af
 
3340af
 	fprintf (stdout, "<actions>\n");
3340af
 	fprintf (stdout, "\t<action name=\"off\" />\n");
3340af
-	fprintf (stdout, "\t<action name=\"on\" />\n");
3340af
+	fprintf (stdout, "\t<action name=\"on\" automatic=\"0\" />\n");
3340af
+	fprintf (stdout, "\t<action name=\"list\" />\n");
3340af
 	fprintf (stdout, "\t<action name=\"metadata\" />\n");
3340af
+	fprintf (stdout, "\t<action name=\"monitor\" />\n");
3340af
 	fprintf (stdout, "\t<action name=\"status\" />\n");
3340af
+	fprintf (stdout, "\t<action name=\"reboot\" />\n");
3340af
 	fprintf (stdout, "</actions>\n");
3340af
 
3340af
 	fprintf (stdout, "</resource-agent>\n");
3340af
@@ -881,7 +904,8 @@ usage()
3340af
 {
3340af
 	fprintf(stderr,"Usage: fence_zvmip [options]\n\n"
3340af
 		"\tWhere [options] =\n"
3340af
-		"\t-o --action [action] - \"off\", \"on\", \"metadata\", \"status\"\n"
3340af
+		"\t-o --action [action] - \"off\", \"on\", \"list\", \"metadata\", "
3340af
+					 "\"monitor\", \"reboot\", \"status\"\n"
3340af
 		"\t--delay [seconds]    - Time to delay fencing action in seconds\n"
3340af
 		"\t-n --plug [target]   - Name of virtual machine to fence\n"
3340af
 		"\t-a --ip [server]     - IP Name/Address of SMAPI Server\n"
3340af
@@ -944,26 +968,32 @@ main(int argc, char **argv)
3340af
 		fence = get_options_stdin(&zvm);
3340af
 
3340af
 	switch(fence) {
3340af
-		case 0 :	// OFFON
3340af
+		case ACT_OFFON :	// OFFON
3340af
 			if ((rc = check_parm(&zvm)) == 0)
3340af
 				rc = zvm_smapi_imageRecycle(&zvm);
3340af
 			break;
3340af
-		case 1 :	// OFF
3340af
+		case ACT_OFF :		// OFF
3340af
 			if ((rc = check_parm(&zvm)) == 0)
3340af
 				rc = zvm_smapi_imageDeactivate(&zvm);
3340af
 			break;
3340af
-		case 2 :	// ON
3340af
+		case ACT_ON :		// ON
3340af
 			if ((rc = check_parm(&zvm)) == 0)
3340af
 				rc = zvm_smapi_imageActivate(&zvm);
3340af
 			break;
3340af
-		case 3 :	// METADATA
3340af
+		case ACT_METADATA :	// METADATA
3340af
 			rc = zvm_metadata();
3340af
 			break;
3340af
-		case 4 :	// STATUS
3340af
+		case ACT_STATUS :	// STATUS
3340af
 			if ((rc = check_parm(&zvm)) == 0)
3340af
 				rc = zvm_smapi_imageQuery(&zvm);
3340af
 			break;
3340af
-		case 5 :
3340af
+		case ACT_MONITOR :	// MONITOR
3340af
+			rc = 0;
3340af
+			break;
3340af
+		case ACT_LIST :
3340af
+			printf("N/A");
3340af
+			break;
3340af
+		case ACT_HELP :
3340af
 			rc = usage();
3340af
 	}
3340af
 	closelog();
3340af
diff --git a/tests/data/metadata/fence_zvmip.xml b/tests/data/metadata/fence_zvmip.xml
3340af
index 1e098d1..7791303 100644
3340af
--- a/tests/data/metadata/fence_zvmip.xml
3340af
+++ b/tests/data/metadata/fence_zvmip.xml
3340af
@@ -41,8 +41,11 @@
3340af
 </parameters>
3340af
 <actions>
3340af
 	<action name="off" />
3340af
-	<action name="on" />
3340af
+	<action name="on" automatic="0" />
3340af
+	<action name="list" />
3340af
 	<action name="metadata" />
3340af
+	<action name="monitor" />
3340af
 	<action name="status" />
3340af
+	<action name="reboot" />
3340af
 </actions>
3340af
 </resource-agent>