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 gboolean 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 strdup_null(
const char *val)
155 stonith_plugin(
int priority,
const char *fmt, ...) G_GNUC_PRINTF(2, 3);
158 stonith_plugin(
int priority, const
char *format, ...)
166 va_start(ap, format);
168 len = vasprintf (&
string, format, ap);
183 static const char *no_parameter_info =
"<!-- no value -->";
185 Stonith *stonith_obj = NULL;
187 static gboolean need_init = TRUE;
188 static Stonith *(*st_new_fn) (
const char *) = NULL;
189 static const char *(*st_info_fn) (Stonith *, int) = NULL;
190 static void (*st_del_fn) (Stonith *) = NULL;
191 static void (*st_log_fn) (Stonith *, PILLogFun) = NULL;
205 if (lha_agents_lib && st_new_fn && st_del_fn && st_info_fn && st_log_fn) {
206 char *xml_meta_longdesc = NULL;
207 char *xml_meta_shortdesc = NULL;
209 char *meta_param = NULL;
210 char *meta_longdesc = NULL;
211 char *meta_shortdesc = NULL;
213 stonith_obj = (*st_new_fn) (agent);
215 (*st_log_fn) (stonith_obj, (PILLogFun) & stonith_plugin);
216 meta_longdesc = strdup_null((*st_info_fn) (stonith_obj, ST_DEVICEDESCR));
217 if (meta_longdesc == NULL) {
218 crm_warn(
"no long description in %s's metadata.", agent);
219 meta_longdesc = strdup(no_parameter_info);
222 meta_shortdesc = strdup_null((*st_info_fn) (stonith_obj, ST_DEVICEID));
223 if (meta_shortdesc == NULL) {
224 crm_warn(
"no short description in %s's metadata.", agent);
225 meta_shortdesc = strdup(no_parameter_info);
228 meta_param = strdup_null((*st_info_fn) (stonith_obj, ST_CONF_XML));
229 if (meta_param == NULL) {
230 crm_warn(
"no list of parameters in %s's metadata.", agent);
231 meta_param = strdup(no_parameter_info);
233 (*st_del_fn) (stonith_obj);
236 crm_perror(LOG_ERR,
"Agent %s not found", agent);
241 (
char *)xmlEncodeEntitiesReentrant(NULL, (
const unsigned char *)meta_longdesc);
243 (
char *)xmlEncodeEntitiesReentrant(NULL, (
const unsigned char *)meta_shortdesc);
246 xml_meta_shortdesc, meta_param);
248 xmlFree(xml_meta_longdesc);
249 xmlFree(xml_meta_shortdesc);
251 free(meta_shortdesc);
267 #include <pils/plugin.h> 274 return PIL_strerror(
rc);
279 const char *agent, GHashTable *params,
int timeout,
280 char **output,
char **error_output)
283 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.