Blob Blame History Raw
From 71c53fb73ff8d33253ff99b84e666913050e16cc Mon Sep 17 00:00:00 2001
From: Ken Gaillot <kgaillot@redhat.com>
Date: Fri, 4 Dec 2020 16:13:30 -0600
Subject: [PATCH 1/4] Refactor: scheduler: rename colocation constructor

... per current guidelines. Also make void since no caller used the return
value.
---
 include/pcmki/pcmki_sched_utils.h      | 10 ++++----
 lib/pacemaker/pcmk_sched_bundle.c      | 12 +++++-----
 lib/pacemaker/pcmk_sched_constraints.c | 43 +++++++++++++++++++---------------
 lib/pacemaker/pcmk_sched_group.c       |  4 ++--
 lib/pacemaker/pcmk_sched_native.c      |  4 ++--
 5 files changed, 39 insertions(+), 34 deletions(-)

diff --git a/include/pcmki/pcmki_sched_utils.h b/include/pcmki/pcmki_sched_utils.h
index f2318c5..fdb3843 100644
--- a/include/pcmki/pcmki_sched_utils.h
+++ b/include/pcmki/pcmki_sched_utils.h
@@ -1,5 +1,5 @@
 /*
- * Copyright 2004-2019 the Pacemaker project contributors
+ * Copyright 2004-2020 the Pacemaker project contributors
  *
  * The version control history for this file may have further details.
  *
@@ -28,10 +28,10 @@ pe__location_t *rsc2node_new(const char *id, pe_resource_t *rsc, int weight,
                              const char *discovery_mode, pe_node_t *node,
                              pe_working_set_t *data_set);
 
-extern gboolean rsc_colocation_new(const char *id, const char *node_attr, int score,
-                                   pe_resource_t * rsc_lh, pe_resource_t * rsc_rh,
-                                   const char *state_lh, const char *state_rh,
-                                   pe_working_set_t * data_set);
+void pcmk__new_colocation(const char *id, const char *node_attr, int score,
+                          pe_resource_t *rsc_lh, pe_resource_t *rsc_rh,
+                          const char *state_lh, const char *state_rh,
+                          pe_working_set_t *data_set);
 
 extern gboolean rsc_ticket_new(const char *id, pe_resource_t * rsc_lh, pe_ticket_t * ticket,
                                const char *state_lh, const char *loss_policy,
diff --git a/lib/pacemaker/pcmk_sched_bundle.c b/lib/pacemaker/pcmk_sched_bundle.c
index e9b8a74..02bff7c 100644
--- a/lib/pacemaker/pcmk_sched_bundle.c
+++ b/lib/pacemaker/pcmk_sched_bundle.c
@@ -140,10 +140,10 @@ pcmk__bundle_allocate(pe_resource_t *rsc, pe_node_t *prefer,
              * host because pacemaker-remoted only supports a single
              * active connection
              */
-            rsc_colocation_new("child-remote-with-docker-remote", NULL,
-                               INFINITY, replica->remote,
-                               container_host->details->remote_rsc, NULL, NULL,
-                               data_set);
+            pcmk__new_colocation("child-remote-with-docker-remote", NULL,
+                                 INFINITY, replica->remote,
+                                 container_host->details->remote_rsc, NULL,
+                                 NULL, data_set);
         }
 
         if (replica->remote) {
@@ -310,8 +310,8 @@ pcmk__bundle_internal_constraints(pe_resource_t *rsc,
             new_rsc_order(replica->container, RSC_STOP, replica->ip, RSC_STOP,
                           pe_order_implies_first|pe_order_preserve, data_set);
 
-            rsc_colocation_new("ip-with-docker", NULL, INFINITY, replica->ip,
-                               replica->container, NULL, NULL, data_set);
+            pcmk__new_colocation("ip-with-docker", NULL, INFINITY, replica->ip,
+                                 replica->container, NULL, NULL, data_set);
         }
 
         if (replica->remote) {
diff --git a/lib/pacemaker/pcmk_sched_constraints.c b/lib/pacemaker/pcmk_sched_constraints.c
index 121754d..cce3f12 100644
--- a/lib/pacemaker/pcmk_sched_constraints.c
+++ b/lib/pacemaker/pcmk_sched_constraints.c
@@ -1339,22 +1339,23 @@ anti_colocation_order(pe_resource_t * first_rsc, int first_role,
     }
 }
 
-gboolean
-rsc_colocation_new(const char *id, const char *node_attr, int score,
-                   pe_resource_t * rsc_lh, pe_resource_t * rsc_rh,
-                   const char *state_lh, const char *state_rh, pe_working_set_t * data_set)
+void
+pcmk__new_colocation(const char *id, const char *node_attr, int score,
+                     pe_resource_t *rsc_lh, pe_resource_t *rsc_rh,
+                     const char *state_lh, const char *state_rh,
+                     pe_working_set_t *data_set)
 {
     rsc_colocation_t *new_con = NULL;
 
     if ((rsc_lh == NULL) || (rsc_rh == NULL)) {
         pcmk__config_err("Ignoring colocation '%s' because resource "
                          "does not exist", id);
-        return FALSE;
+        return;
     }
 
     new_con = calloc(1, sizeof(rsc_colocation_t));
     if (new_con == NULL) {
-        return FALSE;
+        return;
     }
 
     if (pcmk__str_eq(state_lh, RSC_ROLE_STARTED_S, pcmk__str_null_matches | pcmk__str_casei)) {
@@ -1390,8 +1391,6 @@ rsc_colocation_new(const char *id, const char *node_attr, int score,
         anti_colocation_order(rsc_lh, new_con->role_lh, rsc_rh, new_con->role_rh, data_set);
         anti_colocation_order(rsc_rh, new_con->role_rh, rsc_lh, new_con->role_lh, data_set);
     }
-
-    return TRUE;
 }
 
 /* LHS before RHS */
@@ -2311,8 +2310,8 @@ unpack_colocation_set(xmlNode * set, int score, pe_working_set_t * data_set)
                 EXPAND_CONSTRAINT_IDREF(set_id, resource, ID(xml_rsc));
                 if (with != NULL) {
                     pe_rsc_trace(resource, "Colocating %s with %s", resource->id, with->id);
-                    rsc_colocation_new(set_id, NULL, local_score, resource, with, role, role,
-                                       data_set);
+                    pcmk__new_colocation(set_id, NULL, local_score, resource,
+                                         with, role, role, data_set);
                 }
 
                 with = resource;
@@ -2327,8 +2326,8 @@ unpack_colocation_set(xmlNode * set, int score, pe_working_set_t * data_set)
                 EXPAND_CONSTRAINT_IDREF(set_id, resource, ID(xml_rsc));
                 if (last != NULL) {
                     pe_rsc_trace(resource, "Colocating %s with %s", last->id, resource->id);
-                    rsc_colocation_new(set_id, NULL, local_score, last, resource, role, role,
-                                       data_set);
+                    pcmk__new_colocation(set_id, NULL, local_score, last,
+                                         resource, role, role, data_set);
                 }
 
                 last = resource;
@@ -2360,8 +2359,9 @@ unpack_colocation_set(xmlNode * set, int score, pe_working_set_t * data_set)
                         EXPAND_CONSTRAINT_IDREF(set_id, with, ID(xml_rsc_with));
                         pe_rsc_trace(resource, "Anti-Colocating %s with %s", resource->id,
                                      with->id);
-                        rsc_colocation_new(set_id, NULL, local_score, resource, with, role, role,
-                                           data_set);
+                        pcmk__new_colocation(set_id, NULL, local_score,
+                                             resource, with, role, role,
+                                             data_set);
                     }
                 }
             }
