]> git.proxmox.com Git - pve-cluster.git/commitdiff
remove cman, and use corosync.conf instead of cluster.conf
authorDietmar Maurer <dietmar@proxmox.com>
Wed, 25 Feb 2015 16:42:02 +0000 (17:42 +0100)
committerDietmar Maurer <dietmar@proxmox.com>
Wed, 25 Feb 2015 16:42:02 +0000 (17:42 +0100)
data/PVE/pvecm
data/src/cfs-utils.c
data/src/cfs-utils.h
data/src/dcdb.c
data/src/dcdb.h
data/src/pmxcfs.c
data/src/status.c

index b6450119995ec4ba8f3a4679726d8fcef182086d..8fc1c8b4c95e3e80175db24640db89ea279156d2 100755 (executable)
@@ -27,11 +27,11 @@ my $nodename = PVE::INotify::nodename();
 my $local_ip_address = PVE::Cluster::remote_node_ip($nodename);
 
 my $basedir = "/etc/pve";
-my $clusterconf = "$basedir/cluster.conf";
+my $clusterconf = "$basedir/corosync.conf";
 my $libdir = "/var/lib/pve-cluster";
 my $backupdir = "/var/lib/pve-cluster/backup";
 my $dbfile = "$libdir/config.db";
-my $authfile = "$libdir/corosync.authkey";
+my $authfile = "/etc/corosync/authkey";
 
 
 sub backup_database {
@@ -124,11 +124,11 @@ __PACKAGE__->register_method ({
            },
            votes => {
                type => 'integer',
-               description => "Number of votes for this node",
+               description => "Number of votes for this node.",
                minimum => 1,
                optional => 1,
            },
-       },
+       }, 
     },
     returns => { type => 'null' },
     
@@ -151,19 +151,31 @@ __PACKAGE__->register_method ({
        $param->{votes} = 1 if !defined($param->{votes});
 
        my $config = <<_EOD;
-<?xml version="1.0"?>
-<cluster name="$clustername" config_version="1">
-
-  <cman keyfile="$authfile">
-  </cman>
+totem {
+  version: 2
+  secauth: on
+  cluster_name: $clustername
+  config_version: 1
+}
 
-  <clusternodes>
-  <clusternode name="${nodename}" votes="$param->{votes}" nodeid="$param->{nodeid}"/>
-  </clusternodes>
+nodelist {
+  node {
+    ring0_addr: $nodename
+    nodeid: $param->{nodeid}
+    quorum_votes: $param->{votes}
+  }
+}
+       
+quorum {
+  provider: corosync_votequorum
+}
 
-</cluster>
+logging {
+  to_syslog: yes
+  debug: off
+}
 _EOD
-;
+;      
        PVE::Tools::file_set_contents($clusterconf, $config);
 
        PVE::Cluster::ssh_merge_keys();
@@ -172,13 +184,9 @@ _EOD
 
        PVE::Cluster::ssh_merge_known_hosts($nodename, $local_ip_address, 1);
 
-       PVE::Tools::run_command('/etc/init.d/pve-cluster restart'); # restart
-
-       # that cman init script returns strange values - simply ignore for now
-       system('/etc/init.d/cman start');
+       PVE::Tools::run_command('service pve-cluster restart'); # restart
 
-       # also start clvm
-       system('/etc/init.d/clvm start');
+       PVE::Tools::run_command('service corosync restart'); # restart
        
        return undef;
 }});
