23 #include <stonith/stonith.h> 25 #define LHA_STONITH_LIBRARY "libstonith.so.1" 27 static void *lha_agents_lib = NULL;
29 static const char META_TEMPLATE[] =
30 "<?xml version=\"1.0\"?>\n" 31 "<!DOCTYPE resource-agent SYSTEM \"ra-api-1.dtd\">\n" 32 "<resource-agent name=\"%s\">\n" 33 " <version>1.0</version>\n" 34 " <longdesc lang=\"en\">\n" 37 " <shortdesc lang=\"en\">%s</shortdesc>\n" 40 " <action name=\"start\" timeout=\"20\" />\n" 41 " <action name=\"stop\" timeout=\"15\" />\n" 42 " <action name=\"status\" timeout=\"20\" />\n" 43 " <action name=\"monitor\" timeout=\"20\" interval=\"3600\"/>\n" 44 " <action name=\"meta-data\" timeout=\"15\" />\n" 46 " <special tag=\"heartbeat\">\n" 47 " <version>2.0</version>\n" " </special>\n" "</resource-agent>\n";
50 find_library_function(
void **handle,
const char *lib,
const char *fn)
54 if (*handle == NULL) {
55 *handle = dlopen(lib, RTLD_LAZY);
56 if ((*handle) == NULL) {
57 crm_err(
"Could not open %s: %s", lib, dlerror());
62 a_function = dlsym(*handle, fn);
63 if (a_function == NULL) {
64 crm_err(
"Could not find %s in %s: %s", fn, lib, dlerror());
81 Stonith *stonith_obj = NULL;
83 static gboolean need_init = TRUE;
84 static Stonith *(*st_new_fn) (
const char *) = NULL;
85 static void (*st_del_fn) (Stonith *) = NULL;
95 if (lha_agents_lib && st_new_fn && st_del_fn) {
96 stonith_obj = (*st_new_fn) (agent);
98 (*st_del_fn) (stonith_obj);
108 static gboolean need_init = TRUE;
112 char **type_list = NULL;
113 static char **(*type_list_fn) (void) = NULL;
114 static void (*type_free_fn) (
char **) = NULL;
118 type_list_fn = find_library_function(&lha_agents_lib,
121 type_free_fn = find_library_function(&lha_agents_lib,
123 "stonith_free_hostlist");
127 type_list = (*type_list_fn) ();
130 for (entry = type_list; entry != NULL && *entry; ++entry) {
135 if (type_list && type_free_fn) {
136 (*type_free_fn) (type_list);
142 strdup_null(
const char *val)
151 stonith_plugin(
int priority,
const char *fmt, ...)
__attribute__((__format__ (__printf__, 2, 3)));
154 stonith_plugin(
int priority, const
char *format, ...)
162 va_start(ap, format);
164 len = vasprintf (&
string, format, ap);
179 static const char *no_parameter_info =
"<!-- no value -->";
181 Stonith *stonith_obj = NULL;
183 static gboolean need_init = TRUE;
184 static Stonith *(*st_new_fn) (
const char *) = NULL;
185 static const char *(*st_info_fn) (Stonith *, int) = NULL;
186 static void (*st_del_fn) (Stonith *) = NULL;
187 static void (*st_log_fn) (Stonith *, PILLogFun) = NULL;
201 if (lha_agents_lib && st_new_fn && st_del_fn && st_info_fn && st_log_fn) {
202 char *xml_meta_longdesc = NULL;
203 char *xml_meta_shortdesc = NULL;
205 char *meta_param = NULL;
206 char *meta_longdesc = NULL;
207 char *meta_shortdesc = NULL;
209 stonith_obj = (*st_new_fn) (agent);
211 (*st_log_fn) (stonith_obj, (PILLogFun) & stonith_plugin);
212 meta_longdesc = strdup_null((*st_info_fn) (stonith_obj, ST_DEVICEDESCR));
213 if (meta_longdesc == NULL) {
214 crm_warn(
"no long description in %s's metadata.", agent);
215 meta_longdesc = strdup(no_parameter_info);
218 meta_shortdesc = strdup_null((*st_info_fn) (stonith_obj, ST_DEVICEID));
219 if (meta_shortdesc == NULL) {
220 crm_warn(
"no short description in %s's metadata.", agent);
221 meta_shortdesc = strdup(no_parameter_info);
224 meta_param = strdup_null((*st_info_fn) (stonith_obj, ST_CONF_XML));
225 if (meta_param == NULL) {
226 crm_warn(
"no list of parameters in %s's metadata.", agent);
227 meta_param = strdup(no_parameter_info);
229 (*st_del_fn) (stonith_obj);
232 crm_perror(LOG_ERR,
"Agent %s not found", agent);
237 (
char *)xmlEncodeEntitiesReentrant(NULL, (
const unsigned char *)meta_longdesc);
239 (
char *)xmlEncodeEntitiesReentrant(NULL, (
const unsigned char *)meta_shortdesc);
242 xml_meta_shortdesc, meta_param);
244 xmlFree(xml_meta_longdesc);
245 xmlFree(xml_meta_shortdesc);
247 free(meta_shortdesc);
263 #include <pils/plugin.h> 270 return PIL_strerror(
rc);
275 const char *agent, GHashTable *params,
int timeout,
276 char **output,
char **error_output)
279 crm_perror(LOG_ERR,
"Cannot validate Linux-HA fence agents");
int stonith__lha_validate(stonith_t *st, int call_options, const char *target, const char *agent, GHashTable *params, int timeout, char **output, char **error_output)
int stonith__lha_metadata(const char *agent, int timeout, char **output)
#define LHA_STONITH_LIBRARY
#define do_crm_log_alias(level, file, function, line, fmt, args...)
Log a message as if it came from a different code location.
const char * i_hate_pils(int rc)
int stonith__list_lha_agents(stonith_key_value_t **devices)
stonith_key_value_t * stonith_key_value_add(stonith_key_value_t *kvp, const char *key, const char *value)
#define crm_warn(fmt, args...)
#define crm_trace(fmt, args...)
Wrappers for and extensions to libxml2.
#define crm_perror(level, fmt, args...)
Send a system error message to both the log and stderr.
#define crm_err(fmt, args...)
bool stonith__agent_is_lha(const char *agent)
Determine namespace of a fence agent.
char * crm_strdup_printf(char const *format,...) __attribute__((__format__(__printf__