1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327
|
/*
* Copyright (C) 2004 Andrew Beekhof <andrew@beekhof.net>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include <crm_internal.h>
#include <crm/crm.h>
#include <crm/msg_xml.h>
#include <crm/common/xml.h>
#include <crm/transition.h>
/* #include <sys/param.h> */
/* */
crm_graph_functions_t *graph_fns = NULL;
static gboolean
update_synapse_ready(synapse_t *synapse, int action_id)
{
gboolean updates = FALSE;
CRM_CHECK(synapse->executed == FALSE, return FALSE);
CRM_CHECK(synapse->confirmed == FALSE, return FALSE);
synapse->ready = TRUE;
slist_iter(
prereq, crm_action_t, synapse->inputs, lpc,
crm_debug_3("Processing input %d", prereq->id);
if(prereq->id == action_id) {
crm_debug_2("Marking input %d of synapse %d confirmed",
action_id, synapse->id);
prereq->confirmed = TRUE;
updates = TRUE;
} else if(prereq->confirmed == FALSE) {
synapse->ready = FALSE;
}
);
if(updates) {
crm_debug_2("Updated synapse %d", synapse->id);
}
return updates;
}
static gboolean
update_synapse_confirmed(synapse_t *synapse, int action_id)
{
gboolean updates = FALSE;
gboolean is_confirmed = TRUE;
CRM_CHECK(synapse->executed, return FALSE);
CRM_CHECK(synapse->confirmed == FALSE, return TRUE);
is_confirmed = TRUE;
slist_iter(
action, crm_action_t, synapse->actions, lpc,
crm_debug_3("Processing action %d", action->id);
if(action->id == action_id) {
crm_debug_2("Confirmed: Action %d of Synapse %d",
action_id, synapse->id);
action->confirmed = TRUE;
updates = TRUE;
} else if(action->confirmed == FALSE) {
is_confirmed = FALSE;
crm_debug_3("Synapse %d still not confirmed after action %d",
synapse->id, action_id);
}
);
if(is_confirmed && synapse->confirmed == FALSE) {
crm_debug_2("Confirmed: Synapse %d", synapse->id);
synapse->confirmed = TRUE;
updates = TRUE;
}
if(updates) {
crm_debug_3("Updated synapse %d", synapse->id);
}
return updates;
}
gboolean
update_graph(crm_graph_t *graph, crm_action_t *action)
{
gboolean rc = FALSE;
gboolean updates = FALSE;
slist_iter(
synapse, synapse_t, graph->synapses, lpc,
if (synapse->confirmed) {
crm_debug_2("Synapse complete");
} else if (synapse->executed) {
crm_debug_2("Synapse executed");
rc = update_synapse_confirmed(synapse, action->id);
} else if(action->failed == FALSE || synapse->priority == INFINITY) {
rc = update_synapse_ready(synapse, action->id);
}
updates = updates || rc;
);
if(updates) {
crm_debug_2("Updated graph with completed action %d",
action->id);
}
return updates;
}
static gboolean
should_fire_synapse(synapse_t *synapse)
{
CRM_CHECK(synapse->executed == FALSE, return FALSE);
CRM_CHECK(synapse->confirmed == FALSE, return FALSE);
crm_debug_3("Checking pre-reqs for %d", synapse->id);
/* lookup prereqs */
synapse->ready = TRUE;
slist_iter(
prereq, crm_action_t, synapse->inputs, lpc,
crm_debug_3("Processing input %d", prereq->id);
if(prereq->confirmed == FALSE) {
crm_debug_3("Inputs for synapse %d not satisfied",
synapse->id);
synapse->ready = FALSE;
break;
}
);
return synapse->ready;
}
static gboolean
initiate_action(crm_graph_t *graph, crm_action_t *action)
{
const char *id = NULL;
CRM_CHECK(action->executed == FALSE, return FALSE);
id = ID(action->xml);
CRM_CHECK(id != NULL, return FALSE);
action->executed = TRUE;
if(action->type == action_type_pseudo){
crm_debug_2("Executing pseudo-event: %d", action->id);
return graph_fns->pseudo(graph, action);
} else if(action->type == action_type_rsc) {
crm_debug_2("Executing rsc-event: %d", action->id);
return graph_fns->rsc(graph, action);
} else if(action->type == action_type_crm) {
const char *task = NULL;
task = crm_element_value(action->xml, XML_LRM_ATTR_TASK);
CRM_CHECK(task != NULL, return FALSE);
if(safe_str_eq(task, CRM_OP_FENCE)) {
crm_debug_2("Executing STONITH-event: %d",
action->id);
return graph_fns->stonith(graph, action);
}
crm_debug_2("Executing crm-event: %d", action->id);
return graph_fns->crmd(graph, action);
}
te_log_action(LOG_ERR,
"Failed on unsupported command type: %s (id=%s)",
crm_element_name(action->xml), id);
return FALSE;
}
static gboolean
fire_synapse(crm_graph_t *graph, synapse_t *synapse)
{
CRM_CHECK(synapse != NULL, return FALSE);
CRM_CHECK(synapse->ready, return FALSE);
CRM_CHECK(synapse->confirmed == FALSE, return TRUE);
crm_debug_2("Synapse %d fired", synapse->id);
synapse->executed = TRUE;
slist_iter(
action, crm_action_t, synapse->actions, lpc,
/* allow some leeway */
gboolean passed = FALSE;
/* Invoke the action and start the timer */
passed = initiate_action(graph, action);
if(passed == FALSE) {
crm_err("Failed initiating <%s id=%d> in synapse %d",
crm_element_name(action->xml),
action->id, synapse->id);
synapse->confirmed = TRUE;
action->confirmed = TRUE;
action->failed = TRUE;
return FALSE;
}
);
return TRUE;
}
int
run_graph(crm_graph_t *graph)
{
int stat_log_level = LOG_DEBUG;
int pass_result = transition_active;
const char *status = "In-progress";
if(graph_fns == NULL) {
set_default_graph_functions();
}
if(graph == NULL) {
return transition_complete;
}
graph->fired = 0;
graph->pending = 0;
graph->skipped = 0;
graph->completed = 0;
graph->incomplete = 0;
crm_debug_2("Entering graph %d callback", graph->id);
/* Pre-calculate the number of completed and in-flight operations */
slist_iter(
synapse, synapse_t, graph->synapses, lpc,
if (synapse->confirmed) {
crm_debug_3("Synapse %d complete", synapse->id);
graph->completed++;
} else if(synapse->executed) {
crm_debug_2("Synapse %d: confirmation pending", synapse->id);
graph->pending++;
}
);
/* Now check if there is work to do */
slist_iter(
synapse, synapse_t, graph->synapses, lpc,
if(graph->batch_limit > 0 && graph->pending >= graph->batch_limit) {
crm_debug("Throttling output: batch limit (%d) reached",
graph->batch_limit);
break;
} else if (synapse->confirmed || synapse->executed) {
/* Already handled */
continue;
}
if(synapse->priority < graph->abort_priority) {
crm_debug_2("Skipping synapse %d: aborting", synapse->id);
graph->skipped++;
} else if(should_fire_synapse(synapse)) {
crm_debug_2("Synapse %d fired", synapse->id);
graph->fired++;
CRM_CHECK(fire_synapse(graph, synapse),
stat_log_level = LOG_ERR;
graph->abort_priority = INFINITY;
graph->incomplete++;
graph->fired--);
if (synapse->confirmed == FALSE) {
graph->pending++;
}
} else {
crm_debug_2("Synapse %d cannot fire", synapse->id);
graph->incomplete++;
}
);
if(graph->pending == 0 && graph->fired == 0) {
graph->complete = TRUE;
stat_log_level = LOG_NOTICE;
pass_result = transition_complete;
status = "Complete";
if(graph->incomplete != 0 && graph->abort_priority <= 0) {
stat_log_level = LOG_WARNING;
pass_result = transition_terminated;
status = "Terminated";
} else if(graph->skipped != 0) {
status = "Stopped";
}
} else if(graph->fired == 0) {
pass_result = transition_pending;
}
do_crm_log(stat_log_level+1,
"====================================================");
do_crm_log(stat_log_level,
"Transition %d (Complete=%d, Pending=%d,"
" Fired=%d, Skipped=%d, Incomplete=%d, Source=%s): %s",
graph->id, graph->completed, graph->pending, graph->fired,
graph->skipped, graph->incomplete, graph->source, status);
return pass_result;
}
|