af918f
From abbfc0ba9afb6c2d1ce54fea2d0cf25ce1d9108a Mon Sep 17 00:00:00 2001
af918f
From: Ken Gaillot <kgaillot@redhat.com>
af918f
Date: Fri, 10 Jan 2020 18:18:07 -0600
af918f
Subject: [PATCH 10/10] Low: scheduler: clear resource history when appropriate
af918f
af918f
Tell the controller to clear resource history from the CIB when a resource has
af918f
a shutdown lock that expired or was cancelled because the resource is already
af918f
active elsewhere.
af918f
---
af918f
 include/crm/pengine/internal.h |  6 +++++-
af918f
 include/crm/pengine/status.h   |  6 +++++-
af918f
 lib/pengine/unpack.c           |  1 +
af918f
 lib/pengine/utils.c            | 34 ++++++++++++++++++++++++++++++++--
af918f
 pengine/allocate.c             |  1 +
af918f
 pengine/graph.c                | 16 ++++++++++++++--
af918f
 pengine/native.c               |  6 ++++++
af918f
 7 files changed, 64 insertions(+), 6 deletions(-)
af918f
af918f
diff --git a/include/crm/pengine/internal.h b/include/crm/pengine/internal.h
af918f
index fc908e8..64b9a50 100644
af918f
--- a/include/crm/pengine/internal.h
af918f
+++ b/include/crm/pengine/internal.h
af918f
@@ -1,5 +1,7 @@
af918f
 /*
af918f
- * Copyright 2004-2019 Andrew Beekhof <andrew@beekhof.net>
af918f
+ * Copyright 2004-2020 the Pacemaker project contributors
af918f
+ *
af918f
+ * The version control history for this file may have further details.
af918f
  *
af918f
  * This source code is licensed under the GNU Lesser General Public License
af918f
  * version 2.1 or later (LGPLv2.1+) WITHOUT ANY WARRANTY.
af918f
@@ -366,4 +368,7 @@ void pe__free_param_checks(pe_working_set_t *data_set);
af918f
 bool pe__shutdown_requested(pe_node_t *node);
f0d7ba
 bool pe__resource_is_disabled(pe_resource_t *rsc);
f0d7ba
 
af918f
+pe_action_t *pe__clear_resource_history(pe_resource_t *rsc, pe_node_t *node,
af918f
+                                        pe_working_set_t *data_set);
af918f
+
af918f
 #endif
af918f
diff --git a/include/crm/pengine/status.h b/include/crm/pengine/status.h
af918f
index 1e8d5bb..9f9fd3b 100644
af918f
--- a/include/crm/pengine/status.h
af918f
+++ b/include/crm/pengine/status.h
af918f
@@ -1,5 +1,7 @@
af918f
 /*
af918f
- * Copyright (C) 2004 Andrew Beekhof <andrew@beekhof.net>
af918f
+ * Copyright 2004-2020 the Pacemaker project contributors
af918f
+ *
af918f
+ * The version control history for this file may have further details.
af918f
  *
af918f
  * This program is free software; you can redistribute it and/or
af918f
  * modify it under the terms of the GNU Lesser General Public
af918f
@@ -280,6 +282,8 @@ enum pe_action_flags {
af918f
 
af918f
     pe_action_reschedule = 0x02000,
af918f
     pe_action_tracking = 0x04000,
af918f
+
af918f
+    pe_action_dc = 0x10000,         //! Action may run on DC instead of target
af918f
 };
af918f
 /* *INDENT-ON* */
af918f
 
