399718
From e57cbc5b85d3459d7a6f004f6252ffd1e60a51d5 Mon Sep 17 00:00:00 2001
399718
From: Ken Gaillot <kgaillot@redhat.com>
399718
Date: Tue, 22 Aug 2017 16:40:15 -0500
399718
Subject: [PATCH] Refactor: pengine: functionize common ordering tasks
399718
399718
Enhances readability
399718
399718
The only functional difference is that demotes of resources on guest nodes will
399718
now get pe_order_runnable_left when ordered relative to the guest node
399718
connection start (and the container is not failed). It was already used in
399718
comparable situations, and makes sense.
399718
---
399718
 pengine/allocate.c | 111 ++++++++++++++++++++++++++++++-----------------------
399718
 1 file changed, 63 insertions(+), 48 deletions(-)
399718
399718
diff --git a/pengine/allocate.c b/pengine/allocate.c
399718
index 3c3df27..a540f9f 100644
399718
--- a/pengine/allocate.c
399718
+++ b/pengine/allocate.c
399718
@@ -1206,6 +1206,37 @@ allocate_resources(pe_working_set_t * data_set)
399718
     }
399718
 }
399718
 
399718
+/* We always use pe_order_preserve with these convenience functions to exempt
399718
+ * internally generated constraints from the prohibition of user constraints
399718
+ * involving remote connection resources.
399718
+ *
399718
+ * The start ordering additionally uses pe_order_runnable_left so that the
399718
+ * specified action is not runnable if the start is not runnable.
399718
+ */
399718
+
399718
+static inline void
399718
+order_start_then_action(resource_t *lh_rsc, action_t *rh_action,
399718
+                        enum pe_ordering extra, pe_working_set_t *data_set)
399718
+{
399718
+    if (lh_rsc && rh_action && data_set) {
399718
+        custom_action_order(lh_rsc, start_key(lh_rsc), NULL,
399718
+                            rh_action->rsc, NULL, rh_action,
399718
+                            pe_order_preserve | pe_order_runnable_left | extra,
399718
+                            data_set);
399718
+    }
399718
+}
399718
+
399718
+static inline void
399718
+order_action_then_stop(action_t *lh_action, resource_t *rh_rsc,
399718
+                       enum pe_ordering extra, pe_working_set_t *data_set)
399718
+{
399718
+    if (lh_action && rh_rsc && data_set) {
399718
+        custom_action_order(lh_action->rsc, NULL, lh_action,
399718
+                            rh_rsc, stop_key(rh_rsc), NULL,
399718
+                            pe_order_preserve | extra, data_set);
399718
+    }
399718
+}
399718
+
399718
 static void
399718
 cleanup_orphans(resource_t * rsc, pe_working_set_t * data_set)
399718
 {
399718
@@ -1235,9 +1266,12 @@ cleanup_orphans(resource_t * rsc, pe_working_set_t * data_set)
399718
                         CRM_XS " %s",
399718
                         rsc->id, node->details->uname, clear_op->uuid);
399718
 
399718
-            custom_action_order(rsc, NULL, clear_op,
399718
-                            rsc, generate_op_key(rsc->id, RSC_STOP, 0), NULL,
399718
-                            pe_order_optional, data_set);
399718
+            /* We can't use order_action_then_stop() here because its
399718
+             * pe_order_preserve breaks things
399718
+             */
399718
+            custom_action_order(clear_op->rsc, NULL, clear_op,
399718
+                                rsc, stop_key(rsc), NULL,
399718
+                                pe_order_optional, data_set);
399718
         }
399718
     }
399718
 }
399718
@@ -1817,14 +1851,12 @@ apply_container_ordering(action_t *action, pe_working_set_t *data_set)
399718
         case start_rsc:
399718
         case action_promote:
399718
             /* Force resource recovery if the container is recovered */
399718
-            custom_action_order(container, generate_op_key(container->id, RSC_START, 0), NULL,
399718
-                                action->rsc, NULL, action,
399718
-                                pe_order_preserve | pe_order_implies_then | pe_order_runnable_left, data_set);
399718
+            order_start_then_action(container, action, pe_order_implies_then,
399718
+                                    data_set);
399718
 
