summaryrefslogtreecommitdiffstats
path: root/include/crm/pengine/internal.h
blob: caf1e213ccf49472d8261d2dc35cc525b4d9c3b6 (plain)
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
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
/*
 * Copyright 2004-2024 the Pacemaker project contributors
 *
 * The version control history for this file may have further details.
 *
 * This source code is licensed under the GNU Lesser General Public License
 * version 2.1 or later (LGPLv2.1+) WITHOUT ANY WARRANTY.
 */

#ifndef PE_INTERNAL__H
#  define PE_INTERNAL__H

#  include <stdbool.h>
#  include <stdint.h>
#  include <string.h>
#  include <crm/common/xml.h>
#  include <crm/pengine/status.h>
#  include <crm/pengine/remote_internal.h>
#  include <crm/common/internal.h>
#  include <crm/common/options_internal.h>
#  include <crm/common/output_internal.h>
#  include <crm/common/scheduler_internal.h>

const char *pe__resource_description(const pcmk_resource_t *rsc,
                                     uint32_t show_opts);

bool pe__clone_is_ordered(const pcmk_resource_t *clone);
int pe__set_clone_flag(pcmk_resource_t *clone, enum pcmk__clone_flags flag);
bool pe__clone_flag_is_set(const pcmk_resource_t *clone, uint32_t flags);

bool pe__group_flag_is_set(const pcmk_resource_t *group, uint32_t flags);
pcmk_resource_t *pe__last_group_member(const pcmk_resource_t *group);

const pcmk_resource_t *pe__const_top_resource(const pcmk_resource_t *rsc,
                                              bool include_bundle);

int pe__clone_max(const pcmk_resource_t *clone);
int pe__clone_node_max(const pcmk_resource_t *clone);
int pe__clone_promoted_max(const pcmk_resource_t *clone);
int pe__clone_promoted_node_max(const pcmk_resource_t *clone);
void pe__create_clone_notifications(pcmk_resource_t *clone);
void pe__free_clone_notification_data(pcmk_resource_t *clone);
void pe__create_clone_notif_pseudo_ops(pcmk_resource_t *clone,
                                       pcmk_action_t *start,
                                       pcmk_action_t *started,
                                       pcmk_action_t *stop,
                                       pcmk_action_t *stopped);

pcmk_action_t *pe__new_rsc_pseudo_action(pcmk_resource_t *rsc, const char *task,
                                         bool optional, bool runnable);

void pe__create_promotable_pseudo_ops(pcmk_resource_t *clone,
                                      bool any_promoting, bool any_demoting);

bool pe_can_fence(const pcmk_scheduler_t *scheduler, const pcmk_node_t *node);

char *native_parameter(pcmk_resource_t *rsc, pcmk_node_t *node, gboolean create,
                       const char *name, pcmk_scheduler_t *scheduler);
pcmk_node_t *native_location(const pcmk_resource_t *rsc, GList **list,
                             int current);
void native_add_running(pcmk_resource_t *rsc, pcmk_node_t *node,
                        pcmk_scheduler_t *scheduler, gboolean failed);

gboolean native_unpack(pcmk_resource_t *rsc, pcmk_scheduler_t *scheduler);
gboolean group_unpack(pcmk_resource_t *rsc, pcmk_scheduler_t *scheduler);
gboolean clone_unpack(pcmk_resource_t *rsc, pcmk_scheduler_t *scheduler);
gboolean pe__unpack_bundle(pcmk_resource_t *rsc, pcmk_scheduler_t *scheduler);

pcmk_resource_t *native_find_rsc(pcmk_resource_t *rsc, const char *id,
                                 const pcmk_node_t *node, int flags);

gboolean native_active(pcmk_resource_t *rsc, gboolean all);
gboolean group_active(pcmk_resource_t *rsc, gboolean all);
gboolean clone_active(pcmk_resource_t *rsc, gboolean all);
gboolean pe__bundle_active(pcmk_resource_t *rsc, gboolean all);

//! \deprecated This function will be removed in a future release
void native_print(pcmk_resource_t *rsc, const char *pre_text, long options,
                  void *print_data);

//! \deprecated This function will be removed in a future release
void group_print(pcmk_resource_t *rsc, const char *pre_text, long options,
                 void *print_data);

