root/lib/pengine/complex.c

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

DEFINITIONS

This source file includes following definitions.
  1. get_resource_type
  2. dup_attr
  3. expand_parents_fixed_nvpairs
  4. get_meta_attributes
  5. get_rsc_attributes
  6. template_op_key
  7. unpack_template
  8. add_template_rsc
  9. detect_promotable
  10. free_params_table
  11. pe_rsc_params
  12. unpack_requires
  13. warn_about_deprecated_classes
  14. pe__unpack_resource
  15. is_parent
  16. uber_parent
  17. pe__const_top_resource
  18. common_free
  19. pe__count_active_node
  20. active_node
  21. pe__find_active_requires
  22. pe__count_common
  23. pe__set_next_role

   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 Lesser General Public License
   7  * version 2.1 or later (LGPLv2.1+) WITHOUT ANY WARRANTY.
   8  */
   9 
  10 #include <crm_internal.h>
  11 
  12 #include <crm/pengine/rules.h>
  13 #include <crm/pengine/internal.h>
  14 #include <crm/msg_xml.h>
  15 #include <crm/common/xml_internal.h>
  16 #include <crm/common/scheduler_internal.h>
  17 
  18 #include "pe_status_private.h"
  19 
  20 void populate_hash(xmlNode * nvpair_list, GHashTable * hash, const char **attrs, int attrs_length);
  21 
  22 static pcmk_node_t *active_node(const pcmk_resource_t *rsc,
  23                                 unsigned int *count_all,
  24                                 unsigned int *count_clean);
  25 
  26 pcmk_rsc_methods_t resource_class_functions[] = {
  27     {
  28          native_unpack,
  29          native_find_rsc,
  30          native_parameter,
  31          native_print,
  32          native_active,
  33          native_resource_state,
  34          native_location,
  35          native_free,
  36          pe__count_common,
  37          pe__native_is_filtered,
  38          active_node,
  39          pe__primitive_max_per_node,
  40     },
  41     {
  42          group_unpack,
  43          native_find_rsc,
  44          native_parameter,
  45          group_print,
  46          group_active,
  47          group_resource_state,
  48          native_location,
  49          group_free,
  50          pe__count_common,
  51          pe__group_is_filtered,
  52          active_node,
  53          pe__group_max_per_node,
  54     },
  55     {
  56          clone_unpack,
  57          native_find_rsc,
  58          native_parameter,
  59          clone_print,
  60          clone_active,
  61          clone_resource_state,
  62          native_location,
  63          clone_free,
  64          pe__count_common,
  65          pe__clone_is_filtered,
  66          active_node,
  67          pe__clone_max_per_node,
  68     },
  69     {
  70          pe__unpack_bundle,
  71          native_find_rsc,
  72          native_parameter,
  73          pe__print_bundle,
  74          pe__bundle_active,
  75          pe__bundle_resource_state,
  76          native_location,
  77          pe__free_bundle,
  78          pe__count_bundle,
  79          pe__bundle_is_filtered,
  80          pe__bundle_active_node,
  81          pe__bundle_max_per_node,
  82     }
  83 };
  84 
  85 static enum pe_obj_types
  86 get_resource_type(const char *name)
     /* [previous][next][first][last][top][bottom][index][help] */
  87 {
  88     if (pcmk__str_eq(name, XML_CIB_TAG_RESOURCE, pcmk__str_casei)) {
  89         return pcmk_rsc_variant_primitive;
  90 
  91     } else if (pcmk__str_eq(name, XML_CIB_TAG_GROUP, pcmk__str_casei)) {
  92         return pcmk_rsc_variant_group;
  93 
  94     } else if (pcmk__str_eq(name, XML_CIB_TAG_INCARNATION, pcmk__str_casei)) {
  95         return pcmk_rsc_variant_clone;
  96 
  97     } else if (pcmk__str_eq(name, PCMK_XE_PROMOTABLE_LEGACY, pcmk__str_casei)) {
  98         // @COMPAT deprecated since 2.0.0
  99         return pcmk_rsc_variant_clone;
 100 
 101     } else if (pcmk__str_eq(name, XML_CIB_TAG_CONTAINER, pcmk__str_casei)) {
 102         return pcmk_rsc_variant_bundle;
 103     }
 104 
 105     return pcmk_rsc_variant_unknown;
 106 }
 107 
 108 static void
 109 dup_attr(gpointer key, gpointer value, gpointer user_data)
     /* [previous][next][first][last][top][bottom][index][help] */
 110 {
 111     add_hash_param(user_data, key, value);
 112 }
 113 
 114 static void
 115 expand_parents_fixed_nvpairs(pcmk_resource_t *rsc,
     /* [previous][next][first][last][top][bottom][index][help] */
 116                              pe_rule_eval_data_t *rule_data,
 117                              GHashTable *meta_hash, pcmk_scheduler_t *scheduler)
 118 {
 119     GHashTable *parent_orig_meta = pcmk__strkey_table(free, free);
 120     pcmk_resource_t *p = rsc->parent;
 121 
 122     if (p == NULL) {
 123         return ;
 124     }
 125 
 126     /* Search all parent resources, get the fixed value of "meta_attributes" set only in the original xml, and stack it in the hash table. */
 127     /* The fixed value of the lower parent resource takes precedence and is not overwritten. */
 128     while(p != NULL) {
 129         /* A hash table for comparison is generated, including the id-ref. */
 130         pe__unpack_dataset_nvpairs(p->xml, XML_TAG_META_SETS, rule_data,
 131                                    parent_orig_meta, NULL, FALSE, scheduler);
 132         p = p->parent; 
 133     }
 134 
 135     /* If there is a fixed value of "meta_attributes" of the parent resource, it will be processed. */
 136     if (parent_orig_meta != NULL) {
 137         GHashTableIter iter;
 138         char *key = NULL;
 139         char *value = NULL;
 140 
 141         g_hash_table_iter_init(&iter, parent_orig_meta);
 142         while (g_hash_table_iter_next(&iter, (gpointer *) &key, (gpointer *) &value)) {
 143             /* Parameters set in the original xml of the parent resource will also try to overwrite the child resource. */
 144             /* Attributes that already exist in the child lease are not updated. */
 145             dup_attr(key, value, meta_hash);
 146         }
 147     }
 148 
 149     if (parent_orig_meta != NULL) {
 150         g_hash_table_destroy(parent_orig_meta);
 151     }
 152     
 153     return ;
 154 
 155 }
 156 void
 157 get_meta_attributes(GHashTable * meta_hash, pcmk_resource_t * rsc,
     /* [previous][next][first][last][top][bottom][index][help] */
 158                     pcmk_node_t *node, pcmk_scheduler_t *scheduler)
 159 {
 160     pe_rsc_eval_data_t rsc_rule_data = {
 161         .standard = crm_element_value(rsc->xml, XML_AGENT_ATTR_CLASS),
 162         .provider = crm_element_value(rsc->xml, XML_AGENT_ATTR_PROVIDER),
 163         .agent = crm_element_value(rsc->xml, XML_EXPR_ATTR_TYPE)
 164     };
 165 
 166     pe_rule_eval_data_t rule_data = {
 167         .node_hash = NULL,
 168         .role = pcmk_role_unknown,
 169         .now = scheduler->now,
 170         .match_data = NULL,
 171         .rsc_data = &rsc_rule_data,
 172         .op_data = NULL
 173     };
 174 
 175     if (node) {
 176         rule_data.node_hash = node->details->attrs;
 177     }
 178 
 179     for (xmlAttrPtr a = pcmk__xe_first_attr(rsc->xml); a != NULL; a = a->next) {
 180         const char *prop_name = (const char *) a->name;
 181         const char *prop_value = pcmk__xml_attr_value(a);
 182 
 183         add_hash_param(meta_hash, prop_name, prop_value);
 184     }
 185 
 186     pe__unpack_dataset_nvpairs(rsc->xml, XML_TAG_META_SETS, &rule_data,
 187                                meta_hash, NULL, FALSE, scheduler);
 188 
 189     /* Set the "meta_attributes" explicitly set in the parent resource to the hash table of the child resource. */
 190     /* If it is already explicitly set as a child, it will not be overwritten. */
 191     if (rsc->parent != NULL) {
 192         expand_parents_fixed_nvpairs(rsc, &rule_data, meta_hash, scheduler);
 193     }
 194 
 195     /* check the defaults */
 196     pe__unpack_dataset_nvpairs(scheduler->rsc_defaults, XML_TAG_META_SETS,
 197                                &rule_data, meta_hash, NULL, FALSE, scheduler);
 198 
 199     /* If there is "meta_attributes" that the parent resource has not explicitly set, set a value that is not set from rsc_default either. */
 200     /* The values already set up to this point will not be overwritten. */
 201     if (rsc->parent) {
 202         g_hash_table_foreach(rsc->parent->meta, dup_attr, meta_hash);
 203     }
 204 }
 205 
 206 void
 207 get_rsc_attributes(GHashTable *meta_hash, const pcmk_resource_t *rsc,
     /* [previous][next][first][last][top][bottom][index][help] */
 208                    const pcmk_node_t *node, pcmk_scheduler_t *scheduler)
 209 {
 210     pe_rule_eval_data_t rule_data = {
 211         .node_hash = NULL,
 212         .role = pcmk_role_unknown,
 213         .now = scheduler->now,
 214         .match_data = NULL,
 215         .rsc_data = NULL,
 216         .op_data = NULL
 217     };
 218 
 219     if (node) {
 220         rule_data.node_hash = node->details->attrs;
 221     }
 222 
 223     pe__unpack_dataset_nvpairs(rsc->xml, XML_TAG_ATTR_SETS, &rule_data,
 224                                meta_hash, NULL, FALSE, scheduler);
 225 
 226     /* set anything else based on the parent */
 227     if (rsc->parent != NULL) {
 228         get_rsc_attributes(meta_hash, rsc->parent, node, scheduler);
 229 
 230     } else {
 231         /* and finally check the defaults */
 232         pe__unpack_dataset_nvpairs(scheduler->rsc_defaults, XML_TAG_ATTR_SETS,
 233                                    &rule_data, meta_hash, NULL, FALSE,
 234                                    scheduler);
 235     }
 236 }
 237 
 238 static char *
 239 template_op_key(xmlNode * op)
     /* [previous][next][first][last][top][bottom][index][help] */
 240 {
 241     const char *name = crm_element_value(op, "name");
 242     const char *role = crm_element_value(op, "role");
 243     char *key = NULL;
 244 
 245     if ((role == NULL)
 246         || pcmk__strcase_any_of(role, PCMK__ROLE_STARTED, PCMK__ROLE_UNPROMOTED,
 247                                 PCMK__ROLE_UNPROMOTED_LEGACY, NULL)) {
 248         role = PCMK__ROLE_UNKNOWN;
 249     }
 250 
 251     key = crm_strdup_printf("%s-%s", name, role);
 252     return key;
 253 }
 254 
 255 static gboolean
 256 unpack_template(xmlNode *xml_obj, xmlNode **expanded_xml,
     /* [previous][next][first][last][top][bottom][index][help] */
 257                 pcmk_scheduler_t *scheduler)
 258 {
 259     xmlNode *cib_resources = NULL;
 260     xmlNode *template = NULL;
 261     xmlNode *new_xml = NULL;
 262     xmlNode *child_xml = NULL;
 263     xmlNode *rsc_ops = NULL;
 264     xmlNode *template_ops = NULL;
 265     const char *template_ref = NULL;
 266     const char *clone = NULL;
 267     const char *id = NULL;
 268 
 269     if (xml_obj == NULL) {
 270         pe_err("No resource object for template unpacking");
 271         return FALSE;
 272     }
 273 
 274     template_ref = crm_element_value(xml_obj, XML_CIB_TAG_RSC_TEMPLATE);
 275     if (template_ref == NULL) {
 276         return TRUE;
 277     }
 278 
 279     id = ID(xml_obj);
 280     if (id == NULL) {
 281         pe_err("'%s' object must have a id", xml_obj->name);
 282         return FALSE;
 283     }
 284 
 285     if (pcmk__str_eq(template_ref, id, pcmk__str_none)) {
 286         pe_err("The resource object '%s' should not reference itself", id);
 287         return FALSE;
 288     }
 289 
 290     cib_resources = get_xpath_object("//" XML_CIB_TAG_RESOURCES,
 291                                      scheduler->input, LOG_TRACE);
 292     if (cib_resources == NULL) {
 293         pe_err("No resources configured");
 294         return FALSE;
 295     }
 296 
 297     template = pcmk__xe_match(cib_resources, XML_CIB_TAG_RSC_TEMPLATE,
 298                               XML_ATTR_ID, template_ref);
 299     if (template == NULL) {
 300         pe_err("No template named '%s'", template_ref);
 301         return FALSE;
 302     }
 303 
 304     new_xml = copy_xml(template);
 305     xmlNodeSetName(new_xml, xml_obj->name);
 306     crm_xml_add(new_xml, XML_ATTR_ID, id);
 307 
 308     clone = crm_element_value(xml_obj, XML_RSC_ATTR_INCARNATION);
 309     if(clone) {
 310         crm_xml_add(new_xml, XML_RSC_ATTR_INCARNATION, clone);
 311     }
 312 
 313     template_ops = find_xml_node(new_xml, "operations", FALSE);
 314 
 315     for (child_xml = pcmk__xe_first_child(xml_obj); child_xml != NULL;
 316          child_xml = pcmk__xe_next(child_xml)) {
 317         xmlNode *new_child = NULL;
 318 
 319         new_child = add_node_copy(new_xml, child_xml);
 320 
 321         if (pcmk__str_eq((const char *)new_child->name, "operations", pcmk__str_none)) {
 322             rsc_ops = new_child;
 323         }
 324     }
 325 
 326     if (template_ops && rsc_ops) {
 327         xmlNode *op = NULL;
 328         GHashTable *rsc_ops_hash = pcmk__strkey_table(free, NULL);
 329 
 330         for (op = pcmk__xe_first_child(rsc_ops); op != NULL;
 331              op = pcmk__xe_next(op)) {
 332 
 333             char *key = template_op_key(op);
 334 
 335             g_hash_table_insert(rsc_ops_hash, key, op);
 336         }
 337 
 338         for (op = pcmk__xe_first_child(template_ops); op != NULL;
 339              op = pcmk__xe_next(op)) {
 340 
 341             char *key = template_op_key(op);
 342 
 343             if (g_hash_table_lookup(rsc_ops_hash, key) == NULL) {
 344                 add_node_copy(rsc_ops, op);
 345             }
 346 
 347             free(key);
 348         }
 349 
 350         if (rsc_ops_hash) {
 351             g_hash_table_destroy(rsc_ops_hash);
 352         }
 353 
 354         free_xml(template_ops);
 355     }
 356 
 357     /*free_xml(*expanded_xml); */
 358     *expanded_xml = new_xml;
 359 
 360 #if 0 /* Disable multi-level templates for now */
 361     if (!unpack_template(new_xml, expanded_xml, scheduler)) {
 362        free_xml(*expanded_xml);
 363        *expanded_xml = NULL;
 364        return FALSE;
 365     }
 366 #endif
 367 
 368     return TRUE;
 369 }
 370 
 371 static gboolean
 372 add_template_rsc(xmlNode *xml_obj, pcmk_scheduler_t *scheduler)
     /* [previous][next][first][last][top][bottom][index][help] */
 373 {
 374     const char *template_ref = NULL;
 375     const char *id = NULL;
 376 
 377     if (xml_obj == NULL) {
 378         pe_err("No resource object for processing resource list of template");
 379         return FALSE;
 380     }
 381 
 382     template_ref = crm_element_value(xml_obj, XML_CIB_TAG_RSC_TEMPLATE);
 383     if (template_ref == NULL) {
 384         return TRUE;
 385     }
 386 
 387     id = ID(xml_obj);
 388     if (id == NULL) {
 389         pe_err("'%s' object must have a id", xml_obj->name);
 390         return FALSE;
 391     }
 392 
 393     if (pcmk__str_eq(template_ref, id, pcmk__str_none)) {
 394         pe_err("The resource object '%s' should not reference itself", id);
 395         return FALSE;
 396     }
 397 
 398     if (add_tag_ref(scheduler->template_rsc_sets, template_ref, id) == FALSE) {
 399         return FALSE;
 400     }
 401 
 402     return TRUE;
 403 }
 404 
 405 static bool
 406 detect_promotable(pcmk_resource_t *rsc)
     /* [previous][next][first][last][top][bottom][index][help] */
 407 {
 408     const char *promotable = g_hash_table_lookup(rsc->meta,
 409                                                  XML_RSC_ATTR_PROMOTABLE);
 410 
 411     if (crm_is_true(promotable)) {
 412         return TRUE;
 413     }
 414 
 415     // @COMPAT deprecated since 2.0.0
 416     if (pcmk__xe_is(rsc->xml, PCMK_XE_PROMOTABLE_LEGACY)) {
 417         /* @TODO in some future version, pe_warn_once() here,
 418          *       then drop support in even later version
 419          */
 420         g_hash_table_insert(rsc->meta, strdup(XML_RSC_ATTR_PROMOTABLE),
 421                             strdup(XML_BOOLEAN_TRUE));
 422         return TRUE;
 423     }
 424     return FALSE;
 425 }
 426 
 427 static void
 428 free_params_table(gpointer data)
     /* [previous][next][first][last][top][bottom][index][help] */
 429 {
 430     g_hash_table_destroy((GHashTable *) data);
 431 }
 432 
 433 /*!
 434  * \brief Get a table of resource parameters
 435  *
 436  * \param[in,out] rsc        Resource to query
 437  * \param[in]     node       Node for evaluating rules (NULL for defaults)
 438  * \param[in,out] scheduler  Scheduler data
 439  *
 440  * \return Hash table containing resource parameter names and values
 441  *         (or NULL if \p rsc or \p scheduler is NULL)
 442  * \note The returned table will be destroyed when the resource is freed, so
 443  *       callers should not destroy it.
 444  */
 445 GHashTable *
 446 pe_rsc_params(pcmk_resource_t *rsc, const pcmk_node_t *node,
     /* [previous][next][first][last][top][bottom][index][help] */
 447               pcmk_scheduler_t *scheduler)
 448 {
 449     GHashTable *params_on_node = NULL;
 450 
 451     /* A NULL node is used to request the resource's default parameters
 452      * (not evaluated for node), but we always want something non-NULL
 453      * as a hash table key.
 454      */
 455     const char *node_name = "";
 456 
 457     // Sanity check
 458     if ((rsc == NULL) || (scheduler == NULL)) {
 459         return NULL;
 460     }
 461     if ((node != NULL) && (node->details->uname != NULL)) {
 462         node_name = node->details->uname;
 463     }
 464 
 465     // Find the parameter table for given node
 466     if (rsc->parameter_cache == NULL) {
 467         rsc->parameter_cache = pcmk__strikey_table(free, free_params_table);
 468     } else {
 469         params_on_node = g_hash_table_lookup(rsc->parameter_cache, node_name);
 470     }
 471 
 472     // If none exists yet, create one with parameters evaluated for node
 473     if (params_on_node == NULL) {
 474         params_on_node = pcmk__strkey_table(free, free);
 475         get_rsc_attributes(params_on_node, rsc, node, scheduler);
 476         g_hash_table_insert(rsc->parameter_cache, strdup(node_name),
 477                             params_on_node);
 478     }
 479     return params_on_node;
 480 }
 481 
 482 /*!
 483  * \internal
 484  * \brief Unpack a resource's "requires" meta-attribute
 485  *
 486  * \param[in,out] rsc         Resource being unpacked
 487  * \param[in]     value       Value of "requires" meta-attribute
 488  * \param[in]     is_default  Whether \p value was selected by default
 489  */
 490 static void
 491 unpack_requires(pcmk_resource_t *rsc, const char *value, bool is_default)
     /* [previous][next][first][last][top][bottom][index][help] */
 492 {
 493     if (pcmk__str_eq(value, PCMK__VALUE_NOTHING, pcmk__str_casei)) {
 494 
 495     } else if (pcmk__str_eq(value, PCMK__VALUE_QUORUM, pcmk__str_casei)) {
 496         pe__set_resource_flags(rsc, pcmk_rsc_needs_quorum);
 497 
 498     } else if (pcmk__str_eq(value, PCMK__VALUE_FENCING, pcmk__str_casei)) {
 499         pe__set_resource_flags(rsc, pcmk_rsc_needs_fencing);
 500         if (!pcmk_is_set(rsc->cluster->flags, pcmk_sched_fencing_enabled)) {
 501             pcmk__config_warn("%s requires fencing but fencing is disabled",
 502                               rsc->id);
 503         }
 504 
 505     } else if (pcmk__str_eq(value, PCMK__VALUE_UNFENCING, pcmk__str_casei)) {
 506         if (pcmk_is_set(rsc->flags, pcmk_rsc_fence_device)) {
 507             pcmk__config_warn("Resetting \"" XML_RSC_ATTR_REQUIRES "\" for %s "
 508                               "to \"" PCMK__VALUE_QUORUM "\" because fencing "
 509                               "devices cannot require unfencing", rsc->id);
 510             unpack_requires(rsc, PCMK__VALUE_QUORUM, true);
 511             return;
 512 
 513         } else if (!pcmk_is_set(rsc->cluster->flags,
 514                                 pcmk_sched_fencing_enabled)) {
 515             pcmk__config_warn("Resetting \"" XML_RSC_ATTR_REQUIRES "\" for %s "
 516                               "to \"" PCMK__VALUE_QUORUM "\" because fencing "
 517                               "is disabled", rsc->id);
 518             unpack_requires(rsc, PCMK__VALUE_QUORUM, true);
 519             return;
 520 
 521         } else {
 522             pe__set_resource_flags(rsc, pcmk_rsc_needs_fencing
 523                                         |pcmk_rsc_needs_unfencing);
 524         }
 525 
 526     } else {
 527         const char *orig_value = value;
 528 
 529         if (pcmk_is_set(rsc->flags, pcmk_rsc_fence_device)) {
 530             value = PCMK__VALUE_QUORUM;
 531 
 532         } else if ((rsc->variant == pcmk_rsc_variant_primitive)
 533                    && xml_contains_remote_node(rsc->xml)) {
 534             value = PCMK__VALUE_QUORUM;
 535 
 536         } else if (pcmk_is_set(rsc->cluster->flags,
 537                                pcmk_sched_enable_unfencing)) {
 538             value = PCMK__VALUE_UNFENCING;
 539 
 540         } else if (pcmk_is_set(rsc->cluster->flags,
 541                                pcmk_sched_fencing_enabled)) {
 542             value = PCMK__VALUE_FENCING;
 543 
 544         } else if (rsc->cluster->no_quorum_policy == pcmk_no_quorum_ignore) {
 545             value = PCMK__VALUE_NOTHING;
 546 
 547         } else {
 548             value = PCMK__VALUE_QUORUM;
 549         }
 550 
 551         if (orig_value != NULL) {
 552             pcmk__config_err("Resetting '" XML_RSC_ATTR_REQUIRES "' for %s "
 553                              "to '%s' because '%s' is not valid",
 554                               rsc->id, value, orig_value);
 555         }
 556         unpack_requires(rsc, value, true);
 557         return;
 558     }
 559 
 560     pe_rsc_trace(rsc, "\tRequired to start: %s%s", value,
 561                  (is_default? " (default)" : ""));
 562 }
 563 
 564 #ifndef PCMK__COMPAT_2_0
 565 static void
 566 warn_about_deprecated_classes(pcmk_resource_t *rsc)
     /* [previous][next][first][last][top][bottom][index][help] */
 567 {
 568     const char *std = crm_element_value(rsc->xml, XML_AGENT_ATTR_CLASS);
 569 
 570     if (pcmk__str_eq(std, PCMK_RESOURCE_CLASS_UPSTART, pcmk__str_none)) {
 571         pe_warn_once(pcmk__wo_upstart,
 572                      "Support for Upstart resources (such as %s) is deprecated "
 573                      "and will be removed in a future release of Pacemaker",
 574                      rsc->id);
 575 
 576     } else if (pcmk__str_eq(std, PCMK_RESOURCE_CLASS_NAGIOS, pcmk__str_none)) {
 577         pe_warn_once(pcmk__wo_nagios,
 578                      "Support for Nagios resources (such as %s) is deprecated "
 579                      "and will be removed in a future release of Pacemaker",
 580                      rsc->id);
 581     }
 582 }
 583 #endif
 584 
 585 /*!
 586  * \internal
 587  * \brief Unpack configuration XML for a given resource
 588  *
 589  * Unpack the XML object containing a resource's configuration into a new
 590  * \c pcmk_resource_t object.
 591  *
 592  * \param[in]     xml_obj    XML node containing the resource's configuration
 593  * \param[out]    rsc        Where to store the unpacked resource information
 594  * \param[in]     parent     Resource's parent, if any
 595  * \param[in,out] scheduler  Scheduler data
 596  *
 597  * \return Standard Pacemaker return code
 598  * \note If pcmk_rc_ok is returned, \p *rsc is guaranteed to be non-NULL, and
 599  *       the caller is responsible for freeing it using its variant-specific
 600  *       free() method. Otherwise, \p *rsc is guaranteed to be NULL.
 601  */
 602 int
 603 pe__unpack_resource(xmlNode *xml_obj, pcmk_resource_t **rsc,
     /* [previous][next][first][last][top][bottom][index][help] */
 604                     pcmk_resource_t *parent, pcmk_scheduler_t *scheduler)
 605 {
 606     xmlNode *expanded_xml = NULL;
 607     xmlNode *ops = NULL;
 608     const char *value = NULL;
 609     const char *id = NULL;
 610     bool guest_node = false;
 611     bool remote_node = false;
 612 
 613     pe_rule_eval_data_t rule_data = {
 614         .node_hash = NULL,
 615         .role = pcmk_role_unknown,
 616         .now = NULL,
 617         .match_data = NULL,
 618         .rsc_data = NULL,
 619         .op_data = NULL
 620     };
 621 
 622     CRM_CHECK(rsc != NULL, return EINVAL);
 623     CRM_CHECK((xml_obj != NULL) && (scheduler != NULL),
 624               *rsc = NULL;
 625               return EINVAL);
 626 
 627     rule_data.now = scheduler->now;
 628 
 629     crm_log_xml_trace(xml_obj, "[raw XML]");
 630 
 631     id = crm_element_value(xml_obj, XML_ATTR_ID);
 632     if (id == NULL) {
 633         pe_err("Ignoring <%s> configuration without " XML_ATTR_ID,
 634                xml_obj->name);
 635         return pcmk_rc_unpack_error;
 636     }
 637 
 638     if (unpack_template(xml_obj, &expanded_xml, scheduler) == FALSE) {
 639         return pcmk_rc_unpack_error;
 640     }
 641 
 642     *rsc = calloc(1, sizeof(pcmk_resource_t));
 643     if (*rsc == NULL) {
 644         crm_crit("Unable to allocate memory for resource '%s'", id);
 645         return ENOMEM;
 646     }
 647     (*rsc)->cluster = scheduler;
 648 
 649     if (expanded_xml) {
 650         crm_log_xml_trace(expanded_xml, "[expanded XML]");
 651         (*rsc)->xml = expanded_xml;
 652         (*rsc)->orig_xml = xml_obj;
 653 
 654     } else {
 655         (*rsc)->xml = xml_obj;
 656         (*rsc)->orig_xml = NULL;
 657     }
 658 
 659     /* Do not use xml_obj from here on, use (*rsc)->xml in case templates are involved */
 660 
 661     (*rsc)->parent = parent;
 662 
 663     ops = find_xml_node((*rsc)->xml, "operations", FALSE);
 664     (*rsc)->ops_xml = expand_idref(ops, scheduler->input);
 665 
 666     (*rsc)->variant = get_resource_type((const char *) (*rsc)->xml->name);
 667     if ((*rsc)->variant == pcmk_rsc_variant_unknown) {
 668         pe_err("Ignoring resource '%s' of unknown type '%s'",
 669                id, (*rsc)->xml->name);
 670         common_free(*rsc);
 671         *rsc = NULL;
 672         return pcmk_rc_unpack_error;
 673     }
 674 
 675 #ifndef PCMK__COMPAT_2_0
 676     warn_about_deprecated_classes(*rsc);
 677 #endif
 678 
 679     (*rsc)->meta = pcmk__strkey_table(free, free);
 680     (*rsc)->allowed_nodes = pcmk__strkey_table(NULL, free);
 681     (*rsc)->known_on = pcmk__strkey_table(NULL, free);
 682 
 683     value = crm_element_value((*rsc)->xml, XML_RSC_ATTR_INCARNATION);
 684     if (value) {
 685         (*rsc)->id = crm_strdup_printf("%s:%s", id, value);
 686         add_hash_param((*rsc)->meta, XML_RSC_ATTR_INCARNATION, value);
 687 
 688     } else {
 689         (*rsc)->id = strdup(id);
 690     }
 691 
 692     (*rsc)->fns = &resource_class_functions[(*rsc)->variant];
 693 
 694     get_meta_attributes((*rsc)->meta, *rsc, NULL, scheduler);
 695     (*rsc)->parameters = pe_rsc_params(*rsc, NULL, scheduler); // \deprecated
 696 
 697     (*rsc)->flags = 0;
 698     pe__set_resource_flags(*rsc, pcmk_rsc_runnable|pcmk_rsc_unassigned);
 699 
 700     if (!pcmk_is_set(scheduler->flags, pcmk_sched_in_maintenance)) {
 701         pe__set_resource_flags(*rsc, pcmk_rsc_managed);
 702     }
 703 
 704     (*rsc)->rsc_cons = NULL;
 705     (*rsc)->rsc_tickets = NULL;
 706     (*rsc)->actions = NULL;
 707     (*rsc)->role = pcmk_role_stopped;
 708     (*rsc)->next_role = pcmk_role_unknown;
 709 
 710     (*rsc)->recovery_type = pcmk_multiply_active_restart;
 711     (*rsc)->stickiness = 0;
 712     (*rsc)->migration_threshold = INFINITY;
 713     (*rsc)->failure_timeout = 0;
 714 
 715     value = g_hash_table_lookup((*rsc)->meta, XML_CIB_ATTR_PRIORITY);
 716     (*rsc)->priority = char2score(value);
 717 
 718     value = g_hash_table_lookup((*rsc)->meta, XML_RSC_ATTR_CRITICAL);
 719     if ((value == NULL) || crm_is_true(value)) {
 720         pe__set_resource_flags(*rsc, pcmk_rsc_critical);
 721     }
 722 
 723     value = g_hash_table_lookup((*rsc)->meta, XML_RSC_ATTR_NOTIFY);
 724     if (crm_is_true(value)) {
 725         pe__set_resource_flags(*rsc, pcmk_rsc_notify);
 726     }
 727 
 728     if (xml_contains_remote_node((*rsc)->xml)) {
 729         (*rsc)->is_remote_node = TRUE;
 730         if (g_hash_table_lookup((*rsc)->meta, XML_RSC_ATTR_CONTAINER)) {
 731             guest_node = true;
 732         } else {
 733             remote_node = true;
 734         }
 735     }
 736 
 737     value = g_hash_table_lookup((*rsc)->meta, XML_OP_ATTR_ALLOW_MIGRATE);
 738     if (crm_is_true(value)) {
 739         pe__set_resource_flags(*rsc, pcmk_rsc_migratable);
 740     } else if ((value == NULL) && remote_node) {
 741         /* By default, we want remote nodes to be able
 742          * to float around the cluster without having to stop all the
 743          * resources within the remote-node before moving. Allowing
 744          * migration support enables this feature. If this ever causes
 745          * problems, migration support can be explicitly turned off with
 746          * allow-migrate=false.
 747          */
 748         pe__set_resource_flags(*rsc, pcmk_rsc_migratable);
 749     }
 750 
 751     value = g_hash_table_lookup((*rsc)->meta, XML_RSC_ATTR_MANAGED);
 752     if (value != NULL && !pcmk__str_eq("default", value, pcmk__str_casei)) {
 753         if (crm_is_true(value)) {
 754             pe__set_resource_flags(*rsc, pcmk_rsc_managed);
 755         } else {
 756             pe__clear_resource_flags(*rsc, pcmk_rsc_managed);
 757         }
 758     }
 759 
 760     value = g_hash_table_lookup((*rsc)->meta, XML_RSC_ATTR_MAINTENANCE);
 761     if (crm_is_true(value)) {
 762         pe__clear_resource_flags(*rsc, pcmk_rsc_managed);
 763         pe__set_resource_flags(*rsc, pcmk_rsc_maintenance);
 764     }
 765     if (pcmk_is_set(scheduler->flags, pcmk_sched_in_maintenance)) {
 766         pe__clear_resource_flags(*rsc, pcmk_rsc_managed);
 767         pe__set_resource_flags(*rsc, pcmk_rsc_maintenance);
 768     }
 769 
 770     if (pe_rsc_is_clone(pe__const_top_resource(*rsc, false))) {
 771         value = g_hash_table_lookup((*rsc)->meta, XML_RSC_ATTR_UNIQUE);
 772         if (crm_is_true(value)) {
 773             pe__set_resource_flags(*rsc, pcmk_rsc_unique);
 774         }
 775         if (detect_promotable(*rsc)) {
 776             pe__set_resource_flags(*rsc, pcmk_rsc_promotable);
 777         }
 778     } else {
 779         pe__set_resource_flags(*rsc, pcmk_rsc_unique);
 780     }
 781 
 782     value = g_hash_table_lookup((*rsc)->meta, XML_RSC_ATTR_RESTART);
 783     if (pcmk__str_eq(value, "restart", pcmk__str_casei)) {
 784         (*rsc)->restart_type = pe_restart_restart;
 785         pe_rsc_trace((*rsc), "%s dependency restart handling: restart",
 786                      (*rsc)->id);
 787         pe_warn_once(pcmk__wo_restart_type,
 788                      "Support for restart-type is deprecated and will be removed in a future release");
 789 
 790     } else {
 791         (*rsc)->restart_type = pe_restart_ignore;
 792         pe_rsc_trace((*rsc), "%s dependency restart handling: ignore",
 793                      (*rsc)->id);
 794     }
 795 
 796     value = g_hash_table_lookup((*rsc)->meta, XML_RSC_ATTR_MULTIPLE);
 797     if (pcmk__str_eq(value, "stop_only", pcmk__str_casei)) {
 798         (*rsc)->recovery_type = pcmk_multiply_active_stop;
 799         pe_rsc_trace((*rsc), "%s multiple running resource recovery: stop only",
 800                      (*rsc)->id);
 801 
 802     } else if (pcmk__str_eq(value, "block", pcmk__str_casei)) {
 803         (*rsc)->recovery_type = pcmk_multiply_active_block;
 804         pe_rsc_trace((*rsc), "%s multiple running resource recovery: block",
 805                      (*rsc)->id);
 806 
 807     } else if (pcmk__str_eq(value, "stop_unexpected", pcmk__str_casei)) {
 808         (*rsc)->recovery_type = pcmk_multiply_active_unexpected;
 809         pe_rsc_trace((*rsc), "%s multiple running resource recovery: "
 810                              "stop unexpected instances",
 811                      (*rsc)->id);
 812 
 813     } else { // "stop_start"
 814         if (!pcmk__str_eq(value, "stop_start",
 815                           pcmk__str_casei|pcmk__str_null_matches)) {
 816             pe_warn("%s is not a valid value for " XML_RSC_ATTR_MULTIPLE
 817                     ", using default of \"stop_start\"", value);
 818         }
 819         (*rsc)->recovery_type = pcmk_multiply_active_restart;
 820         pe_rsc_trace((*rsc), "%s multiple running resource recovery: "
 821                              "stop/start", (*rsc)->id);
 822     }
 823 
 824     value = g_hash_table_lookup((*rsc)->meta, XML_RSC_ATTR_STICKINESS);
 825     if (value != NULL && !pcmk__str_eq("default", value, pcmk__str_casei)) {
 826         (*rsc)->stickiness = char2score(value);
 827     }
 828 
 829     value = g_hash_table_lookup((*rsc)->meta, PCMK_META_MIGRATION_THRESHOLD);
 830     if (value != NULL && !pcmk__str_eq("default", value, pcmk__str_casei)) {
 831         (*rsc)->migration_threshold = char2score(value);
 832         if ((*rsc)->migration_threshold < 0) {
 833             /* @TODO We use 1 here to preserve previous behavior, but this
 834              * should probably use the default (INFINITY) or 0 (to disable)
 835              * instead.
 836              */
 837             pe_warn_once(pcmk__wo_neg_threshold,
 838                          PCMK_META_MIGRATION_THRESHOLD
 839                          " must be non-negative, using 1 instead");
 840             (*rsc)->migration_threshold = 1;
 841         }
 842     }
 843 
 844     if (pcmk__str_eq(crm_element_value((*rsc)->xml, XML_AGENT_ATTR_CLASS),
 845                      PCMK_RESOURCE_CLASS_STONITH, pcmk__str_casei)) {
 846         pe__set_working_set_flags(scheduler, pcmk_sched_have_fencing);
 847         pe__set_resource_flags(*rsc, pcmk_rsc_fence_device);
 848     }
 849 
 850     value = g_hash_table_lookup((*rsc)->meta, XML_RSC_ATTR_REQUIRES);
 851     unpack_requires(*rsc, value, false);
 852 
 853     value = g_hash_table_lookup((*rsc)->meta, PCMK_META_FAILURE_TIMEOUT);
 854     if (value != NULL) {
 855         // Stored as seconds
 856         (*rsc)->failure_timeout = (int) (crm_parse_interval_spec(value) / 1000);
 857     }
 858 
 859     if (remote_node) {
 860         GHashTable *params = pe_rsc_params(*rsc, NULL, scheduler);
 861 
 862         /* Grabbing the value now means that any rules based on node attributes
 863          * will evaluate to false, so such rules should not be used with
 864          * reconnect_interval.
 865          *
 866          * @TODO Evaluate per node before using
 867          */
 868         value = g_hash_table_lookup(params, XML_REMOTE_ATTR_RECONNECT_INTERVAL);
 869         if (value) {
 870             /* reconnect delay works by setting failure_timeout and preventing the
 871              * connection from starting until the failure is cleared. */
 872             (*rsc)->remote_reconnect_ms = crm_parse_interval_spec(value);
 873             /* we want to override any default failure_timeout in use when remote
 874              * reconnect_interval is in use. */ 
 875             (*rsc)->failure_timeout = (*rsc)->remote_reconnect_ms / 1000;
 876         }
 877     }
 878 
 879     get_target_role(*rsc, &((*rsc)->next_role));
 880     pe_rsc_trace((*rsc), "%s desired next state: %s", (*rsc)->id,
 881                  (*rsc)->next_role != pcmk_role_unknown? role2text((*rsc)->next_role) : "default");
 882 
 883     if ((*rsc)->fns->unpack(*rsc, scheduler) == FALSE) {
 884         (*rsc)->fns->free(*rsc);
 885         *rsc = NULL;
 886         return pcmk_rc_unpack_error;
 887     }
 888 
 889     if (pcmk_is_set(scheduler->flags, pcmk_sched_symmetric_cluster)) {
 890         // This tag must stay exactly the same because it is tested elsewhere
 891         resource_location(*rsc, NULL, 0, "symmetric_default", scheduler);
 892     } else if (guest_node) {
 893         /* remote resources tied to a container resource must always be allowed
 894          * to opt-in to the cluster. Whether the connection resource is actually
 895          * allowed to be placed on a node is dependent on the container resource */
 896         resource_location(*rsc, NULL, 0, "remote_connection_default",
 897                           scheduler);
 898     }
 899 
 900     pe_rsc_trace((*rsc), "%s action notification: %s", (*rsc)->id,
 901                  pcmk_is_set((*rsc)->flags, pcmk_rsc_notify)? "required" : "not required");
 902 
 903     (*rsc)->utilization = pcmk__strkey_table(free, free);
 904 
 905     pe__unpack_dataset_nvpairs((*rsc)->xml, XML_TAG_UTILIZATION, &rule_data,
 906                                (*rsc)->utilization, NULL, FALSE, scheduler);
 907 
 908     if (expanded_xml) {
 909         if (add_template_rsc(xml_obj, scheduler) == FALSE) {
 910             (*rsc)->fns->free(*rsc);
 911             *rsc = NULL;
 912             return pcmk_rc_unpack_error;
 913         }
 914     }
 915     return pcmk_rc_ok;
 916 }
 917 
 918 gboolean
 919 is_parent(pcmk_resource_t *child, pcmk_resource_t *rsc)
     /* [previous][next][first][last][top][bottom][index][help] */
 920 {
 921     pcmk_resource_t *parent = child;
 922 
 923     if (parent == NULL || rsc == NULL) {
 924         return FALSE;
 925     }
 926     while (parent->parent != NULL) {
 927         if (parent->parent == rsc) {
 928             return TRUE;
 929         }
 930         parent = parent->parent;
 931     }
 932     return FALSE;
 933 }
 934 
 935 pcmk_resource_t *
 936 uber_parent(pcmk_resource_t *rsc)
     /* [previous][next][first][last][top][bottom][index][help] */
 937 {
 938     pcmk_resource_t *parent = rsc;
 939 
 940     if (parent == NULL) {
 941         return NULL;
 942     }
 943     while ((parent->parent != NULL)
 944            && (parent->parent->variant != pcmk_rsc_variant_bundle)) {
 945         parent = parent->parent;
 946     }
 947     return parent;
 948 }
 949 
 950 /*!
 951  * \internal
 952  * \brief Get the topmost parent of a resource as a const pointer
 953  *
 954  * \param[in] rsc             Resource to check
 955  * \param[in] include_bundle  If true, go all the way to bundle
 956  *
 957  * \return \p NULL if \p rsc is NULL, \p rsc if \p rsc has no parent,
 958  *         the bundle if \p rsc is bundled and \p include_bundle is true,
 959  *         otherwise the topmost parent of \p rsc up to a clone
 960  */
 961 const pcmk_resource_t *
 962 pe__const_top_resource(const pcmk_resource_t *rsc, bool include_bundle)
     /* [previous][next][first][last][top][bottom][index][help] */
 963 {
 964     const pcmk_resource_t *parent = rsc;
 965 
 966     if (parent == NULL) {
 967         return NULL;
 968     }
 969     while (parent->parent != NULL) {
 970         if (!include_bundle
 971             && (parent->parent->variant == pcmk_rsc_variant_bundle)) {
 972             break;
 973         }
 974         parent = parent->parent;
 975     }
 976     return parent;
 977 }
 978 
 979 void
 980 common_free(pcmk_resource_t * rsc)
     /* [previous][next][first][last][top][bottom][index][help] */
 981 {
 982     if (rsc == NULL) {
 983         return;
 984     }
 985 
 986     pe_rsc_trace(rsc, "Freeing %s %d", rsc->id, rsc->variant);
 987 
 988     g_list_free(rsc->rsc_cons);
 989     g_list_free(rsc->rsc_cons_lhs);
 990     g_list_free(rsc->rsc_tickets);
 991     g_list_free(rsc->dangling_migrations);
 992 
 993     if (rsc->parameter_cache != NULL) {
 994         g_hash_table_destroy(rsc->parameter_cache);
 995     }
 996     if (rsc->meta != NULL) {
 997         g_hash_table_destroy(rsc->meta);
 998     }
 999     if (rsc->utilization != NULL) {
1000         g_hash_table_destroy(rsc->utilization);
1001     }
1002 
1003     if ((rsc->parent == NULL)
1004         && pcmk_is_set(rsc->flags, pcmk_rsc_removed)) {
1005 
1006         free_xml(rsc->xml);
1007         rsc->xml = NULL;
1008         free_xml(rsc->orig_xml);
1009         rsc->orig_xml = NULL;
1010 
1011         /* if rsc->orig_xml, then rsc->xml is an expanded xml from a template */
1012     } else if (rsc->orig_xml) {
1013         free_xml(rsc->xml);
1014         rsc->xml = NULL;
1015     }
1016     if (rsc->running_on) {
1017         g_list_free(rsc->running_on);
1018         rsc->running_on = NULL;
1019     }
1020     if (rsc->known_on) {
1021         g_hash_table_destroy(rsc->known_on);
1022         rsc->known_on = NULL;
1023     }
1024     if (rsc->actions) {
1025         g_list_free(rsc->actions);
1026         rsc->actions = NULL;
1027     }
1028     if (rsc->allowed_nodes) {
1029         g_hash_table_destroy(rsc->allowed_nodes);
1030         rsc->allowed_nodes = NULL;
1031     }
1032     g_list_free(rsc->fillers);
1033     g_list_free(rsc->rsc_location);
1034     pe_rsc_trace(rsc, "Resource freed");
1035     free(rsc->id);
1036     free(rsc->clone_name);
1037     free(rsc->allocated_to);
1038     free(rsc->variant_opaque);
1039     free(rsc->pending_task);
1040     free(rsc);
1041 }
1042 
1043 /*!
1044  * \internal
1045  * \brief Count a node and update most preferred to it as appropriate
1046  *
1047  * \param[in]     rsc          An active resource
1048  * \param[in]     node         A node that \p rsc is active on
1049  * \param[in,out] active       This will be set to \p node if \p node is more
1050  *                             preferred than the current value
1051  * \param[in,out] count_all    If not NULL, this will be incremented
1052  * \param[in,out] count_clean  If not NULL, this will be incremented if \p node
1053  *                             is online and clean
1054  *
1055  * \return true if the count should continue, or false if sufficiently known
1056  */
1057 bool
1058 pe__count_active_node(const pcmk_resource_t *rsc, pcmk_node_t *node,
     /* [previous][next][first][last][top][bottom][index][help] */
1059                       pcmk_node_t **active, unsigned int *count_all,
1060                       unsigned int *count_clean)
1061 {
1062     bool keep_looking = false;
1063     bool is_happy = false;
1064 
1065     CRM_CHECK((rsc != NULL) && (node != NULL) && (active != NULL),
1066               return false);
1067 
1068     is_happy = node->details->online && !node->details->unclean;
1069 
1070     if (count_all != NULL) {
1071         ++*count_all;
1072     }
1073     if ((count_clean != NULL) && is_happy) {
1074         ++*count_clean;
1075     }
1076     if ((count_all != NULL) || (count_clean != NULL)) {
1077         keep_looking = true; // We're counting, so go through entire list
1078     }
1079 
1080     if (rsc->partial_migration_source != NULL) {
1081         if (node->details == rsc->partial_migration_source->details) {
1082             *active = node; // This is the migration source
1083         } else {
1084             keep_looking = true;
1085         }
1086     } else if (!pcmk_is_set(rsc->flags, pcmk_rsc_needs_fencing)) {
1087         if (is_happy && ((*active == NULL) || !(*active)->details->online
1088                          || (*active)->details->unclean)) {
1089             *active = node; // This is the first clean node
1090         } else {
1091             keep_looking = true;
1092         }
1093     }
1094     if (*active == NULL) {
1095         *active = node; // This is the first node checked
1096     }
1097     return keep_looking;
1098 }
1099 
1100 // Shared implementation of pcmk_rsc_methods_t:active_node()
1101 static pcmk_node_t *
1102 active_node(const pcmk_resource_t *rsc, unsigned int *count_all,
     /* [previous][next][first][last][top][bottom][index][help] */
1103             unsigned int *count_clean)
1104 {
1105     pcmk_node_t *active = NULL;
1106 
1107     if (count_all != NULL) {
1108         *count_all = 0;
1109     }
1110     if (count_clean != NULL) {
1111         *count_clean = 0;
1112     }
1113     if (rsc == NULL) {
1114         return NULL;
1115     }
1116     for (GList *iter = rsc->running_on; iter != NULL; iter = iter->next) {
1117         if (!pe__count_active_node(rsc, (pcmk_node_t *) iter->data, &active,
1118                                    count_all, count_clean)) {
1119             break; // Don't waste time iterating if we don't have to
1120         }
1121     }
1122     return active;
1123 }
1124 
1125 /*!
1126  * \brief
1127  * \internal Find and count active nodes according to "requires"
1128  *
1129  * \param[in]  rsc    Resource to check
1130  * \param[out] count  If not NULL, will be set to count of active nodes
1131  *
1132  * \return An active node (or NULL if resource is not active anywhere)
1133  *
1134  * \note This is a convenience wrapper for active_node() where the count of all
1135  *       active nodes or only clean active nodes is desired according to the
1136  *       "requires" meta-attribute.
1137  */
1138 pcmk_node_t *
1139 pe__find_active_requires(const pcmk_resource_t *rsc, unsigned int *count)
     /* [previous][next][first][last][top][bottom][index][help] */
