pacemaker  2.1.7-0f7f88312f
Scalable High-Availability cluster resource manager
lrmd.h
Go to the documentation of this file.
1 /*
2  * Copyright 2012-2022 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_LRMD__H
11 # define PCMK__CRM_LRMD__H
12 
13 #include <stdbool.h> // bool
14 #include <glib.h> // guint, GList
15 #include <crm_config.h>
16 #include <crm/lrmd_events.h>
17 #include <crm/services.h>
18 
19 #ifdef __cplusplus
20 extern "C" {
21 #endif
22 
29 typedef struct lrmd_s lrmd_t;
30 typedef struct lrmd_key_value_s {
31  char *key;
32  char *value;
35 
36 /* This should be bumped every time there is an incompatible change that
37  * prevents older clients from connecting to this version of the server.
38  */
39 #define LRMD_PROTOCOL_VERSION "1.1"
40 
41 /* This is the version that the client version will actually be compared
42  * against. This should be identical to LRMD_PROTOCOL_VERSION. However, we
43  * accidentally bumped LRMD_PROTOCOL_VERSION in 6424a647 (1.1.15) when we didn't
44  * need to, so for now it's different. If we ever have a truly incompatible
45  * bump, we can drop this and compare against LRMD_PROTOCOL_VERSION.
46  */
47 #define LRMD_MIN_PROTOCOL_VERSION "1.0"
48 
49 /* *INDENT-OFF* */
50 #define DEFAULT_REMOTE_KEY_LOCATION PACEMAKER_CONFIG_DIR "/authkey"
51 #define ALT_REMOTE_KEY_LOCATION "/etc/corosync/authkey"
52 #define DEFAULT_REMOTE_PORT 3121
53 #define DEFAULT_REMOTE_USERNAME "lrmd"
54 
55 #define F_LRMD_OPERATION "lrmd_op"
56 #define F_LRMD_CLIENTNAME "lrmd_clientname"
57 #define F_LRMD_IS_IPC_PROVIDER "lrmd_is_ipc_provider"
58 #define F_LRMD_CLIENTID "lrmd_clientid"
59 #define F_LRMD_PROTOCOL_VERSION "lrmd_protocol_version"
60 #define F_LRMD_REMOTE_MSG_TYPE "lrmd_remote_msg_type"
61 #define F_LRMD_REMOTE_MSG_ID "lrmd_remote_msg_id"
62 #define F_LRMD_CALLBACK_TOKEN "lrmd_async_id"
63 #define F_LRMD_CALLID "lrmd_callid"
64 #define F_LRMD_CALLOPTS "lrmd_callopt"
65 #define F_LRMD_CALLDATA "lrmd_calldata"
66 #define F_LRMD_RC "lrmd_rc"
67 #define F_LRMD_EXEC_RC "lrmd_exec_rc"
68 #define F_LRMD_OP_STATUS "lrmd_exec_op_status"
69 #define F_LRMD_TIMEOUT "lrmd_timeout"
70 #define F_LRMD_WATCHDOG "lrmd_watchdog"
71 #define F_LRMD_CLASS "lrmd_class"
72 #define F_LRMD_PROVIDER "lrmd_provider"
73 #define F_LRMD_TYPE "lrmd_type"
74 #define F_LRMD_ORIGIN "lrmd_origin"
75 
76 #define F_LRMD_RSC_RUN_TIME "lrmd_run_time"
77 #define F_LRMD_RSC_RCCHANGE_TIME "lrmd_rcchange_time"
78 #define F_LRMD_RSC_EXEC_TIME "lrmd_exec_time"
79 #define F_LRMD_RSC_QUEUE_TIME "lrmd_queue_time"
80 
81 #define F_LRMD_RSC_ID "lrmd_rsc_id"
82 #define F_LRMD_RSC_ACTION "lrmd_rsc_action"
83 #define F_LRMD_RSC_USERDATA_STR "lrmd_rsc_userdata_str"
84 #define F_LRMD_RSC_OUTPUT "lrmd_rsc_output"
85 #define F_LRMD_RSC_EXIT_REASON "lrmd_rsc_exit_reason"
86 #define F_LRMD_RSC_START_DELAY "lrmd_rsc_start_delay"
87 #define F_LRMD_RSC_INTERVAL "lrmd_rsc_interval"
88 #define F_LRMD_RSC_DELETED "lrmd_rsc_deleted"
89 #define F_LRMD_RSC "lrmd_rsc"
90 
91 #define F_LRMD_ALERT_ID "lrmd_alert_id"
92 #define F_LRMD_ALERT_PATH "lrmd_alert_path"
93 #define F_LRMD_ALERT "lrmd_alert"
94 
95 #define LRMD_OP_RSC_REG "lrmd_rsc_register"
96 #define LRMD_OP_RSC_EXEC "lrmd_rsc_exec"
97 #define LRMD_OP_RSC_CANCEL "lrmd_rsc_cancel"
98 #define LRMD_OP_RSC_UNREG "lrmd_rsc_unregister"
99 #define LRMD_OP_RSC_INFO "lrmd_rsc_info"
100 #define LRMD_OP_RSC_METADATA "lrmd_rsc_metadata"
101 #define LRMD_OP_POKE "lrmd_rsc_poke"
102 #define LRMD_OP_NEW_CLIENT "lrmd_rsc_new_client"
103 #define LRMD_OP_CHECK "lrmd_check"
104 #define LRMD_OP_ALERT_EXEC "lrmd_alert_exec"
105 #define LRMD_OP_GET_RECURRING "lrmd_get_recurring"
106 
107 #define LRMD_IPC_OP_NEW "new"
108 #define LRMD_IPC_OP_DESTROY "destroy"
109 #define LRMD_IPC_OP_EVENT "event"
110 #define LRMD_IPC_OP_REQUEST "request"
111 #define LRMD_IPC_OP_RESPONSE "response"
112 #define LRMD_IPC_OP_SHUTDOWN_REQ "shutdown_req"
113 #define LRMD_IPC_OP_SHUTDOWN_ACK "shutdown_ack"
114 #define LRMD_IPC_OP_SHUTDOWN_NACK "shutdown_nack"
115 
116 #define F_LRMD_IPC_OP "lrmd_ipc_op"
117 #define F_LRMD_IPC_IPC_SERVER "lrmd_ipc_server"
118 #define F_LRMD_IPC_SESSION "lrmd_ipc_session"
119 #define F_LRMD_IPC_CLIENT "lrmd_ipc_client"
120 #define F_LRMD_IPC_USER "lrmd_ipc_user"
121 #define F_LRMD_IPC_MSG "lrmd_ipc_msg"
122 #define F_LRMD_IPC_MSG_ID "lrmd_ipc_msg_id"
123 #define F_LRMD_IPC_MSG_FLAGS "lrmd_ipc_msg_flags"
124 
125 #define T_LRMD "lrmd"
126 #define T_LRMD_REPLY "lrmd_reply"
127 #define T_LRMD_NOTIFY "lrmd_notify"
128 #define T_LRMD_IPC_PROXY "lrmd_ipc_proxy"
129 #define T_LRMD_RSC_OP "lrmd_rsc_op"
130 /* *INDENT-ON* */
131 
135 lrmd_t *lrmd_api_new(void);
136 
149 lrmd_t *lrmd_remote_api_new(const char *nodename, const char *server, int port);
150 
158 bool lrmd_dispatch(lrmd_t *lrmd);
159 
172 int lrmd_poll(lrmd_t *lrmd, int timeout);
173 
179 void lrmd_api_delete(lrmd_t *lrmd);
180 
181 lrmd_key_value_t *lrmd_key_value_add(lrmd_key_value_t * kvp, const char *key, const char *value);
182 
185 
188 
202 
205 };
206 
207 typedef struct lrmd_rsc_info_s {
208  char *id;
209  char *type;
210  char *standard;
211  char *provider;
213 
214 typedef struct lrmd_op_info_s {
215  char *rsc_id;
216  char *action;
220 
221 lrmd_rsc_info_t *lrmd_new_rsc_info(const char *rsc_id, const char *standard,
222  const char *provider, const char *type);
224 void lrmd_free_rsc_info(lrmd_rsc_info_t * rsc_info);
225 void lrmd_free_op_info(lrmd_op_info_t *op_info);
226 
227 typedef void (*lrmd_event_callback) (lrmd_event_data_t * event);
228 
229 typedef struct lrmd_list_s {
230  const char *val;
231  struct lrmd_list_s *next;
232 } lrmd_list_t;
233 
234 void lrmd_list_freeall(lrmd_list_t * head);
236 
237 typedef struct lrmd_api_operations_s {
248  int (*connect) (lrmd_t *lrmd, const char *client_name, int *fd);
249 
262  int (*connect_async) (lrmd_t *lrmd, const char *client_name,
263  int timeout /*ms */ );
264 
272  int (*is_connected) (lrmd_t *lrmd);
273 
284  int (*poke_connection) (lrmd_t *lrmd);
285 
293  int (*disconnect) (lrmd_t *lrmd);
294 
309  int (*register_rsc) (lrmd_t *lrmd, const char *rsc_id, const char *standard,
310  const char *provider, const char *agent,
311  enum lrmd_call_options options);
312 
322  lrmd_rsc_info_t *(*get_rsc_info) (lrmd_t *lrmd, const char *rsc_id,
323  enum lrmd_call_options options);
324 
336  int (*get_recurring_ops) (lrmd_t *lrmd, const char *rsc_id, int timeout_ms,
337  enum lrmd_call_options options, GList **output);
338 
353  int (*unregister_rsc) (lrmd_t *lrmd, const char *rsc_id,
354  enum lrmd_call_options options);
355 
362  void (*set_callback) (lrmd_t *lrmd, lrmd_event_callback callback);
363 
389  int (*exec) (lrmd_t *lrmd, const char *rsc_id, const char *action,
390  const char *userdata, guint interval_ms, int timeout,
391  int start_delay, enum lrmd_call_options options,
392  lrmd_key_value_t *params);
393 
412  int (*cancel) (lrmd_t *lrmd, const char *rsc_id, const char *action,
413  guint interval_ms);
414 
436  int (*get_metadata) (lrmd_t *lrmd, const char *standard,
437  const char *provider, const char *agent,
438  char **output, enum lrmd_call_options options);
439 
454  int (*list_agents) (lrmd_t *lrmd, lrmd_list_t **agents,
455  const char *standard, const char *provider);
456 
469  int (*list_ocf_providers) (lrmd_t *lrmd, const char *agent,
470  lrmd_list_t **providers);
471 
483  int (*list_standards) (lrmd_t *lrmd, lrmd_list_t **standards);
484 
503  int (*exec_alert) (lrmd_t *lrmd, const char *alert_id,
504  const char *alert_path, int timeout,
505  lrmd_key_value_t *params);
506 
523  int (*get_metadata_params) (lrmd_t *lrmd, const char *standard,
524  const char *provider, const char *agent,
525  char **output, enum lrmd_call_options options,
526  lrmd_key_value_t *params);
527 
529 
530 struct lrmd_s {
533 };
534 
535 static inline const char *
536 lrmd_event_type2str(enum lrmd_callback_event type)
537 {
538  switch (type) {
539  case lrmd_event_register:
540  return "register";
542  return "unregister";
544  return "exec_complete";
546  return "disconnect";
547  case lrmd_event_connect:
548  return "connect";
549  case lrmd_event_poke:
550  return "poke";
552  return "new_client";
553  }
554  return "unknown";
555 }
556 
557 #ifdef __cplusplus
558 }
559 #endif
560 
561 #endif
Services API.
char * rsc_id
Definition: lrmd.h:215
struct lrmd_rsc_info_s lrmd_rsc_info_t
lrmd_call_options
Definition: lrmd.h:183
int(* get_recurring_ops)(lrmd_t *lrmd, const char *rsc_id, int timeout_ms, enum lrmd_call_options options, GList **output)
Retrieve recurring operations registered for a resource.
Definition: lrmd.h:336
int(* connect_async)(lrmd_t *lrmd, const char *client_name, int timeout)
Initiate an executor connection without blocking.
Definition: lrmd.h:262
void(* lrmd_event_callback)(lrmd_event_data_t *event)
Definition: lrmd.h:227
void lrmd_free_op_info(lrmd_op_info_t *op_info)
Definition: lrmd_client.c:1826
char * id
Definition: lrmd.h:208
void lrmd_list_freeall(lrmd_list_t *head)
Definition: lrmd_client.c:131
enum crm_ais_msg_types type
Definition: cpg.c:48
int(* cancel)(lrmd_t *lrmd, const char *rsc_id, const char *action, guint interval_ms)
Cancel a recurring resource action.
Definition: lrmd.h:412
lrmd_t * lrmd_remote_api_new(const char *nodename, const char *server, int port)
Create a new TLS connection to a remote executor.
Definition: lrmd_client.c:2344
Send notifications for recurring operations only when the result changes.
Definition: lrmd.h:204
const char * action
Definition: pcmk_fence.c:30
const char * val
Definition: lrmd.h:230
struct lrmd_api_operations_s lrmd_api_operations_t
int(* exec)(lrmd_t *lrmd, const char *rsc_id, const char *action, const char *userdata, guint interval_ms, int timeout, int start_delay, enum lrmd_call_options options, lrmd_key_value_t *params)
Request execution of a resource action.
Definition: lrmd.h:389
char * interval_ms_s
Definition: lrmd.h:217
lrmd_rsc_info_t * lrmd_new_rsc_info(const char *rsc_id, const char *standard, const char *provider, const char *type)
Definition: lrmd_client.c:1755
lrmd_rsc_info_t * lrmd_copy_rsc_info(lrmd_rsc_info_t *rsc_info)
Definition: lrmd_client.c:1769
int(* exec_alert)(lrmd_t *lrmd, const char *alert_id, const char *alert_path, int timeout, lrmd_key_value_t *params)
Execute an alert agent.
Definition: lrmd.h:503
int(* poke_connection)(lrmd_t *lrmd)
Poke executor connection to verify it is still active.
Definition: lrmd.h:284
char * key
Definition: lrmd.h:31
struct lrmd_list_s * next
Definition: lrmd.h:231
int(* connect)(lrmd_t *lrmd, const char *client_name, int *fd)
Connect to an executor.
Definition: lrmd.h:248
lrmd_t * lrmd_api_new(void)
Create a new connection to the local executor.
Definition: lrmd_client.c:2335
bool lrmd_dispatch(lrmd_t *lrmd)
Use after lrmd_poll returns 1 to read and dispatch a message.
Definition: lrmd_client.c:481
lrmd_key_value_t * lrmd_key_value_add(lrmd_key_value_t *kvp, const char *key, const char *value)
Definition: lrmd_client.c:146
int(* get_metadata_params)(lrmd_t *lrmd, const char *standard, const char *provider, const char *agent, char **output, enum lrmd_call_options options, lrmd_key_value_t *params)
Retrieve resource agent metadata synchronously with parameters.
Definition: lrmd.h:523
Notify only the client that made the request (rather than all clients)
Definition: lrmd.h:187
struct lrmd_key_value_s * next
Definition: lrmd.h:33
int(* list_agents)(lrmd_t *lrmd, lrmd_list_t **agents, const char *standard, const char *provider)
Retrieve a list of installed resource agents.
Definition: lrmd.h:454
int(* unregister_rsc)(lrmd_t *lrmd, const char *rsc_id, enum lrmd_call_options options)
Unregister a resource from the executor.
Definition: lrmd.h:353
int(* disconnect)(lrmd_t *lrmd)
Disconnect from the executor.
Definition: lrmd.h:293
char * action
Definition: lrmd.h:216
void lrmd_key_value_freeall(lrmd_key_value_t *head)
Definition: lrmd_client.c:169
void * lrmd_private
Definition: lrmd.h:532
char * type
Definition: lrmd.h:209
struct lrmd_key_value_s lrmd_key_value_t
lrmd_api_operations_t * cmds
Definition: lrmd.h:531
int(* list_standards)(lrmd_t *lrmd, lrmd_list_t **standards)
Retrieve a list of supported standards.
Definition: lrmd.h:483
char * standard
Definition: lrmd.h:210
char * provider
Definition: lrmd.h:211
Definition: lrmd.h:530
int lrmd_poll(lrmd_t *lrmd, int timeout)
Check whether a message is available on an executor connection.
Definition: lrmd_client.c:447
int(* list_ocf_providers)(lrmd_t *lrmd, const char *agent, lrmd_list_t **providers)
Retrieve a list of resource agent providers.
Definition: lrmd.h:469
struct lrmd_list_s lrmd_list_t
int(* register_rsc)(lrmd_t *lrmd, const char *rsc_id, const char *standard, const char *provider, const char *agent, enum lrmd_call_options options)
Register a resource with the executor.
Definition: lrmd.h:309
void lrmd_free_rsc_info(lrmd_rsc_info_t *rsc_info)
Definition: lrmd_client.c:1776
struct lrmd_op_info_s lrmd_op_info_t
void lrmd_api_delete(lrmd_t *lrmd)
Destroy executor connection object.
Definition: lrmd_client.c:2353
char * timeout_ms_s
Definition: lrmd.h:218
lrmd_callback_event
Definition: lrmd_events.h:26
Resource agent executor events.
unsigned int timeout
Definition: pcmk_fence.c:32
char * value
Definition: lrmd.h:32
int(* is_connected)(lrmd_t *lrmd)
Check whether connection to executor daemon is (still) active.
Definition: lrmd.h:272
int(* get_metadata)(lrmd_t *lrmd, const char *standard, const char *provider, const char *agent, char **output, enum lrmd_call_options options)
Retrieve resource agent metadata synchronously.
Definition: lrmd.h:436
void(* set_callback)(lrmd_t *lrmd, lrmd_event_callback callback)
Set a callback for executor events.
Definition: lrmd.h:362