399718
             /* Wait for the connection resource to be up too */
399718
-            custom_action_order(remote_rsc, generate_op_key(remote_rsc->id, RSC_START, 0), NULL,
399718
-                                action->rsc, NULL, action,
399718
-                                pe_order_preserve | pe_order_runnable_left, data_set);
399718
+            order_start_then_action(remote_rsc, action, pe_order_none,
399718
+                                    data_set);
399718
             break;
399718
         case stop_rsc:
399718
             if(is_set(container->flags, pe_rsc_failed)) {
399718
@@ -1836,9 +1868,8 @@ apply_container_ordering(action_t *action, pe_working_set_t *data_set)
399718
                  */
399718
             } else {
399718
                 /* Otherwise, ensure the operation happens before the connection is brought down */
399718
-                custom_action_order(action->rsc, NULL, action,
399718
-                                    remote_rsc, generate_op_key(remote_rsc->id, RSC_STOP, 0), NULL,
399718
-                                    pe_order_preserve, data_set);
399718
+                order_action_then_stop(action, remote_rsc, pe_order_none,
399718
+                                       data_set);
399718
             }
399718
             break;
399718
         case action_demote:
399718
@@ -1854,9 +1885,8 @@ apply_container_ordering(action_t *action, pe_working_set_t *data_set)
399718
 
399718
             } else {
399718
                 /* Otherwise, ensure the operation happens before the connection is brought down */
399718
-                custom_action_order(action->rsc, NULL, action,
399718
-                                    remote_rsc, generate_op_key(remote_rsc->id, RSC_STOP, 0), NULL,
399718
-                                    pe_order_preserve, data_set);
399718
+                order_action_then_stop(action, remote_rsc, pe_order_none,
399718
+                                       data_set);
399718
             }
399718
             break;
399718
         default:
399718
@@ -1867,14 +1897,12 @@ apply_container_ordering(action_t *action, pe_working_set_t *data_set)
399718
                  * the connection was re-established
399718
                  */
399718
                 if(task != no_action) {
399718
-                    custom_action_order(remote_rsc, generate_op_key(remote_rsc->id, RSC_START, 0), NULL,
399718
-                                        action->rsc, NULL, action,
399718
-                                        pe_order_preserve | pe_order_runnable_left | pe_order_implies_then, data_set);
399718
+                    order_start_then_action(remote_rsc, action,
399718
+                                            pe_order_implies_then, data_set);
399718
                 }
399718
             } else {
399718
-                custom_action_order(remote_rsc, generate_op_key(remote_rsc->id, RSC_START, 0), NULL,
399718
-                                    action->rsc, NULL, action,
399718
-                                    pe_order_preserve | pe_order_runnable_left, data_set);
399718
+                order_start_then_action(remote_rsc, action, pe_order_none,
399718
+                                        data_set);
399718
             }
399718
             break;
399718
     }
