root/lib/pacemaker/pcmk_scheduler.c

/* [previous][next][first][last][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. check_params
  2. failcount_clear_action_exists
  3. check_failure_threshold
  4. apply_exclusive_discovery
  5. apply_stickiness
  6. apply_shutdown_locks
  7. count_available_nodes
  8. apply_node_criteria
  9. allocate_resources
  10. clear_failcounts_if_orphaned
  11. schedule_resource_actions
  12. is_managed
  13. any_managed_resources
  14. needs_fencing
  15. needs_shutdown
  16. add_nondc_fencing
  17. schedule_fencing
  18. schedule_fencing_and_shutdowns
  19. log_resource_details
  20. log_all_actions
  21. log_unrunnable_actions
  22. unpack_cib
  23. pcmk__schedule_actions

   1 /*
   2  * Copyright 2004-2023 the Pacemaker project contributors
   3  *
   4  * The version control history for this file may have further details.
   5  *
   6  * This source code is licensed under the GNU General Public License version 2
   7  * or later (GPLv2+) WITHOUT ANY WARRANTY.
   8  */
   9 
  10 #include <crm_internal.h>
  11 
  12 #include <crm/crm.h>
  13 #include <crm/cib.h>
  14 #include <crm/msg_xml.h>
  15 #include <crm/common/xml.h>
  16 #include <crm/common/xml_internal.h>
  17 
  18 #include <glib.h>
  19 
  20 #include <crm/pengine/status.h>
  21 #include <pacemaker-internal.h>
  22 #include "libpacemaker_private.h"
  23 
  24 CRM_TRACE_INIT_DATA(pacemaker);
  25 
  26 /*!
  27  * \internal
  28  * \brief Do deferred action checks after allocation
  29  *
  30  * When unpacking the resource history, the scheduler checks for resource
  31  * configurations that have changed since an action was run. However, at that
  32  * time, bundles using the REMOTE_CONTAINER_HACK don't have their final
  33  * parameter information, so instead they add a deferred check to a list. This
  34  * function processes one entry in that list.
  35  *
  36  * \param[in,out] rsc     Resource that action history is for
  37  * \param[in,out] node    Node that action history is for
  38  * \param[in]     rsc_op  Action history entry
  39  * \param[in]     check   Type of deferred check to do
  40  */
  41 static void
  42 check_params(pe_resource_t *rsc, pe_node_t *node, const xmlNode *rsc_op,
     /* [previous][next][first][last][top][bottom][index][help] */
  43              enum pe_check_parameters check)
  44 {
  45     const char *reason = NULL;
  46     op_digest_cache_t *digest_data = NULL;
  47 
  48     switch (check) {
  49         case pe_check_active:
  50             if (pcmk__check_action_config(rsc, node, rsc_op)
  51                 && pe_get_failcount(node, rsc, NULL, pe_fc_effective, NULL)) {
  52                 reason = "action definition changed";
  53             }
  54             break;
  55 
  56         case pe_check_last_failure:
  57             digest_data = rsc_action_digest_cmp(rsc, rsc_op, node,
  58                                                 rsc->cluster);
  59             switch (digest_data->rc) {
  60                 case RSC_DIGEST_UNKNOWN:
  61                     crm_trace("Resource %s history entry %s on %s has "
  62                               "no digest to compare",
  63                               rsc->id, ID(rsc_op), node->details->id);
  64                     break;
  65                 case RSC_DIGEST_MATCH:
  66                     break;
  67                 default:
  68                     reason = "resource parameters have changed";
  69                     break;
  70             }
  71             break;
  72     }
  73     if (reason != NULL) {
  74         pe__clear_failcount(rsc, node, reason, rsc->cluster);
  75     }
  76 }
  77 
  78 /*!
  79  * \internal
  80  * \brief Check whether a resource has failcount clearing scheduled on a node
  81  *
  82  * \param[in] node  Node to check
  83  * \param[in] rsc   Resource to check
  84  *
  85  * \return true if \p rsc has failcount clearing scheduled on \p node,
  86  *         otherwise false
  87  */
  88 static bool
  89 failcount_clear_action_exists(const pe_node_t *node, const pe_resource_t *rsc)
     /* [previous][next][first][last][top][bottom][index][help] */
  90 {
  91     GList *list = pe__resource_actions(rsc, node, CRM_OP_CLEAR_FAILCOUNT, TRUE);
  92 
  93     if (list != NULL) {
  94         g_list_free(list);
  95         return true;
  96     }
  97     return false;
  98 }
  99 
 100 /*!
 101  * \internal
 102  * \brief Ban a resource from a node if it reached its failure threshold there
 103  *
 104  * \param[in,out] rsc   Resource to check failure threshold for
 105  * \param[in]     node  Node to check \p rsc on
 106  */
 107 static void
 108 check_failure_threshold(pe_resource_t *rsc, const pe_node_t *node)
     /* [previous][next][first][last][top][bottom][index][help] */
 109 {
 110     // If this is a collective resource, apply recursively to children instead
 111     if (rsc->children != NULL) {
 112         g_list_foreach(rsc->children, (GFunc) check_failure_threshold,
 113                        (gpointer) node);
 114         return;
 115 
 116     } else if (failcount_clear_action_exists(node, rsc)) {
 117         /* Don't force the resource away from this node due to a failcount
 118          * that's going to be cleared.
 119          *
 120          * @TODO Failcount clearing can be scheduled in
 121          * pcmk__handle_rsc_config_changes() via process_rsc_history(), or in
 122          * schedule_resource_actions() via check_params(). This runs well before
 123          * then, so it cannot detect those, meaning we might check the migration
 124          * threshold when we shouldn't. Worst case, we stop or move the
 125          * resource, then move it back in the next transition.
 126          */
 127         return;
 128 
 129     } else {
 130         pe_resource_t *failed = NULL;
 131 
 132         if (pcmk__threshold_reached(rsc, node, &failed)) {
 133             resource_location(failed, node, -INFINITY, "__fail_limit__",
 134                               rsc->cluster);
 135         }
 136     }
 137 }
 138 
 139 /*!
 140  * \internal
 141  * \brief If resource has exclusive discovery, ban node if not allowed
 142  *
 143  * Location constraints have a resource-discovery option that allows users to
 144  * specify where probes are done for the affected resource. If this is set to
 145  * exclusive, probes will only be done on nodes listed in exclusive constraints.
 146  * This function bans the resource from the node if the node is not listed.
 147  *
 148  * \param[in,out] rsc   Resource to check
 149  * \param[in]     node  Node to check \p rsc on
 150  */
 151 static void
 152 apply_exclusive_discovery(pe_resource_t *rsc, const pe_node_t *node)
     /* [previous][next][first][last][top][bottom][index][help] */
 153 {
 154     if (rsc->exclusive_discover
 155         || pe__const_top_resource(rsc, false)->exclusive_discover) {
 156         pe_node_t *match = NULL;
 157 
 158         // If this is a collective resource, apply recursively to children
 159         g_list_foreach(rsc->children, (GFunc) apply_exclusive_discovery,
 160                        (gpointer) node);
 161 
 162         match = g_hash_table_lookup(rsc->allowed_nodes, node->details->id);
 163         if ((match != NULL)
 164             && (match->rsc_discover_mode != pe_discover_exclusive)) {
 165             match->weight = -INFINITY;
 166         }
 167     }
 168 }
 169 
 170 /*!
 171  * \internal
 172  * \brief Apply stickiness to a resource if appropriate
 173  *
 174  * \param[in,out] rsc       Resource to check for stickiness
 175  * \param[in,out] data_set  Cluster working set
 176  */
 177 static void
 178 apply_stickiness(pe_resource_t *rsc, pe_working_set_t *data_set)
     /* [previous][next][first][last][top][bottom][index][help] */
 179 {
 180     pe_node_t *node = NULL;
 181 
 182     // If this is a collective resource, apply recursively to children instead
 183     if (rsc->children != NULL) {
 184         g_list_foreach(rsc->children, (GFunc) apply_stickiness, data_set);
 185         return;
 186     }
 187 
 188     /* A resource is sticky if it is managed, has stickiness configured, and is
 189      * active on a single node.
 190      */
 191     if (!pcmk_is_set(rsc->flags, pe_rsc_managed)
 192         || (rsc->stickiness < 1) || !pcmk__list_of_1(rsc->running_on)) {
 193         return;
 194     }
 195 
 196     node = rsc->running_on->data;
 197 
 198     /* In a symmetric cluster, stickiness can always be used. In an
 199      * asymmetric cluster, we have to check whether the resource is still
 200      * allowed on the node, so we don't keep the resource somewhere it is no
 201      * longer explicitly enabled.
 202      */
 203     if (!pcmk_is_set(rsc->cluster->flags, pe_flag_symmetric_cluster)
 204         && (pe_hash_table_lookup(rsc->allowed_nodes,
 205                                  node->details->id) == NULL)) {
 206         pe_rsc_debug(rsc,
 207                      "Ignoring %s stickiness because the cluster is "
 208                      "asymmetric and %s is not explicitly allowed",
 209                      rsc->id, pe__node_name(node));
 210         return;
 211     }
 212 
 213     pe_rsc_debug(rsc, "Resource %s has %d stickiness on %s",
 214                  rsc->id, rsc->stickiness, pe__node_name(node));
 215     resource_location(rsc, node, rsc->stickiness, "stickiness", data_set);
 216 }
 217 
 218 /*!
 219  * \internal
 220  * \brief Apply shutdown locks for all resources as appropriate
 221  *
 222  * \param[in,out] data_set  Cluster working set
 223  */
 224 static void
 225 apply_shutdown_locks(pe_working_set_t *data_set)
     /* [previous][next][first][last][top][bottom][index][help] */
 226 {
 227     if (!pcmk_is_set(data_set->flags, pe_flag_shutdown_lock)) {
 228         return;
 229     }
 230     for (GList *iter = data_set->resources; iter != NULL; iter = iter->next) {
 231         pe_resource_t *rsc = (pe_resource_t *) iter->data;
 232 
 233         rsc->cmds->shutdown_lock(rsc);
 234     }
 235 }
 236 
 237 /*!
 238  * \internal
 239  * \brief Calculate the number of available nodes in the cluster
 240  *
 241  * \param[in,out] data_set  Cluster working set
 242  */
 243 static void
 244 count_available_nodes(pe_working_set_t *data_set)
     /* [previous][next][first][last][top][bottom][index][help] */
 245 {
 246     if (pcmk_is_set(data_set->flags, pe_flag_no_compat)) {
 247         return;
 248     }
 249 
 250     // @COMPAT for API backward compatibility only (cluster does not use value)
 251     for (GList *iter = data_set->nodes; iter != NULL; iter = iter->next) {
 252         pe_node_t *node = (pe_node_t *) iter->data;
 253 
 254         if ((node != NULL) && (node->weight >= 0) && node->details->online
 255             && (node->details->type != node_ping)) {
 256             data_set->max_valid_nodes++;
 257         }
 258     }
 259     crm_trace("Online node count: %d", data_set->max_valid_nodes);
 260 }
 261 
 262 /*
 263  * \internal
 264  * \brief Apply node-specific scheduling criteria
 265  *
 266  * After the CIB has been unpacked, process node-specific scheduling criteria
 267  * including shutdown locks, location constraints, resource stickiness,
 268  * migration thresholds, and exclusive resource discovery.
 269  */
 270 static void
 271 apply_node_criteria(pe_working_set_t *data_set)
     /* [previous][next][first][last][top][bottom][index][help] */
 272 {
 273     crm_trace("Applying node-specific scheduling criteria");
 274     apply_shutdown_locks(data_set);
 275     count_available_nodes(data_set);
 276     pcmk__apply_locations(data_set);
 277     g_list_foreach(data_set->resources, (GFunc) apply_stickiness, data_set);
 278 
 279     for (GList *node_iter = data_set->nodes; node_iter != NULL;
 280          node_iter = node_iter->next) {
 281         for (GList *rsc_iter = data_set->resources; rsc_iter != NULL;
 282              rsc_iter = rsc_iter->next) {
 283             pe_node_t *node = (pe_node_t *) node_iter->data;
 284             pe_resource_t *rsc = (pe_resource_t *) rsc_iter->data;
 285 
 286             check_failure_threshold(rsc, node);
 287             apply_exclusive_discovery(rsc, node);
 288         }
 289     }
 290 }
 291 
 292 /*!
 293  * \internal
 294  * \brief Allocate resources to nodes
 295  *
 296  * \param[in,out] data_set  Cluster working set
 297  */
 298 static void
 299 allocate_resources(pe_working_set_t *data_set)
     /* [previous][next][first][last][top][bottom][index][help] */
 300 {
 301     GList *iter = NULL;
 302 
 303     crm_trace("Allocating resources to nodes");
 304 
 305     if (!pcmk__str_eq(data_set->placement_strategy, "default", pcmk__str_casei)) {
 306         pcmk__sort_resources(data_set);
 307     }
 308     pcmk__show_node_capacities("Original", data_set);
 309 
 310     if (pcmk_is_set(data_set->flags, pe_flag_have_remote_nodes)) {
 311         /* Allocate remote connection resources first (which will also allocate
 312          * any colocation dependencies). If the connection is migrating, always
 313          * prefer the partial migration target.
 314          */
 315         for (iter = data_set->resources; iter != NULL; iter = iter->next) {
 316             pe_resource_t *rsc = (pe_resource_t *) iter->data;
 317 
 318             if (rsc->is_remote_node) {
 319                 pe_rsc_trace(rsc, "Allocating remote connection resource '%s'",
 320                              rsc->id);
 321                 rsc->cmds->assign(rsc, rsc->partial_migration_target);
 322             }
 323         }
 324     }
 325 
 326     /* now do the rest of the resources */
 327     for (iter = data_set->resources; iter != NULL; iter = iter->next) {
 328         pe_resource_t *rsc = (pe_resource_t *) iter->data;
 329 
 330         if (!rsc->is_remote_node) {
 331             pe_rsc_trace(rsc, "Allocating %s resource '%s'",
 332                          crm_element_name(rsc->xml), rsc->id);
 333             rsc->cmds->assign(rsc, NULL);
 334         }
 335     }
 336 
 337     pcmk__show_node_capacities("Remaining", data_set);
 338 }
 339 
 340 /*!
 341  * \internal
 342  * \brief Schedule fail count clearing on online nodes if resource is orphaned
 343  *
 344  * \param[in,out] rsc       Resource to check
 345  * \param[in,out] data_set  Cluster working set
 346  */
 347 static void
 348 clear_failcounts_if_orphaned(pe_resource_t *rsc, pe_working_set_t *data_set)
     /* [previous][next][first][last][top][bottom][index][help] */
 349 {
 350     if (!pcmk_is_set(rsc->flags, pe_rsc_orphan)) {
 351         return;
 352     }
 353     crm_trace("Clear fail counts for orphaned resource %s", rsc->id);
 354 
 355     /* There's no need to recurse into rsc->children because those
 356      * should just be unallocated clone instances.
 357      */
 358 
 359     for (GList *iter = data_set->nodes; iter != NULL; iter = iter->next) {
 360         pe_node_t *node = (pe_node_t *) iter->data;
 361         pe_action_t *clear_op = NULL;
 362 
 363         if (!node->details->online) {
 364             continue;
 365         }
 366         if (pe_get_failcount(node, rsc, NULL, pe_fc_effective, NULL) == 0) {
 367             continue;
 368         }
 369 
 370         clear_op = pe__clear_failcount(rsc, node, "it is orphaned", data_set);
 371 
 372         /* We can't use order_action_then_stop() here because its
 373          * pe_order_preserve breaks things
 374          */
 375         pcmk__new_ordering(clear_op->rsc, NULL, clear_op, rsc, stop_key(rsc),
 376                            NULL, pe_order_optional, data_set);
 377     }
 378 }
 379 
 380 /*!
 381  * \internal
 382  * \brief Schedule any resource actions needed
 383  *
 384  * \param[in,out] data_set  Cluster working set
 385  */
 386 static void
 387 schedule_resource_actions(pe_working_set_t *data_set)
     /* [previous][next][first][last][top][bottom][index][help] */
 388 {
 389     // Process deferred action checks
 390     pe__foreach_param_check(data_set, check_params);
 391     pe__free_param_checks(data_set);
 392 
 393     if (pcmk_is_set(data_set->flags, pe_flag_startup_probes)) {
 394         crm_trace("Scheduling probes");
 395         pcmk__schedule_probes(data_set);
 396     }
 397 
 398     if (pcmk_is_set(data_set->flags, pe_flag_stop_rsc_orphans)) {
 399         g_list_foreach(data_set->resources,
 400                        (GFunc) clear_failcounts_if_orphaned, data_set);
 401     }
 402 
 403     crm_trace("Scheduling resource actions");
 404     for (GList *iter = data_set->resources; iter != NULL; iter = iter->next) {
 405         pe_resource_t *rsc = (pe_resource_t *) iter->data;
 406 
 407         rsc->cmds->create_actions(rsc);
 408     }
 409 }
 410 
 411 /*!
 412  * \internal
 413  * \brief Check whether a resource or any of its descendants are managed
 414  *
 415  * \param[in] rsc  Resource to check
 416  *
 417  * \return true if resource or any descendant is managed, otherwise false
 418  */
 419 static bool
 420 is_managed(const pe_resource_t *rsc)
     /* [previous][next][first][last][top][bottom][index][help] */
 421 {
 422     if (pcmk_is_set(rsc->flags, pe_rsc_managed)) {
 423         return true;
 424     }
 425     for (GList *iter = rsc->children; iter != NULL; iter = iter->next) {
 426         if (is_managed((pe_resource_t *) iter->data)) {
 427             return true;
 428         }
 429     }
 430     return false;
 431 }
 432 
 433 /*!
 434  * \internal
 435  * \brief Check whether any resources in the cluster are managed
 436  *
 437  * \param[in] data_set  Cluster working set
 438  *
 439  * \return true if any resource is managed, otherwise false
 440  */
 441 static bool
 442 any_managed_resources(const pe_working_set_t *data_set)
     /* [previous][next][first][last][top][bottom][index][help] */
 443 {
 444     for (const GList *iter = data_set->resources;
 445          iter != NULL; iter = iter->next) {
 446         if (is_managed((const pe_resource_t *) iter->data)) {
 447             return true;
 448         }
 449     }
 450     return false;
 451 }
 452 
 453 /*!
 454  * \internal
 455  * \brief Check whether a node requires fencing
 456  *
 457  * \param[in] node          Node to check
 458  * \param[in] have_managed  Whether any resource in cluster is managed
 459  * \param[in] data_set      Cluster working set
 460  *
 461  * \return true if \p node should be fenced, otherwise false
 462  */
 463 static bool
 464 needs_fencing(const pe_node_t *node, bool have_managed,
     /* [previous][next][first][last][top][bottom][index][help] */
 465               const pe_working_set_t *data_set)
 466 {
 467     return have_managed && node->details->unclean
 468            && pe_can_fence(data_set, node);
 469 }
 470 
 471 /*!
 472  * \internal
 473  * \brief Check whether a node requires shutdown
 474  *
 475  * \param[in] node          Node to check
 476  *
 477  * \return true if \p node should be shut down, otherwise false
 478  */
 479 static bool
 480 needs_shutdown(const pe_node_t *node)
     /* [previous][next][first][last][top][bottom][index][help] */
 481 {
 482     if (pe__is_guest_or_remote_node(node)) {
 483        /* Do not send shutdown actions for Pacemaker Remote nodes.
 484         * @TODO We might come up with a good use for this in the future.
 485         */
 486         return false;
 487     }
 488     return node->details->online && node->details->shutdown;
 489 }
 490 
 491 /*!
 492  * \internal
 493  * \brief Track and order non-DC fencing
 494  *
 495  * \param[in,out] list      List of existing non-DC fencing actions
 496  * \param[in,out] action    Fencing action to prepend to \p list
 497  * \param[in]     data_set  Cluster working set
 498  *
 499  * \return (Possibly new) head of \p list
 500  */
 501 static GList *
 502 add_nondc_fencing(GList *list, pe_action_t *action,
     /* [previous][next][first][last][top][bottom][index][help] */
 503                   const pe_working_set_t *data_set)
 504 {
 505     if (!pcmk_is_set(data_set->flags, pe_flag_concurrent_fencing)
 506         && (list != NULL)) {
 507         /* Concurrent fencing is disabled, so order each non-DC
 508          * fencing in a chain. If there is any DC fencing or
 509          * shutdown, it will be ordered after the last action in the
 510          * chain later.
 511          */
 512         order_actions((pe_action_t *) list->data, action, pe_order_optional);
 513     }
 514     return g_list_prepend(list, action);
 515 }
 516 
 517 /*!
 518  * \internal
 519  * \brief Schedule a node for fencing
 520  *
 521  * \param[in,out] node      Node that requires fencing
 522  * \param[in,out] data_set  Cluster working set
 523  */
 524 static pe_action_t *
 525 schedule_fencing(pe_node_t *node, pe_working_set_t *data_set)
     /* [previous][next][first][last][top][bottom][index][help] */
 526 {
 527     pe_action_t *fencing = pe_fence_op(node, NULL, FALSE, "node is unclean",
 528                                        FALSE, data_set);
 529 
 530     pe_warn("Scheduling node %s for fencing", pe__node_name(node));
 531     pcmk__order_vs_fence(fencing, data_set);
 532     return fencing;
 533 }
 534 
 535 /*!
 536  * \internal
 537  * \brief Create and order node fencing and shutdown actions
 538  *
 539  * \param[in,out] data_set  Cluster working set
 540  */
 541 static void
 542 schedule_fencing_and_shutdowns(pe_working_set_t *data_set)
     /* [previous][next][first][last][top][bottom][index][help] */
 543 {
 544     pe_action_t *dc_down = NULL;
 545     bool integrity_lost = false;
 546     bool have_managed = any_managed_resources(data_set);
 547     GList *fencing_ops = NULL;
 548     GList *shutdown_ops = NULL;
 549 
 550     crm_trace("Scheduling fencing and shutdowns as needed");
 551     if (!have_managed) {
 552         crm_notice("No fencing will be done until there are resources to manage");
 553     }
 554 
 555     // Check each node for whether it needs fencing or shutdown
 556     for (GList *iter = data_set->nodes; iter != NULL; iter = iter->next) {
 557         pe_node_t *node = (pe_node_t *) iter->data;
 558         pe_action_t *fencing = NULL;
 559 
 560         /* Guest nodes are "fenced" by recovering their container resource,
 561          * so handle them separately.
 562          */
 563         if (pe__is_guest_node(node)) {
 564             if (node->details->remote_requires_reset && have_managed
 565                 && pe_can_fence(data_set, node)) {
 566                 pcmk__fence_guest(node);
 567             }
 568             continue;
 569         }
 570 
 571         if (needs_fencing(node, have_managed, data_set)) {
 572             fencing = schedule_fencing(node, data_set);
 573 
 574             // Track DC and non-DC fence actions separately
 575             if (node->details->is_dc) {
 576                 dc_down = fencing;
 577             } else {
 578                 fencing_ops = add_nondc_fencing(fencing_ops, fencing, data_set);
 579             }
 580 
 581         } else if (needs_shutdown(node)) {
 582             pe_action_t *down_op = pcmk__new_shutdown_action(node);
 583 
 584             // Track DC and non-DC shutdown actions separately
 585             if (node->details->is_dc) {
 586                 dc_down = down_op;
 587             } else {
 588                 shutdown_ops = g_list_prepend(shutdown_ops, down_op);
 589             }
 590         }
 591 
 592         if ((fencing == NULL) && node->details->unclean) {
 593             integrity_lost = true;
 594             pe_warn("Node %s is unclean but cannot be fenced",
 595                     pe__node_name(node));
 596         }
 597     }
 598 
 599     if (integrity_lost) {
 600         if (!pcmk_is_set(data_set->flags, pe_flag_stonith_enabled)) {
 601             pe_warn("Resource functionality and data integrity cannot be "
 602                     "guaranteed (configure, enable, and test fencing to "
 603                     "correct this)");
 604 
 605         } else if (!pcmk_is_set(data_set->flags, pe_flag_have_quorum)) {
 606             crm_notice("Unclean nodes will not be fenced until quorum is "
 607                        "attained or no-quorum-policy is set to ignore");
 608         }
 609     }
 610 
 611     if (dc_down != NULL) {
 612         /* Order any non-DC shutdowns before any DC shutdown, to avoid repeated
 613          * DC elections. However, we don't want to order non-DC shutdowns before
 614          * a DC *fencing*, because even though we don't want a node that's
 615          * shutting down to become DC, the DC fencing could be ordered before a
 616          * clone stop that's also ordered before the shutdowns, thus leading to
 617          * a graph loop.
 618          */
 619         if (pcmk__str_eq(dc_down->task, CRM_OP_SHUTDOWN, pcmk__str_none)) {
 620             pcmk__order_after_each(dc_down, shutdown_ops);
 621         }
 622 
 623         // Order any non-DC fencing before any DC fencing or shutdown
 624 
 625         if (pcmk_is_set(data_set->flags, pe_flag_concurrent_fencing)) {
 626             /* With concurrent fencing, order each non-DC fencing action
 627              * separately before any DC fencing or shutdown.
 628              */
 629             pcmk__order_after_each(dc_down, fencing_ops);
 630         } else if (fencing_ops != NULL) {
 631             /* Without concurrent fencing, the non-DC fencing actions are
 632              * already ordered relative to each other, so we just need to order
 633              * the DC fencing after the last action in the chain (which is the
 634              * first item in the list).
 635              */
 636             order_actions((pe_action_t *) fencing_ops->data, dc_down,
 637                           pe_order_optional);
 638         }
 639     }
 640     g_list_free(fencing_ops);
 641     g_list_free(shutdown_ops);
 642 }
 643 
 644 static void
 645 log_resource_details(pe_working_set_t *data_set)
     /* [previous][next][first][last][top][bottom][index][help] */
 646 {
 647     pcmk__output_t *out = data_set->priv;
 648     GList *all = NULL;
 649 
 650     /* We need a list of nodes that we are allowed to output information for.
 651      * This is necessary because out->message for all the resource-related
 652      * messages expects such a list, due to the `crm_mon --node=` feature.  Here,
 653      * we just make it a list of all the nodes.
 654      */
 655     all = g_list_prepend(all, (gpointer) "*");
 656 
 657     for (GList *item = data_set->resources; item != NULL; item = item->next) {
 658         pe_resource_t *rsc = (pe_resource_t *) item->data;
 659 
 660         // Log all resources except inactive orphans
 661         if (!pcmk_is_set(rsc->flags, pe_rsc_orphan)
 662             || (rsc->role != RSC_ROLE_STOPPED)) {
 663             out->message(out, crm_map_element_name(rsc->xml), 0, rsc, all, all);
 664         }
 665     }
 666 
 667     g_list_free(all);
 668 }
 669 
 670 static void
 671 log_all_actions(pe_working_set_t *data_set)
     /* [previous][next][first][last][top][bottom][index][help] */
 672 {
 673     /* This only ever outputs to the log, so ignore whatever output object was
 674      * previously set and just log instead.
 675      */
 676     pcmk__output_t *prev_out = data_set->priv;
 677     pcmk__output_t *out = NULL;
 678 
 679     if (pcmk__log_output_new(&out) != pcmk_rc_ok) {
 680         return;
 681     }
 682 
 683     pe__register_messages(out);
 684     pcmk__register_lib_messages(out);
 685     pcmk__output_set_log_level(out, LOG_NOTICE);
 686     data_set->priv = out;
 687 
 688     out->begin_list(out, NULL, NULL, "Actions");
 689     pcmk__output_actions(data_set);
 690     out->end_list(out);
 691     out->finish(out, CRM_EX_OK, true, NULL);
 692     pcmk__output_free(out);
 693 
 694     data_set->priv = prev_out;
 695 }
 696 
 697 /*!
 698  * \internal
 699  * \brief Log all required but unrunnable actions at trace level
 700  *
 701  * \param[in] data_set  Cluster working set
 702  */
 703 static void
 704 log_unrunnable_actions(const pe_working_set_t *data_set)
     /* [previous][next][first][last][top][bottom][index][help] */
 705 {
 706     const uint64_t flags = pe_action_optional|pe_action_runnable|pe_action_pseudo;
 707 
 708     crm_trace("Required but unrunnable actions:");
 709     for (const GList *iter = data_set->actions;
 710          iter != NULL; iter = iter->next) {
 711 
 712         const pe_action_t *action = (const pe_action_t *) iter->data;
 713 
 714         if (!pcmk_any_flags_set(action->flags, flags)) {
 715             pcmk__log_action("\t", action, true);
 716         }
 717     }
 718 }
 719 
 720 /*!
 721  * \internal
 722  * \brief Unpack the CIB for scheduling
 723  *
 724  * \param[in,out] cib       CIB XML to unpack (may be NULL if already unpacked)
 725  * \param[in]     flags     Working set flags to set in addition to defaults
 726  * \param[in,out] data_set  Cluster working set
 727  */
 728 static void
 729 unpack_cib(xmlNode *cib, unsigned long long flags, pe_working_set_t *data_set)
     /* [previous][next][first][last][top][bottom][index][help] */
 730 {
 731     const char* localhost_save = NULL;
 732 
 733     if (pcmk_is_set(data_set->flags, pe_flag_have_status)) {
 734         crm_trace("Reusing previously calculated cluster status");
 735         pe__set_working_set_flags(data_set, flags);
 736         return;
 737     }
 738 
 739     if (data_set->localhost) {
 740         localhost_save = data_set->localhost;
 741     }
 742 
 743     CRM_ASSERT(cib != NULL);
 744     crm_trace("Calculating cluster status");
 745 
 746     /* This will zero the entire struct without freeing anything first, so
 747      * callers should never call pcmk__schedule_actions() with a populated data
 748      * set unless pe_flag_have_status is set (i.e. cluster_status() was
 749      * previously called, whether directly or via pcmk__schedule_actions()).
 750      */
 751     set_working_set_defaults(data_set);
 752 
 753     if (localhost_save) {
 754         data_set->localhost = localhost_save;
 755     }
 756 
 757     pe__set_working_set_flags(data_set, flags);
 758     data_set->input = cib;
 759     cluster_status(data_set); // Sets pe_flag_have_status
 760 }
 761 
 762 /*!
 763  * \internal
 764  * \brief Run the scheduler for a given CIB
 765  *
 766  * \param[in,out] cib       CIB XML to use as scheduler input
 767  * \param[in]     flags     Working set flags to set in addition to defaults
 768  * \param[in,out] data_set  Cluster working set
 769  */
 770 void
 771 pcmk__schedule_actions(xmlNode *cib, unsigned long long flags,
     /* [previous][next][first][last][top][bottom][index][help] */
 772                        pe_working_set_t *data_set)
 773 {
 774     unpack_cib(cib, flags, data_set);
 775     pcmk__set_allocation_methods(data_set);
 776     pcmk__apply_node_health(data_set);
 777     pcmk__unpack_constraints(data_set);
 778     if (pcmk_is_set(data_set->flags, pe_flag_check_config)) {
 779         return;
 780     }
 781 
 782     if (!pcmk_is_set(data_set->flags, pe_flag_quick_location) &&
 783          pcmk__is_daemon) {
 784         log_resource_details(data_set);
 785     }
 786 
 787     apply_node_criteria(data_set);
 788 
 789     if (pcmk_is_set(data_set->flags, pe_flag_quick_location)) {
 790         return;
 791     }
 792 
 793     pcmk__create_internal_constraints(data_set);
 794     pcmk__handle_rsc_config_changes(data_set);
 795     allocate_resources(data_set);
 796     schedule_resource_actions(data_set);
 797 
 798     /* Remote ordering constraints need to happen prior to calculating fencing
 799      * because it is one more place we can mark nodes as needing fencing.
 800      */
 801     pcmk__order_remote_connection_actions(data_set);
 802 
 803     schedule_fencing_and_shutdowns(data_set);
 804     pcmk__apply_orderings(data_set);
 805     log_all_actions(data_set);
 806     pcmk__create_graph(data_set);
 807 
 808     if (get_crm_log_level() == LOG_TRACE) {
 809         log_unrunnable_actions(data_set);
 810     }
 811 }

/* [previous][next][first][last][top][bottom][index][help] */