2 Copyright (C) 2010 - 2020 Proxmox Server Solutions GmbH
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU Affero General Public License as published by
6 the Free Software Foundation, either version 3 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU Affero General Public License for more details.
14 You should have received a copy of the GNU Affero General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 Author: Dietmar Maurer <dietmar@proxmox.com>
21 #define G_LOG_DOMAIN "status"
25 #endif /* HAVE_CONFIG_H */
32 #include <sys/syslog.h>
34 #include <rrd_client.h>
38 #include "cfs-utils.h"
43 #define KVSTORE_CPG_GROUP_NAME "pve_kvstore_v1"
46 KVSTORE_MESSAGE_UPDATE
= 1,
47 KVSTORE_MESSAGE_UPDATE_COMPLETE
= 2,
48 KVSTORE_MESSAGE_LOG
= 3,
51 static uint32_t vminfo_version_counter
;
79 static memdb_change_t memdb_change_array
[] = {
80 { .path
= "corosync.conf" },
81 { .path
= "corosync.conf.new" },
82 { .path
= "storage.cfg" },
83 { .path
= "user.cfg" },
84 { .path
= "domains.cfg" },
85 { .path
= "priv/shadow.cfg" },
86 { .path
= "priv/acme/plugins.cfg" },
87 { .path
= "priv/tfa.cfg" },
88 { .path
= "priv/token.cfg" },
89 { .path
= "priv/ipam.db" },
90 { .path
= "datacenter.cfg" },
91 { .path
= "vzdump.cron" },
92 { .path
= "jobs.cfg" },
93 { .path
= "ha/crm_commands" },
94 { .path
= "ha/manager_status" },
95 { .path
= "ha/resources.cfg" },
96 { .path
= "ha/groups.cfg" },
97 { .path
= "ha/fence.cfg" },
98 { .path
= "status.cfg" },
99 { .path
= "replication.cfg" },
100 { .path
= "ceph.conf" },
101 { .path
= "sdn/vnets.cfg" },
102 { .path
= "sdn/zones.cfg" },
103 { .path
= "sdn/controllers.cfg" },
104 { .path
= "sdn/subnets.cfg" },
105 { .path
= "sdn/ipams.cfg" },
106 { .path
= "sdn/dns.cfg" },
107 { .path
= "sdn/.running-config" },
108 { .path
= "virtual-guest/cpu-models.conf" },
118 cfs_clinfo_t
*clinfo
;
119 uint32_t clinfo_version
;
122 uint32_t vmlist_version
;
129 GHashTable
*memdb_changes
;
131 clusterlog_t
*clusterlog
;
134 static cfs_status_t cfs_status
;
146 uint32_t cman_version
;
148 GHashTable
*nodes_byid
;
149 GHashTable
*nodes_byname
;
153 g_int32_hash (gconstpointer v
)
155 return *(const uint32_t *) v
;
159 g_int32_equal (gconstpointer v1
,
162 return *((const uint32_t*) v1
) == *((const uint32_t*) v2
);
165 static void vminfo_free(vminfo_t
*vminfo
)
167 g_return_if_fail(vminfo
!= NULL
);
169 if (vminfo
->nodename
)
170 g_free(vminfo
->nodename
);
176 static const char *vminfo_type_to_string(vminfo_t
*vminfo
)
178 if (vminfo
->vmtype
== VMTYPE_QEMU
) {
180 } else if (vminfo
->vmtype
== VMTYPE_OPENVZ
) {
181 // FIXME: remove openvz stuff for 7.x
183 } else if (vminfo
->vmtype
== VMTYPE_LXC
) {
190 static const char *vminfo_type_to_path_type(vminfo_t
*vminfo
)
192 if (vminfo
->vmtype
== VMTYPE_QEMU
) {
193 return "qemu-server"; // special case..
195 return vminfo_type_to_string(vminfo
);
199 int vminfo_to_path(vminfo_t
*vminfo
, GString
*path
)
201 g_return_val_if_fail(vminfo
!= NULL
, -1);
202 g_return_val_if_fail(path
!= NULL
, -1);
204 if (!vminfo
->nodename
)
207 const char *type
= vminfo_type_to_path_type(vminfo
);
208 g_string_printf(path
, "/nodes/%s/%s/%u.conf", vminfo
->nodename
, type
, vminfo
->vmid
);
213 void cfs_clnode_destroy(
214 cfs_clnode_t
*clnode
)
216 g_return_if_fail(clnode
!= NULL
);
219 g_hash_table_destroy(clnode
->kvhash
);
222 g_free(clnode
->name
);
227 cfs_clnode_t
*cfs_clnode_new(
232 g_return_val_if_fail(name
!= NULL
, NULL
);
234 cfs_clnode_t
*clnode
= g_new0(cfs_clnode_t
, 1);
238 clnode
->name
= g_strdup(name
);
239 clnode
->nodeid
= nodeid
;
240 clnode
->votes
= votes
;
245 gboolean
cfs_clinfo_destroy(
246 cfs_clinfo_t
*clinfo
)
248 g_return_val_if_fail(clinfo
!= NULL
, FALSE
);
250 if (clinfo
->cluster_name
)
251 g_free(clinfo
->cluster_name
);
253 if (clinfo
->nodes_byname
)
254 g_hash_table_destroy(clinfo
->nodes_byname
);
256 if (clinfo
->nodes_byid
)
257 g_hash_table_destroy(clinfo
->nodes_byid
);
264 cfs_clinfo_t
*cfs_clinfo_new(
265 const char *cluster_name
,
266 uint32_t cman_version
)
268 g_return_val_if_fail(cluster_name
!= NULL
, NULL
);
270 cfs_clinfo_t
*clinfo
= g_new0(cfs_clinfo_t
, 1);
274 clinfo
->cluster_name
= g_strdup(cluster_name
);
275 clinfo
->cman_version
= cman_version
;
277 if (!(clinfo
->nodes_byid
= g_hash_table_new_full(
278 g_int32_hash
, g_int32_equal
, NULL
,
279 (GDestroyNotify
)cfs_clnode_destroy
)))
282 if (!(clinfo
->nodes_byname
= g_hash_table_new(g_str_hash
, g_str_equal
)))
288 cfs_clinfo_destroy(clinfo
);
293 gboolean
cfs_clinfo_add_node(
294 cfs_clinfo_t
*clinfo
,
295 cfs_clnode_t
*clnode
)
297 g_return_val_if_fail(clinfo
!= NULL
, FALSE
);
298 g_return_val_if_fail(clnode
!= NULL
, FALSE
);
300 g_hash_table_replace(clinfo
->nodes_byid
, &clnode
->nodeid
, clnode
);
301 g_hash_table_replace(clinfo
->nodes_byname
, clnode
->name
, clnode
);
307 cfs_create_memberlist_msg(
310 g_return_val_if_fail(str
!= NULL
, -EINVAL
);
312 g_mutex_lock (&mutex
);
314 g_string_append_printf(str
,"{\n");
318 cfs_clinfo_t
*clinfo
= cfs_status
.clinfo
;
320 if (clinfo
&& clinfo
->nodes_byid
)
321 nodecount
= g_hash_table_size(clinfo
->nodes_byid
);
324 g_string_append_printf(str
, "\"nodename\": \"%s\",\n", cfs
.nodename
);
325 g_string_append_printf(str
, "\"version\": %u,\n", cfs_status
.clinfo_version
);
327 g_string_append_printf(str
, "\"cluster\": { ");
328 g_string_append_printf(str
, "\"name\": \"%s\", \"version\": %d, "
329 "\"nodes\": %d, \"quorate\": %d ",
330 clinfo
->cluster_name
, clinfo
->cman_version
,
331 nodecount
, cfs_status
.quorate
);
333 g_string_append_printf(str
,"},\n");
334 g_string_append_printf(str
,"\"nodelist\": {\n");
336 GHashTable
*ht
= clinfo
->nodes_byid
;
340 g_hash_table_iter_init (&iter
, ht
);
343 while (g_hash_table_iter_next (&iter
, &key
, &value
)) {
344 cfs_clnode_t
*node
= (cfs_clnode_t
*)value
;
345 if (i
) g_string_append_printf(str
, ",\n");
348 g_string_append_printf(str
, " \"%s\": { \"id\": %d, \"online\": %d",
349 node
->name
, node
->nodeid
, node
->online
);
352 char *ip
= (char *)g_hash_table_lookup(cfs_status
.iphash
, node
->name
);
354 g_string_append_printf(str
, ", \"ip\": \"%s\"", ip
);
357 g_string_append_printf(str
, "}");
360 g_string_append_printf(str
,"\n }\n");
362 g_string_append_printf(str
, "\"nodename\": \"%s\",\n", cfs
.nodename
);
363 g_string_append_printf(str
, "\"version\": %u\n", cfs_status
.clinfo_version
);
366 g_string_append_printf(str
,"}\n");
368 g_mutex_unlock (&mutex
);
374 kventry_free(kventry_t
*entry
)
376 g_return_if_fail(entry
!= NULL
);
384 kventry_hash_new(void)
386 return g_hash_table_new_full(g_str_hash
, g_str_equal
, NULL
,
387 (GDestroyNotify
)kventry_free
);
391 rrdentry_free(rrdentry_t
*entry
)
393 g_return_if_fail(entry
!= NULL
);
401 rrdentry_hash_new(void)
403 return g_hash_table_new_full(g_str_hash
, g_str_equal
, NULL
,
404 (GDestroyNotify
)rrdentry_free
);
408 cfs_cluster_log_dump(GString
*str
, const char *user
, guint max_entries
)
410 clusterlog_dump(cfs_status
.clusterlog
, str
, user
, max_entries
);
414 cfs_cluster_log(clog_entry_t
*entry
)
416 g_return_if_fail(entry
!= NULL
);
418 clusterlog_insert(cfs_status
.clusterlog
, entry
);
420 if (cfs_status
.kvstore
) {
422 iov
[0].iov_base
= (char *)entry
;
423 iov
[0].iov_len
= clog_entry_size(entry
);
425 if (dfsm_is_initialized(cfs_status
.kvstore
))
426 dfsm_send_message(cfs_status
.kvstore
, KVSTORE_MESSAGE_LOG
, iov
, 1);
430 void cfs_status_init(void)
432 g_mutex_lock (&mutex
);
434 cfs_status
.start_time
= time(NULL
);
436 cfs_status
.vmlist
= vmlist_hash_new();
438 cfs_status
.kvhash
= kventry_hash_new();
440 cfs_status
.rrdhash
= rrdentry_hash_new();
442 cfs_status
.iphash
= g_hash_table_new_full(g_str_hash
, g_str_equal
, g_free
, g_free
);
444 cfs_status
.memdb_changes
= g_hash_table_new(g_str_hash
, g_str_equal
);
446 for (int i
= 0; i
< G_N_ELEMENTS(memdb_change_array
); i
++) {
447 g_hash_table_replace(cfs_status
.memdb_changes
,
448 memdb_change_array
[i
].path
,
449 &memdb_change_array
[i
]);
452 cfs_status
.clusterlog
= clusterlog_new();
455 clusterlog_add(cfs_status
.clusterlog
, "root", "cluster", getpid(),
456 LOG_INFO
, "starting cluster log");
458 g_mutex_unlock (&mutex
);
461 void cfs_status_cleanup(void)
463 g_mutex_lock (&mutex
);
465 cfs_status
.clinfo_version
++;
467 if (cfs_status
.clinfo
) {
468 cfs_clinfo_destroy(cfs_status
.clinfo
);
469 cfs_status
.clinfo
= NULL
;
472 if (cfs_status
.vmlist
) {
473 g_hash_table_destroy(cfs_status
.vmlist
);
474 cfs_status
.vmlist
= NULL
;
477 if (cfs_status
.kvhash
) {
478 g_hash_table_destroy(cfs_status
.kvhash
);
479 cfs_status
.kvhash
= NULL
;
482 if (cfs_status
.rrdhash
) {
483 g_hash_table_destroy(cfs_status
.rrdhash
);
484 cfs_status
.rrdhash
= NULL
;
487 if (cfs_status
.iphash
) {
488 g_hash_table_destroy(cfs_status
.iphash
);
489 cfs_status
.iphash
= NULL
;
492 if (cfs_status
.clusterlog
)
493 clusterlog_destroy(cfs_status
.clusterlog
);
495 g_mutex_unlock (&mutex
);
498 void cfs_status_set_clinfo(
499 cfs_clinfo_t
*clinfo
)
501 g_return_if_fail(clinfo
!= NULL
);
503 g_mutex_lock (&mutex
);
505 cfs_status
.clinfo_version
++;
507 cfs_clinfo_t
*old
= cfs_status
.clinfo
;
509 cfs_status
.clinfo
= clinfo
;
511 cfs_message("update cluster info (cluster name %s, version = %d)",
512 clinfo
->cluster_name
, clinfo
->cman_version
);
515 if (old
&& old
->nodes_byid
&& clinfo
->nodes_byid
) {
517 GHashTable
*ht
= clinfo
->nodes_byid
;
521 g_hash_table_iter_init (&iter
, ht
);
523 while (g_hash_table_iter_next (&iter
, &key
, &value
)) {
524 cfs_clnode_t
*node
= (cfs_clnode_t
*)value
;
525 cfs_clnode_t
*oldnode
;
526 if ((oldnode
= g_hash_table_lookup(old
->nodes_byid
, key
))) {
527 node
->online
= oldnode
->online
;
528 node
->kvhash
= oldnode
->kvhash
;
529 oldnode
->kvhash
= NULL
;
536 cfs_clinfo_destroy(old
);
539 g_mutex_unlock (&mutex
);
543 dump_kvstore_versions(
546 const char *nodename
)
548 g_return_if_fail(kvhash
!= NULL
);
549 g_return_if_fail(str
!= NULL
);
550 g_return_if_fail(nodename
!= NULL
);
552 GHashTable
*ht
= kvhash
;
556 g_string_append_printf(str
, "\"%s\": {\n", nodename
);
558 g_hash_table_iter_init (&iter
, ht
);
561 while (g_hash_table_iter_next (&iter
, &key
, &value
)) {
562 kventry_t
*entry
= (kventry_t
*)value
;
563 if (i
) g_string_append_printf(str
, ",\n");
565 g_string_append_printf(str
,"\"%s\": %u", entry
->key
, entry
->version
);
568 g_string_append_printf(str
, "}\n");
572 cfs_create_version_msg(GString
*str
)
574 g_return_val_if_fail(str
!= NULL
, -EINVAL
);
576 g_mutex_lock (&mutex
);
578 g_string_append_printf(str
,"{\n");
580 g_string_append_printf(str
, "\"starttime\": %lu,\n", (unsigned long)cfs_status
.start_time
);
582 g_string_append_printf(str
, "\"clinfo\": %u,\n", cfs_status
.clinfo_version
);
584 g_string_append_printf(str
, "\"vmlist\": %u,\n", cfs_status
.vmlist_version
);
586 for (int i
= 0; i
< G_N_ELEMENTS(memdb_change_array
); i
++) {
587 g_string_append_printf(str
, "\"%s\": %u,\n",
588 memdb_change_array
[i
].path
,
589 memdb_change_array
[i
].version
);
592 g_string_append_printf(str
, "\"kvstore\": {\n");
594 dump_kvstore_versions(str
, cfs_status
.kvhash
, cfs
.nodename
);
596 cfs_clinfo_t
*clinfo
= cfs_status
.clinfo
;
598 if (clinfo
&& clinfo
->nodes_byid
) {
599 GHashTable
*ht
= clinfo
->nodes_byid
;
603 g_hash_table_iter_init (&iter
, ht
);
605 while (g_hash_table_iter_next (&iter
, &key
, &value
)) {
606 cfs_clnode_t
*node
= (cfs_clnode_t
*)value
;
609 g_string_append_printf(str
, ",\n");
610 dump_kvstore_versions(str
, node
->kvhash
, node
->name
);
614 g_string_append_printf(str
,"}\n");
616 g_string_append_printf(str
,"}\n");
618 g_mutex_unlock (&mutex
);
624 vmlist_hash_new(void)
626 return g_hash_table_new_full(g_int_hash
, g_int_equal
, NULL
,
627 (GDestroyNotify
)vminfo_free
);
631 vmlist_hash_insert_vm(
635 const char *nodename
,
638 g_return_val_if_fail(vmlist
!= NULL
, FALSE
);
639 g_return_val_if_fail(nodename
!= NULL
, FALSE
);
640 g_return_val_if_fail(vmid
!= 0, FALSE
);
641 // FIXME: remove openvz stuff for 7.x
642 g_return_val_if_fail(vmtype
== VMTYPE_QEMU
|| vmtype
== VMTYPE_OPENVZ
||
643 vmtype
== VMTYPE_LXC
, FALSE
);
645 if (!replace
&& g_hash_table_lookup(vmlist
, &vmid
)) {
646 cfs_critical("detected duplicate VMID %d", vmid
);
650 vminfo_t
*vminfo
= g_new0(vminfo_t
, 1);
653 vminfo
->vmtype
= vmtype
;
654 vminfo
->nodename
= g_strdup(nodename
);
656 vminfo
->version
= ++vminfo_version_counter
;
658 g_hash_table_replace(vmlist
, &vminfo
->vmid
, vminfo
);
667 const char *nodename
)
669 g_return_if_fail(cfs_status
.vmlist
!= NULL
);
670 g_return_if_fail(nodename
!= NULL
);
671 g_return_if_fail(vmid
!= 0);
672 // FIXME: remove openvz stuff for 7.x
673 g_return_if_fail(vmtype
== VMTYPE_QEMU
|| vmtype
== VMTYPE_OPENVZ
||
674 vmtype
== VMTYPE_LXC
);
676 cfs_debug("vmlist_register_vm: %s/%u %d", nodename
, vmid
, vmtype
);
678 g_mutex_lock (&mutex
);
680 cfs_status
.vmlist_version
++;
682 vmlist_hash_insert_vm(cfs_status
.vmlist
, vmtype
, vmid
, nodename
, TRUE
);
684 g_mutex_unlock (&mutex
);
688 vmlist_different_vm_exists(
691 const char *nodename
)
693 g_return_val_if_fail(cfs_status
.vmlist
!= NULL
, FALSE
);
694 g_return_val_if_fail(vmid
!= 0, FALSE
);
696 gboolean res
= FALSE
;
698 g_mutex_lock (&mutex
);
701 if ((vminfo
= (vminfo_t
*)g_hash_table_lookup(cfs_status
.vmlist
, &vmid
))) {
702 if (!(vminfo
->vmtype
== vmtype
&& strcmp(vminfo
->nodename
, nodename
) == 0))
705 g_mutex_unlock (&mutex
);
714 g_return_val_if_fail(cfs_status
.vmlist
!= NULL
, FALSE
);
715 g_return_val_if_fail(vmid
!= 0, FALSE
);
717 g_mutex_lock (&mutex
);
719 gpointer res
= g_hash_table_lookup(cfs_status
.vmlist
, &vmid
);
721 g_mutex_unlock (&mutex
);
730 g_return_if_fail(cfs_status
.vmlist
!= NULL
);
731 g_return_if_fail(vmid
!= 0);
733 g_mutex_lock (&mutex
);
735 cfs_status
.vmlist_version
++;
737 g_hash_table_remove(cfs_status
.vmlist
, &vmid
);
739 g_mutex_unlock (&mutex
);
742 void cfs_status_set_vmlist(
745 g_return_if_fail(vmlist
!= NULL
);
747 g_mutex_lock (&mutex
);
749 cfs_status
.vmlist_version
++;
751 if (cfs_status
.vmlist
)
752 g_hash_table_destroy(cfs_status
.vmlist
);
754 cfs_status
.vmlist
= vmlist
;
756 g_mutex_unlock (&mutex
);
760 cfs_create_vmlist_msg(GString
*str
)
762 g_return_val_if_fail(cfs_status
.vmlist
!= NULL
, -EINVAL
);
763 g_return_val_if_fail(str
!= NULL
, -EINVAL
);
765 g_mutex_lock (&mutex
);
767 g_string_append_printf(str
,"{\n");
769 GHashTable
*ht
= cfs_status
.vmlist
;
771 guint count
= g_hash_table_size(ht
);
774 g_string_append_printf(str
,"\"version\": %u\n", cfs_status
.vmlist_version
);
776 g_string_append_printf(str
,"\"version\": %u,\n", cfs_status
.vmlist_version
);
778 g_string_append_printf(str
,"\"ids\": {\n");
783 g_hash_table_iter_init (&iter
, ht
);
786 while (g_hash_table_iter_next (&iter
, &key
, &value
)) {
787 vminfo_t
*vminfo
= (vminfo_t
*)value
;
788 const char *type
= vminfo_type_to_string(vminfo
);
791 g_string_append_printf(str
, ",\n");
794 g_string_append_printf(str
,"\"%u\": { \"node\": \"%s\", \"type\": \"%s\", \"version\": %u }",
795 vminfo
->vmid
, vminfo
->nodename
, type
, vminfo
->version
);
798 g_string_append_printf(str
,"}\n");
800 g_string_append_printf(str
,"\n}\n");
802 g_mutex_unlock (&mutex
);
807 // checks the conf for a line starting with '$prop:' and returns the value
808 // afterwards, whitout initial whitespace(s), we only deal with the format
809 // restricion imposed by our perl VM config parser, main reference is
810 // PVE::QemuServer::parse_vm_config this allows to be very fast and still
812 // main restrictions used for our advantage is the properties match reges:
813 // ($line =~ m/^([a-z][a-z_]*\d*):\s*(.+?)\s*$/) from parse_vm_config
814 // currently we only look at the current configuration in place, i.e., *no*
815 // snapshort and *no* pending changes
817 _get_property_value(char *conf
, int conf_size
, const char *prop
, int prop_len
)
819 const char *const conf_end
= conf
+ conf_size
;
821 size_t remaining_size
;
823 char *next_newline
= memchr(conf
, '\n', conf_size
);
824 if (next_newline
== NULL
) {
825 return NULL
; // valid property lines end with \n, but none in the config
827 *next_newline
= '\0';
829 while (line
!= NULL
) {
830 if (!line
[0]) goto next
;
832 // snapshot or pending section start, but nothing found yet -> not found
833 if (line
[0] == '[') return NULL
;
834 // properties start with /^[a-z]/, so continue early if not
835 if (line
[0] < 'a' || line
[0] > 'z') goto next
;
837 int line_len
= strlen(line
);
838 if (line_len
<= prop_len
+ 1) goto next
;
840 if (line
[prop_len
] == ':' && memcmp(line
, prop
, prop_len
) == 0) { // found
841 char *v_start
= &line
[prop_len
+ 1];
843 // drop initial value whitespaces here already
844 while (*v_start
&& isspace(*v_start
)) v_start
++;
846 if (!*v_start
) return NULL
;
848 char *v_end
= &line
[line_len
- 1];
849 while (v_end
> v_start
&& isspace(*v_end
)) v_end
--;
855 line
= next_newline
+ 1;
856 remaining_size
= conf_end
- line
;
857 if (remaining_size
<= prop_len
) {
860 next_newline
= memchr(line
, '\n', remaining_size
);
861 if (next_newline
== NULL
) {
862 return NULL
; // valid property lines end with \n, but none in the config
864 *next_newline
= '\0';
867 return NULL
; // not found
871 _g_str_append_kv_jsonescaped(GString
*str
, const char *k
, const char *v
)
873 g_string_append_printf(str
, "\"%s\": \"", k
);
876 if (*v
== '\\' || *v
== '"') {
877 g_string_append_c(str
, '\\');
879 g_string_append_c(str
, *v
);
882 g_string_append_c(str
, '"');
886 cfs_create_guest_conf_property_msg(GString
*str
, memdb_t
*memdb
, const char *prop
, uint32_t vmid
)
888 g_return_val_if_fail(cfs_status
.vmlist
!= NULL
, -EINVAL
);
889 g_return_val_if_fail(str
!= NULL
, -EINVAL
);
891 int prop_len
= strlen(prop
);
893 GString
*path
= NULL
;
895 // Prelock &memdb->mutex in order to enable the usage of memdb_read_nolock
896 // to prevent Deadlocks as in #2553
897 g_mutex_lock (&memdb
->mutex
);
898 g_mutex_lock (&mutex
);
900 g_string_printf(str
,"{\n");
902 GHashTable
*ht
= cfs_status
.vmlist
;
904 if (!g_hash_table_size(ht
)) {
908 if ((path
= g_string_sized_new(256)) == NULL
) {
914 vminfo_t
*vminfo
= (vminfo_t
*) g_hash_table_lookup(cfs_status
.vmlist
, &vmid
);
915 if (vminfo
== NULL
) goto enoent
;
917 if (!vminfo_to_path(vminfo
, path
)) goto err
;
919 // use memdb_read_nolock because lock is handled here
920 int size
= memdb_read_nolock(memdb
, path
->str
, &tmp
);
921 if (tmp
== NULL
) goto err
;
922 if (size
<= prop_len
) goto ret
;
924 char *val
= _get_property_value(tmp
, size
, prop
, prop_len
);
925 if (val
== NULL
) goto ret
;
927 g_string_append_printf(str
, "\"%u\":{", vmid
);
928 _g_str_append_kv_jsonescaped(str
, prop
, val
);
929 g_string_append_c(str
, '}');
933 g_hash_table_iter_init (&iter
, ht
);
937 while (g_hash_table_iter_next (&iter
, &key
, &value
)) {
938 vminfo_t
*vminfo
= (vminfo_t
*)value
;
940 if (!vminfo_to_path(vminfo
, path
)) goto err
;
942 g_free(tmp
); // no-op if already null
944 // use memdb_read_nolock because lock is handled here
945 int size
= memdb_read_nolock(memdb
, path
->str
, &tmp
);
946 if (tmp
== NULL
|| size
<= prop_len
) continue;
948 char *val
= _get_property_value(tmp
, size
, prop
, prop_len
);
949 if (val
== NULL
) continue;
951 if (!first
) g_string_append_printf(str
, ",\n");
954 g_string_append_printf(str
, "\"%u\":{", vminfo
->vmid
);
955 _g_str_append_kv_jsonescaped(str
, prop
, val
);
956 g_string_append_c(str
, '}');
962 g_string_free(path
, TRUE
);
964 g_string_append_printf(str
,"\n}\n");
965 g_mutex_unlock (&mutex
);
966 g_mutex_unlock (&memdb
->mutex
);
977 record_memdb_change(const char *path
)
979 g_return_if_fail(cfs_status
.memdb_changes
!= 0);
983 if ((ce
= (memdb_change_t
*)g_hash_table_lookup(cfs_status
.memdb_changes
, path
))) {
989 record_memdb_reload(void)
991 for (int i
= 0; i
< G_N_ELEMENTS(memdb_change_array
); i
++) {
992 memdb_change_array
[i
].version
++;
1003 g_return_val_if_fail(kvhash
!= NULL
, FALSE
);
1004 g_return_val_if_fail(key
!= NULL
, FALSE
);
1005 g_return_val_if_fail(data
!= NULL
, FALSE
);
1009 g_hash_table_remove(kvhash
, key
);
1010 } else if ((entry
= (kventry_t
*)g_hash_table_lookup(kvhash
, key
))) {
1011 g_free(entry
->data
);
1012 entry
->data
= g_memdup(data
, len
);
1016 kventry_t
*entry
= g_new0(kventry_t
, 1);
1018 entry
->key
= g_strdup(key
);
1019 entry
->data
= g_memdup(data
, len
);
1022 g_hash_table_replace(kvhash
, entry
->key
, entry
);
1028 static const char *rrd_def_node
[] = {
1029 "DS:loadavg:GAUGE:120:0:U",
1030 "DS:maxcpu:GAUGE:120:0:U",
1031 "DS:cpu:GAUGE:120:0:U",
1032 "DS:iowait:GAUGE:120:0:U",
1033 "DS:memtotal:GAUGE:120:0:U",
1034 "DS:memused:GAUGE:120:0:U",
1035 "DS:swaptotal:GAUGE:120:0:U",
1036 "DS:swapused:GAUGE:120:0:U",
1037 "DS:roottotal:GAUGE:120:0:U",
1038 "DS:rootused:GAUGE:120:0:U",
1039 "DS:netin:DERIVE:120:0:U",
1040 "DS:netout:DERIVE:120:0:U",
1042 "RRA:AVERAGE:0.5:1:70", // 1 min avg - one hour
1043 "RRA:AVERAGE:0.5:30:70", // 30 min avg - one day
1044 "RRA:AVERAGE:0.5:180:70", // 3 hour avg - one week
1045 "RRA:AVERAGE:0.5:720:70", // 12 hour avg - one month
1046 "RRA:AVERAGE:0.5:10080:70", // 7 day avg - ony year
1048 "RRA:MAX:0.5:1:70", // 1 min max - one hour
1049 "RRA:MAX:0.5:30:70", // 30 min max - one day
1050 "RRA:MAX:0.5:180:70", // 3 hour max - one week
1051 "RRA:MAX:0.5:720:70", // 12 hour max - one month
1052 "RRA:MAX:0.5:10080:70", // 7 day max - ony year
1056 static const char *rrd_def_vm
[] = {
1057 "DS:maxcpu:GAUGE:120:0:U",
1058 "DS:cpu:GAUGE:120:0:U",
1059 "DS:maxmem:GAUGE:120:0:U",
1060 "DS:mem:GAUGE:120:0:U",
1061 "DS:maxdisk:GAUGE:120:0:U",
1062 "DS:disk:GAUGE:120:0:U",
1063 "DS:netin:DERIVE:120:0:U",
1064 "DS:netout:DERIVE:120:0:U",
1065 "DS:diskread:DERIVE:120:0:U",
1066 "DS:diskwrite:DERIVE:120:0:U",
1068 "RRA:AVERAGE:0.5:1:70", // 1 min avg - one hour
1069 "RRA:AVERAGE:0.5:30:70", // 30 min avg - one day
1070 "RRA:AVERAGE:0.5:180:70", // 3 hour avg - one week
1071 "RRA:AVERAGE:0.5:720:70", // 12 hour avg - one month
1072 "RRA:AVERAGE:0.5:10080:70", // 7 day avg - ony year
1074 "RRA:MAX:0.5:1:70", // 1 min max - one hour
1075 "RRA:MAX:0.5:30:70", // 30 min max - one day
1076 "RRA:MAX:0.5:180:70", // 3 hour max - one week
1077 "RRA:MAX:0.5:720:70", // 12 hour max - one month
1078 "RRA:MAX:0.5:10080:70", // 7 day max - ony year
1082 static const char *rrd_def_storage
[] = {
1083 "DS:total:GAUGE:120:0:U",
1084 "DS:used:GAUGE:120:0:U",
1086 "RRA:AVERAGE:0.5:1:70", // 1 min avg - one hour
1087 "RRA:AVERAGE:0.5:30:70", // 30 min avg - one day
1088 "RRA:AVERAGE:0.5:180:70", // 3 hour avg - one week
1089 "RRA:AVERAGE:0.5:720:70", // 12 hour avg - one month
1090 "RRA:AVERAGE:0.5:10080:70", // 7 day avg - ony year
1092 "RRA:MAX:0.5:1:70", // 1 min max - one hour
1093 "RRA:MAX:0.5:30:70", // 30 min max - one day
1094 "RRA:MAX:0.5:180:70", // 3 hour max - one week
1095 "RRA:MAX:0.5:720:70", // 12 hour max - one month
1096 "RRA:MAX:0.5:10080:70", // 7 day max - ony year
1100 #define RRDDIR "/var/lib/rrdcached/db"
1104 const char *filename
,
1106 const char *rrddef
[])
1108 /* start at day boundary */
1111 struct tm
*ltm
= localtime(&ctime
);
1117 if (rrd_create_r(filename
, 60, timelocal(ltm
), argcount
, rrddef
)) {
1118 cfs_message("RRD create error %s: %s", filename
, rrd_get_error());
1122 static inline const char *
1128 while (*data
&& found
< count
) {
1141 g_return_if_fail(key
!= NULL
);
1142 g_return_if_fail(data
!= NULL
);
1143 g_return_if_fail(len
> 0);
1144 g_return_if_fail(len
< 4096);
1146 static const char *rrdcsock
= "unix:/var/run/rrdcached.sock";
1149 if (rrdc_connect(rrdcsock
) != 0)
1152 char *filename
= NULL
;
1156 if (strncmp(key
, "pve2-node/", 10) == 0) {
1157 const char *node
= key
+ 10;
1161 if (strchr(node
, '/') != NULL
)
1164 if (strlen(node
) < 1)
1167 filename
= g_strdup_printf(RRDDIR
"/%s", key
);
1169 if (!g_file_test(filename
, G_FILE_TEST_EXISTS
)) {
1171 mkdir(RRDDIR
"/pve2-node", 0755);
1172 int argcount
= sizeof(rrd_def_node
)/sizeof(void*) - 1;
1173 create_rrd_file(filename
, argcount
, rrd_def_node
);
1176 } else if ((strncmp(key
, "pve2-vm/", 8) == 0) ||
1177 (strncmp(key
, "pve2.3-vm/", 10) == 0)) {
1180 if (strncmp(key
, "pve2-vm/", 8) == 0) {
1188 if (strchr(vmid
, '/') != NULL
)
1191 if (strlen(vmid
) < 1)
1194 filename
= g_strdup_printf(RRDDIR
"/%s/%s", "pve2-vm", vmid
);
1196 if (!g_file_test(filename
, G_FILE_TEST_EXISTS
)) {
1198 mkdir(RRDDIR
"/pve2-vm", 0755);
1199 int argcount
= sizeof(rrd_def_vm
)/sizeof(void*) - 1;
1200 create_rrd_file(filename
, argcount
, rrd_def_vm
);
1203 } else if (strncmp(key
, "pve2-storage/", 13) == 0) {
1204 const char *node
= key
+ 13;
1206 const char *storage
= node
;
1207 while (*storage
&& *storage
!= '/')
1210 if (*storage
!= '/' || ((storage
- node
) < 1))
1215 if (strchr(storage
, '/') != NULL
)
1218 if (strlen(storage
) < 1)
1221 filename
= g_strdup_printf(RRDDIR
"/%s", key
);
1223 if (!g_file_test(filename
, G_FILE_TEST_EXISTS
)) {
1225 mkdir(RRDDIR
"/pve2-storage", 0755);
1227 char *dir
= g_path_get_dirname(filename
);
1231 int argcount
= sizeof(rrd_def_storage
)/sizeof(void*) - 1;
1232 create_rrd_file(filename
, argcount
, rrd_def_storage
);
1239 const char *dp
= skip
? rrd_skip_data(data
, skip
) : data
;
1241 const char *update_args
[] = { dp
, NULL
};
1245 if ((status
= rrdc_update(filename
, 1, update_args
)) != 0) {
1246 cfs_message("RRDC update error %s: %d", filename
, status
);
1249 if (rrd_update_r(filename
, NULL
, 1, update_args
) != 0) {
1250 cfs_message("RRD update error %s: %s", filename
, rrd_get_error());
1256 if (rrd_update_r(filename
, NULL
, 1, update_args
) != 0) {
1257 cfs_message("RRD update error %s: %s", filename
, rrd_get_error());
1268 cfs_critical("RRD update error: unknown/wrong key %s", key
);
1278 rrdentry_t
*entry
= (rrdentry_t
*)value
;
1279 uint32_t ctime
= GPOINTER_TO_UINT(user_data
);
1281 int diff
= ctime
- entry
->time
;
1283 /* remove everything older than 5 minutes */
1286 return (diff
> expire
) ? TRUE
: FALSE
;
1289 static char *rrd_dump_buf
= NULL
;
1290 static time_t rrd_dump_last
= 0;
1293 cfs_rrd_dump(GString
*str
)
1297 g_mutex_lock (&mutex
);
1300 if (rrd_dump_buf
&& (ctime
- rrd_dump_last
) < 2) {
1301 g_string_assign(str
, rrd_dump_buf
);
1302 g_mutex_unlock (&mutex
);
1306 /* remove old data */
1307 g_hash_table_foreach_remove(cfs_status
.rrdhash
, rrd_entry_is_old
,
1308 GUINT_TO_POINTER(ctime
));
1310 g_string_set_size(str
, 0);
1312 GHashTableIter iter
;
1313 gpointer key
, value
;
1315 g_hash_table_iter_init (&iter
, cfs_status
.rrdhash
);
1317 while (g_hash_table_iter_next (&iter
, &key
, &value
)) {
1318 rrdentry_t
*entry
= (rrdentry_t
*)value
;
1319 g_string_append(str
, key
);
1320 g_string_append(str
, ":");
1321 g_string_append(str
, entry
->data
);
1322 g_string_append(str
, "\n");
1325 g_string_append_c(str
, 0); // never return undef
1327 rrd_dump_last
= ctime
;
1329 g_free(rrd_dump_buf
);
1330 rrd_dump_buf
= g_strdup(str
->str
);
1332 g_mutex_unlock (&mutex
);
1338 const char *nodename
,
1342 g_return_val_if_fail(iphash
!= NULL
, FALSE
);
1343 g_return_val_if_fail(nodename
!= NULL
, FALSE
);
1344 g_return_val_if_fail(ip
!= NULL
, FALSE
);
1345 g_return_val_if_fail(len
> 0, FALSE
);
1346 g_return_val_if_fail(len
< 256, FALSE
);
1347 g_return_val_if_fail(ip
[len
-1] == 0, FALSE
);
1349 char *oldip
= (char *)g_hash_table_lookup(iphash
, nodename
);
1351 if (!oldip
|| (strcmp(oldip
, ip
) != 0)) {
1352 cfs_status
.clinfo_version
++;
1353 g_hash_table_replace(iphash
, g_strdup(nodename
), g_strdup(ip
));
1361 GHashTable
*rrdhash
,
1366 g_return_val_if_fail(rrdhash
!= NULL
, FALSE
);
1367 g_return_val_if_fail(key
!= NULL
, FALSE
);
1368 g_return_val_if_fail(data
!= NULL
, FALSE
);
1369 g_return_val_if_fail(len
> 0, FALSE
);
1370 g_return_val_if_fail(len
< 4096, FALSE
);
1371 g_return_val_if_fail(data
[len
-1] == 0, FALSE
);
1374 if ((entry
= (rrdentry_t
*)g_hash_table_lookup(rrdhash
, key
))) {
1375 g_free(entry
->data
);
1376 entry
->data
= g_memdup(data
, len
);
1378 entry
->time
= time(NULL
);
1380 rrdentry_t
*entry
= g_new0(rrdentry_t
, 1);
1382 entry
->key
= g_strdup(key
);
1383 entry
->data
= g_memdup(data
, len
);
1385 entry
->time
= time(NULL
);
1387 g_hash_table_replace(rrdhash
, entry
->key
, entry
);
1390 update_rrd_data(key
, data
, len
);
1396 kvstore_send_update_message(
1402 if (!dfsm_is_initialized(dfsm
))
1405 struct iovec iov
[2];
1408 g_strlcpy(name
, key
, sizeof(name
));
1410 iov
[0].iov_base
= &name
;
1411 iov
[0].iov_len
= sizeof(name
);
1413 iov
[1].iov_base
= (char *)data
;
1414 iov
[1].iov_len
= len
;
1416 if (dfsm_send_message(dfsm
, KVSTORE_MESSAGE_UPDATE
, iov
, 2) == CS_OK
)
1422 static clog_entry_t
*
1423 kvstore_parse_log_message(
1427 g_return_val_if_fail(msg
!= NULL
, NULL
);
1429 if (msg_len
< sizeof(clog_entry_t
)) {
1430 cfs_critical("received short log message (%zu < %zu)", msg_len
, sizeof(clog_entry_t
));
1434 clog_entry_t
*entry
= (clog_entry_t
*)msg
;
1436 uint32_t size
= sizeof(clog_entry_t
) + entry
->node_len
+
1437 entry
->ident_len
+ entry
->tag_len
+ entry
->msg_len
;
1439 if (msg_len
!= size
) {
1440 cfs_critical("received log message with wrong size (%zu != %u)", msg_len
, size
);
1444 char *msgptr
= entry
->data
;
1446 if (*((char *)msgptr
+ entry
->node_len
- 1)) {
1447 cfs_critical("unterminated string in log message");
1450 msgptr
+= entry
->node_len
;
1452 if (*((char *)msgptr
+ entry
->ident_len
- 1)) {
1453 cfs_critical("unterminated string in log message");
1456 msgptr
+= entry
->ident_len
;
1458 if (*((char *)msgptr
+ entry
->tag_len
- 1)) {
1459 cfs_critical("unterminated string in log message");
1462 msgptr
+= entry
->tag_len
;
1464 if (*((char *)msgptr
+ entry
->msg_len
- 1)) {
1465 cfs_critical("unterminated string in log message");
1473 kvstore_parse_update_message(
1477 gconstpointer
*data
,
1480 g_return_val_if_fail(msg
!= NULL
, FALSE
);
1481 g_return_val_if_fail(key
!= NULL
, FALSE
);
1482 g_return_val_if_fail(data
!= NULL
, FALSE
);
1483 g_return_val_if_fail(len
!= NULL
, FALSE
);
1485 if (msg_len
< 256) {
1486 cfs_critical("received short kvstore message (%zu < 256)", msg_len
);
1490 /* test if key is null terminated */
1492 for (i
= 0; i
< 256; i
++)
1493 if (((char *)msg
)[i
] == 0)
1500 *len
= msg_len
- 256;
1502 *data
= (char *) msg
+ 256;
1508 cfs_create_status_msg(
1510 const char *nodename
,
1513 g_return_val_if_fail(str
!= NULL
, -EINVAL
);
1514 g_return_val_if_fail(key
!= NULL
, -EINVAL
);
1518 GHashTable
*kvhash
= NULL
;
1520 g_mutex_lock (&mutex
);
1522 if (!nodename
|| !nodename
[0] || !strcmp(nodename
, cfs
.nodename
)) {
1523 kvhash
= cfs_status
.kvhash
;
1524 } else if (cfs_status
.clinfo
&& cfs_status
.clinfo
->nodes_byname
) {
1525 cfs_clnode_t
*clnode
;
1526 if ((clnode
= g_hash_table_lookup(cfs_status
.clinfo
->nodes_byname
, nodename
)))
1527 kvhash
= clnode
->kvhash
;
1531 if (kvhash
&& (entry
= (kventry_t
*)g_hash_table_lookup(kvhash
, key
))) {
1532 g_string_append_len(str
, entry
->data
, entry
->len
);
1536 g_mutex_unlock (&mutex
);
1547 g_return_val_if_fail(key
!= NULL
, FALSE
);
1548 g_return_val_if_fail(data
!= NULL
, FALSE
);
1549 g_return_val_if_fail(cfs_status
.kvhash
!= NULL
, FALSE
);
1551 if (len
> CFS_MAX_STATUS_SIZE
)
1554 g_mutex_lock (&mutex
);
1558 if (strncmp(key
, "rrd/", 4) == 0) {
1559 res
= rrdentry_hash_set(cfs_status
.rrdhash
, key
+ 4, data
, len
);
1560 } else if (!strcmp(key
, "nodeip")) {
1561 res
= nodeip_hash_set(cfs_status
.iphash
, cfs
.nodename
, data
, len
);
1563 res
= kventry_hash_set(cfs_status
.kvhash
, key
, data
, len
);
1565 g_mutex_unlock (&mutex
);
1567 if (cfs_status
.kvstore
)
1568 kvstore_send_update_message(cfs_status
.kvstore
, key
, data
, len
);
1570 return res
? 0 : -ENOMEM
;
1574 cfs_kvstore_node_set(
1580 g_return_val_if_fail(nodeid
!= 0, FALSE
);
1581 g_return_val_if_fail(key
!= NULL
, FALSE
);
1582 g_return_val_if_fail(data
!= NULL
, FALSE
);
1584 g_mutex_lock (&mutex
);
1586 if (!cfs_status
.clinfo
|| !cfs_status
.clinfo
->nodes_byid
)
1587 goto ret
; /* ignore */
1589 cfs_clnode_t
*clnode
= g_hash_table_lookup(cfs_status
.clinfo
->nodes_byid
, &nodeid
);
1591 goto ret
; /* ignore */
1593 cfs_debug("got node %d status update %s", nodeid
, key
);
1595 if (strncmp(key
, "rrd/", 4) == 0) {
1596 rrdentry_hash_set(cfs_status
.rrdhash
, key
+ 4, data
, len
);
1597 } else if (!strcmp(key
, "nodeip")) {
1598 nodeip_hash_set(cfs_status
.iphash
, clnode
->name
, data
, len
);
1600 if (!clnode
->kvhash
) {
1601 if (!(clnode
->kvhash
= kventry_hash_new())) {
1602 goto ret
; /*ignore */
1606 kventry_hash_set(clnode
->kvhash
, key
, data
, len
);
1610 g_mutex_unlock (&mutex
);
1616 cfs_kvstore_sync(void)
1618 g_return_val_if_fail(cfs_status
.kvhash
!= NULL
, FALSE
);
1619 g_return_val_if_fail(cfs_status
.kvstore
!= NULL
, FALSE
);
1621 gboolean res
= TRUE
;
1623 g_mutex_lock (&mutex
);
1625 GHashTable
*ht
= cfs_status
.kvhash
;
1626 GHashTableIter iter
;
1627 gpointer key
, value
;
1629 g_hash_table_iter_init (&iter
, ht
);
1631 while (g_hash_table_iter_next (&iter
, &key
, &value
)) {
1632 kventry_t
*entry
= (kventry_t
*)value
;
1633 kvstore_send_update_message(cfs_status
.kvstore
, entry
->key
, entry
->data
, entry
->len
);
1636 g_mutex_unlock (&mutex
);
1653 g_return_val_if_fail(dfsm
!= NULL
, -1);
1654 g_return_val_if_fail(msg
!= NULL
, -1);
1655 g_return_val_if_fail(res_ptr
!= NULL
, -1);
1657 /* ignore message for ourself */
1658 if (dfsm_nodeid_is_local(dfsm
, nodeid
, pid
))
1661 if (msg_type
== KVSTORE_MESSAGE_UPDATE
) {
1665 if (kvstore_parse_update_message(msg
, msg_len
, &key
, &data
, &len
)) {
1666 cfs_kvstore_node_set(nodeid
, key
, data
, len
);
1668 cfs_critical("cant parse update message");
1670 } else if (msg_type
== KVSTORE_MESSAGE_LOG
) {
1671 cfs_message("received log"); // fixme: remove
1672 const clog_entry_t
*entry
;
1673 if ((entry
= kvstore_parse_log_message(msg
, msg_len
))) {
1674 clusterlog_insert(cfs_status
.clusterlog
, entry
);
1676 cfs_critical("cant parse log message");
1679 cfs_critical("received unknown message type %d\n", msg_type
);
1696 const struct cpg_address
*member_list
,
1697 size_t member_list_entries
)
1699 g_return_if_fail(dfsm
!= NULL
);
1700 g_return_if_fail(member_list
!= NULL
);
1702 cfs_debug("enter %s", __func__
);
1704 g_mutex_lock (&mutex
);
1706 cfs_clinfo_t
*clinfo
= cfs_status
.clinfo
;
1708 if (clinfo
&& clinfo
->nodes_byid
) {
1710 GHashTable
*ht
= clinfo
->nodes_byid
;
1711 GHashTableIter iter
;
1712 gpointer key
, value
;
1714 g_hash_table_iter_init (&iter
, ht
);
1716 while (g_hash_table_iter_next (&iter
, &key
, &value
)) {
1717 cfs_clnode_t
*node
= (cfs_clnode_t
*)value
;
1718 node
->online
= FALSE
;
1721 for (int i
= 0; i
< member_list_entries
; i
++) {
1723 if ((node
= g_hash_table_lookup(clinfo
->nodes_byid
, &member_list
[i
].nodeid
))) {
1724 node
->online
= TRUE
;
1728 cfs_status
.clinfo_version
++;
1731 g_mutex_unlock (&mutex
);
1738 unsigned int *res_len
)
1740 g_return_val_if_fail(dfsm
!= NULL
, NULL
);
1742 gpointer msg
= clusterlog_get_state(cfs_status
.clusterlog
, res_len
);
1748 dfsm_process_update(
1751 dfsm_sync_info_t
*syncinfo
,
1757 cfs_critical("%s: received unexpected update message", __func__
);
1763 dfsm_process_state_update(
1766 dfsm_sync_info_t
*syncinfo
)
1768 g_return_val_if_fail(dfsm
!= NULL
, -1);
1769 g_return_val_if_fail(syncinfo
!= NULL
, -1);
1771 clog_base_t
*clog
[syncinfo
->node_count
];
1773 int local_index
= -1;
1774 for (int i
= 0; i
< syncinfo
->node_count
; i
++) {
1775 dfsm_node_info_t
*ni
= &syncinfo
->nodes
[i
];
1778 if (syncinfo
->local
== ni
)
1781 clog_base_t
*base
= (clog_base_t
*)ni
->state
;
1782 if (ni
->state_len
> 8 && ni
->state_len
== clog_size(base
)) {
1783 clog
[i
] = ni
->state
;
1785 cfs_critical("received log with wrong size %u", ni
->state_len
);
1790 if (!clusterlog_merge(cfs_status
.clusterlog
, clog
, syncinfo
->node_count
, local_index
)) {
1791 cfs_critical("unable to merge log files");
1803 dfsm_sync_info_t
*syncinfo
)
1805 g_return_val_if_fail(dfsm
!= NULL
, -1);
1806 g_return_val_if_fail(syncinfo
!= NULL
, -1);
1812 dfsm_synced(dfsm_t
*dfsm
)
1814 g_return_if_fail(dfsm
!= NULL
);
1816 char *ip
= (char *)g_hash_table_lookup(cfs_status
.iphash
, cfs
.nodename
);
1820 cfs_status_set("nodeip", ip
, strlen(ip
) + 1);
1827 dfsm_sync_info_t
*syncinfo
)
1832 static dfsm_callbacks_t kvstore_dfsm_callbacks
= {
1833 .dfsm_deliver_fn
= dfsm_deliver
,
1834 .dfsm_confchg_fn
= dfsm_confchg
,
1836 .dfsm_get_state_fn
= dfsm_get_state
,
1837 .dfsm_process_state_update_fn
= dfsm_process_state_update
,
1838 .dfsm_process_update_fn
= dfsm_process_update
,
1839 .dfsm_commit_fn
= dfsm_commit
,
1840 .dfsm_cleanup_fn
= dfsm_cleanup
,
1841 .dfsm_synced_fn
= dfsm_synced
,
1845 cfs_status_dfsm_new(void)
1847 g_mutex_lock (&mutex
);
1849 cfs_status
.kvstore
= dfsm_new(NULL
, KVSTORE_CPG_GROUP_NAME
, G_LOG_DOMAIN
,
1850 0, &kvstore_dfsm_callbacks
);
1851 g_mutex_unlock (&mutex
);
1853 return cfs_status
.kvstore
;
1857 cfs_is_quorate(void)
1859 g_mutex_lock (&mutex
);
1860 gboolean res
= cfs_status
.quorate
;
1861 g_mutex_unlock (&mutex
);
1871 g_mutex_lock (&mutex
);
1873 uint32_t prev_quorate
= cfs_status
.quorate
;
1874 cfs_status
.quorate
= quorate
;
1876 if (!prev_quorate
&& cfs_status
.quorate
) {
1878 cfs_message("node has quorum");
1881 if (prev_quorate
&& !cfs_status
.quorate
) {
1883 cfs_message("node lost quorum");
1886 g_mutex_unlock (&mutex
);