399718
@@ -1988,11 +2016,7 @@ apply_remote_ordering(action_t *action, pe_working_set_t *data_set)
399718
     switch (task) {
399718
         case start_rsc:
399718
         case action_promote:
399718
-            /* This as an internally generated constraint exempt from
399718
-             * user constraint prohibitions, and this action isn't runnable
399718
-             * if the connection start isn't runnable.
399718
-             */
399718
-            order_opts = pe_order_preserve | pe_order_runnable_left;
399718
+            order_opts = pe_order_none;
399718
 
399718
             if (state == remote_state_failed) {
399718
                 /* Force recovery, by making this action required */
399718
@@ -2000,10 +2024,7 @@ apply_remote_ordering(action_t *action, pe_working_set_t *data_set)
399718
             }
399718
 
399718
             /* Ensure connection is up before running this action */
399718
-            custom_action_order(remote_rsc,
399718
-                                generate_op_key(remote_rsc->id, RSC_START, 0),
399718
-                                NULL, action->rsc, NULL, action, order_opts,
399718
-                                data_set);
399718
+            order_start_then_action(remote_rsc, action, order_opts, data_set);
399718
             break;
399718
 
399718
         case stop_rsc:
399718
@@ -2012,9 +2033,8 @@ apply_remote_ordering(action_t *action, pe_working_set_t *data_set)
399718
              */
399718
             if(state == remote_state_resting) {
399718
                 /* Wait for the connection resource to be up and assume everything is as we left it */
399718
-                custom_action_order(remote_rsc, generate_op_key(remote_rsc->id, RSC_START, 0), NULL,
399718
-                                    action->rsc, NULL, action,
399718
-                                    pe_order_preserve | pe_order_runnable_left, data_set);
399718
+                order_start_then_action(remote_rsc, action, pe_order_none,
399718
+                                        data_set);
399718
 
399718
             } else {
399718
                 if(state == remote_state_failed) {
399718
@@ -2026,9 +2046,8 @@ apply_remote_ordering(action_t *action, pe_working_set_t *data_set)
399718
                     pe_fence_node(data_set, action->node, "resources are active and the connection is unrecoverable");
399718
                 }
399718
 
399718
-                custom_action_order(action->rsc, NULL, action,
399718
-                                    remote_rsc, generate_op_key(remote_rsc->id, RSC_STOP, 0), NULL,
399718
-                                    pe_order_preserve | pe_order_implies_first, data_set);
399718
+                order_action_then_stop(action, remote_rsc,
399718
+                                       pe_order_implies_first, data_set);
399718
             }
399718
             break;
399718
 
399718
@@ -2038,9 +2057,8 @@ apply_remote_ordering(action_t *action, pe_working_set_t *data_set)
399718
              * blocked because the connection start would not be allowed.
399718
              */
399718
             if(state == remote_state_resting || state == remote_state_unknown) {
399718
-                custom_action_order(remote_rsc, generate_op_key(remote_rsc->id, RSC_START, 0), NULL,
399718
-                                    action->rsc, NULL, action,
399718
-                                    pe_order_preserve, data_set);
399718
+                order_start_then_action(remote_rsc, action, pe_order_none,
399718
+                                        data_set);
399718
             } /* Otherwise we can rely on the stop ordering */
399718
             break;
399718
 
399718
@@ -2051,9 +2069,8 @@ apply_remote_ordering(action_t *action, pe_working_set_t *data_set)
399718
                  * recurring monitors to be restarted, even if just
399718
                  * the connection was re-established
399718
                  */
399718
-                custom_action_order(remote_rsc, generate_op_key(remote_rsc->id, RSC_START, 0), NULL,
399718
-                                    action->rsc, NULL, action,
399718
-                                    pe_order_preserve | pe_order_runnable_left | pe_order_implies_then, data_set);
399718
+                order_start_then_action(remote_rsc, action,
399718
+                                        pe_order_implies_then, data_set);
399718
 
399718
             } else {
399718
                 if(task == monitor_rsc && state == remote_state_failed) {
399718
@@ -2073,14 +2090,12 @@ apply_remote_ordering(action_t *action, pe_working_set_t *data_set)
399718
                      * stopped _before_ we let the connection get
399718
                      * closed
399718
                      */
399718
-                    custom_action_order(action->rsc, NULL, action,
399718
-                                        remote_rsc, generate_op_key(remote_rsc->id, RSC_STOP, 0), NULL,
399718
-                                        pe_order_preserve | pe_order_runnable_left, data_set);
399718
+                    order_action_then_stop(action, remote_rsc,
399718
+                                           pe_order_runnable_left, data_set);
399718
 
399718
                 } else {
399718
-                    custom_action_order(remote_rsc, generate_op_key(remote_rsc->id, RSC_START, 0), NULL,
399718
-                                        action->rsc, NULL, action,
399718
-                                        pe_order_preserve | pe_order_runnable_left, data_set);
399718
+                    order_start_then_action(remote_rsc, action, pe_order_none,
399718
+                                            data_set);
399718
                 }
399718
             }
399718
             break;
399718
-- 
399718
1.8.3.1
399718