45 #include <sys/types.h> 46 #include <sys/socket.h> 47 #include <sys/select.h> 51 #include <qb/qbipcc.h> 66 qb_ipcc_connection_t *
c;
76 static void cfg_inst_free (
void *inst);
92 error =
hdb_error_to_cs (hdb_handle_create (&cfg_hdb,
sizeof (
struct cfg_inst), cfg_handle));
94 goto error_no_destroy;
97 error =
hdb_error_to_cs (hdb_handle_get (&cfg_hdb, *cfg_handle, (
void *)&cfg_inst));
102 cfg_inst->finalize = 0;
104 if (cfg_inst->c == NULL) {
106 goto error_put_destroy;
113 (void)hdb_handle_put (&cfg_hdb, *cfg_handle);
118 (void)hdb_handle_put (&cfg_hdb, *cfg_handle);
120 (void)hdb_handle_destroy (&cfg_hdb, *cfg_handle);
128 int32_t *selection_fd)
133 error =
hdb_error_to_cs (hdb_handle_get (&cfg_hdb, cfg_handle, (
void *)&cfg_inst));
134 if (error !=
CS_OK) {
138 error =
qb_to_cs_error (qb_ipcc_fd_get (cfg_inst->c, selection_fd));
140 (void)hdb_handle_put (&cfg_hdb, cfg_handle);
155 struct qb_ipc_response_header *dispatch_data;
160 if (error !=
CS_OK) {
172 dispatch_data = (
struct qb_ipc_response_header *)dispatch_buf;
197 if (error !=
CS_OK) {
211 switch (dispatch_data->id) {
217 res_lib_cfg_testshutdown = (
struct res_lib_cfg_testshutdown *)dispatch_data;
225 if (cfg_inst->finalize) {
242 (void)hdb_handle_put (&cfg_hdb, cfg_handle);
247 static void cfg_inst_free (
void *inst)
250 qb_ipcc_disconnect(cfg_inst->
c);
260 error =
hdb_error_to_cs(hdb_handle_get (&cfg_hdb, cfg_handle, (
void *)&cfg_inst));
261 if (error !=
CS_OK) {
268 if (cfg_inst->finalize) {
269 (void)hdb_handle_put (&cfg_hdb, cfg_handle);
273 cfg_inst->finalize = 1;
275 (void)hdb_handle_destroy (&cfg_hdb, cfg_handle);
277 (void)hdb_handle_put (&cfg_hdb, cfg_handle);
285 char ***interface_names,
287 unsigned int *interface_count)
296 error =
hdb_error_to_cs(hdb_handle_get (&cfg_hdb, cfg_handle, (
void *)&cfg_inst));
297 if (error !=
CS_OK) {
301 req_lib_cfg_ringstatusget.header.size =
sizeof (
struct req_lib_cfg_ringstatusget);
304 iov.iov_base = (
void *)&req_lib_cfg_ringstatusget,
305 iov.iov_len = sizeof (
struct req_lib_cfg_ringstatusget),
310 &res_lib_cfg_ringstatusget,
313 if (error !=
CS_OK) {
314 goto exit_handle_put;
317 *interface_count = res_lib_cfg_ringstatusget.interface_count;
318 *interface_names = malloc (
sizeof (
char *) * *interface_count);
319 if (*interface_names == NULL) {
322 memset (*interface_names, 0,
sizeof (
char *) * *interface_count);
324 *status = malloc (
sizeof (
char *) * *interface_count);
325 if (*status == NULL) {
327 goto error_free_interface_names_array;
329 memset (*status, 0,
sizeof (
char *) * *interface_count);
331 for (i = 0; i < res_lib_cfg_ringstatusget.interface_count; i++) {
332 (*(interface_names))[i] = strdup (res_lib_cfg_ringstatusget.interface_name[i]);
333 if ((*(interface_names))[i] == NULL) {
335 goto error_free_interface_names;
339 for (i = 0; i < res_lib_cfg_ringstatusget.interface_count; i++) {
340 (*(status))[i] = strdup (res_lib_cfg_ringstatusget.interface_status[i]);
341 if ((*(status))[i] == NULL) {
343 goto error_free_status;
346 goto exit_handle_put;
349 for (j = 0; j < i; j++) {
350 free ((*(status))[j]);
352 i = *interface_count;
354 error_free_interface_names:
355 for (j = 0; j < i; j++) {
356 free ((*(interface_names))[j]);
361 error_free_interface_names_array:
362 free (*interface_names);
365 (void)hdb_handle_put (&cfg_hdb, cfg_handle);
381 size_t cfg_node_status_size;
382 void *res_lib_cfg_nodestatuget_ptr;
392 cfg_node_status_size =
sizeof(
struct res_lib_cfg_nodestatusget_v1);
393 res_lib_cfg_nodestatuget_ptr = &res_lib_cfg_nodestatusget_v1;
401 error =
hdb_error_to_cs(hdb_handle_get (&cfg_hdb, cfg_handle, (
void *)&cfg_inst));
402 if (error !=
CS_OK) {
406 req_lib_cfg_nodestatusget.header.size =
sizeof (
struct req_lib_cfg_nodestatusget);
408 req_lib_cfg_nodestatusget.nodeid =
nodeid;
409 req_lib_cfg_nodestatusget.version =
version;
411 iov.iov_base = (
void *)&req_lib_cfg_nodestatusget,
412 iov.iov_len = sizeof (
struct req_lib_cfg_nodestatusget),
417 res_lib_cfg_nodestatuget_ptr,
419 if (error !=
CS_OK) {
423 res_lib_cfg_nodestatusget_version = res_lib_cfg_nodestatuget_ptr;
424 error = res_lib_cfg_nodestatusget_version->header.error;
425 if (error !=
CS_OK) {
429 if (res_lib_cfg_nodestatusget_version->version != version) {
439 memcpy(node_status, &res_lib_cfg_nodestatusget_v1.node_status,
445 (void)hdb_handle_put (&cfg_hdb, cfg_handle);
462 req_lib_cfg_trackstart.
header.size =
sizeof (
struct req_lib_cfg_trackstart);
468 if (error !=
CS_OK) {
472 iov.iov_base = (
void *)&req_lib_cfg_trackstart,
473 iov.iov_len = sizeof (
struct req_lib_cfg_trackstart),
478 &res_lib_cfg_trackstart,
481 (void)hdb_handle_put (&cfg_hdb, cfg_handle);
483 return (error ==
CS_OK ? res_lib_cfg_trackstart.
header.error : error);
498 if (error !=
CS_OK) {
502 req_lib_cfg_trackstop.
header.size =
sizeof (
struct req_lib_cfg_trackstop);
505 iov.iov_base = (
void *)&req_lib_cfg_trackstop,
506 iov.iov_len = sizeof (
struct req_lib_cfg_trackstop),
511 &res_lib_cfg_trackstop,
514 (void)hdb_handle_put (&cfg_hdb, cfg_handle);
516 return (error ==
CS_OK ? res_lib_cfg_trackstop.
header.error : error);
536 if (error !=
CS_OK) {
541 req_lib_cfg_killnode.header.size =
sizeof (
struct req_lib_cfg_killnode);
542 req_lib_cfg_killnode.nodeid =
nodeid;
543 strcpy((
char *)req_lib_cfg_killnode.reason.value, reason);
544 req_lib_cfg_killnode.reason.length = strlen(reason)+1;
546 iov.iov_base = (
void *)&req_lib_cfg_killnode;
547 iov.iov_len =
sizeof (
struct req_lib_cfg_killnode);
552 &res_lib_cfg_killnode,
555 error = res_lib_cfg_killnode.header.error;
557 (void)hdb_handle_put (&cfg_hdb, cfg_handle);
559 return (error ==
CS_OK ? res_lib_cfg_killnode.header.error : error);
575 if (error !=
CS_OK) {
580 req_lib_cfg_tryshutdown.header.size =
sizeof (
struct req_lib_cfg_tryshutdown);
583 iov.iov_base = (
void *)&req_lib_cfg_tryshutdown;
584 iov.iov_len =
sizeof (req_lib_cfg_tryshutdown);
589 &res_lib_cfg_tryshutdown,
592 (void)hdb_handle_put (&cfg_hdb, cfg_handle);
594 return (error ==
CS_OK ? res_lib_cfg_tryshutdown.header.error : error);
610 if (error !=
CS_OK) {
615 req_lib_cfg_replytoshutdown.header.size =
sizeof (
struct req_lib_cfg_replytoshutdown);
618 iov.iov_base = (
void *)&req_lib_cfg_replytoshutdown;
619 iov.iov_len =
sizeof (
struct req_lib_cfg_replytoshutdown);
624 &res_lib_cfg_replytoshutdown,
644 const char *addr_buf;
646 char zeroes[
sizeof(
struct sockaddr_storage)];
650 if (error !=
CS_OK) {
653 memset(zeroes, 0,
sizeof(zeroes));
655 req_lib_cfg_get_node_addrs.header.size =
sizeof (req_lib_cfg_get_node_addrs);
659 iov.iov_base = (
char *)&req_lib_cfg_get_node_addrs;
660 iov.iov_len =
sizeof (req_lib_cfg_get_node_addrs);
666 res_lib_cfg_get_node_addrs = (
struct res_lib_cfg_get_node_addrs *)response_buf;
668 if (error !=
CS_OK) {
672 if (res_lib_cfg_get_node_addrs->
family == AF_INET)
673 addrlen =
sizeof(
struct sockaddr_in);
674 if (res_lib_cfg_get_node_addrs->
family == AF_INET6)
675 addrlen =
sizeof(
struct sockaddr_in6);
677 for (i = 0, addr_buf = (
char *)res_lib_cfg_get_node_addrs->
addrs;
678 i < max_addrs && i<res_lib_cfg_get_node_addrs->
num_addrs;
680 struct sockaddr_in *in;
681 struct sockaddr_in6 *in6;
685 if (res_lib_cfg_get_node_addrs->
family == AF_INET) {
686 in = (
struct sockaddr_in *)addrs[i].address;
687 if (memcmp(addr_buf, zeroes, addrlen) == 0) {
690 in->sin_family = AF_INET;
692 memcpy(&in->sin_addr, addr_buf,
sizeof(
struct in_addr));
694 if (res_lib_cfg_get_node_addrs->
family == AF_INET6) {
695 in6 = (
struct sockaddr_in6 *)addrs[i].address;
697 if (memcmp(addr_buf, zeroes, addrlen) == 0) {
698 in6->sin6_family = 0;
700 in6->sin6_family = AF_INET6;
702 memcpy(&in6->sin6_addr, addr_buf,
sizeof(
struct in6_addr));
708 *num_addrs = res_lib_cfg_get_node_addrs->
num_addrs;
709 errno = error = res_lib_cfg_get_node_addrs->header.error;
712 hdb_handle_put (&cfg_hdb, cfg_handle);
719 unsigned int *local_nodeid)
727 error =
hdb_error_to_cs(hdb_handle_get (&cfg_hdb, handle, (
void *)&cfg_inst));
728 if (error !=
CS_OK) {
732 req_lib_cfg_local_get.header.size =
sizeof (
struct qb_ipc_request_header);
735 iov.iov_base = (
void *)&req_lib_cfg_local_get;
736 iov.iov_len =
sizeof (
struct req_lib_cfg_local_get);
742 &res_lib_cfg_local_get,
745 if (error !=
CS_OK) {
749 error = res_lib_cfg_local_get.header.error;
751 *local_nodeid = res_lib_cfg_local_get.local_nodeid;
754 (void)hdb_handle_put (&cfg_hdb, handle);
768 error =
hdb_error_to_cs(hdb_handle_get (&cfg_hdb, handle, (
void *)&cfg_inst));
769 if (error !=
CS_OK) {
773 req_lib_cfg_reload_config.header.size =
sizeof (
struct qb_ipc_request_header);
776 iov.iov_base = (
void *)&req_lib_cfg_reload_config;
777 iov.iov_len =
sizeof (
struct req_lib_cfg_reload_config);
783 &res_lib_cfg_reload_config,
786 if (error !=
CS_OK) {
790 error = res_lib_cfg_reload_config.header.error;
793 (void)hdb_handle_put (&cfg_hdb, handle);
807 error =
hdb_error_to_cs(hdb_handle_get (&cfg_hdb, handle, (
void *)&cfg_inst));
808 if (error !=
CS_OK) {
812 req_lib_cfg_reopen_log_files.header.size =
sizeof (
struct qb_ipc_request_header);
815 iov.iov_base = (
void *)&req_lib_cfg_reopen_log_files;
816 iov.iov_len =
sizeof (
struct req_lib_cfg_reopen_log_files);
822 &res_lib_cfg_reopen_log_files,
825 if (error !=
CS_OK) {
829 error = res_lib_cfg_reopen_log_files.header.error;
832 (void)hdb_handle_put (&cfg_hdb, handle);
The res_lib_cfg_reopen_log_files struct.
cs_error_t corosync_cfg_kill_node(corosync_cfg_handle_t cfg_handle, unsigned int nodeid, const char *reason)
corosync_cfg_kill_node
cs_error_t hdb_error_to_cs(int res)
The res_lib_cfg_replytoshutdown struct.
cs_error_t corosync_cfg_local_get(corosync_cfg_handle_t handle, unsigned int *local_nodeid)
corosync_cfg_local_get
struct corosync_cfg_shutdown_callback_t
The res_lib_cfg_testshutdown struct.
cs_error_t corosync_cfg_ring_status_get(corosync_cfg_handle_t cfg_handle, char ***interface_names, char ***status, unsigned int *interface_count)
corosync_cfg_ring_status_get
cs_error_t corosync_cfg_fd_get(corosync_cfg_handle_t cfg_handle, int32_t *selection_fd)
corosync_cfg_fd_get
cs_error_t corosync_cfg_initialize(corosync_cfg_handle_t *cfg_handle, const corosync_cfg_callbacks_t *cfg_callbacks)
corosync_cfg_initialize
The res_lib_cfg_nodestatusget struct.
The res_lib_cfg_get_node_addrs struct.
corosync_cfg_callbacks_t callbacks
corosync_cfg_node_status_version_t
The req_lib_cfg_get_node_addrs struct.
corosync_cfg_shutdown_flags_t
Shutdown types.
cs_error_t corosync_cfg_reload_config(corosync_cfg_handle_t handle)
corosync_cfg_reload_config
struct qb_ipc_request_header header
uint64_t corosync_cfg_handle_t
The req_lib_cfg_reload_config struct.
#define IPC_RESPONSE_SIZE
cs_error_t corosync_cfg_finalize(corosync_cfg_handle_t cfg_handle)
corosync_cfg_finalize
#define IPC_DISPATCH_SIZE
The res_lib_cfg_local_get struct.
The res_lib_cfg_killnode struct.
cs_error_t corosync_cfg_replyto_shutdown(corosync_cfg_handle_t cfg_handle, corosync_cfg_shutdown_reply_flags_t response)
corosync_cfg_replyto_shutdown
cs_error_t corosync_cfg_trackstart(corosync_cfg_handle_t cfg_handle, uint8_t track_flags)
corosync_cfg_trackstart Track CFG for shutdown requests
corosync_cfg_shutdown_callback_t corosync_cfg_shutdown_callback
The req_lib_cfg_tryshutdown struct.
cs_error_t corosync_cfg_get_node_addrs(corosync_cfg_handle_t cfg_handle, unsigned int nodeid, size_t max_addrs, int *num_addrs, corosync_cfg_node_address_t *addrs)
corosync_cfg_get_node_addrs
cs_error_t corosync_cfg_dispatch(corosync_cfg_handle_t cfg_handle, cs_dispatch_flags_t dispatch_flags)
corosync_cfg_dispatch
cs_error_t
The cs_error_t enum.
cs_dispatch_flags_t
The cs_dispatch_flags_t enum.
The req_lib_cfg_replytoshutdown struct.
The res_lib_cfg_tryshutdown struct.
DECLARE_HDB_DATABASE(cfg_hdb, cfg_inst_free)
cs_error_t corosync_cfg_trackstop(corosync_cfg_handle_t cfg_handle)
corosync_cfg_trackstop Stop tracking CFG for shutdown requests
corosync_cfg_shutdown_reply_flags_t
enum corosync_cfg_shutdown_reply_flags_t
The req_lib_cfg_ringstatusget struct.
cs_error_t corosync_cfg_try_shutdown(corosync_cfg_handle_t cfg_handle, corosync_cfg_shutdown_flags_t flags)
corosync_cfg_try_shutdown
cs_error_t corosync_cfg_node_status_get(corosync_cfg_handle_t cfg_handle, unsigned int nodeid, corosync_cfg_node_status_version_t version, void *node_status)
corosync_cfg_node_status_get
#define CS_MAX_NAME_LENGTH
struct qb_ipc_response_header header
The res_lib_cfg_ringstatusget struct.
The req_lib_cfg_nodestatusget struct.
The res_lib_cfg_reload_config struct.
struct qb_ipc_request_header header
The req_lib_cfg_reopen_log_files struct.
#define CS_IPC_TIMEOUT_MS
cs_error_t qb_to_cs_error(int result)
qb_to_cs_error
cs_error_t corosync_cfg_reopen_log_files(corosync_cfg_handle_t handle)
Reopen logging files.
struct qb_ipc_response_header header
The req_lib_cfg_killnode struct.
The req_lib_cfg_local_get struct.