conga/ricci/modules/cluster ClusterConf.cpp Cl ...
CVSROOT: /cvs/cluster
Module name: conga
Changes by: rmccabe at sourceware.org 2007-08-23 15:30:29
Modified files:
ricci/modules/cluster: ClusterConf.cpp ClusterConf.h
ClusterModule.h ClusterStatus.cpp ClusterStatus.h Clusvcadm.cpp Clusvcadm.h Fence.cpp Fence.h NoServiceManager.h Virt.cpp Virt.h main.cpp
Log message:
- Return more useful error messages in responses for failed commands
- Readability/formatting/whitespace fixes.
Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/conga/ricci/modules/cluster/ClusterConf.cpp.diff?cvsroot=cluster&r1=1.10&r2=1.11
http://sourceware.org/cgi-bin/cvsweb.cgi/conga/ricci/modules/cluster/ClusterConf.h.diff?cvsroot=cluster&r1=1.3&r2=1.4
http://sourceware.org/cgi-bin/cvsweb.cgi/conga/ricci/modules/cluster/ClusterModule.h.diff?cvsroot=cluster&r1=1.1&r2=1.2
http://sourceware.org/cgi-bin/cvsweb.cgi/conga/ricci/modules/cluster/ClusterStatus.cpp.diff?cvsroot=cluster&r1=1.20&r2=1.21
http://sourceware.org/cgi-bin/cvsweb.cgi/conga/ricci/modules/cluster/ClusterStatus.h.diff?cvsroot=cluster&r1=1.4&r2=1.5
http://sourceware.org/cgi-bin/cvsweb.cgi/conga/ricci/modules/cluster/Clusvcadm.cpp.diff?cvsroot=cluster&r1=1.14&r2=1.15
http://sourceware.org/cgi-bin/cvsweb.cgi/conga/ricci/modules/cluster/Clusvcadm.h.diff?cvsroot=cluster&r1=1.3&r2=1.4
http://sourceware.org/cgi-bin/cvsweb.cgi/conga/ricci/modules/cluster/Fence.cpp.diff?cvsroot=cluster&r1=1.5&r2=1.6
http://sourceware.org/cgi-bin/cvsweb.cgi/conga/ricci/modules/cluster/Fence.h.diff?cvsroot=cluster&r1=1.2&r2=1.3
http://sourceware.org/cgi-bin/cvsweb.cgi/conga/ricci/modules/cluster/NoServiceManager.h.diff?cvsroot=cluster&r1=1.1&r2=1.2
http://sourceware.org/cgi-bin/cvsweb.cgi/conga/ricci/modules/cluster/Virt.cpp.diff?cvsroot=cluster&r1=1.4&r2=1.5
http://sourceware.org/cgi-bin/cvsweb.cgi/conga/ricci/modules/cluster/Virt.h.diff?cvsroot=cluster&r1=1.3&r2=1.4
http://sourceware.org/cgi-bin/cvsweb.cgi/conga/ricci/modules/cluster/main.cpp.diff?cvsroot=cluster&r1=1.4&r2=1.5
ricci/modules/cluster/ClusterConf.cpp +118 -98
@@ -13,7 +13,7 @@ You should have received a copy of the GNU General Public License along with this program; see the file COPYING. If not, write to the - Free Software Foundation, Inc., 675 Mass Ave, Cambridge, + Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ /*
@@ -33,131 +33,151 @@ using namespace std; -#define CLUSTER_CONF_DIR String("/etc/cluster/") -#define CLUSTER_CONF_NAME String("cluster.conf") -#define CLUSTER_CONF_PATH (CLUSTER_CONF_DIR + CLUSTER_CONF_NAME) +#define CLUSTER_CONF_DIR String("/etc/cluster/") +#define CLUSTER_CONF_NAME String("cluster.conf") +#define CLUSTER_CONF_PATH (CLUSTER_CONF_DIR + CLUSTER_CONF_NAME) -#define CCS_TOOL_PATH "/sbin/ccs_tool" +#define CCS_TOOL_PATH "/sbin/ccs_tool" -static void -set_CMAN_TOOL_PATH(); +static void set_CMAN_TOOL_PATH(); static String CMAN_TOOL_PATH; - XMLObject ClusterConf::get() { - return readXML(CLUSTER_CONF_PATH); + return readXML(CLUSTER_CONF_PATH); } void -ClusterConf::set(const XMLObject& xml, - bool propagate) -{ - set_CMAN_TOOL_PATH(); - - // sanity check - if (xml.tag() != "cluster") - throw String("invalid cluster.conf: no cluster tag"); - if (xml.get_attr("name").empty()) - 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: no config_version attribute"); - - // create dir, if not existing - DIR* dir = opendir(CLUSTER_CONF_DIR.c_str()); - if (dir) - closedir(dir); - else { - 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 + ": " + String(strerror(errno)); - } else - throw String("opendir() error: ") + String(strerror(errno)); - } - - // save tmp cluster.conf - String tmp_path(CLUSTER_CONF_PATH + ".tmp_ricci"); - fstream fs(tmp_path.c_str(), - ios_base::out | ios_base::trunc); - fs << generateXML(xml); - fs.close(); - - // propagate/move to proper place - if (propagate) { - try { - String out, err; - int status; - vector<String> args; - args.push_back("update"); - args.push_back(tmp_path); - 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: ") + err; - - if (is_cman(xml)) { - args.clear(); - args.push_back("version"); - args.push_back("-r"); - args.push_back(utils::to_string(conf_version)); - 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: ") + err; - } - - unlink(tmp_path.c_str()); - } catch ( ... ) { - unlink(tmp_path.c_str()); - throw; - } - } 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: ") + String(strerror(errnold)); - } - } +ClusterConf::set(const XMLObject& xml, bool propagate) { + set_CMAN_TOOL_PATH(); + char cconf_path[] = "/etc/cluster/cluster.conf.tmp.ricciXXXXXX"; + int err = 0; + + // sanity check + if (xml.tag() != "cluster") + throw String("invalid cluster.conf: no cluster tag"); + if (xml.get_attr("name").empty()) + 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: no config_version attribute"); + + // create dir, if it doesn't exist + DIR *dir = opendir(CLUSTER_CONF_DIR.c_str()); + if (dir) + closedir(dir); + else { + if (errno == ENOENT) { + if (mkdir(CLUSTER_CONF_DIR.c_str(), 0755)) + throw String("failed to create " + CLUSTER_CONF_DIR + + ": " + String(strerror(errno))); + } else + throw String("opendir() error: ") + String(strerror(errno)); + } + + mode_t old_umask = umask(0077); + int conf_fd = mkstemp(cconf_path); + err = errno; + umask(old_umask); + + if (conf_fd < 0) { + throw String("error creating temporary cluster.conf: " + + String(strerror(err))); + } + + String conf_xml(generateXML(xml)); + ssize_t ret = write(conf_fd, conf_xml.c_str(), conf_xml.size()); + err = errno; + close(conf_fd); + + if (ret != (ssize_t) conf_xml.size()) { + throw String("error creating temporary cluster.conf: " + + String(strerror(err))); + } + + // propagate/move to proper place + if (propagate) { + try { + String out, err; + int status; + vector<String> args; + + args.push_back("update"); + args.push_back(cconf_path); + + 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 to propagate conf: ") + err; + + if (is_cman(xml)) { + args.clear(); + args.push_back("version"); + args.push_back("-r"); + args.push_back(utils::to_string(conf_version)); + + 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 to update version: ") + err; + } + + unlink(cconf_path); + } catch ( ... ) { + unlink(cconf_path); + throw; + } + } else { + if (rename(cconf_path, CLUSTER_CONF_PATH.c_str())) { + int errnold = errno; + unlink(cconf_path); + throw String("failed to rename cluster.conf: ") + + String(strerror(errnold)); + } + } } -void +void ClusterConf::purge_conf() { - unlink(CLUSTER_CONF_PATH.c_str()); + unlink(CLUSTER_CONF_PATH.c_str()); } bool ClusterConf::is_gulm(const XMLObject& cluster_conf) { - for (list<XMLObject>::const_iterator iter = cluster_conf.children().begin(); - iter != cluster_conf.children().end(); - iter++) - if (iter->tag() == "gulm") - return true; - return false; + for (list<XMLObject>::const_iterator iter = cluster_conf.children().begin(); + iter != cluster_conf.children().end(); + iter++) + { + if (iter->tag() == "gulm") + return true; + } + return false; } bool ClusterConf::is_cman(const XMLObject& cluster_conf) { - return !is_gulm(cluster_conf); + return !is_gulm(cluster_conf); } - - -void +void set_CMAN_TOOL_PATH() { - static bool path_set = false; - if (!path_set) { - CMAN_TOOL_PATH = "/sbin/cman_tool"; - if (access(CMAN_TOOL_PATH.c_str(), X_OK)) - CMAN_TOOL_PATH = "/usr/sbin/cman_tool"; - path_set = true; - } + static bool path_set = false; + if (!path_set) { + CMAN_TOOL_PATH = "/sbin/cman_tool"; + if (access(CMAN_TOOL_PATH.c_str(), X_OK)) + CMAN_TOOL_PATH = "/usr/sbin/cman_tool"; + path_set = true; + } }
ricci/modules/cluster/ClusterConf.h +10 -14
@@ -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
@@ -13,7 +13,7 @@You should have received a copy of the GNU General Public License along with this program; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 675 Mass Ave, Cambridge, +Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ /*
@@ -26,19 +26,15 @@#include "XML.h" -class ClusterConf { - public: -static XMLObject get (); - static void set(const XMLObject& xml, - bool propagate=true); -static void purge_conf (); - - static bool is_gulm(const XMLObject& cluster_conf); - static bool is_cman(const XMLObject& cluster_conf); - -}; + public: +static XMLObject get (); + static void set(const XMLObject& xml, bool propagate=true); +static void purge_conf (); + static bool is_gulm(const XMLObject& cluster_conf); + static bool is_cman(const XMLObject& cluster_conf); +}; -#endif // ClusterConf_h +#endif // ClusterConf_h
ricci/modules/cluster/ClusterModule.h +8 -11
@@ -1,5 +1,5 @@/* -Copyright Red Hat, Inc. 2006 +Copyright Red Hat, Inc. 2006-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
@@ -13,7 +13,7 @@You should have received a copy of the GNU General Public License along with this program; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 675 Mass Ave, Cambridge, +Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ /*
@@ -26,16 +26,13 @@#include "Module.h" - class ClusterModule : public Module { - public: -ClusterModule (); - virtual ~ClusterModule(); - - private: - -}; + public: +ClusterModule (); + virtual ~ClusterModule(); + private: +}; -#endif // ClusterModule_h +#endif // ClusterModule_h
ricci/modules/cluster/ClusterStatus.cpp +383 -376
811 lines not on this page · raw message
ricci/modules/cluster/ClusterStatus.h +8 -12
@@ -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
@@ -13,7 +13,7 @@You should have received a copy of the GNU General Public License along with this program; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 675 Mass Ave, Cambridge, +Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ /*
@@ -26,17 +26,13 @@#include "XML.h" -class Cluster { - public: -static XMLObject status (); - - static void start_node(bool cluster_startup = false); - static void stop_node(bool cluster_shutdown = false, - bool purge_conf = false); - + public: +static XMLObject status (); + static void start_node(bool cluster_startup = false); + static void stop_node( bool cluster_shutdown = false, + bool purge_conf = false); }; - -#endif // ClusterStatus_h +#endif // ClusterStatus_h
ricci/modules/cluster/Clusvcadm.cpp +374 -302
717 lines not on this page · raw message
ricci/modules/cluster/Clusvcadm.h +8 -11
@@ -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
@@ -13,28 +13,25 @@You should have received a copy of the GNU General Public License along with this program; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 675 Mass Ave, Cambridge, +Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ /* * Author: Stanko Kupcevic <[email protected]> */ -#ifndef Clusvcadm_h#define Clusvcadm_h#include "String.h" -class Clusvcadm { - public: - static void start(const String& servicename, const String& nodename); - static void migrate(const String& servicename, const String& nodename); - static void restart(const String& servicename); - static void stop(const String& servicename); + public: + static void start(const String& servicename, const String& nodename); + static void migrate(const String& servicename, const String& nodename); + static void restart(const String& servicename); + static void stop(const String& servicename); }; - -#endif // Clusvcadm_h +#endif // Clusvcadm_h
ricci/modules/cluster/Fence.cpp +14 -16
@@ -13,7 +13,7 @@ You should have received a copy of the GNU General Public License along with this program; see the file COPYING. If not, write to the - Free Software Foundation, Inc., 675 Mass Ave, Cambridge, + Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ /*
@@ -27,23 +27,21 @@ using namespace std; +#define FENCE_NODE_TOOL_PATH "/sbin/fence_node" -#define FENCE_NODE_TOOL_PATH "/sbin/fence_node" - - +void +Fence::fence_node(const String& nodename) +{ + String out, err; + int status; + vector<String> args; + args.push_back("-O"); + args.push_back(nodename); + if (utils::execute(FENCE_NODE_TOOL_PATH, args, out, err, status, false)) + throw command_not_found_error_msg(FENCE_NODE_TOOL_PATH); -void -Fence::fence_node(const String& nodename) -{ - String out, err; - int status; - vector<String> args; - args.push_back("-O"); - args.push_back(nodename); - 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: ") + err; + if (status != 0) + throw String("fence_node failed: ") + err; }
ricci/modules/cluster/Fence.h +4 -6
@@ -1,5 +1,5 @@/* -Copyright Red Hat, Inc. 2006 +Copyright Red Hat, Inc. 2006-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
@@ -13,7 +13,7 @@You should have received a copy of the GNU General Public License along with this program; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 675 Mass Ave, Cambridge, +Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ /*
@@ -29,10 +29,8 @@class Fence { - public: - static void fence_node(const String& nodename); - + public: + static void fence_node(const String& nodename); }; -#endif // Fence_h
ricci/modules/cluster/NoServiceManager.h +7 -11
@@ -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
@@ -13,7 +13,7 @@You should have received a copy of the GNU General Public License along with this program; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 675 Mass Ave, Cambridge, +Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ /*
@@ -26,16 +26,12 @@#include "Except.h" - class NoServiceManager : public Except { - public: - NoServiceManager() - : Except(1, "Service Manager not running on this node") {} - virtual ~NoServiceManager() - {} - + public: + NoServiceManager() + : Except(1, "Service Manager not running on this node") {} + virtual ~NoServiceManager() {} }; - -#endif // NoServiceManager_h +#endif // NoServiceManager_h
ricci/modules/cluster/Virt.cpp +16 -17
@@ -13,7 +13,7 @@ You should have received a copy of the GNU General Public License along with this program; see the file COPYING. If not, write to the - Free Software Foundation, Inc., 675 Mass Ave, Cambridge, + Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
@@ -33,21 +33,22 @@ using namespace std; bool Virt::virt_guest(void) { - try { - String out, err; - int status; - vector<String> args; - if (utils::execute(DMIDECODE_PATH, args, out, err, status, false)) - throw command_not_found_error_msg(DMIDECODE_PATH); - if (status != 0) + try { + String out, err; + int status; + vector<String> args; + + 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: " + err); - if (out.find("Vendor: Xen") != out.npos) - return true; - if (out.find("Manufacturer: Xen") != out.npos) - return true; - } catch ( ... ) {} + if (out.find("Vendor: Xen") != out.npos) + return true; + if (out.find("Manufacturer: Xen") != out.npos) + return true; + } catch ( ... ) {} - return false; + return false; } bool Virt::delete_xvm_key(void) {
@@ -66,7 +67,7 @@ if (key_base64 == NULL) throw String("no key was given"); - + keylen = strlen(key_base64); if (keylen < 1) throw String("no key was given");
@@ -115,7 +116,6 @@ int fd; 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)
@@ -130,7 +130,6 @@ close(fd); if ((size_t) ret != keylen) throw String("error generating key: ") + String(strerror(err)); - fd = open(XVM_KEY_PATH, O_WRONLY | O_EXCL | O_CREAT, 0600); if (fd < 0)
ricci/modules/cluster/Virt.h +8 -8
@@ -1,5 +1,5 @@/* -Copyright Red Hat, Inc. 2006 +Copyright Red Hat, Inc. 2006-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
@@ -13,7 +13,7 @@You should have received a copy of the GNU General Public License along with this program; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 675 Mass Ave, Cambridge, +Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
@@ -30,12 +30,12 @@#define DMIDECODE_PATH "/usr/sbin/dmidecode"class Virt { - public: -static bool virt_guest (void ); -static bool delete_xvm_key (void ); -static bool set_xvm_key (const char *key_base64); -static char *get_xvm_key (void ); -static bool generate_xvm_key (size_t key_bytes); + public: +static bool virt_guest (void ); +static bool delete_xvm_key (void ); +static bool set_xvm_key (const char *key_base64); +static char *get_xvm_key (void ); +static bool generate_xvm_key (size_t key_bytes); };#endif
ricci/modules/cluster/main.cpp +11 -11
@@ -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
@@ -13,7 +13,7 @@ You should have received a copy of the GNU General Public License along with this program; see the file COPYING. If not, write to the - Free Software Foundation, Inc., 675 Mass Ave, Cambridge, + Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ /*
@@ -24,18 +24,18 @@ #include "ClusterModule.h" #include <iostream> + using namespace std; int main(int argc, char** argv) { - try { - ClusterModule m; - return stdin_out_module_driver(m, - argc, - argv); - } catch (String e) { - cerr << e << endl; - return 1; - } + try { + ClusterModule m; + return stdin_out_module_driver(m, argc, argv); + } catch (String e) { + cerr << e << endl; + return 1; + } + return 1; }