pacemaker  2.1.8-3980678f03
Scalable High-Availability cluster resource manager
ipc.h
Go to the documentation of this file.
1 /*
2  * Copyright 2004-2024 the Pacemaker project contributors
3  *
4  * The version control history for this file may have further details.
5  *
6  * This source code is licensed under the GNU Lesser General Public License
7  * version 2.1 or later (LGPLv2.1+) WITHOUT ANY WARRANTY.
8  */
9 
10 #ifndef PCMK__CRM_COMMON_IPC__H
11 #define PCMK__CRM_COMMON_IPC__H
12 
13 
14 #include <sys/uio.h>
15 #include <qb/qbipcc.h>
16 #include <crm/common/xml.h>
17 
18 #ifdef __cplusplus
19 extern "C" {
20 #endif
21 
29 /*
30  * Message creation utilities
31  *
32  * These are used for both IPC messages and cluster layer messages. However,
33  * since this is public API, they stay in this header for backward
34  * compatibility.
35  */
36 
37 // @COMPAT Make internal when we can break API backward compatibility
39 #define create_reply(request, xml_response_data) \
40  create_reply_adv(request, xml_response_data, __func__)
41 
42 // @COMPAT Make internal when we can break API backward compatibility
44 xmlNode *create_reply_adv(const xmlNode *request, xmlNode *xml_response_data,
45  const char *origin);
46 
47 // @COMPAT Make internal when we can break API backward compatibility
49 #define create_request(task, xml_data, host_to, sys_to, sys_from, uuid_from) \
50  create_request_adv(task, xml_data, host_to, sys_to, sys_from, uuid_from, \
51  __func__)
52 
53 // @COMPAT Make internal when we can break API backward compatibility
55 xmlNode *create_request_adv(const char *task, xmlNode *xml_data,
56  const char *host_to, const char *sys_to,
57  const char *sys_from, const char *uuid_from,
58  const char *origin);
59 
60 
61 /*
62  * The library supports two methods of creating IPC connections. The older code
63  * allows connecting to any arbitrary IPC name. The newer code only allows
64  * connecting to one of the Pacemaker daemons.
65  *
66  * As daemons are converted to use the new model, the old functions should be
67  * considered deprecated for use with those daemons. Once all daemons are
68  * converted, the old functions should be officially deprecated as public API
69  * and eventually made internal API.
70  */
71 
72 /*
73  * Pacemaker daemon IPC
74  */
75 
85 };
86 
87 // NOTE: sbd (as of at least 1.5.2) uses this enum
91 
92  // NOTE: sbd (as of at least 1.5.2) uses this value
94 
95  // NOTE: sbd (as of at least 1.5.2) uses this value
97 
99 };
100 
106 };
107 
108 // NOTE: sbd (as of at least 1.5.2) uses this
111 
126 typedef void (*pcmk_ipc_callback_t)(pcmk_ipc_api_t *api,
127  enum pcmk_ipc_event event_type,
128  crm_exit_t status,
129  void *event_data, void *user_data);
130 
131 // NOTE: sbd (as of at least 1.5.2) uses this
133 
134 // NOTE: sbd (as of at least 1.5.2) uses this
136 
137 // NOTE: sbd (as of at least 1.5.2) uses this
139 
141 
142 int pcmk_poll_ipc(const pcmk_ipc_api_t *api, int timeout_ms);
143 
145 
146 // NOTE: sbd (as of at least 1.5.2) uses this
148  void *user_data);
149 
150 const char *pcmk_ipc_name(const pcmk_ipc_api_t *api, bool for_log);
151 
153 
154 int pcmk_ipc_purge_node(pcmk_ipc_api_t *api, const char *node_name,
155  uint32_t nodeid);
156 
157 
158 /*
159  * Generic IPC API (to eventually be deprecated as public API and made internal)
160  */
161 
162 /* *INDENT-OFF* */
164 {
165  crm_ipc_flags_none = 0x00000000,
166 
167  crm_ipc_compressed = 0x00000001, /* Message has been compressed */
168 
169  crm_ipc_proxied = 0x00000100, /* _ALL_ replies to proxied connections need to be sent as events */
170  crm_ipc_client_response = 0x00000200, /* A Response is expected in reply */
171 
172  // These are options for Pacemaker's internal use only (pcmk__ipc_send_*())
173  crm_ipc_server_event = 0x00010000, /* Send an Event instead of a Response */
174  crm_ipc_server_free = 0x00020000, /* Free the iovec after sending */
175  crm_ipc_proxied_relay_response = 0x00040000, /* all replies to proxied connections are sent as events, this flag preserves whether the event should be treated as an actual event, or a response.*/
176 
177 #if !defined(PCMK_ALLOW_DEPRECATED) || (PCMK_ALLOW_DEPRECATED == 1)
178  crm_ipc_server_info = 0x00100000,
179  crm_ipc_server_error = 0x00200000,
180 #endif
181 };
182 /* *INDENT-ON* */
183 
184 typedef struct crm_ipc_s crm_ipc_t;
185 
186 crm_ipc_t *crm_ipc_new(const char *name, size_t max_size);
187 bool crm_ipc_connect(crm_ipc_t * client);
188 void crm_ipc_close(crm_ipc_t * client);
189 void crm_ipc_destroy(crm_ipc_t * client);
190 void pcmk_free_ipc_event(struct iovec *event);
191 
192 int crm_ipc_send(crm_ipc_t *client, const xmlNode *message,
193  enum crm_ipc_flags flags, int32_t ms_timeout, xmlNode **reply);
194 
195 int crm_ipc_get_fd(crm_ipc_t * client);
196 bool crm_ipc_connected(crm_ipc_t * client);
197 int crm_ipc_ready(crm_ipc_t * client);
198 long crm_ipc_read(crm_ipc_t * client);
199 const char *crm_ipc_buffer(crm_ipc_t * client);
200 uint32_t crm_ipc_buffer_flags(crm_ipc_t * client);
201 const char *crm_ipc_name(crm_ipc_t * client);
202 unsigned int crm_ipc_default_buffer_size(void);
203 
239 int crm_ipc_is_authentic_process(int sock, uid_t refuid, gid_t refgid,
240  pid_t *gotpid, uid_t *gotuid, gid_t *gotgid);
241 
242 // @COMPAT Make internal when we can break API backward compatibility
244 xmlNode *create_hello_message(const char *uuid, const char *client_name,
245  const char *major_version, const char *minor_version);
246 
247 #ifdef __cplusplus
248 }
249 #endif
250 
251 #endif
bool crm_ipc_connect(crm_ipc_t *client)
Establish an IPC connection to a Pacemaker component.
Definition: ipc_client.c:968
enum pcmk_ipc_dispatch dispatch_type
Scheduler.
Definition: ipc.h:84
int pcmk_connect_ipc(pcmk_ipc_api_t *api, enum pcmk_ipc_dispatch dispatch_type)
Connect to a Pacemaker daemon via IPC.
Definition: ipc_client.c:571
const char * name
Definition: cib.c:26
Launcher.
Definition: ipc.h:83
int crm_ipc_get_fd(crm_ipc_t *client)
Definition: ipc_client.c:1054
int pcmk_new_ipc_api(pcmk_ipc_api_t **api, enum pcmk_ipc_server server)
Create a new object for using Pacemaker daemon IPC.
Definition: ipc_client.c:51
xmlNode * create_reply_adv(const xmlNode *request, xmlNode *xml_response_data, const char *origin)
Create a Pacemaker reply (for IPC or cluster layer)
Definition: messages.c:104
void pcmk_dispatch_ipc(pcmk_ipc_api_t *api)
Dispatch available messages on an IPC connection (without main loop)
Definition: ipc_client.c:439
int pcmk_ipc_purge_node(pcmk_ipc_api_t *api, const char *node_name, uint32_t nodeid)
Ask a Pacemaker daemon to purge a node from its peer cache.
Definition: ipc_client.c:797
enum crm_exit_e crm_exit_t
long crm_ipc_read(crm_ipc_t *client)
Definition: ipc_client.c:1165
xmlNode * create_hello_message(const char *uuid, const char *client_name, const char *major_version, const char *minor_version)
Create XML for a controller IPC "hello" message.
Definition: ipc_controld.c:627
uint32_t crm_ipc_buffer_flags(crm_ipc_t *client)
Definition: ipc_client.c:1221
const char * crm_ipc_buffer(crm_ipc_t *client)
Definition: ipc_client.c:1214
int pcmk_poll_ipc(const pcmk_ipc_api_t *api, int timeout_ms)
Check whether an IPC connection has data available (without main loop)
Definition: ipc_client.c:399
CIB manager.
Definition: ipc.h:79
Caller will poll and dispatch IPC.
Definition: ipc.h:104
pcmk_ipc_server
Available IPC interfaces.
Definition: ipc.h:77
struct crm_ipc_s crm_ipc_t
Definition: ipc.h:184
pcmk_ipc_callback_t cb
Wrappers for and extensions to libxml2.
unsigned int crm_ipc_default_buffer_size(void)
Return pacemaker&#39;s default IPC buffer size.
Definition: ipc_common.c:62
void crm_ipc_destroy(crm_ipc_t *client)
Definition: ipc_client.c:1006
void pcmk_free_ipc_event(struct iovec *event)
Free an I/O vector created by pcmk__ipc_prepare_iov()
Definition: ipc_server.c:259
void(* pcmk_ipc_callback_t)(pcmk_ipc_api_t *api, enum pcmk_ipc_event event_type, crm_exit_t status, void *event_data, void *user_data)
Callback function type for Pacemaker daemon IPC APIs.
Definition: ipc.h:126
bool crm_ipc_connected(crm_ipc_t *client)
Definition: ipc_client.c:1068
int crm_ipc_ready(crm_ipc_t *client)
Check whether an IPC connection is ready to be read.
Definition: ipc_client.c:1100
pcmk_ipc_dispatch
How IPC replies should be dispatched.
Definition: ipc.h:102
Notification from daemon.
Definition: ipc.h:98
pcmk_ipc_event
Possible event types that an IPC event callback can be called for.
Definition: ipc.h:89
const char * crm_ipc_name(crm_ipc_t *client)
Definition: ipc_client.c:1235
Attach IPC to GMainLoop for dispatch.
Definition: ipc.h:103
Termination of IPC connection.
Definition: ipc.h:93
Executor.
Definition: ipc.h:81
Controller.
Definition: ipc.h:80
Sending a command will wait for any reply.
Definition: ipc.h:105
xmlNode * create_request_adv(const char *task, xmlNode *xml_data, const char *host_to, const char *sys_to, const char *sys_from, const char *uuid_from, const char *origin)
Create a Pacemaker request (for IPC or cluster layer)
Definition: messages.c:40
void pcmk_free_ipc_api(pcmk_ipc_api_t *api)
Free the contents of an IPC API object.
Definition: ipc_client.c:206
crm_ipc_t * crm_ipc_new(const char *name, size_t max_size)
Create a new (legacy) object for using Pacemaker daemon IPC.
Definition: ipc_client.c:850
const char * pcmk_ipc_name(const pcmk_ipc_api_t *api, bool for_log)
Get the IPC name used with an IPC API connection.
Definition: ipc_client.c:247
Fencer.
Definition: ipc.h:82
Daemon&#39;s reply to client IPC request.
Definition: ipc.h:96
Result of asynchronous connection attempt.
Definition: ipc.h:90
Attribute manager.
Definition: ipc.h:78
enum pcmk_ipc_server server
void pcmk_register_ipc_callback(pcmk_ipc_api_t *api, pcmk_ipc_callback_t cb, void *user_data)
Register a callback for IPC API events.
Definition: ipc_client.c:645
int crm_ipc_send(crm_ipc_t *client, const xmlNode *message, enum crm_ipc_flags flags, int32_t ms_timeout, xmlNode **reply)
Send an IPC XML message.
Definition: ipc_client.c:1308
crm_ipc_flags
Definition: ipc.h:163
void crm_ipc_close(crm_ipc_t *client)
Definition: ipc_client.c:993
void pcmk_disconnect_ipc(pcmk_ipc_api_t *api)
Disconnect an IPC API instance.
Definition: ipc_client.c:594
uint64_t flags
Definition: remote.c:215
int crm_ipc_is_authentic_process(int sock, uid_t refuid, gid_t refgid, pid_t *gotpid, uid_t *gotuid, gid_t *gotgid)
Check the authenticity of the IPC socket peer process (legacy)
Definition: ipc_client.c:1580
bool pcmk_ipc_is_connected(pcmk_ipc_api_t *api)
Check whether an IPC API connection is active.
Definition: ipc_client.c:287