[Cluster-devel] conga/ricci/modules/cluster ClusterConf.cpp Cl ...

rmccabe at sourceware.org rmccabe at sourceware.org
Wed Aug 22 18:47:21 UTC 2007


CVSROOT:	/cvs/cluster
Module name:	conga
Changes by:	rmccabe at sourceware.org	2007-08-22 18:47:20

Modified files:
	ricci/modules/cluster: ClusterConf.cpp ClusterStatus.cpp 
	                       Clusvcadm.cpp Fence.cpp Virt.cpp 
	ricci/modules/cluster/clumon/src/daemon: Monitor.cpp main.cpp 

Log message:
	- Return more useful error information when a command fails.
	- Some other minor cleanups.

Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/conga/ricci/modules/cluster/ClusterConf.cpp.diff?cvsroot=cluster&r1=1.9&r2=1.10
http://sourceware.org/cgi-bin/cvsweb.cgi/conga/ricci/modules/cluster/ClusterStatus.cpp.diff?cvsroot=cluster&r1=1.19&r2=1.20
http://sourceware.org/cgi-bin/cvsweb.cgi/conga/ricci/modules/cluster/Clusvcadm.cpp.diff?cvsroot=cluster&r1=1.13&r2=1.14
http://sourceware.org/cgi-bin/cvsweb.cgi/conga/ricci/modules/cluster/Fence.cpp.diff?cvsroot=cluster&r1=1.4&r2=1.5
http://sourceware.org/cgi-bin/cvsweb.cgi/conga/ricci/modules/cluster/Virt.cpp.diff?cvsroot=cluster&r1=1.3&r2=1.4
http://sourceware.org/cgi-bin/cvsweb.cgi/conga/ricci/modules/cluster/clumon/src/daemon/Monitor.cpp.diff?cvsroot=cluster&r1=1.14&r2=1.15
http://sourceware.org/cgi-bin/cvsweb.cgi/conga/ricci/modules/cluster/clumon/src/daemon/main.cpp.diff?cvsroot=cluster&r1=1.4&r2=1.5