@@ -2412,7 +2412,8 @@ colocate_rsc_sets(const char *id, xmlNode * set1, xmlNode * set2, int score,
     }
 
     if (rsc_1 != NULL && rsc_2 != NULL) {
-        rsc_colocation_new(id, NULL, score, rsc_1, rsc_2, role_1, role_2, data_set);
+        pcmk__new_colocation(id, NULL, score, rsc_1, rsc_2, role_1, role_2,
+                             data_set);
 
     } else if (rsc_1 != NULL) {
         for (xml_rsc = pcmk__xe_first_child(set2); xml_rsc != NULL;
@@ -2420,7 +2421,8 @@ colocate_rsc_sets(const char *id, xmlNode * set1, xmlNode * set2, int score,
 
             if (pcmk__str_eq((const char *)xml_rsc->name, XML_TAG_RESOURCE_REF, pcmk__str_none)) {
                 EXPAND_CONSTRAINT_IDREF(id, rsc_2, ID(xml_rsc));
-                rsc_colocation_new(id, NULL, score, rsc_1, rsc_2, role_1, role_2, data_set);
+                pcmk__new_colocation(id, NULL, score, rsc_1, rsc_2, role_1,
+                                     role_2, data_set);
             }
         }
 
@@ -2430,7 +2432,8 @@ colocate_rsc_sets(const char *id, xmlNode * set1, xmlNode * set2, int score,
 
             if (pcmk__str_eq((const char *)xml_rsc->name, XML_TAG_RESOURCE_REF, pcmk__str_none)) {
                 EXPAND_CONSTRAINT_IDREF(id, rsc_1, ID(xml_rsc));
-                rsc_colocation_new(id, NULL, score, rsc_1, rsc_2, role_1, role_2, data_set);
+                pcmk__new_colocation(id, NULL, score, rsc_1, rsc_2, role_1,
+                                     role_2, data_set);
             }
         }
 
@@ -2449,7 +2452,8 @@ colocate_rsc_sets(const char *id, xmlNode * set1, xmlNode * set2, int score,
 
                     if (pcmk__str_eq((const char *)xml_rsc_2->name, XML_TAG_RESOURCE_REF, pcmk__str_none)) {
                         EXPAND_CONSTRAINT_IDREF(id, rsc_2, ID(xml_rsc_2));
-                        rsc_colocation_new(id, NULL, score, rsc_1, rsc_2, role_1, role_2, data_set);
+                        pcmk__new_colocation(id, NULL, score, rsc_1, rsc_2,
+                                             role_1, role_2, data_set);
                     }
                 }
             }
@@ -2534,7 +2538,8 @@ unpack_simple_colocation(xmlNode * xml_obj, pe_working_set_t * data_set)
         score_i = char2score(score);
     }
 
-    rsc_colocation_new(id, attr, score_i, rsc_lh, rsc_rh, state_lh, state_rh, data_set);
+    pcmk__new_colocation(id, attr, score_i, rsc_lh, rsc_rh, state_lh, state_rh,
+                         data_set);
     return TRUE;
 }
 
diff --git a/lib/pacemaker/pcmk_sched_group.c b/lib/pacemaker/pcmk_sched_group.c
index 35f25af..79847e8 100644
--- a/lib/pacemaker/pcmk_sched_group.c
+++ b/lib/pacemaker/pcmk_sched_group.c
@@ -192,8 +192,8 @@ group_internal_constraints(pe_resource_t * rsc, pe_working_set_t * data_set)
             }
 
         } else if (group_data->colocated) {
-            rsc_colocation_new("group:internal_colocation", NULL, INFINITY,
-                               child_rsc, last_rsc, NULL, NULL, data_set);
+            pcmk__new_colocation("group:internal_colocation", NULL, INFINITY,
+                                 child_rsc, last_rsc, NULL, NULL, data_set);
         }
 
         if (pcmk_is_set(top->flags, pe_rsc_promotable)) {
diff --git a/lib/pacemaker/pcmk_sched_native.c b/lib/pacemaker/pcmk_sched_native.c
index 9196f59..b18f52e 100644
--- a/lib/pacemaker/pcmk_sched_native.c
+++ b/lib/pacemaker/pcmk_sched_native.c
@@ -1697,8 +1697,8 @@ native_internal_constraints(pe_resource_t * rsc, pe_working_set_t * data_set)
             } else {
                 score = INFINITY; /* Force them to run on the same host */
             }
-            rsc_colocation_new("resource-with-container", NULL, score, rsc,
-                               rsc->container, NULL, NULL, data_set);
+            pcmk__new_colocation("resource-with-container", NULL, score, rsc,
+                                 rsc->container, NULL, NULL, data_set);
         }
     }
 
-- 
1.8.3.1


From 9fced08910267513a3208772cca712e6ebec54bc Mon Sep 17 00:00:00 2001
From: Ken Gaillot <kgaillot@redhat.com>
Date: Fri, 4 Dec 2020 16:24:25 -0600
Subject: [PATCH 2/4] Refactor: scheduler,tools: rename colocation type

... per current guidelines
---
 include/crm/pengine/pe_types.h         |  4 ++--
 include/pcmki/pcmki_sched_allocate.h   | 22 +++++++++++-----------
 include/pcmki/pcmki_sched_utils.h      |  4 ++--
 include/pcmki/pcmki_scheduler.h        |  5 ++---
 lib/pacemaker/pcmk_output.c            | 12 ++++++------
 lib/pacemaker/pcmk_sched_bundle.c      |  4 ++--
 lib/pacemaker/pcmk_sched_clone.c       | 20 ++++++++++----------
 lib/pacemaker/pcmk_sched_constraints.c | 12 ++++++------
 lib/pacemaker/pcmk_sched_graph.c       |  3 ++-
 lib/pacemaker/pcmk_sched_group.c       |  6 +++---
 lib/pacemaker/pcmk_sched_native.c      | 18 ++++++++++--------
 lib/pacemaker/pcmk_sched_promotable.c  |  8 ++++----
 lib/pacemaker/pcmk_sched_utilization.c |  4 ++--
 tools/crm_resource_runtime.c           |  2 +-
 14 files changed, 63 insertions(+), 61 deletions(-)

diff --git a/include/crm/pengine/pe_types.h b/include/crm/pengine/pe_types.h
index 9fea637..59d5ce8 100644
--- a/include/crm/pengine/pe_types.h
+++ b/include/crm/pengine/pe_types.h
@@ -340,8 +340,8 @@ struct pe_resource_s {
 
     //!@{
     //! This field should be treated as internal to Pacemaker
-    GListPtr rsc_cons_lhs;      // List of rsc_colocation_t*
-    GListPtr rsc_cons;          // List of rsc_colocation_t*
+    GListPtr rsc_cons_lhs;      // List of pcmk__colocation_t*
+    GListPtr rsc_cons;          // List of pcmk__colocation_t*
     GListPtr rsc_location;      // List of pe__location_t*
     GListPtr actions;           // List of pe_action_t*
     GListPtr rsc_tickets;       // List of rsc_ticket*
diff --git a/include/pcmki/pcmki_sched_allocate.h b/include/pcmki/pcmki_sched_allocate.h
index a7f8c11..0859eaa 100644
--- a/include/pcmki/pcmki_sched_allocate.h
+++ b/include/pcmki/pcmki_sched_allocate.h
@@ -26,9 +26,9 @@ struct resource_alloc_functions_s {
     void (*internal_constraints) (pe_resource_t *, pe_working_set_t *);
 
     void (*rsc_colocation_lh) (pe_resource_t *, pe_resource_t *,
-                               rsc_colocation_t *, pe_working_set_t *);
+                               pcmk__colocation_t *, pe_working_set_t *);
     void (*rsc_colocation_rh) (pe_resource_t *, pe_resource_t *,
-                               rsc_colocation_t *, pe_working_set_t *);
+                               pcmk__colocation_t *, pe_working_set_t *);
 
     void (*rsc_location) (pe_resource_t *, pe__location_t *);
 
