public inbox for cluster-cvs@sourceware.org
help / color / mirror / Atom feed
* cluster: STABLE2 - fence: IPMI over lan timeout adjusted and configurable
@ 2008-11-19 17:07 Jan Friesse
  0 siblings, 0 replies; only message in thread
From: Jan Friesse @ 2008-11-19 17:07 UTC (permalink / raw)
  To: cluster-cvs-relay

Gitweb:        http://git.fedorahosted.org/git/cluster.git?p=cluster.git;a=commitdiff;h=59229fddbf3c15c2279e4841c443e7a60a6799a6
Commit:        59229fddbf3c15c2279e4841c443e7a60a6799a6
Parent:        6f11a5cb225a9547a18440e9129410c32aa2be3f
Author:        Jan Friesse <jfriesse@redhat.com>
AuthorDate:    Wed Nov 19 17:50:03 2008 +0100
Committer:     Jan Friesse <jfriesse@redhat.com>
CommitterDate: Wed Nov 19 18:03:50 2008 +0100

fence: IPMI over lan timeout adjusted and configurable

This patch adjust timeout to default value 10s which
should be enough for most today IPMI implementations.
It also removes retries, because this job is done
by fenced.

Because some devices still need longer timeouts,
timeout is adjustable by parameter -t (or timeout for stdin
and XML configuration).

This should fix BZ: 401481, 276541 and 452894
---
 fence/agents/ipmilan/ipmilan.c |   50 ++++++++++++++++++++--------------------
 1 files changed, 25 insertions(+), 25 deletions(-)

diff --git a/fence/agents/ipmilan/ipmilan.c b/fence/agents/ipmilan/ipmilan.c
index 3b4987b..117228c 100644
--- a/fence/agents/ipmilan/ipmilan.c
+++ b/fence/agents/ipmilan/ipmilan.c
@@ -26,6 +26,8 @@
 #define ST_POWEROFF 2
 #define ST_GENERIC_RESET 3
 
+#define DEFAULT_TIMEOUT 10
+
 #define log(lvl, fmt, args...) fprintf(stderr, fmt, ##args)
 #include <libgen.h>
 #include <copyright.cf>
@@ -59,6 +61,7 @@ struct ipmi {
 	int i_config;
 	int i_verbose;
 	int i_lanplus;
+	int i_timeout;
 };
 
 
