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" },
109 { .path
= "nodes/hardware-map.conf" },
119 cfs_clinfo_t
*clinfo
;
120 uint32_t clinfo_version
;
123 uint32_t vmlist_version
;
130 GHashTable
*memdb_changes
;
132 clusterlog_t
*clusterlog
;
135 static cfs_status_t cfs_status
;
147 uint32_t cman_version
;
149 GHashTable
*nodes_byid
;
150 GHashTable
*nodes_byname
;
154 g_int32_hash (gconstpointer v
)
156 return *(const uint32_t *) v
;
160 g_int32_equal (gconstpointer v1
,
163 return *((const uint32_t*) v1
) == *((const uint32_t*) v2
);
166 static void vminfo_free(vminfo_t
*vminfo
)
168 g_return_if_fail(vminfo
!= NULL
);
170 if (vminfo
->nodename
)
171 g_free(vminfo
->nodename
);
177 static const char *vminfo_type_to_string(vminfo_t
*vminfo
)
179 if (vminfo
->vmtype
== VMTYPE_QEMU
) {
181 } else if (vminfo
->vmtype
== VMTYPE_OPENVZ
) {
182 // FIXME: remove openvz stuff for 7.x
184 } else if (vminfo
->vmtype
== VMTYPE_LXC
) {
191 static const char *vminfo_type_to_path_type(vminfo_t
*vminfo
)
193 if (vminfo
->vmtype
== VMTYPE_QEMU
) {
194 return "qemu-server"; // special case..
196 return vminfo_type_to_string(vminfo
);
200 int vminfo_to_path(vminfo_t
*vminfo
, GString
*path
)
202 g_return_val_if_fail(vminfo
!= NULL
, -1);
203 g_return_val_if_fail(path
!= NULL
, -1);
205 if (!vminfo
->nodename
)
208 const char *type
= vminfo_type_to_path_type(vminfo
);
209 g_string_printf(path
, "/nodes/%s/%s/%u.conf", vminfo
->nodename
, type
, vminfo
->vmid
);
214 void cfs_clnode_destroy(
215 cfs_clnode_t
*clnode
)
217 g_return_if_fail(clnode
!= NULL
);
220 g_hash_table_destroy(clnode
->kvhash
);
223 g_free(clnode
->name
);
228 cfs_clnode_t
*cfs_clnode_new(
233 g_return_val_if_fail(name
!= NULL
, NULL
);
235 cfs_clnode_t
*clnode
= g_new0(cfs_clnode_t
, 1);
239 clnode
->name
= g_strdup(name
);
240 clnode
->nodeid
= nodeid
;
241 clnode
->votes
= votes
;
246 gboolean
cfs_clinfo_destroy(
247 cfs_clinfo_t
*clinfo
)
249 g_return_val_if_fail(clinfo
!= NULL
, FALSE
);
251 if (clinfo
->cluster_name
)
252 g_free(clinfo
->cluster_name
);
254 if (clinfo
->nodes_byname
)
255 g_hash_table_destroy(clinfo
->nodes_byname
);
257 if (clinfo
->nodes_byid
)
258 g_hash_table_destroy(clinfo
->nodes_byid
);
265 cfs_clinfo_t
*cfs_clinfo_new(
266 const char *cluster_name
,
267 uint32_t cman_version
)
269 g_return_val_if_fail(cluster_name
!= NULL
, NULL
);
271 cfs_clinfo_t
*clinfo
= g_new0(cfs_clinfo_t
, 1);
275 clinfo
->cluster_name
= g_strdup(cluster_name
);
276 clinfo
->cman_version
= cman_version
;
278 if (!(clinfo
->nodes_byid
= g_hash_table_new_full(
279 g_int32_hash
, g_int32_equal
, NULL
,
280 (GDestroyNotify
)cfs_clnode_destroy
)))
283 if (!(clinfo
->nodes_byname
= g_hash_table_new(g_str_hash
, g_str_equal
)))
289 cfs_clinfo_destroy(clinfo
);
294 gboolean
cfs_clinfo_add_node(
295 cfs_clinfo_t
*clinfo
,
296 cfs_clnode_t
*clnode
)
298 g_return_val_if_fail(clinfo
!= NULL
, FALSE
);
299 g_return_val_if_fail(clnode
!= NULL
, FALSE
);
301 g_hash_table_replace(clinfo
->nodes_byid
, &clnode
->nodeid
, clnode
);
302 g_hash_table_replace(clinfo
->nodes_byname
, clnode
->name
, clnode
);
308 cfs_create_memberlist_msg(
311 g_return_val_if_fail(str
!= NULL
, -EINVAL
);
313 g_mutex_lock (&mutex
);
315 g_string_append_printf(str
,"{\n");
319 cfs_clinfo_t
*clinfo
= cfs_status
.clinfo
;
321 if (clinfo
&& clinfo
->nodes_byid
)
322 nodecount
= g_hash_table_size(clinfo
->nodes_byid
);
325 g_string_append_printf(str
, "\"nodename\": \"%s\",\n", cfs
.nodename
);
326 g_string_append_printf(str
, "\"version\": %u,\n", cfs_status
.clinfo_version
);
328 g_string_append_printf(str
, "\"cluster\": { ");
329 g_string_append_printf(str
, "\"name\": \"%s\", \"version\": %d, "
330 "\"nodes\": %d, \"quorate\": %d ",
331 clinfo
->cluster_name
, clinfo
->cman_version
,
332 nodecount
, cfs_status
.quorate
);
334 g_string_append_printf(str
,"},\n");
335 g_string_append_printf(str
,"\"nodelist\": {\n");
337 GHashTable
*ht
= clinfo
->nodes_byid
;
341 g_hash_table_iter_init (&iter
, ht
);
344 while (g_hash_table_iter_next (&iter
, &key
, &value
)) {
345 cfs_clnode_t
*node
= (cfs_clnode_t
*)value
;
346 if (i
) g_string_append_printf(str
, ",\n");
349 g_string_append_printf(str
, " \"%s\": { \"id\": %d, \"online\": %d",
350 node
->name
, node
->nodeid
, node
->online
);
353 char *ip
= (char *)g_hash_table_lookup(cfs_status
.iphash
, node
->name
);
355 g_string_append_printf(str
, ", \"ip\": \"%s\"", ip
);
358 g_string_append_printf(str
, "}");
361 g_string_append_printf(str
,"\n }\n");
363 g_string_append_printf(str
, "\"nodename\": \"%s\",\n", cfs
.nodename
);
364 g_string_append_printf(str
, "\"version\": %u\n", cfs_status
.clinfo_version
);
367 g_string_append_printf(str
,"}\n");
369 g_mutex_unlock (&mutex
);
375 kventry_free(kventry_t
*entry
)
377 g_return_if_fail(entry
!= NULL
);
385 kventry_hash_new(void)
387 return g_hash_table_new_full(g_str_hash
, g_str_equal
, NULL
,
388 (GDestroyNotify
)kventry_free
);
392 rrdentry_free(rrdentry_t
*entry
)
394 g_return_if_fail(entry
!= NULL
);
402 rrdentry_hash_new(void)
404 return g_hash_table_new_full(g_str_hash
, g_str_equal
, NULL
,
405 (GDestroyNotify
)rrdentry_free
);
409 cfs_cluster_log_dump(GString
*str
, const char *user
, guint max_entries
)
411 clusterlog_dump(cfs_status
.clusterlog
, str
, user
, max_entries
);
415 cfs_cluster_log(clog_entry_t
*entry
)
417 g_return_if_fail(entry
!= NULL
);
419 clusterlog_insert(cfs_status
.clusterlog
, entry
);
421 if (cfs_status
.kvstore
) {
423 iov
[0].iov_base
= (char *)entry
;
424 iov
[0].iov_len
= clog_entry_size(entry
);
426 if (dfsm_is_initialized(cfs_status
.kvstore
))
427 dfsm_send_message(cfs_status
.kvstore
, KVSTORE_MESSAGE_LOG
, iov
, 1);
431 void cfs_status_init(void)
433 g_mutex_lock (&mutex
);
435 cfs_status
.start_time
= time(NULL
);
437 cfs_status
.vmlist
= vmlist_hash_new();
439 cfs_status
.kvhash
= kventry_hash_new();
441 cfs_status
.rrdhash
= rrdentry_hash_new();
443 cfs_status
.iphash
= g_hash_table_new_full(g_str_hash
, g_str_equal
, g_free
, g_free
);
445 cfs_status
.memdb_changes
= g_hash_table_new(g_str_hash
, g_str_equal
);
447 for (int i
= 0; i
< G_N_ELEMENTS(memdb_change_array
); i
++) {
448 g_hash_table_replace(cfs_status
.memdb_changes
,
449 memdb_change_array
[i
].path
,
450 &memdb_change_array
[i
]);
453 cfs_status
.clusterlog
= clusterlog_new();
456 clusterlog_add(cfs_status
.clusterlog
, "root", "cluster", getpid(),
457 LOG_INFO
, "starting cluster log");
459 g_mutex_unlock (&mutex
);
462 void cfs_status_cleanup(void)
464 g_mutex_lock (&mutex
);
466 cfs_status
.clinfo_version
++;
468 if (cfs_status
.clinfo
) {
469 cfs_clinfo_destroy(cfs_status
.clinfo
);
470 cfs_status
.clinfo
= NULL
;
473 if (cfs_status
.vmlist
) {
474 g_hash_table_destroy(cfs_status
.vmlist
);
475 cfs_status
.vmlist
= NULL
;
478 if (cfs_status
.kvhash
) {
479 g_hash_table_destroy(cfs_status
.kvhash
);
480 cfs_status
.kvhash
= NULL
;
483 if (cfs_status
.rrdhash
) {
484 g_hash_table_destroy(cfs_status
.rrdhash
);
485 cfs_status
.rrdhash
= NULL
;
488 if (cfs_status
.iphash
) {
489 g_hash_table_destroy(cfs_status
.iphash
);
490 cfs_status
.iphash
= NULL
;
493 if (cfs_status
.clusterlog
)
494 clusterlog_destroy(cfs_status
.clusterlog
);
496 g_mutex_unlock (&mutex
);
499 void cfs_status_set_clinfo(
500 cfs_clinfo_t
*clinfo
)
502 g_return_if_fail(clinfo
!= NULL
);
504 g_mutex_lock (&mutex
);
506 cfs_status
.clinfo_version
++;
508 cfs_clinfo_t
*old
= cfs_status
.clinfo
;
510 cfs_status
.clinfo
= clinfo
;
512 cfs_message("update cluster info (cluster name %s, version = %d)",
513 clinfo
->cluster_name
, clinfo
->cman_version
);
516 if (old
&& old
->nodes_byid
&& clinfo
->nodes_byid
) {
518 GHashTable
*ht
= clinfo
->nodes_byid
;
522 g_hash_table_iter_init (&iter
, ht
);
524 while (g_hash_table_iter_next (&iter
, &key
, &value
)) {
525 cfs_clnode_t
*node
= (cfs_clnode_t
*)value
;
526 cfs_clnode_t
*oldnode
;
527 if ((oldnode
= g_hash_table_lookup(old
->nodes_byid
, key
))) {
528 node
->online
= oldnode
->online
;
529 node
->kvhash
= oldnode
->kvhash
;
530 oldnode
->kvhash
= NULL
;
537 cfs_clinfo_destroy(old
);
540 g_mutex_unlock (&mutex
);
544 dump_kvstore_versions(
547 const char *nodename
)
549 g_return_if_fail(kvhash
!= NULL
);
550 g_return_if_fail(str
!= NULL
);
551 g_return_if_fail(nodename
!= NULL
);
553 GHashTable
*ht
= kvhash
;
557 g_string_append_printf(str
, "\"%s\": {\n", nodename
);
559 g_hash_table_iter_init (&iter
, ht
);
562 while (g_hash_table_iter_next (&iter
, &key
, &value
)) {
563 kventry_t
*entry
= (kventry_t
*)value
;
564 if (i
) g_string_append_printf(str
, ",\n");
566 g_string_append_printf(str
,"\"%s\": %u", entry
->key
, entry
->version
);
569 g_string_append_printf(str
, "}\n");
573 cfs_create_version_msg(GString
*str
)
575 g_return_val_if_fail(str
!= NULL
, -EINVAL
);
577 g_mutex_lock (&mutex
);
579 g_string_append_printf(str
,"{\n");
581 g_string_append_printf(str
, "\"starttime\": %lu,\n", (unsigned long)cfs_status
.start_time
);
583 g_string_append_printf(str
, "\"clinfo\": %u,\n", cfs_status
.clinfo_version
);
585 g_string_append_printf(str
, "\"vmlist\": %u,\n", cfs_status
.vmlist_version
);
587 for (int i
= 0; i
< G_N_ELEMENTS(memdb_change_array
); i
++) {
588 g_string_append_printf(str
, "\"%s\": %u,\n",
589 memdb_change_array
[i
].path
,
590 memdb_change_array
[i
].version
);
593 g_string_append_printf(str
, "\"kvstore\": {\n");
595 dump_kvstore_versions(str
, cfs_status
.kvhash
, cfs
.nodename
);
597 cfs_clinfo_t
*clinfo
= cfs_status
.clinfo
;
599 if (clinfo
&& clinfo
->nodes_byid
) {
600 GHashTable
*ht
= clinfo
->nodes_byid
;
604 g_hash_table_iter_init (&iter
, ht
);
606 while (g_hash_table_iter_next (&iter
, &key
, &value
)) {
607 cfs_clnode_t
*node
= (cfs_clnode_t
*)value
;
610 g_string_append_printf(str
, ",\n");
611 dump_kvstore_versions(str
, node
->kvhash
, node
->name
);
615 g_string_append_printf(str
,"}\n");
617 g_string_append_printf(str
,"}\n");
619 g_mutex_unlock (&mutex
);
625 vmlist_hash_new(void)
627 return g_hash_table_new_full(g_int_hash
, g_int_equal
, NULL
,
628 (GDestroyNotify
)vminfo_free
);
632 vmlist_hash_insert_vm(
636 const char *nodename
,
639 g_return_val_if_fail(vmlist
!= NULL
, FALSE
);
640 g_return_val_if_fail(nodename
!= NULL
, FALSE
);
641 g_return_val_if_fail(vmid
!= 0, FALSE
);
642 // FIXME: remove openvz stuff for 7.x
643 g_return_val_if_fail(vmtype
== VMTYPE_QEMU
|| vmtype
== VMTYPE_OPENVZ
||
644 vmtype
== VMTYPE_LXC
, FALSE
);
646 if (!replace
&& g_hash_table_lookup(vmlist
, &vmid
)) {
647 cfs_critical("detected duplicate VMID %d", vmid
);
651 vminfo_t
*vminfo
= g_new0(vminfo_t
, 1);
654 vminfo
->vmtype
= vmtype
;
655 vminfo
->nodename
= g_strdup(nodename
);
657 vminfo
->version
= ++vminfo_version_counter
;
659 g_hash_table_replace(vmlist
, &vminfo
->vmid
, vminfo
);
668 const char *nodename
)
670 g_return_if_fail(cfs_status
.vmlist
!= NULL
);
671 g_return_if_fail(nodename
!= NULL
);
672 g_return_if_fail(vmid
!= 0);
673 // FIXME: remove openvz stuff for 7.x
674 g_return_if_fail(vmtype
== VMTYPE_QEMU
|| vmtype
== VMTYPE_OPENVZ
||
675 vmtype
== VMTYPE_LXC
);
677 cfs_debug("vmlist_register_vm: %s/%u %d", nodename
, vmid
, vmtype
);
679 g_mutex_lock (&mutex
);
681 cfs_status
.vmlist_version
++;
683 vmlist_hash_insert_vm(cfs_status
.vmlist
, vmtype
, vmid
, nodename
, TRUE
);
685 g_mutex_unlock (&mutex
);
689 vmlist_different_vm_exists(
692 const char *nodename
)
694 g_return_val_if_fail(cfs_status
.vmlist
!= NULL
, FALSE
);
695 g_return_val_if_fail(vmid
!= 0, FALSE
);
697 gboolean res
= FALSE
;
699 g_mutex_lock (&mutex
);
702 if ((vminfo
= (vminfo_t
*)g_hash_table_lookup(cfs_status
.vmlist
, &vmid
))) {
703 if (!(vminfo
->vmtype
== vmtype
&& strcmp(vminfo
->nodename
, nodename
) == 0))
706 g_mutex_unlock (&mutex
);
715 g_return_val_if_fail(cfs_status
.vmlist
!= NULL
, FALSE
);
716 g_return_val_if_fail(vmid
!= 0, FALSE
);
718 g_mutex_lock (&mutex
);
720 gpointer res
= g_hash_table_lookup(cfs_status
.vmlist
, &vmid
);
722 g_mutex_unlock (&mutex
);
731 g_return_if_fail(cfs_status
.vmlist
!= NULL
);
732 g_return_if_fail(vmid
!= 0);
734 g_mutex_lock (&mutex
);
736 cfs_status
.vmlist_version
++;
738 g_hash_table_remove(cfs_status
.vmlist
, &vmid
);
740 g_mutex_unlock (&mutex
);
743 void cfs_status_set_vmlist(
746 g_return_if_fail(vmlist
!= NULL
);
748 g_mutex_lock (&mutex
);
750 cfs_status
.vmlist_version
++;
752 if (cfs_status
.vmlist
)
753 g_hash_table_destroy(cfs_status
.vmlist
);
755 cfs_status
.vmlist
= vmlist
;
757 g_mutex_unlock (&mutex
);
761 cfs_create_vmlist_msg(GString
*str
)
763 g_return_val_if_fail(cfs_status
.vmlist
!= NULL
, -EINVAL
);
764 g_return_val_if_fail(str
!= NULL
, -EINVAL
);
766 g_mutex_lock (&mutex
);
768 g_string_append_printf(str
,"{\n");
770 GHashTable
*ht
= cfs_status
.vmlist
;
772 guint count
= g_hash_table_size(ht
);
775 g_string_append_printf(str
,"\"version\": %u\n", cfs_status
.vmlist_version
);
777 g_string_append_printf(str
,"\"version\": %u,\n", cfs_status
.vmlist_version
);
779 g_string_append_printf(str
,"\"ids\": {\n");
784 g_hash_table_iter_init (&iter
, ht
);
787 while (g_hash_table_iter_next (&iter
, &key
, &value
)) {
788 vminfo_t
*vminfo
= (vminfo_t
*)value
;
789 const char *type
= vminfo_type_to_string(vminfo
);
792 g_string_append_printf(str
, ",\n");
795 g_string_append_printf(str
,"\"%u\": { \"node\": \"%s\", \"type\": \"%s\", \"version\": %u }",
796 vminfo
->vmid
, vminfo
->nodename
, type
, vminfo
->version
);
799 g_string_append_printf(str
,"}\n");
801 g_string_append_printf(str
,"\n}\n");
803 g_mutex_unlock (&mutex
);
808 // checks the conf for a line starting with '$prop:' and returns the value
809 // afterwards, whitout initial whitespace(s), we only deal with the format
810 // restricion imposed by our perl VM config parser, main reference is
811 // PVE::QemuServer::parse_vm_config this allows to be very fast and still
813 // main restrictions used for our advantage is the properties match reges:
814 // ($line =~ m/^([a-z][a-z_]*\d*):\s*(.+?)\s*$/) from parse_vm_config
815 // currently we only look at the current configuration in place, i.e., *no*
816 // snapshort and *no* pending changes
818 _get_property_value(char *conf
, int conf_size
, const char *prop
, int prop_len
)
820 const char *const conf_end
= conf
+ conf_size
;
822 size_t remaining_size
;
824 char *next_newline
= memchr(conf
, '\n', conf_size
);
825 if (next_newline
== NULL
) {
826 return NULL
; // valid property lines end with \n, but none in the config
828 *next_newline
= '\0';
830 while (line
!= NULL
) {
831 if (!line
[0]) goto next
;
833 // snapshot or pending section start, but nothing found yet -> not found
834 if (line
[0] == '[') return NULL
;
835 // properties start with /^[a-z]/, so continue early if not
836 if (line
[0] < 'a' || line
[0] > 'z') goto next
;
838 int line_len
= strlen(line
);
839 if (line_len
<= prop_len
+ 1) goto next
;
841 if (line
[prop_len
] == ':' && memcmp(line
, prop
, prop_len
) == 0) { // found
842 char *v_start
= &line
[prop_len
+ 1];
844 // drop initial value whitespaces here already
845 while (*v_start
&& isspace(*v_start
)) v_start
++;
847 if (!*v_start
) return NULL
;
849 char *v_end
= &line
[line_len
- 1];
850 while (v_end
> v_start
&& isspace(*v_end
)) v_end
--;
856 line
= next_newline
+ 1;
857 remaining_size
= conf_end
- line
;
858 if (remaining_size
<= prop_len
) {
861 next_newline
= memchr(line
, '\n', remaining_size
);
862 if (next_newline
== NULL
) {
863 return NULL
; // valid property lines end with \n, but none in the config
865 *next_newline
= '\0';
868 return NULL
; // not found
872 _g_str_append_kv_jsonescaped(GString
*str
, const char *k
, const char *v
)
874 g_string_append_printf(str
, "\"%s\": \"", k
);
877 if (*v
== '\\' || *v
== '"') {
878 g_string_append_c(str
, '\\');
880 g_string_append_c(str
, *v
);
883 g_string_append_c(str
, '"');
887 cfs_create_guest_conf_property_msg(GString
*str
, memdb_t
*memdb
, const char *prop
, uint32_t vmid
)
889 g_return_val_if_fail(cfs_status
.vmlist
!= NULL
, -EINVAL
);
890 g_return_val_if_fail(str
!= NULL
, -EINVAL
);
892 int prop_len
= strlen(prop
);
894 GString
*path
= NULL
;
896 // Prelock &memdb->mutex in order to enable the usage of memdb_read_nolock
897 // to prevent Deadlocks as in #2553
898 g_mutex_lock (&memdb
->mutex
);
899 g_mutex_lock (&mutex
);
901 g_string_printf(str
,"{\n");
903 GHashTable
*ht
= cfs_status
.vmlist
;
905 if (!g_hash_table_size(ht
)) {
909 if ((path
= g_string_sized_new(256)) == NULL
) {
915 vminfo_t
*vminfo
= (vminfo_t
*) g_hash_table_lookup(cfs_status
.vmlist
, &vmid
);
916 if (vminfo
== NULL
) goto enoent
;
918 if (!vminfo_to_path(vminfo
, path
)) goto err
;
920 // use memdb_read_nolock because lock is handled here
921 int size
= memdb_read_nolock(memdb
, path
->str
, &tmp
);
922 if (tmp
== NULL
) goto err
;
923 if (size
<= prop_len
) goto ret
;
925 char *val
= _get_property_value(tmp
, size
, prop
, prop_len
);
926 if (val
== NULL
) goto ret
;
928 g_string_append_printf(str
, "\"%u\":{", vmid
);
929 _g_str_append_kv_jsonescaped(str
, prop
, val
);
930 g_string_append_c(str
, '}');
934 g_hash_table_iter_init (&iter
, ht
);
938 while (g_hash_table_iter_next (&iter
, &key
, &value
)) {
939 vminfo_t
*vminfo
= (vminfo_t
*)value
;
941 if (!vminfo_to_path(vminfo
, path
)) goto err
;
943 g_free(tmp
); // no-op if already null
945 // use memdb_read_nolock because lock is handled here
946 int size
= memdb_read_nolock(memdb
, path
->str
, &tmp
);
947 if (tmp
== NULL
|| size
<= prop_len
) continue;
949 char *val
= _get_property_value(tmp
, size
, prop
, prop_len
);
950 if (val
== NULL
) continue;
952 if (!first
) g_string_append_printf(str
, ",\n");
955 g_string_append_printf(str
, "\"%u\":{", vminfo
->vmid
);
956 _g_str_append_kv_jsonescaped(str
, prop
, val
);
957 g_string_append_c(str
, '}');
963 g_string_free(path
, TRUE
);
965 g_string_append_printf(str
,"\n}\n");
966 g_mutex_unlock (&mutex
);
967 g_mutex_unlock (&memdb
->mutex
);
978 record_memdb_change(const char *path
)
980 g_return_if_fail(cfs_status
.memdb_changes
!= 0);
984 if ((ce
= (memdb_change_t
*)g_hash_table_lookup(cfs_status
.memdb_changes
, path
))) {
990 record_memdb_reload(void)
992 for (int i
= 0; i
< G_N_ELEMENTS(memdb_change_array
); i
++) {
993 memdb_change_array
[i
].version
++;
1004 g_return_val_if_fail(kvhash
!= NULL
, FALSE
);
1005 g_return_val_if_fail(key
!= NULL
, FALSE
);
1006 g_return_val_if_fail(data
!= NULL
, FALSE
);
1010 g_hash_table_remove(kvhash
, key
);
1011 } else if ((entry
= (kventry_t
*)g_hash_table_lookup(kvhash
, key
))) {
1012 g_free(entry
->data
);
1013 entry
->data
= g_memdup(data
, len
);
1017 kventry_t
*entry
= g_new0(kventry_t
, 1);
1019 entry
->key
= g_strdup(key
);
1020 entry
->data
= g_memdup(data
, len
);
1023 g_hash_table_replace(kvhash
, entry
->key
, entry
);
1029 static const char *rrd_def_node
[] = {
1030 "DS:loadavg:GAUGE:120:0:U",
1031 "DS:maxcpu:GAUGE:120:0:U",
1032 "DS:cpu:GAUGE:120:0:U",
1033 "DS:iowait:GAUGE:120:0:U",
1034 "DS:memtotal:GAUGE:120:0:U",
1035 "DS:memused:GAUGE:120:0:U",
1036 "DS:swaptotal:GAUGE:120:0:U",
1037 "DS:swapused:GAUGE:120:0:U",
1038 "DS:roottotal:GAUGE:120:0:U",
1039 "DS:rootused:GAUGE:120:0:U",
1040 "DS:netin:DERIVE:120:0:U",
1041 "DS:netout:DERIVE:120:0:U",
1043 "RRA:AVERAGE:0.5:1:70", // 1 min avg - one hour
1044 "RRA:AVERAGE:0.5:30:70", // 30 min avg - one day
1045 "RRA:AVERAGE:0.5:180:70", // 3 hour avg - one week
1046 "RRA:AVERAGE:0.5:720:70", // 12 hour avg - one month
1047 "RRA:AVERAGE:0.5:10080:70", // 7 day avg - ony year
1049 "RRA:MAX:0.5:1:70", // 1 min max - one hour
1050 "RRA:MAX:0.5:30:70", // 30 min max - one day
1051 "RRA:MAX:0.5:180:70", // 3 hour max - one week
1052 "RRA:MAX:0.5:720:70", // 12 hour max - one month
1053 "RRA:MAX:0.5:10080:70", // 7 day max - ony year
1057 static const char *rrd_def_vm
[] = {
1058 "DS:maxcpu:GAUGE:120:0:U",
1059 "DS:cpu:GAUGE:120:0:U",
1060 "DS:maxmem:GAUGE:120:0:U",
1061 "DS:mem:GAUGE:120:0:U",
1062 "DS:maxdisk:GAUGE:120:0:U",
1063 "DS:disk:GAUGE:120:0:U",
1064 "DS:netin:DERIVE:120:0:U",
1065 "DS:netout:DERIVE:120:0:U",
1066 "DS:diskread:DERIVE:120:0:U",
1067 "DS:diskwrite:DERIVE:120:0:U",
1069 "RRA:AVERAGE:0.5:1:70", // 1 min avg - one hour
1070 "RRA:AVERAGE:0.5:30:70", // 30 min avg - one day
1071 "RRA:AVERAGE:0.5:180:70", // 3 hour avg - one week
1072 "RRA:AVERAGE:0.5:720:70", // 12 hour avg - one month
1073 "RRA:AVERAGE:0.5:10080:70", // 7 day avg - ony year
1075 "RRA:MAX:0.5:1:70", // 1 min max - one hour
1076 "RRA:MAX:0.5:30:70", // 30 min max - one day
1077 "RRA:MAX:0.5:180:70", // 3 hour max - one week
1078 "RRA:MAX:0.5:720:70", // 12 hour max - one month
1079 "RRA:MAX:0.5:10080:70", // 7 day max - ony year
1083 static const char *rrd_def_storage
[] = {
1084 "DS:total:GAUGE:120:0:U",
1085 "DS:used:GAUGE:120:0:U",
1087 "RRA:AVERAGE:0.5:1:70", // 1 min avg - one hour
1088 "RRA:AVERAGE:0.5:30:70", // 30 min avg - one day
1089 "RRA:AVERAGE:0.5:180:70", // 3 hour avg - one week
1090 "RRA:AVERAGE:0.5:720:70", // 12 hour avg - one month
1091 "RRA:AVERAGE:0.5:10080:70", // 7 day avg - ony year
1093 "RRA:MAX:0.5:1:70", // 1 min max - one hour
1094 "RRA:MAX:0.5:30:70", // 30 min max - one day
1095 "RRA:MAX:0.5:180:70", // 3 hour max - one week
1096 "RRA:MAX:0.5:720:70", // 12 hour max - one month
1097 "RRA:MAX:0.5:10080:70", // 7 day max - ony year
1101 #define RRDDIR "/var/lib/rrdcached/db"
1105 const char *filename
,
1107 const char *rrddef
[])
1109 /* start at day boundary */
1112 struct tm
*ltm
= localtime(&ctime
);
1118 if (rrd_create_r(filename
, 60, timelocal(ltm
), argcount
, rrddef
)) {
1119 cfs_message("RRD create error %s: %s", filename
, rrd_get_error());
1123 static inline const char *
1129 while (*data
&& found
< count
) {
1142 g_return_if_fail(key
!= NULL
);
1143 g_return_if_fail(data
!= NULL
);
1144 g_return_if_fail(len
> 0);
1145 g_return_if_fail(len
< 4096);
1147 static const char *rrdcsock
= "unix:/var/run/rrdcached.sock";
1150 if (rrdc_connect(rrdcsock
) != 0)
1153 char *filename
= NULL
;
1157 if (strncmp(key
, "pve2-node/", 10) == 0) {
1158 const char *node
= key
+ 10;
1162 if (strchr(node
, '/') != NULL
)
1165 if (strlen(node
) < 1)
1168 filename
= g_strdup_printf(RRDDIR
"/%s", key
);
1170 if (!g_file_test(filename
, G_FILE_TEST_EXISTS
)) {
1172 mkdir(RRDDIR
"/pve2-node", 0755);
1173 int argcount
= sizeof(rrd_def_node
)/sizeof(void*) - 1;
1174 create_rrd_file(filename
, argcount
, rrd_def_node
);
1177 } else if ((strncmp(key
, "pve2-vm/", 8) == 0) ||
1178 (strncmp(key
, "pve2.3-vm/", 10) == 0)) {
1181 if (strncmp(key
, "pve2-vm/", 8) == 0) {
1189 if (strchr(vmid
, '/') != NULL
)
1192 if (strlen(vmid
) < 1)
1195 filename
= g_strdup_printf(RRDDIR
"/%s/%s", "pve2-vm", vmid
);
1197 if (!g_file_test(filename
, G_FILE_TEST_EXISTS
)) {
1199 mkdir(RRDDIR
"/pve2-vm", 0755);
1200 int argcount
= sizeof(rrd_def_vm
)/sizeof(void*) - 1;
1201 create_rrd_file(filename
, argcount
, rrd_def_vm
);
1204 } else if (strncmp(key
, "pve2-storage/", 13) == 0) {
1205 const char *node
= key
+ 13;
1207 const char *storage
= node
;
1208 while (*storage
&& *storage
!= '/')
1211 if (*storage
!= '/' || ((storage
- node
) < 1))
1216 if (strchr(storage
, '/') != NULL
)
1219 if (strlen(storage
) < 1)
1222 filename
= g_strdup_printf(RRDDIR
"/%s", key
);
1224 if (!g_file_test(filename
, G_FILE_TEST_EXISTS
)) {
1226 mkdir(RRDDIR
"/pve2-storage", 0755);
1228 char *dir
= g_path_get_dirname(filename
);
1232 int argcount
= sizeof(rrd_def_storage
)/sizeof(void*) - 1;
1233 create_rrd_file(filename
, argcount
, rrd_def_storage
);
1240 const char *dp
= skip
? rrd_skip_data(data
, skip
) : data
;
1242 const char *update_args
[] = { dp
, NULL
};
1246 if ((status
= rrdc_update(filename
, 1, update_args
)) != 0) {
1247 cfs_message("RRDC update error %s: %d", filename
, status
);
1250 if (rrd_update_r(filename
, NULL
, 1, update_args
) != 0) {
1251 cfs_message("RRD update error %s: %s", filename
, rrd_get_error());
1257 if (rrd_update_r(filename
, NULL
, 1, update_args
) != 0) {
1258 cfs_message("RRD update error %s: %s", filename
, rrd_get_error());
1269 cfs_critical("RRD update error: unknown/wrong key %s", key
);
1279 rrdentry_t
*entry
= (rrdentry_t
*)value
;
1280 uint32_t ctime
= GPOINTER_TO_UINT(user_data
);
1282 int diff
= ctime
- entry
->time
;
1284 /* remove everything older than 5 minutes */
1287 return (diff
> expire
) ? TRUE
: FALSE
;
1290 static char *rrd_dump_buf
= NULL
;
1291 static time_t rrd_dump_last
= 0;
1294 cfs_rrd_dump(GString
*str
)
1298 g_mutex_lock (&mutex
);
1301 if (rrd_dump_buf
&& (ctime
- rrd_dump_last
) < 2) {
1302 g_string_assign(str
, rrd_dump_buf
);
1303 g_mutex_unlock (&mutex
);
1307 /* remove old data */
1308 g_hash_table_foreach_remove(cfs_status
.rrdhash
, rrd_entry_is_old
,
1309 GUINT_TO_POINTER(ctime
));
1311 g_string_set_size(str
, 0);
1313 GHashTableIter iter
;
1314 gpointer key
, value
;
1316 g_hash_table_iter_init (&iter
, cfs_status
.rrdhash
);
1318 while (g_hash_table_iter_next (&iter
, &key
, &value
)) {
1319 rrdentry_t
*entry
= (rrdentry_t
*)value
;
1320 g_string_append(str
, key
);
1321 g_string_append(str
, ":");
1322 g_string_append(str
, entry
->data
);
1323 g_string_append(str
, "\n");
1326 g_string_append_c(str
, 0); // never return undef
1328 rrd_dump_last
= ctime
;
1330 g_free(rrd_dump_buf
);
1331 rrd_dump_buf
= g_strdup(str
->str
);
1333 g_mutex_unlock (&mutex
);
1339 const char *nodename
,
1343 g_return_val_if_fail(iphash
!= NULL
, FALSE
);
1344 g_return_val_if_fail(nodename
!= NULL
, FALSE
);
1345 g_return_val_if_fail(ip
!= NULL
, FALSE
);
1346 g_return_val_if_fail(len
> 0, FALSE
);
1347 g_return_val_if_fail(len
< 256, FALSE
);
1348 g_return_val_if_fail(ip
[len
-1] == 0, FALSE
);
1350 char *oldip
= (char *)g_hash_table_lookup(iphash
, nodename
);
1352 if (!oldip
|| (strcmp(oldip
, ip
) != 0)) {
1353 cfs_status
.clinfo_version
++;
1354 g_hash_table_replace(iphash
, g_strdup(nodename
), g_strdup(ip
));
1362 GHashTable
*rrdhash
,
1367 g_return_val_if_fail(rrdhash
!= NULL
, FALSE
);
1368 g_return_val_if_fail(key
!= NULL
, FALSE
);
1369 g_return_val_if_fail(data
!= NULL
, FALSE
);
1370 g_return_val_if_fail(len
> 0, FALSE
);
1371 g_return_val_if_fail(len
< 4096, FALSE
);
1372 g_return_val_if_fail(data
[len
-1] == 0, FALSE
);
1375 if ((entry
= (rrdentry_t
*)g_hash_table_lookup(rrdhash
, key
))) {
1376 g_free(entry
->data
);
1377 entry
->data
= g_memdup(data
, len
);
1379 entry
->time
= time(NULL
);
1381 rrdentry_t
*entry
= g_new0(rrdentry_t
, 1);
1383 entry
->key
= g_strdup(key
);
1384 entry
->data
= g_memdup(data
, len
);
1386 entry
->time
= time(NULL
);
1388 g_hash_table_replace(rrdhash
, entry
->key
, entry
);
1391 update_rrd_data(key
, data
, len
);
1397 kvstore_send_update_message(
1403 if (!dfsm_is_initialized(dfsm
))
1406 struct iovec iov
[2];
1409 g_strlcpy(name
, key
, sizeof(name
));
1411 iov
[0].iov_base
= &name
;
1412 iov
[0].iov_len
= sizeof(name
);
1414 iov
[1].iov_base
= (char *)data
;
1415 iov
[1].iov_len
= len
;
1417 if (dfsm_send_message(dfsm
, KVSTORE_MESSAGE_UPDATE
, iov
, 2) == CS_OK
)
1423 static clog_entry_t
*
1424 kvstore_parse_log_message(
1428 g_return_val_if_fail(msg
!= NULL
, NULL
);
1430 if (msg_len
< sizeof(clog_entry_t
)) {
1431 cfs_critical("received short log message (%zu < %zu)", msg_len
, sizeof(clog_entry_t
));
1435 clog_entry_t
*entry
= (clog_entry_t
*)msg
;
1437 uint32_t size
= sizeof(clog_entry_t
) + entry
->node_len
+
1438 entry
->ident_len
+ entry
->tag_len
+ entry
->msg_len
;
1440 if (msg_len
!= size
) {
1441 cfs_critical("received log message with wrong size (%zu != %u)", msg_len
, size
);
1445 char *msgptr
= entry
->data
;
1447 if (*((char *)msgptr
+ entry
->node_len
- 1)) {
1448 cfs_critical("unterminated string in log message");
1451 msgptr
+= entry
->node_len
;
1453 if (*((char *)msgptr
+ entry
->ident_len
- 1)) {
1454 cfs_critical("unterminated string in log message");
1457 msgptr
+= entry
->ident_len
;
1459 if (*((char *)msgptr
+ entry
->tag_len
- 1)) {
1460 cfs_critical("unterminated string in log message");
1463 msgptr
+= entry
->tag_len
;
1465 if (*((char *)msgptr
+ entry
->msg_len
- 1)) {
1466 cfs_critical("unterminated string in log message");
1474 kvstore_parse_update_message(
1478 gconstpointer
*data
,
1481 g_return_val_if_fail(msg
!= NULL
, FALSE
);
1482 g_return_val_if_fail(key
!= NULL
, FALSE
);
1483 g_return_val_if_fail(data
!= NULL
, FALSE
);
1484 g_return_val_if_fail(len
!= NULL
, FALSE
);
1486 if (msg_len
< 256) {
1487 cfs_critical("received short kvstore message (%zu < 256)", msg_len
);
1491 /* test if key is null terminated */
1493 for (i
= 0; i
< 256; i
++)
1494 if (((char *)msg
)[i
] == 0)
1501 *len
= msg_len
- 256;
1503 *data
= (char *) msg
+ 256;
1509 cfs_create_status_msg(
1511 const char *nodename
,
1514 g_return_val_if_fail(str
!= NULL
, -EINVAL
);
1515 g_return_val_if_fail(key
!= NULL
, -EINVAL
);
1519 GHashTable
*kvhash
= NULL
;
1521 g_mutex_lock (&mutex
);
1523 if (!nodename
|| !nodename
[0] || !strcmp(nodename
, cfs
.nodename
)) {
1524 kvhash
= cfs_status
.kvhash
;
1525 } else if (cfs_status
.clinfo
&& cfs_status
.clinfo
->nodes_byname
) {
1526 cfs_clnode_t
*clnode
;
1527 if ((clnode
= g_hash_table_lookup(cfs_status
.clinfo
->nodes_byname
, nodename
)))
1528 kvhash
= clnode
->kvhash
;
1532 if (kvhash
&& (entry
= (kventry_t
*)g_hash_table_lookup(kvhash
, key
))) {
1533 g_string_append_len(str
, entry
->data
, entry
->len
);
1537 g_mutex_unlock (&mutex
);
1548 g_return_val_if_fail(key
!= NULL
, FALSE
);
1549 g_return_val_if_fail(data
!= NULL
, FALSE
);
1550 g_return_val_if_fail(cfs_status
.kvhash
!= NULL
, FALSE
);
1552 if (len
> CFS_MAX_STATUS_SIZE
)
1555 g_mutex_lock (&mutex
);
1559 if (strncmp(key
, "rrd/", 4) == 0) {
1560 res
= rrdentry_hash_set(cfs_status
.rrdhash
, key
+ 4, data
, len
);
1561 } else if (!strcmp(key
, "nodeip")) {
1562 res
= nodeip_hash_set(cfs_status
.iphash
, cfs
.nodename
, data
, len
);
1564 res
= kventry_hash_set(cfs_status
.kvhash
, key
, data
, len
);
1566 g_mutex_unlock (&mutex
);
1568 if (cfs_status
.kvstore
)
1569 kvstore_send_update_message(cfs_status
.kvstore
, key
, data
, len
);
1571 return res
? 0 : -ENOMEM
;
1575 cfs_kvstore_node_set(
1581 g_return_val_if_fail(nodeid
!= 0, FALSE
);
1582 g_return_val_if_fail(key
!= NULL
, FALSE
);
1583 g_return_val_if_fail(data
!= NULL
, FALSE
);
1585 g_mutex_lock (&mutex
);
1587 if (!cfs_status
.clinfo
|| !cfs_status
.clinfo
->nodes_byid
)
1588 goto ret
; /* ignore */
1590 cfs_clnode_t
*clnode
= g_hash_table_lookup(cfs_status
.clinfo
->nodes_byid
, &nodeid
);
1592 goto ret
; /* ignore */
1594 cfs_debug("got node %d status update %s", nodeid
, key
);
1596 if (strncmp(key
, "rrd/", 4) == 0) {
1597 rrdentry_hash_set(cfs_status
.rrdhash
, key
+ 4, data
, len
);
1598 } else if (!strcmp(key
, "nodeip")) {
1599 nodeip_hash_set(cfs_status
.iphash
, clnode
->name
, data
, len
);
1601 if (!clnode
->kvhash
) {
1602 if (!(clnode
->kvhash
= kventry_hash_new())) {
1603 goto ret
; /*ignore */
1607 kventry_hash_set(clnode
->kvhash
, key
, data
, len
);
1611 g_mutex_unlock (&mutex
);
1617 cfs_kvstore_sync(void)
1619 g_return_val_if_fail(cfs_status
.kvhash
!= NULL
, FALSE
);
1620 g_return_val_if_fail(cfs_status
.kvstore
!= NULL
, FALSE
);
1622 gboolean res
= TRUE
;
1624 g_mutex_lock (&mutex
);
1626 GHashTable
*ht
= cfs_status
.kvhash
;
1627 GHashTableIter iter
;
1628 gpointer key
, value
;
1630 g_hash_table_iter_init (&iter
, ht
);
1632 while (g_hash_table_iter_next (&iter
, &key
, &value
)) {
1633 kventry_t
*entry
= (kventry_t
*)value
;
1634 kvstore_send_update_message(cfs_status
.kvstore
, entry
->key
, entry
->data
, entry
->len
);
1637 g_mutex_unlock (&mutex
);
1654 g_return_val_if_fail(dfsm
!= NULL
, -1);
1655 g_return_val_if_fail(msg
!= NULL
, -1);
1656 g_return_val_if_fail(res_ptr
!= NULL
, -1);
1658 /* ignore message for ourself */
1659 if (dfsm_nodeid_is_local(dfsm
, nodeid
, pid
))
1662 if (msg_type
== KVSTORE_MESSAGE_UPDATE
) {
1666 if (kvstore_parse_update_message(msg
, msg_len
, &key
, &data
, &len
)) {
1667 cfs_kvstore_node_set(nodeid
, key
, data
, len
);
1669 cfs_critical("cant parse update message");
1671 } else if (msg_type
== KVSTORE_MESSAGE_LOG
) {
1672 cfs_message("received log"); // fixme: remove
1673 const clog_entry_t
*entry
;
1674 if ((entry
= kvstore_parse_log_message(msg
, msg_len
))) {
1675 clusterlog_insert(cfs_status
.clusterlog
, entry
);
1677 cfs_critical("cant parse log message");
1680 cfs_critical("received unknown message type %d\n", msg_type
);
1697 const struct cpg_address
*member_list
,
1698 size_t member_list_entries
)
1700 g_return_if_fail(dfsm
!= NULL
);
1701 g_return_if_fail(member_list
!= NULL
);
1703 cfs_debug("enter %s", __func__
);
1705 g_mutex_lock (&mutex
);
1707 cfs_clinfo_t
*clinfo
= cfs_status
.clinfo
;
1709 if (clinfo
&& clinfo
->nodes_byid
) {
1711 GHashTable
*ht
= clinfo
->nodes_byid
;
1712 GHashTableIter iter
;
1713 gpointer key
, value
;
1715 g_hash_table_iter_init (&iter
, ht
);
1717 while (g_hash_table_iter_next (&iter
, &key
, &value
)) {
1718 cfs_clnode_t
*node
= (cfs_clnode_t
*)value
;
1719 node
->online
= FALSE
;
1722 for (int i
= 0; i
< member_list_entries
; i
++) {
1724 if ((node
= g_hash_table_lookup(clinfo
->nodes_byid
, &member_list
[i
].nodeid
))) {
1725 node
->online
= TRUE
;
1729 cfs_status
.clinfo_version
++;
1732 g_mutex_unlock (&mutex
);
1739 unsigned int *res_len
)
1741 g_return_val_if_fail(dfsm
!= NULL
, NULL
);
1743 gpointer msg
= clusterlog_get_state(cfs_status
.clusterlog
, res_len
);
1749 dfsm_process_update(
1752 dfsm_sync_info_t
*syncinfo
,
1758 cfs_critical("%s: received unexpected update message", __func__
);
1764 dfsm_process_state_update(
1767 dfsm_sync_info_t
*syncinfo
)
1769 g_return_val_if_fail(dfsm
!= NULL
, -1);
1770 g_return_val_if_fail(syncinfo
!= NULL
, -1);
1772 clog_base_t
*clog
[syncinfo
->node_count
];
1774 int local_index
= -1;
1775 for (int i
= 0; i
< syncinfo
->node_count
; i
++) {
1776 dfsm_node_info_t
*ni
= &syncinfo
->nodes
[i
];
1779 if (syncinfo
->local
== ni
)
1782 clog_base_t
*base
= (clog_base_t
*)ni
->state
;
1783 if (ni
->state_len
> 8 && ni
->state_len
== clog_size(base
)) {
1784 clog
[i
] = ni
->state
;
1786 cfs_critical("received log with wrong size %u", ni
->state_len
);
1791 if (!clusterlog_merge(cfs_status
.clusterlog
, clog
, syncinfo
->node_count
, local_index
)) {
1792 cfs_critical("unable to merge log files");
1804 dfsm_sync_info_t
*syncinfo
)
1806 g_return_val_if_fail(dfsm
!= NULL
, -1);
1807 g_return_val_if_fail(syncinfo
!= NULL
, -1);
1813 dfsm_synced(dfsm_t
*dfsm
)
1815 g_return_if_fail(dfsm
!= NULL
);
1817 char *ip
= (char *)g_hash_table_lookup(cfs_status
.iphash
, cfs
.nodename
);
1821 cfs_status_set("nodeip", ip
, strlen(ip
) + 1);
1828 dfsm_sync_info_t
*syncinfo
)
1833 static dfsm_callbacks_t kvstore_dfsm_callbacks
= {
1834 .dfsm_deliver_fn
= dfsm_deliver
,
1835 .dfsm_confchg_fn
= dfsm_confchg
,
1837 .dfsm_get_state_fn
= dfsm_get_state
,
1838 .dfsm_process_state_update_fn
= dfsm_process_state_update
,
1839 .dfsm_process_update_fn
= dfsm_process_update
,
1840 .dfsm_commit_fn
= dfsm_commit
,
1841 .dfsm_cleanup_fn
= dfsm_cleanup
,
1842 .dfsm_synced_fn
= dfsm_synced
,
1846 cfs_status_dfsm_new(void)
1848 g_mutex_lock (&mutex
);
1850 cfs_status
.kvstore
= dfsm_new(NULL
, KVSTORE_CPG_GROUP_NAME
, G_LOG_DOMAIN
,
1851 0, &kvstore_dfsm_callbacks
);
1852 g_mutex_unlock (&mutex
);
1854 return cfs_status
.kvstore
;
1858 cfs_is_quorate(void)
1860 g_mutex_lock (&mutex
);
1861 gboolean res
= cfs_status
.quorate
;
1862 g_mutex_unlock (&mutex
);
1872 g_mutex_lock (&mutex
);
1874 uint32_t prev_quorate
= cfs_status
.quorate
;
1875 cfs_status
.quorate
= quorate
;
1877 if (!prev_quorate
&& cfs_status
.quorate
) {
1879 cfs_message("node has quorum");
1882 if (prev_quorate
&& !cfs_status
.quorate
) {
1884 cfs_message("node lost quorum");
1887 g_mutex_unlock (&mutex
);