@@ -56,10 +56,10 @@ pe_node_t *pcmk__native_allocate(pe_resource_t *rsc, pe_node_t *preferred,
 extern void native_create_actions(pe_resource_t * rsc, pe_working_set_t * data_set);
 extern void native_internal_constraints(pe_resource_t * rsc, pe_working_set_t * data_set);
 void native_rsc_colocation_lh(pe_resource_t *lh_rsc, pe_resource_t *rh_rsc,
-                              rsc_colocation_t *constraint,
+                              pcmk__colocation_t *constraint,
                               pe_working_set_t *data_set);
 void native_rsc_colocation_rh(pe_resource_t *lh_rsc, pe_resource_t *rh_rsc,
-                              rsc_colocation_t *constraint,
+                              pcmk__colocation_t *constraint,
                               pe_working_set_t *data_set);
 extern void rsc_ticket_constraint(pe_resource_t * lh_rsc, rsc_ticket_t * rsc_ticket,
                                   pe_working_set_t * data_set);
@@ -76,10 +76,10 @@ pe_node_t *pcmk__group_allocate(pe_resource_t *rsc, pe_node_t *preferred,
 extern void group_create_actions(pe_resource_t * rsc, pe_working_set_t * data_set);
 extern void group_internal_constraints(pe_resource_t * rsc, pe_working_set_t * data_set);
 void group_rsc_colocation_lh(pe_resource_t *lh_rsc, pe_resource_t *rh_rsc,
-                             rsc_colocation_t *constraint,
+                             pcmk__colocation_t *constraint,
                              pe_working_set_t *data_set);
 void group_rsc_colocation_rh(pe_resource_t *lh_rsc, pe_resource_t *rh_rsc,
-                             rsc_colocation_t *constraint,
+                             pcmk__colocation_t *constraint,
                              pe_working_set_t *data_set);
 extern enum pe_action_flags group_action_flags(pe_action_t * action, pe_node_t * node);
 void group_rsc_location(pe_resource_t *rsc, pe__location_t *constraint);
@@ -97,11 +97,11 @@ void pcmk__bundle_internal_constraints(pe_resource_t *rsc,
                                        pe_working_set_t *data_set);
 void pcmk__bundle_rsc_colocation_lh(pe_resource_t *lh_rsc,
                                     pe_resource_t *rh_rsc,
-                                    rsc_colocation_t *constraint,
+                                    pcmk__colocation_t *constraint,
                                     pe_working_set_t *data_set);
 void pcmk__bundle_rsc_colocation_rh(pe_resource_t *lh_rsc,
                                     pe_resource_t *rh_rsc,
-                                    rsc_colocation_t *constraint,
+                                    pcmk__colocation_t *constraint,
                                     pe_working_set_t *data_set);
 void pcmk__bundle_rsc_location(pe_resource_t *rsc, pe__location_t *constraint);
 enum pe_action_flags pcmk__bundle_action_flags(pe_action_t *action,
@@ -114,10 +114,10 @@ pe_node_t *pcmk__clone_allocate(pe_resource_t *rsc, pe_node_t *preferred,
 extern void clone_create_actions(pe_resource_t * rsc, pe_working_set_t * data_set);
 extern void clone_internal_constraints(pe_resource_t * rsc, pe_working_set_t * data_set);
 void clone_rsc_colocation_lh(pe_resource_t *lh_rsc, pe_resource_t *rh_rsc,
-                             rsc_colocation_t *constraint,
+                             pcmk__colocation_t *constraint,
                              pe_working_set_t *data_set);
 void clone_rsc_colocation_rh(pe_resource_t *lh_rsc, pe_resource_t *rh_rsc,
-                             rsc_colocation_t *constraint,
+                             pcmk__colocation_t *constraint,
                              pe_working_set_t *data_set);
 void clone_rsc_location(pe_resource_t *rsc, pe__location_t *constraint);
 extern enum pe_action_flags clone_action_flags(pe_action_t * action, pe_node_t * node);
@@ -133,7 +133,7 @@ void create_promotable_actions(pe_resource_t *rsc, pe_working_set_t *data_set);
 void promote_demote_constraints(pe_resource_t *rsc, pe_working_set_t *data_set);
 void promotable_constraints(pe_resource_t *rsc, pe_working_set_t *data_set);
 void promotable_colocation_rh(pe_resource_t *lh_rsc, pe_resource_t *rh_rsc,
-                              rsc_colocation_t *constraint,
+                              pcmk__colocation_t *constraint,
                               pe_working_set_t *data_set);
 
 /* extern resource_object_functions_t resource_variants[]; */
diff --git a/include/pcmki/pcmki_sched_utils.h b/include/pcmki/pcmki_sched_utils.h
index fdb3843..b8d7750 100644
--- a/include/pcmki/pcmki_sched_utils.h
+++ b/include/pcmki/pcmki_sched_utils.h
@@ -20,7 +20,7 @@
 #include <pcmki/pcmki_scheduler.h>
 
 /* Constraint helper functions */
-extern rsc_colocation_t *invert_constraint(rsc_colocation_t * constraint);
+pcmk__colocation_t *invert_constraint(pcmk__colocation_t *constraint);
 
 pe__location_t *copy_constraint(pe__location_t *constraint);
 
@@ -71,7 +71,7 @@ enum filter_colocation_res {
 
 extern enum filter_colocation_res
 filter_colocation_constraint(pe_resource_t * rsc_lh, pe_resource_t * rsc_rh,
-                             rsc_colocation_t * constraint, gboolean preview);
+                             pcmk__colocation_t *constraint, gboolean preview);
 
 extern int compare_capacity(const pe_node_t * node1, const pe_node_t * node2);
 extern void calculate_utilization(GHashTable * current_utilization,
diff --git a/include/pcmki/pcmki_scheduler.h b/include/pcmki/pcmki_scheduler.h
index 342d57a..b24e994 100644
--- a/include/pcmki/pcmki_scheduler.h
+++ b/include/pcmki/pcmki_scheduler.h
@@ -10,7 +10,6 @@
 #ifndef PENGINE__H
 #  define PENGINE__H
 
-typedef struct rsc_colocation_s rsc_colocation_t;
 typedef struct rsc_ticket_s rsc_ticket_t;
 typedef struct lrm_agent_s lrm_agent_t;
 
@@ -37,7 +36,7 @@ enum pe_weights {
     pe_weights_rollback = 0x10,
 };
 
-struct rsc_colocation_s {
+typedef struct {
     const char *id;
     const char *node_attribute;
     pe_resource_t *rsc_lh;
@@ -47,7 +46,7 @@ struct rsc_colocation_s {
     int role_rh;
 
     int score;
-};
+} pcmk__colocation_t;
 
 enum loss_ticket_policy_e {
     loss_ticket_stop,
diff --git a/lib/pacemaker/pcmk_output.c b/lib/pacemaker/pcmk_output.c
index 0d20a54..500afd1 100644
--- a/lib/pacemaker/pcmk_output.c
+++ b/lib/pacemaker/pcmk_output.c
@@ -47,7 +47,7 @@ pcmk__out_epilogue(pcmk__output_t *out, xmlNodePtr *xml, int retval) {
 }
 
 static char *
-colocations_header(pe_resource_t *rsc, rsc_colocation_t *cons,
+colocations_header(pe_resource_t *rsc, pcmk__colocation_t *cons,
                    gboolean dependents) {
     char *score = NULL;
     char *retval = NULL;
@@ -68,7 +68,7 @@ colocations_header(pe_resource_t *rsc, rsc_colocation_t *cons,
 
 static void
 colocations_xml_node(pcmk__output_t *out, pe_resource_t *rsc,
-                     rsc_colocation_t *cons) {
+                     pcmk__colocation_t *cons) {
     char *score = NULL;
     xmlNodePtr node = NULL;
 
@@ -146,7 +146,7 @@ rsc_is_colocated_with_list(pcmk__output_t *out, va_list args) {
 
     pe__set_resource_flags(rsc, pe_rsc_allocating);
     for (GList *lpc = rsc->rsc_cons; lpc != NULL; lpc = lpc->next) {
-        rsc_colocation_t *cons = (rsc_colocation_t *) lpc->data;
+        pcmk__colocation_t *cons = (pcmk__colocation_t *) lpc->data;
         char *hdr = NULL;
 
         PCMK__OUTPUT_LIST_HEADER(out, FALSE, rc, "Resources %s is colocated with", rsc->id);
@@ -189,7 +189,7 @@ rsc_is_colocated_with_list_xml(pcmk__output_t *out, va_list args) {
 
     pe__set_resource_flags(rsc, pe_rsc_allocating);
     for (GList *lpc = rsc->rsc_cons; lpc != NULL; lpc = lpc->next) {
-        rsc_colocation_t *cons = (rsc_colocation_t *) lpc->data;
+        pcmk__colocation_t *cons = (pcmk__colocation_t *) lpc->data;
 
         if (pcmk_is_set(cons->rsc_rh->flags, pe_rsc_allocating)) {
             colocations_xml_node(out, cons->rsc_rh, cons);
@@ -221,7 +221,7 @@ rscs_colocated_with_list(pcmk__output_t *out, va_list args) {
 
     pe__set_resource_flags(rsc, pe_rsc_allocating);
     for (GList *lpc = rsc->rsc_cons_lhs; lpc != NULL; lpc = lpc->next) {
-        rsc_colocation_t *cons = (rsc_colocation_t *) lpc->data;
+        pcmk__colocation_t *cons = (pcmk__colocation_t *) lpc->data;
         char *hdr = NULL;
 
         PCMK__OUTPUT_LIST_HEADER(out, FALSE, rc, "Resources colocated with %s", rsc->id);
@@ -264,7 +264,7 @@ rscs_colocated_with_list_xml(pcmk__output_t *out, va_list args) {
 
     pe__set_resource_flags(rsc, pe_rsc_allocating);
     for (GList *lpc = rsc->rsc_cons_lhs; lpc != NULL; lpc = lpc->next) {
-        rsc_colocation_t *cons = (rsc_colocation_t *) lpc->data;
+        pcmk__colocation_t *cons = (pcmk__colocation_t *) lpc->data;
 
         if (pcmk_is_set(cons->rsc_lh->flags, pe_rsc_allocating)) {
             colocations_xml_node(out, cons->rsc_lh, cons);
diff --git a/lib/pacemaker/pcmk_sched_bundle.c b/lib/pacemaker/pcmk_sched_bundle.c
index 02bff7c..ac9219c 100644
--- a/lib/pacemaker/pcmk_sched_bundle.c
+++ b/lib/pacemaker/pcmk_sched_bundle.c
@@ -425,7 +425,7 @@ compatible_replica(pe_resource_t *rsc_lh, pe_resource_t *rsc,
 
 void
 pcmk__bundle_rsc_colocation_lh(pe_resource_t *rsc, pe_resource_t *rsc_rh,
-                               rsc_colocation_t *constraint,
+                               pcmk__colocation_t *constraint,
                                pe_working_set_t *data_set)
 {
     /* -- Never called --
@@ -469,7 +469,7 @@ int copies_per_node(pe_resource_t * rsc)
 
 void
 pcmk__bundle_rsc_colocation_rh(pe_resource_t *rsc_lh, pe_resource_t *rsc,
-                               rsc_colocation_t *constraint,
+                               pcmk__colocation_t *constraint,
                                pe_working_set_t *data_set)
 {
     GListPtr allocated_rhs = NULL;
diff --git a/lib/pacemaker/pcmk_sched_clone.c b/lib/pacemaker/pcmk_sched_clone.c
index e419a24..9485a98 100644
--- a/lib/pacemaker/pcmk_sched_clone.c
+++ b/lib/pacemaker/pcmk_sched_clone.c
@@ -237,7 +237,7 @@ sort_clone_instance(gconstpointer a, gconstpointer b, gpointer data_set)
 
         if(resource1->parent) {
             for (gIter = resource1->parent->rsc_cons; gIter; gIter = gIter->next) {
-                rsc_colocation_t *constraint = (rsc_colocation_t *) gIter->data;
+                pcmk__colocation_t *constraint = (pcmk__colocation_t *) gIter->data;
 
                 if (constraint->score == 0) {
                     continue;
@@ -252,7 +252,7 @@ sort_clone_instance(gconstpointer a, gconstpointer b, gpointer data_set)
             }
 
             for (gIter = resource1->parent->rsc_cons_lhs; gIter; gIter = gIter->next) {
-                rsc_colocation_t *constraint = (rsc_colocation_t *) gIter->data;
+                pcmk__colocation_t *constraint = (pcmk__colocation_t *) gIter->data;
 
                 if (constraint->score == 0) {
                     continue;
@@ -269,7 +269,7 @@ sort_clone_instance(gconstpointer a, gconstpointer b, gpointer data_set)
 
         if(resource2->parent) {
             for (gIter = resource2->parent->rsc_cons; gIter; gIter = gIter->next) {
-                rsc_colocation_t *constraint = (rsc_colocation_t *) gIter->data;
+                pcmk__colocation_t *constraint = (pcmk__colocation_t *) gIter->data;
 
                 crm_trace("Applying %s to %s", constraint->id, resource2->id);
 
@@ -281,7 +281,7 @@ sort_clone_instance(gconstpointer a, gconstpointer b, gpointer data_set)
             }
 
             for (gIter = resource2->parent->rsc_cons_lhs; gIter; gIter = gIter->next) {
-                rsc_colocation_t *constraint = (rsc_colocation_t *) gIter->data;
+                pcmk__colocation_t *constraint = (pcmk__colocation_t *) gIter->data;
 
                 crm_trace("Applying %s to %s", constraint->id, resource2->id);
 
@@ -499,7 +499,7 @@ append_parent_colocation(pe_resource_t * rsc, pe_resource_t * child, gboolean al
 
     gIter = rsc->rsc_cons;
     for (; gIter != NULL; gIter = gIter->next) {
-        rsc_colocation_t *cons = (rsc_colocation_t *) gIter->data;
+        pcmk__colocation_t *cons = (pcmk__colocation_t *) gIter->data;
 
         if (cons->score == 0) {
             continue;
@@ -511,7 +511,7 @@ append_parent_colocation(pe_resource_t * rsc, pe_resource_t * child, gboolean al
 
     gIter = rsc->rsc_cons_lhs;
     for (; gIter != NULL; gIter = gIter->next) {
-        rsc_colocation_t *cons = (rsc_colocation_t *) gIter->data;
+        pcmk__colocation_t *cons = (pcmk__colocation_t *) gIter->data;
 
         if (cons->score == 0) {
             continue;
@@ -645,7 +645,7 @@ pcmk__clone_allocate(pe_resource_t *rsc, pe_node_t *prefer,
      * order to allocate clone instances
      */
     for (GListPtr gIter = rsc->rsc_cons; gIter != NULL; gIter = gIter->next) {
-        rsc_colocation_t *constraint = (rsc_colocation_t *) gIter->data;
+        pcmk__colocation_t *constraint = (pcmk__colocation_t *) gIter->data;
 
         if (constraint->score == 0) {
             continue;
@@ -656,7 +656,7 @@ pcmk__clone_allocate(pe_resource_t *rsc, pe_node_t *prefer,
     }
 
     for (GListPtr gIter = rsc->rsc_cons_lhs; gIter != NULL; gIter = gIter->next) {
-        rsc_colocation_t *constraint = (rsc_colocation_t *) gIter->data;
+        pcmk__colocation_t *constraint = (pcmk__colocation_t *) gIter->data;
 
         if (constraint->score == 0) {
             continue;
@@ -1055,7 +1055,7 @@ find_compatible_child(pe_resource_t *local_child, pe_resource_t *rsc,
 
 void
 clone_rsc_colocation_lh(pe_resource_t *rsc_lh, pe_resource_t *rsc_rh,
-                        rsc_colocation_t *constraint,
+                        pcmk__colocation_t *constraint,
                         pe_working_set_t *data_set)
 {
     /* -- Never called --
@@ -1067,7 +1067,7 @@ clone_rsc_colocation_lh(pe_resource_t *rsc_lh, pe_resource_t *rsc_rh,
 
 void
 clone_rsc_colocation_rh(pe_resource_t *rsc_lh, pe_resource_t *rsc_rh,
-                        rsc_colocation_t *constraint,
+                        pcmk__colocation_t *constraint,
                         pe_working_set_t *data_set)
 {
     GListPtr gIter = NULL;
diff --git a/lib/pacemaker/pcmk_sched_constraints.c b/lib/pacemaker/pcmk_sched_constraints.c
index cce3f12..1b44837 100644
--- a/lib/pacemaker/pcmk_sched_constraints.c
+++ b/lib/pacemaker/pcmk_sched_constraints.c
@@ -1204,8 +1204,8 @@ generate_location_rule(pe_resource_t *rsc, xmlNode *rule_xml,
 static gint
 sort_cons_priority_lh(gconstpointer a, gconstpointer b)
 {
-    const rsc_colocation_t *rsc_constraint1 = (const rsc_colocation_t *)a;
-    const rsc_colocation_t *rsc_constraint2 = (const rsc_colocation_t *)b;
+    const pcmk__colocation_t *rsc_constraint1 = (const pcmk__colocation_t *) a;
+    const pcmk__colocation_t *rsc_constraint2 = (const pcmk__colocation_t *) b;
 
     if (a == NULL) {
         return 1;
@@ -1252,8 +1252,8 @@ sort_cons_priority_lh(gconstpointer a, gconstpointer b)
 static gint
 sort_cons_priority_rh(gconstpointer a, gconstpointer b)
 {
-    const rsc_colocation_t *rsc_constraint1 = (const rsc_colocation_t *)a;
-    const rsc_colocation_t *rsc_constraint2 = (const rsc_colocation_t *)b;
+    const pcmk__colocation_t *rsc_constraint1 = (const pcmk__colocation_t *) a;
+    const pcmk__colocation_t *rsc_constraint2 = (const pcmk__colocation_t *) b;
 
     if (a == NULL) {
         return 1;
@@ -1345,7 +1345,7 @@ pcmk__new_colocation(const char *id, const char *node_attr, int score,
                      const char *state_lh, const char *state_rh,
                      pe_working_set_t *data_set)
 {
-    rsc_colocation_t *new_con = NULL;
+    pcmk__colocation_t *new_con = NULL;
 
     if ((rsc_lh == NULL) || (rsc_rh == NULL)) {
         pcmk__config_err("Ignoring colocation '%s' because resource "
@@ -1353,7 +1353,7 @@ pcmk__new_colocation(const char *id, const char *node_attr, int score,
         return;
     }
 
-    new_con = calloc(1, sizeof(rsc_colocation_t));
+    new_con = calloc(1, sizeof(pcmk__colocation_t));
     if (new_con == NULL) {
         return;
     }
diff --git a/lib/pacemaker/pcmk_sched_graph.c b/lib/pacemaker/pcmk_sched_graph.c
index 51f7063..c012d23 100644
--- a/lib/pacemaker/pcmk_sched_graph.c
+++ b/lib/pacemaker/pcmk_sched_graph.c
@@ -510,7 +510,8 @@ update_colo_start_chain(pe_action_t *action, pe_working_set_t *data_set)
     }
 
     for (gIter = rsc->rsc_cons_lhs; gIter != NULL; gIter = gIter->next) {
-        rsc_colocation_t *colocate_with = (rsc_colocation_t *)gIter->data;
+        pcmk__colocation_t *colocate_with = (pcmk__colocation_t *) gIter->data;
+
         if (colocate_with->score == INFINITY) {
             mark_start_blocked(colocate_with->rsc_lh, action->rsc, data_set);
         }
diff --git a/lib/pacemaker/pcmk_sched_group.c b/lib/pacemaker/pcmk_sched_group.c
index 79847e8..f1ce0be 100644
--- a/lib/pacemaker/pcmk_sched_group.c
+++ b/lib/pacemaker/pcmk_sched_group.c
@@ -282,7 +282,7 @@ group_internal_constraints(pe_resource_t * rsc, pe_working_set_t * data_set)
 
 void
 group_rsc_colocation_lh(pe_resource_t *rsc_lh, pe_resource_t *rsc_rh,
-                        rsc_colocation_t *constraint,
+                        pcmk__colocation_t *constraint,
                         pe_working_set_t *data_set)
 {
     GListPtr gIter = NULL;
@@ -328,7 +328,7 @@ group_rsc_colocation_lh(pe_resource_t *rsc_lh, pe_resource_t *rsc_rh,
 
 void
 group_rsc_colocation_rh(pe_resource_t *rsc_lh, pe_resource_t *rsc_rh,
-                        rsc_colocation_t *constraint,
+                        pcmk__colocation_t *constraint,
                         pe_working_set_t *data_set)
 {
     GListPtr gIter = rsc_rh->children;
@@ -514,7 +514,7 @@ pcmk__group_merge_weights(pe_resource_t *rsc, const char *rhs,
                                                      factor, flags);
 
     for (; gIter != NULL; gIter = gIter->next) {
-        rsc_colocation_t *constraint = (rsc_colocation_t *) gIter->data;
+        pcmk__colocation_t *constraint = (pcmk__colocation_t *) gIter->data;
 
         if (constraint->score == 0) {
             continue;
diff --git a/lib/pacemaker/pcmk_sched_native.c b/lib/pacemaker/pcmk_sched_native.c
index b18f52e..87d8bfb 100644
--- a/lib/pacemaker/pcmk_sched_native.c
+++ b/lib/pacemaker/pcmk_sched_native.c
@@ -434,7 +434,7 @@ pcmk__native_merge_weights(pe_resource_t *rsc, const char *rhs,
 
         for (; gIter != NULL; gIter = gIter->next) {
             pe_resource_t *other = NULL;
-            rsc_colocation_t *constraint = (rsc_colocation_t *) gIter->data;
+            pcmk__colocation_t *constraint = (pcmk__colocation_t *) gIter->data;
 
             if (constraint->score == 0) {
                 continue;
@@ -526,7 +526,7 @@ pcmk__native_allocate(pe_resource_t *rsc, pe_node_t *prefer,
     pe__show_node_weights(true, rsc, "Pre-alloc", rsc->allowed_nodes);
 
     for (gIter = rsc->rsc_cons; gIter != NULL; gIter = gIter->next) {
-        rsc_colocation_t *constraint = (rsc_colocation_t *) gIter->data;
+        pcmk__colocation_t *constraint = (pcmk__colocation_t *) gIter->data;
 
         GHashTable *archive = NULL;
         pe_resource_t *rsc_rh = constraint->rsc_rh;
@@ -560,7 +560,7 @@ pcmk__native_allocate(pe_resource_t *rsc, pe_node_t *prefer,
     pe__show_node_weights(true, rsc, "Post-coloc", rsc->allowed_nodes);
 
     for (gIter = rsc->rsc_cons_lhs; gIter != NULL; gIter = gIter->next) {
-        rsc_colocation_t *constraint = (rsc_colocation_t *) gIter->data;
+        pcmk__colocation_t *constraint = (pcmk__colocation_t *) gIter->data;
 
         if (constraint->score == 0) {
             continue;
@@ -1712,7 +1712,7 @@ native_internal_constraints(pe_resource_t * rsc, pe_working_set_t * data_set)
 
 void
 native_rsc_colocation_lh(pe_resource_t *rsc_lh, pe_resource_t *rsc_rh,
-                         rsc_colocation_t *constraint,
+                         pcmk__colocation_t *constraint,
                          pe_working_set_t *data_set)
 {
     if (rsc_lh == NULL) {
@@ -1735,7 +1735,7 @@ native_rsc_colocation_lh(pe_resource_t *rsc_lh, pe_resource_t *rsc_rh,
 
 enum filter_colocation_res
 filter_colocation_constraint(pe_resource_t * rsc_lh, pe_resource_t * rsc_rh,
-                             rsc_colocation_t * constraint, gboolean preview)
+                             pcmk__colocation_t *constraint, gboolean preview)
 {
     if (constraint->score == 0) {
         return influence_nothing;
@@ -1819,7 +1819,8 @@ filter_colocation_constraint(pe_resource_t * rsc_lh, pe_resource_t * rsc_rh,
 }
 
 static void
-influence_priority(pe_resource_t * rsc_lh, pe_resource_t * rsc_rh, rsc_colocation_t * constraint)
+influence_priority(pe_resource_t *rsc_lh, pe_resource_t *rsc_rh,
+                   pcmk__colocation_t *constraint)
 {
     const char *rh_value = NULL;
     const char *lh_value = NULL;
@@ -1860,7 +1861,8 @@ influence_priority(pe_resource_t * rsc_lh, pe_resource_t * rsc_rh, rsc_colocatio
 }
 
 static void
-colocation_match(pe_resource_t * rsc_lh, pe_resource_t * rsc_rh, rsc_colocation_t * constraint)
+colocation_match(pe_resource_t *rsc_lh, pe_resource_t *rsc_rh,
+                 pcmk__colocation_t *constraint)
 {
     const char *attribute = CRM_ATTR_ID;
     const char *value = NULL;
@@ -1928,7 +1930,7 @@ colocation_match(pe_resource_t * rsc_lh, pe_resource_t * rsc_rh, rsc_colocation_
 
 void
 native_rsc_colocation_rh(pe_resource_t *rsc_lh, pe_resource_t *rsc_rh,
-                         rsc_colocation_t *constraint,
+                         pcmk__colocation_t *constraint,
                          pe_working_set_t *data_set)
 {
     enum filter_colocation_res filter_results;
diff --git a/lib/pacemaker/pcmk_sched_promotable.c b/lib/pacemaker/pcmk_sched_promotable.c
index b976344..9a5474a 100644
--- a/lib/pacemaker/pcmk_sched_promotable.c
+++ b/lib/pacemaker/pcmk_sched_promotable.c
@@ -319,7 +319,7 @@ promotion_order(pe_resource_t *rsc, pe_working_set_t *data_set)
 
     gIter = rsc->rsc_cons;
     for (; gIter != NULL; gIter = gIter->next) {
-        rsc_colocation_t *constraint = (rsc_colocation_t *) gIter->data;
+        pcmk__colocation_t *constraint = (pcmk__colocation_t *) gIter->data;
 
         if (constraint->score == 0) {
             continue;
@@ -343,7 +343,7 @@ promotion_order(pe_resource_t *rsc, pe_working_set_t *data_set)
 
     gIter = rsc->rsc_cons_lhs;
     for (; gIter != NULL; gIter = gIter->next) {
-        rsc_colocation_t *constraint = (rsc_colocation_t *) gIter->data;
+        pcmk__colocation_t *constraint = (pcmk__colocation_t *) gIter->data;
 
         if (constraint->score == 0) {
             continue;
@@ -738,7 +738,7 @@ pcmk__set_instance_roles(pe_resource_t *rsc, pe_working_set_t *data_set)
         apply_master_location(child_rsc, rsc->rsc_location, chosen);
 
         for (gIter2 = child_rsc->rsc_cons; gIter2 != NULL; gIter2 = gIter2->next) {
-            rsc_colocation_t *cons = (rsc_colocation_t *) gIter2->data;
+            pcmk__colocation_t *cons = (pcmk__colocation_t *) gIter2->data;
 
             if (cons->score == 0) {
                 continue;
@@ -981,7 +981,7 @@ node_hash_update_one(GHashTable * hash, pe_node_t * other, const char *attr, int
 
 void
 promotable_colocation_rh(pe_resource_t *rsc_lh, pe_resource_t *rsc_rh,
-                         rsc_colocation_t *constraint,
+                         pcmk__colocation_t *constraint,
                          pe_working_set_t *data_set)
 {
     GListPtr gIter = NULL;
diff --git a/lib/pacemaker/pcmk_sched_utilization.c b/lib/pacemaker/pcmk_sched_utilization.c
index b46b2fa..0df3a17 100644
--- a/lib/pacemaker/pcmk_sched_utilization.c
+++ b/lib/pacemaker/pcmk_sched_utilization.c
@@ -276,7 +276,7 @@ find_colocated_rscs(GListPtr colocated_rscs, pe_resource_t * rsc, pe_resource_t
     colocated_rscs = g_list_append(colocated_rscs, rsc);
 
     for (gIter = rsc->rsc_cons; gIter != NULL; gIter = gIter->next) {
-        rsc_colocation_t *constraint = (rsc_colocation_t *) gIter->data;
+        pcmk__colocation_t *constraint = (pcmk__colocation_t *) gIter->data;
         pe_resource_t *rsc_rh = constraint->rsc_rh;
 
         /* Break colocation loop */
@@ -298,7 +298,7 @@ find_colocated_rscs(GListPtr colocated_rscs, pe_resource_t * rsc, pe_resource_t
     }
 
     for (gIter = rsc->rsc_cons_lhs; gIter != NULL; gIter = gIter->next) {
-        rsc_colocation_t *constraint = (rsc_colocation_t *) gIter->data;
+        pcmk__colocation_t *constraint = (pcmk__colocation_t *) gIter->data;
         pe_resource_t *rsc_lh = constraint->rsc_lh;
 
         /* Break colocation loop */
diff --git a/tools/crm_resource_runtime.c b/tools/crm_resource_runtime.c
index f4500db..e0804fc 100644
--- a/tools/crm_resource_runtime.c
+++ b/tools/crm_resource_runtime.c
@@ -392,7 +392,7 @@ cli_resource_update_attribute(pcmk__output_t *out, pe_resource_t *rsc,
             crm_debug("Looking for dependencies %p", rsc->rsc_cons_lhs);
             pe__set_resource_flags(rsc, pe_rsc_allocating);
             for (lpc = rsc->rsc_cons_lhs; lpc != NULL; lpc = lpc->next) {
-                rsc_colocation_t *cons = (rsc_colocation_t *) lpc->data;
+                pcmk__colocation_t *cons = (pcmk__colocation_t *) lpc->data;
                 pe_resource_t *peer = cons->rsc_lh;
 
                 crm_debug("Checking %s %d", cons->id, cons->score);
-- 
1.8.3.1


From 83401876df22539c35f09b21135eefc7432f3839 Mon Sep 17 00:00:00 2001
From: Ken Gaillot <kgaillot@redhat.com>
Date: Fri, 4 Dec 2020 17:02:36 -0600
Subject: [PATCH 3/4] Refactor: scheduler: make colocation constraint unpacker
 static

... for linker efficiency. Also make it (and a function it calls) return void
since the only caller ignored the value.
---
 include/pcmki/pcmki_sched_allocate.h   |  2 --
 lib/pacemaker/pcmk_sched_constraints.c | 45 +++++++++++++++-------------------
 2 files changed, 20 insertions(+), 27 deletions(-)

diff --git a/include/pcmki/pcmki_sched_allocate.h b/include/pcmki/pcmki_sched_allocate.h
index 0859eaa..d226c8c 100644
--- a/include/pcmki/pcmki_sched_allocate.h
+++ b/include/pcmki/pcmki_sched_allocate.h
@@ -141,8 +141,6 @@ extern resource_alloc_functions_t resource_class_alloc_functions[];
 
 extern gboolean unpack_rsc_order(xmlNode * xml_obj, pe_working_set_t * data_set);
 
-extern gboolean unpack_rsc_colocation(xmlNode * xml_obj, pe_working_set_t * data_set);
-
 extern gboolean unpack_rsc_ticket(xmlNode * xml_obj, pe_working_set_t * data_set);
 
 void LogNodeActions(pe_working_set_t * data_set, gboolean terminal);
diff --git a/lib/pacemaker/pcmk_sched_constraints.c b/lib/pacemaker/pcmk_sched_constraints.c
index 1b44837..0029ad7 100644
--- a/lib/pacemaker/pcmk_sched_constraints.c
+++ b/lib/pacemaker/pcmk_sched_constraints.c
@@ -49,6 +49,7 @@ static pe__location_t *generate_location_rule(pe_resource_t *rsc,
                                               pe_working_set_t *data_set,
                                               pe_match_data_t *match_data);
 static void unpack_location(xmlNode *xml_obj, pe_working_set_t *data_set);
+static void unpack_rsc_colocation(xmlNode *xml_obj, pe_working_set_t *data_set);
 
 static bool
 evaluate_lifetime(xmlNode *lifetime, pe_working_set_t *data_set)
@@ -2463,7 +2464,7 @@ colocate_rsc_sets(const char *id, xmlNode * set1, xmlNode * set2, int score,
     return TRUE;
 }
 
-static gboolean
+static void
 unpack_simple_colocation(xmlNode * xml_obj, pe_working_set_t * data_set)
 {
     int score_i = 0;
@@ -2488,24 +2489,24 @@ unpack_simple_colocation(xmlNode * xml_obj, pe_working_set_t * data_set)
     if (rsc_lh == NULL) {
         pcmk__config_err("Ignoring constraint '%s' because resource '%s' "
                          "does not exist", id, id_lh);
-        return FALSE;
+        return;
 
     } else if (rsc_rh == NULL) {
         pcmk__config_err("Ignoring constraint '%s' because resource '%s' "
                          "does not exist", id, id_rh);
-        return FALSE;
+        return;
 
     } else if (instance_lh && pe_rsc_is_clone(rsc_lh) == FALSE) {
         pcmk__config_err("Ignoring constraint '%s' because resource '%s' "
                          "is not a clone but instance '%s' was requested",
                          id, id_lh, instance_lh);
-        return FALSE;
+        return;
 
     } else if (instance_rh && pe_rsc_is_clone(rsc_rh) == FALSE) {
         pcmk__config_err("Ignoring constraint '%s' because resource '%s' "
                          "is not a clone but instance '%s' was requested",
                          id, id_rh, instance_rh);
-        return FALSE;
+        return;
     }
 
     if (instance_lh) {
@@ -2514,7 +2515,7 @@ unpack_simple_colocation(xmlNode * xml_obj, pe_working_set_t * data_set)
             pcmk__config_warn("Ignoring constraint '%s' because resource '%s' "
                               "does not have an instance '%s'",
                               id, id_lh, instance_lh);
-            return FALSE;
+            return;
         }
     }
 
@@ -2524,7 +2525,7 @@ unpack_simple_colocation(xmlNode * xml_obj, pe_working_set_t * data_set)
             pcmk__config_warn("Ignoring constraint '%s' because resource '%s' "
                               "does not have an instance '%s'",
                               "'%s'", id, id_rh, instance_rh);
-            return FALSE;
+            return;
         }
     }
 
@@ -2540,7 +2541,6 @@ unpack_simple_colocation(xmlNode * xml_obj, pe_working_set_t * data_set)
 
     pcmk__new_colocation(id, attr, score_i, rsc_lh, rsc_rh, state_lh, state_rh,
                          data_set);
-    return TRUE;
 }
 
 static gboolean
@@ -2660,8 +2660,8 @@ unpack_colocation_tags(xmlNode * xml_obj, xmlNode ** expanded_xml, pe_working_se
     return TRUE;
 }
 
-gboolean
-unpack_rsc_colocation(xmlNode * xml_obj, pe_working_set_t * data_set)
+static void
+unpack_rsc_colocation(xmlNode *xml_obj, pe_working_set_t *data_set)
 {
     int score_i = 0;
     xmlNode *set = NULL;
@@ -2674,19 +2674,16 @@ unpack_rsc_colocation(xmlNode * xml_obj, pe_working_set_t * data_set)
     const char *id = crm_element_value(xml_obj, XML_ATTR_ID);
     const char *score = crm_element_value(xml_obj, XML_RULE_ATTR_SCORE);
 
-    gboolean rc = TRUE;
-
     if (score) {
         score_i = char2score(score);
     }
 
-    rc = unpack_colocation_tags(xml_obj, &expanded_xml, data_set);
+    if (!unpack_colocation_tags(xml_obj, &expanded_xml, data_set)) {
+        return;
+    }
     if (expanded_xml) {
         orig_xml = xml_obj;
         xml_obj = expanded_xml;
-
-    } else if (rc == FALSE) {
-        return FALSE;
     }
 
     for (set = pcmk__xe_first_child(xml_obj); set != NULL;
@@ -2695,11 +2692,11 @@ unpack_rsc_colocation(xmlNode * xml_obj, pe_working_set_t * data_set)
         if (pcmk__str_eq((const char *)set->name, XML_CONS_TAG_RSC_SET, pcmk__str_none)) {
             any_sets = TRUE;
             set = expand_idref(set, data_set->input);
-            if (unpack_colocation_set(set, score_i, data_set) == FALSE) {
-                return FALSE;
-
-            } else if (last && colocate_rsc_sets(id, last, set, score_i, data_set) == FALSE) {
-                return FALSE;
+            if (!unpack_colocation_set(set, score_i, data_set)) {
+                return;
+            }
+            if (last && !colocate_rsc_sets(id, last, set, score_i, data_set)) {
+                return;
             }
             last = set;
         }
@@ -2710,11 +2707,9 @@ unpack_rsc_colocation(xmlNode * xml_obj, pe_working_set_t * data_set)
         xml_obj = orig_xml;
     }
 
-    if (any_sets == FALSE) {
-        return unpack_simple_colocation(xml_obj, data_set);
+    if (!any_sets) {
+        unpack_simple_colocation(xml_obj, data_set);
     }
-
-    return TRUE;
 }
 
 gboolean
-- 
1.8.3.1


From 2278e01f8d951d939c172ac71e168a11199f84f7 Mon Sep 17 00:00:00 2001
From: Ken Gaillot <kgaillot@redhat.com>
Date: Mon, 21 Dec 2020 17:07:45 -0600
Subject: [PATCH 4/4] Refactor: scheduler: functionize checking whether
 colocation applies

This allows us to have more consistent trace messages, and will reduce
code duplication when more checks are added later.
---
 include/pcmki/pcmki_sched_utils.h     |  3 +++
 lib/pacemaker/pcmk_sched_clone.c      | 12 +++++-------
 lib/pacemaker/pcmk_sched_group.c      | 12 ++++++------
 lib/pacemaker/pcmk_sched_native.c     | 14 ++++----------
 lib/pacemaker/pcmk_sched_promotable.c | 25 ++++++++-----------------
 lib/pacemaker/pcmk_sched_utils.c      | 31 +++++++++++++++++++++++++++++++
 6 files changed, 57 insertions(+), 40 deletions(-)

diff --git a/include/pcmki/pcmki_sched_utils.h b/include/pcmki/pcmki_sched_utils.h
index b8d7750..c7ae1b8 100644
--- a/include/pcmki/pcmki_sched_utils.h
+++ b/include/pcmki/pcmki_sched_utils.h
@@ -72,6 +72,9 @@ enum filter_colocation_res {
 extern enum filter_colocation_res
 filter_colocation_constraint(pe_resource_t * rsc_lh, pe_resource_t * rsc_rh,
                              pcmk__colocation_t *constraint, gboolean preview);
+bool pcmk__colocation_applies(pe_resource_t *rsc,
+                              pcmk__colocation_t *colocation,
+                              bool promoted_only);
 
 extern int compare_capacity(const pe_node_t * node1, const pe_node_t * node2);
 extern void calculate_utilization(GHashTable * current_utilization,
diff --git a/lib/pacemaker/pcmk_sched_clone.c b/lib/pacemaker/pcmk_sched_clone.c
index 9485a98..5a06151 100644
--- a/lib/pacemaker/pcmk_sched_clone.c
+++ b/lib/pacemaker/pcmk_sched_clone.c
@@ -658,14 +658,12 @@ pcmk__clone_allocate(pe_resource_t *rsc, pe_node_t *prefer,
     for (GListPtr gIter = rsc->rsc_cons_lhs; gIter != NULL; gIter = gIter->next) {
         pcmk__colocation_t *constraint = (pcmk__colocation_t *) gIter->data;
 
-        if (constraint->score == 0) {
-            continue;
+        if (pcmk__colocation_applies(rsc, constraint, false)) {
+            rsc->allowed_nodes = constraint->rsc_lh->cmds->merge_weights(constraint->rsc_lh,
+                    rsc->id, rsc->allowed_nodes, constraint->node_attribute,
+                    constraint->score / (float) INFINITY,
+                    pe_weights_rollback|pe_weights_positive);
         }
-        rsc->allowed_nodes =
-            constraint->rsc_lh->cmds->merge_weights(constraint->rsc_lh, rsc->id, rsc->allowed_nodes,
-                                                    constraint->node_attribute,
-                                                    (float)constraint->score / INFINITY,
-                                                    (pe_weights_rollback | pe_weights_positive));
     }
 
     pe__show_node_weights(!show_scores, rsc, __func__, rsc->allowed_nodes);
diff --git a/lib/pacemaker/pcmk_sched_group.c b/lib/pacemaker/pcmk_sched_group.c
index f1ce0be..5334f23 100644
--- a/lib/pacemaker/pcmk_sched_group.c
+++ b/lib/pacemaker/pcmk_sched_group.c
@@ -516,13 +516,13 @@ pcmk__group_merge_weights(pe_resource_t *rsc, const char *rhs,
     for (; gIter != NULL; gIter = gIter->next) {
         pcmk__colocation_t *constraint = (pcmk__colocation_t *) gIter->data;
 
-        if (constraint->score == 0) {
-            continue;
+        if (pcmk__colocation_applies(rsc, constraint, false)) {
+            nodes = pcmk__native_merge_weights(constraint->rsc_lh, rsc->id,
+                                               nodes,
+                                               constraint->node_attribute,
+                                               constraint->score / (float) INFINITY,
+                                               flags);
         }
-        nodes = pcmk__native_merge_weights(constraint->rsc_lh, rsc->id, nodes,
-                                           constraint->node_attribute,
-                                           constraint->score / (float) INFINITY,
-                                           flags);
     }
 
     pe__clear_resource_flags(rsc, pe_rsc_merging);
diff --git a/lib/pacemaker/pcmk_sched_native.c b/lib/pacemaker/pcmk_sched_native.c
index 87d8bfb..c302db6 100644
--- a/lib/pacemaker/pcmk_sched_native.c
+++ b/lib/pacemaker/pcmk_sched_native.c
@@ -562,17 +562,11 @@ pcmk__native_allocate(pe_resource_t *rsc, pe_node_t *prefer,
     for (gIter = rsc->rsc_cons_lhs; gIter != NULL; gIter = gIter->next) {
         pcmk__colocation_t *constraint = (pcmk__colocation_t *) gIter->data;
 
-        if (constraint->score == 0) {
-            continue;
+        if (pcmk__colocation_applies(rsc, constraint, false)) {
+            rsc->allowed_nodes = constraint->rsc_lh->cmds->merge_weights(constraint->rsc_lh,
+                    rsc->id, rsc->allowed_nodes, constraint->node_attribute,
+                    constraint->score / (float) INFINITY, pe_weights_rollback);
         }
-        pe_rsc_trace(rsc, "Merging score of '%s' constraint (%s with %s)",
-                     constraint->id, constraint->rsc_lh->id,
-                     constraint->rsc_rh->id);
-        rsc->allowed_nodes =
-            constraint->rsc_lh->cmds->merge_weights(constraint->rsc_lh, rsc->id, rsc->allowed_nodes,
-                                                    constraint->node_attribute,
-                                                    (float)constraint->score / INFINITY,
-                                                    pe_weights_rollback);
     }
 
     if (rsc->next_role == RSC_ROLE_STOPPED) {
diff --git a/lib/pacemaker/pcmk_sched_promotable.c b/lib/pacemaker/pcmk_sched_promotable.c
index 9a5474a..a0eeaad 100644
--- a/lib/pacemaker/pcmk_sched_promotable.c
+++ b/lib/pacemaker/pcmk_sched_promotable.c
@@ -345,23 +345,14 @@ promotion_order(pe_resource_t *rsc, pe_working_set_t *data_set)
     for (; gIter != NULL; gIter = gIter->next) {
         pcmk__colocation_t *constraint = (pcmk__colocation_t *) gIter->data;
 
-        if (constraint->score == 0) {
-            continue;
-        }
-
-        /* (re-)adds location preferences of resource that wish to be
-         * colocated with the master instance
-         */
-        if (constraint->role_rh == RSC_ROLE_MASTER) {
-            pe_rsc_trace(rsc, "LHS: %s with %s: %d", constraint->rsc_lh->id, constraint->rsc_rh->id,
-                         constraint->score);
-            rsc->allowed_nodes =
-                constraint->rsc_lh->cmds->merge_weights(constraint->rsc_lh, rsc->id,
-                                                        rsc->allowed_nodes,
-                                                        constraint->node_attribute,
-                                                        (float)constraint->score / INFINITY,
-                                                        (pe_weights_rollback |
-                                                         pe_weights_positive));
+        if (pcmk__colocation_applies(rsc, constraint, true)) {
+            /* (Re-)add location preferences of resource that wishes to be
+             * colocated with the promoted instance.
+             */
+            rsc->allowed_nodes = constraint->rsc_lh->cmds->merge_weights(constraint->rsc_lh,
+                    rsc->id, rsc->allowed_nodes, constraint->node_attribute,
+                    constraint->score / (float) INFINITY,
+                    pe_weights_rollback|pe_weights_positive);
         }
     }
 
diff --git a/lib/pacemaker/pcmk_sched_utils.c b/lib/pacemaker/pcmk_sched_utils.c
index eaaf526..aba417a 100644
--- a/lib/pacemaker/pcmk_sched_utils.c
+++ b/lib/pacemaker/pcmk_sched_utils.c
@@ -765,3 +765,34 @@ pcmk__create_history_xml(xmlNode *parent, lrmd_event_data_t *op,
     free(key);
     return xml_op;
 }
+
+/*!
+ * \internal
+ * \brief Check whether a colocation constraint should apply
+ *
+ * \param[in] rsc            Resource of interest (for logging)
+ * \param[in] colocation     Colocation constraint to check
+ * \param[in] promoted_only  If true, constraint applies if right-hand is promoted
+ */
+bool
+pcmk__colocation_applies(pe_resource_t *rsc, pcmk__colocation_t *colocation,
+                         bool promoted_only)
+{
+    CRM_CHECK((rsc != NULL) && (colocation != NULL), return false);
+
+    if (colocation->score == 0) {
+        pe_rsc_trace(rsc, "Ignoring colocation constraint %s: 0 score",
+                     colocation->id);
+        return false;
+    }
+    if (promoted_only && (colocation->role_rh != RSC_ROLE_MASTER)) {
+        pe_rsc_trace(rsc, "Ignoring colocation constraint %s: role",
+                     colocation->id);
+        return false;
+    }
+    pe_rsc_trace(rsc, "Applying colocation constraint %s: %s with %s%s (%d)",
+                 colocation->id, colocation->rsc_lh->id,
+                 (promoted_only? "promoted " : ""),
+                 colocation->rsc_rh->id, colocation->score);
+    return true;
+}
-- 
1.8.3.1