pacemaker  1.1.15-e174ec8
Scalable High-Availability cluster resource manager
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules 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 
25 #include <stdbool.h>
26 #include <crm/services.h>
27 
28 #ifndef LRMD__H
29 # define LRMD__H
30 
31 typedef struct lrmd_s lrmd_t;
32 typedef struct lrmd_key_value_s {
33  char *key;
34  char *value;
37 
38 #define LRMD_PROTOCOL_VERSION "1.1"
39 
40 /* *INDENT-OFF* */
41 #define DEFAULT_REMOTE_KEY_LOCATION "/etc/pacemaker/authkey"
42 #define ALT_REMOTE_KEY_LOCATION "/etc/corosync/authkey"
43 #define DEFAULT_REMOTE_PORT 3121
44 #define DEFAULT_REMOTE_USERNAME "lrmd"
45 
46 #define F_LRMD_OPERATION "lrmd_op"
47 #define F_LRMD_CLIENTNAME "lrmd_clientname"
48 #define F_LRMD_IS_IPC_PROVIDER "lrmd_is_ipc_provider"
49 #define F_LRMD_CLIENTID "lrmd_clientid"
50 #define F_LRMD_PROTOCOL_VERSION "lrmd_protocol_version"
51 #define F_LRMD_REMOTE_MSG_TYPE "lrmd_remote_msg_type"
52 #define F_LRMD_REMOTE_MSG_ID "lrmd_remote_msg_id"
53 #define F_LRMD_CALLBACK_TOKEN "lrmd_async_id"
54 #define F_LRMD_CALLID "lrmd_callid"
55 #define F_LRMD_CANCEL_CALLID "lrmd_cancel_callid"
56 #define F_LRMD_CALLOPTS "lrmd_callopt"
57 #define F_LRMD_CALLDATA "lrmd_calldata"
58 #define F_LRMD_RC "lrmd_rc"
59 #define F_LRMD_EXEC_RC "lrmd_exec_rc"
60 #define F_LRMD_OP_STATUS "lrmd_exec_op_status"
61 #define F_LRMD_TIMEOUT "lrmd_timeout"
62 #define F_LRMD_WATCHDOG "lrmd_watchdog"
63 #define F_LRMD_CLASS "lrmd_class"
64 #define F_LRMD_PROVIDER "lrmd_provider"
65 #define F_LRMD_TYPE "lrmd_type"
66 #define F_LRMD_ORIGIN "lrmd_origin"
67 
68 #define F_LRMD_RSC_RUN_TIME "lrmd_run_time"
69 #define F_LRMD_RSC_RCCHANGE_TIME "lrmd_rcchange_time"
70 #define F_LRMD_RSC_EXEC_TIME "lrmd_exec_time"
71 #define F_LRMD_RSC_QUEUE_TIME "lrmd_queue_time"
72 
73 #define F_LRMD_RSC_ID "lrmd_rsc_id"
74 #define F_LRMD_RSC_ACTION "lrmd_rsc_action"
75 #define F_LRMD_RSC_USERDATA_STR "lrmd_rsc_userdata_str"
76 #define F_LRMD_RSC_OUTPUT "lrmd_rsc_output"
77 #define F_LRMD_RSC_EXIT_REASON "lrmd_rsc_exit_reason"
78 #define F_LRMD_RSC_START_DELAY "lrmd_rsc_start_delay"
79 #define F_LRMD_RSC_INTERVAL "lrmd_rsc_interval"
80 #define F_LRMD_RSC_METADATA "lrmd_rsc_metadata_res"
81 #define F_LRMD_RSC_DELETED "lrmd_rsc_deleted"
82 #define F_LRMD_RSC "lrmd_rsc"
83 
84 #define LRMD_OP_RSC_CHK_REG "lrmd_rsc_check_register"
85 #define LRMD_OP_RSC_REG "lrmd_rsc_register"
86 #define LRMD_OP_RSC_EXEC "lrmd_rsc_exec"
87 #define LRMD_OP_RSC_CANCEL "lrmd_rsc_cancel"
88 #define LRMD_OP_RSC_UNREG "lrmd_rsc_unregister"
89 #define LRMD_OP_RSC_INFO "lrmd_rsc_info"
90 #define LRMD_OP_RSC_METADATA "lrmd_rsc_metadata"
91 #define LRMD_OP_POKE "lrmd_rsc_poke"
92 #define LRMD_OP_NEW_CLIENT "lrmd_rsc_new_client"
93 #define LRMD_OP_CHECK "lrmd_check"
94 
95 #define LRMD_IPC_OP_NEW "new"
96 #define LRMD_IPC_OP_DESTROY "destroy"
97 #define LRMD_IPC_OP_EVENT "event"
98 #define LRMD_IPC_OP_REQUEST "request"
99 #define LRMD_IPC_OP_RESPONSE "response"
100 #define LRMD_IPC_OP_SHUTDOWN_REQ "shutdown_req"
101 #define LRMD_IPC_OP_SHUTDOWN_ACK "shutdown_ack"
102 
103 #define F_LRMD_IPC_OP "lrmd_ipc_op"
104 #define F_LRMD_IPC_IPC_SERVER "lrmd_ipc_server"
105 #define F_LRMD_IPC_SESSION "lrmd_ipc_session"
106 #define F_LRMD_IPC_CLIENT "lrmd_ipc_client"
107 #define F_LRMD_IPC_PROXY_NODE "lrmd_ipc_proxy_node"
108 #define F_LRMD_IPC_USER "lrmd_ipc_user"
109 #define F_LRMD_IPC_MSG "lrmd_ipc_msg"
110 #define F_LRMD_IPC_MSG_ID "lrmd_ipc_msg_id"
111 #define F_LRMD_IPC_MSG_FLAGS "lrmd_ipc_msg_flags"
112 
113 #define T_LRMD "lrmd"
114 #define T_LRMD_REPLY "lrmd_reply"
115 #define T_LRMD_NOTIFY "lrmd_notify"
116 #define T_LRMD_IPC_PROXY "lrmd_ipc_proxy"
117 /* *INDENT-ON* */
118 
122 lrmd_t *lrmd_api_new(void);
123 
133 lrmd_t *lrmd_remote_api_new(const char *nodename, const char *server, int port);
134 
142 bool lrmd_dispatch(lrmd_t * lrmd);
143 
151 int lrmd_poll(lrmd_t * lrmd, int timeout);
152 
156 void lrmd_api_delete(lrmd_t * lrmd);
157 lrmd_key_value_t *lrmd_key_value_add(lrmd_key_value_t * kvp, const char *key, const char *value);
158 
159 /* *INDENT-OFF* */
160 /* Reserved for future use */
162  lrmd_opt_none = 0x00000000,
163  /* lrmd_opt_sync_call = 0x00000001, //Not implemented, patches welcome. */
173 };
174 
183 };
184 
185 /* *INDENT-ON* */
186 
187 typedef struct lrmd_event_data_s {
190 
192  const char *rsc_id;
194  const char *op_type;
196  const char *user_data;
197 
199  int call_id;
201  int timeout;
203  int interval;
208 
214  const char *output;
216  unsigned int t_run;
218  unsigned int t_rcchange;
220  unsigned int exec_time;
222  unsigned int queue_time;
223 
226 
227  /* This is a GHashTable containing the
228  * parameters given to the operation */
229  void *params;
230 
231  /* client node name associated with this conneciton.
232  * This is useful if multiple clients are being utilized by
233  * a single process. This name allows the actions to be matched
234  * to the proper client. */
235  const char *remote_nodename;
236 
238  const char *exit_reason;
239 
241 
243 void lrmd_free_event(lrmd_event_data_t * event);
244 
245 typedef struct lrmd_rsc_info_s {
246  char *id;
247  char *type;
248  char *class;
249  char *provider;
251 
253 void lrmd_free_rsc_info(lrmd_rsc_info_t * rsc_info);
254 
255 typedef void (*lrmd_event_callback) (lrmd_event_data_t * event);
256 
257 typedef struct lrmd_list_s {
258  const char *val;
259  struct lrmd_list_s *next;
260 } lrmd_list_t;
261 
262 void lrmd_list_freeall(lrmd_list_t * head);
264 
265 typedef struct lrmd_api_operations_s {
272  int (*connect) (lrmd_t * lrmd, const char *client_name, int *fd);
273 
284  int (*connect_async) (lrmd_t * lrmd, const char *client_name, int timeout /*ms */ );
285 
292  int (*is_connected) (lrmd_t * lrmd);
293 
301  int (*poke_connection) (lrmd_t * lrmd);
302 
309  int (*disconnect) (lrmd_t * lrmd);
310 
319  int (*register_rsc) (lrmd_t * lrmd,
320  const char *rsc_id,
321  const char *class,
322  const char *provider, const char *agent, enum lrmd_call_options options);
323 
330  lrmd_rsc_info_t *(*get_rsc_info) (lrmd_t * lrmd,
331  const char *rsc_id, enum lrmd_call_options options);
332 
347  int (*unregister_rsc) (lrmd_t * lrmd, const char *rsc_id, enum lrmd_call_options options);
348 
352  void (*set_callback) (lrmd_t * lrmd, lrmd_event_callback callback);
353 
369  int (*exec) (lrmd_t * lrmd, const char *rsc_id, const char *action, const char *userdata, /* userdata string given back in event notification */
370  int interval, /* ms */
371  int timeout, /* ms */
372  int start_delay, /* ms */
373  enum lrmd_call_options options, lrmd_key_value_t * params); /* ownership of params is given up to api here */
374 
398  int (*cancel) (lrmd_t * lrmd, const char *rsc_id, const char *action, int interval);
399 
408  int (*get_metadata) (lrmd_t * lrmd,
409  const char *class,
410  const char *provider,
411  const char *agent, char **output, enum lrmd_call_options options);
412 
422  int (*list_agents) (lrmd_t * lrmd, lrmd_list_t ** agents, const char *class,
423  const char *provider);
424 
435  int (*list_ocf_providers) (lrmd_t * lrmd, const char *agent, lrmd_list_t ** providers);
436 
445  int (*list_standards) (lrmd_t * lrmd, lrmd_list_t ** standards);
446 
448 
449 struct lrmd_s {
451  void *private;
452 };
453 
454 static inline const char *
455 lrmd_event_type2str(enum lrmd_callback_event type)
456 {
457  switch (type) {
458  case lrmd_event_register:
459  return "register";
461  return "unregister";
463  return "exec_complete";
465  return "disconnect";
466  case lrmd_event_connect:
467  return "connect";
468  case lrmd_event_poke:
469  return "poke";
471  return "new_client";
472  }
473  return "unknown";
474 }
475 
476 #endif
Services API.
struct lrmd_rsc_info_s lrmd_rsc_info_t
lrmd_call_options
Definition: lrmd.h:161
lrmd_callback_event
Definition: lrmd.h:175
const char * user_data
Definition: lrmd.h:196
const char * rsc_id
Definition: lrmd.h:192
int(* cancel)(lrmd_t *lrmd, const char *rsc_id, const char *action, int interval)
Cancel a recurring command.
Definition: lrmd.h:398
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:369
unsigned int queue_time
Definition: lrmd.h:222
int(* poke_connection)(lrmd_t *lrmd)
Poke lrmd connection to verify it is still capable of serving requests.
Definition: lrmd.h:301
void(* set_callback)(lrmd_t *lrmd, lrmd_event_callback callback)
Sets the callback to receive lrmd events on.
Definition: lrmd.h:352
int(* is_connected)(lrmd_t *lrmd)
Is connected to lrmd daemon?
Definition: lrmd.h:292
char * id
Definition: lrmd.h:246
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:227
void(* lrmd_event_callback)(lrmd_event_data_t *event)
Definition: lrmd.h:255
unsigned int t_rcchange
Definition: lrmd.h:218
const char * output
Definition: lrmd.h:214
struct lrmd_event_data_s lrmd_event_data_t
enum ocf_exitcode rc
Definition: lrmd.h:210
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:2181
int connection_rc
Definition: lrmd.h:225
int(* disconnect)(lrmd_t *lrmd)
Disconnect from the lrmd.
Definition: lrmd.h:309
const char * val
Definition: lrmd.h:258
struct lrmd_api_operations_s lrmd_api_operations_t
unsigned int exec_time
Definition: lrmd.h:220
int(* list_ocf_providers)(lrmd_t *lrmd, const char *agent, lrmd_list_t **providers)
Retrieve a list of resource agent providers.
Definition: lrmd.h:435
void * params
Definition: lrmd.h:229
lrmd_rsc_info_t * lrmd_copy_rsc_info(lrmd_rsc_info_t *rsc_info)
Definition: lrmd_client.c:1465
const char * exit_reason
Definition: lrmd.h:238
int(* get_metadata)(lrmd_t *lrmd, const char *class, const char *provider, const char *agent, char **output, enum lrmd_call_options options)
Get the metadata documentation for a resource.
Definition: lrmd.h:408
char * key
Definition: lrmd.h:33
struct lrmd_list_s * next
Definition: lrmd.h:259
int rsc_deleted
Definition: lrmd.h:207
lrmd_t * lrmd_api_new(void)
Create a new local lrmd connection.
Definition: lrmd_client.c:2148
bool lrmd_dispatch(lrmd_t *lrmd)
Use after lrmd_poll returns 1 to read and dispatch a message.
Definition: lrmd_client.c:442
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:205
int(* connect_async)(lrmd_t *lrmd, const char *client_name, int timeout)
Establish an connection to lrmd, don't block while connecting.
Definition: lrmd.h:284
const char * op_type
Definition: lrmd.h:194
unsigned int t_run
Definition: lrmd.h:216
void lrmd_key_value_freeall(lrmd_key_value_t *head)
Definition: lrmd_client.c:176
char * type
Definition: lrmd.h:247
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:272
const char * remote_nodename
Definition: lrmd.h:235
ocf_exitcode
Definition: services.h:91
lrmd_api_operations_t * cmds
Definition: lrmd.h:450
enum lrmd_callback_event type
Definition: lrmd.h:189
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:422
int(* unregister_rsc)(lrmd_t *lrmd, const char *rsc_id, enum lrmd_call_options options)
Unregister a resource from the lrmd.
Definition: lrmd.h:347
lrmd_event_data_t * lrmd_copy_event(lrmd_event_data_t *event)
Definition: lrmd_client.c:196
char * provider
Definition: lrmd.h:249
Definition: lrmd.h:449
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:417
struct lrmd_list_s lrmd_list_t
void lrmd_free_rsc_info(lrmd_rsc_info_t *rsc_info)
Definition: lrmd_client.c:1482
void lrmd_api_delete(lrmd_t *lrmd)
Destroy lrmd object.
Definition: lrmd_client.c:2210
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:319
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:445
enum crm_ais_msg_types type
Definition: internal.h:51