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/acme/plugins.cfg" },
87 { .path
= "priv/tfa.cfg" },
88 { .path
= "priv/token.cfg" },
89 { .path
= "datacenter.cfg" },
90 { .path
= "vzdump.cron" },
91 { .path
= "ha/crm_commands" },
92 { .path
= "ha/manager_status" },
93 { .path
= "ha/resources.cfg" },
94 { .path
= "ha/groups.cfg" },
95 { .path
= "ha/fence.cfg" },
96 { .path
= "status.cfg" },
97 { .path
= "replication.cfg" },
98 { .path
= "ceph.conf" },
99 { .path
= "sdn/vnets.cfg" },
100 { .path
= "sdn/zones.cfg" },
101 { .path
= "sdn/controllers.cfg" },
102 { .path
= "sdn/.version" },
103 { .path
= "virtual-guest/cpu-models.conf" },
113 cfs_clinfo_t
*clinfo
;
114 uint32_t clinfo_version
;
117 uint32_t vmlist_version
;
124 GHashTable
*memdb_changes
;
126 clusterlog_t
*clusterlog
;
129 static cfs_status_t cfs_status
;
141 uint32_t cman_version
;
143 GHashTable
*nodes_byid
;
144 GHashTable
*nodes_byname
;
148 g_int32_hash (gconstpointer v
)
150 return *(const uint32_t *) v
;
154 g_int32_equal (gconstpointer v1
,
157 return *((const uint32_t*) v1
) == *((const uint32_t*) v2
);
160 static void vminfo_free(vminfo_t
*vminfo
)
162 g_return_if_fail(vminfo
!= NULL
);
164 if (vminfo
->nodename
)
165 g_free(vminfo
->nodename
);
171 static const char *vminfo_type_to_string(vminfo_t
*vminfo
)
173 if (vminfo
->vmtype
== VMTYPE_QEMU
) {
175 } else if (vminfo
->vmtype
== VMTYPE_OPENVZ
) {
177 } else if (vminfo
->vmtype
== VMTYPE_LXC
) {
184 static const char *vminfo_type_to_path_type(vminfo_t
*vminfo
)
186 if (vminfo
->vmtype
== VMTYPE_QEMU
) {
187 return "qemu-server"; // special case..
189 return vminfo_type_to_string(vminfo
);
193 int vminfo_to_path(vminfo_t
*vminfo
, GString
*path
)
195 g_return_val_if_fail(vminfo
!= NULL
, -1);
196 g_return_val_if_fail(path
!= NULL
, -1);
198 if (!vminfo
->nodename
)
201 const char *type
= vminfo_type_to_path_type(vminfo
);
202 g_string_printf(path
, "/nodes/%s/%s/%u.conf", vminfo
->nodename
, type
, vminfo
->vmid
);
207 void cfs_clnode_destroy(
208 cfs_clnode_t
*clnode
)
210 g_return_if_fail(clnode
!= NULL
);
213 g_hash_table_destroy(clnode
->kvhash
);
216 g_free(clnode
->name
);
221 cfs_clnode_t
*cfs_clnode_new(
226 g_return_val_if_fail(name
!= NULL
, NULL
);
228 cfs_clnode_t
*clnode
= g_new0(cfs_clnode_t
, 1);
232 clnode
->name
= g_strdup(name
);
233 clnode
->nodeid
= nodeid
;
234 clnode
->votes
= votes
;
239 gboolean
cfs_clinfo_destroy(
240 cfs_clinfo_t
*clinfo
)
242 g_return_val_if_fail(clinfo
!= NULL
, FALSE
);
244 if (clinfo
->cluster_name
)
245 g_free(clinfo
->cluster_name
);
247 if (clinfo
->nodes_byname
)
248 g_hash_table_destroy(clinfo
->nodes_byname
);
250 if (clinfo
->nodes_byid
)
251 g_hash_table_destroy(clinfo
->nodes_byid
);
258 cfs_clinfo_t
*cfs_clinfo_new(
259 const char *cluster_name
,
260 uint32_t cman_version
)
262 g_return_val_if_fail(cluster_name
!= NULL
, NULL
);
264 cfs_clinfo_t
*clinfo
= g_new0(cfs_clinfo_t
, 1);
268 clinfo
->cluster_name
= g_strdup(cluster_name
);
269 clinfo
->cman_version
= cman_version
;
271 if (!(clinfo
->nodes_byid
= g_hash_table_new_full(
272 g_int32_hash
, g_int32_equal
, NULL
,
273 (GDestroyNotify
)cfs_clnode_destroy
)))
276 if (!(clinfo
->nodes_byname
= g_hash_table_new(g_str_hash
, g_str_equal
)))
282 cfs_clinfo_destroy(clinfo
);
287 gboolean
cfs_clinfo_add_node(
288 cfs_clinfo_t
*clinfo
,
289 cfs_clnode_t
*clnode
)
291 g_return_val_if_fail(clinfo
!= NULL
, FALSE
);
292 g_return_val_if_fail(clnode
!= NULL
, FALSE
);
294 g_hash_table_replace(clinfo
->nodes_byid
, &clnode
->nodeid
, clnode
);
295 g_hash_table_replace(clinfo
->nodes_byname
, clnode
->name
, clnode
);
301 cfs_create_memberlist_msg(
304 g_return_val_if_fail(str
!= NULL
, -EINVAL
);
306 g_mutex_lock (&mutex
);
308 g_string_append_printf(str
,"{\n");
312 cfs_clinfo_t
*clinfo
= cfs_status
.clinfo
;
314 if (clinfo
&& clinfo
->nodes_byid
)
315 nodecount
= g_hash_table_size(clinfo
->nodes_byid
);
318 g_string_append_printf(str
, "\"nodename\": \"%s\",\n", cfs
.nodename
);
319 g_string_append_printf(str
, "\"version\": %u,\n", cfs_status
.clinfo_version
);
321 g_string_append_printf(str
, "\"cluster\": { ");
322 g_string_append_printf(str
, "\"name\": \"%s\", \"version\": %d, "
323 "\"nodes\": %d, \"quorate\": %d ",
324 clinfo
->cluster_name
, clinfo
->cman_version
,
325 nodecount
, cfs_status
.quorate
);
327 g_string_append_printf(str
,"},\n");
328 g_string_append_printf(str
,"\"nodelist\": {\n");
330 GHashTable
*ht
= clinfo
->nodes_byid
;
334 g_hash_table_iter_init (&iter
, ht
);
337 while (g_hash_table_iter_next (&iter
, &key
, &value
)) {
338 cfs_clnode_t
*node
= (cfs_clnode_t
*)value
;
339 if (i
) g_string_append_printf(str
, ",\n");
342 g_string_append_printf(str
, " \"%s\": { \"id\": %d, \"online\": %d",
343 node
->name
, node
->nodeid
, node
->online
);
346 char *ip
= (char *)g_hash_table_lookup(cfs_status
.iphash
, node
->name
);
348 g_string_append_printf(str
, ", \"ip\": \"%s\"", ip
);
351 g_string_append_printf(str
, "}");
354 g_string_append_printf(str
,"\n }\n");
356 g_string_append_printf(str
, "\"nodename\": \"%s\",\n", cfs
.nodename
);
357 g_string_append_printf(str
, "\"version\": %u\n", cfs_status
.clinfo_version
);
360 g_string_append_printf(str
,"}\n");
362 g_mutex_unlock (&mutex
);
368 kventry_free(kventry_t
*entry
)
370 g_return_if_fail(entry
!= NULL
);
378 kventry_hash_new(void)
380 return g_hash_table_new_full(g_str_hash
, g_str_equal
, NULL
,
381 (GDestroyNotify
)kventry_free
);
385 rrdentry_free(rrdentry_t
*entry
)
387 g_return_if_fail(entry
!= NULL
);
395 rrdentry_hash_new(void)
397 return g_hash_table_new_full(g_str_hash
, g_str_equal
, NULL
,
398 (GDestroyNotify
)rrdentry_free
);
402 cfs_cluster_log_dump(GString
*str
, const char *user
, guint max_entries
)
404 clusterlog_dump(cfs_status
.clusterlog
, str
, user
, max_entries
);
408 cfs_cluster_log(clog_entry_t
*entry
)
410 g_return_if_fail(entry
!= NULL
);
412 clusterlog_insert(cfs_status
.clusterlog
, entry
);
414 if (cfs_status
.kvstore
) {
416 iov
[0].iov_base
= (char *)entry
;
417 iov
[0].iov_len
= clog_entry_size(entry
);
419 if (dfsm_is_initialized(cfs_status
.kvstore
))
420 dfsm_send_message(cfs_status
.kvstore
, KVSTORE_MESSAGE_LOG
, iov
, 1);
424 void cfs_status_init(void)
426 g_mutex_lock (&mutex
);
428 cfs_status
.start_time
= time(NULL
);
430 cfs_status
.vmlist
= vmlist_hash_new();
432 cfs_status
.kvhash
= kventry_hash_new();
434 cfs_status
.rrdhash
= rrdentry_hash_new();
436 cfs_status
.iphash
= g_hash_table_new_full(g_str_hash
, g_str_equal
, g_free
, g_free
);
438 cfs_status
.memdb_changes
= g_hash_table_new(g_str_hash
, g_str_equal
);
440 for (int i
= 0; i
< G_N_ELEMENTS(memdb_change_array
); i
++) {
441 g_hash_table_replace(cfs_status
.memdb_changes
,
442 memdb_change_array
[i
].path
,
443 &memdb_change_array
[i
]);
446 cfs_status
.clusterlog
= clusterlog_new();
449 clusterlog_add(cfs_status
.clusterlog
, "root", "cluster", getpid(),
450 LOG_INFO
, "starting cluster log");
452 g_mutex_unlock (&mutex
);
455 void cfs_status_cleanup(void)
457 g_mutex_lock (&mutex
);
459 cfs_status
.clinfo_version
++;
461 if (cfs_status
.clinfo
) {
462 cfs_clinfo_destroy(cfs_status
.clinfo
);
463 cfs_status
.clinfo
= NULL
;
466 if (cfs_status
.vmlist
) {
467 g_hash_table_destroy(cfs_status
.vmlist
);
468 cfs_status
.vmlist
= NULL
;
471 if (cfs_status
.kvhash
) {
472 g_hash_table_destroy(cfs_status
.kvhash
);
473 cfs_status
.kvhash
= NULL
;
476 if (cfs_status
.rrdhash
) {
477 g_hash_table_destroy(cfs_status
.rrdhash
);
478 cfs_status
.rrdhash
= NULL
;
481 if (cfs_status
.iphash
) {
482 g_hash_table_destroy(cfs_status
.iphash
);
483 cfs_status
.iphash
= NULL
;
486 if (cfs_status
.clusterlog
)
487 clusterlog_destroy(cfs_status
.clusterlog
);
489 g_mutex_unlock (&mutex
);
492 void cfs_status_set_clinfo(
493 cfs_clinfo_t
*clinfo
)
495 g_return_if_fail(clinfo
!= NULL
);
497 g_mutex_lock (&mutex
);
499 cfs_status
.clinfo_version
++;
501 cfs_clinfo_t
*old
= cfs_status
.clinfo
;
503 cfs_status
.clinfo
= clinfo
;
505 cfs_message("update cluster info (cluster name %s, version = %d)",
506 clinfo
->cluster_name
, clinfo
->cman_version
);
509 if (old
&& old
->nodes_byid
&& clinfo
->nodes_byid
) {
511 GHashTable
*ht
= clinfo
->nodes_byid
;
515 g_hash_table_iter_init (&iter
, ht
);
517 while (g_hash_table_iter_next (&iter
, &key
, &value
)) {
518 cfs_clnode_t
*node
= (cfs_clnode_t
*)value
;
519 cfs_clnode_t
*oldnode
;
520 if ((oldnode
= g_hash_table_lookup(old
->nodes_byid
, key
))) {
521 node
->online
= oldnode
->online
;
522 node
->kvhash
= oldnode
->kvhash
;
523 oldnode
->kvhash
= NULL
;
530 cfs_clinfo_destroy(old
);
533 g_mutex_unlock (&mutex
);
537 dump_kvstore_versions(
540 const char *nodename
)
542 g_return_if_fail(kvhash
!= NULL
);
543 g_return_if_fail(str
!= NULL
);
544 g_return_if_fail(nodename
!= NULL
);
546 GHashTable
*ht
= kvhash
;
550 g_string_append_printf(str
, "\"%s\": {\n", nodename
);
552 g_hash_table_iter_init (&iter
, ht
);
555 while (g_hash_table_iter_next (&iter
, &key
, &value
)) {
556 kventry_t
*entry
= (kventry_t
*)value
;
557 if (i
) g_string_append_printf(str
, ",\n");
559 g_string_append_printf(str
,"\"%s\": %u", entry
->key
, entry
->version
);
562 g_string_append_printf(str
, "}\n");
566 cfs_create_version_msg(GString
*str
)
568 g_return_val_if_fail(str
!= NULL
, -EINVAL
);
570 g_mutex_lock (&mutex
);
572 g_string_append_printf(str
,"{\n");
574 g_string_append_printf(str
, "\"starttime\": %lu,\n", (unsigned long)cfs_status
.start_time
);
576 g_string_append_printf(str
, "\"clinfo\": %u,\n", cfs_status
.clinfo_version
);
578 g_string_append_printf(str
, "\"vmlist\": %u,\n", cfs_status
.vmlist_version
);
580 for (int i
= 0; i
< G_N_ELEMENTS(memdb_change_array
); i
++) {
581 g_string_append_printf(str
, "\"%s\": %u,\n",
582 memdb_change_array
[i
].path
,
583 memdb_change_array
[i
].version
);
586 g_string_append_printf(str
, "\"kvstore\": {\n");
588 dump_kvstore_versions(str
, cfs_status
.kvhash
, cfs
.nodename
);
590 cfs_clinfo_t
*clinfo
= cfs_status
.clinfo
;
592 if (clinfo
&& clinfo
->nodes_byid
) {
593 GHashTable
*ht
= clinfo
->nodes_byid
;
597 g_hash_table_iter_init (&iter
, ht
);
599 while (g_hash_table_iter_next (&iter
, &key
, &value
)) {
600 cfs_clnode_t
*node
= (cfs_clnode_t
*)value
;
603 g_string_append_printf(str
, ",\n");
604 dump_kvstore_versions(str
, node
->kvhash
, node
->name
);
608 g_string_append_printf(str
,"}\n");
610 g_string_append_printf(str
,"}\n");
612 g_mutex_unlock (&mutex
);
618 vmlist_hash_new(void)
620 return g_hash_table_new_full(g_int_hash
, g_int_equal
, NULL
,
621 (GDestroyNotify
)vminfo_free
);
625 vmlist_hash_insert_vm(
629 const char *nodename
,
632 g_return_val_if_fail(vmlist
!= NULL
, FALSE
);
633 g_return_val_if_fail(nodename
!= NULL
, FALSE
);
634 g_return_val_if_fail(vmid
!= 0, FALSE
);
635 g_return_val_if_fail(vmtype
== VMTYPE_QEMU
|| vmtype
== VMTYPE_OPENVZ
||
636 vmtype
== VMTYPE_LXC
, FALSE
);
638 if (!replace
&& g_hash_table_lookup(vmlist
, &vmid
)) {
639 cfs_critical("detected duplicate VMID %d", vmid
);
643 vminfo_t
*vminfo
= g_new0(vminfo_t
, 1);
646 vminfo
->vmtype
= vmtype
;
647 vminfo
->nodename
= g_strdup(nodename
);
649 vminfo
->version
= ++vminfo_version_counter
;
651 g_hash_table_replace(vmlist
, &vminfo
->vmid
, vminfo
);
660 const char *nodename
)
662 g_return_if_fail(cfs_status
.vmlist
!= NULL
);
663 g_return_if_fail(nodename
!= NULL
);
664 g_return_if_fail(vmid
!= 0);
665 g_return_if_fail(vmtype
== VMTYPE_QEMU
|| vmtype
== VMTYPE_OPENVZ
||
666 vmtype
== VMTYPE_LXC
);
668 cfs_debug("vmlist_register_vm: %s/%u %d", nodename
, vmid
, vmtype
);
670 g_mutex_lock (&mutex
);
672 cfs_status
.vmlist_version
++;
674 vmlist_hash_insert_vm(cfs_status
.vmlist
, vmtype
, vmid
, nodename
, TRUE
);
676 g_mutex_unlock (&mutex
);
680 vmlist_different_vm_exists(
683 const char *nodename
)
685 g_return_val_if_fail(cfs_status
.vmlist
!= NULL
, FALSE
);
686 g_return_val_if_fail(vmid
!= 0, FALSE
);
688 gboolean res
= FALSE
;
690 g_mutex_lock (&mutex
);
693 if ((vminfo
= (vminfo_t
*)g_hash_table_lookup(cfs_status
.vmlist
, &vmid
))) {
694 if (!(vminfo
->vmtype
== vmtype
&& strcmp(vminfo
->nodename
, nodename
) == 0))
697 g_mutex_unlock (&mutex
);
706 g_return_val_if_fail(cfs_status
.vmlist
!= NULL
, FALSE
);
707 g_return_val_if_fail(vmid
!= 0, FALSE
);
709 g_mutex_lock (&mutex
);
711 gpointer res
= g_hash_table_lookup(cfs_status
.vmlist
, &vmid
);
713 g_mutex_unlock (&mutex
);
722 g_return_if_fail(cfs_status
.vmlist
!= NULL
);
723 g_return_if_fail(vmid
!= 0);
725 g_mutex_lock (&mutex
);
727 cfs_status
.vmlist_version
++;
729 g_hash_table_remove(cfs_status
.vmlist
, &vmid
);
731 g_mutex_unlock (&mutex
);
734 void cfs_status_set_vmlist(
737 g_return_if_fail(vmlist
!= NULL
);
739 g_mutex_lock (&mutex
);
741 cfs_status
.vmlist_version
++;
743 if (cfs_status
.vmlist
)
744 g_hash_table_destroy(cfs_status
.vmlist
);
746 cfs_status
.vmlist
= vmlist
;
748 g_mutex_unlock (&mutex
);
752 cfs_create_vmlist_msg(GString
*str
)
754 g_return_val_if_fail(cfs_status
.vmlist
!= NULL
, -EINVAL
);
755 g_return_val_if_fail(str
!= NULL
, -EINVAL
);
757 g_mutex_lock (&mutex
);
759 g_string_append_printf(str
,"{\n");
761 GHashTable
*ht
= cfs_status
.vmlist
;
763 guint count
= g_hash_table_size(ht
);
766 g_string_append_printf(str
,"\"version\": %u\n", cfs_status
.vmlist_version
);
768 g_string_append_printf(str
,"\"version\": %u,\n", cfs_status
.vmlist_version
);
770 g_string_append_printf(str
,"\"ids\": {\n");
775 g_hash_table_iter_init (&iter
, ht
);
778 while (g_hash_table_iter_next (&iter
, &key
, &value
)) {
779 vminfo_t
*vminfo
= (vminfo_t
*)value
;
780 const char *type
= vminfo_type_to_string(vminfo
);
783 g_string_append_printf(str
, ",\n");
786 g_string_append_printf(str
,"\"%u\": { \"node\": \"%s\", \"type\": \"%s\", \"version\": %u }",
787 vminfo
->vmid
, vminfo
->nodename
, type
, vminfo
->version
);
790 g_string_append_printf(str
,"}\n");
792 g_string_append_printf(str
,"\n}\n");
794 g_mutex_unlock (&mutex
);
799 // checks the conf for a line starting with '$prop:' and returns the value
800 // afterwards, whitout initial whitespace(s), we only deal with the format
801 // restricion imposed by our perl VM config parser, main reference is
802 // PVE::QemuServer::parse_vm_config this allows to be very fast and still
804 // main restrictions used for our advantage is the properties match reges:
805 // ($line =~ m/^([a-z][a-z_]*\d*):\s*(.+?)\s*$/) from parse_vm_config
806 // currently we only look at the current configuration in place, i.e., *no*
807 // snapshort and *no* pending changes
809 _get_property_value(char *conf
, int conf_size
, const char *prop
, int prop_len
)
811 const char *const conf_end
= conf
+ conf_size
;
813 size_t remaining_size
;
815 char *next_newline
= memchr(conf
, '\n', conf_size
);
816 if (next_newline
== NULL
) {
817 return NULL
; // valid property lines end with \n, but none in the config
819 *next_newline
= '\0';
821 while (line
!= NULL
) {
822 if (!line
[0]) goto next
;
824 // snapshot or pending section start, but nothing found yet -> not found
825 if (line
[0] == '[') return NULL
;
826 // properties start with /^[a-z]/, so continue early if not
827 if (line
[0] < 'a' || line
[0] > 'z') goto next
;
829 int line_len
= strlen(line
);
830 if (line_len
<= prop_len
+ 1) goto next
;
832 if (line
[prop_len
] == ':' && memcmp(line
, prop
, prop_len
) == 0) { // found
833 char *v_start
= &line
[prop_len
+ 1];
835 // drop initial value whitespaces here already
836 while (*v_start
&& isspace(*v_start
)) v_start
++;
838 if (!*v_start
) return NULL
;
840 char *v_end
= &line
[line_len
- 1];
841 while (v_end
> v_start
&& isspace(*v_end
)) v_end
--;
847 line
= next_newline
+ 1;
848 remaining_size
= conf_end
- line
;
849 if (remaining_size
<= prop_len
) {
852 next_newline
= memchr(line
, '\n', remaining_size
);
853 if (next_newline
== NULL
) {
854 return NULL
; // valid property lines end with \n, but none in the config
856 *next_newline
= '\0';
859 return NULL
; // not found
863 _g_str_append_kv_jsonescaped(GString
*str
, const char *k
, const char *v
)
865 g_string_append_printf(str
, "\"%s\": \"", k
);
868 if (*v
== '\\' || *v
== '"') {
869 g_string_append_c(str
, '\\');
871 g_string_append_c(str
, *v
);
874 g_string_append_c(str
, '"');
878 cfs_create_guest_conf_property_msg(GString
*str
, memdb_t
*memdb
, const char *prop
, uint32_t vmid
)
880 g_return_val_if_fail(cfs_status
.vmlist
!= NULL
, -EINVAL
);
881 g_return_val_if_fail(str
!= NULL
, -EINVAL
);
883 int prop_len
= strlen(prop
);
885 GString
*path
= NULL
;
887 // Prelock &memdb->mutex in order to enable the usage of memdb_read_nolock
888 // to prevent Deadlocks as in #2553
889 g_mutex_lock (&memdb
->mutex
);
890 g_mutex_lock (&mutex
);
892 g_string_printf(str
,"{\n");
894 GHashTable
*ht
= cfs_status
.vmlist
;
896 if (!g_hash_table_size(ht
)) {
900 path
= g_string_sized_new(256);
902 vminfo_t
*vminfo
= (vminfo_t
*) g_hash_table_lookup(cfs_status
.vmlist
, &vmid
);
903 if (vminfo
== NULL
) goto enoent
;
905 if (!vminfo_to_path(vminfo
, path
)) goto err
;
907 // use memdb_read_nolock because lock is handled here
908 int size
= memdb_read_nolock(memdb
, path
->str
, &tmp
);
909 if (tmp
== NULL
) goto err
;
910 if (size
<= prop_len
) goto ret
;
912 char *val
= _get_property_value(tmp
, size
, prop
, prop_len
);
913 if (val
== NULL
) goto ret
;
915 g_string_append_printf(str
, "\"%u\":{", vmid
);
916 _g_str_append_kv_jsonescaped(str
, prop
, val
);
917 g_string_append_c(str
, '}');
921 g_hash_table_iter_init (&iter
, ht
);
925 while (g_hash_table_iter_next (&iter
, &key
, &value
)) {
926 vminfo_t
*vminfo
= (vminfo_t
*)value
;
928 if (!vminfo_to_path(vminfo
, path
)) goto err
;
930 g_free(tmp
); // no-op if already null
932 // use memdb_read_nolock because lock is handled here
933 int size
= memdb_read_nolock(memdb
, path
->str
, &tmp
);
934 if (tmp
== NULL
|| size
<= prop_len
) continue;
936 char *val
= _get_property_value(tmp
, size
, prop
, prop_len
);
937 if (val
== NULL
) continue;
939 if (!first
) g_string_append_printf(str
, ",\n");
942 g_string_append_printf(str
, "\"%u\":{", vminfo
->vmid
);
943 _g_str_append_kv_jsonescaped(str
, prop
, val
);
944 g_string_append_c(str
, '}');
950 g_string_free(path
, TRUE
);
952 g_string_append_printf(str
,"\n}\n");
953 g_mutex_unlock (&mutex
);
954 g_mutex_unlock (&memdb
->mutex
);
965 record_memdb_change(const char *path
)
967 g_return_if_fail(cfs_status
.memdb_changes
!= 0);
971 if ((ce
= (memdb_change_t
*)g_hash_table_lookup(cfs_status
.memdb_changes
, path
))) {
977 record_memdb_reload(void)
979 for (int i
= 0; i
< G_N_ELEMENTS(memdb_change_array
); i
++) {
980 memdb_change_array
[i
].version
++;
991 g_return_val_if_fail(kvhash
!= NULL
, FALSE
);
992 g_return_val_if_fail(key
!= NULL
, FALSE
);
993 g_return_val_if_fail(data
!= NULL
, FALSE
);
997 g_hash_table_remove(kvhash
, key
);
998 } else if ((entry
= (kventry_t
*)g_hash_table_lookup(kvhash
, key
))) {
1000 entry
->data
= g_memdup(data
, len
);
1004 kventry_t
*entry
= g_new0(kventry_t
, 1);
1006 entry
->key
= g_strdup(key
);
1007 entry
->data
= g_memdup(data
, len
);
1010 g_hash_table_replace(kvhash
, entry
->key
, entry
);
1016 static const char *rrd_def_node
[] = {
1017 "DS:loadavg:GAUGE:120:0:U",
1018 "DS:maxcpu:GAUGE:120:0:U",
1019 "DS:cpu:GAUGE:120:0:U",
1020 "DS:iowait:GAUGE:120:0:U",
1021 "DS:memtotal:GAUGE:120:0:U",
1022 "DS:memused:GAUGE:120:0:U",
1023 "DS:swaptotal:GAUGE:120:0:U",
1024 "DS:swapused:GAUGE:120:0:U",
1025 "DS:roottotal:GAUGE:120:0:U",
1026 "DS:rootused:GAUGE:120:0:U",
1027 "DS:netin:DERIVE:120:0:U",
1028 "DS:netout: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_vm
[] = {
1045 "DS:maxcpu:GAUGE:120:0:U",
1046 "DS:cpu:GAUGE:120:0:U",
1047 "DS:maxmem:GAUGE:120:0:U",
1048 "DS:mem:GAUGE:120:0:U",
1049 "DS:maxdisk:GAUGE:120:0:U",
1050 "DS:disk:GAUGE:120:0:U",
1051 "DS:netin:DERIVE:120:0:U",
1052 "DS:netout:DERIVE:120:0:U",
1053 "DS:diskread:DERIVE:120:0:U",
1054 "DS:diskwrite:DERIVE:120:0:U",
1056 "RRA:AVERAGE:0.5:1:70", // 1 min avg - one hour
1057 "RRA:AVERAGE:0.5:30:70", // 30 min avg - one day
1058 "RRA:AVERAGE:0.5:180:70", // 3 hour avg - one week
1059 "RRA:AVERAGE:0.5:720:70", // 12 hour avg - one month
1060 "RRA:AVERAGE:0.5:10080:70", // 7 day avg - ony year
1062 "RRA:MAX:0.5:1:70", // 1 min max - one hour
1063 "RRA:MAX:0.5:30:70", // 30 min max - one day
1064 "RRA:MAX:0.5:180:70", // 3 hour max - one week
1065 "RRA:MAX:0.5:720:70", // 12 hour max - one month
1066 "RRA:MAX:0.5:10080:70", // 7 day max - ony year
1070 static const char *rrd_def_storage
[] = {
1071 "DS:total:GAUGE:120:0:U",
1072 "DS:used:GAUGE:120:0:U",
1074 "RRA:AVERAGE:0.5:1:70", // 1 min avg - one hour
1075 "RRA:AVERAGE:0.5:30:70", // 30 min avg - one day
1076 "RRA:AVERAGE:0.5:180:70", // 3 hour avg - one week
1077 "RRA:AVERAGE:0.5:720:70", // 12 hour avg - one month
1078 "RRA:AVERAGE:0.5:10080:70", // 7 day avg - ony year
1080 "RRA:MAX:0.5:1:70", // 1 min max - one hour
1081 "RRA:MAX:0.5:30:70", // 30 min max - one day
1082 "RRA:MAX:0.5:180:70", // 3 hour max - one week
1083 "RRA:MAX:0.5:720:70", // 12 hour max - one month
1084 "RRA:MAX:0.5:10080:70", // 7 day max - ony year
1088 #define RRDDIR "/var/lib/rrdcached/db"
1092 const char *filename
,
1094 const char *rrddef
[])
1096 /* start at day boundary */
1099 struct tm
*ltm
= localtime(&ctime
);
1105 if (rrd_create_r(filename
, 60, timelocal(ltm
), argcount
, rrddef
)) {
1106 cfs_message("RRD create error %s: %s", filename
, rrd_get_error());
1110 static inline const char *
1116 while (*data
&& found
< count
) {
1129 g_return_if_fail(key
!= NULL
);
1130 g_return_if_fail(data
!= NULL
);
1131 g_return_if_fail(len
> 0);
1132 g_return_if_fail(len
< 4096);
1134 static const char *rrdcsock
= "unix:/var/run/rrdcached.sock";
1137 if (rrdc_connect(rrdcsock
) != 0)
1140 char *filename
= NULL
;
1144 if (strncmp(key
, "pve2-node/", 10) == 0) {
1145 const char *node
= key
+ 10;
1149 if (strchr(node
, '/') != NULL
)
1152 if (strlen(node
) < 1)
1155 filename
= g_strdup_printf(RRDDIR
"/%s", key
);
1157 if (!g_file_test(filename
, G_FILE_TEST_EXISTS
)) {
1159 mkdir(RRDDIR
"/pve2-node", 0755);
1160 int argcount
= sizeof(rrd_def_node
)/sizeof(void*) - 1;
1161 create_rrd_file(filename
, argcount
, rrd_def_node
);
1164 } else if ((strncmp(key
, "pve2-vm/", 8) == 0) ||
1165 (strncmp(key
, "pve2.3-vm/", 10) == 0)) {
1168 if (strncmp(key
, "pve2-vm/", 8) == 0) {
1176 if (strchr(vmid
, '/') != NULL
)
1179 if (strlen(vmid
) < 1)
1182 filename
= g_strdup_printf(RRDDIR
"/%s/%s", "pve2-vm", vmid
);
1184 if (!g_file_test(filename
, G_FILE_TEST_EXISTS
)) {
1186 mkdir(RRDDIR
"/pve2-vm", 0755);
1187 int argcount
= sizeof(rrd_def_vm
)/sizeof(void*) - 1;
1188 create_rrd_file(filename
, argcount
, rrd_def_vm
);
1191 } else if (strncmp(key
, "pve2-storage/", 13) == 0) {
1192 const char *node
= key
+ 13;
1194 const char *storage
= node
;
1195 while (*storage
&& *storage
!= '/')
1198 if (*storage
!= '/' || ((storage
- node
) < 1))
1203 if (strchr(storage
, '/') != NULL
)
1206 if (strlen(storage
) < 1)
1209 filename
= g_strdup_printf(RRDDIR
"/%s", key
);
1211 if (!g_file_test(filename
, G_FILE_TEST_EXISTS
)) {
1213 mkdir(RRDDIR
"/pve2-storage", 0755);
1215 char *dir
= g_path_get_dirname(filename
);
1219 int argcount
= sizeof(rrd_def_storage
)/sizeof(void*) - 1;
1220 create_rrd_file(filename
, argcount
, rrd_def_storage
);
1227 const char *dp
= skip
? rrd_skip_data(data
, skip
) : data
;
1229 const char *update_args
[] = { dp
, NULL
};
1233 if ((status
= rrdc_update(filename
, 1, update_args
)) != 0) {
1234 cfs_message("RRDC update error %s: %d", filename
, status
);
1237 if (rrd_update_r(filename
, NULL
, 1, update_args
) != 0) {
1238 cfs_message("RRD update error %s: %s", filename
, rrd_get_error());
1244 if (rrd_update_r(filename
, NULL
, 1, update_args
) != 0) {
1245 cfs_message("RRD update error %s: %s", filename
, rrd_get_error());
1256 cfs_critical("RRD update error: unknown/wrong key %s", key
);
1266 rrdentry_t
*entry
= (rrdentry_t
*)value
;
1267 uint32_t ctime
= GPOINTER_TO_UINT(user_data
);
1269 int diff
= ctime
- entry
->time
;
1271 /* remove everything older than 5 minutes */
1274 return (diff
> expire
) ? TRUE
: FALSE
;
1277 static char *rrd_dump_buf
= NULL
;
1278 static time_t rrd_dump_last
= 0;
1281 cfs_rrd_dump(GString
*str
)
1285 g_mutex_lock (&mutex
);
1288 if (rrd_dump_buf
&& (ctime
- rrd_dump_last
) < 2) {
1289 g_string_assign(str
, rrd_dump_buf
);
1290 g_mutex_unlock (&mutex
);
1294 /* remove old data */
1295 g_hash_table_foreach_remove(cfs_status
.rrdhash
, rrd_entry_is_old
,
1296 GUINT_TO_POINTER(ctime
));
1298 g_string_set_size(str
, 0);
1300 GHashTableIter iter
;
1301 gpointer key
, value
;
1303 g_hash_table_iter_init (&iter
, cfs_status
.rrdhash
);
1305 while (g_hash_table_iter_next (&iter
, &key
, &value
)) {
1306 rrdentry_t
*entry
= (rrdentry_t
*)value
;
1307 g_string_append(str
, key
);
1308 g_string_append(str
, ":");
1309 g_string_append(str
, entry
->data
);
1310 g_string_append(str
, "\n");
1313 g_string_append_c(str
, 0); // never return undef
1315 rrd_dump_last
= ctime
;
1317 g_free(rrd_dump_buf
);
1318 rrd_dump_buf
= g_strdup(str
->str
);
1320 g_mutex_unlock (&mutex
);
1326 const char *nodename
,
1330 g_return_val_if_fail(iphash
!= NULL
, FALSE
);
1331 g_return_val_if_fail(nodename
!= NULL
, FALSE
);
1332 g_return_val_if_fail(ip
!= NULL
, FALSE
);
1333 g_return_val_if_fail(len
> 0, FALSE
);
1334 g_return_val_if_fail(len
< 256, FALSE
);
1335 g_return_val_if_fail(ip
[len
-1] == 0, FALSE
);
1337 char *oldip
= (char *)g_hash_table_lookup(iphash
, nodename
);
1339 if (!oldip
|| (strcmp(oldip
, ip
) != 0)) {
1340 cfs_status
.clinfo_version
++;
1341 g_hash_table_replace(iphash
, g_strdup(nodename
), g_strdup(ip
));
1349 GHashTable
*rrdhash
,
1354 g_return_val_if_fail(rrdhash
!= NULL
, FALSE
);
1355 g_return_val_if_fail(key
!= NULL
, FALSE
);
1356 g_return_val_if_fail(data
!= NULL
, FALSE
);
1357 g_return_val_if_fail(len
> 0, FALSE
);
1358 g_return_val_if_fail(len
< 4096, FALSE
);
1359 g_return_val_if_fail(data
[len
-1] == 0, FALSE
);
1362 if ((entry
= (rrdentry_t
*)g_hash_table_lookup(rrdhash
, key
))) {
1363 g_free(entry
->data
);
1364 entry
->data
= g_memdup(data
, len
);
1366 entry
->time
= time(NULL
);
1368 rrdentry_t
*entry
= g_new0(rrdentry_t
, 1);
1370 entry
->key
= g_strdup(key
);
1371 entry
->data
= g_memdup(data
, len
);
1373 entry
->time
= time(NULL
);
1375 g_hash_table_replace(rrdhash
, entry
->key
, entry
);
1378 update_rrd_data(key
, data
, len
);
1384 kvstore_send_update_message(
1390 if (!dfsm_is_initialized(dfsm
))
1393 struct iovec iov
[2];
1396 g_strlcpy(name
, key
, sizeof(name
));
1398 iov
[0].iov_base
= &name
;
1399 iov
[0].iov_len
= sizeof(name
);
1401 iov
[1].iov_base
= (char *)data
;
1402 iov
[1].iov_len
= len
;
1404 if (dfsm_send_message(dfsm
, KVSTORE_MESSAGE_UPDATE
, iov
, 2) == CS_OK
)
1410 static clog_entry_t
*
1411 kvstore_parse_log_message(
1415 g_return_val_if_fail(msg
!= NULL
, NULL
);
1417 if (msg_len
< sizeof(clog_entry_t
)) {
1418 cfs_critical("received short log message (%zu < %zu)", msg_len
, sizeof(clog_entry_t
));
1422 clog_entry_t
*entry
= (clog_entry_t
*)msg
;
1424 uint32_t size
= sizeof(clog_entry_t
) + entry
->node_len
+
1425 entry
->ident_len
+ entry
->tag_len
+ entry
->msg_len
;
1427 if (msg_len
!= size
) {
1428 cfs_critical("received log message with wrong size (%zu != %u)", msg_len
, size
);
1432 char *msgptr
= entry
->data
;
1434 if (*((char *)msgptr
+ entry
->node_len
- 1)) {
1435 cfs_critical("unterminated string in log message");
1438 msgptr
+= entry
->node_len
;
1440 if (*((char *)msgptr
+ entry
->ident_len
- 1)) {
1441 cfs_critical("unterminated string in log message");
1444 msgptr
+= entry
->ident_len
;
1446 if (*((char *)msgptr
+ entry
->tag_len
- 1)) {
1447 cfs_critical("unterminated string in log message");
1450 msgptr
+= entry
->tag_len
;
1452 if (*((char *)msgptr
+ entry
->msg_len
- 1)) {
1453 cfs_critical("unterminated string in log message");
1461 kvstore_parse_update_message(
1465 gconstpointer
*data
,
1468 g_return_val_if_fail(msg
!= NULL
, FALSE
);
1469 g_return_val_if_fail(key
!= NULL
, FALSE
);
1470 g_return_val_if_fail(data
!= NULL
, FALSE
);
1471 g_return_val_if_fail(len
!= NULL
, FALSE
);
1473 if (msg_len
< 256) {
1474 cfs_critical("received short kvstore message (%zu < 256)", msg_len
);
1478 /* test if key is null terminated */
1480 for (i
= 0; i
< 256; i
++)
1481 if (((char *)msg
)[i
] == 0)
1488 *len
= msg_len
- 256;
1490 *data
= (char *) msg
+ 256;
1496 cfs_create_status_msg(
1498 const char *nodename
,
1501 g_return_val_if_fail(str
!= NULL
, -EINVAL
);
1502 g_return_val_if_fail(key
!= NULL
, -EINVAL
);
1506 GHashTable
*kvhash
= NULL
;
1508 g_mutex_lock (&mutex
);
1510 if (!nodename
|| !nodename
[0] || !strcmp(nodename
, cfs
.nodename
)) {
1511 kvhash
= cfs_status
.kvhash
;
1512 } else if (cfs_status
.clinfo
&& cfs_status
.clinfo
->nodes_byname
) {
1513 cfs_clnode_t
*clnode
;
1514 if ((clnode
= g_hash_table_lookup(cfs_status
.clinfo
->nodes_byname
, nodename
)))
1515 kvhash
= clnode
->kvhash
;
1519 if (kvhash
&& (entry
= (kventry_t
*)g_hash_table_lookup(kvhash
, key
))) {
1520 g_string_append_len(str
, entry
->data
, entry
->len
);
1524 g_mutex_unlock (&mutex
);
1535 g_return_val_if_fail(key
!= NULL
, FALSE
);
1536 g_return_val_if_fail(data
!= NULL
, FALSE
);
1537 g_return_val_if_fail(cfs_status
.kvhash
!= NULL
, FALSE
);
1539 if (len
> CFS_MAX_STATUS_SIZE
)
1542 g_mutex_lock (&mutex
);
1546 if (strncmp(key
, "rrd/", 4) == 0) {
1547 res
= rrdentry_hash_set(cfs_status
.rrdhash
, key
+ 4, data
, len
);
1548 } else if (!strcmp(key
, "nodeip")) {
1549 res
= nodeip_hash_set(cfs_status
.iphash
, cfs
.nodename
, data
, len
);
1551 res
= kventry_hash_set(cfs_status
.kvhash
, key
, data
, len
);
1553 g_mutex_unlock (&mutex
);
1555 if (cfs_status
.kvstore
)
1556 kvstore_send_update_message(cfs_status
.kvstore
, key
, data
, len
);
1558 return res
? 0 : -ENOMEM
;
1562 cfs_kvstore_node_set(
1568 g_return_val_if_fail(nodeid
!= 0, FALSE
);
1569 g_return_val_if_fail(key
!= NULL
, FALSE
);
1570 g_return_val_if_fail(data
!= NULL
, FALSE
);
1572 g_mutex_lock (&mutex
);
1574 if (!cfs_status
.clinfo
|| !cfs_status
.clinfo
->nodes_byid
)
1575 goto ret
; /* ignore */
1577 cfs_clnode_t
*clnode
= g_hash_table_lookup(cfs_status
.clinfo
->nodes_byid
, &nodeid
);
1579 goto ret
; /* ignore */
1581 cfs_debug("got node %d status update %s", nodeid
, key
);
1583 if (strncmp(key
, "rrd/", 4) == 0) {
1584 rrdentry_hash_set(cfs_status
.rrdhash
, key
+ 4, data
, len
);
1585 } else if (!strcmp(key
, "nodeip")) {
1586 nodeip_hash_set(cfs_status
.iphash
, clnode
->name
, data
, len
);
1588 if (!clnode
->kvhash
) {
1589 if (!(clnode
->kvhash
= kventry_hash_new())) {
1590 goto ret
; /*ignore */
1594 kventry_hash_set(clnode
->kvhash
, key
, data
, len
);
1598 g_mutex_unlock (&mutex
);
1604 cfs_kvstore_sync(void)
1606 g_return_val_if_fail(cfs_status
.kvhash
!= NULL
, FALSE
);
1607 g_return_val_if_fail(cfs_status
.kvstore
!= NULL
, FALSE
);
1609 gboolean res
= TRUE
;
1611 g_mutex_lock (&mutex
);
1613 GHashTable
*ht
= cfs_status
.kvhash
;
1614 GHashTableIter iter
;
1615 gpointer key
, value
;
1617 g_hash_table_iter_init (&iter
, ht
);
1619 while (g_hash_table_iter_next (&iter
, &key
, &value
)) {
1620 kventry_t
*entry
= (kventry_t
*)value
;
1621 kvstore_send_update_message(cfs_status
.kvstore
, entry
->key
, entry
->data
, entry
->len
);
1624 g_mutex_unlock (&mutex
);
1641 g_return_val_if_fail(dfsm
!= NULL
, -1);
1642 g_return_val_if_fail(msg
!= NULL
, -1);
1643 g_return_val_if_fail(res_ptr
!= NULL
, -1);
1645 /* ignore message for ourself */
1646 if (dfsm_nodeid_is_local(dfsm
, nodeid
, pid
))
1649 if (msg_type
== KVSTORE_MESSAGE_UPDATE
) {
1653 if (kvstore_parse_update_message(msg
, msg_len
, &key
, &data
, &len
)) {
1654 cfs_kvstore_node_set(nodeid
, key
, data
, len
);
1656 cfs_critical("cant parse update message");
1658 } else if (msg_type
== KVSTORE_MESSAGE_LOG
) {
1659 cfs_message("received log"); // fixme: remove
1660 const clog_entry_t
*entry
;
1661 if ((entry
= kvstore_parse_log_message(msg
, msg_len
))) {
1662 clusterlog_insert(cfs_status
.clusterlog
, entry
);
1664 cfs_critical("cant parse log message");
1667 cfs_critical("received unknown message type %d\n", msg_type
);
1684 const struct cpg_address
*member_list
,
1685 size_t member_list_entries
)
1687 g_return_if_fail(dfsm
!= NULL
);
1688 g_return_if_fail(member_list
!= NULL
);
1690 cfs_debug("enter %s", __func__
);
1692 g_mutex_lock (&mutex
);
1694 cfs_clinfo_t
*clinfo
= cfs_status
.clinfo
;
1696 if (clinfo
&& clinfo
->nodes_byid
) {
1698 GHashTable
*ht
= clinfo
->nodes_byid
;
1699 GHashTableIter iter
;
1700 gpointer key
, value
;
1702 g_hash_table_iter_init (&iter
, ht
);
1704 while (g_hash_table_iter_next (&iter
, &key
, &value
)) {
1705 cfs_clnode_t
*node
= (cfs_clnode_t
*)value
;
1706 node
->online
= FALSE
;
1709 for (int i
= 0; i
< member_list_entries
; i
++) {
1711 if ((node
= g_hash_table_lookup(clinfo
->nodes_byid
, &member_list
[i
].nodeid
))) {
1712 node
->online
= TRUE
;
1716 cfs_status
.clinfo_version
++;
1719 g_mutex_unlock (&mutex
);
1726 unsigned int *res_len
)
1728 g_return_val_if_fail(dfsm
!= NULL
, NULL
);
1730 gpointer msg
= clusterlog_get_state(cfs_status
.clusterlog
, res_len
);
1736 dfsm_process_update(
1739 dfsm_sync_info_t
*syncinfo
,
1745 cfs_critical("%s: received unexpected update message", __func__
);
1751 dfsm_process_state_update(
1754 dfsm_sync_info_t
*syncinfo
)
1756 g_return_val_if_fail(dfsm
!= NULL
, -1);
1757 g_return_val_if_fail(syncinfo
!= NULL
, -1);
1759 clog_base_t
*clog
[syncinfo
->node_count
];
1761 int local_index
= -1;
1762 for (int i
= 0; i
< syncinfo
->node_count
; i
++) {
1763 dfsm_node_info_t
*ni
= &syncinfo
->nodes
[i
];
1766 if (syncinfo
->local
== ni
)
1769 clog_base_t
*base
= (clog_base_t
*)ni
->state
;
1770 if (ni
->state_len
> 8 && ni
->state_len
== clog_size(base
)) {
1771 clog
[i
] = ni
->state
;
1773 cfs_critical("received log with wrong size %u", ni
->state_len
);
1778 if (!clusterlog_merge(cfs_status
.clusterlog
, clog
, syncinfo
->node_count
, local_index
)) {
1779 cfs_critical("unable to merge log files");
1791 dfsm_sync_info_t
*syncinfo
)
1793 g_return_val_if_fail(dfsm
!= NULL
, -1);
1794 g_return_val_if_fail(syncinfo
!= NULL
, -1);
1800 dfsm_synced(dfsm_t
*dfsm
)
1802 g_return_if_fail(dfsm
!= NULL
);
1804 char *ip
= (char *)g_hash_table_lookup(cfs_status
.iphash
, cfs
.nodename
);
1808 cfs_status_set("nodeip", ip
, strlen(ip
) + 1);
1815 dfsm_sync_info_t
*syncinfo
)
1820 static dfsm_callbacks_t kvstore_dfsm_callbacks
= {
1821 .dfsm_deliver_fn
= dfsm_deliver
,
1822 .dfsm_confchg_fn
= dfsm_confchg
,
1824 .dfsm_get_state_fn
= dfsm_get_state
,
1825 .dfsm_process_state_update_fn
= dfsm_process_state_update
,
1826 .dfsm_process_update_fn
= dfsm_process_update
,
1827 .dfsm_commit_fn
= dfsm_commit
,
1828 .dfsm_cleanup_fn
= dfsm_cleanup
,
1829 .dfsm_synced_fn
= dfsm_synced
,
1833 cfs_status_dfsm_new(void)
1835 g_mutex_lock (&mutex
);
1837 cfs_status
.kvstore
= dfsm_new(NULL
, KVSTORE_CPG_GROUP_NAME
, G_LOG_DOMAIN
,
1838 0, &kvstore_dfsm_callbacks
);
1839 g_mutex_unlock (&mutex
);
1841 return cfs_status
.kvstore
;
1845 cfs_is_quorate(void)
1847 g_mutex_lock (&mutex
);
1848 gboolean res
= cfs_status
.quorate
;
1849 g_mutex_unlock (&mutex
);
1859 g_mutex_lock (&mutex
);
1861 uint32_t prev_quorate
= cfs_status
.quorate
;
1862 cfs_status
.quorate
= quorate
;
1864 if (!prev_quorate
&& cfs_status
.quorate
) {
1866 cfs_message("node has quorum");
1869 if (prev_quorate
&& !cfs_status
.quorate
) {
1871 cfs_message("node lost quorum");
1874 g_mutex_unlock (&mutex
);