39static int operations = 0;
40static GHashTable *recurring_actions = NULL;
44static GList *blocked_ops = NULL;
47static GList *inflight_ops = NULL;
49static void handle_blocked_ops(
void);
81init_recurring_actions(
void)
83 if (recurring_actions == NULL) {
101 && (g_list_find(inflight_ops, op) != NULL);
117expand_resource_class(
const char *rsc,
const char *standard,
const char *agent)
119 char *expanded_class = NULL;
121#if PCMK__ENABLE_SERVICE
125 if (found_class != NULL) {
126 crm_debug(
"Found %s agent %s for %s", found_class, agent, rsc);
129 const char *default_standard = NULL;
136#error No standards supported for service alias (configure script bug)
138 crm_info(
"Assuming resource class %s for agent %s for %s",
139 default_standard, agent, rsc);
145 if (expanded_class == NULL) {
148 return expanded_class;
178required_argument_missing(uint32_t ra_caps,
const char *
name,
179 const char *standard,
const char *provider,
180 const char *agent,
const char *
action)
182 if (pcmk__str_empty(
name)) {
183 crm_info(
"Cannot create operation without resource name (bug?)");
187 if (pcmk__str_empty(standard)) {
188 crm_info(
"Cannot create operation for %s without resource class (bug?)",
194 && pcmk__str_empty(provider)) {
195 crm_info(
"Cannot create operation for %s resource %s "
196 "without provider (bug?)", standard,
name);
200 if (pcmk__str_empty(agent)) {
201 crm_info(
"Cannot create operation for %s without agent name (bug?)",
206 if (pcmk__str_empty(
action)) {
207 crm_info(
"Cannot create operation for %s without action name (bug?)",
217 const char *standard,
const char *provider,
218 const char *agent,
const char *
action)
221 if (op->
rsc == NULL) {
225 op->
agent = strdup(agent);
226 if (op->
agent == NULL) {
230 op->
standard = expand_resource_class(
name, standard, agent);
256 const char *provider,
const char *agent,
266 crm_crit(
"Cannot prepare action: %s", strerror(ENOMEM));
267 if (params != NULL) {
268 g_hash_table_destroy(params);
281 }
else if (params != NULL) {
282 g_hash_table_destroy(params);
286 if (required_argument_missing(ra_caps,
name, standard, provider, agent,
290 "Required agent or action information missing");
296 if (copy_action_arguments(op, ra_caps,
name, standard, provider, agent,
298 crm_crit(
"Cannot prepare %s action for %s: %s",
321 crm_info(
"Cannot prepare %s operation for %s: %s",
330 const char *provider,
const char *agent,
337 if (op == NULL || op->
rc != 0) {
359 crm_crit(
"Cannot prepare action for '%s': %s", exec, strerror(ENOMEM));
369 for (
int cur_arg = 1; args[cur_arg - 1] != NULL; cur_arg++) {
372 crm_info(
"Cannot prepare action for '%s': Too many arguments",
379 op->
opaque->
args[cur_arg] = strdup(args[cur_arg - 1]);
381 crm_crit(
"Cannot prepare action for '%s': %s",
382 exec, strerror(ENOMEM));
408 GHashTable *params,
int sequence,
void *cb_data)
416 action->sequence = sequence;
417 action->cb_data = cb_data;
438 CRM_CHECK((op != NULL) && (user != NULL),
return -EINVAL);
458 action->synchronous =
false;
459 action->opaque->callback = cb;
472services_set_op_pending(
svc_action_t *op, DBusPendingCall *pending)
474 if (op->
opaque->pending && (op->
opaque->pending != pending)) {
480 dbus_pending_call_unref(op->
opaque->pending);
482 op->
opaque->pending = pending;
484 crm_trace(
"Updated pending %s DBus call (%p)", op->
id, pending);
494 if ((op == NULL) || (op->
opaque == NULL)) {
499 if(op->
opaque->timerid != 0) {
501 g_source_remove(op->
opaque->timerid);
506 if (dbus_pending_call_get_completed(op->
opaque->pending)) {
508 crm_warn(
"Result of %s op %s was unhandled",
511 crm_debug(
"Will ignore any result of canceled %s op %s",
514 dbus_pending_call_cancel(op->
opaque->pending);
515 services_set_op_pending(op, NULL);
559 crm_warn(
"Treating result from unknown standard '%s' as OCF",
560 ((standard == NULL)?
"unspecified" : standard));
578 CRM_CHECK(g_list_find(inflight_ops, op) == NULL,
return);
579 CRM_CHECK(g_list_find(blocked_ops, op) == NULL,
return);
581 || (g_hash_table_lookup(recurring_actions, op->
id) == NULL),
601 free(op->
opaque->job_path);
616 g_hash_table_destroy(op->
params);
628 if (recurring_actions) {
629 g_hash_table_remove(recurring_actions, op->
id);
652 gboolean cancelled = FALSE;
657 init_recurring_actions();
658 op = g_hash_table_lookup(recurring_actions,
id);
676 crm_info(
"Terminating in-flight op %s[%d] early because it was cancelled",
679 if (cancelled == FALSE) {
680 crm_err(
"Termination of %s[%d] failed",
id, op->
pid);
687 if (inflight_systemd(op)) {
688 inflight_ops = g_list_remove(inflight_ops, op);
707 blocked_ops = g_list_remove(blocked_ops, op);
723 init_recurring_actions();
724 op = g_hash_table_lookup(recurring_actions,
id);
732 if (op->
pid || inflight_systemd(op)) {
759 dup = g_hash_table_lookup(recurring_actions, op->
id);
761 if (dup && (dup != op)) {
824 inflight_ops = g_list_append(inflight_ops, op);
838 inflight_ops = g_list_remove(inflight_ops, op);
839 blocked_ops = g_list_remove(blocked_ops, op);
842 handle_blocked_ops();
853 if (action_callback != NULL) {
856 if (action_fork_callback != NULL) {
861 init_recurring_actions();
862 if (handle_duplicate_recurring(op)) {
867 g_hash_table_replace(recurring_actions, op->
id, op);
872 blocked_ops = g_list_append(blocked_ops, op);
886static gboolean processing_blocked_ops = FALSE;
894 for (gIter = inflight_ops; gIter != NULL; gIter = gIter->next) {
905handle_blocked_ops(
void)
907 GList *executed_ops = NULL;
911 if (processing_blocked_ops) {
916 processing_blocked_ops = TRUE;
920 for (gIter = blocked_ops; gIter != NULL; gIter = gIter->next) {
925 executed_ops = g_list_append(executed_ops, op);
933 for (gIter = executed_ops; gIter != NULL; gIter = gIter->next) {
935 blocked_ops = g_list_remove(blocked_ops, op);
937 g_list_free(executed_ops);
939 processing_blocked_ops = FALSE;
953 const char *
class = op->standard;
955 if (op->
agent == NULL) {
956 crm_info(
"Meta-data requested without specifying agent");
963 crm_info(
"Meta-data requested for agent %s without specifying class",
967 "Agent standard not specified");
971#if PCMK__ENABLE_SERVICE
976 crm_info(
"Meta-data requested for %s, but could not determine class",
980 "Agent standard could not be determined");
992 return execute_action(op);
1015 rc = (execute_metadata_action(op) ==
pcmk_rc_ok);
1039 GList *standards = NULL;
1043#if PCMK__ENABLE_SERVICE
1055 if (agents != NULL) {
1056 standards = g_list_append(standards,
1058 g_list_free_full(agents, free);
1079 if ((standard == NULL)
1089 if (standard == NULL) {
1093 result = g_list_concat(tmp1, tmp2);
1105 result = g_list_concat(tmp1, tmp2);
1129 GList *standards = NULL;
1130 GList *providers = NULL;
1132 gboolean rc = FALSE;
1133 gboolean has_providers = FALSE;
1136 for (iter = standards; iter != NULL; iter = iter->next) {
1150 if (has_providers == TRUE && provider != NULL) {
1152 for (iter = providers; iter != NULL; iter = iter->next) {
1158 }
else if (has_providers == FALSE && provider == NULL) {
1166#if PCMK__ENABLE_SERVICE
1203 g_list_free(standards);
1204 g_list_free(providers);
1225 action->rc = agent_status;
1226 action->status = exec_status;
1228 if (!pcmk__str_eq(
action->opaque->exit_reason, reason,
1230 free(
action->opaque->exit_reason);
1231 action->opaque->exit_reason = (reason == NULL)? NULL : strdup(reason);
1263 const char *format, ...)
1267 char *reason = NULL;
1273 action->rc = agent_status;
1274 action->status = exec_status;
1276 if (format != NULL) {
1277 va_start(ap, format);
1278 len = vasprintf(&reason, format, ap);
1282 free(
action->opaque->exit_reason);
1283 action->opaque->exit_reason = reason;
1299 free(
action->opaque->exit_reason);
1300 action->opaque->exit_reason = NULL;
1319 return "Fence agent";
1322 return "Alert agent";
1324 return "Resource agent";
1339 return action->opaque->exit_reason;
1355 char *output =
action->stdout_data;
1357 action->stdout_data = NULL;
1374 char *output =
action->stderr_data;
1376 action->stderr_data = NULL;
#define PCMK_ACTION_STATUS
#define PCMK_ACTION_META_DATA
#define PCMK_ACTION_MONITOR
char * pcmk__op_key(const char *rsc_id, const char *op_type, guint interval_ms)
Generate an operation key (RESOURCE_ACTION_INTERVAL)
#define PCMK__OP_FMT
printf-style format to create operation key from resource, action, interval
#define PCMK_RESOURCE_CLASS_SYSTEMD
uint32_t pcmk_get_ra_caps(const char *standard)
Get capabilities of a resource agent standard.
#define PCMK_RESOURCE_CLASS_SERVICE
#define PCMK_RESOURCE_CLASS_STONITH
#define PCMK_RESOURCE_CLASS_ALERT
#define PCMK_RESOURCE_CLASS_OCF
#define PCMK_RESOURCE_CLASS_LSB
int crm_user_lookup(const char *name, uid_t *uid, gid_t *gid)
#define pcmk_is_set(g, f)
Convenience alias for pcmk_all_flags_set(), to check single flag.
#define PCMK__ENABLE_SERVICE
#define crm_info(fmt, args...)
#define crm_warn(fmt, args...)
#define crm_crit(fmt, args...)
#define CRM_CHECK(expr, failure_action)
#define crm_debug(fmt, args...)
#define crm_err(fmt, args...)
#define crm_trace(fmt, args...)
Wrappers for and extensions to glib mainloop.
void mainloop_del_fd(mainloop_io_t *client)
gboolean mainloop_child_kill(pid_t pid)
pcmk__action_result_t result
ocf_exitcode
Exit status codes for resource agents.
@ PCMK_OCF_UNKNOWN_ERROR
Unspecified error.
@ PCMK_OCF_UNKNOWN
Action is pending.
pcmk_exec_status
Execution status.
@ PCMK_EXEC_CANCELLED
Action was cancelled.
@ PCMK_EXEC_ERROR_FATAL
Execution failed, do not retry anywhere.
@ PCMK_EXEC_DONE
Action completed, result is known.
@ PCMK_EXEC_ERROR
Execution failed, may be retried.
@ PCMK_EXEC_UNKNOWN
Used only to initialize variables.
@ PCMK_EXEC_ERROR_HARD
Execution failed, do not retry on node.
int pcmk_legacy2rc(int legacy_rc)
void pcmk__set_result(pcmk__action_result_t *result, int exit_status, enum pcmk_exec_status exec_status, const char *exit_reason)
#define pcmk__assert(expr)
#define pcmk__mem_assert(ptr)
svc_action_t * services_alert_create(const char *id, const char *exec, int timeout, GHashTable *params, int sequence, void *cb_data)
Create an alert agent action.
const char * resources_find_service_class(const char *agent)
Find first service class that can provide a specified agent.
char * services__grab_stdout(svc_action_t *action)
gboolean resources_agent_exists(const char *standard, const char *provider, const char *agent)
Check whether a resource agent exists on the local host.
gboolean services_action_kick(const char *name, const char *action, guint interval_ms)
Reschedule a recurring action for immediate execution.
void services__copy_result(const svc_action_t *action, pcmk__action_result_t *result)
int services_action_user(svc_action_t *op, const char *user)
Set the user and group that an action will execute as.
const char * services__action_kind(const svc_action_t *action)
GList * resources_list_agents(const char *standard, const char *provider)
Get a list of resource agents.
gboolean services_action_async(svc_action_t *op, void(*action_callback)(svc_action_t *))
Request asynchronous execution of an action.
gboolean services_action_cancel(const char *name, const char *action, guint interval_ms)
Cancel a recurring action.
gboolean services_action_sync(svc_action_t *op)
GList * resources_list_standards(void)
void services_action_free(svc_action_t *op)
svc_action_t * services__create_resource_action(const char *name, const char *standard, const char *provider, const char *agent, const char *action, guint interval_ms, int timeout, GHashTable *params, enum svc_action_flags flags)
Create a new resource action.
gboolean cancel_recurring_action(svc_action_t *op)
gboolean services_alert_async(svc_action_t *action, void(*cb)(svc_action_t *op))
Execute an alert agent action.
const char * services__exit_reason(const svc_action_t *action)
void services__set_cancelled(svc_action_t *action)
svc_action_t * resources_action_create(const char *name, const char *standard, const char *provider, const char *agent, const char *action, guint interval_ms, int timeout, GHashTable *params, enum svc_action_flags flags)
Create a new resource action.
void services_untrack_op(const svc_action_t *op)
char * services__grab_stderr(svc_action_t *action)
void services__set_result(svc_action_t *action, int agent_status, enum pcmk_exec_status exec_status, const char *reason)
enum ocf_exitcode services_result2ocf(const char *standard, const char *action, int exit_status)
void services_action_cleanup(svc_action_t *op)
GList * resources_list_providers(const char *standard)
Get a list of providers.
svc_action_t * services_action_create_generic(const char *exec, const char *args[])
Request execution of an arbitrary command.
void services_add_inflight_op(svc_action_t *op)
GList * get_directory_list(const char *root, gboolean files, gboolean executable)
Get a list of files or directories in a given path.
gboolean services_action_async_fork_notify(svc_action_t *op, void(*action_callback)(svc_action_t *), void(*action_fork_callback)(svc_action_t *))
Run an action asynchronously, with callback after process is forked.
void services__format_result(svc_action_t *action, int agent_status, enum pcmk_exec_status exec_status, const char *format,...)
gboolean is_op_blocked(const char *rsc)
void services__handle_exec_error(svc_action_t *op, int error)
int services__execute_file(svc_action_t *op)
int services__finalize_async_op(svc_action_t *op)
gboolean recurring_action_timer(gpointer data)
GList * services_os_get_directory_list(const char *root, gboolean files, gboolean executable)
int services__generic_error(const svc_action_t *op)
int services__lsb_prepare(svc_action_t *op)
GList * services__list_lsb_agents(void)
bool services__lsb_agent_exists(const char *agent)
enum ocf_exitcode services__lsb2ocf(const char *action, int exit_status)
int services__get_lsb_metadata(const char *type, char **output)
gboolean services__ocf_agent_exists(const char *provider, const char *agent)
GList * resources_os_list_ocf_providers(void)
int services__ocf_prepare(svc_action_t *op)
enum ocf_exitcode services__ocf2ocf(int exit_status)
GList * resources_os_list_ocf_agents(const char *provider)
GHashTable * pcmk__strkey_table(GDestroyNotify key_destroy_func, GDestroyNotify value_destroy_func)
#define pcmk__str_copy(str)
void(* fork_callback)(svc_action_t *op)
mainloop_io_t * stdout_gsource
mainloop_io_t * stderr_gsource
void(* callback)(svc_action_t *op)
Object for executing external actions.
void * cb_data
For caller's use (not used by library)
char * provider
Resource provider for resource actions that require it, otherwise NULL.
char * agent
Resource agent name for resource actions, otherwise NULL.
char * standard
Resource standard for resource actions, otherwise NULL.
int rc
Exit status of action (set by library upon completion)
char * rsc
XML ID of resource being executed for resource actions, otherwise NULL.
char * action
Name of action being executed for resource actions, otherwise NULL.
enum svc_action_flags flags
Flag group of enum svc_action_flags.
char * stderr_data
Action stderr (set by library)
int timeout
Action timeout (in milliseconds)
char * stdout_data
Action stdout (set by library)
guint interval_ms
Action interval for recurring resource actions, otherwise 0.
int status
Execution status (enum pcmk_exec_status set by library)
svc_action_private_t * opaque
This field should be treated as internal to Pacemaker.
enum ocf_exitcode services__systemd2ocf(int exit_status)
int services__execute_systemd(svc_action_t *op)
int services__systemd_prepare(svc_action_t *op)
GList * systemd_unit_listall(void)
bool systemd_unit_exists(const char *name)
Wrappers for and extensions to libxml2.