pacemaker  2.0.2-debe490
Scalable High-Availability cluster resource manager
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
lrmd.h
Go to the documentation of this file.
1 /*
2  * Copyright 2012-2018 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 LRMD__H
11 # define LRMD__H
12 
13 #ifdef __cplusplus
14 extern "C" {
15 #endif
16 
22 #include <stdbool.h>
23 #include <crm_config.h>
24 #include <crm/services.h>
25 
26 typedef struct lrmd_s lrmd_t;
27 typedef struct lrmd_key_value_s {
28  char *key;
29  char *value;
32 
33 /* This should be bumped every time there is an incompatible change that
34  * prevents older clients from connecting to this version of the server.
35  */
36 #define LRMD_PROTOCOL_VERSION "1.1"
37 
38 /* This is the version that the client version will actually be compared
39  * against. This should be identical to LRMD_PROTOCOL_VERSION. However, we
40  * accidentally bumped LRMD_PROTOCOL_VERSION in 6424a647 (1.1.15) when we didn't
41  * need to, so for now it's different. If we ever have a truly incompatible
42  * bump, we can drop this and compare against LRMD_PROTOCOL_VERSION.
43  */
44 #define LRMD_MIN_PROTOCOL_VERSION "1.0"
45 
46 /* *INDENT-OFF* */
47 #define DEFAULT_REMOTE_KEY_LOCATION PACEMAKER_CONFIG_DIR "/authkey"
48 #define ALT_REMOTE_KEY_LOCATION "/etc/corosync/authkey"
49 #define DEFAULT_REMOTE_PORT 3121
50 #define DEFAULT_REMOTE_USERNAME "lrmd"
51 
52 #define F_LRMD_OPERATION "lrmd_op"
53 #define F_LRMD_CLIENTNAME "lrmd_clientname"
54 #define F_LRMD_IS_IPC_PROVIDER "lrmd_is_ipc_provider"
55 #define F_LRMD_CLIENTID "lrmd_clientid"
56 #define F_LRMD_PROTOCOL_VERSION "lrmd_protocol_version"
57 #define F_LRMD_REMOTE_MSG_TYPE "lrmd_remote_msg_type"
58 #define F_LRMD_REMOTE_MSG_ID "lrmd_remote_msg_id"
59 #define F_LRMD_CALLBACK_TOKEN "lrmd_async_id"
60 #define F_LRMD_CALLID "lrmd_callid"
61 #define F_LRMD_CALLOPTS "lrmd_callopt"
62 #define F_LRMD_CALLDATA "lrmd_calldata"
63 #define F_LRMD_RC "lrmd_rc"
64 #define F_LRMD_EXEC_RC "lrmd_exec_rc"
65 #define F_LRMD_OP_STATUS "lrmd_exec_op_status"
66 #define F_LRMD_TIMEOUT "lrmd_timeout"
67 #define F_LRMD_WATCHDOG "lrmd_watchdog"
68 #define F_LRMD_CLASS "lrmd_class"
69 #define F_LRMD_PROVIDER "lrmd_provider"
70 #define F_LRMD_TYPE "lrmd_type"
71 #define F_LRMD_ORIGIN "lrmd_origin"
72 
73 #define F_LRMD_RSC_RUN_TIME "lrmd_run_time"
74 #define F_LRMD_RSC_RCCHANGE_TIME "lrmd_rcchange_time"
75 #define F_LRMD_RSC_EXEC_TIME "lrmd_exec_time"
76 #define F_LRMD_RSC_QUEUE_TIME "lrmd_queue_time"
77 
78 #define F_LRMD_RSC_ID "lrmd_rsc_id"
79 #define F_LRMD_RSC_ACTION "lrmd_rsc_action"
80 #define F_LRMD_RSC_USERDATA_STR "lrmd_rsc_userdata_str"
81 #define F_LRMD_RSC_OUTPUT "lrmd_rsc_output"
82 #define F_LRMD_RSC_EXIT_REASON "lrmd_rsc_exit_reason"
83 #define F_LRMD_RSC_START_DELAY "lrmd_rsc_start_delay"
84 #define F_LRMD_RSC_INTERVAL "lrmd_rsc_interval"
85 #define F_LRMD_RSC_DELETED "lrmd_rsc_deleted"
86 #define F_LRMD_RSC "lrmd_rsc"
87 
88 #define F_LRMD_ALERT_ID "lrmd_alert_id"
89 #define F_LRMD_ALERT_PATH "lrmd_alert_path"
90 #define F_LRMD_ALERT "lrmd_alert"
91 
92 #define LRMD_OP_RSC_REG "lrmd_rsc_register"
93 #define LRMD_OP_RSC_EXEC "lrmd_rsc_exec"
94 #define LRMD_OP_RSC_CANCEL "lrmd_rsc_cancel"
95 #define LRMD_OP_RSC_UNREG "lrmd_rsc_unregister"
96 #define LRMD_OP_RSC_INFO "lrmd_rsc_info"
97 #define LRMD_OP_RSC_METADATA "lrmd_rsc_metadata"
98 #define LRMD_OP_POKE "lrmd_rsc_poke"
99 #define LRMD_OP_NEW_CLIENT "lrmd_rsc_new_client"
100 #define LRMD_OP_CHECK "lrmd_check"
101 #define LRMD_OP_ALERT_EXEC "lrmd_alert_exec"
102 #define LRMD_OP_GET_RECURRING "lrmd_get_recurring"
103 
104 #define LRMD_IPC_OP_NEW "new"
105 #define LRMD_IPC_OP_DESTROY "destroy"
106 #define LRMD_IPC_OP_EVENT "event"
107 #define LRMD_IPC_OP_REQUEST "request"
108 #define LRMD_IPC_OP_RESPONSE "response"
109 #define LRMD_IPC_OP_SHUTDOWN_REQ "shutdown_req"
110 #define LRMD_IPC_OP_SHUTDOWN_ACK "shutdown_ack"
111 #define LRMD_IPC_OP_SHUTDOWN_NACK "shutdown_nack"
112 
113 #define F_LRMD_IPC_OP "lrmd_ipc_op"
114 #define F_LRMD_IPC_IPC_SERVER "lrmd_ipc_server"
115 #define F_LRMD_IPC_SESSION "lrmd_ipc_session"
116 #define F_LRMD_IPC_CLIENT "lrmd_ipc_client"
117 #define F_LRMD_IPC_USER "lrmd_ipc_user"
118 #define F_LRMD_IPC_MSG "lrmd_ipc_msg"
119 #define F_LRMD_IPC_MSG_ID "lrmd_ipc_msg_id"
120 #define F_LRMD_IPC_MSG_FLAGS "lrmd_ipc_msg_flags"
121 
122 #define T_LRMD "lrmd"
123 #define T_LRMD_REPLY "lrmd_reply"
124 #define T_LRMD_NOTIFY "lrmd_notify"
125 #define T_LRMD_IPC_PROXY "lrmd_ipc_proxy"
126 #define T_LRMD_RSC_OP "lrmd_rsc_op"
127 /* *INDENT-ON* */
128 
132 lrmd_t *lrmd_api_new(void);
133 
143 lrmd_t *lrmd_remote_api_new(const char *nodename, const char *server, int port);
144 
152 bool lrmd_dispatch(lrmd_t * lrmd);
153 
161 int lrmd_poll(lrmd_t * lrmd, int timeout);
162 
166 void lrmd_api_delete(lrmd_t * lrmd);
167 lrmd_key_value_t *lrmd_key_value_add(lrmd_key_value_t * kvp, const char *key, const char *value);
168 
169 /* *INDENT-OFF* */
170 /* Reserved for future use */
172  lrmd_opt_none = 0x00000000,
173  /* lrmd_opt_sync_call = 0x00000001, //Not implemented, patches welcome. */
183 };
184 
193 };
194 
195 /* *INDENT-ON* */
196 
197 typedef struct lrmd_event_data_s {
200 
202  const char *rsc_id;
204  const char *op_type;
206  const char *user_data;
207 
209  int call_id;
211  int timeout;
213  guint interval_ms;
218 
224  const char *output;
226  unsigned int t_run;
228  unsigned int t_rcchange;
230  unsigned int exec_time;
232  unsigned int queue_time;
233 
236 
237  /* This is a GHashTable containing the
238  * parameters given to the operation */
239  void *params;
240 
244  const char *remote_nodename;
245 
247  const char *exit_reason;
249 
251 void lrmd_free_event(lrmd_event_data_t * event);
252 
253 typedef struct lrmd_rsc_info_s {
254  char *id;
255  char *type;
256  char *standard;
257  char *provider;
259 
260 typedef struct lrmd_op_info_s {
261  char *rsc_id;
262  char *action;
266 
267 lrmd_rsc_info_t *lrmd_new_rsc_info(const char *rsc_id, const char *standard,
268  const char *provider, const char *type);
270 void lrmd_free_rsc_info(lrmd_rsc_info_t * rsc_info);
271 void lrmd_free_op_info(lrmd_op_info_t *op_info);
272 
273 typedef void (*lrmd_event_callback) (lrmd_event_data_t * event);
274 
275 typedef struct lrmd_list_s {
276  const char *val;
277  struct lrmd_list_s *next;
278 } lrmd_list_t;
279 
280 void lrmd_list_freeall(lrmd_list_t * head);
282 
283 typedef struct lrmd_api_operations_s {
290  int (*connect) (lrmd_t * lrmd, const char *client_name, int *fd);
291 
302  int (*connect_async) (lrmd_t * lrmd, const char *client_name, int timeout /*ms */ );
303 
310  int (*is_connected) (lrmd_t * lrmd);
311 
319  int (*poke_connection) (lrmd_t * lrmd);
320 
327  int (*disconnect) (lrmd_t * lrmd);
328 
337  int (*register_rsc) (lrmd_t * lrmd,
338  const char *rsc_id,
339  const char *standard,
340  const char *provider, const char *agent, enum lrmd_call_options options);
341 
348  lrmd_rsc_info_t *(*get_rsc_info) (lrmd_t * lrmd,
349  const char *rsc_id, enum lrmd_call_options options);
350 
356  int (*get_recurring_ops) (lrmd_t *lrmd, const char *rsc_id, int timeout_ms,
357  enum lrmd_call_options options, GList **output);
358 
373  int (*unregister_rsc) (lrmd_t * lrmd, const char *rsc_id, enum lrmd_call_options options);
374 
378  void (*set_callback) (lrmd_t * lrmd, lrmd_event_callback callback);
379 
395  int (*exec) (lrmd_t * lrmd, const char *rsc_id, const char *action, const char *userdata, /* userdata string given back in event notification */
396  guint interval_ms,
397  int timeout, /* ms */
398  int start_delay, /* ms */
399  enum lrmd_call_options options, lrmd_key_value_t * params); /* ownership of params is given up to api here */
400 
424  int (*cancel) (lrmd_t *lrmd, const char *rsc_id, const char *action,
425  guint interval_ms);
426 
450  int (*get_metadata) (lrmd_t * lrmd,
451  const char *standard,
452  const char *provider,
453  const char *agent, char **output, enum lrmd_call_options options);
454 
464  int (*list_agents) (lrmd_t * lrmd, lrmd_list_t ** agents,
465  const char *standard, const char *provider);
466 
477  int (*list_ocf_providers) (lrmd_t * lrmd, const char *agent, lrmd_list_t ** providers);
478 
487  int (*list_standards) (lrmd_t * lrmd, lrmd_list_t ** standards);
488 
504  int (*exec_alert) (lrmd_t *lrmd, const char *alert_id,
505  const char *alert_path, int timeout, /* ms */
506  lrmd_key_value_t *params); /* ownership of params is given up to api here */
507 
525  int (*get_metadata_params) (lrmd_t *lrmd, const char *standard,
526  const char *provider, const char *agent,
527  char **output, enum lrmd_call_options options,
528  lrmd_key_value_t *params);
529 
531 
532 struct lrmd_s {
535 };
536 
537 static inline const char *
538 lrmd_event_type2str(enum lrmd_callback_event type)
539 {
540  switch (type) {
541  case lrmd_event_register:
542  return "register";
544  return "unregister";
546  return "exec_complete";
548  return "disconnect";
549  case lrmd_event_connect:
550  return "connect";
551  case lrmd_event_poke:
552  return "poke";
554  return "new_client";
555  }
556  return "unknown";
557 }
558 
559 #ifdef __cplusplus
560 }
561 #endif
562 
563 #endif
Services API.
char * rsc_id
Definition: lrmd.h:261
struct lrmd_rsc_info_s lrmd_rsc_info_t
int(* get_recurring_ops)(lrmd_t *lrmd, const char *rsc_id, int timeout_ms, enum lrmd_call_options options, GList **output)
Retrieve registered recurring operations.
Definition: lrmd.h:356
lrmd_call_options
Definition: lrmd.h:171
lrmd_callback_event
Definition: lrmd.h:185
const char * user_data
Definition: lrmd.h:206
const char * rsc_id
Definition: lrmd.h:202
int(* cancel)(lrmd_t *lrmd, const char *rsc_id, const char *action, guint interval_ms)
Cancel a recurring command.
Definition: lrmd.h:424
unsigned int queue_time
Definition: lrmd.h:232
int(* poke_connection)(lrmd_t *lrmd)
Poke executor connection to verify it is still capable of serving requests.
Definition: lrmd.h:319
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)
Get resource metadata for a resource agent, passing parameters.
Definition: lrmd.h:525
void(* set_callback)(lrmd_t *lrmd, lrmd_event_callback callback)
Set a callback for executor events.
Definition: lrmd.h:378
int(* is_connected)(lrmd_t *lrmd)
Is connected to lrmd daemon?
Definition: lrmd.h:310
void lrmd_free_op_info(lrmd_op_info_t *op_info)
Definition: lrmd_client.c:1553
char * id
Definition: lrmd.h:254
void lrmd_list_freeall(lrmd_list_t *head)
Definition: lrmd_client.c:127
void lrmd_free_event(lrmd_event_data_t *event)
Definition: lrmd_client.c:202
void(* lrmd_event_callback)(lrmd_event_data_t *event)
Definition: lrmd.h:273
unsigned int t_rcchange
Definition: lrmd.h:228
const char * output
Definition: lrmd.h:224
struct lrmd_event_data_s lrmd_event_data_t
enum ocf_exitcode rc
Definition: lrmd.h:220
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:1971
int connection_rc
Definition: lrmd.h:235
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:504
int(* disconnect)(lrmd_t *lrmd)
Disconnect from the executor.
Definition: lrmd.h:327
const char * val
Definition: lrmd.h:276
struct lrmd_api_operations_s lrmd_api_operations_t
unsigned int exec_time
Definition: lrmd.h:230
int(* list_ocf_providers)(lrmd_t *lrmd, const char *agent, lrmd_list_t **providers)
Retrieve a list of resource agent providers.
Definition: lrmd.h:477
char * interval_ms_s
Definition: lrmd.h:263
void * params
Definition: lrmd.h:239
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:1470
lrmd_rsc_info_t * lrmd_copy_rsc_info(lrmd_rsc_info_t *rsc_info)
Definition: lrmd_client.c:1496
const char * exit_reason
Definition: lrmd.h:247
char * key
Definition: lrmd.h:28
struct lrmd_list_s * next
Definition: lrmd.h:277
int rsc_deleted
Definition: lrmd.h:217
lrmd_t * lrmd_api_new(void)
Create a new connection to the local executor.
Definition: lrmd_client.c:1935
bool lrmd_dispatch(lrmd_t *lrmd)
Use after lrmd_poll returns 1 to read and dispatch a message.
Definition: lrmd_client.c:418
lrmd_key_value_t * lrmd_key_value_add(lrmd_key_value_t *kvp, const char *key, const char *value)
Definition: lrmd_client.c:142
struct lrmd_key_value_s * next
Definition: lrmd.h:30
int(* get_metadata)(lrmd_t *lrmd, const char *standard, const char *provider, const char *agent, char **output, enum lrmd_call_options options)
Get resource metadata for a specified resource agent.
Definition: lrmd.h:450
int start_delay
Definition: lrmd.h:215
int(* connect_async)(lrmd_t *lrmd, const char *client_name, int timeout)
Initiate an executor connection without blocking.
Definition: lrmd.h:302
const char * op_type
Definition: lrmd.h:204
char * action
Definition: lrmd.h:262
unsigned int t_run
Definition: lrmd.h:226
void lrmd_key_value_freeall(lrmd_key_value_t *head)
Definition: lrmd_client.c:165
void * lrmd_private
Definition: lrmd.h:534
char * type
Definition: lrmd.h:255
struct lrmd_key_value_s lrmd_key_value_t
int(* connect)(lrmd_t *lrmd, const char *client_name, int *fd)
Connect to an executor.
Definition: lrmd.h:290
const char * remote_nodename
Definition: lrmd.h:244
ocf_exitcode
Definition: services.h:89
lrmd_api_operations_t * cmds
Definition: lrmd.h:533
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:337
enum lrmd_callback_event type
Definition: lrmd.h:199
int(* unregister_rsc)(lrmd_t *lrmd, const char *rsc_id, enum lrmd_call_options options)
Unregister a resource from the executor.
Definition: lrmd.h:373
char * standard
Definition: lrmd.h:256
lrmd_event_data_t * lrmd_copy_event(lrmd_event_data_t *event)
Definition: lrmd_client.c:179
char * provider
Definition: lrmd.h:257
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)
Issue a command on a resource.
Definition: lrmd.h:395
Definition: lrmd.h:532
int lrmd_poll(lrmd_t *lrmd, int timeout)
Poll for a specified timeout period to determine if a message is ready for dispatch.
Definition: lrmd_client.c:393
struct lrmd_list_s lrmd_list_t
void lrmd_free_rsc_info(lrmd_rsc_info_t *rsc_info)
Definition: lrmd_client.c:1503
struct lrmd_op_info_s lrmd_op_info_t
void lrmd_api_delete(lrmd_t *lrmd)
Destroy executor connection object.
Definition: lrmd_client.c:1998
char * timeout_ms_s
Definition: lrmd.h:264
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:464
char * value
Definition: lrmd.h:29
int(* list_standards)(lrmd_t *lrmd, lrmd_list_t **standards)
Retrieve a list of standards supported by this machine/installation.
Definition: lrmd.h:487
guint interval_ms
Definition: lrmd.h:213
enum crm_ais_msg_types type
Definition: internal.h:85