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" },
106 cfs_clinfo_t
*clinfo
;
107 uint32_t clinfo_version
;
110 uint32_t vmlist_version
;
117 GHashTable
*memdb_changes
;
119 clusterlog_t
*clusterlog
;
122 static cfs_status_t cfs_status
;
134 uint32_t cman_version
;
136 GHashTable
*nodes_byid
;
137 GHashTable
*nodes_byname
;
141 g_int32_hash (gconstpointer v
)
143 return *(const uint32_t *) v
;
147 g_int32_equal (gconstpointer v1
,
150 return *((const uint32_t*) v1
) == *((const uint32_t*) v2
);
153 static void vminfo_free(vminfo_t
*vminfo
)
155 g_return_if_fail(vminfo
!= NULL
);
157 if (vminfo
->nodename
)
158 g_free(vminfo
->nodename
);
164 static const char *vminfo_type_to_string(vminfo_t
*vminfo
)
166 if (vminfo
->vmtype
== VMTYPE_QEMU
) {
168 } else if (vminfo
->vmtype
== VMTYPE_OPENVZ
) {
170 } else if (vminfo
->vmtype
== VMTYPE_LXC
) {
177 static const char *vminfo_type_to_path_type(vminfo_t
*vminfo
)
179 if (vminfo
->vmtype
== VMTYPE_QEMU
) {
180 return "qemu-server"; // special case..
182 return vminfo_type_to_string(vminfo
);
186 int vminfo_to_path(vminfo_t
*vminfo
, GString
*path
)
188 g_return_val_if_fail(vminfo
!= NULL
, -1);
189 g_return_val_if_fail(path
!= NULL
, -1);
191 if (!vminfo
->nodename
)
194 const char *type
= vminfo_type_to_path_type(vminfo
);
195 g_string_printf(path
, "/nodes/%s/%s/%u.conf", vminfo
->nodename
, type
, vminfo
->vmid
);
200 void cfs_clnode_destroy(
201 cfs_clnode_t
*clnode
)
203 g_return_if_fail(clnode
!= NULL
);
206 g_hash_table_destroy(clnode
->kvhash
);
209 g_free(clnode
->name
);
214 cfs_clnode_t
*cfs_clnode_new(
219 g_return_val_if_fail(name
!= NULL
, NULL
);
221 cfs_clnode_t
*clnode
= g_new0(cfs_clnode_t
, 1);
225 clnode
->name
= g_strdup(name
);
226 clnode
->nodeid
= nodeid
;
227 clnode
->votes
= votes
;
232 gboolean
cfs_clinfo_destroy(
233 cfs_clinfo_t
*clinfo
)
235 g_return_val_if_fail(clinfo
!= NULL
, FALSE
);
237 if (clinfo
->cluster_name
)
238 g_free(clinfo
->cluster_name
);
240 if (clinfo
->nodes_byname
)
241 g_hash_table_destroy(clinfo
->nodes_byname
);
243 if (clinfo
->nodes_byid
)
244 g_hash_table_destroy(clinfo
->nodes_byid
);
251 cfs_clinfo_t
*cfs_clinfo_new(
252 const char *cluster_name
,
253 uint32_t cman_version
)
255 g_return_val_if_fail(cluster_name
!= NULL
, NULL
);
257 cfs_clinfo_t
*clinfo
= g_new0(cfs_clinfo_t
, 1);
261 clinfo
->cluster_name
= g_strdup(cluster_name
);
262 clinfo
->cman_version
= cman_version
;
264 if (!(clinfo
->nodes_byid
= g_hash_table_new_full(
265 g_int32_hash
, g_int32_equal
, NULL
,
266 (GDestroyNotify
)cfs_clnode_destroy
)))
269 if (!(clinfo
->nodes_byname
= g_hash_table_new(g_str_hash
, g_str_equal
)))
275 cfs_clinfo_destroy(clinfo
);
280 gboolean
cfs_clinfo_add_node(
281 cfs_clinfo_t
*clinfo
,
282 cfs_clnode_t
*clnode
)
284 g_return_val_if_fail(clinfo
!= NULL
, FALSE
);
285 g_return_val_if_fail(clnode
!= NULL
, FALSE
);
287 g_hash_table_replace(clinfo
->nodes_byid
, &clnode
->nodeid
, clnode
);
288 g_hash_table_replace(clinfo
->nodes_byname
, clnode
->name
, clnode
);
294 cfs_create_memberlist_msg(
297 g_return_val_if_fail(str
!= NULL
, -EINVAL
);
299 g_mutex_lock (&mutex
);
301 g_string_append_printf(str
,"{\n");
305 cfs_clinfo_t
*clinfo
= cfs_status
.clinfo
;
307 if (clinfo
&& clinfo
->nodes_byid
)
308 nodecount
= g_hash_table_size(clinfo
->nodes_byid
);
311 g_string_append_printf(str
, "\"nodename\": \"%s\",\n", cfs
.nodename
);
312 g_string_append_printf(str
, "\"version\": %u,\n", cfs_status
.clinfo_version
);
314 g_string_append_printf(str
, "\"cluster\": { ");
315 g_string_append_printf(str
, "\"name\": \"%s\", \"version\": %d, "
316 "\"nodes\": %d, \"quorate\": %d ",
317 clinfo
->cluster_name
, clinfo
->cman_version
,
318 nodecount
, cfs_status
.quorate
);
320 g_string_append_printf(str
,"},\n");
321 g_string_append_printf(str
,"\"nodelist\": {\n");
323 GHashTable
*ht
= clinfo
->nodes_byid
;
327 g_hash_table_iter_init (&iter
, ht
);
330 while (g_hash_table_iter_next (&iter
, &key
, &value
)) {
331 cfs_clnode_t
*node
= (cfs_clnode_t
*)value
;
332 if (i
) g_string_append_printf(str
, ",\n");
335 g_string_append_printf(str
, " \"%s\": { \"id\": %d, \"online\": %d",
336 node
->name
, node
->nodeid
, node
->online
);
339 char *ip
= (char *)g_hash_table_lookup(cfs_status
.iphash
, node
->name
);
341 g_string_append_printf(str
, ", \"ip\": \"%s\"", ip
);
344 g_string_append_printf(str
, "}");
347 g_string_append_printf(str
,"\n }\n");
349 g_string_append_printf(str
, "\"nodename\": \"%s\",\n", cfs
.nodename
);
350 g_string_append_printf(str
, "\"version\": %u\n", cfs_status
.clinfo_version
);
353 g_string_append_printf(str
,"}\n");
355 g_mutex_unlock (&mutex
);
361 kventry_free(kventry_t
*entry
)
363 g_return_if_fail(entry
!= NULL
);
371 kventry_hash_new(void)
373 return g_hash_table_new_full(g_str_hash
, g_str_equal
, NULL
,
374 (GDestroyNotify
)kventry_free
);
378 rrdentry_free(rrdentry_t
*entry
)
380 g_return_if_fail(entry
!= NULL
);
388 rrdentry_hash_new(void)
390 return g_hash_table_new_full(g_str_hash
, g_str_equal
, NULL
,
391 (GDestroyNotify
)rrdentry_free
);
395 cfs_cluster_log_dump(GString
*str
, const char *user
, guint max_entries
)
397 clusterlog_dump(cfs_status
.clusterlog
, str
, user
, max_entries
);
401 cfs_cluster_log(clog_entry_t
*entry
)
403 g_return_if_fail(entry
!= NULL
);
405 clusterlog_insert(cfs_status
.clusterlog
, entry
);
407 if (cfs_status
.kvstore
) {
409 iov
[0].iov_base
= (char *)entry
;
410 iov
[0].iov_len
= clog_entry_size(entry
);
412 if (dfsm_is_initialized(cfs_status
.kvstore
))
413 dfsm_send_message(cfs_status
.kvstore
, KVSTORE_MESSAGE_LOG
, iov
, 1);
417 void cfs_status_init(void)
419 g_mutex_lock (&mutex
);
421 cfs_status
.start_time
= time(NULL
);
423 cfs_status
.vmlist
= vmlist_hash_new();
425 cfs_status
.kvhash
= kventry_hash_new();
427 cfs_status
.rrdhash
= rrdentry_hash_new();
429 cfs_status
.iphash
= g_hash_table_new_full(g_str_hash
, g_str_equal
, g_free
, g_free
);
431 cfs_status
.memdb_changes
= g_hash_table_new(g_str_hash
, g_str_equal
);
433 for (int i
= 0; i
< G_N_ELEMENTS(memdb_change_array
); i
++) {
434 g_hash_table_replace(cfs_status
.memdb_changes
,
435 memdb_change_array
[i
].path
,
436 &memdb_change_array
[i
]);
439 cfs_status
.clusterlog
= clusterlog_new();
442 clusterlog_add(cfs_status
.clusterlog
, "root", "cluster", getpid(),
443 LOG_INFO
, "starting cluster log");
445 g_mutex_unlock (&mutex
);
448 void cfs_status_cleanup(void)
450 g_mutex_lock (&mutex
);
452 cfs_status
.clinfo_version
++;
454 if (cfs_status
.clinfo
) {
455 cfs_clinfo_destroy(cfs_status
.clinfo
);
456 cfs_status
.clinfo
= NULL
;
459 if (cfs_status
.vmlist
) {
460 g_hash_table_destroy(cfs_status
.vmlist
);
461 cfs_status
.vmlist
= NULL
;
464 if (cfs_status
.kvhash
) {
465 g_hash_table_destroy(cfs_status
.kvhash
);
466 cfs_status
.kvhash
= NULL
;
469 if (cfs_status
.rrdhash
) {
470 g_hash_table_destroy(cfs_status
.rrdhash
);
471 cfs_status
.rrdhash
= NULL
;
474 if (cfs_status
.iphash
) {
475 g_hash_table_destroy(cfs_status
.iphash
);
476 cfs_status
.iphash
= NULL
;
479 if (cfs_status
.clusterlog
)
480 clusterlog_destroy(cfs_status
.clusterlog
);
482 g_mutex_unlock (&mutex
);
485 void cfs_status_set_clinfo(
486 cfs_clinfo_t
*clinfo
)
488 g_return_if_fail(clinfo
!= NULL
);
490 g_mutex_lock (&mutex
);
492 cfs_status
.clinfo_version
++;
494 cfs_clinfo_t
*old
= cfs_status
.clinfo
;
496 cfs_status
.clinfo
= clinfo
;
498 cfs_message("update cluster info (cluster name %s, version = %d)",
499 clinfo
->cluster_name
, clinfo
->cman_version
);
502 if (old
&& old
->nodes_byid
&& clinfo
->nodes_byid
) {
504 GHashTable
*ht
= clinfo
->nodes_byid
;
508 g_hash_table_iter_init (&iter
, ht
);
510 while (g_hash_table_iter_next (&iter
, &key
, &value
)) {
511 cfs_clnode_t
*node
= (cfs_clnode_t
*)value
;
512 cfs_clnode_t
*oldnode
;
513 if ((oldnode
= g_hash_table_lookup(old
->nodes_byid
, key
))) {
514 node
->online
= oldnode
->online
;
515 node
->kvhash
= oldnode
->kvhash
;
516 oldnode
->kvhash
= NULL
;
523 cfs_clinfo_destroy(old
);
526 g_mutex_unlock (&mutex
);
530 dump_kvstore_versions(
533 const char *nodename
)
535 g_return_if_fail(kvhash
!= NULL
);
536 g_return_if_fail(str
!= NULL
);
537 g_return_if_fail(nodename
!= NULL
);
539 GHashTable
*ht
= kvhash
;
543 g_string_append_printf(str
, "\"%s\": {\n", nodename
);
545 g_hash_table_iter_init (&iter
, ht
);
548 while (g_hash_table_iter_next (&iter
, &key
, &value
)) {
549 kventry_t
*entry
= (kventry_t
*)value
;
550 if (i
) g_string_append_printf(str
, ",\n");
552 g_string_append_printf(str
,"\"%s\": %u", entry
->key
, entry
->version
);
555 g_string_append_printf(str
, "}\n");
559 cfs_create_version_msg(GString
*str
)
561 g_return_val_if_fail(str
!= NULL
, -EINVAL
);
563 g_mutex_lock (&mutex
);
565 g_string_append_printf(str
,"{\n");
567 g_string_append_printf(str
, "\"starttime\": %lu,\n", (unsigned long)cfs_status
.start_time
);
569 g_string_append_printf(str
, "\"clinfo\": %u,\n", cfs_status
.clinfo_version
);
571 g_string_append_printf(str
, "\"vmlist\": %u,\n", cfs_status
.vmlist_version
);
573 for (int i
= 0; i
< G_N_ELEMENTS(memdb_change_array
); i
++) {
574 g_string_append_printf(str
, "\"%s\": %u,\n",
575 memdb_change_array
[i
].path
,
576 memdb_change_array
[i
].version
);
579 g_string_append_printf(str
, "\"kvstore\": {\n");
581 dump_kvstore_versions(str
, cfs_status
.kvhash
, cfs
.nodename
);
583 cfs_clinfo_t
*clinfo
= cfs_status
.clinfo
;
585 if (clinfo
&& clinfo
->nodes_byid
) {
586 GHashTable
*ht
= clinfo
->nodes_byid
;
590 g_hash_table_iter_init (&iter
, ht
);
592 while (g_hash_table_iter_next (&iter
, &key
, &value
)) {
593 cfs_clnode_t
*node
= (cfs_clnode_t
*)value
;
596 g_string_append_printf(str
, ",\n");
597 dump_kvstore_versions(str
, node
->kvhash
, node
->name
);
601 g_string_append_printf(str
,"}\n");
603 g_string_append_printf(str
,"}\n");
605 g_mutex_unlock (&mutex
);
611 vmlist_hash_new(void)
613 return g_hash_table_new_full(g_int_hash
, g_int_equal
, NULL
,
614 (GDestroyNotify
)vminfo_free
);
618 vmlist_hash_insert_vm(
622 const char *nodename
,
625 g_return_val_if_fail(vmlist
!= NULL
, FALSE
);
626 g_return_val_if_fail(nodename
!= NULL
, FALSE
);
627 g_return_val_if_fail(vmid
!= 0, FALSE
);
628 g_return_val_if_fail(vmtype
== VMTYPE_QEMU
|| vmtype
== VMTYPE_OPENVZ
||
629 vmtype
== VMTYPE_LXC
, FALSE
);
631 if (!replace
&& g_hash_table_lookup(vmlist
, &vmid
)) {
632 cfs_critical("detected duplicate VMID %d", vmid
);
636 vminfo_t
*vminfo
= g_new0(vminfo_t
, 1);
639 vminfo
->vmtype
= vmtype
;
640 vminfo
->nodename
= g_strdup(nodename
);
642 vminfo
->version
= ++vminfo_version_counter
;
644 g_hash_table_replace(vmlist
, &vminfo
->vmid
, vminfo
);
653 const char *nodename
)
655 g_return_if_fail(cfs_status
.vmlist
!= NULL
);
656 g_return_if_fail(nodename
!= NULL
);
657 g_return_if_fail(vmid
!= 0);
658 g_return_if_fail(vmtype
== VMTYPE_QEMU
|| vmtype
== VMTYPE_OPENVZ
||
659 vmtype
== VMTYPE_LXC
);
661 cfs_debug("vmlist_register_vm: %s/%u %d", nodename
, vmid
, vmtype
);
663 g_mutex_lock (&mutex
);
665 cfs_status
.vmlist_version
++;
667 vmlist_hash_insert_vm(cfs_status
.vmlist
, vmtype
, vmid
, nodename
, TRUE
);
669 g_mutex_unlock (&mutex
);
673 vmlist_different_vm_exists(
676 const char *nodename
)
678 g_return_val_if_fail(cfs_status
.vmlist
!= NULL
, FALSE
);
679 g_return_val_if_fail(vmid
!= 0, FALSE
);
681 gboolean res
= FALSE
;
683 g_mutex_lock (&mutex
);
686 if ((vminfo
= (vminfo_t
*)g_hash_table_lookup(cfs_status
.vmlist
, &vmid
))) {
687 if (!(vminfo
->vmtype
== vmtype
&& strcmp(vminfo
->nodename
, nodename
) == 0))
690 g_mutex_unlock (&mutex
);
699 g_return_val_if_fail(cfs_status
.vmlist
!= NULL
, FALSE
);
700 g_return_val_if_fail(vmid
!= 0, FALSE
);
702 g_mutex_lock (&mutex
);
704 gpointer res
= g_hash_table_lookup(cfs_status
.vmlist
, &vmid
);
706 g_mutex_unlock (&mutex
);
715 g_return_if_fail(cfs_status
.vmlist
!= NULL
);
716 g_return_if_fail(vmid
!= 0);
718 g_mutex_lock (&mutex
);
720 cfs_status
.vmlist_version
++;
722 g_hash_table_remove(cfs_status
.vmlist
, &vmid
);
724 g_mutex_unlock (&mutex
);
727 void cfs_status_set_vmlist(
730 g_return_if_fail(vmlist
!= NULL
);
732 g_mutex_lock (&mutex
);
734 cfs_status
.vmlist_version
++;
736 if (cfs_status
.vmlist
)
737 g_hash_table_destroy(cfs_status
.vmlist
);
739 cfs_status
.vmlist
= vmlist
;
741 g_mutex_unlock (&mutex
);
745 cfs_create_vmlist_msg(GString
*str
)
747 g_return_val_if_fail(cfs_status
.vmlist
!= NULL
, -EINVAL
);
748 g_return_val_if_fail(str
!= NULL
, -EINVAL
);
750 g_mutex_lock (&mutex
);
752 g_string_append_printf(str
,"{\n");
754 GHashTable
*ht
= cfs_status
.vmlist
;
756 guint count
= g_hash_table_size(ht
);
759 g_string_append_printf(str
,"\"version\": %u\n", cfs_status
.vmlist_version
);
761 g_string_append_printf(str
,"\"version\": %u,\n", cfs_status
.vmlist_version
);
763 g_string_append_printf(str
,"\"ids\": {\n");
768 g_hash_table_iter_init (&iter
, ht
);
771 while (g_hash_table_iter_next (&iter
, &key
, &value
)) {
772 vminfo_t
*vminfo
= (vminfo_t
*)value
;
773 const char *type
= vminfo_type_to_string(vminfo
);
776 g_string_append_printf(str
, ",\n");
779 g_string_append_printf(str
,"\"%u\": { \"node\": \"%s\", \"type\": \"%s\", \"version\": %u }",
780 vminfo
->vmid
, vminfo
->nodename
, type
, vminfo
->version
);
783 g_string_append_printf(str
,"}\n");
785 g_string_append_printf(str
,"\n}\n");
787 g_mutex_unlock (&mutex
);
792 // checks the conf for a line starting with '$prop:' and returns the value
793 // afterwards, whitout initial whitespace(s), we only deal with the format
794 // restricion imposed by our perl VM config parser, main reference is
795 // PVE::QemuServer::parse_vm_config this allows to be very fast and still
797 // main restrictions used for our advantage is the properties match reges:
798 // ($line =~ m/^([a-z][a-z_]*\d*):\s*(.+?)\s*$/) from parse_vm_config
799 // currently we only look at the current configuration in place, i.e., *no*
800 // snapshort and *no* pending changes
802 _get_property_value(char *conf
, const char *prop
, int prop_len
)
804 char *line
= NULL
, *temp
= NULL
;
806 line
= strtok_r(conf
, "\n", &temp
);
807 while (line
!= NULL
) {
808 if (!line
[0]) goto next
;
810 // snapshot or pending section start and nothing found yet
811 if (line
[0] == '[') return NULL
;
812 // properties start with /^[a-z]/, so continue early if not
813 if (line
[0] < 'a' || line
[0] > 'z') goto next
;
815 int line_len
= strlen(line
);
816 if (line_len
<= prop_len
+ 1) goto next
;
818 if (line
[prop_len
] == ':' && memcmp(line
, prop
, prop_len
) == 0) { // found
819 char *v_start
= &line
[prop_len
+ 1];
821 // drop initial value whitespaces here already
822 while (*v_start
&& isspace(*v_start
)) v_start
++;
824 if (!*v_start
) return NULL
;
826 char *v_end
= &line
[line_len
- 1];
827 while (v_end
> v_start
&& isspace(*v_end
)) v_end
--;
833 line
= strtok_r(NULL
, "\n", &temp
);
836 return NULL
; // not found
840 _g_str_append_kv_jsonescaped(GString
*str
, const char *k
, const char *v
)
842 g_string_append_printf(str
, "\"%s\": \"", k
);
845 if (*v
== '\\' || *v
== '"') {
846 g_string_append_c(str
, '\\');
848 g_string_append_c(str
, *v
);
851 g_string_append_c(str
, '"');
855 cfs_create_guest_conf_property_msg(GString
*str
, memdb_t
*memdb
, const char *prop
, uint32_t vmid
)
857 g_return_val_if_fail(cfs_status
.vmlist
!= NULL
, -EINVAL
);
858 g_return_val_if_fail(str
!= NULL
, -EINVAL
);
860 int prop_len
= strlen(prop
);
862 GString
*path
= NULL
;
864 g_mutex_lock (&mutex
);
866 g_string_printf(str
,"{\n");
868 GHashTable
*ht
= cfs_status
.vmlist
;
870 if (!g_hash_table_size(ht
)) {
874 path
= g_string_new_len(NULL
, 256);
876 vminfo_t
*vminfo
= (vminfo_t
*) g_hash_table_lookup(cfs_status
.vmlist
, &vmid
);
877 if (vminfo
== NULL
) goto enoent
;
879 if (!vminfo_to_path(vminfo
, path
)) goto err
;
881 int size
= memdb_read(memdb
, path
->str
, &tmp
);
882 if (tmp
== NULL
) goto err
;
883 if (size
<= prop_len
) goto ret
;
885 char *val
= _get_property_value(tmp
, prop
, prop_len
);
886 if (val
== NULL
) goto ret
;
888 g_string_append_printf(str
, "\"%u\":{", vmid
);
889 _g_str_append_kv_jsonescaped(str
, prop
, val
);
890 g_string_append_c(str
, '}');
894 g_hash_table_iter_init (&iter
, ht
);
898 while (g_hash_table_iter_next (&iter
, &key
, &value
)) {
899 vminfo_t
*vminfo
= (vminfo_t
*)value
;
901 if (!vminfo_to_path(vminfo
, path
)) goto err
;
903 g_free(tmp
); // no-op if already null
905 int size
= memdb_read(memdb
, path
->str
, &tmp
);
906 if (tmp
== NULL
|| size
<= prop_len
) continue;
908 char *val
= _get_property_value(tmp
, prop
, prop_len
);
909 if (val
== NULL
) continue;
911 if (!first
) g_string_append_printf(str
, ",\n");
914 g_string_append_printf(str
, "\"%u\":{", vminfo
->vmid
);
915 _g_str_append_kv_jsonescaped(str
, prop
, val
);
916 g_string_append_c(str
, '}');
921 g_string_free(path
, TRUE
);
922 g_string_append_printf(str
,"\n}\n");
923 g_mutex_unlock (&mutex
);
935 record_memdb_change(const char *path
)
937 g_return_if_fail(cfs_status
.memdb_changes
!= 0);
941 if ((ce
= (memdb_change_t
*)g_hash_table_lookup(cfs_status
.memdb_changes
, path
))) {
947 record_memdb_reload(void)
949 for (int i
= 0; i
< G_N_ELEMENTS(memdb_change_array
); i
++) {
950 memdb_change_array
[i
].version
++;
961 g_return_val_if_fail(kvhash
!= NULL
, FALSE
);
962 g_return_val_if_fail(key
!= NULL
, FALSE
);
963 g_return_val_if_fail(data
!= NULL
, FALSE
);
967 g_hash_table_remove(kvhash
, key
);
968 } else if ((entry
= (kventry_t
*)g_hash_table_lookup(kvhash
, key
))) {
970 entry
->data
= g_memdup(data
, len
);
974 kventry_t
*entry
= g_new0(kventry_t
, 1);
976 entry
->key
= g_strdup(key
);
977 entry
->data
= g_memdup(data
, len
);
980 g_hash_table_replace(kvhash
, entry
->key
, entry
);
986 static const char *rrd_def_node
[] = {
987 "DS:loadavg:GAUGE:120:0:U",
988 "DS:maxcpu:GAUGE:120:0:U",
989 "DS:cpu:GAUGE:120:0:U",
990 "DS:iowait:GAUGE:120:0:U",
991 "DS:memtotal:GAUGE:120:0:U",
992 "DS:memused:GAUGE:120:0:U",
993 "DS:swaptotal:GAUGE:120:0:U",
994 "DS:swapused:GAUGE:120:0:U",
995 "DS:roottotal:GAUGE:120:0:U",
996 "DS:rootused:GAUGE:120:0:U",
997 "DS:netin:DERIVE:120:0:U",
998 "DS:netout:DERIVE:120:0:U",
1000 "RRA:AVERAGE:0.5:1:70", // 1 min avg - one hour
1001 "RRA:AVERAGE:0.5:30:70", // 30 min avg - one day
1002 "RRA:AVERAGE:0.5:180:70", // 3 hour avg - one week
1003 "RRA:AVERAGE:0.5:720:70", // 12 hour avg - one month
1004 "RRA:AVERAGE:0.5:10080:70", // 7 day avg - ony year
1006 "RRA:MAX:0.5:1:70", // 1 min max - one hour
1007 "RRA:MAX:0.5:30:70", // 30 min max - one day
1008 "RRA:MAX:0.5:180:70", // 3 hour max - one week
1009 "RRA:MAX:0.5:720:70", // 12 hour max - one month
1010 "RRA:MAX:0.5:10080:70", // 7 day max - ony year
1014 static const char *rrd_def_vm
[] = {
1015 "DS:maxcpu:GAUGE:120:0:U",
1016 "DS:cpu:GAUGE:120:0:U",
1017 "DS:maxmem:GAUGE:120:0:U",
1018 "DS:mem:GAUGE:120:0:U",
1019 "DS:maxdisk:GAUGE:120:0:U",
1020 "DS:disk:GAUGE:120:0:U",
1021 "DS:netin:DERIVE:120:0:U",
1022 "DS:netout:DERIVE:120:0:U",
1023 "DS:diskread:DERIVE:120:0:U",
1024 "DS:diskwrite:DERIVE:120:0:U",
1026 "RRA:AVERAGE:0.5:1:70", // 1 min avg - one hour
1027 "RRA:AVERAGE:0.5:30:70", // 30 min avg - one day
1028 "RRA:AVERAGE:0.5:180:70", // 3 hour avg - one week
1029 "RRA:AVERAGE:0.5:720:70", // 12 hour avg - one month
1030 "RRA:AVERAGE:0.5:10080:70", // 7 day avg - ony year
1032 "RRA:MAX:0.5:1:70", // 1 min max - one hour
1033 "RRA:MAX:0.5:30:70", // 30 min max - one day
1034 "RRA:MAX:0.5:180:70", // 3 hour max - one week
1035 "RRA:MAX:0.5:720:70", // 12 hour max - one month
1036 "RRA:MAX:0.5:10080:70", // 7 day max - ony year
1040 static const char *rrd_def_storage
[] = {
1041 "DS:total:GAUGE:120:0:U",
1042 "DS:used:GAUGE:120:0:U",
1044 "RRA:AVERAGE:0.5:1:70", // 1 min avg - one hour
1045 "RRA:AVERAGE:0.5:30:70", // 30 min avg - one day
1046 "RRA:AVERAGE:0.5:180:70", // 3 hour avg - one week
1047 "RRA:AVERAGE:0.5:720:70", // 12 hour avg - one month
1048 "RRA:AVERAGE:0.5:10080:70", // 7 day avg - ony year
1050 "RRA:MAX:0.5:1:70", // 1 min max - one hour
1051 "RRA:MAX:0.5:30:70", // 30 min max - one day
1052 "RRA:MAX:0.5:180:70", // 3 hour max - one week
1053 "RRA:MAX:0.5:720:70", // 12 hour max - one month
1054 "RRA:MAX:0.5:10080:70", // 7 day max - ony year
1058 #define RRDDIR "/var/lib/rrdcached/db"
1062 const char *filename
,
1064 const char *rrddef
[])
1066 /* start at day boundary */
1069 struct tm
*ltm
= localtime(&ctime
);
1075 if (rrd_create_r(filename
, 60, timelocal(ltm
), argcount
, rrddef
)) {
1076 cfs_message("RRD create error %s: %s", filename
, rrd_get_error());
1080 static inline const char *
1086 while (*data
&& found
< count
) {
1099 g_return_if_fail(key
!= NULL
);
1100 g_return_if_fail(data
!= NULL
);
1101 g_return_if_fail(len
> 0);
1102 g_return_if_fail(len
< 4096);
1104 static const char *rrdcsock
= "unix:/var/run/rrdcached.sock";
1107 if (rrdc_connect(rrdcsock
) != 0)
1110 char *filename
= NULL
;
1114 if (strncmp(key
, "pve2-node/", 10) == 0) {
1115 const char *node
= key
+ 10;
1119 if (strchr(node
, '/') != NULL
)
1122 if (strlen(node
) < 1)
1125 filename
= g_strdup_printf(RRDDIR
"/%s", key
);
1127 if (!g_file_test(filename
, G_FILE_TEST_EXISTS
)) {
1129 mkdir(RRDDIR
"/pve2-node", 0755);
1130 int argcount
= sizeof(rrd_def_node
)/sizeof(void*) - 1;
1131 create_rrd_file(filename
, argcount
, rrd_def_node
);
1134 } else if ((strncmp(key
, "pve2-vm/", 8) == 0) ||
1135 (strncmp(key
, "pve2.3-vm/", 10) == 0)) {
1138 if (strncmp(key
, "pve2-vm/", 8) == 0) {
1146 if (strchr(vmid
, '/') != NULL
)
1149 if (strlen(vmid
) < 1)
1152 filename
= g_strdup_printf(RRDDIR
"/%s/%s", "pve2-vm", vmid
);
1154 if (!g_file_test(filename
, G_FILE_TEST_EXISTS
)) {
1156 mkdir(RRDDIR
"/pve2-vm", 0755);
1157 int argcount
= sizeof(rrd_def_vm
)/sizeof(void*) - 1;
1158 create_rrd_file(filename
, argcount
, rrd_def_vm
);
1161 } else if (strncmp(key
, "pve2-storage/", 13) == 0) {
1162 const char *node
= key
+ 13;
1164 const char *storage
= node
;
1165 while (*storage
&& *storage
!= '/')
1168 if (*storage
!= '/' || ((storage
- node
) < 1))
1173 if (strchr(storage
, '/') != NULL
)
1176 if (strlen(storage
) < 1)
1179 filename
= g_strdup_printf(RRDDIR
"/%s", key
);
1181 if (!g_file_test(filename
, G_FILE_TEST_EXISTS
)) {
1183 mkdir(RRDDIR
"/pve2-storage", 0755);
1185 char *dir
= g_path_get_dirname(filename
);
1189 int argcount
= sizeof(rrd_def_storage
)/sizeof(void*) - 1;
1190 create_rrd_file(filename
, argcount
, rrd_def_storage
);
1197 const char *dp
= skip
? rrd_skip_data(data
, skip
) : data
;
1199 const char *update_args
[] = { dp
, NULL
};
1203 if ((status
= rrdc_update(filename
, 1, update_args
)) != 0) {
1204 cfs_message("RRDC update error %s: %d", filename
, status
);
1207 if (rrd_update_r(filename
, NULL
, 1, update_args
) != 0) {
1208 cfs_message("RRD update error %s: %s", filename
, rrd_get_error());
1214 if (rrd_update_r(filename
, NULL
, 1, update_args
) != 0) {
1215 cfs_message("RRD update error %s: %s", filename
, rrd_get_error());
1226 cfs_critical("RRD update error: unknown/wrong key %s", key
);
1236 rrdentry_t
*entry
= (rrdentry_t
*)value
;
1237 uint32_t ctime
= GPOINTER_TO_UINT(user_data
);
1239 int diff
= ctime
- entry
->time
;
1241 /* remove everything older than 5 minutes */
1244 return (diff
> expire
) ? TRUE
: FALSE
;
1247 static char *rrd_dump_buf
= NULL
;
1248 static time_t rrd_dump_last
= 0;
1251 cfs_rrd_dump(GString
*str
)
1255 g_mutex_lock (&mutex
);
1258 if (rrd_dump_buf
&& (ctime
- rrd_dump_last
) < 2) {
1259 g_string_assign(str
, rrd_dump_buf
);
1260 g_mutex_unlock (&mutex
);
1264 /* remove old data */
1265 g_hash_table_foreach_remove(cfs_status
.rrdhash
, rrd_entry_is_old
,
1266 GUINT_TO_POINTER(ctime
));
1268 g_string_set_size(str
, 0);
1270 GHashTableIter iter
;
1271 gpointer key
, value
;
1273 g_hash_table_iter_init (&iter
, cfs_status
.rrdhash
);
1275 while (g_hash_table_iter_next (&iter
, &key
, &value
)) {
1276 rrdentry_t
*entry
= (rrdentry_t
*)value
;
1277 g_string_append(str
, key
);
1278 g_string_append(str
, ":");
1279 g_string_append(str
, entry
->data
);
1280 g_string_append(str
, "\n");
1283 g_string_append_c(str
, 0); // never return undef
1285 rrd_dump_last
= ctime
;
1287 g_free(rrd_dump_buf
);
1288 rrd_dump_buf
= g_strdup(str
->str
);
1290 g_mutex_unlock (&mutex
);
1296 const char *nodename
,
1300 g_return_val_if_fail(iphash
!= NULL
, FALSE
);
1301 g_return_val_if_fail(nodename
!= NULL
, FALSE
);
1302 g_return_val_if_fail(ip
!= NULL
, FALSE
);
1303 g_return_val_if_fail(len
> 0, FALSE
);
1304 g_return_val_if_fail(len
< 256, FALSE
);
1305 g_return_val_if_fail(ip
[len
-1] == 0, FALSE
);
1307 char *oldip
= (char *)g_hash_table_lookup(iphash
, nodename
);
1309 if (!oldip
|| (strcmp(oldip
, ip
) != 0)) {
1310 cfs_status
.clinfo_version
++;
1311 g_hash_table_replace(iphash
, g_strdup(nodename
), g_strdup(ip
));
1319 GHashTable
*rrdhash
,
1324 g_return_val_if_fail(rrdhash
!= NULL
, FALSE
);
1325 g_return_val_if_fail(key
!= NULL
, FALSE
);
1326 g_return_val_if_fail(data
!= NULL
, FALSE
);
1327 g_return_val_if_fail(len
> 0, FALSE
);
1328 g_return_val_if_fail(len
< 4096, FALSE
);
1329 g_return_val_if_fail(data
[len
-1] == 0, FALSE
);
1332 if ((entry
= (rrdentry_t
*)g_hash_table_lookup(rrdhash
, key
))) {
1333 g_free(entry
->data
);
1334 entry
->data
= g_memdup(data
, len
);
1336 entry
->time
= time(NULL
);
1338 rrdentry_t
*entry
= g_new0(rrdentry_t
, 1);
1340 entry
->key
= g_strdup(key
);
1341 entry
->data
= g_memdup(data
, len
);
1343 entry
->time
= time(NULL
);
1345 g_hash_table_replace(rrdhash
, entry
->key
, entry
);
1348 update_rrd_data(key
, data
, len
);
1354 kvstore_send_update_message(
1360 if (!dfsm_is_initialized(dfsm
))
1363 struct iovec iov
[2];
1366 g_strlcpy(name
, key
, sizeof(name
));
1368 iov
[0].iov_base
= &name
;
1369 iov
[0].iov_len
= sizeof(name
);
1371 iov
[1].iov_base
= (char *)data
;
1372 iov
[1].iov_len
= len
;
1374 if (dfsm_send_message(dfsm
, KVSTORE_MESSAGE_UPDATE
, iov
, 2) == CS_OK
)
1380 static clog_entry_t
*
1381 kvstore_parse_log_message(
1385 g_return_val_if_fail(msg
!= NULL
, NULL
);
1387 if (msg_len
< sizeof(clog_entry_t
)) {
1388 cfs_critical("received short log message (%zu < %zu)", msg_len
, sizeof(clog_entry_t
));
1392 clog_entry_t
*entry
= (clog_entry_t
*)msg
;
1394 uint32_t size
= sizeof(clog_entry_t
) + entry
->node_len
+
1395 entry
->ident_len
+ entry
->tag_len
+ entry
->msg_len
;
1397 if (msg_len
!= size
) {
1398 cfs_critical("received log message with wrong size (%zu != %u)", msg_len
, size
);
1404 if (*((char *)msg
+ entry
->node_len
- 1)) {
1405 cfs_critical("unterminated string in log message");
1408 msg
+= entry
->node_len
;
1410 if (*((char *)msg
+ entry
->ident_len
- 1)) {
1411 cfs_critical("unterminated string in log message");
1414 msg
+= entry
->ident_len
;
1416 if (*((char *)msg
+ entry
->tag_len
- 1)) {
1417 cfs_critical("unterminated string in log message");
1420 msg
+= entry
->tag_len
;
1422 if (*((char *)msg
+ entry
->msg_len
- 1)) {
1423 cfs_critical("unterminated string in log message");
1431 kvstore_parse_update_message(
1435 gconstpointer
*data
,
1438 g_return_val_if_fail(msg
!= NULL
, FALSE
);
1439 g_return_val_if_fail(key
!= NULL
, FALSE
);
1440 g_return_val_if_fail(data
!= NULL
, FALSE
);
1441 g_return_val_if_fail(len
!= NULL
, FALSE
);
1443 if (msg_len
< 256) {
1444 cfs_critical("received short kvstore message (%zu < 256)", msg_len
);
1448 /* test if key is null terminated */
1450 for (i
= 0; i
< 256; i
++)
1451 if (((char *)msg
)[i
] == 0)
1458 *len
= msg_len
- 256;
1466 cfs_create_status_msg(
1468 const char *nodename
,
1471 g_return_val_if_fail(str
!= NULL
, -EINVAL
);
1472 g_return_val_if_fail(key
!= NULL
, -EINVAL
);
1476 GHashTable
*kvhash
= NULL
;
1478 g_mutex_lock (&mutex
);
1480 if (!nodename
|| !nodename
[0] || !strcmp(nodename
, cfs
.nodename
)) {
1481 kvhash
= cfs_status
.kvhash
;
1482 } else if (cfs_status
.clinfo
&& cfs_status
.clinfo
->nodes_byname
) {
1483 cfs_clnode_t
*clnode
;
1484 if ((clnode
= g_hash_table_lookup(cfs_status
.clinfo
->nodes_byname
, nodename
)))
1485 kvhash
= clnode
->kvhash
;
1489 if (kvhash
&& (entry
= (kventry_t
*)g_hash_table_lookup(kvhash
, key
))) {
1490 g_string_append_len(str
, entry
->data
, entry
->len
);
1494 g_mutex_unlock (&mutex
);
1505 g_return_val_if_fail(key
!= NULL
, FALSE
);
1506 g_return_val_if_fail(data
!= NULL
, FALSE
);
1507 g_return_val_if_fail(cfs_status
.kvhash
!= NULL
, FALSE
);
1509 if (len
> CFS_MAX_STATUS_SIZE
)
1512 g_mutex_lock (&mutex
);
1516 if (strncmp(key
, "rrd/", 4) == 0) {
1517 res
= rrdentry_hash_set(cfs_status
.rrdhash
, key
+ 4, data
, len
);
1518 } else if (!strcmp(key
, "nodeip")) {
1519 res
= nodeip_hash_set(cfs_status
.iphash
, cfs
.nodename
, data
, len
);
1521 res
= kventry_hash_set(cfs_status
.kvhash
, key
, data
, len
);
1523 g_mutex_unlock (&mutex
);
1525 if (cfs_status
.kvstore
)
1526 kvstore_send_update_message(cfs_status
.kvstore
, key
, data
, len
);
1528 return res
? 0 : -ENOMEM
;
1532 cfs_kvstore_node_set(
1538 g_return_val_if_fail(nodeid
!= 0, FALSE
);
1539 g_return_val_if_fail(key
!= NULL
, FALSE
);
1540 g_return_val_if_fail(data
!= NULL
, FALSE
);
1542 g_mutex_lock (&mutex
);
1544 if (!cfs_status
.clinfo
|| !cfs_status
.clinfo
->nodes_byid
)
1545 goto ret
; /* ignore */
1547 cfs_clnode_t
*clnode
= g_hash_table_lookup(cfs_status
.clinfo
->nodes_byid
, &nodeid
);
1549 goto ret
; /* ignore */
1551 cfs_debug("got node %d status update %s", nodeid
, key
);
1553 if (strncmp(key
, "rrd/", 4) == 0) {
1554 rrdentry_hash_set(cfs_status
.rrdhash
, key
+ 4, data
, len
);
1555 } else if (!strcmp(key
, "nodeip")) {
1556 nodeip_hash_set(cfs_status
.iphash
, clnode
->name
, data
, len
);
1558 if (!clnode
->kvhash
) {
1559 if (!(clnode
->kvhash
= kventry_hash_new())) {
1560 goto ret
; /*ignore */
1564 kventry_hash_set(clnode
->kvhash
, key
, data
, len
);
1568 g_mutex_unlock (&mutex
);
1574 cfs_kvstore_sync(void)
1576 g_return_val_if_fail(cfs_status
.kvhash
!= NULL
, FALSE
);
1577 g_return_val_if_fail(cfs_status
.kvstore
!= NULL
, FALSE
);
1579 gboolean res
= TRUE
;
1581 g_mutex_lock (&mutex
);
1583 GHashTable
*ht
= cfs_status
.kvhash
;
1584 GHashTableIter iter
;
1585 gpointer key
, value
;
1587 g_hash_table_iter_init (&iter
, ht
);
1589 while (g_hash_table_iter_next (&iter
, &key
, &value
)) {
1590 kventry_t
*entry
= (kventry_t
*)value
;
1591 kvstore_send_update_message(cfs_status
.kvstore
, entry
->key
, entry
->data
, entry
->len
);
1594 g_mutex_unlock (&mutex
);
1611 g_return_val_if_fail(dfsm
!= NULL
, -1);
1612 g_return_val_if_fail(msg
!= NULL
, -1);
1613 g_return_val_if_fail(res_ptr
!= NULL
, -1);
1615 /* ignore message for ourself */
1616 if (dfsm_nodeid_is_local(dfsm
, nodeid
, pid
))
1619 if (msg_type
== KVSTORE_MESSAGE_UPDATE
) {
1623 if (kvstore_parse_update_message(msg
, msg_len
, &key
, &data
, &len
)) {
1624 cfs_kvstore_node_set(nodeid
, key
, data
, len
);
1626 cfs_critical("cant parse update message");
1628 } else if (msg_type
== KVSTORE_MESSAGE_LOG
) {
1629 cfs_message("received log"); // fixme: remove
1630 const clog_entry_t
*entry
;
1631 if ((entry
= kvstore_parse_log_message(msg
, msg_len
))) {
1632 clusterlog_insert(cfs_status
.clusterlog
, entry
);
1634 cfs_critical("cant parse log message");
1637 cfs_critical("received unknown message type %d\n", msg_type
);
1654 const struct cpg_address
*member_list
,
1655 size_t member_list_entries
)
1657 g_return_if_fail(dfsm
!= NULL
);
1658 g_return_if_fail(member_list
!= NULL
);
1660 cfs_debug("enter %s", __func__
);
1662 g_mutex_lock (&mutex
);
1664 cfs_clinfo_t
*clinfo
= cfs_status
.clinfo
;
1666 if (clinfo
&& clinfo
->nodes_byid
) {
1668 GHashTable
*ht
= clinfo
->nodes_byid
;
1669 GHashTableIter iter
;
1670 gpointer key
, value
;
1672 g_hash_table_iter_init (&iter
, ht
);
1674 while (g_hash_table_iter_next (&iter
, &key
, &value
)) {
1675 cfs_clnode_t
*node
= (cfs_clnode_t
*)value
;
1676 node
->online
= FALSE
;
1679 for (int i
= 0; i
< member_list_entries
; i
++) {
1681 if ((node
= g_hash_table_lookup(clinfo
->nodes_byid
, &member_list
[i
].nodeid
))) {
1682 node
->online
= TRUE
;
1686 cfs_status
.clinfo_version
++;
1689 g_mutex_unlock (&mutex
);
1696 unsigned int *res_len
)
1698 g_return_val_if_fail(dfsm
!= NULL
, NULL
);
1700 gpointer msg
= clusterlog_get_state(cfs_status
.clusterlog
, res_len
);
1706 dfsm_process_update(
1709 dfsm_sync_info_t
*syncinfo
,
1715 cfs_critical("%s: received unexpected update message", __func__
);
1721 dfsm_process_state_update(
1724 dfsm_sync_info_t
*syncinfo
)
1726 g_return_val_if_fail(dfsm
!= NULL
, -1);
1727 g_return_val_if_fail(syncinfo
!= NULL
, -1);
1729 clog_base_t
*clog
[syncinfo
->node_count
];
1731 int local_index
= -1;
1732 for (int i
= 0; i
< syncinfo
->node_count
; i
++) {
1733 dfsm_node_info_t
*ni
= &syncinfo
->nodes
[i
];
1736 if (syncinfo
->local
== ni
)
1739 clog_base_t
*base
= (clog_base_t
*)ni
->state
;
1740 if (ni
->state_len
> 8 && ni
->state_len
== clog_size(base
)) {
1741 clog
[i
] = ni
->state
;
1743 cfs_critical("received log with wrong size %u", ni
->state_len
);
1748 if (!clusterlog_merge(cfs_status
.clusterlog
, clog
, syncinfo
->node_count
, local_index
)) {
1749 cfs_critical("unable to merge log files");
1761 dfsm_sync_info_t
*syncinfo
)
1763 g_return_val_if_fail(dfsm
!= NULL
, -1);
1764 g_return_val_if_fail(syncinfo
!= NULL
, -1);
1770 dfsm_synced(dfsm_t
*dfsm
)
1772 g_return_if_fail(dfsm
!= NULL
);
1774 char *ip
= (char *)g_hash_table_lookup(cfs_status
.iphash
, cfs
.nodename
);
1778 cfs_status_set("nodeip", ip
, strlen(ip
) + 1);
1785 dfsm_sync_info_t
*syncinfo
)
1790 static dfsm_callbacks_t kvstore_dfsm_callbacks
= {
1791 .dfsm_deliver_fn
= dfsm_deliver
,
1792 .dfsm_confchg_fn
= dfsm_confchg
,
1794 .dfsm_get_state_fn
= dfsm_get_state
,
1795 .dfsm_process_state_update_fn
= dfsm_process_state_update
,
1796 .dfsm_process_update_fn
= dfsm_process_update
,
1797 .dfsm_commit_fn
= dfsm_commit
,
1798 .dfsm_cleanup_fn
= dfsm_cleanup
,
1799 .dfsm_synced_fn
= dfsm_synced
,
1803 cfs_status_dfsm_new(void)
1805 g_mutex_lock (&mutex
);
1807 cfs_status
.kvstore
= dfsm_new(NULL
, KVSTORE_CPG_GROUP_NAME
, G_LOG_DOMAIN
,
1808 0, &kvstore_dfsm_callbacks
);
1809 g_mutex_unlock (&mutex
);
1811 return cfs_status
.kvstore
;
1815 cfs_is_quorate(void)
1817 g_mutex_lock (&mutex
);
1818 gboolean res
= cfs_status
.quorate
;
1819 g_mutex_unlock (&mutex
);
1829 g_mutex_lock (&mutex
);
1831 uint32_t prev_quorate
= cfs_status
.quorate
;
1832 cfs_status
.quorate
= quorate
;
1834 if (!prev_quorate
&& cfs_status
.quorate
) {
1836 cfs_message("node has quorum");
1839 if (prev_quorate
&& !cfs_status
.quorate
) {
1841 cfs_message("node lost quorum");
1844 g_mutex_unlock (&mutex
);