//! \deprecated This function will be removed in a future release
void clone_print(pcmk_resource_t *rsc, const char *pre_text, long options,
                 void *print_data);

//! \deprecated This function will be removed in a future release
void pe__print_bundle(pcmk_resource_t *rsc, const char *pre_text, long options,
                      void *print_data);

gchar *pcmk__native_output_string(const pcmk_resource_t *rsc, const char *name,
                                  const pcmk_node_t *node, uint32_t show_opts,
                                  const char *target_role, bool show_nodes);

int pe__name_and_nvpairs_xml(pcmk__output_t *out, bool is_list, const char *tag_name,
                             ...) G_GNUC_NULL_TERMINATED;
char *pe__node_display_name(pcmk_node_t *node, bool print_detail);


// Clone notifications (pe_notif.c)
void pe__order_notifs_after_fencing(const pcmk_action_t *action,
                                    pcmk_resource_t *rsc,
                                    pcmk_action_t *stonith_op);


// Resource output methods
int pe__clone_xml(pcmk__output_t *out, va_list args);
int pe__clone_default(pcmk__output_t *out, va_list args);
int pe__group_xml(pcmk__output_t *out, va_list args);
int pe__group_default(pcmk__output_t *out, va_list args);
int pe__bundle_xml(pcmk__output_t *out, va_list args);
int pe__bundle_html(pcmk__output_t *out, va_list args);
int pe__bundle_text(pcmk__output_t *out, va_list args);
int pe__node_html(pcmk__output_t *out, va_list args);
int pe__node_text(pcmk__output_t *out, va_list args);
int pe__node_xml(pcmk__output_t *out, va_list args);
int pe__resource_xml(pcmk__output_t *out, va_list args);
int pe__resource_html(pcmk__output_t *out, va_list args);
int pe__resource_text(pcmk__output_t *out, va_list args);

void native_free(pcmk_resource_t *rsc);
void group_free(pcmk_resource_t *rsc);
void clone_free(pcmk_resource_t *rsc);
void pe__free_bundle(pcmk_resource_t *rsc);

enum rsc_role_e native_resource_state(const pcmk_resource_t *rsc,
                                      gboolean current);
enum rsc_role_e group_resource_state(const pcmk_resource_t *rsc,
                                     gboolean current);
enum rsc_role_e clone_resource_state(const pcmk_resource_t *rsc,
                                     gboolean current);
enum rsc_role_e pe__bundle_resource_state(const pcmk_resource_t *rsc,
                                          gboolean current);

void pe__count_common(pcmk_resource_t *rsc);
void pe__count_bundle(pcmk_resource_t *rsc);

void common_free(pcmk_resource_t *rsc);

pcmk_node_t *pe__copy_node(const pcmk_node_t *this_node);
time_t get_effective_time(pcmk_scheduler_t *scheduler);

/* Failure handling utilities (from failcounts.c) */

int pe_get_failcount(const pcmk_node_t *node, pcmk_resource_t *rsc,
                     time_t *last_failure, uint32_t flags,
                     const xmlNode *xml_op);

pcmk_action_t *pe__clear_failcount(pcmk_resource_t *rsc,
                                   const pcmk_node_t *node, const char *reason,
                                   pcmk_scheduler_t *scheduler);

/* Functions for finding/counting a resource's active nodes */

bool pe__count_active_node(const pcmk_resource_t *rsc, pcmk_node_t *node,
                           pcmk_node_t **active, unsigned int *count_all,
                           unsigned int *count_clean);

pcmk_node_t *pe__find_active_requires(const pcmk_resource_t *rsc,
                                    unsigned int *count);

/* Binary like operators for lists of nodes */
GHashTable *pe__node_list2table(const GList *list);

pcmk_action_t *get_pseudo_op(const char *name, pcmk_scheduler_t *scheduler);
gboolean order_actions(pcmk_action_t *lh_action, pcmk_action_t *rh_action,
                       uint32_t flags);

void pe__show_node_scores_as(const char *file, const char *function,
                             int line, bool to_log, const pcmk_resource_t *rsc,
                             const char *comment, GHashTable *nodes,
                             pcmk_scheduler_t *scheduler);

#define pe__show_node_scores(level, rsc, text, nodes, scheduler)    \
        pe__show_node_scores_as(__FILE__, __func__, __LINE__,      \
                                (level), (rsc), (text), (nodes), (scheduler))

