pacemaker  1.1.12-561c4cf
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 <dvossel@redhat.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 <crm/services.h>
26 
27 #ifndef LRMD__H
28 # define LRMD__H
29 
30 typedef struct lrmd_s lrmd_t;
31 typedef struct lrmd_key_value_s {
32  char *key;
33  char *value;
36 
37 #define LRMD_PROTOCOL_VERSION "1.0"
38 
39 /* *INDENT-OFF* */
40 #define DEFAULT_REMOTE_KEY_LOCATION "/etc/pacemaker/authkey"
41 #define ALT_REMOTE_KEY_LOCATION "/etc/corosync/authkey"
42 #define DEFAULT_REMOTE_PORT 3121
43 #define DEFAULT_REMOTE_USERNAME "lrmd"
44 
45 #define F_LRMD_OPERATION "lrmd_op"
46 #define F_LRMD_CLIENTNAME "lrmd_clientname"
47 #define F_LRMD_IS_IPC_PROVIDER "lrmd_is_ipc_provider"
48 #define F_LRMD_CLIENTID "lrmd_clientid"
49 #define F_LRMD_PROTOCOL_VERSION "lrmd_protocol_version"
50 #define F_LRMD_REMOTE_MSG_TYPE "lrmd_remote_msg_type"
51 #define F_LRMD_REMOTE_MSG_ID "lrmd_remote_msg_id"
52 #define F_LRMD_CALLBACK_TOKEN "lrmd_async_id"
53 #define F_LRMD_CALLID "lrmd_callid"
54 #define F_LRMD_CANCEL_CALLID "lrmd_cancel_callid"
55 #define F_LRMD_CALLOPTS "lrmd_callopt"
56 #define F_LRMD_CALLDATA "lrmd_calldata"
57 #define F_LRMD_RC "lrmd_rc"
58 #define F_LRMD_EXEC_RC "lrmd_exec_rc"
59 #define F_LRMD_OP_STATUS "lrmd_exec_op_status"
60 #define F_LRMD_TIMEOUT "lrmd_timeout"
61 #define F_LRMD_CLASS "lrmd_class"
62 #define F_LRMD_PROVIDER "lrmd_provider"
63 #define F_LRMD_TYPE "lrmd_type"
64 #define F_LRMD_ORIGIN "lrmd_origin"
65 
66 #define F_LRMD_RSC_RUN_TIME "lrmd_run_time"
67 #define F_LRMD_RSC_RCCHANGE_TIME "lrmd_rcchange_time"
68 #define F_LRMD_RSC_EXEC_TIME "lrmd_exec_time"
69 #define F_LRMD_RSC_QUEUE_TIME "lrmd_queue_time"
70 
71 #define F_LRMD_RSC_ID "lrmd_rsc_id"
72 #define F_LRMD_RSC_ACTION "lrmd_rsc_action"
73 #define F_LRMD_RSC_USERDATA_STR "lrmd_rsc_userdata_str"
74 #define F_LRMD_RSC_OUTPUT "lrmd_rsc_output"
75 #define F_LRMD_RSC_START_DELAY "lrmd_rsc_start_delay"
76 #define F_LRMD_RSC_INTERVAL "lrmd_rsc_interval"
77 #define F_LRMD_RSC_METADATA "lrmd_rsc_metadata_res"
78 #define F_LRMD_RSC_DELETED "lrmd_rsc_deleted"
79 #define F_LRMD_RSC "lrmd_rsc"
80 
81 #define LRMD_OP_RSC_CHK_REG "lrmd_rsc_check_register"
82 #define LRMD_OP_RSC_REG "lrmd_rsc_register"
83 #define LRMD_OP_RSC_EXEC "lrmd_rsc_exec"
84 #define LRMD_OP_RSC_CANCEL "lrmd_rsc_cancel"
85 #define LRMD_OP_RSC_UNREG "lrmd_rsc_unregister"
86 #define LRMD_OP_RSC_INFO "lrmd_rsc_info"
87 #define LRMD_OP_RSC_METADATA "lrmd_rsc_metadata"
88 #define LRMD_OP_POKE "lrmd_rsc_poke"
89 #define LRMD_OP_NEW_CLIENT "lrmd_rsc_new_client"
90 
91 #define F_LRMD_IPC_OP "lrmd_ipc_op"
92 #define F_LRMD_IPC_IPC_SERVER "lrmd_ipc_server"
93 #define F_LRMD_IPC_SESSION "lrmd_ipc_session"
94 #define F_LRMD_IPC_CLIENT "lrmd_ipc_client"
95 #define F_LRMD_IPC_PROXY_NODE "lrmd_ipc_proxy_node"
96 #define F_LRMD_IPC_USER "lrmd_ipc_user"
97 #define F_LRMD_IPC_MSG "lrmd_ipc_msg"
98 #define F_LRMD_IPC_MSG_ID "lrmd_ipc_msg_id"
99 #define F_LRMD_IPC_MSG_FLAGS "lrmd_ipc_msg_flags"
100 
101 #define T_LRMD "lrmd"
102 #define T_LRMD_REPLY "lrmd_reply"
103 #define T_LRMD_NOTIFY "lrmd_notify"
104 #define T_LRMD_IPC_PROXY "lrmd_ipc_proxy"
105 /* *INDENT-ON* */
106 
110 lrmd_t *lrmd_api_new(void);
111 
121 lrmd_t *lrmd_remote_api_new(const char *nodename, const char *server, int port);
122 
132 bool lrmd_dispatch(lrmd_t * lrmd);
133 
141 int lrmd_poll(lrmd_t * lrmd, int timeout);
142 
146 void lrmd_api_delete(lrmd_t * lrmd);
147 lrmd_key_value_t *lrmd_key_value_add(lrmd_key_value_t * kvp, const char *key, const char *value);
148 
149 /* *INDENT-OFF* */
150 /* Reserved for future use */
152  lrmd_opt_none = 0x00000000,
153  /* lrmd_opt_sync_call = 0x00000001, //Not implemented, patches welcome. */
163 };
164 
173 };
174 
175 /* *INDENT-ON* */
176 
177 typedef struct lrmd_event_data_s {
180 
182  const char *rsc_id;
184  const char *op_type;
186  const char *user_data;
187 
189  int call_id;
191  int timeout;
193  int interval;
198 
204  const char *output;
206  unsigned int t_run;
208  unsigned int t_rcchange;
210  unsigned int exec_time;
212  unsigned int queue_time;
213 
216 
217  /* This is a GHashTable containing the
218  * parameters given to the operation */
219  void *params;
220 
221  /* client node name associated with this conneciton.
222  * This is useful if multiple clients are being utilized by
223  * a single process. This name allows the actions to be matched
224  * to the proper client. */
225  const char *remote_nodename;
226 
228 
230 void lrmd_free_event(lrmd_event_data_t * event);
231 
232 typedef struct lrmd_rsc_info_s {
233  char *id;
234  char *type;
235  char *class;
236  char *provider;
238 
240 void lrmd_free_rsc_info(lrmd_rsc_info_t * rsc_info);
241 
242 typedef void (*lrmd_event_callback) (lrmd_event_data_t * event);
243 
244 typedef struct lrmd_list_s {
245  const char *val;
246  struct lrmd_list_s *next;
247 } lrmd_list_t;
248 
249 void lrmd_list_freeall(lrmd_list_t * head);
251 
252 typedef struct lrmd_api_operations_s {
259  int (*connect) (lrmd_t * lrmd, const char *client_name, int *fd);
260 
271  int (*connect_async) (lrmd_t * lrmd, const char *client_name, int timeout /*ms */ );
272 
279  int (*is_connected) (lrmd_t * lrmd);
280 
288  int (*poke_connection) (lrmd_t * lrmd);
289 
296  int (*disconnect) (lrmd_t * lrmd);
297 
306  int (*register_rsc) (lrmd_t * lrmd,
307  const char *rsc_id,
308  const char *class,
309  const char *provider, const char *agent, enum lrmd_call_options options);
310 
317  lrmd_rsc_info_t *(*get_rsc_info) (lrmd_t * lrmd,
318  const char *rsc_id, enum lrmd_call_options options);
319 
334  int (*unregister_rsc) (lrmd_t * lrmd, const char *rsc_id, enum lrmd_call_options options);
335 
339  void (*set_callback) (lrmd_t * lrmd, lrmd_event_callback callback);
340 
356  int (*exec) (lrmd_t * lrmd, const char *rsc_id, const char *action, const char *userdata, /* userdata string given back in event notification */
357  int interval, /* ms */
358  int timeout, /* ms */
359  int start_delay, /* ms */
360  enum lrmd_call_options options, lrmd_key_value_t * params); /* ownership of params is given up to api here */
361 
385  int (*cancel) (lrmd_t * lrmd, const char *rsc_id, const char *action, int interval);
386 
395  int (*get_metadata) (lrmd_t * lrmd,
396  const char *class,
397  const char *provider,
398  const char *agent, char **output, enum lrmd_call_options options);
399 
409  int (*list_agents) (lrmd_t * lrmd, lrmd_list_t ** agents, const char *class,
410  const char *provider);
411 
422  int (*list_ocf_providers) (lrmd_t * lrmd, const char *agent, lrmd_list_t ** providers);
423 
432  int (*list_standards) (lrmd_t * lrmd, lrmd_list_t ** standards);
433 
435 
436 struct lrmd_s {
438  void *private;
439 };
440 
441 static inline const char *
442 lrmd_event_type2str(enum lrmd_callback_event type)
443 {
444  switch (type) {
445  case lrmd_event_register:
446  return "register";
448  return "unregister";
450  return "exec_complete";
452  return "disconnect";
453  case lrmd_event_connect:
454  return "connect";
455  case lrmd_event_poke:
456  return "poke";
458  return "new_client";
459  }
460  return "unknown";
461 }
462 
463 #endif
Services API.
struct lrmd_rsc_info_s lrmd_rsc_info_t
lrmd_call_options
Definition: lrmd.h:151
lrmd_callback_event
Definition: lrmd.h:165
const char * user_data
Definition: lrmd.h:186
const char * rsc_id
Definition: lrmd.h:182
int(* cancel)(lrmd_t *lrmd, const char *rsc_id, const char *action, int interval)
Cancel a recurring command.
Definition: lrmd.h:385
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:356
unsigned int queue_time
Definition: lrmd.h:212
int(* poke_connection)(lrmd_t *lrmd)
Poke lrmd connection to verify it is still capable of serving requests.
Definition: lrmd.h:288
void(* set_callback)(lrmd_t *lrmd, lrmd_event_callback callback)
Sets the callback to receive lrmd events on.
Definition: lrmd.h:339
int(* is_connected)(lrmd_t *lrmd)
Is connected to lrmd daemon?
Definition: lrmd.h:279
char * id
Definition: lrmd.h:233
void lrmd_list_freeall(lrmd_list_t *head)
void lrmd_free_event(lrmd_event_data_t *event)
void(* lrmd_event_callback)(lrmd_event_data_t *event)
Definition: lrmd.h:242
unsigned int t_rcchange
Definition: lrmd.h:208
const char * output
Definition: lrmd.h:204
struct lrmd_event_data_s lrmd_event_data_t
enum ocf_exitcode rc
Definition: lrmd.h:200
lrmd_t * lrmd_remote_api_new(const char *nodename, const char *server, int port)
Create a new remote lrmd connection using tls backend.
int connection_rc
Definition: lrmd.h:215
int(* disconnect)(lrmd_t *lrmd)
Disconnect from the lrmd.
Definition: lrmd.h:296
const char * val
Definition: lrmd.h:245
struct lrmd_api_operations_s lrmd_api_operations_t
unsigned int exec_time
Definition: lrmd.h:210
int(* list_ocf_providers)(lrmd_t *lrmd, const char *agent, lrmd_list_t **providers)
Retrieve a list of resource agent providers.
Definition: lrmd.h:422
void * params
Definition: lrmd.h:219
lrmd_rsc_info_t * lrmd_copy_rsc_info(lrmd_rsc_info_t *rsc_info)
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:395
char * key
Definition: lrmd.h:32
struct lrmd_list_s * next
Definition: lrmd.h:246
int rsc_deleted
Definition: lrmd.h:197
lrmd_t * lrmd_api_new(void)
Create a new local lrmd connection.
bool lrmd_dispatch(lrmd_t *lrmd)
Use after lrmd_poll returns 1.
lrmd_key_value_t * lrmd_key_value_add(lrmd_key_value_t *kvp, const char *key, const char *value)
struct lrmd_key_value_s * next
Definition: lrmd.h:34
int start_delay
Definition: lrmd.h:195
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:271
const char * op_type
Definition: lrmd.h:184
unsigned int t_run
Definition: lrmd.h:206
void lrmd_key_value_freeall(lrmd_key_value_t *head)
char * type
Definition: lrmd.h:234
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:259
const char * remote_nodename
Definition: lrmd.h:225
ocf_exitcode
Definition: services.h:79
lrmd_api_operations_t * cmds
Definition: lrmd.h:437
enum lrmd_callback_event type
Definition: lrmd.h:179
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:409
int(* unregister_rsc)(lrmd_t *lrmd, const char *rsc_id, enum lrmd_call_options options)
Unregister a resource from the lrmd.
Definition: lrmd.h:334
lrmd_event_data_t * lrmd_copy_event(lrmd_event_data_t *event)
char * provider
Definition: lrmd.h:236
Definition: lrmd.h:436
int lrmd_poll(lrmd_t *lrmd, int timeout)
Poll for a specified timeout period to determine if a message is ready for dispatch.
struct lrmd_list_s lrmd_list_t
void lrmd_free_rsc_info(lrmd_rsc_info_t *rsc_info)
void lrmd_api_delete(lrmd_t *lrmd)
Destroy lrmd object.
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:306
char * value
Definition: lrmd.h:33
int(* list_standards)(lrmd_t *lrmd, lrmd_list_t **standards)
Retrieve a list of standards supported by this machine/installation.
Definition: lrmd.h:432
enum crm_ais_msg_types type
Definition: internal.h:51