af918f
diff --git a/lib/pengine/unpack.c b/lib/pengine/unpack.c
af918f
index bb5efa4..9deff67 100644
af918f
--- a/lib/pengine/unpack.c
af918f
+++ b/lib/pengine/unpack.c
af918f
@@ -2306,6 +2306,7 @@ unpack_shutdown_lock(xmlNode *rsc_entry, pe_resource_t *rsc, pe_node_t *node,
af918f
                 > (lock_time + data_set->shutdown_lock))) {
af918f
             pe_rsc_info(rsc, "Shutdown lock for %s on %s expired",
af918f
                         rsc->id, node->details->uname);
af918f
+            pe__clear_resource_history(rsc, node, data_set);
af918f
         } else {
af918f
             rsc->lock_node = node;
af918f
             rsc->lock_time = lock_time;
af918f
diff --git a/lib/pengine/utils.c b/lib/pengine/utils.c
af918f
index c336e37..84d3399 100644
af918f
--- a/lib/pengine/utils.c
af918f
+++ b/lib/pengine/utils.c
af918f
@@ -490,6 +490,11 @@ custom_action(resource_t * rsc, char *key, const char *task,
af918f
         }
af918f
         action->uuid = strdup(key);
af918f
 
af918f
+        if (safe_str_eq(task, CRM_OP_LRM_DELETE)) {
af918f
+            // Resource history deletion for a node can be done on the DC
af918f
+            pe_set_action_bit(action, pe_action_dc);
af918f
+        }
af918f
+
af918f
         pe_set_action_bit(action, pe_action_runnable);
af918f
         if (optional) {
af918f
             pe_rsc_trace(rsc, "Set optional on %s", action->uuid);
af918f
@@ -570,7 +575,8 @@ custom_action(resource_t * rsc, char *key, const char *task,
af918f
             pe_set_action_bit(action, pe_action_optional);
af918f
 /*   			action->runnable = FALSE; */
af918f
 
af918f
-        } else if (action->node->details->online == FALSE
af918f
+        } else if (is_not_set(action->flags, pe_action_dc)
af918f
+                   && !(action->node->details->online)
af918f
                    && (!is_container_remote_node(action->node) || action->node->details->remote_requires_reset)) {
af918f
             pe_clear_action_bit(action, pe_action_runnable);
af918f
             do_crm_log(warn_level, "Action %s on %s is unrunnable (offline)",
af918f
@@ -581,7 +587,8 @@ custom_action(resource_t * rsc, char *key, const char *task,
f0d7ba
                 pe_fence_node(data_set, action->node, "resource actions are unrunnable", FALSE);
af918f
             }
af918f
 
af918f
-        } else if (action->node->details->pending) {
af918f
+        } else if (is_not_set(action->flags, pe_action_dc)
af918f
+                   && action->node->details->pending) {
af918f
             pe_clear_action_bit(action, pe_action_runnable);
af918f
             do_crm_log(warn_level, "Action %s on %s is unrunnable (pending)",
af918f
                        action->uuid, action->node->details->uname);
af918f
@@ -695,6 +702,8 @@ unpack_operation_on_fail(action_t * action)
af918f
 
af918f
             value = on_fail;
af918f
         }
af918f
+    } else if (safe_str_eq(action->task, CRM_OP_LRM_DELETE)) {
af918f
+        value = "ignore";
af918f
     }
af918f
 
af918f
     return value;
f0d7ba
@@ -2566,3 +2575,24 @@ pe__resource_is_disabled(pe_resource_t *rsc)
f0d7ba
     }
f0d7ba
     return false;
af918f
 }
af918f
+
af918f
+/*!
af918f
+ * \internal
af918f
+ * \brief Create an action to clear a resource's history from CIB
af918f
+ *
af918f
+ * \param[in] rsc   Resource to clear
af918f
+ * \param[in] node  Node to clear history on
af918f
+ *
af918f
+ * \return New action to clear resource history
af918f
+ */
af918f
+pe_action_t *
af918f
+pe__clear_resource_history(pe_resource_t *rsc, pe_node_t *node,
af918f
+                           pe_working_set_t *data_set)
af918f
+{
af918f
+    char *key = NULL;
af918f
+
af918f
+    CRM_ASSERT(rsc && node);
af918f
+    key = generate_op_key(rsc->id, CRM_OP_LRM_DELETE, 0);
af918f
+    return custom_action(rsc, key, CRM_OP_LRM_DELETE, node, FALSE, TRUE,
af918f
+                         data_set);
af918f
+}
af918f
diff --git a/pengine/allocate.c b/pengine/allocate.c
af918f
index 7366716..946f063 100644
af918f
--- a/pengine/allocate.c
af918f
+++ b/pengine/allocate.c
af918f
@@ -1058,6 +1058,7 @@ apply_shutdown_lock(pe_resource_t *rsc, pe_working_set_t *data_set)
af918f
             pe_rsc_info(rsc,
af918f
                         "Cancelling shutdown lock because %s is already active",
af918f
                         rsc->id);
af918f
+            pe__clear_resource_history(rsc, rsc->lock_node, data_set);
af918f
             rsc->lock_node = NULL;
