File bsc#1182313-0002-Low-scheduler-unknown_on_node-should-ignore-pending-.patch of Package pacemaker.32860
From 93f6f524f1a3d769381009eacc671e3e8575fb28 Mon Sep 17 00:00:00 2001
From: Ken Gaillot <kgaillot@redhat.com>
Date: Thu, 2 Feb 2023 10:25:53 -0600
Subject: [PATCH 2/5] Low: scheduler: unknown_on_node() should ignore pending
actions
Previously, unknown_on_node() looked for any lrm_rsc_op at all to decide
whether a resource is known on a node. However if the only action is pending,
the resource is not yet known.
Also drop a redundant argument and add a doxygen block. (The rsc argument is
not const due to a getDocPtr() call in the chain, as well as libxml2 calls that
are likely const in practice but aren't marked as such.)
---
lib/pengine/unpack.c | 37 +++++++++++++++++++++++++------------
1 file changed, 25 insertions(+), 12 deletions(-)
diff --git a/lib/pengine/unpack.c b/lib/pengine/unpack.c
index 2aec59a2d..acd97e8da 100644
--- a/lib/pengine/unpack.c
+++ b/lib/pengine/unpack.c
@@ -2655,19 +2655,32 @@ find_lrm_resource(const char *rsc_id, const char *node_name,
return xml;
}
+/*!
+ * \internal
+ * \brief Check whether a resource has no completed action history on a node
+ *
+ * \param[in,out] rsc Resource to check
+ * \param[in] node_name Node to check
+ *
+ * \return true if \p rsc_id is unknown on \p node_name, otherwise false
+ */
static bool
-unknown_on_node(const char *rsc_id, const char *node_name,
- pe_working_set_t *data_set)
+unknown_on_node(pe_resource_t *rsc, const char *node_name)
{
- xmlNode *lrm_resource = NULL;
-
- lrm_resource = find_lrm_resource(rsc_id, node_name, data_set);
+ bool result = false;
+ xmlXPathObjectPtr search;
+ GString *xpath = g_string_sized_new(256);
- /* If the resource has no lrm_rsc_op history on the node, that means its
- * state is unknown there.
- */
- return (lrm_resource == NULL
- || first_named_child(lrm_resource, XML_LRM_TAG_RSC_OP) == NULL);
+ pcmk__g_strcat(xpath,
+ XPATH_NODE_STATE "[@" XML_ATTR_UNAME "='", node_name, "']"
+ SUB_XPATH_LRM_RESOURCE "[@" XML_ATTR_ID "='", rsc->id, "']"
+ SUB_XPATH_LRM_RSC_OP "[@" XML_LRM_ATTR_RC "!='193']",
+ NULL);
+ search = xpath_search(rsc->cluster->input, (const char *) xpath->str);
+ result = (numXpathResults(search) == 0);
+ freeXpathObject(search);
+ g_string_free(xpath, TRUE);
+ return result;
}
/*!
@@ -3038,7 +3051,7 @@ unpack_migrate_to_failure(pe_resource_t *rsc, const pe_node_t *node,
* Don't just consider it running there. We will get back here anyway in
* case the probe detects it's running there.
*/
- !unknown_on_node(rsc->id, target, data_set)
+ !unknown_on_node(rsc, target)
/* If the resource has newer state on the target after the migration
* events, this migrate_to no longer matters for the target.
*/
@@ -3094,7 +3107,7 @@ unpack_migrate_from_failure(pe_resource_t *rsc, const pe_node_t *node,
* Don't just consider it running there. We will get back here anyway in
* case the probe detects it's running there.
*/
- !unknown_on_node(rsc->id, source, data_set)
+ !unknown_on_node(rsc, source)
/* If the resource has newer state on the source after the migration
* events, this migrate_from no longer matters for the source.
*/
--
2.35.3