Blame SOURCES/019-shutdown-lock.patch

308170
From cf1e90ffe764f3639799206db9444ae32821386b Mon Sep 17 00:00:00 2001
308170
From: Ken Gaillot <kgaillot@redhat.com>
308170
Date: Fri, 10 Jan 2020 18:18:07 -0600
308170
Subject: [PATCH 15/18] Low: scheduler: clear resource history when appropriate
308170
308170
Tell the controller to clear resource history from the CIB when a resource has
308170
a shutdown lock that expired or was cancelled because the resource is already
308170
active elsewhere.
308170
---
308170
 include/crm/pengine/internal.h      |  4 +++-
308170
 include/crm/pengine/pe_types.h      |  4 +++-
308170
 lib/pacemaker/pcmk_sched_allocate.c |  1 +
308170
 lib/pacemaker/pcmk_sched_graph.c    | 16 ++++++++++++++--
308170
 lib/pacemaker/pcmk_sched_native.c   |  6 ++++++
308170
 lib/pengine/unpack.c                |  1 +
308170
 lib/pengine/utils.c                 | 34 ++++++++++++++++++++++++++++++++--
308170
 7 files changed, 60 insertions(+), 6 deletions(-)
308170
308170
diff --git a/include/crm/pengine/internal.h b/include/crm/pengine/internal.h
308170
index 119624d..bc2c70e 100644
308170
--- a/include/crm/pengine/internal.h
308170
+++ b/include/crm/pengine/internal.h
308170
@@ -1,5 +1,5 @@
308170
 /*
308170
- * Copyright 2004-2019 the Pacemaker project contributors
308170
+ * Copyright 2004-2020 the Pacemaker project contributors
308170
  *
308170
  * The version control history for this file may have further details.
308170
  *
308170
@@ -435,5 +435,7 @@ void pe__unpack_dataset_nvpairs(xmlNode *xml_obj, const char *set_name,
308170
                                 pe_working_set_t *data_set);
308170
 
308170
 bool pe__resource_is_disabled(pe_resource_t *rsc);
308170
+pe_action_t *pe__clear_resource_history(pe_resource_t *rsc, pe_node_t *node,
308170
+                                        pe_working_set_t *data_set);
308170
 
308170
 #endif
308170
diff --git a/include/crm/pengine/pe_types.h b/include/crm/pengine/pe_types.h
308170
index 123d8ef..572787b 100644
308170
--- a/include/crm/pengine/pe_types.h
308170
+++ b/include/crm/pengine/pe_types.h
308170
@@ -1,5 +1,5 @@
308170
 /*
308170
- * Copyright 2004-2019 the Pacemaker project contributors
308170
+ * Copyright 2004-2020 the Pacemaker project contributors
308170
  *
308170
  * The version control history for this file may have further details.
308170
  *
308170
@@ -287,6 +287,8 @@ enum pe_action_flags {
308170
     pe_action_reschedule = 0x02000,
308170
     pe_action_tracking = 0x04000,
308170
     pe_action_dedup = 0x08000, //! Internal state tracking when creating graph
308170
+
308170
+    pe_action_dc = 0x10000,         //! Action may run on DC instead of target
308170
 };
308170
 /* *INDENT-ON* */
308170
 
308170
diff --git a/lib/pacemaker/pcmk_sched_allocate.c b/lib/pacemaker/pcmk_sched_allocate.c
308170
index 884e1bd..195d055 100644
308170
--- a/lib/pacemaker/pcmk_sched_allocate.c
308170
+++ b/lib/pacemaker/pcmk_sched_allocate.c
308170
@@ -1026,6 +1026,7 @@ apply_shutdown_lock(pe_resource_t *rsc, pe_working_set_t *data_set)
308170
             pe_rsc_info(rsc,
308170
                         "Cancelling shutdown lock because %s is already active",
308170
                         rsc->id);
308170
+            pe__clear_resource_history(rsc, rsc->lock_node, data_set);
308170
             rsc->lock_node = NULL;
308170
             rsc->lock_time = 0;
308170
         }
