16 #include <sys/types.h> 25 #define PCMK_IPC_DEFAULT_QUEUE_MAX 500 27 static GHashTable *client_connections = NULL;
38 return client_connections? g_hash_table_size(client_connections) : 0;
53 if ((func != NULL) && (client_connections != NULL)) {
54 g_hash_table_foreach(client_connections, func, user_data);
61 if (client_connections) {
62 return g_hash_table_lookup(client_connections, c);
76 if (client_connections &&
id) {
77 g_hash_table_iter_init(&iter, client_connections);
78 while (g_hash_table_iter_next(&iter, &key, (gpointer *) & client)) {
79 if (strcmp(client->id,
id) == 0) {
85 crm_trace(
"No client found with id=%s",
id);
94 }
else if (c->
name == NULL && c->
id == NULL) {
96 }
else if (c->
name == NULL) {
106 if (client_connections != NULL) {
107 int active = g_hash_table_size(client_connections);
110 crm_err(
"Exiting with %d active IPC client%s",
113 g_hash_table_destroy(client_connections); client_connections = NULL;
120 qb_ipcs_connection_t *c = NULL;
122 if (service == NULL) {
126 c = qb_ipcs_connection_first_get(service);
129 qb_ipcs_connection_t *last = c;
131 c = qb_ipcs_connection_next_get(service, last);
134 crm_notice(
"Disconnecting client %p, pid=%d...",
136 qb_ipcs_disconnect(last);
137 qb_ipcs_connection_unref(last);
152 client_from_connection(qb_ipcs_connection_t *c,
void *key, uid_t uid_client)
156 if (client == NULL) {
164 if (client->
user == NULL) {
165 client->
user = strdup(
"#unprivileged");
167 crm_err(
"Unable to enforce ACLs for user ID %d, assuming unprivileged",
180 if (client->
id == NULL) {
181 crm_err(
"Could not generate UUID for client");
189 if (client_connections == NULL) {
191 client_connections = g_hash_table_new(g_direct_hash, g_direct_equal);
193 g_hash_table_insert(client_connections, key, client);
216 gid_t uid_cluster = 0;
217 gid_t gid_cluster = 0;
224 static bool need_log = TRUE;
227 crm_warn(
"Could not find user and group IDs for user %s",
233 if (uid_client != 0) {
234 crm_trace(
"Giving group %u access to new IPC connection", gid_cluster);
236 qb_ipcs_connection_auth_set(c, -1, gid_cluster, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP);
240 client = client_from_connection(c, NULL, uid_client);
241 if (client == NULL) {
245 if ((uid_client == 0) || (uid_client == uid_cluster)) {
250 crm_debug(
"New IPC client %s for PID %u with uid %d and gid %d",
251 client->
id, client->
pid, uid_client, gid_client);
255 static struct iovec *
256 pcmk__new_ipc_event(
void)
258 struct iovec *iov = calloc(2,
sizeof(
struct iovec));
273 free(event[0].iov_base);
274 free(event[1].iov_base);
280 free_event(gpointer
data)
301 if (client_connections) {
303 crm_trace(
"Destroying %p/%p (%d remaining)",
304 c, c->
ipcs, g_hash_table_size(client_connections) - 1);
305 g_hash_table_remove(client_connections, c->
ipcs);
308 crm_trace(
"Destroying remote connection %p (%d remaining)",
309 c, g_hash_table_size(client_connections) - 1);
310 g_hash_table_remove(client_connections, c->
id);
353 if ((errno == 0) && (qmax_int > 0)) {
354 client->
queue_max = (
unsigned int) qmax_int;
364 struct qb_ipcs_connection_stats stats;
366 stats.client_pid = 0;
367 qb_ipcs_connection_stats_get(c, &stats, 0);
368 return stats.client_pid;
387 char *uncompressed = NULL;
396 *
id = ((
struct qb_ipc_response_header *)
data)->id;
413 uncompressed = calloc(1, size_u);
415 crm_trace(
"Decompressing message data %u bytes into %u bytes",
418 rc = BZ2_bzBuffToBuffDecompress(uncompressed, &size_u, text, header->
size_compressed, 1, 0);
441 crm_ipcs_flush_events_cb(gpointer
data)
446 crm_ipcs_flush_events(c);
461 guint
delay = (queue_len < 5)? (1000 + 100 * queue_len) : 1500;
479 unsigned int sent = 0;
480 unsigned int queue_len = 0;
496 struct iovec *
event = NULL;
506 qb_rc = qb_ipcs_event_sendv(c->
ipcs, event, 2);
514 header =
event[0].iov_base;
516 crm_trace(
"Event %d to %p[%d] (%lld compressed bytes) sent",
517 header->
qb.id, c->
ipcs, c->
pid, (
long long) qb_rc);
519 crm_trace(
"Event %d to %p[%d] (%lld bytes) sent: %.120s",
520 header->
qb.id, c->
ipcs, c->
pid, (
long long) qb_rc,
521 (
char *) (event[1].iov_base));
527 if (sent > 0 || queue_len) {
528 crm_trace(
"Sent %d events (%d remaining) for %p[%d]: %s (%lld)",
529 sent, queue_len, c->
ipcs, c->
pid,
540 if ((c->
queue_backlog <= 1) || (queue_len < c->queue_backlog)) {
542 crm_warn(
"Client with process ID %u has a backlog of %u messages " 545 crm_err(
"Evicting client with process ID %u due to backlog of %u messages " 548 qb_ipcs_disconnect(c->
ipcs);
554 delay_next_flush(c, queue_len);
578 uint32_t max_send_size,
struct iovec **result,
581 static unsigned int biggest = 0;
583 unsigned int total = 0;
584 char *compressed = NULL;
588 if ((message == NULL) || (result == NULL)) {
593 if (header == NULL) {
599 if (max_send_size == 0) {
605 iov = pcmk__new_ipc_event();
607 iov[0].iov_base = header;
613 if (total < max_send_size) {
614 iov[1].iov_base = buffer;
618 unsigned int new_size = 0;
621 (
unsigned int) max_send_size, &compressed,
628 iov[1].iov_base = compressed;
638 crm_err(
"Could not compress %u-byte message into less than IPC " 639 "limit of %u bytes; set PCMK_ipc_buffer to higher value " 640 "(%u bytes suggested)",
650 header->
qb.size = iov[0].iov_len + iov[1].iov_len;
651 header->
qb.id = (int32_t)request;
656 *bytes = header->
qb.size;
665 static uint32_t
id = 1;
682 header->
qb.id =
id++;
689 struct iovec *iov_copy = pcmk__new_ipc_event();
692 iov_copy[0].iov_len = iov[0].iov_len;
693 iov_copy[0].iov_base = malloc(iov[0].iov_len);
694 memcpy(iov_copy[0].iov_base, iov[0].iov_base, iov[0].iov_len);
696 iov_copy[1].iov_len = iov[1].iov_len;
697 iov_copy[1].iov_base = malloc(iov[1].iov_len);
698 memcpy(iov_copy[1].iov_base, iov[1].iov_base, iov[1].iov_len);
700 add_event(c, iov_copy);
708 qb_rc = qb_ipcs_response_sendv(c->
ipcs, iov, 2);
709 if (qb_rc < header->qb.size) {
713 crm_notice(
"Response %d to pid %d failed: %s " 714 CRM_XS " bytes=%u rc=%lld ipcs=%p",
716 header->
qb.size, (
long long) qb_rc, c->
ipcs);
719 crm_trace(
"Response %d sent, %lld bytes to %p[%d]",
720 header->
qb.id, (
long long) qb_rc, c->
ipcs, c->
pid);
729 rc = crm_ipcs_flush_events(c);
731 crm_ipcs_flush_events(c);
734 if ((
rc == EPIPE) || (
rc == ENOTCONN)) {
744 struct iovec *iov = NULL;
780 uint32_t request, uint32_t
flags,
const char *tag,
788 crm_trace(
"Ack'ing IPC message from %s as <%s status=%d>",
813 qb_ipcs_service_t **ipcs_rw,
814 qb_ipcs_service_t **ipcs_shm,
815 struct qb_ipcs_service_handlers *ro_cb,
816 struct qb_ipcs_service_handlers *rw_cb)
819 QB_IPC_NATIVE, ro_cb);
822 QB_IPC_NATIVE, rw_cb);
827 if (*ipcs_ro == NULL || *ipcs_rw == NULL || *ipcs_shm == NULL) {
828 crm_err(
"Failed to create the CIB manager: exiting and inhibiting respawn");
829 crm_warn(
"Verify pacemaker and pacemaker_remote are not both enabled");
847 qb_ipcs_service_t *ipcs_rw,
848 qb_ipcs_service_t *ipcs_shm)
850 qb_ipcs_destroy(ipcs_ro);
851 qb_ipcs_destroy(ipcs_rw);
852 qb_ipcs_destroy(ipcs_shm);
879 struct qb_ipcs_service_handlers *cb)
884 crm_err(
"Failed to create pacemaker-attrd server: exiting and inhibiting respawn");
885 crm_warn(
"Verify pacemaker and pacemaker_remote are not both enabled.");
900 struct qb_ipcs_service_handlers *cb)
906 crm_err(
"Failed to create fencer: exiting and inhibiting respawn.");
907 crm_warn(
"Verify pacemaker and pacemaker_remote are not both enabled.");
928 || !strcmp(
name,
"stonith-ng")
929 || !strcmp(
name,
"attrd")
#define CRM_CHECK(expr, failure_action)
#define PCMK__SERVER_BASED_RW
const char * pcmk__message_name(const char *name)
Get name to be used as identifier for cluster messages.
void pcmk__drop_all_clients(qb_ipcs_service_t *service)
#define crm_notice(fmt, args...)
const char * pcmk__client_name(pcmk__client_t *c)
const char * bz2_strerror(int rc)
char * crm_generate_uuid(void)
void pcmk__client_cleanup(void)
int pcmk__ipc_prepare_iov(uint32_t request, xmlNode *message, uint32_t max_send_size, struct iovec **result, ssize_t *bytes)
void pcmk__free_client(pcmk__client_t *c)
_Noreturn crm_exit_t crm_exit(crm_exit_t rc)
pcmk__client_t * pcmk__new_client(qb_ipcs_connection_t *c, uid_t uid_client, gid_t gid_client)
bool crm_is_daemon_name(const char *name)
Check whether string represents a client name used by cluster daemons.
qb_ipcs_service_t * mainloop_add_ipc_server_with_prio(const char *name, enum qb_ipc_type type, struct qb_ipcs_service_handlers *callbacks, enum qb_loop_priority prio)
Start server-side API end-point, hooked into the internal event loop.
xmlNode * pcmk__client_data2xml(pcmk__client_t *c, void *data, uint32_t *id, uint32_t *flags)
int pcmk__client_pid(qb_ipcs_connection_t *c)
const char * crm_xml_add_int(xmlNode *node, const char *name, int value)
Create an XML attribute with specified name and integer value.
const char * crm_xml_add(xmlNode *node, const char *name, const char *value)
Create an XML attribute with specified name and value.
void pcmk_free_ipc_event(struct iovec *event)
Free an I/O vector created by pcmk__ipc_prepare_iov()
enum crm_exit_e crm_exit_t
#define CRM_LOG_ASSERT(expr)
guint pcmk__ipc_client_count()
int pcmk_daemon_user(uid_t *uid, gid_t *gid)
Get user and group IDs of pacemaker daemon user.
struct pcmk__ipc_header_s pcmk__ipc_header_t
const char * pcmk_rc_str(int rc)
Get a user-friendly description of a return code.
void pcmk__foreach_ipc_client(GHFunc func, gpointer user_data)
xmlNode * string2xml(const char *input)
void pcmk__serve_attrd_ipc(qb_ipcs_service_t **ipcs, struct qb_ipcs_service_handlers *cb)
pcmk__client_t * pcmk__new_unauth_client(void *key)
Allocate a new pcmk__client_t object and generate its ID.
#define pcmk__set_client_flags(client, flags_to_set)
void pcmk__serve_fenced_ipc(qb_ipcs_service_t **ipcs, struct qb_ipcs_service_handlers *cb)
#define crm_warn(fmt, args...)
pcmk__client_t * pcmk__find_client_by_id(const char *id)
#define PCMK__IPC_VERSION
#define crm_debug(fmt, args...)
#define crm_trace(fmt, args...)
#define pcmk_is_set(g, f)
Convenience alias for pcmk_all_flags_set(), to check single flag.
G_GNUC_INTERNAL bool pcmk__valid_ipc_header(const pcmk__ipc_header_t *header)
int pcmk__ipc_send_xml(pcmk__client_t *c, uint32_t request, xmlNode *message, uint32_t flags)
xmlNode * create_xml_node(xmlNode *parent, const char *name)
int pcmk__compress(const char *data, unsigned int length, unsigned int max, char **result, unsigned int *result_len)
unsigned int crm_ipc_default_buffer_size(void)
Return pacemaker's default IPC buffer size.
void free_xml(xmlNode *child)
#define PCMK__SERVER_BASED_RO
qb_ipcs_service_t * pcmk__serve_controld_ipc(struct qb_ipcs_service_handlers *cb)
int pcmk__ipc_send_iov(pcmk__client_t *c, struct iovec *iov, uint32_t flags)
#define CRM_SYSTEM_STONITHD
#define PCMK_IPC_DEFAULT_QUEUE_MAX
long long crm_parse_ll(const char *text, const char *default_text)
Parse a long long integer value from a string.
#define CRM_SYSTEM_TENGINE
bool pcmk__set_client_queue_max(pcmk__client_t *client, const char *qmax)
#define crm_perror(level, fmt, args...)
Send a system error message to both the log and stderr.
#define pcmk__set_ipc_flags(ipc_flags, ipc_name, flags_to_set)
#define crm_err(fmt, args...)
void pcmk__serve_based_ipc(qb_ipcs_service_t **ipcs_ro, qb_ipcs_service_t **ipcs_rw, qb_ipcs_service_t **ipcs_shm, struct qb_ipcs_service_handlers *ro_cb, struct qb_ipcs_service_handlers *rw_cb)
char * dump_xml_unformatted(xmlNode *msg)
#define pcmk__plural_s(i)
pcmk__client_t * pcmk__find_client(qb_ipcs_connection_t *c)
IPC interface to Pacemaker daemons.
#define crm_log_xml_trace(xml, text)
#define PCMK__SERVER_BASED_SHM
struct pcmk__remote_s * remote
char * pcmk__uid2username(uid_t uid)
qb_ipcs_service_t * mainloop_add_ipc_server(const char *name, enum qb_ipc_type type, struct qb_ipcs_service_handlers *callbacks)
void pcmk__stop_based_ipc(qb_ipcs_service_t *ipcs_ro, qb_ipcs_service_t *ipcs_rw, qb_ipcs_service_t *ipcs_shm)
unsigned int queue_backlog
qb_ipcs_connection_t * ipcs
int pcmk__ipc_send_ack_as(const char *function, int line, pcmk__client_t *c, uint32_t request, uint32_t flags, const char *tag, crm_exit_t status)