pacemaker  1.1.18-7fdfbbe
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 (c) 2012 David Vossel <davidvossel@gmail.com>
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17  *
18  */
19 
20 #ifndef LRMD__H
21 # define LRMD__H
22 
28 #include <stdbool.h>
29 #include <crm/services.h>
30 
31 typedef struct lrmd_s lrmd_t;
32 typedef struct lrmd_key_value_s {
33  char *key;
34  char *value;
37 
38 /* This should be bumped every time there is an incompatible change that
39  * prevents older clients from connecting to this version of the server.
40  */
41 #define LRMD_PROTOCOL_VERSION "1.1"
42 
43 /* This is the version that the client version will actually be compared
44  * against. This should be identical to LRMD_PROTOCOL_VERSION. However, we
45  * accidentally bumped LRMD_PROTOCOL_VERSION in 6424a647 (1.1.15) when we didn't
46  * need to, so for now it's different. If we ever have a truly incompatible
47  * bump, we can drop this and compare against LRMD_PROTOCOL_VERSION.
48  */
49 #define LRMD_MIN_PROTOCOL_VERSION "1.0"
50 
51 /* *INDENT-OFF* */
52 #define DEFAULT_REMOTE_KEY_LOCATION "/etc/pacemaker/authkey"
53 #define ALT_REMOTE_KEY_LOCATION "/etc/corosync/authkey"
54 #define DEFAULT_REMOTE_PORT 3121
55 #define DEFAULT_REMOTE_USERNAME "lrmd"
56 
57 #define F_LRMD_OPERATION "lrmd_op"
58 #define F_LRMD_CLIENTNAME "lrmd_clientname"
59 #define F_LRMD_IS_IPC_PROVIDER "lrmd_is_ipc_provider"
60 #define F_LRMD_CLIENTID "lrmd_clientid"
61 #define F_LRMD_PROTOCOL_VERSION "lrmd_protocol_version"
62 #define F_LRMD_REMOTE_MSG_TYPE "lrmd_remote_msg_type"
63 #define F_LRMD_REMOTE_MSG_ID "lrmd_remote_msg_id"
64 #define F_LRMD_CALLBACK_TOKEN "lrmd_async_id"
65 #define F_LRMD_CALLID "lrmd_callid"
66 #define F_LRMD_CANCEL_CALLID "lrmd_cancel_callid"
67 #define F_LRMD_CALLOPTS "lrmd_callopt"
68 #define F_LRMD_CALLDATA "lrmd_calldata"
69 #define F_LRMD_RC "lrmd_rc"
70 #define F_LRMD_EXEC_RC "lrmd_exec_rc"
71 #define F_LRMD_OP_STATUS "lrmd_exec_op_status"
72 #define F_LRMD_TIMEOUT "lrmd_timeout"
73 #define F_LRMD_WATCHDOG "lrmd_watchdog"
74 #define F_LRMD_CLASS "lrmd_class"
75 #define F_LRMD_PROVIDER "lrmd_provider"
76 #define F_LRMD_TYPE "lrmd_type"
77 #define F_LRMD_ORIGIN "lrmd_origin"
78 
79 #define F_LRMD_RSC_RUN_TIME "lrmd_run_time"
80 #define F_LRMD_RSC_RCCHANGE_TIME "lrmd_rcchange_time"
81 #define F_LRMD_RSC_EXEC_TIME "lrmd_exec_time"
82 #define F_LRMD_RSC_QUEUE_TIME "lrmd_queue_time"
83 
84 #define F_LRMD_RSC_ID "lrmd_rsc_id"
85 #define F_LRMD_RSC_ACTION "lrmd_rsc_action"
86 #define F_LRMD_RSC_USERDATA_STR "lrmd_rsc_userdata_str"
87 #define F_LRMD_RSC_OUTPUT "lrmd_rsc_output"
88 #define F_LRMD_RSC_EXIT_REASON "lrmd_rsc_exit_reason"
89 #define F_LRMD_RSC_START_DELAY "lrmd_rsc_start_delay"
90 #define F_LRMD_RSC_INTERVAL "lrmd_rsc_interval"
91 #define F_LRMD_RSC_METADATA "lrmd_rsc_metadata_res"
92 #define F_LRMD_RSC_DELETED "lrmd_rsc_deleted"
93 #define F_LRMD_RSC "lrmd_rsc"
94 
95 #define F_LRMD_ALERT_ID "lrmd_alert_id"
96 #define F_LRMD_ALERT_PATH "lrmd_alert_path"
97 #define F_LRMD_ALERT "lrmd_alert"
98 
99 #define LRMD_OP_RSC_CHK_REG "lrmd_rsc_check_register"
100 #define LRMD_OP_RSC_REG "lrmd_rsc_register"
101 #define LRMD_OP_RSC_EXEC "lrmd_rsc_exec"
102 #define LRMD_OP_RSC_CANCEL "lrmd_rsc_cancel"
103 #define LRMD_OP_RSC_UNREG "lrmd_rsc_unregister"
104 #define LRMD_OP_RSC_INFO "lrmd_rsc_info"
105 #define LRMD_OP_RSC_METADATA "lrmd_rsc_metadata"
106 #define LRMD_OP_POKE "lrmd_rsc_poke"
107 #define LRMD_OP_NEW_CLIENT "lrmd_rsc_new_client"
108 #define LRMD_OP_CHECK "lrmd_check"
109 #define LRMD_OP_ALERT_EXEC "lrmd_alert_exec"
110 
111 #define LRMD_IPC_OP_NEW "new"
112 #define LRMD_IPC_OP_DESTROY "destroy"
113 #define LRMD_IPC_OP_EVENT "event"
114 #define LRMD_IPC_OP_REQUEST "request"
115 #define LRMD_IPC_OP_RESPONSE "response"
116 #define LRMD_IPC_OP_SHUTDOWN_REQ "shutdown_req"
117 #define LRMD_IPC_OP_SHUTDOWN_ACK "shutdown_ack"
118 #define LRMD_IPC_OP_SHUTDOWN_NACK "shutdown_nack"
119 
120 #define F_LRMD_IPC_OP "lrmd_ipc_op"
121 #define F_LRMD_IPC_IPC_SERVER "lrmd_ipc_server"
122 #define F_LRMD_IPC_SESSION "lrmd_ipc_session"
123 #define F_LRMD_IPC_CLIENT "lrmd_ipc_client"
124 #define F_LRMD_IPC_PROXY_NODE "lrmd_ipc_proxy_node"
125 #define F_LRMD_IPC_USER "lrmd_ipc_user"
126 #define F_LRMD_IPC_MSG "lrmd_ipc_msg"
127 #define F_LRMD_IPC_MSG_ID "lrmd_ipc_msg_id"
128 #define F_LRMD_IPC_MSG_FLAGS "lrmd_ipc_msg_flags"
129 
130 #define T_LRMD "lrmd"
131 #define T_LRMD_REPLY "lrmd_reply"
132 #define T_LRMD_NOTIFY "lrmd_notify"
133 #define T_LRMD_IPC_PROXY "lrmd_ipc_proxy"
134 /* *INDENT-ON* */
135 
139 lrmd_t *lrmd_api_new(void);
140 
150 lrmd_t *lrmd_remote_api_new(const char *nodename, const char *server, int port);
151 
159 bool lrmd_dispatch(lrmd_t * lrmd);
160 
168 int lrmd_poll(lrmd_t * lrmd, int timeout);
169 
173 void lrmd_api_delete(lrmd_t * lrmd);
174 lrmd_key_value_t *lrmd_key_value_add(lrmd_key_value_t * kvp, const char *key, const char *value);
175 
176 /* *INDENT-OFF* */
177 /* Reserved for future use */
179  lrmd_opt_none = 0x00000000,
180  /* lrmd_opt_sync_call = 0x00000001, //Not implemented, patches welcome. */
190 };
191 
200 };
201 
202 /* *INDENT-ON* */
203 
204 typedef struct lrmd_event_data_s {
207 
209  const char *rsc_id;
211  const char *op_type;
213  const char *user_data;
214 
216  int call_id;
218  int timeout;
220  int interval;
225 
231  const char *output;
233  unsigned int t_run;
235  unsigned int t_rcchange;
237  unsigned int exec_time;
239  unsigned int queue_time;
240 
243 
244  /* This is a GHashTable containing the
245  * parameters given to the operation */
246  void *params;
247 
251  const char *remote_nodename;
252 
254  const char *exit_reason;
256 
258 void lrmd_free_event(lrmd_event_data_t * event);
259 
260 typedef struct lrmd_rsc_info_s {
261  char *id;
262  char *type;
263  char *class;
264  char *provider;
266 
268 void lrmd_free_rsc_info(lrmd_rsc_info_t * rsc_info);
269 
270 typedef void (*lrmd_event_callback) (lrmd_event_data_t * event);
271 
272 typedef struct lrmd_list_s {
273  const char *val;
274  struct lrmd_list_s *next;
275 } lrmd_list_t;
276 
277 void lrmd_list_freeall(lrmd_list_t * head);
279 
280 typedef struct lrmd_api_operations_s {
287  int (*connect) (lrmd_t * lrmd, const char *client_name, int *fd);
288 
299  int (*connect_async) (lrmd_t * lrmd, const char *client_name, int timeout /*ms */ );
300 
307  int (*is_connected) (lrmd_t * lrmd);
308 
316  int (*poke_connection) (lrmd_t * lrmd);
317 
324  int (*disconnect) (lrmd_t * lrmd);
325 
334  int (*register_rsc) (lrmd_t * lrmd,
335  const char *rsc_id,
336  const char *class,
337  const char *provider, const char *agent, enum lrmd_call_options options);
338 
345  lrmd_rsc_info_t *(*get_rsc_info) (lrmd_t * lrmd,
346  const char *rsc_id, enum lrmd_call_options options);
347 
362  int (*unregister_rsc) (lrmd_t * lrmd, const char *rsc_id, enum lrmd_call_options options);
363 
367  void (*set_callback) (lrmd_t * lrmd, lrmd_event_callback callback);
368 
384  int (*exec) (lrmd_t * lrmd, const char *rsc_id, const char *action, const char *userdata, /* userdata string given back in event notification */
385  int interval, /* ms */
386  int timeout, /* ms */
387  int start_delay, /* ms */
388  enum lrmd_call_options options, lrmd_key_value_t * params); /* ownership of params is given up to api here */
389 
413  int (*cancel) (lrmd_t * lrmd, const char *rsc_id, const char *action, int interval);
414 
438  int (*get_metadata) (lrmd_t * lrmd,
439  const char *class,
440  const char *provider,
441  const char *agent, char **output, enum lrmd_call_options options);
442 
452  int (*list_agents) (lrmd_t * lrmd, lrmd_list_t ** agents, const char *class,
453  const char *provider);
454 
465  int (*list_ocf_providers) (lrmd_t * lrmd, const char *agent, lrmd_list_t ** providers);
466 
475  int (*list_standards) (lrmd_t * lrmd, lrmd_list_t ** standards);
476 
492  int (*exec_alert) (lrmd_t *lrmd, const char *alert_id,
493  const char *alert_path, int timeout, /* ms */
494  lrmd_key_value_t *params); /* ownership of params is given up to api here */
495 
497 
498 struct lrmd_s {
500  void *private;
501 };
502 
503 static inline const char *
504 lrmd_event_type2str(enum lrmd_callback_event type)
505 {
506  switch (type) {
507  case lrmd_event_register:
508  return "register";
510  return "unregister";
512  return "exec_complete";
514  return "disconnect";
515  case lrmd_event_connect:
516  return "connect";
517  case lrmd_event_poke:
518  return "poke";
520  return "new_client";
521  }
522  return "unknown";
523 }
524 
525 #endif
Services API.
struct lrmd_rsc_info_s lrmd_rsc_info_t
lrmd_call_options
Definition: lrmd.h:178
lrmd_callback_event
Definition: lrmd.h:192
const char * user_data
Definition: lrmd.h:213
const char * rsc_id
Definition: lrmd.h:209
int(* cancel)(lrmd_t *lrmd, const char *rsc_id, const char *action, int interval)
Cancel a recurring command.
Definition: lrmd.h:413
int(* exec)(lrmd_t *lrmd, const char *rsc_id, const char *action, const char *userdata, int interval, int timeout, int start_delay, enum lrmd_call_options options, lrmd_key_value_t *params)
Issue a command on a resource.
Definition: lrmd.h:384
unsigned int queue_time
Definition: lrmd.h:239
int(* poke_connection)(lrmd_t *lrmd)
Poke lrmd connection to verify it is still capable of serving requests.
Definition: lrmd.h:316
void(* set_callback)(lrmd_t *lrmd, lrmd_event_callback callback)
Sets the callback to receive lrmd events on.
Definition: lrmd.h:367
int(* is_connected)(lrmd_t *lrmd)
Is connected to lrmd daemon?
Definition: lrmd.h:307
char * id
Definition: lrmd.h:261
void lrmd_list_freeall(lrmd_list_t *head)
Definition: lrmd_client.c:138
void lrmd_free_event(lrmd_event_data_t *event)
Definition: lrmd_client.c:213
void(* lrmd_event_callback)(lrmd_event_data_t *event)
Definition: lrmd.h:270
unsigned int t_rcchange
Definition: lrmd.h:235
const char * output
Definition: lrmd.h:231
struct lrmd_event_data_s lrmd_event_data_t
enum ocf_exitcode rc
Definition: lrmd.h:227
lrmd_t * lrmd_remote_api_new(const char *nodename, const char *server, int port)
Create a new remote lrmd connection using tls backend.
Definition: lrmd_client.c:1855
int connection_rc
Definition: lrmd.h:242
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:492
int(* disconnect)(lrmd_t *lrmd)
Disconnect from the lrmd.
Definition: lrmd.h:324
const char * val
Definition: lrmd.h:273
struct lrmd_api_operations_s lrmd_api_operations_t
unsigned int exec_time
Definition: lrmd.h:237
int(* list_ocf_providers)(lrmd_t *lrmd, const char *agent, lrmd_list_t **providers)
Retrieve a list of resource agent providers.
Definition: lrmd.h:465
void * params
Definition: lrmd.h:246
lrmd_rsc_info_t * lrmd_copy_rsc_info(lrmd_rsc_info_t *rsc_info)
Definition: lrmd_client.c:1458
const char * exit_reason
Definition: lrmd.h:254
int(* get_metadata)(lrmd_t *lrmd, const char *class, const char *provider, const char *agent, char **output, enum lrmd_call_options options)
Get resource metadata for a specified resource agent.
Definition: lrmd.h:438
char * key
Definition: lrmd.h:33
struct lrmd_list_s * next
Definition: lrmd.h:274
int rsc_deleted
Definition: lrmd.h:224
lrmd_t * lrmd_api_new(void)
Create a new local lrmd connection.
Definition: lrmd_client.c:1821
bool lrmd_dispatch(lrmd_t *lrmd)
Use after lrmd_poll returns 1 to read and dispatch a message.
Definition: lrmd_client.c:428
lrmd_key_value_t * lrmd_key_value_add(lrmd_key_value_t *kvp, const char *key, const char *value)
Definition: lrmd_client.c:153
struct lrmd_key_value_s * next
Definition: lrmd.h:35
int start_delay
Definition: lrmd.h:222
int(* connect_async)(lrmd_t *lrmd, const char *client_name, int timeout)
Establish an connection to lrmd, don&#39;t block while connecting.
Definition: lrmd.h:299
const char * op_type
Definition: lrmd.h:211
unsigned int t_run
Definition: lrmd.h:233
void lrmd_key_value_freeall(lrmd_key_value_t *head)
Definition: lrmd_client.c:176
char * type
Definition: lrmd.h:262
struct lrmd_key_value_s lrmd_key_value_t
int(* connect)(lrmd_t *lrmd, const char *client_name, int *fd)
Connect from the lrmd.
Definition: lrmd.h:287
const char * remote_nodename
Definition: lrmd.h:251
ocf_exitcode
Definition: services.h:104
lrmd_api_operations_t * cmds
Definition: lrmd.h:499
enum lrmd_callback_event type
Definition: lrmd.h:206
int(* list_agents)(lrmd_t *lrmd, lrmd_list_t **agents, const char *class, const char *provider)
Retrieve a list of installed resource agents.
Definition: lrmd.h:452
int(* unregister_rsc)(lrmd_t *lrmd, const char *rsc_id, enum lrmd_call_options options)
Unregister a resource from the lrmd.
Definition: lrmd.h:362
lrmd_event_data_t * lrmd_copy_event(lrmd_event_data_t *event)
Definition: lrmd_client.c:190
char * provider
Definition: lrmd.h:264
Definition: lrmd.h:498
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:403
struct lrmd_list_s lrmd_list_t
void lrmd_free_rsc_info(lrmd_rsc_info_t *rsc_info)
Definition: lrmd_client.c:1475
void lrmd_api_delete(lrmd_t *lrmd)
Destroy lrmd object.
Definition: lrmd_client.c:1883
int(* register_rsc)(lrmd_t *lrmd, const char *rsc_id, const char *class, const char *provider, const char *agent, enum lrmd_call_options options)
Register a resource with the lrmd.
Definition: lrmd.h:334
char * value
Definition: lrmd.h:34
int(* list_standards)(lrmd_t *lrmd, lrmd_list_t **standards)
Retrieve a list of standards supported by this machine/installation.
Definition: lrmd.h:475
enum crm_ais_msg_types type
Definition: internal.h:51