commit 61c6a8acd9c093af333cabe5381c9b7500880c5f
Author: Andrew Beekhof <andrew@beekhof.net>
Date:   Thu Jun 15 10:40:39 2017 +1000

    Fix: PE: Correctly implement pe_order_implies_first_printed

Index: pacemaker/pengine/graph.c
===================================================================
--- pacemaker.orig/pengine/graph.c
+++ pacemaker/pengine/graph.c
@@ -174,7 +174,8 @@ rsc_expand_action(action_t * action)
 }
 
 static enum pe_graph_flags
-graph_update_action(action_t * first, action_t * then, node_t * node, enum pe_action_flags flags,
+graph_update_action(action_t * first, action_t * then, node_t * node,
+                    enum pe_action_flags first_flags, enum pe_action_flags then_flags,
                     enum pe_ordering type)
 {
     enum pe_graph_flags changed = pe_graph_none;
@@ -186,10 +187,10 @@ graph_update_action(action_t * first, ac
         processed = TRUE;
         if (then->rsc) {
             changed |=
-                then->rsc->cmds->update_actions(first, then, node, flags & pe_action_optional,
+                then->rsc->cmds->update_actions(first, then, node, first_flags & pe_action_optional,
                                                 pe_action_optional, pe_order_implies_then);
 
-        } else if (is_set(flags, pe_action_optional) == FALSE) {
+        } else if (is_set(first_flags, pe_action_optional) == FALSE) {
             if (update_action_flags(then, pe_action_optional | pe_action_clear)) {
                 changed |= pe_graph_updated_then;
             }
@@ -206,7 +207,7 @@ graph_update_action(action_t * first, ac
 
         processed = TRUE;
         changed |=
-            then->rsc->cmds->update_actions(first, then, node, flags, restart, pe_order_restart);
+            then->rsc->cmds->update_actions(first, then, node, first_flags, restart, pe_order_restart);
         if (changed) {
             pe_rsc_trace(then->rsc, "restart: %s then %s: changed", first->uuid, then->uuid);
         } else {
@@ -218,10 +219,10 @@ graph_update_action(action_t * first, ac
         processed = TRUE;
         if (first->rsc) {
             changed |=
-                first->rsc->cmds->update_actions(first, then, node, flags,
+                first->rsc->cmds->update_actions(first, then, node, first_flags,
                                                  pe_action_optional, pe_order_implies_first);
 
-        } else if (is_set(flags, pe_action_optional) == FALSE) {
+        } else if (is_set(first_flags, pe_action_optional) == FALSE) {
             if (update_action_flags(first, pe_action_runnable | pe_action_clear)) {
                 changed |= pe_graph_updated_first;
             }
@@ -238,7 +239,7 @@ graph_update_action(action_t * first, ac
         processed = TRUE;
         if (then->rsc) {
             changed |=
-                then->rsc->cmds->update_actions(first, then, node, flags & pe_action_optional,
+                then->rsc->cmds->update_actions(first, then, node, first_flags & pe_action_optional,
                                                 pe_action_optional, pe_order_implies_first_master);
         }
 
@@ -256,10 +257,10 @@ graph_update_action(action_t * first, ac
         processed = TRUE;
         if (then->rsc) {
             changed |=
-                then->rsc->cmds->update_actions(first, then, node, flags,
+                then->rsc->cmds->update_actions(first, then, node, first_flags,
                                                 pe_action_runnable, pe_order_one_or_more);
 
-        } else if (is_set(flags, pe_action_runnable)) {
+        } else if (is_set(first_flags, pe_action_runnable)) {
             /* alright. a "first" action is considered runnable, incremente
              * the 'runnable_before' counter */
             then->runnable_before++;
@@ -284,12 +285,12 @@ graph_update_action(action_t * first, ac
         processed = TRUE;
         if (then->rsc) {
             changed |=
-                then->rsc->cmds->update_actions(first, then, node, flags,
+                then->rsc->cmds->update_actions(first, then, node, first_flags,
                                                 pe_action_runnable, pe_order_runnable_left);
 
-        } else if (is_set(flags, pe_action_runnable) == FALSE) {
+        } else if (is_set(first_flags, pe_action_runnable) == FALSE) {
             if (update_action_flags(then, pe_action_runnable | pe_action_clear)) {
-                changed |= pe_graph_updated_then;
+                 changed |= pe_graph_updated_then;
             }
         }
         if (changed) {
@@ -303,7 +304,7 @@ graph_update_action(action_t * first, ac
         processed = TRUE;
         if (then->rsc) {
             changed |=
-                then->rsc->cmds->update_actions(first, then, node, flags,
+                then->rsc->cmds->update_actions(first, then, node, first_flags,
                                                 pe_action_optional, pe_order_implies_first_migratable);
         }
         if (changed) {
@@ -317,7 +318,7 @@ graph_update_action(action_t * first, ac
         processed = TRUE;
         if (then->rsc) {
             changed |=
-                then->rsc->cmds->update_actions(first, then, node, flags,
+                then->rsc->cmds->update_actions(first, then, node, first_flags,
                                                 pe_action_optional, pe_order_pseudo_left);
         }
         if (changed) {
@@ -331,7 +332,7 @@ graph_update_action(action_t * first, ac
         processed = TRUE;
         if (then->rsc) {
             changed |=
-                then->rsc->cmds->update_actions(first, then, node, flags,
+                then->rsc->cmds->update_actions(first, then, node, first_flags,
                                                 pe_action_runnable, pe_order_optional);
         }
         if (changed) {
@@ -345,7 +346,7 @@ graph_update_action(action_t * first, ac
         processed = TRUE;
         if (then->rsc) {
             changed |=
-                then->rsc->cmds->update_actions(first, then, node, flags,
+                then->rsc->cmds->update_actions(first, then, node, first_flags,
                                                 pe_action_runnable, pe_order_asymmetrical);
         }
 
@@ -358,13 +359,13 @@ graph_update_action(action_t * first, ac
     }
 
     if ((first->flags & pe_action_runnable) && (type & pe_order_implies_then_printed)
-        && (flags & pe_action_optional) == 0) {
+        && (first_flags & pe_action_optional) == 0) {
         processed = TRUE;
         crm_trace("%s implies %s printed", first->uuid, then->uuid);
         update_action_flags(then, pe_action_print_always);      /* don't care about changed */
     }
 
-    if ((type & pe_order_implies_first_printed) && (flags & pe_action_optional) == 0) {
+    if (is_set(type, pe_order_implies_first_printed) && is_set(then_flags, pe_action_optional) == FALSE) {
         processed = TRUE;
         crm_trace("%s implies %s printed", then->uuid, first->uuid);
         update_action_flags(first, pe_action_print_always);     /* don't care about changed */
@@ -508,7 +509,6 @@ update_action(action_t * then)
                 crm_trace("Then: Found node %s for %s", then_node->details->uname, then->uuid);
             }
         }
-
         /* Disable constraint if it only applies when on same node, but isn't */
         if (is_set(other->type, pe_order_same_node) && first_node && then_node
             && (first_node->details != then_node->details)) {
@@ -522,8 +522,7 @@ update_action(action_t * then)
 
         clear_bit(changed, pe_graph_updated_first);
 
-        if (first->rsc != then->rsc
-            && first->rsc != NULL && then->rsc != NULL && first->rsc != then->rsc->parent) {
+        if (first->rsc != then->rsc && is_parent(then->rsc, first->rsc) == FALSE) {
             first = rsc_expand_action(first);
         }
         if (first != other->action) {
@@ -582,7 +581,8 @@ update_action(action_t * then)
                 node = first->node;
             }
             clear_bit(first_flags, pe_action_pseudo);
-            changed |= graph_update_action(first, then, node, first_flags, otype);
+
+            changed |= graph_update_action(first, then, node, first_flags, then_flags, otype);
 
             /* 'first' was for a complex resource (clone, group, etc),
              * create a new dependency if necessary
