44 #include <sys/types.h>
45 #include <sys/socket.h>
49 #include <qb/qbdefs.h>
50 #include <qb/qbipcc.h>
62 qb_ipcc_connection_t *
c;
68 static void votequorum_inst_free (
void *inst);
79 error =
hdb_error_to_cs(hdb_handle_create (&votequorum_handle_t_db,
sizeof (
struct votequorum_inst), handle));
81 goto error_no_destroy;
84 error =
hdb_error_to_cs(hdb_handle_get (&votequorum_handle_t_db, *handle, (
void *)&votequorum_inst));
91 if (votequorum_inst->
c == NULL) {
93 goto error_put_destroy;
97 memcpy(&votequorum_inst->
callbacks, callbacks, sizeof (*callbacks));
99 memset(&votequorum_inst->
callbacks, 0, sizeof (*callbacks));
101 hdb_handle_put (&votequorum_handle_t_db, *handle);
106 hdb_handle_put (&votequorum_handle_t_db, *handle);
108 hdb_handle_destroy (&votequorum_handle_t_db, *handle);
113 static void votequorum_inst_free (
void *inst)
116 qb_ipcc_disconnect(vq_inst->
c);
125 error =
hdb_error_to_cs(hdb_handle_get (&votequorum_handle_t_db, handle, (
void *)&votequorum_inst));
126 if (error !=
CS_OK) {
134 hdb_handle_put (&votequorum_handle_t_db, handle);
140 hdb_handle_destroy (&votequorum_handle_t_db, handle);
142 hdb_handle_put (&votequorum_handle_t_db, handle);
159 error =
hdb_error_to_cs(hdb_handle_get (&votequorum_handle_t_db, handle, (
void *)&votequorum_inst));
160 if (error !=
CS_OK) {
164 req_lib_votequorum_getinfo.header.size =
sizeof (
struct req_lib_votequorum_getinfo);
168 iov.iov_base = (
char *)&req_lib_votequorum_getinfo;
169 iov.iov_len =
sizeof (
struct req_lib_votequorum_getinfo);
175 &res_lib_votequorum_getinfo,
178 if (error !=
CS_OK) {
182 error = res_lib_votequorum_getinfo.header.error;
191 info->
flags = res_lib_votequorum_getinfo.
flags;
197 hdb_handle_put (&votequorum_handle_t_db, handle);
212 error =
hdb_error_to_cs(hdb_handle_get (&votequorum_handle_t_db, handle, (
void *)&votequorum_inst));
213 if (error !=
CS_OK) {
218 req_lib_votequorum_setexpected.header.size =
sizeof (
struct req_lib_votequorum_setexpected);
222 iov.iov_base = (
char *)&req_lib_votequorum_setexpected;
223 iov.iov_len =
sizeof (
struct req_lib_votequorum_setexpected);
229 &res_lib_votequorum_status,
232 if (error !=
CS_OK) {
236 error = res_lib_votequorum_status.header.error;
239 hdb_handle_put (&votequorum_handle_t_db, handle);
255 error =
hdb_error_to_cs(hdb_handle_get (&votequorum_handle_t_db, handle, (
void *)&votequorum_inst));
256 if (error !=
CS_OK) {
260 req_lib_votequorum_setvotes.header.size =
sizeof (
struct req_lib_votequorum_setvotes);
265 iov.iov_base = (
char *)&req_lib_votequorum_setvotes;
266 iov.iov_len =
sizeof (
struct req_lib_votequorum_setvotes);
272 &res_lib_votequorum_status,
275 if (error !=
CS_OK) {
279 error = res_lib_votequorum_status.header.error;
282 hdb_handle_put (&votequorum_handle_t_db, handle);
298 error =
hdb_error_to_cs(hdb_handle_get (&votequorum_handle_t_db, handle, (
void *)&votequorum_inst));
299 if (error !=
CS_OK) {
303 req_lib_votequorum_trackstart.header.size =
sizeof (
struct req_lib_votequorum_trackstart);
308 iov.iov_base = (
char *)&req_lib_votequorum_trackstart;
309 iov.iov_len =
sizeof (
struct req_lib_votequorum_trackstart);
315 &res_lib_votequorum_status,
318 if (error !=
CS_OK) {
322 error = res_lib_votequorum_status.header.error;
325 hdb_handle_put (&votequorum_handle_t_db, handle);
339 error =
hdb_error_to_cs(hdb_handle_get (&votequorum_handle_t_db, handle, (
void *)&votequorum_inst));
340 if (error !=
CS_OK) {
344 req_lib_votequorum_general.header.size =
sizeof (
struct req_lib_votequorum_general);
347 iov.iov_base = (
char *)&req_lib_votequorum_general;
348 iov.iov_len =
sizeof (
struct req_lib_votequorum_general);
354 &res_lib_votequorum_status,
357 if (error !=
CS_OK) {
361 error = res_lib_votequorum_status.header.error;
364 hdb_handle_put (&votequorum_handle_t_db, handle);
377 error =
hdb_error_to_cs(hdb_handle_get (&votequorum_handle_t_db, handle, (
void *)&votequorum_inst));
378 if (error !=
CS_OK) {
382 *context = votequorum_inst->
context;
384 hdb_handle_put (&votequorum_handle_t_db, handle);
396 error =
hdb_error_to_cs(hdb_handle_get (&votequorum_handle_t_db, handle, (
void *)&votequorum_inst));
397 if (error !=
CS_OK) {
403 hdb_handle_put (&votequorum_handle_t_db, handle);
416 error =
hdb_error_to_cs(hdb_handle_get (&votequorum_handle_t_db, handle, (
void *)&votequorum_inst));
417 if (error !=
CS_OK) {
423 (void)hdb_handle_put (&votequorum_handle_t_db, handle);
437 struct qb_ipc_response_header *dispatch_data;
450 error =
hdb_error_to_cs(hdb_handle_get (&votequorum_handle_t_db, handle,
451 (
void *)&votequorum_inst));
452 if (error !=
CS_OK) {
464 dispatch_data = (
struct qb_ipc_response_header *)dispatch_buf;
489 if (error !=
CS_OK) {
503 switch (dispatch_data->id) {
509 res_lib_votequorum_notification = (
struct res_lib_votequorum_notification *)dispatch_data;
512 res_lib_votequorum_notification->context,
513 res_lib_votequorum_notification->quorate,
514 res_lib_votequorum_notification->node_list_entries,
523 res_lib_votequorum_expectedvotes_notification = (
struct res_lib_votequorum_expectedvotes_notification *)dispatch_data;
526 res_lib_votequorum_expectedvotes_notification->context,
527 res_lib_votequorum_expectedvotes_notification->expected_votes);
553 hdb_handle_put (&votequorum_handle_t_db, handle);
567 if ((strlen(name) == 0) ||
572 error =
hdb_error_to_cs(hdb_handle_get (&votequorum_handle_t_db, handle, (
void *)&votequorum_inst));
573 if (error !=
CS_OK) {
578 req_lib_votequorum_qdevice_register.header.size =
sizeof (
struct req_lib_votequorum_qdevice_register);
580 strcpy(req_lib_votequorum_qdevice_register.
name, name);
582 iov.iov_base = (
char *)&req_lib_votequorum_qdevice_register;
583 iov.iov_len =
sizeof (
struct req_lib_votequorum_qdevice_register);
589 &res_lib_votequorum_status,
592 if (error !=
CS_OK) {
596 error = res_lib_votequorum_status.header.error;
599 hdb_handle_put (&votequorum_handle_t_db, handle);
607 unsigned int cast_vote)
615 if ((strlen(name) == 0) ||
620 error =
hdb_error_to_cs(hdb_handle_get (&votequorum_handle_t_db, handle, (
void *)&votequorum_inst));
621 if (error !=
CS_OK) {
625 req_lib_votequorum_qdevice_poll.header.size =
sizeof (
struct req_lib_votequorum_qdevice_poll);
627 strcpy(req_lib_votequorum_qdevice_poll.
name, name);
630 iov.iov_base = (
char *)&req_lib_votequorum_qdevice_poll;
631 iov.iov_len =
sizeof (
struct req_lib_votequorum_qdevice_poll);
637 &res_lib_votequorum_status,
640 if (error !=
CS_OK) {
644 error = res_lib_votequorum_status.header.error;
647 hdb_handle_put (&votequorum_handle_t_db, handle);
663 if ((strlen(name) == 0) ||
668 error =
hdb_error_to_cs(hdb_handle_get (&votequorum_handle_t_db, handle, (
void *)&votequorum_inst));
669 if (error !=
CS_OK) {
673 req_lib_votequorum_qdevice_master_wins.header.size =
sizeof (
struct req_lib_votequorum_qdevice_master_wins);
675 strcpy(req_lib_votequorum_qdevice_master_wins.
name, name);
676 req_lib_votequorum_qdevice_master_wins.
allow =
allow;
678 iov.iov_base = (
char *)&req_lib_votequorum_qdevice_master_wins;
679 iov.iov_len =
sizeof (
struct req_lib_votequorum_qdevice_master_wins);
685 &res_lib_votequorum_status,
688 if (error !=
CS_OK) {
692 error = res_lib_votequorum_status.header.error;
695 hdb_handle_put (&votequorum_handle_t_db, handle);
711 if ((strlen(oldname) == 0) ||
713 (strlen(newname) == 0) ||
718 error =
hdb_error_to_cs(hdb_handle_get (&votequorum_handle_t_db, handle, (
void *)&votequorum_inst));
719 if (error !=
CS_OK) {
723 req_lib_votequorum_qdevice_update.header.size =
sizeof (
struct req_lib_votequorum_qdevice_update);
725 strcpy(req_lib_votequorum_qdevice_update.
oldname, oldname);
726 strcpy(req_lib_votequorum_qdevice_update.
newname, newname);
728 iov.iov_base = (
char *)&req_lib_votequorum_qdevice_update;
729 iov.iov_len =
sizeof (
struct req_lib_votequorum_qdevice_update);
735 &res_lib_votequorum_status,
738 if (error !=
CS_OK) {
742 error = res_lib_votequorum_status.header.error;
745 hdb_handle_put (&votequorum_handle_t_db, handle);
760 if ((strlen(name) == 0) ||
765 error =
hdb_error_to_cs(hdb_handle_get (&votequorum_handle_t_db, handle, (
void *)&votequorum_inst));
766 if (error !=
CS_OK) {
770 req_lib_votequorum_qdevice_unregister.header.size =
sizeof (
struct req_lib_votequorum_qdevice_unregister);
772 strcpy(req_lib_votequorum_qdevice_unregister.
name, name);
774 iov.iov_base = (
char *)&req_lib_votequorum_qdevice_unregister;
775 iov.iov_len =
sizeof (
struct req_lib_votequorum_qdevice_unregister);
781 &res_lib_votequorum_status,
784 if (error !=
CS_OK) {
788 error = res_lib_votequorum_status.header.error;
791 hdb_handle_put (&votequorum_handle_t_db, handle);
char name[VOTEQUORUM_QDEVICE_MAX_NAME_LEN]
char newname[VOTEQUORUM_QDEVICE_MAX_NAME_LEN]
cs_error_t votequorum_trackstart(votequorum_handle_t handle, uint64_t context, unsigned int flags)
Track node and quorum changes.
char oldname[VOTEQUORUM_QDEVICE_MAX_NAME_LEN]
cs_error_t votequorum_setvotes(votequorum_handle_t handle, unsigned int nodeid, unsigned int votes)
set votes for a node
cs_error_t votequorum_initialize(votequorum_handle_t *handle, votequorum_callbacks_t *callbacks)
Create a new quorum connection.
cs_error_t hdb_error_to_cs(int res)
cs_error_t votequorum_context_set(votequorum_handle_t handle, void *context)
uint64_t votequorum_handle_t
votequorum_callbacks_t callbacks
char name[VOTEQUORUM_QDEVICE_MAX_NAME_LEN]
char qdevice_name[VOTEQUORUM_QDEVICE_MAX_NAME_LEN]
unsigned int highest_expected
cs_error_t votequorum_dispatch(votequorum_handle_t handle, cs_dispatch_flags_t dispatch_types)
Dispatch messages and configuration changes.
unsigned int highest_expected
cs_error_t votequorum_qdevice_poll(votequorum_handle_t handle, const char *name, unsigned int cast_vote)
Poll a quorum device.
char name[VOTEQUORUM_QDEVICE_MAX_NAME_LEN]
cs_error_t votequorum_qdevice_update(votequorum_handle_t handle, const char *oldname, const char *newname)
Update registered name of a quorum device.
unsigned int expected_votes
cs_error_t votequorum_finalize(votequorum_handle_t handle)
Close the quorum handle.
#define IPC_DISPATCH_SIZE
cs_error_t votequorum_setexpected(votequorum_handle_t handle, unsigned int expected_votes)
set expected_votes
cs_error_t votequorum_fd_get(votequorum_handle_t handle, int *fd)
Get a file descriptor on which to poll.
char name[VOTEQUORUM_QDEVICE_MAX_NAME_LEN]
cs_error_t votequorum_qdevice_register(votequorum_handle_t handle, const char *name)
Register a quorum device.
cs_error_t votequorum_context_get(votequorum_handle_t handle, void **context)
Save and retrieve private data/context.
unsigned int qdevice_votes
votequorum_expectedvotes_notification_fn_t votequorum_expectedvotes_notify_fn
votequorum_notification_fn_t votequorum_notify_fn
char qdevice_name[VOTEQUORUM_QDEVICE_MAX_NAME_LEN]
char newname[VOTEQUORUM_QDEVICE_MAX_NAME_LEN]
cs_error_t votequorum_qdevice_master_wins(votequorum_handle_t handle, const char *name, unsigned int allow)
Allow qdevice to tell votequorum if master_wins can be enabled or not.
cs_error_t votequorum_trackstop(votequorum_handle_t handle)
unsigned int qdevice_votes
unsigned int node_expected_votes
#define VOTEQUORUM_QDEVICE_MAX_NAME_LEN
#define DECLARE_HDB_DATABASE
char oldname[VOTEQUORUM_QDEVICE_MAX_NAME_LEN]
cs_error_t votequorum_qdevice_unregister(votequorum_handle_t handle, const char *name)
Unregister a quorum device.
#define CS_IPC_TIMEOUT_MS
cs_error_t votequorum_getinfo(votequorum_handle_t handle, unsigned int nodeid, struct votequorum_info *info)
Get quorum information.
cs_error_t qb_to_cs_error(int result)
unsigned int expected_votes