308170
diff --git a/lib/pacemaker/pcmk_sched_graph.c b/lib/pacemaker/pcmk_sched_graph.c
308170
index 2861f3d..355ffca 100644
308170
--- a/lib/pacemaker/pcmk_sched_graph.c
308170
+++ b/lib/pacemaker/pcmk_sched_graph.c
308170
@@ -586,10 +586,11 @@ update_action(pe_action_t *then, pe_working_set_t *data_set)
308170
 
308170
             /* 'then' is required, so we must abandon 'first'
308170
              * (e.g. a required stop cancels any reload).
308170
-             * Only used with reload actions as 'first'.
308170
              */
308170
             set_bit(other->action->flags, pe_action_optional);
308170
-            clear_bit(first->rsc->flags, pe_rsc_reload);
308170
+            if (!strcmp(first->task, CRMD_ACTION_RELOAD)) {
308170
+                clear_bit(first->rsc->flags, pe_rsc_reload);
308170
+            }
308170
         }
308170
 
308170
         if (first->rsc && then->rsc && (first->rsc != then->rsc)
308170
@@ -1039,6 +1040,11 @@ action2xml(action_t * action, gboolean as_input, pe_working_set_t *data_set)
308170
     } else if (safe_str_eq(action->task, CRM_OP_LRM_REFRESH)) {
308170
         action_xml = create_xml_node(NULL, XML_GRAPH_TAG_CRM_EVENT);
308170
 
308170
+    } else if (safe_str_eq(action->task, CRM_OP_LRM_DELETE)) {
308170
+        // CIB-only clean-up for shutdown locks
308170
+        action_xml = create_xml_node(NULL, XML_GRAPH_TAG_CRM_EVENT);
308170
+        crm_xml_add(action_xml, PCMK__XA_MODE, XML_TAG_CIB);
308170
+
308170
 /* 	} else if(safe_str_eq(action->task, RSC_PROBED)) { */
308170
 /* 		action_xml = create_xml_node(NULL, XML_GRAPH_TAG_CRM_EVENT); */
308170
 
308170
@@ -1051,6 +1057,7 @@ action2xml(action_t * action, gboolean as_input, pe_working_set_t *data_set)
308170
 
308170
     } else {
308170
         action_xml = create_xml_node(NULL, XML_GRAPH_TAG_RSC_OP);
308170
+
308170
 #if ENABLE_VERSIONED_ATTRS
308170
         rsc_details = pe_rsc_action_details(action);
308170
 #endif
308170
@@ -1392,6 +1399,11 @@ should_dump_action(pe_action_t *action)
308170
         log_action(LOG_DEBUG, "Unallocated action", action, false);
308170
         return false;
308170
 
308170
+    } else if (is_set(action->flags, pe_action_dc)) {
308170
+        crm_trace("Action %s (%d) should be dumped: "
308170
+                  "can run on DC instead of %s",
308170
+                  action->uuid, action->id, action->node->details->uname);
308170
+
308170
     } else if (pe__is_guest_node(action->node)
308170
                && !action->node->details->remote_requires_reset) {
308170
         crm_trace("Action %s (%d) should be dumped: "
308170
diff --git a/lib/pacemaker/pcmk_sched_native.c b/lib/pacemaker/pcmk_sched_native.c
308170
index 9ebdd35..714a7a0 100644
308170
--- a/lib/pacemaker/pcmk_sched_native.c
308170
+++ b/lib/pacemaker/pcmk_sched_native.c
308170
@@ -1403,6 +1403,12 @@ native_internal_constraints(resource_t * rsc, pe_working_set_t * data_set)
308170
                             pe_order_runnable_left, data_set);
308170
     }
308170
 
308170
+    // Don't clear resource history if probing on same node
308170
+    custom_action_order(rsc, generate_op_key(rsc->id, CRM_OP_LRM_DELETE, 0),
308170
+                        NULL, rsc, generate_op_key(rsc->id, RSC_STATUS, 0),
308170
+                        NULL, pe_order_same_node|pe_order_then_cancels_first,
308170
+                        data_set);
308170
+
308170
     // Certain checks need allowed nodes
