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;
451 error =
hdb_error_to_cs(hdb_handle_get (&votequorum_handle_t_db, handle,
452 (
void *)&votequorum_inst));
453 if (error !=
CS_OK) {
465 dispatch_data = (
struct qb_ipc_response_header *)dispatch_buf;
490 if (error !=
CS_OK) {
504 switch (dispatch_data->id) {
510 res_lib_votequorum_notification = (
struct res_lib_votequorum_notification *)dispatch_data;
511 marshall_from_mar_votequorum_ring_id (&ring_id, &res_lib_votequorum_notification->ring_id);
514 res_lib_votequorum_notification->context,
515 res_lib_votequorum_notification->quorate,
517 res_lib_votequorum_notification->node_list_entries,
526 res_lib_votequorum_expectedvotes_notification = (
struct res_lib_votequorum_expectedvotes_notification *)dispatch_data;
529 res_lib_votequorum_expectedvotes_notification->context,
530 res_lib_votequorum_expectedvotes_notification->expected_votes);
556 hdb_handle_put (&votequorum_handle_t_db, handle);
570 if ((strlen(name) == 0) ||
575 error =
hdb_error_to_cs(hdb_handle_get (&votequorum_handle_t_db, handle, (
void *)&votequorum_inst));
576 if (error !=
CS_OK) {
581 req_lib_votequorum_qdevice_register.header.size =
sizeof (
struct req_lib_votequorum_qdevice_register);
583 strcpy(req_lib_votequorum_qdevice_register.
name, name);
585 iov.iov_base = (
char *)&req_lib_votequorum_qdevice_register;
586 iov.iov_len =
sizeof (
struct req_lib_votequorum_qdevice_register);
592 &res_lib_votequorum_status,
595 if (error !=
CS_OK) {
599 error = res_lib_votequorum_status.header.error;
602 hdb_handle_put (&votequorum_handle_t_db, handle);
610 unsigned int cast_vote,
619 if ((strlen(name) == 0) ||
624 error =
hdb_error_to_cs(hdb_handle_get (&votequorum_handle_t_db, handle, (
void *)&votequorum_inst));
625 if (error !=
CS_OK) {
629 req_lib_votequorum_qdevice_poll.header.size =
sizeof (
struct req_lib_votequorum_qdevice_poll);
631 strcpy(req_lib_votequorum_qdevice_poll.
name, name);
633 marshall_to_mar_votequorum_ring_id(&req_lib_votequorum_qdevice_poll.ring_id, &ring_id);
635 iov.iov_base = (
char *)&req_lib_votequorum_qdevice_poll;
636 iov.iov_len =
sizeof (
struct req_lib_votequorum_qdevice_poll);
642 &res_lib_votequorum_status,
645 if (error !=
CS_OK) {
649 error = res_lib_votequorum_status.header.error;
652 hdb_handle_put (&votequorum_handle_t_db, handle);
668 if ((strlen(name) == 0) ||
673 error =
hdb_error_to_cs(hdb_handle_get (&votequorum_handle_t_db, handle, (
void *)&votequorum_inst));
674 if (error !=
CS_OK) {
678 req_lib_votequorum_qdevice_master_wins.header.size =
sizeof (
struct req_lib_votequorum_qdevice_master_wins);
680 strcpy(req_lib_votequorum_qdevice_master_wins.
name, name);
681 req_lib_votequorum_qdevice_master_wins.
allow =
allow;
683 iov.iov_base = (
char *)&req_lib_votequorum_qdevice_master_wins;
684 iov.iov_len =
sizeof (
struct req_lib_votequorum_qdevice_master_wins);
690 &res_lib_votequorum_status,
693 if (error !=
CS_OK) {
697 error = res_lib_votequorum_status.header.error;
700 hdb_handle_put (&votequorum_handle_t_db, handle);
716 if ((strlen(oldname) == 0) ||
718 (strlen(newname) == 0) ||
723 error =
hdb_error_to_cs(hdb_handle_get (&votequorum_handle_t_db, handle, (
void *)&votequorum_inst));
724 if (error !=
CS_OK) {
728 req_lib_votequorum_qdevice_update.header.size =
sizeof (
struct req_lib_votequorum_qdevice_update);
730 strcpy(req_lib_votequorum_qdevice_update.
oldname, oldname);
731 strcpy(req_lib_votequorum_qdevice_update.
newname, newname);
733 iov.iov_base = (
char *)&req_lib_votequorum_qdevice_update;
734 iov.iov_len =
sizeof (
struct req_lib_votequorum_qdevice_update);
740 &res_lib_votequorum_status,
743 if (error !=
CS_OK) {
747 error = res_lib_votequorum_status.header.error;
750 hdb_handle_put (&votequorum_handle_t_db, handle);
765 if ((strlen(name) == 0) ||
770 error =
hdb_error_to_cs(hdb_handle_get (&votequorum_handle_t_db, handle, (
void *)&votequorum_inst));
771 if (error !=
CS_OK) {
775 req_lib_votequorum_qdevice_unregister.header.size =
sizeof (
struct req_lib_votequorum_qdevice_unregister);
777 strcpy(req_lib_votequorum_qdevice_unregister.
name, name);
779 iov.iov_base = (
char *)&req_lib_votequorum_qdevice_unregister;
780 iov.iov_len =
sizeof (
struct req_lib_votequorum_qdevice_unregister);
786 &res_lib_votequorum_status,
789 if (error !=
CS_OK) {
793 error = res_lib_votequorum_status.header.error;
796 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.
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
The res_lib_votequorum_notification struct.
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]
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.
votequorum_notification_fn_t votequorum_notify_fn
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.
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