--- conga/ricci/modules/cluster/ClusterConf.cpp	2006/12/10 18:58:46	1.9
+++ conga/ricci/modules/cluster/ClusterConf.cpp	2007/08/22 18:47:19	1.10
@@ -1,5 +1,5 @@
 /*
-  Copyright Red Hat, Inc. 2005
+  Copyright Red Hat, Inc. 2005-2007
 
   This program is free software; you can redistribute it and/or modify it
   under the terms of the GNU General Public License as published by the
@@ -60,12 +60,12 @@
   
   // sanity check
   if (xml.tag() != "cluster")
-    throw String("invalid cluster.conf");
+    throw String("invalid cluster.conf: no cluster tag");
   if (xml.get_attr("name").empty())
-    throw String("invalid cluster.conf");
+    throw String("invalid cluster.conf: no cluster name attribute");
   long long conf_version = utils::to_long(xml.get_attr("config_version"));
   if (conf_version == 0)
-    throw String("invalid cluster.conf");
+    throw String("invalid cluster.conf: no config_version attribute");
   
   // create dir, if not existing
   DIR* dir = opendir(CLUSTER_CONF_DIR.c_str());
@@ -75,9 +75,9 @@
     if (errno == ENOENT) {
       if (mkdir(CLUSTER_CONF_DIR.c_str(), 
 		S_IRWXU|S_IRGRP|S_IXGRP|S_IROTH|S_IXOTH))
-	throw String("failed to create ") + CLUSTER_CONF_DIR;      
+	throw String("failed to create ") + CLUSTER_CONF_DIR + ": " + String(strerror(errno));
     } else
-      throw String("opendir() error");
+      throw String("opendir() error: ") + String(strerror(errno));
   }
   
   // save tmp cluster.conf
@@ -98,7 +98,7 @@
       if (utils::execute(CCS_TOOL_PATH, args, out, err, status, false))
 	throw command_not_found_error_msg(CCS_TOOL_PATH);
       if (status != 0)
-	throw String("ccs_tool failed");
+	throw String("ccs_tool failed: ") + err;
       
       if (is_cman(xml)) {
 	args.clear();
@@ -108,7 +108,7 @@
 	if (utils::execute(CMAN_TOOL_PATH, args, out, err, status, false))
 	  throw command_not_found_error_msg(CMAN_TOOL_PATH);
 	if (status != 0)
-	  throw String("cman_tool failed");
+	  throw String("cman_tool failed: ") + err;
       }
       
       unlink(tmp_path.c_str());
@@ -118,8 +118,9 @@
     }
   } else {
     if (rename(tmp_path.c_str(), CLUSTER_CONF_PATH.c_str())) {
+	  int errnold = errno;
       unlink(tmp_path.c_str());
-      throw String("failed to rename cluster.conf");
+      throw String("failed to rename cluster.conf: ") + String(strerror(errnold));
     }
   }
 }
--- conga/ricci/modules/cluster/ClusterStatus.cpp	2007/03/06 09:15:01	1.19
+++ conga/ricci/modules/cluster/ClusterStatus.cpp	2007/08/22 18:47:19	1.20
@@ -1,5 +1,5 @@
 /*
-  Copyright Red Hat, Inc. 2005
+  Copyright Red Hat, Inc. 2005-2007
 
   This program is free software; you can redistribute it and/or modify it
   under the terms of the GNU General Public License as published by the
@@ -50,11 +50,8 @@
 
 
 
-static void run_initd(const String& servname,
-		      bool start,
-		      bool fail);
-static void run_chkconfig(const String& servname,
-			  bool on);
+static void run_initd(const String& servname, bool start, bool fail);
+static void run_chkconfig(const String& servname, bool on);
 static void cman_leave();
 static void gulm_leave();
 
@@ -377,9 +374,7 @@
 }
 
 void 
-run_initd(const String& servname,
-	  bool start,
-	  bool fail)
+run_initd(const String& servname, bool start, bool fail)
 {
   String path(INITD_DIR_PATH);
   path += servname;
@@ -396,7 +391,7 @@
     if (status == 0)
       failed = false;
   if (fail && failed)
-    throw String("service ") + servname + " " + String(start?"start":"stop") + " failed";
+    throw String("service ") + servname + " " + String(start?"start":"stop") + " failed: " + err;
 }
 
 void 
@@ -434,7 +429,7 @@
     if (utils::execute(MODPROBE_PATH, args, out, err, status, false))
       throw command_not_found_error_msg(MODPROBE_PATH);
     if (status != 0)
-      throw String("modprobe -r failed");
+      throw String("modprobe -r failed: ") + err;
   }
 }
 
--- conga/ricci/modules/cluster/Clusvcadm.cpp	2007/08/20 16:31:14	1.13
+++ conga/ricci/modules/cluster/Clusvcadm.cpp	2007/08/22 18:47:19	1.14
@@ -38,7 +38,8 @@
 class ServiceStatus
 {
 public:
-  enum state {RG_STATE_STOPPED         = 110,    // Resource group is stopped
+  enum state {
+		  RG_STATE_STOPPED         = 110,    // Resource group is stopped
 	      RG_STATE_STARTING        = 111,    // Resource is starting
 	      RG_STATE_STARTED         = 112,    // Resource is started
 	      RG_STATE_STOPPING        = 113,    // Resource is stopping
@@ -48,7 +49,8 @@
 	      RG_STATE_ERROR           = 117,    // Recoverable error
 	      RG_STATE_RECOVER         = 118,    // Pending recovery
 	      RG_STATE_DISABLED        = 119,    // Resource not allowd to run
-	      RG_STATE_MIGRATE         = 120};   // Resource migrating
+	      RG_STATE_MIGRATE         = 120     // Resource migrating
+  };
   
   ServiceStatus(const String& name,
 		const String& node, 
@@ -202,7 +204,7 @@
 	if (utils::execute(CLUSVCADM_TOOL_PATH, args, out, err, status, false))
 	  throw command_not_found_error_msg(CLUSVCADM_TOOL_PATH);
 	if (status != 0)
-	  throw String("clusvcadm failed to migrate " + servicename);
+	  throw String("clusvcadm failed to migrate " + servicename + ": " + err);
       }
       return;
     }
@@ -236,7 +238,7 @@
 	if (utils::execute(CLUSVCADM_TOOL_PATH, args, out, err, status, false))
 	  throw command_not_found_error_msg(CLUSVCADM_TOOL_PATH);
 	if (status != 0)
-	  throw String("clusvcadm failed to stop " + servicename);
+	  throw String("clusvcadm failed to stop " + servicename + ": " + err);
       }
       return;
     }
@@ -288,7 +290,7 @@
 	if (utils::execute(CLUSVCADM_TOOL_PATH, args, out, err, status, false))
 	  throw command_not_found_error_msg(CLUSVCADM_TOOL_PATH);
 	if (status != 0)
-	  throw String("clusvcadm failed to restart cluster service " + servicename);
+	  throw String("clusvcadm failed to restart cluster service " + servicename + ": " + err);
       }
       return;
     }
@@ -306,25 +308,17 @@
   int status;
   vector<String> args;
   
-  bool fast_available = false;  // clustat -f ?
-  args.push_back("-h");
-  if (utils::execute(CLUSTAT_TOOL_PATH, args, out, err, status, false))
-    throw command_not_found_error_msg(CLUSTAT_TOOL_PATH);
-  if (out.find("-f") != out.npos)
-    fast_available = true;
-  
   args.clear();
-  if (fast_available)
-    args.push_back("-f");
+  args.push_back("-f");
   args.push_back("-x");
   if (utils::execute(CLUSTAT_TOOL_PATH, args, out, err, status, false))
     throw command_not_found_error_msg(CLUSTAT_TOOL_PATH);
   if (status)
-    throw String("clustat failed");
+    throw String("clustat failed: ") + err;
   
   XMLObject xml = parseXML(out);
   if (xml.tag() != "clustat")
-    throw String("invalid clustat output");
+    throw String("invalid clustat output: no clustat tag");
   
   XMLObject nodes_xml("noname"), groups_xml("noname"), quorum_xml("noname");
   for (list<XMLObject>::const_iterator iter = xml.children().begin();
--- conga/ricci/modules/cluster/Fence.cpp	2006/10/06 03:10:13	1.4
+++ conga/ricci/modules/cluster/Fence.cpp	2007/08/22 18:47:19	1.5
@@ -1,5 +1,5 @@
 /*
-  Copyright Red Hat, Inc. 2005
+  Copyright Red Hat, Inc. 2005-2007
 
   This program is free software; you can redistribute it and/or modify it
   under the terms of the GNU General Public License as published by the
@@ -45,5 +45,5 @@
   if (utils::execute(FENCE_NODE_TOOL_PATH, args, out, err, status, false))
     throw command_not_found_error_msg(FENCE_NODE_TOOL_PATH);
   if (status != 0)
-    throw String("fence_node failed");
+    throw String("fence_node failed: ") + err;
 }
--- conga/ricci/modules/cluster/Virt.cpp	2007/07/23 18:47:50	1.3
+++ conga/ricci/modules/cluster/Virt.cpp	2007/08/22 18:47:19	1.4
@@ -22,6 +22,8 @@
 #include <stdlib.h>
 #include <fcntl.h>
 #include <sys/stat.h>
+#include <string.h>
+#include <errno.h>
 #include "base64.h"
 }
 
@@ -38,7 +40,7 @@
         if (utils::execute(DMIDECODE_PATH, args, out, err, status, false))
             throw command_not_found_error_msg(DMIDECODE_PATH);
         if (status != 0)
-			throw String("dmidecode failed");
+			throw String("dmidecode failed: " + err);
         if (out.find("Vendor: Xen") != out.npos)
             return true;
         if (out.find("Manufacturer: Xen") != out.npos)
@@ -76,21 +78,24 @@
 	old_mask = umask(077);
 
 	fd = mkstemp(tmpname);
-	umask(old_mask);
 	if (fd < 0) {
+		int err = errno;
+		umask(old_mask);
 		memset(buf, 0, keylen_dec);
 		free(buf);
-		throw String("error setting new key");
+		throw String("error setting new key: ") + String(strerror(err));
 	}
+	umask(old_mask);
 
 	fchmod(fd, 0600);
 	ret = write(fd, buf, keylen_dec);
 	if (ret < 0 || (size_t) ret != keylen_dec) {
+		int err = errno;
 		unlink(tmpname);
 		close(fd);
 		memset(buf, 0, keylen_dec);
 		free(buf);
-		throw String("error setting new key");
+		throw String("error setting new key: ") + String(strerror(err));
 	}
 
 	close(fd);
@@ -98,8 +103,9 @@
 	free(buf);
 
 	if (rename(tmpname, XVM_KEY_PATH) != 0) {
+		int err = errno;
 		unlink(tmpname);
-		throw String("error setting new key");
+		throw String("error setting new key: ") + String(strerror(err));
 	}
 
 	return (true);
@@ -110,29 +116,32 @@
 	size_t ret;
 	char buf[XVM_KEY_MAX_SIZE];
 	struct stat stat;
+	int err = 0;
 
 	if (keylen < XVM_KEY_MIN_SIZE || keylen > XVM_KEY_MAX_SIZE)
 		throw String("invalid key length");
 
 	fd = open("/dev/urandom", O_RDONLY);
 	if (fd < 0)
-		throw String("error generating key");
+		throw String("error generating key: ") + String(strerror(errno));
 
 	ret = read(fd, buf, keylen);
+	err = errno;
 	close(fd);
 	if ((size_t) ret != keylen)
-		throw String("error generating key");
+		throw String("error generating key: ") + String(strerror(err));
 		
 
 	fd = open(XVM_KEY_PATH, O_WRONLY | O_EXCL | O_CREAT, 0600);
 	if (fd < 0)
-		throw String("error generating key");
+		throw String("error generating key: ") + String(strerror(errno));
 
 	ret = write(fd, buf, keylen);
+	err = errno;
 	close(fd);
 	if ((size_t) ret != keylen) {
 		unlink(XVM_KEY_PATH);
-		throw String("error generating key");
+		throw String("error generating key: ") + String(strerror(err));
 	}
 	return (true);
 }
@@ -145,21 +154,23 @@
 	char buf[XVM_KEY_MAX_SIZE];
 	struct stat st;
 	char *key_out = NULL;
+	int err = 0;
 
 	fd = open(XVM_KEY_PATH, O_RDONLY);
 	if (fd < 0)
-		throw String("error retrieving key");
+		throw String("error retrieving key:") + String(strerror(errno));
 
 	if (fstat(fd, &st) != 0) {
 		close(fd);
-		throw String("error retrieving key");
+		throw String("error retrieving key: ") + String(strerror(errno));
 	}
 
 	ret = read(fd, buf, sizeof(buf));
+	err = errno;
 	close(fd);
 	if (ret < 0 || (off_t) ret != st.st_size) {
 		memset(buf, 0, sizeof(buf));
-		throw String("error retrieving key");
+		throw String("error retrieving key: ") + String(strerror(err));
 	}
 	keylen_bin = (size_t) ret;
 
--- conga/ricci/modules/cluster/clumon/src/daemon/Monitor.cpp	2007/03/23 17:25:13	1.14
+++ conga/ricci/modules/cluster/clumon/src/daemon/Monitor.cpp	2007/08/22 18:47:20	1.15
@@ -49,6 +49,8 @@
 #define RG_STATE_ERROR                  117     /** Recoverable error */
 #define RG_STATE_RECOVER                118     /** Pending recovery */
 #define RG_STATE_DISABLED               119     /** Resource not allowd to run */
