} 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" },
{ .path = "priv/shadow.cfg" },
+ { .path = "priv/tfa.cfg" },
{ .path = "datacenter.cfg" },
{ .path = "vzdump.cron" },
+ { .path = "ha/crm_commands" },
+ { .path = "ha/manager_status" },
+ { .path = "ha/resources.cfg" },
+ { .path = "ha/groups.cfg" },
+ { .path = "ha/fence.cfg" },
+ { .path = "status.cfg" },
+ { .path = "replication.cfg" },
+ { .path = "ceph.conf" },
};
-static GStaticMutex mutex = G_STATIC_MUTEX_INIT;
+static GMutex mutex;
typedef struct {
time_t start_time;
g_free(vminfo);
}
+static const char *vminfo_type_to_string(vminfo_t *vminfo)
+{
+ if (vminfo->vmtype == VMTYPE_QEMU) {
+ return "qemu";
+ } else if (vminfo->vmtype == VMTYPE_OPENVZ) {
+ return "openvz";
+ } else if (vminfo->vmtype == VMTYPE_LXC) {
+ return "lxc";
+ } else {
+ return "unknown";
+ }
+}
+
void cfs_clnode_destroy(
cfs_clnode_t *clnode)
{
{
g_return_val_if_fail(str != NULL, -EINVAL);
- g_static_mutex_lock(&mutex);
+ g_mutex_lock (&mutex);
g_string_append_printf(str,"{\n");
g_string_append_printf(str,"}\n");
- g_static_mutex_unlock (&mutex);
+ g_mutex_unlock (&mutex);
return 0;
}
iov[0].iov_base = (char *)entry;
iov[0].iov_len = clog_entry_size(entry);
- dfsm_send_message(cfs_status.kvstore, KVSTORE_MESSAGE_LOG, iov, 1);
+ if (dfsm_is_initialized(cfs_status.kvstore))
+ dfsm_send_message(cfs_status.kvstore, KVSTORE_MESSAGE_LOG, iov, 1);
}
}
void cfs_status_init(void)
{
- g_static_mutex_lock (&mutex);
+ g_mutex_lock (&mutex);
cfs_status.start_time = time(NULL);
clusterlog_add(cfs_status.clusterlog, "root", "cluster", getpid(),
LOG_INFO, "starting cluster log");
- g_static_mutex_unlock (&mutex);
+ g_mutex_unlock (&mutex);
}
void cfs_status_cleanup(void)
{
- g_static_mutex_lock (&mutex);
+ g_mutex_lock (&mutex);
cfs_status.clinfo_version++;
if (cfs_status.clusterlog)
clusterlog_destroy(cfs_status.clusterlog);
- g_static_mutex_unlock (&mutex);
+ g_mutex_unlock (&mutex);
}
void cfs_status_set_clinfo(
{
g_return_if_fail(clinfo != NULL);
- g_static_mutex_lock (&mutex);
+ g_mutex_lock (&mutex);
cfs_status.clinfo_version++;
cfs_clinfo_destroy(old);
- g_static_mutex_unlock (&mutex);
+ g_mutex_unlock (&mutex);
}
static void
{
g_return_val_if_fail(str != NULL, -EINVAL);
- g_static_mutex_lock (&mutex);
+ g_mutex_lock (&mutex);
g_string_append_printf(str,"{\n");
g_string_append_printf(str,"}\n");
- g_static_mutex_unlock (&mutex);
+ g_mutex_unlock (&mutex);
return 0;
}
g_return_val_if_fail(vmlist != NULL, FALSE);
g_return_val_if_fail(nodename != NULL, FALSE);
g_return_val_if_fail(vmid != 0, FALSE);
- g_return_val_if_fail(vmtype == VMTYPE_QEMU || vmtype == VMTYPE_OPENVZ, FALSE);
+ g_return_val_if_fail(vmtype == VMTYPE_QEMU || vmtype == VMTYPE_OPENVZ ||
+ vmtype == VMTYPE_LXC, FALSE);
if (!replace && g_hash_table_lookup(vmlist, &vmid)) {
cfs_critical("detected duplicate VMID %d", vmid);
g_return_if_fail(cfs_status.vmlist != NULL);
g_return_if_fail(nodename != NULL);
g_return_if_fail(vmid != 0);
- g_return_if_fail(vmtype == VMTYPE_QEMU || vmtype == VMTYPE_OPENVZ);
+ g_return_if_fail(vmtype == VMTYPE_QEMU || vmtype == VMTYPE_OPENVZ ||
+ vmtype == VMTYPE_LXC);
cfs_debug("vmlist_register_vm: %s/%u %d", nodename, vmid, vmtype);
- g_static_mutex_lock (&mutex);
+ g_mutex_lock (&mutex);
cfs_status.vmlist_version++;
vmlist_hash_insert_vm(cfs_status.vmlist, vmtype, vmid, nodename, TRUE);
- g_static_mutex_unlock (&mutex);
+ g_mutex_unlock (&mutex);
}
gboolean
gboolean res = FALSE;
- g_static_mutex_lock (&mutex);
+ g_mutex_lock (&mutex);
vminfo_t *vminfo;
if ((vminfo = (vminfo_t *)g_hash_table_lookup(cfs_status.vmlist, &vmid))) {
if (!(vminfo->vmtype == vmtype && strcmp(vminfo->nodename, nodename) == 0))
res = TRUE;
}
- g_static_mutex_unlock (&mutex);
+ g_mutex_unlock (&mutex);
return res;
}
g_return_val_if_fail(cfs_status.vmlist != NULL, FALSE);
g_return_val_if_fail(vmid != 0, FALSE);
- g_static_mutex_lock (&mutex);
+ g_mutex_lock (&mutex);
gpointer res = g_hash_table_lookup(cfs_status.vmlist, &vmid);
- g_static_mutex_unlock (&mutex);
+ g_mutex_unlock (&mutex);
return res != NULL;
}
g_return_if_fail(cfs_status.vmlist != NULL);
g_return_if_fail(vmid != 0);
- g_static_mutex_lock (&mutex);
+ g_mutex_lock (&mutex);
cfs_status.vmlist_version++;
g_hash_table_remove(cfs_status.vmlist, &vmid);
- g_static_mutex_unlock (&mutex);
+ g_mutex_unlock (&mutex);
}
void cfs_status_set_vmlist(
{
g_return_if_fail(vmlist != NULL);
- g_static_mutex_lock (&mutex);
+ g_mutex_lock (&mutex);
cfs_status.vmlist_version++;
cfs_status.vmlist = vmlist;
- g_static_mutex_unlock (&mutex);
+ g_mutex_unlock (&mutex);
}
int
g_return_val_if_fail(cfs_status.vmlist != NULL, -EINVAL);
g_return_val_if_fail(str != NULL, -EINVAL);
- g_static_mutex_lock (&mutex);
+ g_mutex_lock (&mutex);
g_string_append_printf(str,"{\n");
int first = 1;
while (g_hash_table_iter_next (&iter, &key, &value)) {
vminfo_t *vminfo = (vminfo_t *)value;
- char *type;
- if (vminfo->vmtype == VMTYPE_QEMU) {
- type = "qemu";
- } else if (vminfo->vmtype == VMTYPE_OPENVZ) {
- type = "openvz";
- } else {
- type = "unknown";
- }
+ const char *type = vminfo_type_to_string(vminfo);
if (!first)
g_string_append_printf(str, ",\n");
}
g_string_append_printf(str,"\n}\n");
- g_static_mutex_unlock (&mutex);
+ g_mutex_unlock (&mutex);
return 0;
}
g_return_val_if_fail(data != NULL, FALSE);
kventry_t *entry;
- if ((entry = (kventry_t *)g_hash_table_lookup(kvhash, key))) {
+ if (!len) {
+ g_hash_table_remove(kvhash, key);
+ } else if ((entry = (kventry_t *)g_hash_table_lookup(kvhash, key))) {
g_free(entry->data);
entry->data = g_memdup(data, len);
entry->len = len;
"DS:swapused:GAUGE:120:0:U",
"DS:roottotal:GAUGE:120:0:U",
"DS:rootused:GAUGE:120:0:U",
- "DS:netin:COUNTER:120:0:U",
- "DS:netout:COUNTER:120:0:U",
+ "DS:netin:DERIVE:120:0:U",
+ "DS:netout:DERIVE:120:0:U",
"RRA:AVERAGE:0.5:1:70", // 1 min avg - one hour
"RRA:AVERAGE:0.5:30:70", // 30 min avg - one day
"DS:mem:GAUGE:120:0:U",
"DS:maxdisk:GAUGE:120:0:U",
"DS:disk:GAUGE:120:0:U",
- "DS:netin:COUNTER:120:0:U",
- "DS:netout:COUNTER:120:0:U",
- "DS:diskread:COUNTER:120:0:U",
- "DS:diskwrite:COUNTER:120:0:U",
+ "DS:netin:DERIVE:120:0:U",
+ "DS:netout:DERIVE:120:0:U",
+ "DS:diskread:DERIVE:120:0:U",
+ "DS:diskwrite:DERIVE:120:0:U",
"RRA:AVERAGE:0.5:1:70", // 1 min avg - one hour
"RRA:AVERAGE:0.5:30:70", // 30 min avg - one day
if (rrdc_connect(rrdcsock) != 0)
use_daemon = 0;
- char *filename = g_strdup_printf(RRDDIR "/%s", key);
+ char *filename = NULL;
int skip = 0;
if (strncmp(key, "pve2-node/", 10) == 0) {
const char *node = key + 10;
- skip = 1;
+ skip = 2;
if (strchr(node, '/') != NULL)
goto keyerror;
if (strlen(node) < 1)
goto keyerror;
+ filename = g_strdup_printf(RRDDIR "/%s", key);
+
if (!g_file_test(filename, G_FILE_TEST_EXISTS)) {
mkdir(RRDDIR "/pve2-node", 0755);
create_rrd_file(filename, argcount, rrd_def_node);
}
- } else if (strncmp(key, "pve2-vm/", 8) == 0) {
- const char *vmid = key + 8;
+ } else if ((strncmp(key, "pve2-vm/", 8) == 0) ||
+ (strncmp(key, "pve2.3-vm/", 10) == 0)) {
+ const char *vmid;
- skip = 2;
+ if (strncmp(key, "pve2-vm/", 8) == 0) {
+ vmid = key + 8;
+ skip = 2;
+ } else {
+ vmid = key + 10;
+ skip = 4;
+ }
if (strchr(vmid, '/') != NULL)
goto keyerror;
if (strlen(vmid) < 1)
goto keyerror;
+ filename = g_strdup_printf(RRDDIR "/%s/%s", "pve2-vm", vmid);
+
if (!g_file_test(filename, G_FILE_TEST_EXISTS)) {
mkdir(RRDDIR "/pve2-vm", 0755);
if (strlen(storage) < 1)
goto keyerror;
+ filename = g_strdup_printf(RRDDIR "/%s", key);
+
if (!g_file_test(filename, G_FILE_TEST_EXISTS)) {
mkdir(RRDDIR "/pve2-storage", 0755);
}
ret:
- g_free(filename);
+ if (filename)
+ g_free(filename);
+
return;
keyerror:
cfs_rrd_dump(GString *str)
{
time_t ctime;
- time(&ctime);
+ g_mutex_lock (&mutex);
+
+ time(&ctime);
if (rrd_dump_buf && (ctime - rrd_dump_last) < 2) {
g_string_assign(str, rrd_dump_buf);
+ g_mutex_unlock (&mutex);
return;
}
if (rrd_dump_buf)
g_free(rrd_dump_buf);
rrd_dump_buf = g_strdup(str->str);
+
+ g_mutex_unlock (&mutex);
}
static gboolean
gpointer data,
guint32 len)
{
+ if (!dfsm_is_initialized(dfsm))
+ return -EACCES;
struct iovec iov[2];
g_return_val_if_fail(msg != NULL, NULL);
if (msg_len < sizeof(clog_entry_t)) {
- cfs_critical("received short log message (%lu < %lu)", msg_len, sizeof(clog_entry_t));
+ cfs_critical("received short log message (%zu < %zu)", msg_len, sizeof(clog_entry_t));
return NULL;
}
entry->ident_len + entry->tag_len + entry->msg_len;
if (msg_len != size) {
- cfs_critical("received log message with wrong size (%lu != %u)", msg_len, size);
+ cfs_critical("received log message with wrong size (%zu != %u)", msg_len, size);
return NULL;
}
g_return_val_if_fail(len != NULL, FALSE);
if (msg_len < 256) {
- cfs_critical("received short kvstore message (%lu < 256)", msg_len);
+ cfs_critical("received short kvstore message (%zu < 256)", msg_len);
return FALSE;
}
GHashTable *kvhash = NULL;
- g_static_mutex_lock (&mutex);
+ g_mutex_lock (&mutex);
if (!nodename || !nodename[0] || !strcmp(nodename, cfs.nodename)) {
kvhash = cfs_status.kvhash;
- } else {
+ } else if (cfs_status.clinfo && cfs_status.clinfo->nodes_byname) {
cfs_clnode_t *clnode;
if ((clnode = g_hash_table_lookup(cfs_status.clinfo->nodes_byname, nodename)))
kvhash = clnode->kvhash;
res = 0;
}
- g_static_mutex_unlock (&mutex);
+ g_mutex_unlock (&mutex);
return res;
}
if (len > CFS_MAX_STATUS_SIZE)
return -EFBIG;
- g_static_mutex_lock (&mutex);
+ g_mutex_lock (&mutex);
gboolean res;
} else {
res = kventry_hash_set(cfs_status.kvhash, key, data, len);
}
- g_static_mutex_unlock (&mutex);
+ g_mutex_unlock (&mutex);
if (cfs_status.kvstore)
kvstore_send_update_message(cfs_status.kvstore, key, data, len);
g_return_val_if_fail(key != NULL, FALSE);
g_return_val_if_fail(data != NULL, FALSE);
- g_static_mutex_lock (&mutex);
+ g_mutex_lock (&mutex);
if (!cfs_status.clinfo || !cfs_status.clinfo->nodes_byid)
goto ret; /* ignore */
}
ret:
- g_static_mutex_unlock (&mutex);
+ g_mutex_unlock (&mutex);
return TRUE;
}
gboolean res = TRUE;
- g_static_mutex_lock (&mutex);
+ g_mutex_lock (&mutex);
GHashTable *ht = cfs_status.kvhash;
GHashTableIter iter;
kvstore_send_update_message(cfs_status.kvstore, entry->key, entry->data, entry->len);
}
- g_static_mutex_unlock (&mutex);
+ g_mutex_unlock (&mutex);
return res;
}
cfs_debug("enter %s", __func__);
- g_static_mutex_lock (&mutex);
+ g_mutex_lock (&mutex);
cfs_clinfo_t *clinfo = cfs_status.clinfo;
cfs_status.clinfo_version++;
}
- g_static_mutex_unlock (&mutex);
+ g_mutex_unlock (&mutex);
}
static gpointer
dfsm_t *
cfs_status_dfsm_new(void)
{
- g_static_mutex_lock (&mutex);
+ g_mutex_lock (&mutex);
cfs_status.kvstore = dfsm_new(NULL, KVSTORE_CPG_GROUP_NAME, G_LOG_DOMAIN,
0, &kvstore_dfsm_callbacks);
- g_static_mutex_unlock (&mutex);
+ g_mutex_unlock (&mutex);
return cfs_status.kvstore;
}
gboolean
cfs_is_quorate(void)
{
- g_static_mutex_lock (&mutex);
+ g_mutex_lock (&mutex);
gboolean res = cfs_status.quorate;
- g_static_mutex_unlock (&mutex);
+ g_mutex_unlock (&mutex);
return res;
}
uint32_t quorate,
gboolean quiet)
{
- g_static_mutex_lock (&mutex);
+ g_mutex_lock (&mutex);
uint32_t prev_quorate = cfs_status.quorate;
cfs_status.quorate = quorate;
cfs_message("node lost quorum");
}
- g_static_mutex_unlock (&mutex);
+ g_mutex_unlock (&mutex);
}
-