GHashTable *pcmk__unpack_action_meta(pcmk_resource_t *rsc,
                                     const pcmk_node_t *node,
                                     const char *action_name, guint interval_ms,
                                     const xmlNode *action_config);
GHashTable *pcmk__unpack_action_rsc_params(const xmlNode *action_xml,
                                           GHashTable *node_attrs,
                                           pcmk_scheduler_t *data_set);
xmlNode *pcmk__find_action_config(const pcmk_resource_t *rsc,
                                  const char *action_name, guint interval_ms,
                                  bool include_disabled);

enum rsc_start_requirement pcmk__action_requires(const pcmk_resource_t *rsc,
                                                 const char *action_name);

enum action_fail_response pcmk__parse_on_fail(const pcmk_resource_t *rsc,
                                              const char *action_name,
                                              guint interval_ms,
                                              const char *value);

enum rsc_role_e pcmk__role_after_failure(const pcmk_resource_t *rsc,
                                         const char *action_name,
                                         enum action_fail_response on_fail,
                                         GHashTable *meta);

pcmk_action_t *custom_action(pcmk_resource_t *rsc, char *key, const char *task,
                             const pcmk_node_t *on_node, gboolean optional,
                             pcmk_scheduler_t *scheduler);

#  define delete_key(rsc) pcmk__op_key(rsc->id, PCMK_ACTION_DELETE, 0)
#  define delete_action(rsc, node, optional) custom_action(		\
		rsc, delete_key(rsc), PCMK_ACTION_DELETE, node, \
		optional, rsc->cluster);

#  define stop_key(rsc) pcmk__op_key(rsc->id, PCMK_ACTION_STOP, 0)
#  define stop_action(rsc, node, optional) custom_action(			\
		rsc, stop_key(rsc), PCMK_ACTION_STOP, node,		\
		optional, rsc->cluster);

#  define reload_key(rsc) pcmk__op_key(rsc->id, PCMK_ACTION_RELOAD_AGENT, 0)
#  define start_key(rsc) pcmk__op_key(rsc->id, PCMK_ACTION_START, 0)
#  define start_action(rsc, node, optional) custom_action(		\
		rsc, start_key(rsc), PCMK_ACTION_START, node,           \
		optional, rsc->cluster)

#  define promote_key(rsc) pcmk__op_key(rsc->id, PCMK_ACTION_PROMOTE, 0)
#  define promote_action(rsc, node, optional) custom_action(		\
		rsc, promote_key(rsc), PCMK_ACTION_PROMOTE, node,	\
		optional, rsc->cluster)

#  define demote_key(rsc) pcmk__op_key(rsc->id, PCMK_ACTION_DEMOTE, 0)
#  define demote_action(rsc, node, optional) custom_action(		\
		rsc, demote_key(rsc), PCMK_ACTION_DEMOTE, node, \
		optional, rsc->cluster)

pcmk_action_t *find_first_action(const GList *input, const char *uuid,
                                 const char *task, const pcmk_node_t *on_node);

enum action_tasks get_complex_task(const pcmk_resource_t *rsc,
                                   const char *name);

GList *find_actions(GList *input, const char *key, const pcmk_node_t *on_node);
GList *find_actions_exact(GList *input, const char *key,
                          const pcmk_node_t *on_node);
GList *pe__resource_actions(const pcmk_resource_t *rsc, const pcmk_node_t *node,
                            const char *task, bool require_node);

extern void pe_free_action(pcmk_action_t *action);

void resource_location(pcmk_resource_t *rsc, const pcmk_node_t *node, int score,
                       const char *tag, pcmk_scheduler_t *scheduler);

extern int pe__is_newer_op(const xmlNode *xml_a, const xmlNode *xml_b,
                           bool same_node_default);
extern gint sort_op_by_callid(gconstpointer a, gconstpointer b);
gboolean get_target_role(const pcmk_resource_t *rsc, enum rsc_role_e *role);
void pe__set_next_role(pcmk_resource_t *rsc, enum rsc_role_e role,
                       const char *why);

pcmk_resource_t *find_clone_instance(const pcmk_resource_t *rsc,
                                     const char *sub_id);

extern void destroy_ticket(gpointer data);
pcmk_ticket_t *ticket_new(const char *ticket_id, pcmk_scheduler_t *scheduler);

