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 {
},
votes => {
type => 'integer',
- description => "Number of votes for this node",
+ description => "Number of votes for this node.",
minimum => 1,
optional => 1,
},
- },
+ },
},
returns => { type => 'null' },
$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();
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;
}});
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";
}
}
code => sub {
my ($param) = @_;
- my $cmd = ['cman_tool', 'status'];
+ my $cmd = ['corosync-quorumtool', '-siH'];
exec (@$cmd);
code => sub {
my ($param) = @_;
- my $cmd = ['cman_tool', 'nodes'];
+ my $cmd = ['corosync-quorumtool', '-l'];
exec (@$cmd);
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
#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"
}
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;
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:
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;
}
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) {
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) {
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) {
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,
{ "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 },
};
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;
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);
} 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" },