43 #include <sys/types.h> 44 #include <sys/socket.h> 48 #include <qb/qbipcc.h> 59 qb_ipcc_connection_t *
c;
69 static void quorum_inst_free (
void *inst);
76 uint32_t *quorum_type)
94 uint32_t *quorum_type,
100 struct qb_ipc_request_header quorum_gettype_req;
104 uint32_t local_quorum_type;
108 goto error_no_destroy;
111 error =
hdb_error_to_cs(hdb_handle_create (&quorum_handle_t_db,
sizeof (
struct quorum_inst), handle));
112 if (error !=
CS_OK) {
113 goto error_no_destroy;
116 error =
hdb_error_to_cs(hdb_handle_get (&quorum_handle_t_db, *handle, (
void *)&quorum_inst));
117 if (error !=
CS_OK) {
122 quorum_inst->finalize = 0;
124 if (quorum_inst->c == NULL) {
126 goto error_put_destroy;
131 quorum_gettype_req.size =
sizeof (quorum_gettype_req);
134 iov.iov_base = (
char *)&quorum_gettype_req;
135 iov.iov_len =
sizeof (quorum_gettype_req);
141 &res_lib_quorum_gettype,
142 sizeof(res_lib_quorum_gettype), -1));
144 if (error !=
CS_OK) {
145 goto error_put_destroy;
147 error = res_lib_quorum_gettype.header.error;
148 local_quorum_type = res_lib_quorum_gettype.
quorum_type;
151 quorum_model_gettype_req.header.size =
sizeof (quorum_model_gettype_req);
153 quorum_model_gettype_req.model = model;
155 iov.iov_base = (
char *)&quorum_model_gettype_req;
156 iov.iov_len =
sizeof (quorum_model_gettype_req);
162 &res_lib_quorum_model_gettype,
163 sizeof(res_lib_quorum_model_gettype), -1));
165 if (error !=
CS_OK) {
166 goto error_put_destroy;
168 error = res_lib_quorum_model_gettype.header.error;
169 local_quorum_type = res_lib_quorum_model_gettype.quorum_type;
173 if (quorum_type != NULL) {
174 *quorum_type = local_quorum_type;
177 if (model_data != NULL) {
188 quorum_inst->model_data.model = model;
189 quorum_inst->context =
context;
191 (void)hdb_handle_put (&quorum_handle_t_db, *handle);
196 (void)hdb_handle_put (&quorum_handle_t_db, *handle);
198 (void)hdb_handle_destroy (&quorum_handle_t_db, *handle);
203 static void quorum_inst_free (
void *inst)
206 qb_ipcc_disconnect(quorum_inst->
c);
215 error =
hdb_error_to_cs(hdb_handle_get (&quorum_handle_t_db, handle, (
void *)&quorum_inst));
216 if (error !=
CS_OK) {
223 if (quorum_inst->finalize) {
224 (void)hdb_handle_put (&quorum_handle_t_db, handle);
228 quorum_inst->finalize = 1;
230 (void)hdb_handle_destroy (&quorum_handle_t_db, handle);
232 (void)hdb_handle_put (&quorum_handle_t_db, handle);
244 struct qb_ipc_request_header req;
247 error =
hdb_error_to_cs(hdb_handle_get (&quorum_handle_t_db, handle, (
void *)&quorum_inst));
248 if (error !=
CS_OK) {
252 req.size =
sizeof (req);
255 iov.iov_base = (
char *)&req;
256 iov.iov_len =
sizeof (req);
262 &res_lib_quorum_getquorate,
265 if (error !=
CS_OK) {
269 error = res_lib_quorum_getquorate.header.error;
271 *quorate = res_lib_quorum_getquorate.
quorate;
274 (void)hdb_handle_put (&quorum_handle_t_db, handle);
286 error =
hdb_error_to_cs(hdb_handle_get (&quorum_handle_t_db, handle, (
void *)&quorum_inst));
287 if (error !=
CS_OK) {
293 (void)hdb_handle_put (&quorum_handle_t_db, handle);
306 error =
hdb_error_to_cs(hdb_handle_get (&quorum_handle_t_db, handle, (
void *)&quorum_inst));
307 if (error !=
CS_OK) {
311 *context = quorum_inst->context;
313 (void)hdb_handle_put (&quorum_handle_t_db, handle);
325 error =
hdb_error_to_cs(hdb_handle_get (&quorum_handle_t_db, handle, (
void *)&quorum_inst));
326 if (error !=
CS_OK) {
330 quorum_inst->context =
context;
332 (void)hdb_handle_put (&quorum_handle_t_db, handle);
346 struct qb_ipc_response_header res;
348 error =
hdb_error_to_cs(hdb_handle_get (&quorum_handle_t_db, handle, (
void *)&quorum_inst));
349 if (error !=
CS_OK) {
353 req_lib_quorum_trackstart.header.size =
sizeof (
struct req_lib_quorum_trackstart);
357 iov.iov_base = (
char *)&req_lib_quorum_trackstart;
358 iov.iov_len =
sizeof (
struct req_lib_quorum_trackstart);
367 if (error !=
CS_OK) {
374 (void)hdb_handle_put (&quorum_handle_t_db, handle);
385 struct qb_ipc_request_header req;
386 struct qb_ipc_response_header res;
388 error =
hdb_error_to_cs(hdb_handle_get (&quorum_handle_t_db, handle, (
void *)&quorum_inst));
389 if (error !=
CS_OK) {
393 req.size =
sizeof (req);
396 iov.iov_base = (
char *)&req;
397 iov.iov_len =
sizeof (req);
406 if (error !=
CS_OK) {
413 (void)hdb_handle_put (&quorum_handle_t_db, handle);
426 struct quorum_inst quorum_inst_copy;
427 struct qb_ipc_response_header *dispatch_data;
445 (
void *)&quorum_inst));
446 if (error !=
CS_OK) {
458 dispatch_data = (
struct qb_ipc_response_header *)dispatch_buf;
483 if (error !=
CS_OK) {
492 memcpy (&quorum_inst_copy, quorum_inst,
sizeof(quorum_inst_copy));
498 switch (dispatch_data->id) {
503 res_lib_quorum_notification = (
struct res_lib_quorum_notification *)dispatch_data;
506 res_lib_quorum_notification->quorate,
507 res_lib_quorum_notification->ring_seq,
508 res_lib_quorum_notification->view_list_entries,
521 switch (dispatch_data->id) {
526 res_lib_quorum_v1_quorum_notification =
527 (
struct res_lib_quorum_v1_quorum_notification *)dispatch_data;
529 ring_id.
nodeid = res_lib_quorum_v1_quorum_notification->ring_id.nodeid;
530 ring_id.
seq = res_lib_quorum_v1_quorum_notification->ring_id.seq;
533 res_lib_quorum_v1_quorum_notification->quorate,
535 res_lib_quorum_v1_quorum_notification->view_list_entries,
536 res_lib_quorum_v1_quorum_notification->
view_list);
542 res_lib_quorum_v1_nodelist_notification =
543 (
struct res_lib_quorum_v1_nodelist_notification *)dispatch_data;
545 ring_id.
nodeid = res_lib_quorum_v1_nodelist_notification->ring_id.nodeid;
546 ring_id.
seq = res_lib_quorum_v1_nodelist_notification->ring_id.seq;
548 joined_list = res_lib_quorum_v1_nodelist_notification->
member_list +
549 res_lib_quorum_v1_nodelist_notification->member_list_entries;
550 left_list = joined_list +
551 res_lib_quorum_v1_nodelist_notification->joined_list_entries;
555 res_lib_quorum_v1_nodelist_notification->member_list_entries,
556 res_lib_quorum_v1_nodelist_notification->
member_list,
557 res_lib_quorum_v1_nodelist_notification->joined_list_entries,
559 res_lib_quorum_v1_nodelist_notification->left_list_entries,
569 if (quorum_inst->finalize) {
586 (void)hdb_handle_put (&quorum_handle_t_db, handle);
The res_lib_quorum_getquorate struct.
quorum_model_data_t model_data
cs_error_t hdb_error_to_cs(int res)
cs_error_t quorum_dispatch(quorum_handle_t handle, cs_dispatch_flags_t dispatch_types)
Dispatch messages and configuration changes.
The req_lib_quorum_trackstart struct.
The quorum_callbacks_t struct.
The res_lib_quorum_notification struct.
quorum_model_v1_data_t model_v1_data
cs_error_t quorum_trackstop(quorum_handle_t handle)
quorum_trackstop
cs_error_t quorum_model_initialize(quorum_handle_t *handle, quorum_model_t model, quorum_model_data_t *model_data, uint32_t *quorum_type, void *context)
quorum_v1_quorum_notification_fn_t quorum_notify_fn
cs_error_t quorum_getquorate(quorum_handle_t handle, int *quorate)
Get quorum information.
cs_error_t quorum_context_get(quorum_handle_t handle, const void **context)
quorum_context_get
#define IPC_DISPATCH_SIZE
cs_error_t quorum_context_set(quorum_handle_t handle, const void *context)
quorum_context_set
quorum_notification_fn_t quorum_notify_fn
cs_error_t
The cs_error_t enum.
cs_dispatch_flags_t
The cs_dispatch_flags_t enum.
uint64_t quorum_handle_t
quorum_handle_t
The res_lib_quorum_gettype struct.
quorum_model_v0_data_t model_v0_data
mar_uint32_t member_list[]
quorum_v1_nodelist_notification_fn_t nodelist_notify_fn
cs_error_t quorum_fd_get(quorum_handle_t handle, int *fd)
Get a file descriptor on which to poll.
DECLARE_HDB_DATABASE(quorum_handle_t_db, quorum_inst_free)
quorum_notification_fn_t quorum_notify_fn
cs_error_t quorum_trackstart(quorum_handle_t handle, unsigned int flags)
Track node and quorum changes.
#define CS_IPC_TIMEOUT_MS
cs_error_t qb_to_cs_error(int result)
qb_to_cs_error
cs_error_t quorum_finalize(quorum_handle_t handle)
Close the quorum handle.
cs_error_t quorum_initialize(quorum_handle_t *handle, quorum_callbacks_t *callbacks, uint32_t *quorum_type)
Create a new quorum connection.