@@ -356,8 +364,8 @@ __PACKAGE__->register_method ({
                die "this host already contains virtual machines - please remove the first\n";
            }
 
-           if (system("cman_tool status >/dev/null 2>&1") == 0) {
-               die "cman is already running\n";
+           if (system("corosync-quorumtool >/dev/null 2>&1") == 0) {
+               die "corosync is already running\n";
            }
        }
 
@@ -466,7 +474,7 @@ __PACKAGE__->register_method ({
     code => sub {
        my ($param) = @_;
 
-       my $cmd = ['cman_tool', 'status'];
+       my $cmd = ['corosync-quorumtool', '-siH'];
 
        exec (@$cmd);
 
@@ -487,7 +495,7 @@ __PACKAGE__->register_method ({
     code => sub {
        my ($param) = @_;
 
-       my $cmd = ['cman_tool', 'nodes'];
+       my $cmd = ['corosync-quorumtool', '-l'];
 
        exec (@$cmd);
 
index 40767696d18c07a516c848928725d65629d59784..92d98aa40258a7c1ab7df166aace24eac563918d 100644 (file)
@@ -159,76 +159,28 @@ cfs_log(
        g_free(orgmsg);
 }
 
-// xml parser for cluster.conf - just good enough to extract version
-
-typedef struct
-{
-  guint64 version;
-} PVEClusterConfig;
-
-static void
-parser_start_element (
-       GMarkupParseContext  *context,
-       const gchar          *element_name,
-       const gchar         **attribute_names,
-       const gchar         **attribute_values,
-       gpointer              user_data,
-       GError              **error)
-{
-       PVEClusterConfig *data = user_data;
-
-       if (!data->version && !strcmp(element_name, "cluster")) { 
-               const char **n = attribute_names;
-               const char **v = attribute_values;
-
-               while (n && v && *n) {
-                       if (!strcmp(*n, "config_version")) {
-                               char *e = NULL;
-                               guint64 ver = strtoull(*v, &e, 10);
-                               if (e) 
-                                       data->version = ver;      
-                       }
-                       ++n;
-                       ++v;
-               }
-       }
-}
-
-static GMarkupParser cluster_conf_parser = { 
-       .start_element = parser_start_element 
-};
-
 guint64 
 cluster_config_version(
        const gpointer config_data, 
        gsize config_length)
 {
-       GMarkupParseContext *ctx;
-
-       GError *err = NULL;
-
-       PVEClusterConfig cfg = { .version = 0 };
-       if (!(ctx = g_markup_parse_context_new(&cluster_conf_parser, 0, &cfg, NULL))) {
-               cfs_critical("g_markup_parse_context_new failed");
-               return 0;
-       }
-
-       if (!g_markup_parse_context_parse(ctx, config_data, config_length, &err)) {
-               cfs_critical("unable to parse cluster config - %s", err->message);
-               g_error_free (err);
-               g_markup_parse_context_free(ctx);
-               return cfg.version;
-       }
-
-       if (!g_markup_parse_context_end_parse(ctx, &err)) {
-               cfs_critical("unable to parse cluster config - %s", err->message);
-               g_error_free (err);
-               g_markup_parse_context_free(ctx);
-               return cfg.version;
+       GRegex *regex;
+       GMatchInfo *match_info;
+       guint64 version = 0;
+       
+       regex = g_regex_new ("config_version\\s*:\\s*(\\d+)", 0, 0, NULL);
+       g_regex_match (regex, config_data, 0, &match_info);
+       if (g_match_info_matches (match_info)) {
+               gchar *word = g_match_info_fetch (match_info, 1);
+               if (strlen(word)) {
+                       version = strtoull(word, NULL, 10);
+               }
+               g_free (word);
        }
+       g_match_info_free (match_info);
+       g_regex_unref (regex);
 
-       g_markup_parse_context_free(ctx);
-       return cfg.version;
+       return version;
 }
 
 ssize_t 
index b088a9cfbc2b6fd87ecc6bf40f0a2c1cb66d7bc2..b97214c83b4e2ecf14da0ed5fe232ed740813618 100644 (file)
@@ -29,7 +29,7 @@
 #include <glib.h>
 #include <fcntl.h>
 
-#define HOST_CLUSTER_CONF_FN "/etc/cluster/cluster.conf"
+#define HOST_CLUSTER_CONF_FN "/etc/corosync/corosync.conf"
 #define CFS_PID_FN "/var/run/pve-cluster.pid"
 #define VARLIBDIR "/var/lib/pve-cluster"
 
index 3edc0a1716a3292d5528f34cb620af0f17be3bec..307c7ec5602f27bfb3df399c28aca4038ea53d95 100644 (file)
@@ -351,22 +351,24 @@ dcdb_parse_update_inode(
 }
 
 void 
-dcdb_sync_cluster_conf(
+dcdb_sync_corosync_conf(
        memdb_t *memdb, 
-       gboolean notify_cman)
+       gboolean notify_corosync)
 {
        g_return_if_fail(memdb != NULL);
 
        int len;
        gpointer data = NULL;
 
-       len = memdb_read(memdb, "cluster.conf", &data);
+       len = memdb_read(memdb, "corosync.conf", &data);
        if (len <= 0)
                return;
 
        guint64 new_version = cluster_config_version(data, len);
-       if (!new_version) 
+       if (!new_version) {
+               cfs_critical("unable to parse cluster config_version");
                return;
+       }
 
        char *old_data = NULL;
        gsize old_length = 0;
@@ -390,23 +392,24 @@ dcdb_sync_cluster_conf(
                goto ret;
 
        if (new_version < old_version) {
-               cfs_critical("local cluster.conf is newer");
+               cfs_critical("local corosync.conf is newer");
                goto ret;
        }
 
-       if (!atomic_write_file(HOST_CLUSTER_CONF_FN, data, len, 0640, 0))
+       if (!atomic_write_file(HOST_CLUSTER_CONF_FN, data, len, 0644, 0))
                goto ret;
 
-       cfs_message("wrote new cluster config '%s'", HOST_CLUSTER_CONF_FN);
-
-       if (notify_cman && old_version) {
-               /* tell cman that there is a new config file */
-               cfs_debug ("run cman_tool version");
-               int status = system("/usr/sbin/cman_tool version -r -S >/dev/null 2>&1");
+       cfs_message("wrote new corosync config '%s' (version = %zd)",
+                   HOST_CLUSTER_CONF_FN, new_version);
+       
+       if (notify_corosync && old_version) {
+               /* tell corosync that there is a new config file */
+               cfs_debug ("run corosync-cfgtool -R");
+               int status = system("corosync-cfgtool -R >/dev/null 2>&1");
                if (WIFEXITED(status) && WEXITSTATUS(status) != 0) {
-                       cfs_critical("cman_tool version failed with exit code %d\n", WEXITSTATUS(status));
+                       cfs_critical("corosync-cfgtool -R failed with exit code %d\n", WEXITSTATUS(status));
                }
-               cfs_debug ("end cman_tool version");
+               cfs_debug ("end corosync-cfgtool -R");
        }
 
 ret:
@@ -714,7 +717,7 @@ dcdb_commit(
        if (!bdb_backend_commit_update(memdb, localsi->master, localsi->idx, localsi->updates)) 
                return -1;
 
-       dcdb_sync_cluster_conf(memdb, FALSE);
+       dcdb_sync_corosync_conf(memdb, FALSE);
 
        return 0;
 }
@@ -851,8 +854,8 @@ dcdb_deliver(
                msg_result = memdb_write(memdb, path, nodeid, msg_time,
                                         buf, size, offset, flags);
 
-               if ((msg_result >= 0) && !strcmp(path, "cluster.conf"))
-                       dcdb_sync_cluster_conf(memdb, dfsm_nodeid_is_local(dfsm, nodeid, pid));
+               if ((msg_result >= 0) && !strcmp(path, "corosync.conf"))
+                       dcdb_sync_corosync_conf(memdb, dfsm_nodeid_is_local(dfsm, nodeid, pid));
 
        } else if (msg_type == DCDB_MESSAGE_CFS_CREATE) {
 
@@ -862,8 +865,8 @@ dcdb_deliver(
                
                msg_result = memdb_create(memdb, path, nodeid, msg_time);
 
-               if ((msg_result >= 0) && !strcmp(path, "cluster.conf"))
-                       dcdb_sync_cluster_conf(memdb, dfsm_nodeid_is_local(dfsm, nodeid, pid));
+               if ((msg_result >= 0) && !strcmp(path, "corosync.conf"))
+                       dcdb_sync_corosync_conf(memdb, dfsm_nodeid_is_local(dfsm, nodeid, pid));
                
        } else if (msg_type == DCDB_MESSAGE_CFS_MKDIR) {
 
@@ -889,8 +892,8 @@ dcdb_deliver(
 
                msg_result = memdb_rename(memdb, path, to, nodeid, msg_time);
                
-               if ((msg_result >= 0) && !strcmp(to, "cluster.conf"))
-                       dcdb_sync_cluster_conf(memdb, dfsm_nodeid_is_local(dfsm, nodeid, pid));
+               if ((msg_result >= 0) && !strcmp(to, "corosync.conf"))
+                       dcdb_sync_corosync_conf(memdb, dfsm_nodeid_is_local(dfsm, nodeid, pid));
                        
        } else if (msg_type == DCDB_MESSAGE_CFS_MTIME) {
 
index 52a43211cb8a75e9de51b453f43919a27fd94b12..0da2afe896e752789b5494f8a6d0e99429e1026c 100644 (file)
@@ -46,9 +46,9 @@ typedef enum {
 
 dfsm_t *dcdb_new(memdb_t *memdb);
 
-void dcdb_sync_cluster_conf(
+void dcdb_sync_corosync_conf(
        memdb_t *memdb, 
-       gboolean notify_cman);
+       gboolean notify_corosync);
 
 int dcdb_send_fuse_message(
        dfsm_t *dfsm, 
index 992d727fe0a21a41a22b70b6a4e13f20733a285a..5f3b682579ae38dfd8743452ea29d3f002986312 100644 (file)
@@ -745,7 +745,7 @@ int main(int argc, char *argv[])
                { "debug", 'd', 0, G_OPTION_ARG_NONE, &cfs.debug, "Turn on debug messages", NULL },
                { "foreground", 'f', 0, G_OPTION_ARG_NONE, &foreground, "Do not daemonize server", NULL },
                { "local", 'l', 0, G_OPTION_ARG_NONE, &force_local_mode, 
-                 "Force local mode (ignore cluster.conf, force quorum)", NULL },
+                 "Force local mode (ignore corosync.conf, force quorum)", NULL },
                { NULL },
        };
 
@@ -830,7 +830,7 @@ int main(int argc, char *argv[])
                goto err;
        }
 
-       // automatically import cluster.conf from host
+       // automatically import corosync.conf from host
        if (create && !force_local_mode) {
                char *cdata = NULL;
                gsize clen = 0;
@@ -838,28 +838,28 @@ int main(int argc, char *argv[])
 
                        guint32 mtime = time(NULL);
 
-                       memdb_create(memdb, "/cluster.conf", 0, mtime);
-                       if (memdb_write(memdb, "/cluster.conf", 0, mtime, cdata, clen, 0, 1) < 0) {
-                               cfs_critical("memdb_write failed - unable to import cluster.conf");
+                       memdb_create(memdb, "/corosync.conf", 0, mtime);
+                       if (memdb_write(memdb, "/corosync.conf", 0, mtime, cdata, clen, 0, 1) < 0) {
+                               cfs_critical("memdb_write failed - unable to import corosync.conf");
                                goto err;
                        }
                }
        }
 
-       // does cluster.conf exist?
+       // does corosync.conf exist?
        gpointer conf_data = NULL;
-       int len = memdb_read(memdb, "cluster.conf", &conf_data);
+       int len = memdb_read(memdb, "corosync.conf", &conf_data);
        if (len >= 0) {
                if (force_local_mode) {
-                       cfs_message("forcing local mode (althought cluster.conf exists)");
+                       cfs_message("forcing local mode (althought corosync.conf exists)");
                        cfs_set_quorate(1, TRUE);
                } else {
                        if (!(dcdb = dcdb_new(memdb)))
                                goto err;
-                       dcdb_sync_cluster_conf(memdb, 1);
+                       dcdb_sync_corosync_conf(memdb, 1);
                }
        } else {
-               cfs_debug("using local mode (cluster.conf does not exist)");
+               cfs_debug("using local mode (corosync.conf does not exist)");
                cfs_set_quorate(1, TRUE);
        }
        if (conf_data) g_free(conf_data);
index 6dddf105c3a72fc241eb67a985bea9ff7b7e8637..65f7ec958b9773e15fa31bae45c348f6590e4184 100644 (file)
@@ -75,8 +75,8 @@ typedef struct {
 } memdb_change_t;
 
 static memdb_change_t memdb_change_array[] = {
-       { .path = "cluster.conf" },
-       { .path = "cluster.conf.new" },
+       { .path = "corosync.conf" },
+       { .path = "corosync.conf.new" },
        { .path = "storage.cfg" },
        { .path = "user.cfg" },
        { .path = "domains.cfg" },