af918f
             rsc->lock_time = 0;
af918f
         }
af918f
diff --git a/pengine/graph.c b/pengine/graph.c
af918f
index 33168ca..a045549 100644
af918f
--- a/pengine/graph.c
af918f
+++ b/pengine/graph.c
af918f
@@ -596,10 +596,11 @@ update_action(action_t * then)
af918f
 
af918f
             /* 'then' is required, so we must abandon 'first'
af918f
              * (e.g. a required stop cancels any reload).
af918f
-             * Only used with reload actions as 'first'.
af918f
              */
af918f
             set_bit(other->action->flags, pe_action_optional);
af918f
-            clear_bit(first->rsc->flags, pe_rsc_reload);
af918f
+            if (!strcmp(first->task, CRMD_ACTION_RELOAD)) {
af918f
+                clear_bit(first->rsc->flags, pe_rsc_reload);
af918f
+            }
af918f
         }
af918f
 
af918f
         if (first->rsc && then->rsc && (first->rsc != then->rsc)
af918f
@@ -1051,6 +1052,11 @@ action2xml(action_t * action, gboolean as_input, pe_working_set_t *data_set)
af918f
     } else if (safe_str_eq(action->task, CRM_OP_LRM_REFRESH)) {
af918f
         action_xml = create_xml_node(NULL, XML_GRAPH_TAG_CRM_EVENT);
af918f
 
af918f
+    } else if (safe_str_eq(action->task, CRM_OP_LRM_DELETE)) {
af918f
+        // CIB-only clean-up for shutdown locks
af918f
+        action_xml = create_xml_node(NULL, XML_GRAPH_TAG_CRM_EVENT);
af918f
+        crm_xml_add(action_xml, PCMK__XA_MODE, XML_TAG_CIB);
af918f
+
af918f
 /* 	} else if(safe_str_eq(action->task, RSC_PROBED)) { */
af918f
 /* 		action_xml = create_xml_node(NULL, XML_GRAPH_TAG_CRM_EVENT); */
af918f
 
af918f
@@ -1063,6 +1069,7 @@ action2xml(action_t * action, gboolean as_input, pe_working_set_t *data_set)
af918f
 
af918f
     } else {
af918f
         action_xml = create_xml_node(NULL, XML_GRAPH_TAG_RSC_OP);
af918f
+
af918f
 #if ENABLE_VERSIONED_ATTRS
af918f
         rsc_details = pe_rsc_action_details(action);
af918f
 #endif
af918f
@@ -1404,6 +1411,11 @@ should_dump_action(action_t * action)
af918f
         log_action(LOG_DEBUG, "Unallocated action", action, FALSE);
af918f
         return FALSE;
af918f
 
af918f
+    } else if (is_set(action->flags, pe_action_dc)) {
af918f
+        crm_trace("Action %s (%d) should be dumped: "
af918f
+                  "can run on DC instead of %s",
af918f
+                  action->uuid, action->id, action->node->details->uname);
af918f
+
af918f
     } else if(is_container_remote_node(action->node) && action->node->details->remote_requires_reset == FALSE) {
af918f
         crm_trace("Assuming action %s for %s will be runnable", action->uuid, action->node->details->uname);
af918f
 
af918f
diff --git a/pengine/native.c b/pengine/native.c
af918f
index 1abaf29..b639fae 100644
af918f
--- a/pengine/native.c
af918f
+++ b/pengine/native.c
af918f
@@ -1439,6 +1439,12 @@ native_internal_constraints(resource_t * rsc, pe_working_set_t * data_set)
af918f
                             pe_order_runnable_left, data_set);
af918f
     }
af918f
 
af918f
+    // Don't clear resource history if probing on same node
af918f
+    custom_action_order(rsc, generate_op_key(rsc->id, CRM_OP_LRM_DELETE, 0),
af918f
+                        NULL, rsc, generate_op_key(rsc->id, RSC_STATUS, 0),
af918f
+                        NULL, pe_order_same_node|pe_order_then_cancels_first,
af918f
+                        data_set);
af918f
+
af918f
     // Certain checks need allowed nodes
af918f
     if (check_unfencing || check_utilization || rsc->container) {
af918f
         allowed_nodes = allowed_nodes_as_list(rsc, data_set);
af918f
-- 
af918f
1.8.3.1
af918f