2 * Copyright (c) 2009 Red Hat, Inc.
6 * Author: Christine Caulfield (ccaulfie@redhat.com)
8 * This software licensed under BSD license, the text of which follows:
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions are met:
13 * - Redistributions of source code must retain the above copyright notice,
14 * this list of conditions and the following disclaimer.
15 * - Redistributions in binary form must reproduce the above copyright notice,
16 * this list of conditions and the following disclaimer in the documentation
17 * and/or other materials provided with the distribution.
18 * - Neither the name of the MontaVista Software, Inc. nor the names of its
19 * contributors may be used to endorse or promote products derived from this
20 * software without specific prior written permission.
22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTIBUTORS "AS IS"
23 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
26 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
27 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
28 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
29 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
30 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
32 * THE POSSIBILITY OF SUCH DAMAGE.
37 #include <sys/types.h>
44 #include <corosync/corotypes.h>
45 #include <corosync/votequorum.h>
47 static votequorum_handle_t g_handle
;
49 static const char *node_state(int state
)
52 case VOTEQUORUM_NODESTATE_MEMBER
:
55 case VOTEQUORUM_NODESTATE_DEAD
:
58 case VOTEQUORUM_NODESTATE_LEAVING
:
68 static void votequorum_expectedvotes_notification_fn(
69 votequorum_handle_t handle
,
71 uint32_t expected_votes
74 printf("votequorum expectedvotes notification called \n");
75 printf(" expected_votes = %d\n", expected_votes
);
79 static void votequorum_quorum_notification_fn(
80 votequorum_handle_t handle
,
83 uint32_t node_list_entries
,
84 votequorum_node_t node_list
[]
89 printf("votequorum quorum notification called \n");
90 printf(" number of nodes = %d\n", node_list_entries
);
91 printf(" quorate = %d\n", quorate
);
93 for (i
= 0; i
< node_list_entries
; i
++) {
94 printf(" " CS_PRI_NODE_ID
": %s\n", node_list
[i
].nodeid
, node_state(node_list
[i
].state
));
99 static void votequorum_nodelist_notification_fn(
100 votequorum_handle_t handle
,
102 votequorum_ring_id_t ring_id
,
103 uint32_t node_list_entries
,
109 printf("votequorum nodelist notification called \n");
110 printf(" number of nodes = %d\n", node_list_entries
);
111 printf(" current ringid = (" CS_PRI_RING_ID
")\n", ring_id
.nodeid
, ring_id
.seq
);
114 for (i
= 0; i
< node_list_entries
; i
++) {
115 printf(CS_PRI_NODE_ID
" ", node_list
[i
]);
121 int main(int argc
, char *argv
[])
123 struct votequorum_info info
;
124 votequorum_callbacks_t callbacks
;
127 if (argc
> 1 && strcmp(argv
[1], "-h")==0) {
128 fprintf(stderr
, "usage: %s [new-expected] [new-votes]\n", argv
[0]);
132 callbacks
.votequorum_quorum_notify_fn
= votequorum_quorum_notification_fn
;
133 callbacks
.votequorum_nodelist_notify_fn
= votequorum_nodelist_notification_fn
;
134 callbacks
.votequorum_expectedvotes_notify_fn
= votequorum_expectedvotes_notification_fn
;
136 if ( (err
=votequorum_initialize(&g_handle
, &callbacks
)) != CS_OK
)
137 fprintf(stderr
, "votequorum_initialize FAILED: %d\n", err
);
139 if ( (err
= votequorum_trackstart(g_handle
, g_handle
, CS_TRACK_CHANGES
)) != CS_OK
)
140 fprintf(stderr
, "votequorum_trackstart FAILED: %d\n", err
);
142 if ( (err
=votequorum_getinfo(g_handle
, 0, &info
)) != CS_OK
)
143 fprintf(stderr
, "votequorum_getinfo FAILED: %d\n", err
);
145 printf("node votes %d\n", info
.node_votes
);
146 printf("expected votes %d\n", info
.node_expected_votes
);
147 printf("highest expected %d\n", info
.highest_expected
);
148 printf("total votes %d\n", info
.total_votes
);
149 printf("quorum %d\n", info
.quorum
);
151 if (info
.flags
& VOTEQUORUM_INFO_TWONODE
) printf("2Node ");
152 if (info
.flags
& VOTEQUORUM_INFO_QUORATE
) printf("Quorate ");
153 if (info
.flags
& VOTEQUORUM_INFO_WAIT_FOR_ALL
) printf("WaitForAll ");
154 if (info
.flags
& VOTEQUORUM_INFO_LAST_MAN_STANDING
) printf("LastManStanding ");
155 if (info
.flags
& VOTEQUORUM_INFO_AUTO_TIE_BREAKER
) printf("AutoTieBreaker ");
156 if (info
.flags
& VOTEQUORUM_INFO_ALLOW_DOWNSCALE
) printf("AllowDownscale ");
161 if (argc
>= 2 && atoi(argv
[1])) {
162 if ( (err
=votequorum_setexpected(g_handle
, atoi(argv
[1]))) != CS_OK
)
163 fprintf(stderr
, "set expected votes FAILED: %d\n", err
);
165 if (argc
>= 3 && atoi(argv
[2])) {
166 if ( (err
=votequorum_setvotes(g_handle
, 0, atoi(argv
[2]))) != CS_OK
)
167 fprintf(stderr
, "set votes FAILED: %d\n", err
);
171 if ( (err
=votequorum_getinfo(g_handle
, 0, &info
)) != CS_OK
)
172 fprintf(stderr
, "votequorum_getinfo2 FAILED: %d\n", err
);
174 printf("-------------------\n");
175 printf("node votes %d\n", info
.node_votes
);
176 printf("expected votes %d\n", info
.node_expected_votes
);
177 printf("highest expected %d\n", info
.highest_expected
);
178 printf("total votes %d\n", info
.total_votes
);
179 printf("votequorum %d\n", info
.quorum
);
181 if (info
.flags
& VOTEQUORUM_INFO_TWONODE
) printf("2Node ");
182 if (info
.flags
& VOTEQUORUM_INFO_QUORATE
) printf("Quorate ");
183 if (info
.flags
& VOTEQUORUM_INFO_WAIT_FOR_ALL
) printf("WaitForAll ");
184 if (info
.flags
& VOTEQUORUM_INFO_LAST_MAN_STANDING
) printf("LastManStanding ");
185 if (info
.flags
& VOTEQUORUM_INFO_AUTO_TIE_BREAKER
) printf("AutoTieBreaker ");
186 if (info
.flags
& VOTEQUORUM_INFO_ALLOW_DOWNSCALE
) printf("AllowDownscale ");
191 printf("Waiting for votequorum events, press ^C to finish\n");
192 printf("-------------------\n");
195 if (votequorum_dispatch(g_handle
, CS_DISPATCH_ALL
) != CS_OK
) {
196 fprintf(stderr
, "votequorum_dispatch error\n");