2 Copyright (C) 2010 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/tfa.cfg" },
87 { .path
= "datacenter.cfg" },
88 { .path
= "vzdump.cron" },
89 { .path
= "ha/crm_commands" },
90 { .path
= "ha/manager_status" },
91 { .path
= "ha/resources.cfg" },
92 { .path
= "ha/groups.cfg" },
93 { .path
= "ha/fence.cfg" },
94 { .path
= "status.cfg" },
95 { .path
= "replication.cfg" },
96 { .path
= "ceph.conf" },
97 { .path
= "sdn.cfg" },
98 { .path
= "sdn.cfg.new" },
108 cfs_clinfo_t
*clinfo
;
109 uint32_t clinfo_version
;
112 uint32_t vmlist_version
;
119 GHashTable
*memdb_changes
;
121 clusterlog_t
*clusterlog
;
124 static cfs_status_t cfs_status
;
136 uint32_t cman_version
;
138 GHashTable
*nodes_byid
;
139 GHashTable
*nodes_byname
;
143 g_int32_hash (gconstpointer v
)
145 return *(const uint32_t *) v
;
149 g_int32_equal (gconstpointer v1
,
152 return *((const uint32_t*) v1
) == *((const uint32_t*) v2
);
155 static void vminfo_free(vminfo_t
*vminfo
)
157 g_return_if_fail(vminfo
!= NULL
);
159 if (vminfo
->nodename
)
160 g_free(vminfo
->nodename
);
166 static const char *vminfo_type_to_string(vminfo_t
*vminfo
)
168 if (vminfo
->vmtype
== VMTYPE_QEMU
) {
170 } else if (vminfo
->vmtype
== VMTYPE_OPENVZ
) {
172 } else if (vminfo
->vmtype
== VMTYPE_LXC
) {
179 static const char *vminfo_type_to_path_type(vminfo_t
*vminfo
)
181 if (vminfo
->vmtype
== VMTYPE_QEMU
) {
182 return "qemu-server"; // special case..
184 return vminfo_type_to_string(vminfo
);
188 int vminfo_to_path(vminfo_t
*vminfo
, GString
*path
)
190 g_return_val_if_fail(vminfo
!= NULL
, -1);
191 g_return_val_if_fail(path
!= NULL
, -1);
193 if (!vminfo
->nodename
)
196 const char *type
= vminfo_type_to_path_type(vminfo
);
197 g_string_printf(path
, "/nodes/%s/%s/%u.conf", vminfo
->nodename
, type
, vminfo
->vmid
);
202 void cfs_clnode_destroy(
203 cfs_clnode_t
*clnode
)
205 g_return_if_fail(clnode
!= NULL
);
208 g_hash_table_destroy(clnode
->kvhash
);
211 g_free(clnode
->name
);
216 cfs_clnode_t
*cfs_clnode_new(
221 g_return_val_if_fail(name
!= NULL
, NULL
);
223 cfs_clnode_t
*clnode
= g_new0(cfs_clnode_t
, 1);
227 clnode
->name
= g_strdup(name
);
228 clnode
->nodeid
= nodeid
;
229 clnode
->votes
= votes
;
234 gboolean
cfs_clinfo_destroy(
235 cfs_clinfo_t
*clinfo
)
237 g_return_val_if_fail(clinfo
!= NULL
, FALSE
);
239 if (clinfo
->cluster_name
)
240 g_free(clinfo
->cluster_name
);
242 if (clinfo
->nodes_byname
)
243 g_hash_table_destroy(clinfo
->nodes_byname
);
245 if (clinfo
->nodes_byid
)
246 g_hash_table_destroy(clinfo
->nodes_byid
);
253 cfs_clinfo_t
*cfs_clinfo_new(
254 const char *cluster_name
,
255 uint32_t cman_version
)
257 g_return_val_if_fail(cluster_name
!= NULL
, NULL
);
259 cfs_clinfo_t
*clinfo
= g_new0(cfs_clinfo_t
, 1);
263 clinfo
->cluster_name
= g_strdup(cluster_name
);
264 clinfo
->cman_version
= cman_version
;
266 if (!(clinfo
->nodes_byid
= g_hash_table_new_full(
267 g_int32_hash
, g_int32_equal
, NULL
,
268 (GDestroyNotify
)cfs_clnode_destroy
)))
271 if (!(clinfo
->nodes_byname
= g_hash_table_new(g_str_hash
, g_str_equal
)))
277 cfs_clinfo_destroy(clinfo
);
282 gboolean
cfs_clinfo_add_node(
283 cfs_clinfo_t
*clinfo
,
284 cfs_clnode_t
*clnode
)
286 g_return_val_if_fail(clinfo
!= NULL
, FALSE
);
287 g_return_val_if_fail(clnode
!= NULL
, FALSE
);
289 g_hash_table_replace(clinfo
->nodes_byid
, &clnode
->nodeid
, clnode
);
290 g_hash_table_replace(clinfo
->nodes_byname
, clnode
->name
, clnode
);
296 cfs_create_memberlist_msg(
299 g_return_val_if_fail(str
!= NULL
, -EINVAL
);
301 g_mutex_lock (&mutex
);
303 g_string_append_printf(str
,"{\n");
307 cfs_clinfo_t
*clinfo
= cfs_status
.clinfo
;
309 if (clinfo
&& clinfo
->nodes_byid
)
310 nodecount
= g_hash_table_size(clinfo
->nodes_byid
);
313 g_string_append_printf(str
, "\"nodename\": \"%s\",\n", cfs
.nodename
);
314 g_string_append_printf(str
, "\"version\": %u,\n", cfs_status
.clinfo_version
);
316 g_string_append_printf(str
, "\"cluster\": { ");
317 g_string_append_printf(str
, "\"name\": \"%s\", \"version\": %d, "
318 "\"nodes\": %d, \"quorate\": %d ",
319 clinfo
->cluster_name
, clinfo
->cman_version
,
320 nodecount
, cfs_status
.quorate
);
322 g_string_append_printf(str
,"},\n");
323 g_string_append_printf(str
,"\"nodelist\": {\n");
325 GHashTable
*ht
= clinfo
->nodes_byid
;
329 g_hash_table_iter_init (&iter
, ht
);
332 while (g_hash_table_iter_next (&iter
, &key
, &value
)) {
333 cfs_clnode_t
*node
= (cfs_clnode_t
*)value
;
334 if (i
) g_string_append_printf(str
, ",\n");
337 g_string_append_printf(str
, " \"%s\": { \"id\": %d, \"online\": %d",
338 node
->name
, node
->nodeid
, node
->online
);
341 char *ip
= (char *)g_hash_table_lookup(cfs_status
.iphash
, node
->name
);
343 g_string_append_printf(str
, ", \"ip\": \"%s\"", ip
);
346 g_string_append_printf(str
, "}");
349 g_string_append_printf(str
,"\n }\n");
351 g_string_append_printf(str
, "\"nodename\": \"%s\",\n", cfs
.nodename
);
352 g_string_append_printf(str
, "\"version\": %u\n", cfs_status
.clinfo_version
);
355 g_string_append_printf(str
,"}\n");
357 g_mutex_unlock (&mutex
);
363 kventry_free(kventry_t
*entry
)
365 g_return_if_fail(entry
!= NULL
);
373 kventry_hash_new(void)
375 return g_hash_table_new_full(g_str_hash
, g_str_equal
, NULL
,
376 (GDestroyNotify
)kventry_free
);
380 rrdentry_free(rrdentry_t
*entry
)
382 g_return_if_fail(entry
!= NULL
);
390 rrdentry_hash_new(void)
392 return g_hash_table_new_full(g_str_hash
, g_str_equal
, NULL
,
393 (GDestroyNotify
)rrdentry_free
);
397 cfs_cluster_log_dump(GString
*str
, const char *user
, guint max_entries
)
399 clusterlog_dump(cfs_status
.clusterlog
, str
, user
, max_entries
);
403 cfs_cluster_log(clog_entry_t
*entry
)
405 g_return_if_fail(entry
!= NULL
);
407 clusterlog_insert(cfs_status
.clusterlog
, entry
);
409 if (cfs_status
.kvstore
) {
411 iov
[0].iov_base
= (char *)entry
;
412 iov
[0].iov_len
= clog_entry_size(entry
);
414 if (dfsm_is_initialized(cfs_status
.kvstore
))
415 dfsm_send_message(cfs_status
.kvstore
, KVSTORE_MESSAGE_LOG
, iov
, 1);
419 void cfs_status_init(void)
421 g_mutex_lock (&mutex
);
423 cfs_status
.start_time
= time(NULL
);
425 cfs_status
.vmlist
= vmlist_hash_new();
427 cfs_status
.kvhash
= kventry_hash_new();
429 cfs_status
.rrdhash
= rrdentry_hash_new();
431 cfs_status
.iphash
= g_hash_table_new_full(g_str_hash
, g_str_equal
, g_free
, g_free
);
433 cfs_status
.memdb_changes
= g_hash_table_new(g_str_hash
, g_str_equal
);
435 for (int i
= 0; i
< G_N_ELEMENTS(memdb_change_array
); i
++) {
436 g_hash_table_replace(cfs_status
.memdb_changes
,
437 memdb_change_array
[i
].path
,
438 &memdb_change_array
[i
]);
441 cfs_status
.clusterlog
= clusterlog_new();
444 clusterlog_add(cfs_status
.clusterlog
, "root", "cluster", getpid(),
445 LOG_INFO
, "starting cluster log");
447 g_mutex_unlock (&mutex
);
450 void cfs_status_cleanup(void)
452 g_mutex_lock (&mutex
);
454 cfs_status
.clinfo_version
++;
456 if (cfs_status
.clinfo
) {
457 cfs_clinfo_destroy(cfs_status
.clinfo
);
458 cfs_status
.clinfo
= NULL
;
461 if (cfs_status
.vmlist
) {
462 g_hash_table_destroy(cfs_status
.vmlist
);
463 cfs_status
.vmlist
= NULL
;
466 if (cfs_status
.kvhash
) {
467 g_hash_table_destroy(cfs_status
.kvhash
);
468 cfs_status
.kvhash
= NULL
;
471 if (cfs_status
.rrdhash
) {
472 g_hash_table_destroy(cfs_status
.rrdhash
);
473 cfs_status
.rrdhash
= NULL
;
476 if (cfs_status
.iphash
) {
477 g_hash_table_destroy(cfs_status
.iphash
);
478 cfs_status
.iphash
= NULL
;
481 if (cfs_status
.clusterlog
)
482 clusterlog_destroy(cfs_status
.clusterlog
);
484 g_mutex_unlock (&mutex
);
487 void cfs_status_set_clinfo(
488 cfs_clinfo_t
*clinfo
)
490 g_return_if_fail(clinfo
!= NULL
);
492 g_mutex_lock (&mutex
);
494 cfs_status
.clinfo_version
++;
496 cfs_clinfo_t
*old
= cfs_status
.clinfo
;
498 cfs_status
.clinfo
= clinfo
;
500 cfs_message("update cluster info (cluster name %s, version = %d)",
501 clinfo
->cluster_name
, clinfo
->cman_version
);
504 if (old
&& old
->nodes_byid
&& clinfo
->nodes_byid
) {
506 GHashTable
*ht
= clinfo
->nodes_byid
;
510 g_hash_table_iter_init (&iter
, ht
);
512 while (g_hash_table_iter_next (&iter
, &key
, &value
)) {
513 cfs_clnode_t
*node
= (cfs_clnode_t
*)value
;
514 cfs_clnode_t
*oldnode
;
515 if ((oldnode
= g_hash_table_lookup(old
->nodes_byid
, key
))) {
516 node
->online
= oldnode
->online
;
517 node
->kvhash
= oldnode
->kvhash
;
518 oldnode
->kvhash
= NULL
;
525 cfs_clinfo_destroy(old
);
528 g_mutex_unlock (&mutex
);
532 dump_kvstore_versions(
535 const char *nodename
)
537 g_return_if_fail(kvhash
!= NULL
);
538 g_return_if_fail(str
!= NULL
);
539 g_return_if_fail(nodename
!= NULL
);
541 GHashTable
*ht
= kvhash
;
545 g_string_append_printf(str
, "\"%s\": {\n", nodename
);
547 g_hash_table_iter_init (&iter
, ht
);
550 while (g_hash_table_iter_next (&iter
, &key
, &value
)) {
551 kventry_t
*entry
= (kventry_t
*)value
;
552 if (i
) g_string_append_printf(str
, ",\n");
554 g_string_append_printf(str
,"\"%s\": %u", entry
->key
, entry
->version
);
557 g_string_append_printf(str
, "}\n");
561 cfs_create_version_msg(GString
*str
)
563 g_return_val_if_fail(str
!= NULL
, -EINVAL
);
565 g_mutex_lock (&mutex
);
567 g_string_append_printf(str
,"{\n");
569 g_string_append_printf(str
, "\"starttime\": %lu,\n", (unsigned long)cfs_status
.start_time
);
571 g_string_append_printf(str
, "\"clinfo\": %u,\n", cfs_status
.clinfo_version
);
573 g_string_append_printf(str
, "\"vmlist\": %u,\n", cfs_status
.vmlist_version
);
575 for (int i
= 0; i
< G_N_ELEMENTS(memdb_change_array
); i
++) {
576 g_string_append_printf(str
, "\"%s\": %u,\n",
577 memdb_change_array
[i
].path
,
578 memdb_change_array
[i
].version
);
581 g_string_append_printf(str
, "\"kvstore\": {\n");
583 dump_kvstore_versions(str
, cfs_status
.kvhash
, cfs
.nodename
);
585 cfs_clinfo_t
*clinfo
= cfs_status
.clinfo
;
587 if (clinfo
&& clinfo
->nodes_byid
) {
588 GHashTable
*ht
= clinfo
->nodes_byid
;
592 g_hash_table_iter_init (&iter
, ht
);
594 while (g_hash_table_iter_next (&iter
, &key
, &value
)) {
595 cfs_clnode_t
*node
= (cfs_clnode_t
*)value
;
598 g_string_append_printf(str
, ",\n");
599 dump_kvstore_versions(str
, node
->kvhash
, node
->name
);
603 g_string_append_printf(str
,"}\n");
605 g_string_append_printf(str
,"}\n");
607 g_mutex_unlock (&mutex
);
613 vmlist_hash_new(void)
615 return g_hash_table_new_full(g_int_hash
, g_int_equal
, NULL
,
616 (GDestroyNotify
)vminfo_free
);
620 vmlist_hash_insert_vm(
624 const char *nodename
,
627 g_return_val_if_fail(vmlist
!= NULL
, FALSE
);
628 g_return_val_if_fail(nodename
!= NULL
, FALSE
);
629 g_return_val_if_fail(vmid
!= 0, FALSE
);
630 g_return_val_if_fail(vmtype
== VMTYPE_QEMU
|| vmtype
== VMTYPE_OPENVZ
||
631 vmtype
== VMTYPE_LXC
, FALSE
);
633 if (!replace
&& g_hash_table_lookup(vmlist
, &vmid
)) {
634 cfs_critical("detected duplicate VMID %d", vmid
);
638 vminfo_t
*vminfo
= g_new0(vminfo_t
, 1);
641 vminfo
->vmtype
= vmtype
;
642 vminfo
->nodename
= g_strdup(nodename
);
644 vminfo
->version
= ++vminfo_version_counter
;
646 g_hash_table_replace(vmlist
, &vminfo
->vmid
, vminfo
);
655 const char *nodename
)
657 g_return_if_fail(cfs_status
.vmlist
!= NULL
);
658 g_return_if_fail(nodename
!= NULL
);
659 g_return_if_fail(vmid
!= 0);
660 g_return_if_fail(vmtype
== VMTYPE_QEMU
|| vmtype
== VMTYPE_OPENVZ
||
661 vmtype
== VMTYPE_LXC
);
663 cfs_debug("vmlist_register_vm: %s/%u %d", nodename
, vmid
, vmtype
);
665 g_mutex_lock (&mutex
);
667 cfs_status
.vmlist_version
++;
669 vmlist_hash_insert_vm(cfs_status
.vmlist
, vmtype
, vmid
, nodename
, TRUE
);
671 g_mutex_unlock (&mutex
);
675 vmlist_different_vm_exists(
678 const char *nodename
)
680 g_return_val_if_fail(cfs_status
.vmlist
!= NULL
, FALSE
);
681 g_return_val_if_fail(vmid
!= 0, FALSE
);
683 gboolean res
= FALSE
;
685 g_mutex_lock (&mutex
);
688 if ((vminfo
= (vminfo_t
*)g_hash_table_lookup(cfs_status
.vmlist
, &vmid
))) {
689 if (!(vminfo
->vmtype
== vmtype
&& strcmp(vminfo
->nodename
, nodename
) == 0))
692 g_mutex_unlock (&mutex
);
701 g_return_val_if_fail(cfs_status
.vmlist
!= NULL
, FALSE
);
702 g_return_val_if_fail(vmid
!= 0, FALSE
);
704 g_mutex_lock (&mutex
);
706 gpointer res
= g_hash_table_lookup(cfs_status
.vmlist
, &vmid
);
708 g_mutex_unlock (&mutex
);
717 g_return_if_fail(cfs_status
.vmlist
!= NULL
);
718 g_return_if_fail(vmid
!= 0);
720 g_mutex_lock (&mutex
);
722 cfs_status
.vmlist_version
++;
724 g_hash_table_remove(cfs_status
.vmlist
, &vmid
);
726 g_mutex_unlock (&mutex
);
729 void cfs_status_set_vmlist(
732 g_return_if_fail(vmlist
!= NULL
);
734 g_mutex_lock (&mutex
);
736 cfs_status
.vmlist_version
++;
738 if (cfs_status
.vmlist
)
739 g_hash_table_destroy(cfs_status
.vmlist
);
741 cfs_status
.vmlist
= vmlist
;
743 g_mutex_unlock (&mutex
);
747 cfs_create_vmlist_msg(GString
*str
)
749 g_return_val_if_fail(cfs_status
.vmlist
!= NULL
, -EINVAL
);
750 g_return_val_if_fail(str
!= NULL
, -EINVAL
);
752 g_mutex_lock (&mutex
);
754 g_string_append_printf(str
,"{\n");
756 GHashTable
*ht
= cfs_status
.vmlist
;
758 guint count
= g_hash_table_size(ht
);
761 g_string_append_printf(str
,"\"version\": %u\n", cfs_status
.vmlist_version
);
763 g_string_append_printf(str
,"\"version\": %u,\n", cfs_status
.vmlist_version
);
765 g_string_append_printf(str
,"\"ids\": {\n");
770 g_hash_table_iter_init (&iter
, ht
);
773 while (g_hash_table_iter_next (&iter
, &key
, &value
)) {
774 vminfo_t
*vminfo
= (vminfo_t
*)value
;
775 const char *type
= vminfo_type_to_string(vminfo
);
778 g_string_append_printf(str
, ",\n");
781 g_string_append_printf(str
,"\"%u\": { \"node\": \"%s\", \"type\": \"%s\", \"version\": %u }",
782 vminfo
->vmid
, vminfo
->nodename
, type
, vminfo
->version
);
785 g_string_append_printf(str
,"}\n");
787 g_string_append_printf(str
,"\n}\n");
789 g_mutex_unlock (&mutex
);
794 // checks the conf for a line starting with '$prop:' and returns the value
795 // afterwards, whitout initial whitespace(s), we only deal with the format
796 // restricion imposed by our perl VM config parser, main reference is
797 // PVE::QemuServer::parse_vm_config this allows to be very fast and still
799 // main restrictions used for our advantage is the properties match reges:
800 // ($line =~ m/^([a-z][a-z_]*\d*):\s*(.+?)\s*$/) from parse_vm_config
801 // currently we only look at the current configuration in place, i.e., *no*
802 // snapshort and *no* pending changes
804 _get_property_value(char *conf
, const char *prop
, int prop_len
)
806 char *line
= NULL
, *temp
= NULL
;
808 line
= strtok_r(conf
, "\n", &temp
);
809 while (line
!= NULL
) {
810 if (!line
[0]) goto next
;
812 // snapshot or pending section start and nothing found yet
813 if (line
[0] == '[') return NULL
;
814 // properties start with /^[a-z]/, so continue early if not
815 if (line
[0] < 'a' || line
[0] > 'z') goto next
;
817 int line_len
= strlen(line
);
818 if (line_len
<= prop_len
+ 1) goto next
;
820 if (line
[prop_len
] == ':' && memcmp(line
, prop
, prop_len
) == 0) { // found
821 char *v_start
= &line
[prop_len
+ 1];
823 // drop initial value whitespaces here already
824 while (*v_start
&& isspace(*v_start
)) v_start
++;
826 if (!*v_start
) return NULL
;
828 char *v_end
= &line
[line_len
- 1];
829 while (v_end
> v_start
&& isspace(*v_end
)) v_end
--;
835 line
= strtok_r(NULL
, "\n", &temp
);
838 return NULL
; // not found
842 _g_str_append_kv_jsonescaped(GString
*str
, const char *k
, const char *v
)
844 g_string_append_printf(str
, "\"%s\": \"", k
);
847 if (*v
== '\\' || *v
== '"') {
848 g_string_append_c(str
, '\\');
850 g_string_append_c(str
, *v
);
853 g_string_append_c(str
, '"');
857 cfs_create_guest_conf_property_msg(GString
*str
, memdb_t
*memdb
, const char *prop
, uint32_t vmid
)
859 g_return_val_if_fail(cfs_status
.vmlist
!= NULL
, -EINVAL
);
860 g_return_val_if_fail(str
!= NULL
, -EINVAL
);
862 int prop_len
= strlen(prop
);
864 GString
*path
= NULL
;
866 g_mutex_lock (&mutex
);
868 g_string_printf(str
,"{\n");
870 GHashTable
*ht
= cfs_status
.vmlist
;
872 if (!g_hash_table_size(ht
)) {
876 path
= g_string_sized_new(256);
878 vminfo_t
*vminfo
= (vminfo_t
*) g_hash_table_lookup(cfs_status
.vmlist
, &vmid
);
879 if (vminfo
== NULL
) goto enoent
;
881 if (!vminfo_to_path(vminfo
, path
)) goto err
;
883 int size
= memdb_read(memdb
, path
->str
, &tmp
);
884 if (tmp
== NULL
) goto err
;
885 if (size
<= prop_len
) goto ret
;
887 char *val
= _get_property_value(tmp
, prop
, prop_len
);
888 if (val
== NULL
) goto ret
;
890 g_string_append_printf(str
, "\"%u\":{", vmid
);
891 _g_str_append_kv_jsonescaped(str
, prop
, val
);
892 g_string_append_c(str
, '}');
896 g_hash_table_iter_init (&iter
, ht
);
900 while (g_hash_table_iter_next (&iter
, &key
, &value
)) {
901 vminfo_t
*vminfo
= (vminfo_t
*)value
;
903 if (!vminfo_to_path(vminfo
, path
)) goto err
;
905 g_free(tmp
); // no-op if already null
907 int size
= memdb_read(memdb
, path
->str
, &tmp
);
908 if (tmp
== NULL
|| size
<= prop_len
) continue;
910 char *val
= _get_property_value(tmp
, prop
, prop_len
);
911 if (val
== NULL
) continue;
913 if (!first
) g_string_append_printf(str
, ",\n");
916 g_string_append_printf(str
, "\"%u\":{", vminfo
->vmid
);
917 _g_str_append_kv_jsonescaped(str
, prop
, val
);
918 g_string_append_c(str
, '}');
924 g_string_free(path
, TRUE
);
926 g_string_append_printf(str
,"\n}\n");
927 g_mutex_unlock (&mutex
);
939 record_memdb_change(const char *path
)
941 g_return_if_fail(cfs_status
.memdb_changes
!= 0);
945 if ((ce
= (memdb_change_t
*)g_hash_table_lookup(cfs_status
.memdb_changes
, path
))) {
951 record_memdb_reload(void)
953 for (int i
= 0; i
< G_N_ELEMENTS(memdb_change_array
); i
++) {
954 memdb_change_array
[i
].version
++;
965 g_return_val_if_fail(kvhash
!= NULL
, FALSE
);
966 g_return_val_if_fail(key
!= NULL
, FALSE
);
967 g_return_val_if_fail(data
!= NULL
, FALSE
);
971 g_hash_table_remove(kvhash
, key
);
972 } else if ((entry
= (kventry_t
*)g_hash_table_lookup(kvhash
, key
))) {
974 entry
->data
= g_memdup(data
, len
);
978 kventry_t
*entry
= g_new0(kventry_t
, 1);
980 entry
->key
= g_strdup(key
);
981 entry
->data
= g_memdup(data
, len
);
984 g_hash_table_replace(kvhash
, entry
->key
, entry
);
990 static const char *rrd_def_node
[] = {
991 "DS:loadavg:GAUGE:120:0:U",
992 "DS:maxcpu:GAUGE:120:0:U",
993 "DS:cpu:GAUGE:120:0:U",
994 "DS:iowait:GAUGE:120:0:U",
995 "DS:memtotal:GAUGE:120:0:U",
996 "DS:memused:GAUGE:120:0:U",
997 "DS:swaptotal:GAUGE:120:0:U",
998 "DS:swapused:GAUGE:120:0:U",
999 "DS:roottotal:GAUGE:120:0:U",
1000 "DS:rootused:GAUGE:120:0:U",
1001 "DS:netin:DERIVE:120:0:U",
1002 "DS:netout:DERIVE:120:0:U",
1004 "RRA:AVERAGE:0.5:1:70", // 1 min avg - one hour
1005 "RRA:AVERAGE:0.5:30:70", // 30 min avg - one day
1006 "RRA:AVERAGE:0.5:180:70", // 3 hour avg - one week
1007 "RRA:AVERAGE:0.5:720:70", // 12 hour avg - one month
1008 "RRA:AVERAGE:0.5:10080:70", // 7 day avg - ony year
1010 "RRA:MAX:0.5:1:70", // 1 min max - one hour
1011 "RRA:MAX:0.5:30:70", // 30 min max - one day
1012 "RRA:MAX:0.5:180:70", // 3 hour max - one week
1013 "RRA:MAX:0.5:720:70", // 12 hour max - one month
1014 "RRA:MAX:0.5:10080:70", // 7 day max - ony year
1018 static const char *rrd_def_vm
[] = {
1019 "DS:maxcpu:GAUGE:120:0:U",
1020 "DS:cpu:GAUGE:120:0:U",
1021 "DS:maxmem:GAUGE:120:0:U",
1022 "DS:mem:GAUGE:120:0:U",
1023 "DS:maxdisk:GAUGE:120:0:U",
1024 "DS:disk:GAUGE:120:0:U",
1025 "DS:netin:DERIVE:120:0:U",
1026 "DS:netout:DERIVE:120:0:U",
1027 "DS:diskread:DERIVE:120:0:U",
1028 "DS:diskwrite:DERIVE:120:0:U",
1030 "RRA:AVERAGE:0.5:1:70", // 1 min avg - one hour
1031 "RRA:AVERAGE:0.5:30:70", // 30 min avg - one day
1032 "RRA:AVERAGE:0.5:180:70", // 3 hour avg - one week
1033 "RRA:AVERAGE:0.5:720:70", // 12 hour avg - one month
1034 "RRA:AVERAGE:0.5:10080:70", // 7 day avg - ony year
1036 "RRA:MAX:0.5:1:70", // 1 min max - one hour
1037 "RRA:MAX:0.5:30:70", // 30 min max - one day
1038 "RRA:MAX:0.5:180:70", // 3 hour max - one week
1039 "RRA:MAX:0.5:720:70", // 12 hour max - one month
1040 "RRA:MAX:0.5:10080:70", // 7 day max - ony year
1044 static const char *rrd_def_storage
[] = {
1045 "DS:total:GAUGE:120:0:U",
1046 "DS:used:GAUGE:120:0:U",
1048 "RRA:AVERAGE:0.5:1:70", // 1 min avg - one hour
1049 "RRA:AVERAGE:0.5:30:70", // 30 min avg - one day
1050 "RRA:AVERAGE:0.5:180:70", // 3 hour avg - one week
1051 "RRA:AVERAGE:0.5:720:70", // 12 hour avg - one month
1052 "RRA:AVERAGE:0.5:10080:70", // 7 day avg - ony year
1054 "RRA:MAX:0.5:1:70", // 1 min max - one hour
1055 "RRA:MAX:0.5:30:70", // 30 min max - one day
1056 "RRA:MAX:0.5:180:70", // 3 hour max - one week
1057 "RRA:MAX:0.5:720:70", // 12 hour max - one month
1058 "RRA:MAX:0.5:10080:70", // 7 day max - ony year
1062 #define RRDDIR "/var/lib/rrdcached/db"
1066 const char *filename
,
1068 const char *rrddef
[])
1070 /* start at day boundary */
1073 struct tm
*ltm
= localtime(&ctime
);
1079 if (rrd_create_r(filename
, 60, timelocal(ltm
), argcount
, rrddef
)) {
1080 cfs_message("RRD create error %s: %s", filename
, rrd_get_error());
1084 static inline const char *
1090 while (*data
&& found
< count
) {
1103 g_return_if_fail(key
!= NULL
);
1104 g_return_if_fail(data
!= NULL
);
1105 g_return_if_fail(len
> 0);
1106 g_return_if_fail(len
< 4096);
1108 static const char *rrdcsock
= "unix:/var/run/rrdcached.sock";
1111 if (rrdc_connect(rrdcsock
) != 0)
1114 char *filename
= NULL
;
1118 if (strncmp(key
, "pve2-node/", 10) == 0) {
1119 const char *node
= key
+ 10;
1123 if (strchr(node
, '/') != NULL
)
1126 if (strlen(node
) < 1)
1129 filename
= g_strdup_printf(RRDDIR
"/%s", key
);
1131 if (!g_file_test(filename
, G_FILE_TEST_EXISTS
)) {
1133 mkdir(RRDDIR
"/pve2-node", 0755);
1134 int argcount
= sizeof(rrd_def_node
)/sizeof(void*) - 1;
1135 create_rrd_file(filename
, argcount
, rrd_def_node
);
1138 } else if ((strncmp(key
, "pve2-vm/", 8) == 0) ||
1139 (strncmp(key
, "pve2.3-vm/", 10) == 0)) {
1142 if (strncmp(key
, "pve2-vm/", 8) == 0) {
1150 if (strchr(vmid
, '/') != NULL
)
1153 if (strlen(vmid
) < 1)
1156 filename
= g_strdup_printf(RRDDIR
"/%s/%s", "pve2-vm", vmid
);
1158 if (!g_file_test(filename
, G_FILE_TEST_EXISTS
)) {
1160 mkdir(RRDDIR
"/pve2-vm", 0755);
1161 int argcount
= sizeof(rrd_def_vm
)/sizeof(void*) - 1;
1162 create_rrd_file(filename
, argcount
, rrd_def_vm
);
1165 } else if (strncmp(key
, "pve2-storage/", 13) == 0) {
1166 const char *node
= key
+ 13;
1168 const char *storage
= node
;
1169 while (*storage
&& *storage
!= '/')
1172 if (*storage
!= '/' || ((storage
- node
) < 1))
1177 if (strchr(storage
, '/') != NULL
)
1180 if (strlen(storage
) < 1)
1183 filename
= g_strdup_printf(RRDDIR
"/%s", key
);
1185 if (!g_file_test(filename
, G_FILE_TEST_EXISTS
)) {
1187 mkdir(RRDDIR
"/pve2-storage", 0755);
1189 char *dir
= g_path_get_dirname(filename
);
1193 int argcount
= sizeof(rrd_def_storage
)/sizeof(void*) - 1;
1194 create_rrd_file(filename
, argcount
, rrd_def_storage
);
1201 const char *dp
= skip
? rrd_skip_data(data
, skip
) : data
;
1203 const char *update_args
[] = { dp
, NULL
};
1207 if ((status
= rrdc_update(filename
, 1, update_args
)) != 0) {
1208 cfs_message("RRDC update error %s: %d", filename
, status
);
1211 if (rrd_update_r(filename
, NULL
, 1, update_args
) != 0) {
1212 cfs_message("RRD update error %s: %s", filename
, rrd_get_error());
1218 if (rrd_update_r(filename
, NULL
, 1, update_args
) != 0) {
1219 cfs_message("RRD update error %s: %s", filename
, rrd_get_error());
1230 cfs_critical("RRD update error: unknown/wrong key %s", key
);
1240 rrdentry_t
*entry
= (rrdentry_t
*)value
;
1241 uint32_t ctime
= GPOINTER_TO_UINT(user_data
);
1243 int diff
= ctime
- entry
->time
;
1245 /* remove everything older than 5 minutes */
1248 return (diff
> expire
) ? TRUE
: FALSE
;
1251 static char *rrd_dump_buf
= NULL
;
1252 static time_t rrd_dump_last
= 0;
1255 cfs_rrd_dump(GString
*str
)
1259 g_mutex_lock (&mutex
);
1262 if (rrd_dump_buf
&& (ctime
- rrd_dump_last
) < 2) {
1263 g_string_assign(str
, rrd_dump_buf
);
1264 g_mutex_unlock (&mutex
);
1268 /* remove old data */
1269 g_hash_table_foreach_remove(cfs_status
.rrdhash
, rrd_entry_is_old
,
1270 GUINT_TO_POINTER(ctime
));
1272 g_string_set_size(str
, 0);
1274 GHashTableIter iter
;
1275 gpointer key
, value
;
1277 g_hash_table_iter_init (&iter
, cfs_status
.rrdhash
);
1279 while (g_hash_table_iter_next (&iter
, &key
, &value
)) {
1280 rrdentry_t
*entry
= (rrdentry_t
*)value
;
1281 g_string_append(str
, key
);
1282 g_string_append(str
, ":");
1283 g_string_append(str
, entry
->data
);
1284 g_string_append(str
, "\n");
1287 g_string_append_c(str
, 0); // never return undef
1289 rrd_dump_last
= ctime
;
1291 g_free(rrd_dump_buf
);
1292 rrd_dump_buf
= g_strdup(str
->str
);
1294 g_mutex_unlock (&mutex
);
1300 const char *nodename
,
1304 g_return_val_if_fail(iphash
!= NULL
, FALSE
);
1305 g_return_val_if_fail(nodename
!= NULL
, FALSE
);
1306 g_return_val_if_fail(ip
!= NULL
, FALSE
);
1307 g_return_val_if_fail(len
> 0, FALSE
);
1308 g_return_val_if_fail(len
< 256, FALSE
);
1309 g_return_val_if_fail(ip
[len
-1] == 0, FALSE
);
1311 char *oldip
= (char *)g_hash_table_lookup(iphash
, nodename
);
1313 if (!oldip
|| (strcmp(oldip
, ip
) != 0)) {
1314 cfs_status
.clinfo_version
++;
1315 g_hash_table_replace(iphash
, g_strdup(nodename
), g_strdup(ip
));
1323 GHashTable
*rrdhash
,
1328 g_return_val_if_fail(rrdhash
!= NULL
, FALSE
);
1329 g_return_val_if_fail(key
!= NULL
, FALSE
);
1330 g_return_val_if_fail(data
!= NULL
, FALSE
);
1331 g_return_val_if_fail(len
> 0, FALSE
);
1332 g_return_val_if_fail(len
< 4096, FALSE
);
1333 g_return_val_if_fail(data
[len
-1] == 0, FALSE
);
1336 if ((entry
= (rrdentry_t
*)g_hash_table_lookup(rrdhash
, key
))) {
1337 g_free(entry
->data
);
1338 entry
->data
= g_memdup(data
, len
);
1340 entry
->time
= time(NULL
);
1342 rrdentry_t
*entry
= g_new0(rrdentry_t
, 1);
1344 entry
->key
= g_strdup(key
);
1345 entry
->data
= g_memdup(data
, len
);
1347 entry
->time
= time(NULL
);
1349 g_hash_table_replace(rrdhash
, entry
->key
, entry
);
1352 update_rrd_data(key
, data
, len
);
1358 kvstore_send_update_message(
1364 if (!dfsm_is_initialized(dfsm
))
1367 struct iovec iov
[2];
1370 g_strlcpy(name
, key
, sizeof(name
));
1372 iov
[0].iov_base
= &name
;
1373 iov
[0].iov_len
= sizeof(name
);
1375 iov
[1].iov_base
= (char *)data
;
1376 iov
[1].iov_len
= len
;
1378 if (dfsm_send_message(dfsm
, KVSTORE_MESSAGE_UPDATE
, iov
, 2) == CS_OK
)
1384 static clog_entry_t
*
1385 kvstore_parse_log_message(
1389 g_return_val_if_fail(msg
!= NULL
, NULL
);
1391 if (msg_len
< sizeof(clog_entry_t
)) {
1392 cfs_critical("received short log message (%zu < %zu)", msg_len
, sizeof(clog_entry_t
));
1396 clog_entry_t
*entry
= (clog_entry_t
*)msg
;
1398 uint32_t size
= sizeof(clog_entry_t
) + entry
->node_len
+
1399 entry
->ident_len
+ entry
->tag_len
+ entry
->msg_len
;
1401 if (msg_len
!= size
) {
1402 cfs_critical("received log message with wrong size (%zu != %u)", msg_len
, size
);
1406 char *msgptr
= entry
->data
;
1408 if (*((char *)msgptr
+ entry
->node_len
- 1)) {
1409 cfs_critical("unterminated string in log message");
1412 msgptr
+= entry
->node_len
;
1414 if (*((char *)msgptr
+ entry
->ident_len
- 1)) {
1415 cfs_critical("unterminated string in log message");
1418 msgptr
+= entry
->ident_len
;
1420 if (*((char *)msgptr
+ entry
->tag_len
- 1)) {
1421 cfs_critical("unterminated string in log message");
1424 msgptr
+= entry
->tag_len
;
1426 if (*((char *)msgptr
+ entry
->msg_len
- 1)) {
1427 cfs_critical("unterminated string in log message");
1435 kvstore_parse_update_message(
1439 gconstpointer
*data
,
1442 g_return_val_if_fail(msg
!= NULL
, FALSE
);
1443 g_return_val_if_fail(key
!= NULL
, FALSE
);
1444 g_return_val_if_fail(data
!= NULL
, FALSE
);
1445 g_return_val_if_fail(len
!= NULL
, FALSE
);
1447 if (msg_len
< 256) {
1448 cfs_critical("received short kvstore message (%zu < 256)", msg_len
);
1452 /* test if key is null terminated */
1454 for (i
= 0; i
< 256; i
++)
1455 if (((char *)msg
)[i
] == 0)
1462 *len
= msg_len
- 256;
1464 *data
= (char *) msg
+ 256;
1470 cfs_create_status_msg(
1472 const char *nodename
,
1475 g_return_val_if_fail(str
!= NULL
, -EINVAL
);
1476 g_return_val_if_fail(key
!= NULL
, -EINVAL
);
1480 GHashTable
*kvhash
= NULL
;
1482 g_mutex_lock (&mutex
);
1484 if (!nodename
|| !nodename
[0] || !strcmp(nodename
, cfs
.nodename
)) {
1485 kvhash
= cfs_status
.kvhash
;
1486 } else if (cfs_status
.clinfo
&& cfs_status
.clinfo
->nodes_byname
) {
1487 cfs_clnode_t
*clnode
;
1488 if ((clnode
= g_hash_table_lookup(cfs_status
.clinfo
->nodes_byname
, nodename
)))
1489 kvhash
= clnode
->kvhash
;
1493 if (kvhash
&& (entry
= (kventry_t
*)g_hash_table_lookup(kvhash
, key
))) {
1494 g_string_append_len(str
, entry
->data
, entry
->len
);
1498 g_mutex_unlock (&mutex
);
1509 g_return_val_if_fail(key
!= NULL
, FALSE
);
1510 g_return_val_if_fail(data
!= NULL
, FALSE
);
1511 g_return_val_if_fail(cfs_status
.kvhash
!= NULL
, FALSE
);
1513 if (len
> CFS_MAX_STATUS_SIZE
)
1516 g_mutex_lock (&mutex
);
1520 if (strncmp(key
, "rrd/", 4) == 0) {
1521 res
= rrdentry_hash_set(cfs_status
.rrdhash
, key
+ 4, data
, len
);
1522 } else if (!strcmp(key
, "nodeip")) {
1523 res
= nodeip_hash_set(cfs_status
.iphash
, cfs
.nodename
, data
, len
);
1525 res
= kventry_hash_set(cfs_status
.kvhash
, key
, data
, len
);
1527 g_mutex_unlock (&mutex
);
1529 if (cfs_status
.kvstore
)
1530 kvstore_send_update_message(cfs_status
.kvstore
, key
, data
, len
);
1532 return res
? 0 : -ENOMEM
;
1536 cfs_kvstore_node_set(
1542 g_return_val_if_fail(nodeid
!= 0, FALSE
);
1543 g_return_val_if_fail(key
!= NULL
, FALSE
);
1544 g_return_val_if_fail(data
!= NULL
, FALSE
);
1546 g_mutex_lock (&mutex
);
1548 if (!cfs_status
.clinfo
|| !cfs_status
.clinfo
->nodes_byid
)
1549 goto ret
; /* ignore */
1551 cfs_clnode_t
*clnode
= g_hash_table_lookup(cfs_status
.clinfo
->nodes_byid
, &nodeid
);
1553 goto ret
; /* ignore */
1555 cfs_debug("got node %d status update %s", nodeid
, key
);
1557 if (strncmp(key
, "rrd/", 4) == 0) {
1558 rrdentry_hash_set(cfs_status
.rrdhash
, key
+ 4, data
, len
);
1559 } else if (!strcmp(key
, "nodeip")) {
1560 nodeip_hash_set(cfs_status
.iphash
, clnode
->name
, data
, len
);
1562 if (!clnode
->kvhash
) {
1563 if (!(clnode
->kvhash
= kventry_hash_new())) {
1564 goto ret
; /*ignore */
1568 kventry_hash_set(clnode
->kvhash
, key
, data
, len
);
1572 g_mutex_unlock (&mutex
);
1578 cfs_kvstore_sync(void)
1580 g_return_val_if_fail(cfs_status
.kvhash
!= NULL
, FALSE
);
1581 g_return_val_if_fail(cfs_status
.kvstore
!= NULL
, FALSE
);
1583 gboolean res
= TRUE
;
1585 g_mutex_lock (&mutex
);
1587 GHashTable
*ht
= cfs_status
.kvhash
;
1588 GHashTableIter iter
;
1589 gpointer key
, value
;
1591 g_hash_table_iter_init (&iter
, ht
);
1593 while (g_hash_table_iter_next (&iter
, &key
, &value
)) {
1594 kventry_t
*entry
= (kventry_t
*)value
;
1595 kvstore_send_update_message(cfs_status
.kvstore
, entry
->key
, entry
->data
, entry
->len
);
1598 g_mutex_unlock (&mutex
);
1615 g_return_val_if_fail(dfsm
!= NULL
, -1);
1616 g_return_val_if_fail(msg
!= NULL
, -1);
1617 g_return_val_if_fail(res_ptr
!= NULL
, -1);
1619 /* ignore message for ourself */
1620 if (dfsm_nodeid_is_local(dfsm
, nodeid
, pid
))
1623 if (msg_type
== KVSTORE_MESSAGE_UPDATE
) {
1627 if (kvstore_parse_update_message(msg
, msg_len
, &key
, &data
, &len
)) {
1628 cfs_kvstore_node_set(nodeid
, key
, data
, len
);
1630 cfs_critical("cant parse update message");
1632 } else if (msg_type
== KVSTORE_MESSAGE_LOG
) {
1633 cfs_message("received log"); // fixme: remove
1634 const clog_entry_t
*entry
;
1635 if ((entry
= kvstore_parse_log_message(msg
, msg_len
))) {
1636 clusterlog_insert(cfs_status
.clusterlog
, entry
);
1638 cfs_critical("cant parse log message");
1641 cfs_critical("received unknown message type %d\n", msg_type
);
1658 const struct cpg_address
*member_list
,
1659 size_t member_list_entries
)
1661 g_return_if_fail(dfsm
!= NULL
);
1662 g_return_if_fail(member_list
!= NULL
);
1664 cfs_debug("enter %s", __func__
);
1666 g_mutex_lock (&mutex
);
1668 cfs_clinfo_t
*clinfo
= cfs_status
.clinfo
;
1670 if (clinfo
&& clinfo
->nodes_byid
) {
1672 GHashTable
*ht
= clinfo
->nodes_byid
;
1673 GHashTableIter iter
;
1674 gpointer key
, value
;
1676 g_hash_table_iter_init (&iter
, ht
);
1678 while (g_hash_table_iter_next (&iter
, &key
, &value
)) {
1679 cfs_clnode_t
*node
= (cfs_clnode_t
*)value
;
1680 node
->online
= FALSE
;
1683 for (int i
= 0; i
< member_list_entries
; i
++) {
1685 if ((node
= g_hash_table_lookup(clinfo
->nodes_byid
, &member_list
[i
].nodeid
))) {
1686 node
->online
= TRUE
;
1690 cfs_status
.clinfo_version
++;
1693 g_mutex_unlock (&mutex
);
1700 unsigned int *res_len
)
1702 g_return_val_if_fail(dfsm
!= NULL
, NULL
);
1704 gpointer msg
= clusterlog_get_state(cfs_status
.clusterlog
, res_len
);
1710 dfsm_process_update(
1713 dfsm_sync_info_t
*syncinfo
,
1719 cfs_critical("%s: received unexpected update message", __func__
);
1725 dfsm_process_state_update(
1728 dfsm_sync_info_t
*syncinfo
)
1730 g_return_val_if_fail(dfsm
!= NULL
, -1);
1731 g_return_val_if_fail(syncinfo
!= NULL
, -1);
1733 clog_base_t
*clog
[syncinfo
->node_count
];
1735 int local_index
= -1;
1736 for (int i
= 0; i
< syncinfo
->node_count
; i
++) {
1737 dfsm_node_info_t
*ni
= &syncinfo
->nodes
[i
];
1740 if (syncinfo
->local
== ni
)
1743 clog_base_t
*base
= (clog_base_t
*)ni
->state
;
1744 if (ni
->state_len
> 8 && ni
->state_len
== clog_size(base
)) {
1745 clog
[i
] = ni
->state
;
1747 cfs_critical("received log with wrong size %u", ni
->state_len
);
1752 if (!clusterlog_merge(cfs_status
.clusterlog
, clog
, syncinfo
->node_count
, local_index
)) {
1753 cfs_critical("unable to merge log files");
1765 dfsm_sync_info_t
*syncinfo
)
1767 g_return_val_if_fail(dfsm
!= NULL
, -1);
1768 g_return_val_if_fail(syncinfo
!= NULL
, -1);
1774 dfsm_synced(dfsm_t
*dfsm
)
1776 g_return_if_fail(dfsm
!= NULL
);
1778 char *ip
= (char *)g_hash_table_lookup(cfs_status
.iphash
, cfs
.nodename
);
1782 cfs_status_set("nodeip", ip
, strlen(ip
) + 1);
1789 dfsm_sync_info_t
*syncinfo
)
1794 static dfsm_callbacks_t kvstore_dfsm_callbacks
= {
1795 .dfsm_deliver_fn
= dfsm_deliver
,
1796 .dfsm_confchg_fn
= dfsm_confchg
,
1798 .dfsm_get_state_fn
= dfsm_get_state
,
1799 .dfsm_process_state_update_fn
= dfsm_process_state_update
,
1800 .dfsm_process_update_fn
= dfsm_process_update
,
1801 .dfsm_commit_fn
= dfsm_commit
,
1802 .dfsm_cleanup_fn
= dfsm_cleanup
,
1803 .dfsm_synced_fn
= dfsm_synced
,
1807 cfs_status_dfsm_new(void)
1809 g_mutex_lock (&mutex
);
1811 cfs_status
.kvstore
= dfsm_new(NULL
, KVSTORE_CPG_GROUP_NAME
, G_LOG_DOMAIN
,
1812 0, &kvstore_dfsm_callbacks
);
1813 g_mutex_unlock (&mutex
);
1815 return cfs_status
.kvstore
;
1819 cfs_is_quorate(void)
1821 g_mutex_lock (&mutex
);
1822 gboolean res
= cfs_status
.quorate
;
1823 g_mutex_unlock (&mutex
);
1833 g_mutex_lock (&mutex
);
1835 uint32_t prev_quorate
= cfs_status
.quorate
;
1836 cfs_status
.quorate
= quorate
;
1838 if (!prev_quorate
&& cfs_status
.quorate
) {
1840 cfs_message("node has quorum");
1843 if (prev_quorate
&& !cfs_status
.quorate
) {
1845 cfs_message("node lost quorum");
1848 g_mutex_unlock (&mutex
);