@@ -276,42 +279,25 @@ static int
 ipmi_op(struct ipmi *ipmi, int op, struct Etoken *toklist)
 {
 	char cmd[2048];
-	int retries = 5; 
 	int ret;
 
 	build_cmd(cmd, sizeof(cmd), ipmi, op);
 
 	if (ipmi_spawn(ipmi, cmd) != 0)
 		return -1;
-	ret = ipmi_expect(ipmi, toklist, 120);
+	ret = ipmi_expect(ipmi, toklist, ipmi->i_timeout);
 	ipmi_reap(ipmi);
 
-	while ((ret == EAGAIN || ret == ETIMEDOUT) && retries > 0) {
-		dbg_printf(ipmi, 3, "Sleeping 5 ...\n");
-		sleep(5);
-		dbg_printf(ipmi, 1, "Retrying ...\n");
-		--retries;
-		
-		if (ipmi_spawn(ipmi, cmd) != 0)
-			return -1;
-		ret = ipmi_expect(ipmi, toklist, 120);
-		if (ret == EFAULT) {
-			/* Doomed. */
-			break;
-		}
-		ipmi_reap(ipmi);
-	}
-
 	if (ret == EFAULT) {
 		log(LOG_CRIT, "ipmilan: ipmitool failed to create "
 		    "mutex; unable to complete operation\n");
 		return ret;
 	}
 
-	if (ret == EAGAIN) {
+	if (ret == ETIMEDOUT) {
 		/*!!! Still couldn't get through?! */
 		log(LOG_WARNING,
-		    "ipmilan: Failed to connect after 30 seconds\n");
+		    "ipmilan: Failed to connect after %d seconds\n",ipmi->i_timeout);
 	}
 
 	return ret;
@@ -432,7 +418,7 @@ ipmi_destroy(struct ipmi *i)
  */
 static struct ipmi *
 ipmi_init(struct ipmi *i, char *host, char *authtype,
-	  char *user, char *password, int lanplus, int verbose)
+	  char *user, char *password, int lanplus, int verbose,int timeout)
 {
 	const char *p;
 
@@ -503,6 +489,7 @@ ipmi_init(struct ipmi *i, char *host, char *authtype,
 	i->i_id = IPMIID;
 	i->i_verbose = verbose;
 	i->i_lanplus = lanplus;
+	i->i_timeout = timeout;
 
 	return i;
 }
@@ -565,7 +552,7 @@ get_options_stdin(char *ip, size_t iplen,
 		  char *pwd_script, size_t pwd_script_len,
 		  char *user, size_t userlen,
 		  char *op, size_t oplen,
-		  int *lanplus, int *verbose)
+		  int *lanplus, int *verbose,int *timeout)
 {
 	char in[256];
 	int line = 0;
@@ -627,6 +614,10 @@ get_options_stdin(char *ip, size_t iplen,
 				user[0] = 0;
 		} else if (!strcasecmp(name, "lanplus")) {
 			(*lanplus) = 1;
+		} else if (!strcasecmp(name,"timeout")) {
+			if ((sscanf(val,"%d",timeout)!=1) || *timeout<1) {
+			    *timeout=DEFAULT_TIMEOUT;
+			}
 		} else if (!strcasecmp(name, "option") ||
 			   !strcasecmp(name, "operation") ||
 			   !strcasecmp(name, "action")) {
@@ -666,6 +657,7 @@ printf("   -l <login>     Username/Login (if required) to control power\n"
        "                  on IPMI device\n");
 printf("   -o <op>        Operation to perform.\n");
 printf("                  Valid operations: on, off, reboot, status\n");
+printf("   -t <timeout>   Timeout (sec) for IPMI operation (default %d)\n",DEFAULT_TIMEOUT);
 printf("   -V             Print version and exit\n");
 printf("   -v             Verbose mode\n\n");
 printf("If no options are specified, the following options will be read\n");
@@ -679,6 +671,7 @@ printf("   login=<login>         Same as -u\n");
 printf("   option=<op>           Same as -o\n");
 printf("   operation=<op>        Same as -o\n");
 printf("   action=<op>           Same as -o\n");
+printf("   timeout=<timeout>     Same as -t\n");
 printf("   verbose               Same as -v\n\n");
 	exit(1);
 }
@@ -699,6 +692,7 @@ main(int argc, char **argv)
 	int verbose=0;
 	char *pname = basename(argv[0]);
 	struct ipmi *i;
+	int timeout=DEFAULT_TIMEOUT;
 
 	memset(ip, 0, sizeof(ip));
 	memset(authtype, 0, sizeof(authtype));
@@ -710,7 +704,7 @@ main(int argc, char **argv)
 		/*
 		   Parse command line options if any were specified
 		 */
-		while ((opt = getopt(argc, argv, "A:a:i:l:p:S:Po:vV?hH")) != EOF) {
+		while ((opt = getopt(argc, argv, "A:a:i:l:p:S:Po:vV?hHt:")) != EOF) {
 			switch(opt) {
 			case 'A':
 				/* Auth type */
@@ -740,6 +734,12 @@ main(int argc, char **argv)
 				/* Operation */
 				strncpy(op, optarg, sizeof(op));
 				break;
+			case 't':
+				/* Timeout */
+				if ((sscanf(optarg,"%d",&timeout)!=1) || timeout<1) {
+				    fail_exit("Timeout option expects positive number parameter");
+				}
+				break;
 			case 'v':
 				verbose++;
 				break;
@@ -763,7 +763,7 @@ main(int argc, char **argv)
 				      passwd, sizeof(passwd),
 					  pwd_script, sizeof(pwd_script),
 				      user, sizeof(user),
-				      op, sizeof(op), &lanplus, &verbose) != 0)
+				      op, sizeof(op), &lanplus, &verbose,&timeout) != 0)
 			return 1;
 	}
 
@@ -813,7 +813,7 @@ main(int argc, char **argv)
 
 
 	/* Ok, set up the IPMI struct */
-	i = ipmi_init(NULL, ip, authtype, user, passwd, lanplus, verbose);
+	i = ipmi_init(NULL, ip, authtype, user, passwd, lanplus, verbose, timeout);
 	if (!i)
 		fail_exit("Failed to initialize\n");
 


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2008-11-19 17:07 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-11-19 17:07 cluster: STABLE2 - fence: IPMI over lan timeout adjusted and configurable Jan Friesse

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).