diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-06-03 17:01:24 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-06-03 17:01:24 +0000 |
commit | 6dd3dfb79125cd02d02efbce435a6c82e5af92ef (patch) | |
tree | 45084fc83278586f6bbafcb935f92d53f71a6b03 /test/testquorum.c | |
parent | Initial commit. (diff) | |
download | corosync-upstream.tar.xz corosync-upstream.zip |
Adding upstream version 3.1.8.upstream/3.1.8upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'test/testquorum.c')
-rw-r--r-- | test/testquorum.c | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/test/testquorum.c b/test/testquorum.c new file mode 100644 index 0000000..1323b25 --- /dev/null +++ b/test/testquorum.c @@ -0,0 +1,64 @@ +#include <config.h> + +#include <sys/types.h> +#include <stdio.h> +#include <inttypes.h> +#include <stdint.h> +#include <stdlib.h> +#include <unistd.h> +#include <corosync/corotypes.h> +#include <corosync/quorum.h> + +static quorum_handle_t g_handle; + +static void quorum_notification_fn( + quorum_handle_t handle, + uint32_t quorate, + uint64_t ring_id, + uint32_t view_list_entries, + uint32_t *view_list) +{ + int i; + + printf("quorum notification called \n"); + printf(" quorate = %lu\n", (long unsigned int) quorate); + printf(" ring id = " CS_PRI_RING_ID_SEQ "\n", ring_id); + printf(" num nodes = %lu ", (long unsigned int) view_list_entries); + + for (i=0; i<view_list_entries; i++) { + printf(" " CS_PRI_NODE_ID, view_list[i]); + } + printf("\n"); +} + + +int main(int argc, char *argv[]) +{ + int quorate; + quorum_callbacks_t callbacks; + uint32_t quorum_type; + int err; + + callbacks.quorum_notify_fn = quorum_notification_fn; + if ( (err=quorum_initialize(&g_handle, &callbacks, &quorum_type)) != CS_OK) + fprintf(stderr, "quorum_initialize FAILED: %d\n", err); + + if ( (err=quorum_trackstart(g_handle, CS_TRACK_CHANGES)) != CS_OK) + fprintf(stderr, "quorum_trackstart FAILED: %d\n", err); + + if ( (err=quorum_getquorate(g_handle, &quorate)) != CS_OK) + fprintf(stderr, "quorum_getquorate FAILED: %d\n", err); + else { + printf("quorate %d\n", quorate); + } + + printf("Waiting for quorum events, press ^C to finish\n"); + printf("-------------------\n"); + + if (quorum_dispatch(g_handle, CS_DISPATCH_BLOCKING) != CS_OK) { + fprintf(stderr, "Error from quorum_dispatch\n"); + return -1; + } + + return 0; +} |