Blame SOURCES/005-shutdown-lock.patch

ed4e54
From 4bdda97ff76d0e682f4f58bc632cd2cbd417c423 Mon Sep 17 00:00:00 2001
ed4e54
From: Ken Gaillot <kgaillot@redhat.com>
ed4e54
Date: Tue, 14 Jan 2020 12:52:21 -0600
ed4e54
Subject: [PATCH 01/18] Log: controller: improve messages when deleting CIB
ed4e54
 resource history
ed4e54
ed4e54
This also moves delete_rsc_status() to controld_based.c and renames it.
ed4e54
---
ed4e54
 daemons/controld/controld_based.c | 71 +++++++++++++++++++++++++++++++++++++++
ed4e54
 daemons/controld/controld_execd.c | 47 +++++---------------------
ed4e54
 daemons/controld/controld_utils.h |  4 ++-
ed4e54
 3 files changed, 83 insertions(+), 39 deletions(-)
ed4e54
ed4e54
diff --git a/daemons/controld/controld_based.c b/daemons/controld/controld_based.c
ed4e54
index 42e321f..f3a7c4f 100644
ed4e54
--- a/daemons/controld/controld_based.c
ed4e54
+++ b/daemons/controld/controld_based.c
ed4e54
@@ -243,3 +243,74 @@ controld_delete_node_state(const char *uname, enum controld_section_e section,
ed4e54
     }
ed4e54
     free(xpath);
ed4e54
 }
