pacemaker  2.1.7-0f7f88312f
Scalable High-Availability cluster resource manager
ipc.h
Go to the documentation of this file.
1 /*
2  * Copyright 2004-2023 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 #define create_reply(request, xml_response_data) \
38  create_reply_adv(request, xml_response_data, __func__)
39 
40 xmlNode *create_reply_adv(const xmlNode *request, xmlNode *xml_response_data,
41  const char *origin);
42 
43 #define create_request(task, xml_data, host_to, sys_to, sys_from, uuid_from) \
44  create_request_adv(task, xml_data, host_to, sys_to, sys_from, uuid_from, \
45  __func__)
46 
47 xmlNode *create_request_adv(const char *task, xmlNode *xml_data,
48  const char *host_to, const char *sys_to,
49  const char *sys_from, const char *uuid_from,
50  const char *origin);
51 
52 
53 /*
54  * The library supports two methods of creating IPC connections. The older code
55  * allows connecting to any arbitrary IPC name. The newer code only allows
56  * connecting to one of the Pacemaker daemons.
57  *
58  * As daemons are converted to use the new model, the old functions should be
59  * considered deprecated for use with those daemons. Once all daemons are
60  * converted, the old functions should be officially deprecated as public API
61  * and eventually made internal API.
62  */
63 
64 /*
65  * Pacemaker daemon IPC
66  */
67 
77 };
78 
85 };
86 
92 };
93 
96 
111 typedef void (*pcmk_ipc_callback_t)(pcmk_ipc_api_t *api,
112  enum pcmk_ipc_event event_type,
113  crm_exit_t status,
114  void *event_data, void *user_data);
115 
117 
119 
121 
123 
124 int pcmk_poll_ipc(const pcmk_ipc_api_t *api, int timeout_ms);
125 
127 
129  void *user_data);
130 
131 const char *pcmk_ipc_name(const pcmk_ipc_api_t *api, bool for_log);
132 
134 
135 int pcmk_ipc_purge_node(pcmk_ipc_api_t *api, const char *node_name,
136  uint32_t nodeid);
137 
138 
139 /*
140  * Generic IPC API (to eventually be deprecated as public API and made internal)
141  */
142 
143 /* *INDENT-OFF* */
145 {
146  crm_ipc_flags_none = 0x00000000,
147 
148  crm_ipc_compressed = 0x00000001, /* Message has been compressed */
149 
150  crm_ipc_proxied = 0x00000100, /* _ALL_ replies to proxied connections need to be sent as events */
151  crm_ipc_client_response = 0x00000200, /* A Response is expected in reply */
152 
153  // These are options for Pacemaker's internal use only (pcmk__ipc_send_*())
154  crm_ipc_server_event = 0x00010000, /* Send an Event instead of a Response */
155  crm_ipc_server_free = 0x00020000, /* Free the iovec after sending */
156  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.*/
157 
158 #if !defined(PCMK_ALLOW_DEPRECATED) || (PCMK_ALLOW_DEPRECATED == 1)
159  crm_ipc_server_info = 0x00100000,
160  crm_ipc_server_error = 0x00200000,
161 #endif
162 };
163 /* *INDENT-ON* */
164 
165 typedef struct crm_ipc_s crm_ipc_t;
166 
167 crm_ipc_t *crm_ipc_new(const char *name, size_t max_size);
168 bool crm_ipc_connect(crm_ipc_t * client);
169 void crm_ipc_close(crm_ipc_t * client);
170 void crm_ipc_destroy(crm_ipc_t * client);
171 void pcmk_free_ipc_event(struct iovec *event);
172 
173 int crm_ipc_send(crm_ipc_t *client, const xmlNode *message,
174  enum crm_ipc_flags flags, int32_t ms_timeout, xmlNode **reply);
175 
176 int crm_ipc_get_fd(crm_ipc_t * client);
177 bool crm_ipc_connected(crm_ipc_t * client);
178 int crm_ipc_ready(crm_ipc_t * client);
179 long crm_ipc_read(crm_ipc_t * client);
180 const char *crm_ipc_buffer(crm_ipc_t * client);
181 uint32_t crm_ipc_buffer_flags(crm_ipc_t * client);
182 const char *crm_ipc_name(crm_ipc_t * client);
183 unsigned int crm_ipc_default_buffer_size(void);
184 
220 int crm_ipc_is_authentic_process(int sock, uid_t refuid, gid_t refgid,
221  pid_t *gotpid, uid_t *gotuid, gid_t *gotgid);
222 
223 /* This is controller-specific but is declared in this header for C API
224  * backward compatibility.
225  */
226 xmlNode *create_hello_message(const char *uuid, const char *client_name,
227  const char *major_version, const char *minor_version);
228 
229 #ifdef __cplusplus
230 }
231 #endif
232 
233 #endif
bool crm_ipc_connect(crm_ipc_t *client)
Establish an IPC connection to a Pacemaker component.
Definition: ipc_client.c:967
enum pcmk_ipc_dispatch dispatch_type
Scheduler.
Definition: ipc.h:76
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:75
int crm_ipc_get_fd(crm_ipc_t *client)
Definition: ipc_client.c:1053
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:102
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:796
enum crm_exit_e crm_exit_t
long crm_ipc_read(crm_ipc_t *client)
Definition: ipc_client.c:1164
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:619
uint32_t crm_ipc_buffer_flags(crm_ipc_t *client)
Definition: ipc_client.c:1220
const char * crm_ipc_buffer(crm_ipc_t *client)
Definition: ipc_client.c:1213
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:71
Caller will poll and dispatch IPC.
Definition: ipc.h:90
pcmk_ipc_server
Available IPC interfaces.
Definition: ipc.h:69
struct crm_ipc_s crm_ipc_t
Definition: ipc.h:165
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:1005
void pcmk_free_ipc_event(struct iovec *event)
Free an I/O vector created by pcmk__ipc_prepare_iov()
Definition: ipc_server.c:274
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:111
bool crm_ipc_connected(crm_ipc_t *client)
Definition: ipc_client.c:1067
int crm_ipc_ready(crm_ipc_t *client)
Check whether an IPC connection is ready to be read.
Definition: ipc_client.c:1099
pcmk_ipc_dispatch
How IPC replies should be dispatched.
Definition: ipc.h:88
Notification from daemon.
Definition: ipc.h:84
pcmk_ipc_event
Possible event types that an IPC event callback can be called for.
Definition: ipc.h:80
const char * crm_ipc_name(crm_ipc_t *client)
Definition: ipc_client.c:1234
Attach IPC to GMainLoop for dispatch.
Definition: ipc.h:89
Termination of IPC connection.
Definition: ipc.h:82
Executor.
Definition: ipc.h:73
Controller.
Definition: ipc.h:72
Sending a command will wait for any reply.
Definition: ipc.h:91
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:849
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:74
Daemon&#39;s reply to client IPC request.
Definition: ipc.h:83
Result of asynchronous connection attempt.
Definition: ipc.h:81
Attribute manager.
Definition: ipc.h:70
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:1307
crm_ipc_flags
Definition: ipc.h:144
void crm_ipc_close(crm_ipc_t *client)
Definition: ipc_client.c:992
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:1579
bool pcmk_ipc_is_connected(pcmk_ipc_api_t *api)
Check whether an IPC API connection is active.
Definition: ipc_client.c:287