25 #include <stonith/stonith.h>
27 #define LHA_STONITH_LIBRARY "libstonith.so.1"
29 static void *lha_agents_lib = NULL;
31 static const char META_TEMPLATE[] =
32 "<?xml version=\"1.0\"?>\n"
33 "<!DOCTYPE resource-agent SYSTEM \"ra-api-1.dtd\">\n"
34 "<resource-agent name=\"%s\">\n"
35 " <version>1.0</version>\n"
36 " <longdesc lang=\"en\">\n"
39 " <shortdesc lang=\"en\">%s</shortdesc>\n"
42 " <action name=\"start\" timeout=\"20\" />\n"
43 " <action name=\"stop\" timeout=\"15\" />\n"
44 " <action name=\"status\" timeout=\"20\" />\n"
45 " <action name=\"monitor\" timeout=\"20\" interval=\"3600\"/>\n"
46 " <action name=\"meta-data\" timeout=\"15\" />\n"
48 " <special tag=\"heartbeat\">\n"
49 " <version>2.0</version>\n" " </special>\n" "</resource-agent>\n";
52 find_library_function(
void **handle,
const char *lib,
const char *fn)
56 if (*handle == NULL) {
57 *handle = dlopen(lib, RTLD_LAZY);
58 if ((*handle) == NULL) {
59 crm_err(
"Could not open %s: %s", lib, dlerror());
64 a_function = dlsym(*handle, fn);
65 if (a_function == NULL) {
66 crm_err(
"Could not find %s in %s: %s", fn, lib, dlerror());
83 Stonith *stonith_obj = NULL;
85 static gboolean need_init = TRUE;
86 static Stonith *(*st_new_fn) (
const char *) = NULL;
87 static void (*st_del_fn) (Stonith *) = NULL;
97 if (lha_agents_lib && st_new_fn && st_del_fn) {
98 stonith_obj = (*st_new_fn) (agent);
100 (*st_del_fn) (stonith_obj);
110 static gboolean need_init = TRUE;
114 char **type_list = NULL;
115 static char **(*type_list_fn) (void) = NULL;
116 static void (*type_free_fn) (
char **) = NULL;
120 type_list_fn = find_library_function(&lha_agents_lib,
123 type_free_fn = find_library_function(&lha_agents_lib,
125 "stonith_free_hostlist");
129 type_list = (*type_list_fn) ();
132 for (entry = type_list; entry != NULL && *entry; ++entry) {
137 if (type_list && type_free_fn) {
138 (*type_free_fn) (type_list);
144 strdup_null(
const char *val)
153 stonith_plugin(
int priority,
const char *fmt, ...) G_GNUC_PRINTF(2, 3);
156 stonith_plugin(
int priority, const
char *format, ...)
164 va_start(ap, format);
166 len = vasprintf (&
string, format, ap);
181 static const char *no_parameter_info =
"<!-- no value -->";
183 Stonith *stonith_obj = NULL;
185 static gboolean need_init = TRUE;
186 static Stonith *(*st_new_fn) (
const char *) = NULL;
187 static const char *(*st_info_fn) (Stonith *, int) = NULL;
188 static void (*st_del_fn) (Stonith *) = NULL;
189 static void (*st_log_fn) (Stonith *, PILLogFun) = NULL;
203 if (lha_agents_lib && st_new_fn && st_del_fn && st_info_fn && st_log_fn) {
204 char *xml_meta_longdesc = NULL;
205 char *xml_meta_shortdesc = NULL;
207 char *meta_param = NULL;
208 char *meta_longdesc = NULL;
209 char *meta_shortdesc = NULL;
211 stonith_obj = (*st_new_fn) (agent);
213 (*st_log_fn) (stonith_obj, (PILLogFun) & stonith_plugin);
214 meta_longdesc = strdup_null((*st_info_fn) (stonith_obj, ST_DEVICEDESCR));
215 if (meta_longdesc == NULL) {
216 crm_warn(
"no long description in %s's metadata.", agent);
217 meta_longdesc = strdup(no_parameter_info);
220 meta_shortdesc = strdup_null((*st_info_fn) (stonith_obj, ST_DEVICEID));
221 if (meta_shortdesc == NULL) {
222 crm_warn(
"no short description in %s's metadata.", agent);
223 meta_shortdesc = strdup(no_parameter_info);
226 meta_param = strdup_null((*st_info_fn) (stonith_obj, ST_CONF_XML));
227 if (meta_param == NULL) {
228 crm_warn(
"no list of parameters in %s's metadata.", agent);
229 meta_param = strdup(no_parameter_info);
231 (*st_del_fn) (stonith_obj);
234 crm_perror(LOG_ERR,
"Agent %s not found", agent);
239 (
char *)xmlEncodeEntitiesReentrant(NULL, (
const unsigned char *)meta_longdesc);
241 (
char *)xmlEncodeEntitiesReentrant(NULL, (
const unsigned char *)meta_shortdesc);
244 xml_meta_shortdesc, meta_param);
246 xmlFree(xml_meta_longdesc);
247 xmlFree(xml_meta_shortdesc);
249 free(meta_shortdesc);
265 #include <pils/plugin.h>
272 return PIL_strerror(rc);
277 const char *agent, GHashTable *params,
int timeout,
278 char **output,
char **error_output)
281 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
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.