// Resources for manipulating resource names
const char *pe_base_name_end(const char *id);
char *clone_strip(const char *last_rsc_id);
char *clone_zero(const char *last_rsc_id);

static inline bool
pe_base_name_eq(const pcmk_resource_t *rsc, const char *id)
{
    if (id && rsc && rsc->id) {
        // Number of characters in rsc->id before any clone suffix
        size_t base_len = pe_base_name_end(rsc->id) - rsc->id + 1;

        return (strlen(id) == base_len) && !strncmp(id, rsc->id, base_len);
    }
    return false;
}

int pe__target_rc_from_xml(const xmlNode *xml_op);

gint pe__cmp_node_name(gconstpointer a, gconstpointer b);
bool is_set_recursive(const pcmk_resource_t *rsc, long long flag, bool any);

pcmk__op_digest_t *pe__calculate_digests(pcmk_resource_t *rsc, const char *task,
                                         guint *interval_ms,
                                         const pcmk_node_t *node,
                                         const xmlNode *xml_op,
                                         GHashTable *overrides,
                                         bool calc_secure,
                                         pcmk_scheduler_t *scheduler);

void pe__free_digests(gpointer ptr);

pcmk__op_digest_t *rsc_action_digest_cmp(pcmk_resource_t *rsc,
                                         const xmlNode *xml_op,
                                         pcmk_node_t *node,
                                         pcmk_scheduler_t *scheduler);

pcmk_action_t *pe_fence_op(pcmk_node_t *node, const char *op, bool optional,
                           const char *reason, bool priority_delay,
                           pcmk_scheduler_t *scheduler);
void trigger_unfencing(pcmk_resource_t *rsc, pcmk_node_t *node,
                       const char *reason, pcmk_action_t *dependency,
                       pcmk_scheduler_t *scheduler);

char *pe__action2reason(const pcmk_action_t *action, enum pe_action_flags flag);
void pe_action_set_reason(pcmk_action_t *action, const char *reason,
                          bool overwrite);
void pe__add_action_expected_result(pcmk_action_t *action, int expected_result);

void pe__set_resource_flags_recursive(pcmk_resource_t *rsc, uint64_t flags);
void pe__clear_resource_flags_recursive(pcmk_resource_t *rsc, uint64_t flags);
void pe__clear_resource_flags_on_all(pcmk_scheduler_t *scheduler,
                                     uint64_t flag);

gboolean add_tag_ref(GHashTable * tags, const char * tag_name,  const char * obj_ref);

//! \deprecated This function will be removed in a future release
void print_rscs_brief(GList *rsc_list, const char * pre_text, long options,
                      void * print_data, gboolean print_all);
int pe__rscs_brief_output(pcmk__output_t *out, GList *rsc_list, unsigned int options);
void pe_fence_node(pcmk_scheduler_t *scheduler, pcmk_node_t *node,
                   const char *reason, bool priority_delay);

pcmk_node_t *pe_create_node(const char *id, const char *uname, const char *type,
                            const char *score, pcmk_scheduler_t *scheduler);

//! \deprecated This function will be removed in a future release
void common_print(pcmk_resource_t *rsc, const char *pre_text, const char *name,
                  const pcmk_node_t *node, long options, void *print_data);
int pe__common_output_text(pcmk__output_t *out, const pcmk_resource_t *rsc,
                           const char *name, const pcmk_node_t *node,
                           unsigned int options);
int pe__common_output_html(pcmk__output_t *out, const pcmk_resource_t *rsc,
                           const char *name, const pcmk_node_t *node,
                           unsigned int options);

GList *pe__bundle_containers(const pcmk_resource_t *bundle);

int pe__bundle_max(const pcmk_resource_t *rsc);
bool pe__node_is_bundle_instance(const pcmk_resource_t *bundle,
                                 const pcmk_node_t *node);
pcmk_resource_t *pe__bundled_resource(const pcmk_resource_t *rsc);
const pcmk_resource_t *pe__get_rsc_in_container(const pcmk_resource_t *instance);
pcmk_resource_t *pe__first_container(const pcmk_resource_t *bundle);
void pe__foreach_bundle_replica(pcmk_resource_t *bundle,
                                bool (*fn)(pcmk__bundle_replica_t *, void *),
                                void *user_data);