308170
     if (check_unfencing || check_utilization || rsc->container) {
308170
         allowed_nodes = allowed_nodes_as_list(rsc, data_set);
308170
diff --git a/lib/pengine/unpack.c b/lib/pengine/unpack.c
308170
index 5139e60..87edc83 100644
308170
--- a/lib/pengine/unpack.c
308170
+++ b/lib/pengine/unpack.c
308170
@@ -2218,6 +2218,7 @@ unpack_shutdown_lock(xmlNode *rsc_entry, pe_resource_t *rsc, pe_node_t *node,
308170
                 > (lock_time + data_set->shutdown_lock))) {
308170
             pe_rsc_info(rsc, "Shutdown lock for %s on %s expired",
308170
                         rsc->id, node->details->uname);
308170
+            pe__clear_resource_history(rsc, node, data_set);
308170
         } else {
308170
             rsc->lock_node = node;
308170
             rsc->lock_time = lock_time;
308170
diff --git a/lib/pengine/utils.c b/lib/pengine/utils.c
308170
index 586d92c..b61455d 100644
308170
--- a/lib/pengine/utils.c
308170
+++ b/lib/pengine/utils.c
308170
@@ -520,6 +520,11 @@ custom_action(resource_t * rsc, char *key, const char *task,
308170
         }
308170
         action->uuid = strdup(key);
308170
 
308170
+        if (safe_str_eq(task, CRM_OP_LRM_DELETE)) {
308170
+            // Resource history deletion for a node can be done on the DC
308170
+            pe_set_action_bit(action, pe_action_dc);
308170
+        }
308170
+
308170
         pe_set_action_bit(action, pe_action_runnable);
308170
         if (optional) {
308170
             pe_set_action_bit(action, pe_action_optional);
308170
@@ -588,7 +593,8 @@ custom_action(resource_t * rsc, char *key, const char *task,
308170
             pe_set_action_bit(action, pe_action_optional);
308170
 /*   			action->runnable = FALSE; */
308170
 
308170
-        } else if (action->node->details->online == FALSE
308170
+        } else if (is_not_set(action->flags, pe_action_dc)
308170
+                   && !(action->node->details->online)
308170
                    && (!pe__is_guest_node(action->node)
308170
                        || action->node->details->remote_requires_reset)) {
308170
             pe_clear_action_bit(action, pe_action_runnable);
308170
@@ -600,7 +606,8 @@ custom_action(resource_t * rsc, char *key, const char *task,
308170
                 pe_fence_node(data_set, action->node, "resource actions are unrunnable");
308170
             }
308170
 
308170
-        } else if (action->node->details->pending) {
308170
+        } else if (is_not_set(action->flags, pe_action_dc)
308170
+                   && action->node->details->pending) {
308170
             pe_clear_action_bit(action, pe_action_runnable);
308170
             do_crm_log(warn_level, "Action %s on %s is unrunnable (pending)",
308170
                        action->uuid, action->node->details->uname);
308170
@@ -714,6 +721,8 @@ unpack_operation_on_fail(action_t * action)
308170
 
308170
             value = on_fail;
308170
         }
308170
+    } else if (safe_str_eq(action->task, CRM_OP_LRM_DELETE)) {
308170
+        value = "ignore";
308170
     }
308170
 
308170
     return value;
308170
@@ -2595,3 +2604,24 @@ pe__resource_is_disabled(pe_resource_t *rsc)
308170
     }
308170
     return false;
308170
 }
308170
+
308170
+/*!
308170
+ * \internal
308170
+ * \brief Create an action to clear a resource's history from CIB
308170
+ *
308170
+ * \param[in] rsc   Resource to clear
308170
+ * \param[in] node  Node to clear history on
308170
+ *
308170
+ * \return New action to clear resource history
308170
+ */
308170
+pe_action_t *
308170
+pe__clear_resource_history(pe_resource_t *rsc, pe_node_t *node,
308170
+                           pe_working_set_t *data_set)
308170
+{
308170
+    char *key = NULL;
308170
+
308170
+    CRM_ASSERT(rsc && node);
308170
+    key = generate_op_key(rsc->id, CRM_OP_LRM_DELETE, 0);
308170
+    return custom_action(rsc, key, CRM_OP_LRM_DELETE, node, FALSE, TRUE,
308170
+                         data_set);
308170
+}
308170
-- 
308170
1.8.3.1
308170