ed4e54
+
ed4e54
+// Takes node name and resource ID
ed4e54
+#define XPATH_RESOURCE_HISTORY "//" XML_CIB_TAG_STATE                       \
ed4e54
+                               "[@" XML_ATTR_UNAME "='%s'] /"               \
ed4e54
+                               XML_CIB_TAG_LRM "/" XML_LRM_TAG_RESOURCES    \
ed4e54
+                               "/" XML_LRM_TAG_RESOURCE                     \
ed4e54
+                               "[@" XML_ATTR_ID "='%s']"
ed4e54
+// @TODO could add "and @XML_CONFIG_ATTR_SHUTDOWN_LOCK" to limit to locks
ed4e54
+
ed4e54
+/*!
ed4e54
+ * \internal
ed4e54
+ * \brief Clear resource history from CIB for a given resource and node
ed4e54
+ *
ed4e54
+ * \param[in]  rsc_id        ID of resource to be cleared
ed4e54
+ * \param[in]  node          Node whose resource history should be cleared
ed4e54
+ * \param[in]  user_name     ACL user name to use
ed4e54
+ * \param[in]  call_options  CIB call options
ed4e54
+ *
ed4e54
+ * \return Standard Pacemaker return code
ed4e54
+ */
ed4e54
+int
ed4e54
+controld_delete_resource_history(const char *rsc_id, const char *node,
ed4e54
+                                 const char *user_name, int call_options)
ed4e54
+{
ed4e54
+    char *desc = NULL;
ed4e54
+    char *xpath = NULL;
ed4e54
+    int rc = pcmk_rc_ok;
ed4e54
+
ed4e54
+    CRM_CHECK((rsc_id != NULL) && (node != NULL), return EINVAL);
ed4e54
+
ed4e54
+    desc = crm_strdup_printf("resource history for %s on %s", rsc_id, node);
ed4e54
+    if (fsa_cib_conn == NULL) {
ed4e54
+        crm_err("Unable to clear %s: no CIB connection", desc);
ed4e54
+        free(desc);
ed4e54
+        return ENOTCONN;
ed4e54
+    }
ed4e54
+
ed4e54
+    // Ask CIB to delete the entry
ed4e54
+    xpath = crm_strdup_printf(XPATH_RESOURCE_HISTORY, node, rsc_id);
ed4e54
+    rc = cib_internal_op(fsa_cib_conn, CIB_OP_DELETE, NULL, xpath, NULL,
ed4e54
+                         NULL, call_options|cib_xpath, user_name);
ed4e54
+
ed4e54
+    if (rc < 0) {
ed4e54
+        rc = pcmk_legacy2rc(rc);
ed4e54
+        crm_err("Could not delete resource status of %s on %s%s%s: %s "
ed4e54
+                CRM_XS " rc=%d", rsc_id, node,
ed4e54
+                (user_name? " for user " : ""), (user_name? user_name : ""),
ed4e54
+                pcmk_rc_str(rc), rc);
ed4e54
+        free(desc);
ed4e54
+        free(xpath);
ed4e54
+        return rc;
ed4e54
+    }
ed4e54
+
ed4e54
+    if (is_set(call_options, cib_sync_call)) {
ed4e54
+        if (is_set(call_options, cib_dryrun)) {
ed4e54
+            crm_debug("Deletion of %s would succeed", desc);
ed4e54
+        } else {
ed4e54
+            crm_debug("Deletion of %s succeeded", desc);
ed4e54
+        }
ed4e54
+        free(desc);
ed4e54
+
ed4e54
+    } else {
ed4e54
+        crm_info("Clearing %s (via CIB call %d) " CRM_XS " xpath=%s",
ed4e54
+                 desc, rc, xpath);
ed4e54
+        fsa_register_cib_callback(rc, FALSE, desc, cib_delete_callback);
ed4e54
+        // CIB library handles freeing desc
ed4e54
+    }
ed4e54
+
ed4e54
+    free(xpath);
ed4e54
+    return pcmk_rc_ok;
ed4e54
+}
ed4e54
diff --git a/daemons/controld/controld_execd.c b/daemons/controld/controld_execd.c
ed4e54
index 16751b9..212739e 100644
ed4e54
--- a/daemons/controld/controld_execd.c
ed4e54
+++ b/daemons/controld/controld_execd.c
ed4e54
@@ -36,8 +36,6 @@ struct delete_event_s {
ed4e54
 static gboolean is_rsc_active(lrm_state_t * lrm_state, const char *rsc_id);
ed4e54
 static gboolean build_active_RAs(lrm_state_t * lrm_state, xmlNode * rsc_list);
ed4e54
 static gboolean stop_recurring_actions(gpointer key, gpointer value, gpointer user_data);
ed4e54
-static int delete_rsc_status(lrm_state_t * lrm_state, const char *rsc_id, int call_options,
ed4e54
-                             const char *user_name);
ed4e54
 
ed4e54
 static lrmd_event_data_t *construct_op(lrm_state_t * lrm_state, xmlNode * rsc_op,
ed4e54
                                        const char *rsc_id, const char *operation);
ed4e54
@@ -169,7 +167,8 @@ update_history_cache(lrm_state_t * lrm_state, lrmd_rsc_info_t * rsc, lrmd_event_
ed4e54
 
ed4e54
     if (op->rsc_deleted) {
ed4e54
         crm_debug("Purged history for '%s' after %s", op->rsc_id, op->op_type);
ed4e54
-        delete_rsc_status(lrm_state, op->rsc_id, cib_quorum_override, NULL);
ed4e54
+        controld_delete_resource_history(op->rsc_id, lrm_state->node_name,
ed4e54
+                                         NULL, crmd_cib_smart_opt());
ed4e54
         return;
ed4e54
     }
ed4e54
 
ed4e54
@@ -917,31 +916,6 @@ lrm_remove_deleted_op(gpointer key, gpointer value, gpointer user_data)
ed4e54
     return FALSE;
ed4e54
 }
ed4e54
 
ed4e54
-/*
ed4e54
- * Remove the rsc from the CIB
ed4e54
- *
ed4e54
- * Avoids refreshing the entire LRM section of this host
ed4e54
- */
ed4e54
-#define RSC_TEMPLATE "//"XML_CIB_TAG_STATE"[@uname='%s']//"XML_LRM_TAG_RESOURCE"[@id='%s']"
ed4e54
-
ed4e54
-static int
ed4e54
-delete_rsc_status(lrm_state_t * lrm_state, const char *rsc_id, int call_options,
ed4e54
-                  const char *user_name)
ed4e54
-{
ed4e54
-    char *rsc_xpath = NULL;
ed4e54
-    int rc = pcmk_ok;
ed4e54
-
ed4e54
-    CRM_CHECK(rsc_id != NULL, return -ENXIO);
ed4e54
-
ed4e54
-    rsc_xpath = crm_strdup_printf(RSC_TEMPLATE, lrm_state->node_name, rsc_id);
ed4e54
-
ed4e54
-    rc = cib_internal_op(fsa_cib_conn, CIB_OP_DELETE, NULL, rsc_xpath,
ed4e54
-                         NULL, NULL, call_options | cib_xpath, user_name);
ed4e54
-
ed4e54
-    free(rsc_xpath);
ed4e54
-    return rc;
ed4e54
-}
ed4e54
-
ed4e54
 static void
ed4e54
 delete_rsc_entry(lrm_state_t * lrm_state, ha_msg_input_t * input, const char *rsc_id,
ed4e54
                  GHashTableIter * rsc_gIter, int rc, const char *user_name)
ed4e54
@@ -958,7 +932,8 @@ delete_rsc_entry(lrm_state_t * lrm_state, ha_msg_input_t * input, const char *rs
ed4e54
         else
ed4e54
             g_hash_table_remove(lrm_state->resource_history, rsc_id_copy);
ed4e54
         crm_debug("sync: Sending delete op for %s", rsc_id_copy);
ed4e54
-        delete_rsc_status(lrm_state, rsc_id_copy, cib_quorum_override, user_name);
ed4e54
+        controld_delete_resource_history(rsc_id_copy, lrm_state->node_name,
ed4e54
+                                         user_name, crmd_cib_smart_opt());
ed4e54
 
ed4e54
         g_hash_table_foreach_remove(lrm_state->pending_ops, lrm_remove_deleted_op, rsc_id_copy);
ed4e54
         free(rsc_id_copy);
ed4e54
@@ -1694,21 +1669,17 @@ do_lrm_delete(ha_msg_input_t *input, lrm_state_t *lrm_state,
ed4e54
     gboolean unregister = TRUE;
ed4e54
 
ed4e54
 #if ENABLE_ACL
ed4e54
-    int cib_rc = delete_rsc_status(lrm_state, rsc->id,
ed4e54
-                                   cib_dryrun|cib_sync_call, user_name);
ed4e54
+    int cib_rc = controld_delete_resource_history(rsc->id, lrm_state->node_name,
ed4e54
+                                                  user_name,
ed4e54
+                                                  cib_dryrun|cib_sync_call);
ed4e54
 
ed4e54
-    if (cib_rc != pcmk_ok) {
ed4e54
+    if (cib_rc != pcmk_rc_ok) {
ed4e54
         lrmd_event_data_t *op = NULL;
ed4e54
 
ed4e54
-        crm_err("Could not delete resource status of %s for %s (user %s) on %s: %s"
ed4e54
-                CRM_XS " rc=%d",
ed4e54
-                rsc->id, from_sys, (user_name? user_name : "unknown"),
ed4e54
-                from_host, pcmk_strerror(cib_rc), cib_rc);
ed4e54
-
ed4e54
         op = construct_op(lrm_state, input->xml, rsc->id, CRMD_ACTION_DELETE);
ed4e54
         op->op_status = PCMK_LRM_OP_ERROR;
ed4e54
 
ed4e54
-        if (cib_rc == -EACCES) {
ed4e54
+        if (cib_rc == EACCES) {
ed4e54
             op->rc = PCMK_OCF_INSUFFICIENT_PRIV;
ed4e54
         } else {
ed4e54
             op->rc = PCMK_OCF_UNKNOWN_ERROR;
ed4e54
diff --git a/daemons/controld/controld_utils.h b/daemons/controld/controld_utils.h
ed4e54
index f902361..ca8cddb 100644
ed4e54
--- a/daemons/controld/controld_utils.h
ed4e54
+++ b/daemons/controld/controld_utils.h
ed4e54
@@ -1,5 +1,5 @@
ed4e54
 /*
ed4e54
- * Copyright 2004-2019 the Pacemaker project contributors
ed4e54
+ * Copyright 2004-2020 the Pacemaker project contributors
ed4e54
  *
ed4e54
  * The version control history for this file may have further details.
ed4e54
  *
ed4e54
@@ -95,6 +95,8 @@ enum controld_section_e {
ed4e54
 
ed4e54
 void controld_delete_node_state(const char *uname,
ed4e54
                                 enum controld_section_e section, int options);
ed4e54
+int controld_delete_resource_history(const char *rsc_id, const char *node,
ed4e54
+                                     const char *user_name, int call_options);
ed4e54
 
ed4e54
 const char *get_node_id(xmlNode *lrm_rsc_op);
ed4e54
 
ed4e54
-- 
ed4e54
1.8.3.1
ed4e54