+#define RG_STATE_MIGRATE                120     /** Resource migrating */
+
 
 
 
@@ -607,18 +609,8 @@
     int status;
     vector<String> args;
     
-    bool fast_available = false;  // clustat -f ?
-    args.push_back("-h");
-    if (execute("/usr/sbin/clustat", args, out, err, status, EXECUTE_TIMEOUT))
-      throw String("services_info(): missing clustat");
-    if (status)
-      throw String("services_info(): `clustat -h` failed");
-    if (out.find("-f") != out.npos)
-      fast_available = true;
-    
     args.clear();
-    if (fast_available)
-      args.push_back("-f");
+    args.push_back("-f");
     args.push_back("-x");
     if (execute("/usr/sbin/clustat", args, out, err, status, EXECUTE_TIMEOUT))
       throw String("services_info(): missing clustat");
@@ -667,6 +659,7 @@
 	    running = false;
 	    failed = true;
 	    break;
+	  case RG_STATE_MIGRATE:
 	  case RG_STATE_STARTING:
 	  case RG_STATE_STARTED:
 	  case RG_STATE_CHECK:
@@ -676,8 +669,8 @@
 	  default:
 	    continue;
 	  }
-	  service.set_attr("failed", (failed)? "true" : "false");
-	  service.set_attr("running", (running)? "true" : "false");
+	  service.set_attr("failed", (failed) ? "true" : "false");
+	  service.set_attr("running", (running) ? "true" : "false");
 	  if (running)
 	    service.set_attr("nodename", group.get_attr("owner"));
 	  
