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;
452 error =
hdb_error_to_cs(hdb_handle_get (&votequorum_handle_t_db, handle,
453 (
void *)&votequorum_inst));
454 if (error !=
CS_OK) {
466 dispatch_data = (
struct qb_ipc_response_header *)dispatch_buf;
491 if (error !=
CS_OK) {
505 switch (dispatch_data->id) {
511 res_lib_votequorum_quorum_notification = (
struct res_lib_votequorum_quorum_notification *)dispatch_data;
514 res_lib_votequorum_quorum_notification->context,
515 res_lib_votequorum_quorum_notification->quorate,
516 res_lib_votequorum_quorum_notification->node_list_entries,
524 res_lib_votequorum_nodelist_notification = (
struct res_lib_votequorum_nodelist_notification *)dispatch_data;
525 marshall_from_mar_votequorum_ring_id (&ring_id, &res_lib_votequorum_nodelist_notification->ring_id);
528 res_lib_votequorum_nodelist_notification->context,
530 res_lib_votequorum_nodelist_notification->node_list_entries,
531 res_lib_votequorum_nodelist_notification->node_list );
538 res_lib_votequorum_expectedvotes_notification = (
struct res_lib_votequorum_expectedvotes_notification *)dispatch_data;
541 res_lib_votequorum_expectedvotes_notification->context,
542 res_lib_votequorum_expectedvotes_notification->expected_votes);
568 hdb_handle_put (&votequorum_handle_t_db, handle);
582 if ((strlen(name) == 0) ||
587 error =
hdb_error_to_cs(hdb_handle_get (&votequorum_handle_t_db, handle, (
void *)&votequorum_inst));
588 if (error !=
CS_OK) {
593 req_lib_votequorum_qdevice_register.header.size =
sizeof (
struct req_lib_votequorum_qdevice_register);
595 strcpy(req_lib_votequorum_qdevice_register.
name, name);
597 iov.iov_base = (
char *)&req_lib_votequorum_qdevice_register;
598 iov.iov_len =
sizeof (
struct req_lib_votequorum_qdevice_register);
604 &res_lib_votequorum_status,
607 if (error !=
CS_OK) {
611 error = res_lib_votequorum_status.header.error;
614 hdb_handle_put (&votequorum_handle_t_db, handle);
622 unsigned int cast_vote,
631 if ((strlen(name) == 0) ||
636 error =
hdb_error_to_cs(hdb_handle_get (&votequorum_handle_t_db, handle, (
void *)&votequorum_inst));
637 if (error !=
CS_OK) {
641 req_lib_votequorum_qdevice_poll.header.size =
sizeof (
struct req_lib_votequorum_qdevice_poll);
643 strcpy(req_lib_votequorum_qdevice_poll.
name, name);
645 marshall_to_mar_votequorum_ring_id(&req_lib_votequorum_qdevice_poll.ring_id, &ring_id);
647 iov.iov_base = (
char *)&req_lib_votequorum_qdevice_poll;
648 iov.iov_len =
sizeof (
struct req_lib_votequorum_qdevice_poll);
654 &res_lib_votequorum_status,
657 if (error !=
CS_OK) {
661 error = res_lib_votequorum_status.header.error;
664 hdb_handle_put (&votequorum_handle_t_db, handle);
680 if ((strlen(name) == 0) ||
685 error =
hdb_error_to_cs(hdb_handle_get (&votequorum_handle_t_db, handle, (
void *)&votequorum_inst));
686 if (error !=
CS_OK) {
690 req_lib_votequorum_qdevice_master_wins.header.size =
sizeof (
struct req_lib_votequorum_qdevice_master_wins);
692 strcpy(req_lib_votequorum_qdevice_master_wins.
name, name);
693 req_lib_votequorum_qdevice_master_wins.
allow =
allow;
695 iov.iov_base = (
char *)&req_lib_votequorum_qdevice_master_wins;
696 iov.iov_len =
sizeof (
struct req_lib_votequorum_qdevice_master_wins);
702 &res_lib_votequorum_status,
705 if (error !=
CS_OK) {
709 error = res_lib_votequorum_status.header.error;
712 hdb_handle_put (&votequorum_handle_t_db, handle);
728 if ((strlen(oldname) == 0) ||
730 (strlen(newname) == 0) ||
735 error =
hdb_error_to_cs(hdb_handle_get (&votequorum_handle_t_db, handle, (
void *)&votequorum_inst));
736 if (error !=
CS_OK) {
740 req_lib_votequorum_qdevice_update.header.size =
sizeof (
struct req_lib_votequorum_qdevice_update);
742 strcpy(req_lib_votequorum_qdevice_update.
oldname, oldname);
743 strcpy(req_lib_votequorum_qdevice_update.
newname, newname);
745 iov.iov_base = (
char *)&req_lib_votequorum_qdevice_update;
746 iov.iov_len =
sizeof (
struct req_lib_votequorum_qdevice_update);
752 &res_lib_votequorum_status,
755 if (error !=
CS_OK) {
759 error = res_lib_votequorum_status.header.error;
762 hdb_handle_put (&votequorum_handle_t_db, handle);
777 if ((strlen(name) == 0) ||
782 error =
hdb_error_to_cs(hdb_handle_get (&votequorum_handle_t_db, handle, (
void *)&votequorum_inst));
783 if (error !=
CS_OK) {
787 req_lib_votequorum_qdevice_unregister.header.size =
sizeof (
struct req_lib_votequorum_qdevice_unregister);
789 strcpy(req_lib_votequorum_qdevice_unregister.
name, name);
791 iov.iov_base = (
char *)&req_lib_votequorum_qdevice_unregister;
792 iov.iov_len =
sizeof (
struct req_lib_votequorum_qdevice_unregister);
798 &res_lib_votequorum_status,
801 if (error !=
CS_OK) {
805 error = res_lib_votequorum_status.header.error;
808 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.
The votequorum_callbacks_t struct.
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)
votequorum_context_set
uint64_t votequorum_handle_t
votequorum_handle_t
The req_lib_votequorum_qdevice_master_wins struct.
DECLARE_HDB_DATABASE(votequorum_handle_t_db, votequorum_inst_free)
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.
The req_lib_votequorum_qdevice_unregister struct.
The res_lib_votequorum_quorum_notification struct.
unsigned int highest_expected
The res_lib_votequorum_status struct.
char name[VOTEQUORUM_QDEVICE_MAX_NAME_LEN]
The votequorum_node_t struct.
The req_lib_votequorum_general struct.
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.
The req_lib_votequorum_getinfo struct.
char name[VOTEQUORUM_QDEVICE_MAX_NAME_LEN]
votequorum_nodelist_notification_fn_t votequorum_nodelist_notify_fn
cs_error_t votequorum_qdevice_register(votequorum_handle_t handle, const char *name)
Register a quorum device.
The req_lib_votequorum_qdevice_update struct.
cs_error_t
The cs_error_t enum.
cs_error_t votequorum_context_get(votequorum_handle_t handle, void **context)
Save and retrieve private data/context.
The req_lib_votequorum_setvotes struct.
cs_dispatch_flags_t
The cs_dispatch_flags_t enum.
unsigned int qdevice_votes
votequorum_expectedvotes_notification_fn_t votequorum_expectedvotes_notify_fn
The req_lib_votequorum_setexpected struct.
The res_lib_votequorum_expectedvotes_notification struct.
cs_error_t votequorum_qdevice_poll(votequorum_handle_t handle, const char *name, unsigned int cast_vote, votequorum_ring_id_t ring_id)
Poll a quorum device.
The req_lib_votequorum_qdevice_register struct.
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)
votequorum_trackstop
unsigned int qdevice_votes
The votequorum_info struct.
unsigned int node_expected_votes
The req_lib_votequorum_trackstart struct.
#define VOTEQUORUM_QDEVICE_MAX_NAME_LEN
The req_lib_votequorum_qdevice_poll struct.
votequorum_quorum_notification_fn_t votequorum_quorum_notify_fn
char oldname[VOTEQUORUM_QDEVICE_MAX_NAME_LEN]
The votequorum_ring_id_t struct.
The res_lib_votequorum_getinfo struct.
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.
struct memb_ring_id ring_id
cs_error_t qb_to_cs_error(int result)
qb_to_cs_error
unsigned int expected_votes