1140 {
1141     if (rsc == NULL) {
1142         if (count != NULL) {
1143             *count = 0;
1144         }
1145         return NULL;
1146 
1147     } else if (pcmk_is_set(rsc->flags, pcmk_rsc_needs_fencing)) {
1148         return rsc->fns->active_node(rsc, count, NULL);
1149 
1150     } else {
1151         return rsc->fns->active_node(rsc, NULL, count);
1152     }
1153 }
1154 
1155 void
1156 pe__count_common(pcmk_resource_t *rsc)
     /* [previous][next][first][last][top][bottom][index][help] */
1157 {
1158     if (rsc->children != NULL) {
1159         for (GList *item = rsc->children; item != NULL; item = item->next) {
1160             ((pcmk_resource_t *) item->data)->fns->count(item->data);
1161         }
1162 
1163     } else if (!pcmk_is_set(rsc->flags, pcmk_rsc_removed)
1164                || (rsc->role > pcmk_role_stopped)) {
1165         rsc->cluster->ninstances++;
1166         if (pe__resource_is_disabled(rsc)) {
1167             rsc->cluster->disabled_resources++;
1168         }
1169         if (pcmk_is_set(rsc->flags, pcmk_rsc_blocked)) {
1170             rsc->cluster->blocked_resources++;
1171         }
1172     }
1173 }
1174 
1175 /*!
1176  * \internal
1177  * \brief Update a resource's next role
1178  *
1179  * \param[in,out] rsc   Resource to be updated
1180  * \param[in]     role  Resource's new next role
1181  * \param[in]     why   Human-friendly reason why role is changing (for logs)
1182  */
1183 void
1184 pe__set_next_role(pcmk_resource_t *rsc, enum rsc_role_e role, const char *why)
     /* [previous][next][first][last][top][bottom][index][help] */
1185 {
1186     CRM_ASSERT((rsc != NULL) && (why != NULL));
1187     if (rsc->next_role != role) {
1188         pe_rsc_trace(rsc, "Resetting next role for %s from %s to %s (%s)",
1189                      rsc->id, role2text(rsc->next_role), role2text(role), why);
1190         rsc->next_role = role;
1191     }
1192 }

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