25 #include <stonith/stonith.h> 29 #define LHA_STONITH_LIBRARY "libstonith.so.1" 31 static void *lha_agents_lib = NULL;
33 static const char META_TEMPLATE[] =
34 "<?xml version=\"1.0\"?>\n" 35 "<!DOCTYPE resource-agent SYSTEM \"ra-api-1.dtd\">\n" 36 "<resource-agent name=\"%s\">\n" 37 " <version>1.0</version>\n" 38 " <longdesc lang=\"en\">\n" 41 " <shortdesc lang=\"en\">%s</shortdesc>\n" 44 " <action name=\"start\" timeout=\"20\" />\n" 45 " <action name=\"stop\" timeout=\"15\" />\n" 46 " <action name=\"status\" timeout=\"20\" />\n" 47 " <action name=\"monitor\" timeout=\"20\" interval=\"3600\"/>\n" 48 " <action name=\"meta-data\" timeout=\"15\" />\n" 50 " <special tag=\"heartbeat\">\n" 51 " <version>2.0</version>\n" " </special>\n" "</resource-agent>\n";
54 find_library_function(
void **handle,
const char *lib,
const char *fn)
58 if (*handle == NULL) {
59 *handle = dlopen(lib, RTLD_LAZY);
60 if ((*handle) == NULL) {
61 crm_err(
"Could not open %s: %s", lib, dlerror());
66 a_function = dlsym(*handle, fn);
67 if (a_function == NULL) {
68 crm_err(
"Could not find %s in %s: %s", fn, lib, dlerror());
85 Stonith *stonith_obj = NULL;
87 static bool need_init =
true;
88 static Stonith *(*st_new_fn) (
const char *) = NULL;
89 static void (*st_del_fn) (Stonith *) = NULL;
99 if (lha_agents_lib && st_new_fn && st_del_fn) {
100 stonith_obj = (*st_new_fn) (agent);
102 (*st_del_fn) (stonith_obj);
112 static gboolean need_init = TRUE;
116 char **type_list = NULL;
117 static char **(*type_list_fn) (void) = NULL;
118 static void (*type_free_fn) (
char **) = NULL;
122 type_list_fn = find_library_function(&lha_agents_lib,
125 type_free_fn = find_library_function(&lha_agents_lib,
127 "stonith_free_hostlist");
131 type_list = (*type_list_fn) ();
134 for (entry = type_list; entry != NULL && *entry; ++entry) {
139 if (type_list && type_free_fn) {
140 (*type_free_fn) (type_list);
146 stonith_plugin(
int priority,
const char *fmt, ...) G_GNUC_PRINTF(2, 3);
149 stonith_plugin(
int priority, const
char *format, ...)
157 va_start(ap, format);
159 len = vasprintf (&
string, format, ap);
174 static const char *no_parameter_info =
"<!-- no value -->";
176 Stonith *stonith_obj = NULL;
178 static gboolean need_init = TRUE;
179 static Stonith *(*st_new_fn) (
const char *) = NULL;
180 static const char *(*st_info_fn) (Stonith *, int) = NULL;
181 static void (*st_del_fn) (Stonith *) = NULL;
182 static void (*st_log_fn) (Stonith *, PILLogFun) = NULL;
196 if (lha_agents_lib && st_new_fn && st_del_fn && st_info_fn && st_log_fn) {
197 char *xml_meta_longdesc = NULL;
198 char *xml_meta_shortdesc = NULL;
200 char *meta_param = NULL;
201 char *meta_longdesc = NULL;
202 char *meta_shortdesc = NULL;
204 stonith_obj = (*st_new_fn) (agent);
206 (*st_log_fn) (stonith_obj, (PILLogFun) & stonith_plugin);
208 (*st_info_fn) (stonith_obj, ST_DEVICEDESCR));
209 if (meta_longdesc == NULL) {
210 crm_warn(
"no long description in %s's metadata.", agent);
211 meta_longdesc = strdup(no_parameter_info);
215 (*st_info_fn) (stonith_obj, ST_DEVICEID));
216 if (meta_shortdesc == NULL) {
217 crm_warn(
"no short description in %s's metadata.", agent);
218 meta_shortdesc = strdup(no_parameter_info);
222 (*st_info_fn) (stonith_obj, ST_CONF_XML));
223 if (meta_param == NULL) {
224 crm_warn(
"no list of parameters in %s's metadata.", agent);
225 meta_param = strdup(no_parameter_info);
227 (*st_del_fn) (stonith_obj);
230 crm_perror(LOG_ERR,
"Agent %s not found", agent);
235 (
char *)xmlEncodeEntitiesReentrant(NULL, (
const unsigned char *)meta_longdesc);
237 (
char *)xmlEncodeEntitiesReentrant(NULL, (
const unsigned char *)meta_shortdesc);
240 xml_meta_shortdesc, meta_param);
242 xmlFree(xml_meta_longdesc);
243 xmlFree(xml_meta_shortdesc);
245 free(meta_shortdesc);
261 #include <pils/plugin.h> 268 return PIL_strerror(rc);
273 const char *agent, GHashTable *params,
int timeout,
274 char **output,
char **error_output)
277 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...)
char * crm_strdup_printf(char const *format,...) G_GNUC_PRINTF(1
void pcmk__str_update(char **str, const char *value)
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)