--- conga/ricci/modules/cluster/clumon/src/daemon/main.cpp	2006/10/14 18:00:02	1.4
+++ conga/ricci/modules/cluster/clumon/src/daemon/main.cpp	2007/08/22 18:47:20	1.5
@@ -166,7 +166,7 @@
       if (errno == EINTR)
 	continue;
       else
-	throw String("serve_clients(): poll() error");
+	throw String("serve_clients(): poll() error: " + String(strerror(errno)));
     }
     
     // process events
@@ -183,7 +183,7 @@
 	  } catch ( ... ) {}
 	}
 	if (poll_info.revents & (POLLERR | POLLHUP | POLLNVAL))
-	  throw String("serve_clients(): server socket error????");
+	  throw String("serve_clients(): poll: " + String(strerror(errno)));
       } else {
 	// client socket
 	if (poll_info.revents & POLLIN) {
@@ -226,11 +226,11 @@
 segfault(int)
 {
   char msg[128];
-  snprintf(msg, sizeof(msg)-1, "PID %d Thread %d: SIGSEGV, waiting forensics", 
+  snprintf(msg, sizeof(msg), "PID %d Thread %d: SIGSEGV, waiting forensics", 
 	   getpid(), (int) pthread_self());
+
   log_sigsafe(msg, LogAll);
-  while(1)
-    sleep(60);
+  select(0, NULL, NULL, NULL, NULL);
 }
 
 void 




More information about the Cluster-devel mailing list