void pe__foreach_const_bundle_replica(const pcmk_resource_t *bundle,
                                      bool (*fn)(const pcmk__bundle_replica_t *,
                                                 void *),
                                      void *user_data);
pcmk_resource_t *pe__find_bundle_replica(const pcmk_resource_t *bundle,
                                         const pcmk_node_t *node);
bool pe__bundle_needs_remote_name(pcmk_resource_t *rsc);
const char *pe__add_bundle_remote_name(pcmk_resource_t *rsc, xmlNode *xml,
                                       const char *field);
bool pe__is_universal_clone(const pcmk_resource_t *rsc,
                            const pcmk_scheduler_t *scheduler);
void pe__add_param_check(const xmlNode *rsc_op, pcmk_resource_t *rsc,
                         pcmk_node_t *node, enum pcmk__check_parameters,
                         pcmk_scheduler_t *scheduler);
void pe__foreach_param_check(pcmk_scheduler_t *scheduler,
                             void (*cb)(pcmk_resource_t*, pcmk_node_t*,
                                        const xmlNode*,
                                        enum pcmk__check_parameters));
void pe__free_param_checks(pcmk_scheduler_t *scheduler);

bool pe__shutdown_requested(const pcmk_node_t *node);
void pe__update_recheck_time(time_t recheck, pcmk_scheduler_t *scheduler,
                             const char *reason);

/*!
 * \internal
 * \brief Register xml formatting message functions.
 *
 * \param[in,out] out  Output object to register messages with
 */
void pe__register_messages(pcmk__output_t *out);

void pe__unpack_dataset_nvpairs(const xmlNode *xml_obj, const char *set_name,
                                const pe_rule_eval_data_t *rule_data,
                                GHashTable *hash, const char *always_first,
                                gboolean overwrite,
                                pcmk_scheduler_t *scheduler);

bool pe__resource_is_disabled(const pcmk_resource_t *rsc);
void pe__clear_resource_history(pcmk_resource_t *rsc, const pcmk_node_t *node);

GList *pe__rscs_with_tag(pcmk_scheduler_t *scheduler, const char *tag_name);
GList *pe__unames_with_tag(pcmk_scheduler_t *scheduler, const char *tag_name);
bool pe__rsc_has_tag(pcmk_scheduler_t *scheduler, const char *rsc,
                     const char *tag);
bool pe__uname_has_tag(pcmk_scheduler_t *scheduler, const char *node,
                       const char *tag);

bool pe__rsc_running_on_only(const pcmk_resource_t *rsc,
                             const pcmk_node_t *node);
bool pe__rsc_running_on_any(pcmk_resource_t *rsc, GList *node_list);
GList *pe__filter_rsc_list(GList *rscs, GList *filter);
GList * pe__build_node_name_list(pcmk_scheduler_t *scheduler, const char *s);
GList * pe__build_rsc_list(pcmk_scheduler_t *scheduler, const char *s);

bool pcmk__rsc_filtered_by_node(pcmk_resource_t *rsc, GList *only_node);

gboolean pe__bundle_is_filtered(const pcmk_resource_t *rsc, GList *only_rsc,
                                gboolean check_parent);
gboolean pe__clone_is_filtered(const pcmk_resource_t *rsc, GList *only_rsc,
                               gboolean check_parent);
gboolean pe__group_is_filtered(const pcmk_resource_t *rsc, GList *only_rsc,
                               gboolean check_parent);
gboolean pe__native_is_filtered(const pcmk_resource_t *rsc, GList *only_rsc,
                                gboolean check_parent);

xmlNode *pe__failed_probe_for_rsc(const pcmk_resource_t *rsc, const char *name);

const char *pe__clone_child_id(const pcmk_resource_t *rsc);

int pe__sum_node_health_scores(const pcmk_node_t *node, int base_health);
int pe__node_health(pcmk_node_t *node);

static inline enum pcmk__health_strategy
pe__health_strategy(pcmk_scheduler_t *scheduler)
{
    const char *strategy = pcmk__cluster_option(scheduler->config_hash,
                                                PCMK_OPT_NODE_HEALTH_STRATEGY);

    return pcmk__parse_health_strategy(strategy);
}

static inline int
pe__health_score(const char *option, pcmk_scheduler_t *scheduler)
{
    const char *value = pcmk__cluster_option(scheduler->config_hash, option);

    return char2score(value);
}

#endif