~ampelbein/ubuntu/oneiric/heartbeat/lp-770743

« back to all changes in this revision

Viewing changes to lib/crm/transition/graph.c

  • Committer: Bazaar Package Importer
  • Author(s): Ante Karamatic
  • Date: 2009-08-10 19:29:25 UTC
  • mfrom: (5.2.3 experimental)
  • Revision ID: james.westby@ubuntu.com-20090810192925-9zy2llcbgavbskf7
Tags: 2.99.2+sles11r9-5ubuntu1
* New upstream snapshot
* Adjusted heartbeat.install and rules for documentation path

Show diffs side-by-side

added added

removed removed

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