pacemaker  1.1.14-70404b0
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.0"
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_CLASS "lrmd_class"
63 #define F_LRMD_PROVIDER "lrmd_provider"
64 #define F_LRMD_TYPE "lrmd_type"
65 #define F_LRMD_ORIGIN "lrmd_origin"
66 
67 #define F_LRMD_RSC_RUN_TIME "lrmd_run_time"
68 #define F_LRMD_RSC_RCCHANGE_TIME "lrmd_rcchange_time"
69 #define F_LRMD_RSC_EXEC_TIME "lrmd_exec_time"
70 #define F_LRMD_RSC_QUEUE_TIME "lrmd_queue_time"
71 
72 #define F_LRMD_RSC_ID "lrmd_rsc_id"
73 #define F_LRMD_RSC_ACTION "lrmd_rsc_action"
74 #define F_LRMD_RSC_USERDATA_STR "lrmd_rsc_userdata_str"
75 #define F_LRMD_RSC_OUTPUT "lrmd_rsc_output"
76 #define F_LRMD_RSC_EXIT_REASON "lrmd_rsc_exit_reason"
77 #define F_LRMD_RSC_START_DELAY "lrmd_rsc_start_delay"
78 #define F_LRMD_RSC_INTERVAL "lrmd_rsc_interval"
79 #define F_LRMD_RSC_METADATA "lrmd_rsc_metadata_res"
80 #define F_LRMD_RSC_DELETED "lrmd_rsc_deleted"
81 #define F_LRMD_RSC "lrmd_rsc"
82 
83 #define LRMD_OP_RSC_CHK_REG "lrmd_rsc_check_register"
84 #define LRMD_OP_RSC_REG "lrmd_rsc_register"
85 #define LRMD_OP_RSC_EXEC "lrmd_rsc_exec"
86 #define LRMD_OP_RSC_CANCEL "lrmd_rsc_cancel"
87 #define LRMD_OP_RSC_UNREG "lrmd_rsc_unregister"
88 #define LRMD_OP_RSC_INFO "lrmd_rsc_info"
89 #define LRMD_OP_RSC_METADATA "lrmd_rsc_metadata"
90 #define LRMD_OP_POKE "lrmd_rsc_poke"
91 #define LRMD_OP_NEW_CLIENT "lrmd_rsc_new_client"
92 
93 #define F_LRMD_IPC_OP "lrmd_ipc_op"
94 #define F_LRMD_IPC_IPC_SERVER "lrmd_ipc_server"
95 #define F_LRMD_IPC_SESSION "lrmd_ipc_session"
96 #define F_LRMD_IPC_CLIENT "lrmd_ipc_client"
97 #define F_LRMD_IPC_PROXY_NODE "lrmd_ipc_proxy_node"
98 #define F_LRMD_IPC_USER "lrmd_ipc_user"
99 #define F_LRMD_IPC_MSG "lrmd_ipc_msg"
100 #define F_LRMD_IPC_MSG_ID "lrmd_ipc_msg_id"
101 #define F_LRMD_IPC_MSG_FLAGS "lrmd_ipc_msg_flags"
102 
103 #define T_LRMD "lrmd"
104 #define T_LRMD_REPLY "lrmd_reply"
105 #define T_LRMD_NOTIFY "lrmd_notify"
106 #define T_LRMD_IPC_PROXY "lrmd_ipc_proxy"
107 /* *INDENT-ON* */
108 
112 lrmd_t *lrmd_api_new(void);
113 
123 lrmd_t *lrmd_remote_api_new(const char *nodename, const char *server, int port);
124 
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  const char *exit_reason;
229 
231 
233 void lrmd_free_event(lrmd_event_data_t * event);
234 
235 typedef struct lrmd_rsc_info_s {
236  char *id;
237  char *type;
238  char *class;
239  char *provider;
241 
243 void lrmd_free_rsc_info(lrmd_rsc_info_t * rsc_info);
244 
245 typedef void (*lrmd_event_callback) (lrmd_event_data_t * event);
246 
247 typedef struct lrmd_list_s {
248  const char *val;
249  struct lrmd_list_s *next;
250 } lrmd_list_t;
251 
252 void lrmd_list_freeall(lrmd_list_t * head);
254 
255 typedef struct lrmd_api_operations_s {
262  int (*connect) (lrmd_t * lrmd, const char *client_name, int *fd);
263 
274  int (*connect_async) (lrmd_t * lrmd, const char *client_name, int timeout /*ms */ );
275 
282  int (*is_connected) (lrmd_t * lrmd);
283 
291  int (*poke_connection) (lrmd_t * lrmd);
292 
299  int (*disconnect) (lrmd_t * lrmd);
300 
309  int (*register_rsc) (lrmd_t * lrmd,
310  const char *rsc_id,
311  const char *class,
312  const char *provider, const char *agent, enum lrmd_call_options options);
313 
320  lrmd_rsc_info_t *(*get_rsc_info) (lrmd_t * lrmd,
321  const char *rsc_id, enum lrmd_call_options options);
322 
337  int (*unregister_rsc) (lrmd_t * lrmd, const char *rsc_id, enum lrmd_call_options options);
338 
342  void (*set_callback) (lrmd_t * lrmd, lrmd_event_callback callback);
343 
359  int (*exec) (lrmd_t * lrmd, const char *rsc_id, const char *action, const char *userdata, /* userdata string given back in event notification */
360  int interval, /* ms */
361  int timeout, /* ms */
362  int start_delay, /* ms */
363  enum lrmd_call_options options, lrmd_key_value_t * params); /* ownership of params is given up to api here */
364 
388  int (*cancel) (lrmd_t * lrmd, const char *rsc_id, const char *action, int interval);
389 
398  int (*get_metadata) (lrmd_t * lrmd,
399  const char *class,
400  const char *provider,
401  const char *agent, char **output, enum lrmd_call_options options);
402 
412  int (*list_agents) (lrmd_t * lrmd, lrmd_list_t ** agents, const char *class,
413  const char *provider);
414 
425  int (*list_ocf_providers) (lrmd_t * lrmd, const char *agent, lrmd_list_t ** providers);
426 
435  int (*list_standards) (lrmd_t * lrmd, lrmd_list_t ** standards);
436 
438 
439 struct lrmd_s {
441  void *private;
442 };
443 
444 static inline const char *
445 lrmd_event_type2str(enum lrmd_callback_event type)
446 {
447  switch (type) {
448  case lrmd_event_register:
449  return "register";
451  return "unregister";
453  return "exec_complete";
455  return "disconnect";
456  case lrmd_event_connect:
457  return "connect";
458  case lrmd_event_poke:
459  return "poke";
461  return "new_client";
462  }
463  return "unknown";
464 }
465 
466 #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:388
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:359
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:291
void(* set_callback)(lrmd_t *lrmd, lrmd_event_callback callback)
Sets the callback to receive lrmd events on.
Definition: lrmd.h:342
int(* is_connected)(lrmd_t *lrmd)
Is connected to lrmd daemon?
Definition: lrmd.h:282
char * id
Definition: lrmd.h:236
void lrmd_list_freeall(lrmd_list_t *head)
Definition: lrmd_client.c:137
void lrmd_free_event(lrmd_event_data_t *event)
Definition: lrmd_client.c:226
void(* lrmd_event_callback)(lrmd_event_data_t *event)
Definition: lrmd.h:245
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.
Definition: lrmd_client.c:2153
int connection_rc
Definition: lrmd.h:215
int(* disconnect)(lrmd_t *lrmd)
Disconnect from the lrmd.
Definition: lrmd.h:299
const char * val
Definition: lrmd.h:248
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:425
void * params
Definition: lrmd.h:219
lrmd_rsc_info_t * lrmd_copy_rsc_info(lrmd_rsc_info_t *rsc_info)
Definition: lrmd_client.c:1439
const char * exit_reason
Definition: lrmd.h:228
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:398
char * key
Definition: lrmd.h:33
struct lrmd_list_s * next
Definition: lrmd.h:249
int rsc_deleted
Definition: lrmd.h:197
lrmd_t * lrmd_api_new(void)
Create a new local lrmd connection.
Definition: lrmd_client.c:2120
bool lrmd_dispatch(lrmd_t *lrmd)
Use after lrmd_poll returns 1 to read and dispatch a message.
Definition: lrmd_client.c:441
lrmd_key_value_t * lrmd_key_value_add(lrmd_key_value_t *kvp, const char *key, const char *value)
Definition: lrmd_client.c:152
struct lrmd_key_value_s * next
Definition: lrmd.h:35
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:274
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)
Definition: lrmd_client.c:175
char * type
Definition: lrmd.h:237
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:262
const char * remote_nodename
Definition: lrmd.h:225
ocf_exitcode
Definition: services.h:91
lrmd_api_operations_t * cmds
Definition: lrmd.h:440
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:412
int(* unregister_rsc)(lrmd_t *lrmd, const char *rsc_id, enum lrmd_call_options options)
Unregister a resource from the lrmd.
Definition: lrmd.h:337
lrmd_event_data_t * lrmd_copy_event(lrmd_event_data_t *event)
Definition: lrmd_client.c:195
char * provider
Definition: lrmd.h:239
Definition: lrmd.h:439
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:416
struct lrmd_list_s lrmd_list_t
void lrmd_free_rsc_info(lrmd_rsc_info_t *rsc_info)
Definition: lrmd_client.c:1456
void lrmd_api_delete(lrmd_t *lrmd)
Destroy lrmd object.
Definition: lrmd_client.c:2182
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:309
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:435
enum crm_ais_msg_types type
Definition: internal.h:51