Blame SOURCES/001-sync-points.patch

45cd8f
From de05f6b52c667155d262ceeb541dc1041d079d71 Mon Sep 17 00:00:00 2001
45cd8f
From: Chris Lumens <clumens@redhat.com>
45cd8f
Date: Thu, 8 Sep 2022 11:36:58 -0400
45cd8f
Subject: [PATCH 01/26] Refactor: tools: Use a uint32_t for attr_options.
45cd8f
45cd8f
---
45cd8f
 tools/attrd_updater.c | 2 +-
45cd8f
 1 file changed, 1 insertion(+), 1 deletion(-)
45cd8f
45cd8f
diff --git a/tools/attrd_updater.c b/tools/attrd_updater.c
45cd8f
index d90567a..b85a281 100644
45cd8f
--- a/tools/attrd_updater.c
45cd8f
+++ b/tools/attrd_updater.c
45cd8f
@@ -47,7 +47,7 @@ struct {
45cd8f
     gchar *attr_node;
45cd8f
     gchar *attr_set;
45cd8f
     char *attr_value;
45cd8f
-    int attr_options;
45cd8f
+    uint32_t attr_options;
45cd8f
     gboolean query_all;
45cd8f
     gboolean quiet;
45cd8f
 } options = {
45cd8f
-- 
45cd8f
2.31.1
45cd8f
45cd8f
From c6637520b474d44553ade52c0dbe9e36e873135f Mon Sep 17 00:00:00 2001
45cd8f
From: Chris Lumens <clumens@redhat.com>
45cd8f
Date: Fri, 21 Oct 2022 14:31:16 -0400
45cd8f
Subject: [PATCH 02/26] Refactor: libcrmcommon: Make pcmk__xe_match more
45cd8f
 broadly useful.
45cd8f
45cd8f
If attr_v is NULL, simply return the first node with a matching name.
45cd8f
---
45cd8f
 lib/common/xml.c | 10 ++++++----
45cd8f
 1 file changed, 6 insertions(+), 4 deletions(-)
45cd8f
45cd8f
diff --git a/lib/common/xml.c b/lib/common/xml.c
45cd8f
index 036dd87..ac6f46a 100644
45cd8f
--- a/lib/common/xml.c
45cd8f
+++ b/lib/common/xml.c
45cd8f
@@ -510,7 +510,7 @@ find_xml_node(const xmlNode *root, const char *search_path, gboolean must_find)
45cd8f
  * \param[in] parent     XML element to search
45cd8f
  * \param[in] node_name  If not NULL, only match children of this type
45cd8f
  * \param[in] attr_n     If not NULL, only match children with an attribute
45cd8f
- *                       of this name and a value of \p attr_v
45cd8f
+ *                       of this name.
45cd8f
  * \param[in] attr_v     If \p attr_n and this are not NULL, only match children
45cd8f
  *                       with an attribute named \p attr_n and this value
45cd8f
  *
45cd8f
@@ -520,14 +520,16 @@ xmlNode *
45cd8f
 pcmk__xe_match(const xmlNode *parent, const char *node_name,
45cd8f
                const char *attr_n, const char *attr_v)
45cd8f
 {
45cd8f
-    /* ensure attr_v specified when attr_n is */
45cd8f
-    CRM_CHECK(attr_n == NULL || attr_v != NULL, return NULL);
45cd8f
+    CRM_CHECK(parent != NULL, return NULL);
45cd8f
+    CRM_CHECK(attr_v == NULL || attr_n != NULL, return NULL);
45cd8f
 
45cd8f
     for (xmlNode *child = pcmk__xml_first_child(parent); child != NULL;
45cd8f
          child = pcmk__xml_next(child)) {
45cd8f
         if (pcmk__str_eq(node_name, (const char *) (child->name),
45cd8f
                          pcmk__str_null_matches)
45cd8f
-            && ((attr_n == NULL) || attr_matches(child, attr_n, attr_v))) {
45cd8f
+            && ((attr_n == NULL) ||
45cd8f
+                (attr_v == NULL && xmlHasProp(child, (pcmkXmlStr) attr_n)) ||
45cd8f
+                (attr_v != NULL && attr_matches(child, attr_n, attr_v)))) {
45cd8f
             return child;
45cd8f
         }
45cd8f
     }
45cd8f
-- 
45cd8f
2.31.1
45cd8f
45cd8f
From dd520579484c6ec091f7fbb550347941302dad0e Mon Sep 17 00:00:00 2001
45cd8f
From: Chris Lumens <clumens@redhat.com>
45cd8f
Date: Fri, 21 Oct 2022 14:32:46 -0400
45cd8f
Subject: [PATCH 03/26] Tests: libcrmcommon: Add tests for pcmk__xe_match.
45cd8f
45cd8f
---
45cd8f
 lib/common/tests/xml/Makefile.am           |   3 +-
45cd8f
 lib/common/tests/xml/pcmk__xe_match_test.c | 105 +++++++++++++++++++++
45cd8f
 2 files changed, 107 insertions(+), 1 deletion(-)
45cd8f
 create mode 100644 lib/common/tests/xml/pcmk__xe_match_test.c
45cd8f
45cd8f
diff --git a/lib/common/tests/xml/Makefile.am b/lib/common/tests/xml/Makefile.am
45cd8f
index 342ca07..0ccdcc3 100644
45cd8f
--- a/lib/common/tests/xml/Makefile.am
45cd8f
+++ b/lib/common/tests/xml/Makefile.am
45cd8f
@@ -11,6 +11,7 @@ include $(top_srcdir)/mk/tap.mk
45cd8f
 include $(top_srcdir)/mk/unittest.mk
45cd8f
 
45cd8f
 # Add "_test" to the end of all test program names to simplify .gitignore.
45cd8f
-check_PROGRAMS =	pcmk__xe_foreach_child_test
45cd8f
+check_PROGRAMS =	pcmk__xe_foreach_child_test \
45cd8f
+					pcmk__xe_match_test
45cd8f
 
45cd8f
 TESTS = $(check_PROGRAMS)
45cd8f
diff --git a/lib/common/tests/xml/pcmk__xe_match_test.c b/lib/common/tests/xml/pcmk__xe_match_test.c
45cd8f
new file mode 100644
45cd8f
index 0000000..fd529ba
45cd8f
--- /dev/null
45cd8f
+++ b/lib/common/tests/xml/pcmk__xe_match_test.c
45cd8f
@@ -0,0 +1,105 @@
45cd8f
+/*
45cd8f
+ * Copyright 2022 the Pacemaker project contributors
45cd8f
+ *
45cd8f
+ * The version control history for this file may have further details.
45cd8f
+ *
45cd8f
+ * This source code is licensed under the GNU Lesser General Public License
45cd8f
+ * version 2.1 or later (LGPLv2.1+) WITHOUT ANY WARRANTY.
45cd8f
+ */
45cd8f
+
45cd8f
+#include <crm_internal.h>
45cd8f
+
45cd8f
+#include <crm/common/unittest_internal.h>
45cd8f
+#include <crm/common/xml_internal.h>
45cd8f
+
45cd8f
+const char *str1 =
45cd8f
+    "<xml>\n"
45cd8f
+    "  \n"
45cd8f
+    "  <nodeA attrA=\"123\" id=\"1\">\n"
45cd8f
+    "    content\n"
45cd8f
+    "  </nodeA>\n"
45cd8f
+    "  \n"
45cd8f
+    "  <nodeA attrA=\"456\" id=\"2\">\n"
45cd8f
+    "    content\n"
45cd8f
+    "  </nodeA>\n"
45cd8f
+    "  \n"
45cd8f
+    "  <nodeA attrB=\"XYZ\" id=\"3\">\n"
45cd8f
+    "    content\n"
45cd8f
+    "  </nodeA>\n"
45cd8f
+    "  \n"
45cd8f
+    "  <nodeB attrA=\"123\" id=\"4\">\n"
45cd8f
+    "    content\n"
45cd8f
+    "  </nodeA>\n"
45cd8f
+    "  \n"
45cd8f
+    "  <nodeB attrB=\"ABC\" id=\"5\">\n"
45cd8f
+    "    content\n"
45cd8f
+    "  </nodeA>\n"
45cd8f
+    "</xml>";
45cd8f
+
45cd8f
+static void
45cd8f
+bad_input(void **state) {
45cd8f
+    xmlNode *xml = string2xml(str1);
45cd8f
+
45cd8f
+    assert_null(pcmk__xe_match(NULL, NULL, NULL, NULL));
45cd8f
+    assert_null(pcmk__xe_match(NULL, NULL, NULL, "attrX"));
45cd8f
+
45cd8f
+    free_xml(xml);
45cd8f
+}
45cd8f
+
45cd8f
+static void
45cd8f
+not_found(void **state) {
45cd8f
+    xmlNode *xml = string2xml(str1);
45cd8f
+
45cd8f
+    /* No node with an attrX attribute */
45cd8f
+    assert_null(pcmk__xe_match(xml, NULL, "attrX", NULL));
45cd8f
+    /* No nodeX node */
45cd8f
+    assert_null(pcmk__xe_match(xml, "nodeX", NULL, NULL));
45cd8f
+    /* No nodeA node with attrX */
45cd8f
+    assert_null(pcmk__xe_match(xml, "nodeA", "attrX", NULL));
45cd8f
+    /* No nodeA node with attrA=XYZ */
45cd8f
+    assert_null(pcmk__xe_match(xml, "nodeA", "attrA", "XYZ"));
45cd8f
+
45cd8f
+    free_xml(xml);
45cd8f
+}
45cd8f
+
45cd8f
+static void
45cd8f
+find_attrB(void **state) {
45cd8f
+    xmlNode *xml = string2xml(str1);
45cd8f
+    xmlNode *result = NULL;
45cd8f
+
45cd8f
+    /* Find the first node with attrB */
45cd8f
+    result = pcmk__xe_match(xml, NULL, "attrB", NULL);
45cd8f
+    assert_non_null(result);
45cd8f
+    assert_string_equal(crm_element_value(result, "id"), "3");
45cd8f
+
45cd8f
+    /* Find the first nodeB with attrB */
45cd8f
+    result = pcmk__xe_match(xml, "nodeB", "attrB", NULL);
45cd8f
+    assert_non_null(result);
45cd8f
+    assert_string_equal(crm_element_value(result, "id"), "5");
45cd8f
+
45cd8f
+    free_xml(xml);
45cd8f
+}
45cd8f
+
45cd8f
+static void
45cd8f
+find_attrA_matching(void **state) {
45cd8f
+    xmlNode *xml = string2xml(str1);
45cd8f
+    xmlNode *result = NULL;
45cd8f
+
45cd8f
+    /* Find attrA=456 */
45cd8f
+    result = pcmk__xe_match(xml, NULL, "attrA", "456");
45cd8f
+    assert_non_null(result);
45cd8f
+    assert_string_equal(crm_element_value(result, "id"), "2");
45cd8f
+
45cd8f
+    /* Find a nodeB with attrA=123 */
45cd8f
+    result = pcmk__xe_match(xml, "nodeB", "attrA", "123");
45cd8f
+    assert_non_null(result);
45cd8f
+    assert_string_equal(crm_element_value(result, "id"), "4");
45cd8f
+
45cd8f
+    free_xml(xml);
45cd8f
+}
45cd8f
+
45cd8f
+PCMK__UNIT_TEST(NULL, NULL,
45cd8f
+                cmocka_unit_test(bad_input),
45cd8f
+                cmocka_unit_test(not_found),
45cd8f
+                cmocka_unit_test(find_attrB),
45cd8f
+                cmocka_unit_test(find_attrA_matching));
45cd8f
-- 
45cd8f
2.31.1
45cd8f
45cd8f
From 03af8498d8aaf21c509cec9b0ec4b78475da41d7 Mon Sep 17 00:00:00 2001
45cd8f
From: Chris Lumens <clumens@redhat.com>
45cd8f
Date: Thu, 8 Sep 2022 12:22:26 -0400
45cd8f
Subject: [PATCH 04/26] Feature: libcrmcommon: Add attrd options for specifying
45cd8f
 a sync point.
45cd8f
45cd8f
---
45cd8f
 include/crm/common/attrd_internal.h | 16 +++++++++-------
45cd8f
 1 file changed, 9 insertions(+), 7 deletions(-)
45cd8f
45cd8f
diff --git a/include/crm/common/attrd_internal.h b/include/crm/common/attrd_internal.h
45cd8f
index f7033ad..389be48 100644
45cd8f
--- a/include/crm/common/attrd_internal.h
45cd8f
+++ b/include/crm/common/attrd_internal.h
45cd8f
@@ -16,13 +16,15 @@ extern "C" {
45cd8f
 
45cd8f
 // Options for clients to use with functions below
45cd8f
 enum pcmk__node_attr_opts {
45cd8f
-    pcmk__node_attr_none    = 0,
45cd8f
-    pcmk__node_attr_remote  = (1 << 0),
45cd8f
-    pcmk__node_attr_private = (1 << 1),
45cd8f
-    pcmk__node_attr_pattern = (1 << 2),
45cd8f
-    pcmk__node_attr_value   = (1 << 3),
45cd8f
-    pcmk__node_attr_delay   = (1 << 4),
45cd8f
-    pcmk__node_attr_perm    = (1 << 5),
45cd8f
+    pcmk__node_attr_none           = 0,
45cd8f
+    pcmk__node_attr_remote         = (1 << 0),
45cd8f
+    pcmk__node_attr_private        = (1 << 1),
45cd8f
+    pcmk__node_attr_pattern        = (1 << 2),
45cd8f
+    pcmk__node_attr_value          = (1 << 3),
45cd8f
+    pcmk__node_attr_delay          = (1 << 4),
45cd8f
+    pcmk__node_attr_perm           = (1 << 5),
45cd8f
+    pcmk__node_attr_sync_local     = (1 << 6),
45cd8f
+    pcmk__node_attr_sync_cluster   = (1 << 7),
45cd8f
 };
45cd8f
 
45cd8f
 #define pcmk__set_node_attr_flags(node_attr_flags, flags_to_set) do {   \
45cd8f
-- 
45cd8f
2.31.1
45cd8f
45cd8f
From 5c8825293ee21d3823bdcd01b0df9c7d39739940 Mon Sep 17 00:00:00 2001
45cd8f
From: Chris Lumens <clumens@redhat.com>
45cd8f
Date: Thu, 8 Sep 2022 12:23:09 -0400
45cd8f
Subject: [PATCH 05/26] Feature: libcrmcommon: Add sync point to IPC request
45cd8f
 XML.
45cd8f
45cd8f
If one of the pcmk__node_attr_sync_* options is provided, add an
45cd8f
attribute to the request XML.  This will later be inspected by the
45cd8f
server to determine when to send the reply to the client.
45cd8f
---
45cd8f
 include/crm/common/options_internal.h | 2 ++
45cd8f
 include/crm_internal.h                | 1 +
45cd8f
 lib/common/ipc_attrd.c                | 6 ++++++
45cd8f
 3 files changed, 9 insertions(+)
45cd8f
45cd8f
diff --git a/include/crm/common/options_internal.h b/include/crm/common/options_internal.h
45cd8f
index b153c67..f29ba3f 100644
45cd8f
--- a/include/crm/common/options_internal.h
45cd8f
+++ b/include/crm/common/options_internal.h
45cd8f
@@ -145,9 +145,11 @@ bool pcmk__valid_sbd_timeout(const char *value);
45cd8f
 #define PCMK__META_ALLOW_UNHEALTHY_NODES    "allow-unhealthy-nodes"
45cd8f
 
45cd8f
 // Constants for enumerated values for various options
45cd8f
+#define PCMK__VALUE_CLUSTER                 "cluster"
45cd8f
 #define PCMK__VALUE_CUSTOM                  "custom"
45cd8f
 #define PCMK__VALUE_FENCING                 "fencing"
45cd8f
 #define PCMK__VALUE_GREEN                   "green"
45cd8f
+#define PCMK__VALUE_LOCAL                   "local"
45cd8f
 #define PCMK__VALUE_MIGRATE_ON_RED          "migrate-on-red"
45cd8f
 #define PCMK__VALUE_NONE                    "none"
45cd8f
 #define PCMK__VALUE_NOTHING                 "nothing"
45cd8f
diff --git a/include/crm_internal.h b/include/crm_internal.h
45cd8f
index e6e2e96..08193c3 100644
45cd8f
--- a/include/crm_internal.h
45cd8f
+++ b/include/crm_internal.h
45cd8f
@@ -71,6 +71,7 @@
45cd8f
 #define PCMK__XA_ATTR_RESOURCE          "attr_resource"
45cd8f
 #define PCMK__XA_ATTR_SECTION           "attr_section"
45cd8f
 #define PCMK__XA_ATTR_SET               "attr_set"
45cd8f
+#define PCMK__XA_ATTR_SYNC_POINT        "attr_sync_point"
45cd8f
 #define PCMK__XA_ATTR_USER              "attr_user"
45cd8f
 #define PCMK__XA_ATTR_UUID              "attr_key"
45cd8f
 #define PCMK__XA_ATTR_VALUE             "attr_value"
45cd8f
diff --git a/lib/common/ipc_attrd.c b/lib/common/ipc_attrd.c
45cd8f
index f6cfbc4..4606509 100644
45cd8f
--- a/lib/common/ipc_attrd.c
45cd8f
+++ b/lib/common/ipc_attrd.c
45cd8f
@@ -431,6 +431,12 @@ populate_update_op(xmlNode *op, const char *node, const char *name, const char *
45cd8f
                     pcmk_is_set(options, pcmk__node_attr_remote));
45cd8f
     crm_xml_add_int(op, PCMK__XA_ATTR_IS_PRIVATE,
45cd8f
                     pcmk_is_set(options, pcmk__node_attr_private));
45cd8f
+
45cd8f
+    if (pcmk_is_set(options, pcmk__node_attr_sync_local)) {
45cd8f
+        crm_xml_add(op, PCMK__XA_ATTR_SYNC_POINT, PCMK__VALUE_LOCAL);
45cd8f
+    } else if (pcmk_is_set(options, pcmk__node_attr_sync_cluster)) {
45cd8f
+        crm_xml_add(op, PCMK__XA_ATTR_SYNC_POINT, PCMK__VALUE_CLUSTER);
45cd8f
+    }
45cd8f
 }
45cd8f
 
45cd8f
 int
45cd8f
-- 
45cd8f
2.31.1
45cd8f
45cd8f
From e2b3fee630caf0846ca8bbffcef4d6d2acfd32a5 Mon Sep 17 00:00:00 2001
45cd8f
From: Chris Lumens <clumens@redhat.com>
45cd8f
Date: Thu, 8 Sep 2022 12:26:28 -0400
45cd8f
Subject: [PATCH 06/26] Feature: tools: Add --wait= parameter to attrd_updater.
45cd8f
45cd8f
This command line option is used to specify the sync point to use.  For
45cd8f
the moment, it has no effect.
45cd8f
---
45cd8f
 tools/attrd_updater.c | 24 ++++++++++++++++++++++++
45cd8f
 1 file changed, 24 insertions(+)
45cd8f
45cd8f
diff --git a/tools/attrd_updater.c b/tools/attrd_updater.c
45cd8f
index b85a281..c4779a6 100644
45cd8f
--- a/tools/attrd_updater.c
45cd8f
+++ b/tools/attrd_updater.c
45cd8f
@@ -97,6 +97,22 @@ section_cb (const gchar *option_name, const gchar *optarg, gpointer data, GError
45cd8f
     return TRUE;
45cd8f
 }
45cd8f
 
45cd8f
+static gboolean
45cd8f
+wait_cb (const gchar *option_name, const gchar *optarg, gpointer data, GError **err) {
45cd8f
+    if (pcmk__str_eq(optarg, "no", pcmk__str_none)) {
45cd8f
+        pcmk__clear_node_attr_flags(options.attr_options, pcmk__node_attr_sync_local | pcmk__node_attr_sync_cluster);
45cd8f
+        return TRUE;
45cd8f
+    } else if (pcmk__str_eq(optarg, PCMK__VALUE_LOCAL, pcmk__str_none)) {
45cd8f
+        pcmk__clear_node_attr_flags(options.attr_options, pcmk__node_attr_sync_local | pcmk__node_attr_sync_cluster);
45cd8f
+        pcmk__set_node_attr_flags(options.attr_options, pcmk__node_attr_sync_local);
45cd8f
+        return TRUE;
45cd8f
+    } else {
45cd8f
+        g_set_error(err, PCMK__EXITC_ERROR, CRM_EX_USAGE,
45cd8f
+                    "--wait= must be one of 'no', 'local', 'cluster'");
45cd8f
+        return FALSE;
45cd8f
+    }
45cd8f
+}
45cd8f
+
45cd8f
 #define INDENT "                              "
45cd8f
 
45cd8f
 static GOptionEntry required_entries[] = {
45cd8f
@@ -175,6 +191,14 @@ static GOptionEntry addl_entries[] = {
45cd8f
       "If this creates a new attribute, never write the attribute to CIB",
45cd8f
       NULL },
45cd8f
 
45cd8f
+    { "wait", 'W', 0, G_OPTION_ARG_CALLBACK, wait_cb,
45cd8f
+      "Wait for some event to occur before returning.  Values are 'no' (wait\n"
45cd8f
+      INDENT "only for the attribute daemon to acknowledge the request) or\n"
45cd8f
+      INDENT "'local' (wait until the change has propagated to where a local\n"
45cd8f
+      INDENT "query will return the request value, or the value set by a\n"
45cd8f
+      INDENT "later request).  Default is 'no'.",
45cd8f
+      "UNTIL" },
45cd8f
+
45cd8f
     { NULL }
45cd8f
 };
45cd8f
 
45cd8f
-- 
45cd8f
2.31.1
45cd8f
45cd8f
From 52d51ab41b2f00e72724ab39835b3db86605a96b Mon Sep 17 00:00:00 2001
45cd8f
From: Chris Lumens <clumens@redhat.com>
45cd8f
Date: Thu, 20 Oct 2022 14:40:13 -0400
45cd8f
Subject: [PATCH 07/26] Feature: daemons: Add functions for checking a request
45cd8f
 for a sync point.
45cd8f
45cd8f
---
45cd8f
 daemons/attrd/Makefile.am       |  1 +
45cd8f
 daemons/attrd/attrd_sync.c      | 38 +++++++++++++++++++++++++++++++++
45cd8f
 daemons/attrd/pacemaker-attrd.h |  3 +++
45cd8f
 3 files changed, 42 insertions(+)
45cd8f
 create mode 100644 daemons/attrd/attrd_sync.c
45cd8f
45cd8f
diff --git a/daemons/attrd/Makefile.am b/daemons/attrd/Makefile.am
45cd8f
index 1a3d360..6bb81c4 100644
45cd8f
--- a/daemons/attrd/Makefile.am
45cd8f
+++ b/daemons/attrd/Makefile.am
45cd8f
@@ -32,6 +32,7 @@ pacemaker_attrd_SOURCES	= attrd_alerts.c 	\
45cd8f
 						  attrd_elections.c \
45cd8f
 						  attrd_ipc.c 		\
45cd8f
 						  attrd_messages.c 		\
45cd8f
+						  attrd_sync.c 		\
45cd8f
 						  attrd_utils.c 	\
45cd8f
 						  pacemaker-attrd.c
45cd8f
 
45cd8f
diff --git a/daemons/attrd/attrd_sync.c b/daemons/attrd/attrd_sync.c
45cd8f
new file mode 100644
45cd8f
index 0000000..92759d2
45cd8f
--- /dev/null
45cd8f
+++ b/daemons/attrd/attrd_sync.c
45cd8f
@@ -0,0 +1,38 @@
45cd8f
+/*
45cd8f
+ * Copyright 2022 the Pacemaker project contributors
45cd8f
+ *
45cd8f
+ * The version control history for this file may have further details.
45cd8f
+ *
45cd8f
+ * This source code is licensed under the GNU General Public License version 2
45cd8f
+ * or later (GPLv2+) WITHOUT ANY WARRANTY.
45cd8f
+ */
45cd8f
+
45cd8f
+#include <crm_internal.h>
45cd8f
+
45cd8f
+#include <crm/msg_xml.h>
45cd8f
+#include <crm/common/attrd_internal.h>
45cd8f
+
45cd8f
+#include "pacemaker-attrd.h"
45cd8f
+
45cd8f
+const char *
45cd8f
+attrd_request_sync_point(xmlNode *xml)
45cd8f
+{
45cd8f
+    if (xml_has_children(xml)) {
45cd8f
+        xmlNode *child = pcmk__xe_match(xml, XML_ATTR_OP, PCMK__XA_ATTR_SYNC_POINT, NULL);
45cd8f
+
45cd8f
+        if (child) {
45cd8f
+            return crm_element_value(child, PCMK__XA_ATTR_SYNC_POINT);
45cd8f
+        } else {
45cd8f
+            return NULL;
45cd8f
+        }
45cd8f
+
45cd8f
+    } else {
45cd8f
+        return crm_element_value(xml, PCMK__XA_ATTR_SYNC_POINT);
45cd8f
+    }
45cd8f
+}
45cd8f
+
45cd8f
+bool
45cd8f
+attrd_request_has_sync_point(xmlNode *xml)
45cd8f
+{
45cd8f
+    return attrd_request_sync_point(xml) != NULL;
45cd8f
+}
45cd8f
diff --git a/daemons/attrd/pacemaker-attrd.h b/daemons/attrd/pacemaker-attrd.h
45cd8f
index 71ce90a..ff850bb 100644
45cd8f
--- a/daemons/attrd/pacemaker-attrd.h
45cd8f
+++ b/daemons/attrd/pacemaker-attrd.h
45cd8f
@@ -182,4 +182,7 @@ mainloop_timer_t *attrd_add_timer(const char *id, int timeout_ms, attribute_t *a
45cd8f
 void attrd_unregister_handlers(void);
45cd8f
 void attrd_handle_request(pcmk__request_t *request);
45cd8f
 
45cd8f
+const char *attrd_request_sync_point(xmlNode *xml);
45cd8f
+bool attrd_request_has_sync_point(xmlNode *xml);
45cd8f
+
45cd8f
 #endif /* PACEMAKER_ATTRD__H */
45cd8f
-- 
45cd8f
2.31.1
45cd8f
45cd8f
From 2e0509a12ee7d4a612133ee65b75245eea7d271d Mon Sep 17 00:00:00 2001
45cd8f
From: Chris Lumens <clumens@redhat.com>
45cd8f
Date: Thu, 20 Oct 2022 14:42:04 -0400
45cd8f
Subject: [PATCH 08/26] Refactor: daemons: Don't ACK update requests that give
45cd8f
 a sync point.
45cd8f
45cd8f
The ACK is the only response from the server for update messages.  If
45cd8f
the message specified that it wanted to wait for a sync point, we need
45cd8f
to delay sending that response until the sync point is reached.
45cd8f
Therefore, do not always immediately send the ACK.
45cd8f
---
45cd8f
 daemons/attrd/attrd_messages.c | 19 ++++++++++++++-----
45cd8f
 1 file changed, 14 insertions(+), 5 deletions(-)
45cd8f
45cd8f
diff --git a/daemons/attrd/attrd_messages.c b/daemons/attrd/attrd_messages.c
45cd8f
index de4a28a..9e8ae40 100644
45cd8f
--- a/daemons/attrd/attrd_messages.c
45cd8f
+++ b/daemons/attrd/attrd_messages.c
45cd8f
@@ -137,12 +137,21 @@ handle_update_request(pcmk__request_t *request)
45cd8f
         attrd_peer_update(peer, request->xml, host, false);
45cd8f
         pcmk__set_result(&request->result, CRM_EX_OK, PCMK_EXEC_DONE, NULL);
45cd8f
         return NULL;
45cd8f
+
45cd8f
     } else {
45cd8f
-        /* Because attrd_client_update can be called recursively, we send the ACK
45cd8f
-         * here to ensure that the client only ever receives one.
45cd8f
-         */
45cd8f
-        attrd_send_ack(request->ipc_client, request->ipc_id,
45cd8f
-                       request->flags|crm_ipc_client_response);
45cd8f
+        if (!attrd_request_has_sync_point(request->xml)) {
45cd8f
+            /* If the client doesn't want to wait for a sync point, go ahead and send
45cd8f
+             * the ACK immediately.  Otherwise, we'll send the ACK when the appropriate
45cd8f
+             * sync point is reached.
45cd8f
+             *
45cd8f
+             * In the normal case, attrd_client_update can be called recursively which
45cd8f
+             * makes where to send the ACK tricky.  Doing it here ensures the client
45cd8f
+             * only ever receives one.
45cd8f
+             */
45cd8f
+            attrd_send_ack(request->ipc_client, request->ipc_id,
45cd8f
+                           request->flags|crm_ipc_client_response);
45cd8f
+        }
45cd8f
+
45cd8f
         return attrd_client_update(request);
45cd8f
     }
45cd8f
 }
45cd8f
-- 
45cd8f
2.31.1
45cd8f
45cd8f
From 2a0ff66cdf0085c4c8ab1992ef7e785a4facc8c7 Mon Sep 17 00:00:00 2001
45cd8f
From: Chris Lumens <clumens@redhat.com>
45cd8f
Date: Thu, 20 Oct 2022 14:48:48 -0400
45cd8f
Subject: [PATCH 09/26] Feature: daemons: Add support for local sync points on
45cd8f
 updates.
45cd8f
45cd8f
In the IPC dispatcher for attrd, add the client to a wait list if its
45cd8f
request specifies a sync point.  When the attribute's value is changed
45cd8f
on the local attrd, alert any clients waiting on a local sync point by
45cd8f
then sending the previously delayed ACK.
45cd8f
45cd8f
Sync points for other requests and the global sync point are not yet
45cd8f
supported.
45cd8f
45cd8f
Fixes T35.
45cd8f
---
45cd8f
 daemons/attrd/attrd_corosync.c  |  18 +++++
45cd8f
 daemons/attrd/attrd_messages.c  |  12 ++-
45cd8f
 daemons/attrd/attrd_sync.c      | 137 ++++++++++++++++++++++++++++++++
45cd8f
 daemons/attrd/pacemaker-attrd.h |   7 ++
45cd8f
 4 files changed, 173 insertions(+), 1 deletion(-)
45cd8f
45cd8f
diff --git a/daemons/attrd/attrd_corosync.c b/daemons/attrd/attrd_corosync.c
45cd8f
index 539e5bf..4337280 100644
45cd8f
--- a/daemons/attrd/attrd_corosync.c
45cd8f
+++ b/daemons/attrd/attrd_corosync.c
45cd8f
@@ -568,14 +568,32 @@ void
45cd8f
 attrd_peer_update(const crm_node_t *peer, xmlNode *xml, const char *host,
45cd8f
                   bool filter)
45cd8f
 {
45cd8f
+    bool handle_sync_point = false;
45cd8f
+
45cd8f
     if (xml_has_children(xml)) {
45cd8f
         for (xmlNode *child = first_named_child(xml, XML_ATTR_OP); child != NULL;
45cd8f
              child = crm_next_same_xml(child)) {
45cd8f
             copy_attrs(xml, child);
45cd8f
             attrd_peer_update_one(peer, child, filter);
45cd8f
+
45cd8f
+            if (attrd_request_has_sync_point(child)) {
45cd8f
+                handle_sync_point = true;
45cd8f
+            }
45cd8f
         }
45cd8f
 
45cd8f
     } else {
45cd8f
         attrd_peer_update_one(peer, xml, filter);
45cd8f
+
45cd8f
+        if (attrd_request_has_sync_point(xml)) {
45cd8f
+            handle_sync_point = true;
45cd8f
+        }
45cd8f
+    }
45cd8f
+
45cd8f
+    /* If the update XML specified that the client wanted to wait for a sync
45cd8f
+     * point, process that now.
45cd8f
+     */
45cd8f
+    if (handle_sync_point) {
45cd8f
+        crm_debug("Hit local sync point for attribute update");
45cd8f
+        attrd_ack_waitlist_clients(attrd_sync_point_local, xml);
45cd8f
     }
45cd8f
 }
45cd8f
diff --git a/daemons/attrd/attrd_messages.c b/daemons/attrd/attrd_messages.c
45cd8f
index 9e8ae40..c96700f 100644
45cd8f
--- a/daemons/attrd/attrd_messages.c
45cd8f
+++ b/daemons/attrd/attrd_messages.c
45cd8f
@@ -139,7 +139,17 @@ handle_update_request(pcmk__request_t *request)
45cd8f
         return NULL;
45cd8f
 
45cd8f
     } else {
45cd8f
-        if (!attrd_request_has_sync_point(request->xml)) {
45cd8f
+        if (attrd_request_has_sync_point(request->xml)) {
45cd8f
+            /* If this client supplied a sync point it wants to wait for, add it to
45cd8f
+             * the wait list.  Clients on this list will not receive an ACK until
45cd8f
+             * their sync point is hit which will result in the client stalled there
45cd8f
+             * until it receives a response.
45cd8f
+             *
45cd8f
+             * All other clients will receive the expected response as normal.
45cd8f
+             */
45cd8f
+            attrd_add_client_to_waitlist(request);
45cd8f
+
45cd8f
+        } else {
45cd8f
             /* If the client doesn't want to wait for a sync point, go ahead and send
45cd8f
              * the ACK immediately.  Otherwise, we'll send the ACK when the appropriate
45cd8f
              * sync point is reached.
45cd8f
diff --git a/daemons/attrd/attrd_sync.c b/daemons/attrd/attrd_sync.c
45cd8f
index 92759d2..2981bd0 100644
45cd8f
--- a/daemons/attrd/attrd_sync.c
45cd8f
+++ b/daemons/attrd/attrd_sync.c
45cd8f
@@ -14,6 +14,143 @@
45cd8f
 
45cd8f
 #include "pacemaker-attrd.h"
45cd8f
 
45cd8f
+/* A hash table storing clients that are waiting on a sync point to be reached.
45cd8f
+ * The key is waitlist_client - just a plain int.  The obvious key would be
45cd8f
+ * the IPC client's ID, but this is not guaranteed to be unique.  A single client
45cd8f
+ * could be waiting on a sync point for multiple attributes at the same time.
45cd8f
+ *
45cd8f
+ * It is not expected that this hash table will ever be especially large.
45cd8f
+ */
45cd8f
+static GHashTable *waitlist = NULL;
45cd8f
+static int waitlist_client = 0;
45cd8f
+
45cd8f
+struct waitlist_node {
45cd8f
+    /* What kind of sync point does this node describe? */
45cd8f
+    enum attrd_sync_point sync_point;
45cd8f
+
45cd8f
+    /* Information required to construct and send a reply to the client. */
45cd8f
+    char *client_id;
45cd8f
+    uint32_t ipc_id;
45cd8f
+    uint32_t flags;
45cd8f
+};
45cd8f
+
45cd8f
+static void
45cd8f
+next_key(void)
45cd8f
+{
45cd8f
+    do {
45cd8f
+        waitlist_client++;
45cd8f
+        if (waitlist_client < 0) {
45cd8f
+            waitlist_client = 1;
45cd8f
+        }
45cd8f
+    } while (g_hash_table_contains(waitlist, GINT_TO_POINTER(waitlist_client)));
45cd8f
+}
45cd8f
+
45cd8f
+static void
45cd8f
+free_waitlist_node(gpointer data)
45cd8f
+{
45cd8f
+    struct waitlist_node *wl = (struct waitlist_node *) data;
45cd8f
+
45cd8f
+    free(wl->client_id);
45cd8f
+    free(wl);
45cd8f
+}
45cd8f
+
45cd8f
+static const char *
45cd8f
+sync_point_str(enum attrd_sync_point sync_point)
45cd8f
+{
45cd8f
+    if (sync_point == attrd_sync_point_local) {
45cd8f
+        return PCMK__VALUE_LOCAL;
45cd8f
+    } else if  (sync_point == attrd_sync_point_cluster) {
45cd8f
+        return PCMK__VALUE_CLUSTER;
45cd8f
+    } else {
45cd8f
+        return "unknown";
45cd8f
+    }
45cd8f
+}
45cd8f
+
45cd8f
+void
45cd8f
+attrd_add_client_to_waitlist(pcmk__request_t *request)
45cd8f
+{
45cd8f
+    const char *sync_point = attrd_request_sync_point(request->xml);
45cd8f
+    struct waitlist_node *wl = NULL;
45cd8f
+
45cd8f
+    if (sync_point == NULL) {
45cd8f
+        return;
45cd8f
+    }
45cd8f
+
45cd8f
+    if (waitlist == NULL) {
45cd8f
+        waitlist = pcmk__intkey_table(free_waitlist_node);
45cd8f
+    }
45cd8f
+
45cd8f
+    wl = calloc(sizeof(struct waitlist_node), 1);
45cd8f
+
45cd8f
+    CRM_ASSERT(wl != NULL);
45cd8f
+
45cd8f
+    wl->client_id = strdup(request->ipc_client->id);
45cd8f
+
45cd8f
+    CRM_ASSERT(wl->client_id);
45cd8f
+
45cd8f
+    if (pcmk__str_eq(sync_point, PCMK__VALUE_LOCAL, pcmk__str_none)) {
45cd8f
+        wl->sync_point = attrd_sync_point_local;
45cd8f
+    } else if (pcmk__str_eq(sync_point, PCMK__VALUE_CLUSTER, pcmk__str_none)) {
45cd8f
+        wl->sync_point = attrd_sync_point_cluster;
45cd8f
+    } else {
45cd8f
+        free_waitlist_node(wl);
45cd8f
+        return;
45cd8f
+    }
45cd8f
+
45cd8f
+    wl->ipc_id = request->ipc_id;
45cd8f
+    wl->flags = request->flags;
45cd8f
+
45cd8f
+    crm_debug("Added client %s to waitlist for %s sync point",
45cd8f
+              wl->client_id, sync_point_str(wl->sync_point));
45cd8f
+
45cd8f
+    next_key();
45cd8f
+    pcmk__intkey_table_insert(waitlist, waitlist_client, wl);
45cd8f
+
45cd8f
+    /* And then add the key to the request XML so we can uniquely identify
45cd8f
+     * it when it comes time to issue the ACK.
45cd8f
+     */
45cd8f
+    crm_xml_add_int(request->xml, XML_LRM_ATTR_CALLID, waitlist_client);
45cd8f
+}
45cd8f
+
45cd8f
+void
45cd8f
+attrd_ack_waitlist_clients(enum attrd_sync_point sync_point, const xmlNode *xml)
45cd8f
+{
45cd8f
+    int callid;
45cd8f
+    gpointer value;
45cd8f
+
45cd8f
+    if (waitlist == NULL) {
45cd8f
+        return;
45cd8f
+    }
45cd8f
+
45cd8f
+    if (crm_element_value_int(xml, XML_LRM_ATTR_CALLID, &callid) == -1) {
45cd8f
+        crm_warn("Could not get callid from request XML");
45cd8f
+        return;
45cd8f
+    }
45cd8f
+
45cd8f
+    value = pcmk__intkey_table_lookup(waitlist, callid);
45cd8f
+    if (value != NULL) {
45cd8f
+        struct waitlist_node *wl = (struct waitlist_node *) value;
45cd8f
+        pcmk__client_t *client = NULL;
45cd8f
+
45cd8f
+        if (wl->sync_point != sync_point) {
45cd8f
+            return;
45cd8f
+        }
45cd8f
+
45cd8f
+        crm_debug("Alerting client %s for reached %s sync point",
45cd8f
+                  wl->client_id, sync_point_str(wl->sync_point));
45cd8f
+
45cd8f
+        client = pcmk__find_client_by_id(wl->client_id);
45cd8f
+        if (client == NULL) {
45cd8f
+            return;
45cd8f
+        }
45cd8f
+
45cd8f
+        attrd_send_ack(client, wl->ipc_id, wl->flags | crm_ipc_client_response);
45cd8f
+
45cd8f
+        /* And then remove the client so it doesn't get alerted again. */
45cd8f
+        pcmk__intkey_table_remove(waitlist, callid);
45cd8f
+    }
45cd8f
+}
45cd8f
+
45cd8f
 const char *
45cd8f
 attrd_request_sync_point(xmlNode *xml)
45cd8f
 {
45cd8f
diff --git a/daemons/attrd/pacemaker-attrd.h b/daemons/attrd/pacemaker-attrd.h
45cd8f
index ff850bb..9dd8320 100644
45cd8f
--- a/daemons/attrd/pacemaker-attrd.h
45cd8f
+++ b/daemons/attrd/pacemaker-attrd.h
45cd8f
@@ -182,6 +182,13 @@ mainloop_timer_t *attrd_add_timer(const char *id, int timeout_ms, attribute_t *a
45cd8f
 void attrd_unregister_handlers(void);
45cd8f
 void attrd_handle_request(pcmk__request_t *request);
45cd8f
 
45cd8f
+enum attrd_sync_point {
45cd8f
+    attrd_sync_point_local,
45cd8f
+    attrd_sync_point_cluster,
45cd8f
+};
45cd8f
+
45cd8f
+void attrd_add_client_to_waitlist(pcmk__request_t *request);
45cd8f
+void attrd_ack_waitlist_clients(enum attrd_sync_point sync_point, const xmlNode *xml);
45cd8f
 const char *attrd_request_sync_point(xmlNode *xml);
45cd8f
 bool attrd_request_has_sync_point(xmlNode *xml);
45cd8f
 
45cd8f
-- 
45cd8f
2.31.1
45cd8f
45cd8f
From 59caaf1682191a91d6062358b770f8b9457ba3eb Mon Sep 17 00:00:00 2001
45cd8f
From: Chris Lumens <clumens@redhat.com>
45cd8f
Date: Thu, 20 Oct 2022 14:56:58 -0400
45cd8f
Subject: [PATCH 10/26] Feature: daemons: If a client disconnects, remove it
45cd8f
 from the waitlist.
45cd8f
45cd8f
---
45cd8f
 daemons/attrd/attrd_ipc.c       |  5 +++++
45cd8f
 daemons/attrd/attrd_sync.c      | 21 +++++++++++++++++++++
45cd8f
 daemons/attrd/pacemaker-attrd.h |  1 +
45cd8f
 3 files changed, 27 insertions(+)
45cd8f
45cd8f
diff --git a/daemons/attrd/attrd_ipc.c b/daemons/attrd/attrd_ipc.c
45cd8f
index 7e4a1c0..8aa39c2 100644
45cd8f
--- a/daemons/attrd/attrd_ipc.c
45cd8f
+++ b/daemons/attrd/attrd_ipc.c
45cd8f
@@ -438,8 +438,13 @@ attrd_ipc_closed(qb_ipcs_connection_t *c)
45cd8f
         crm_trace("Ignoring request to clean up unknown connection %p", c);
45cd8f
     } else {
45cd8f
         crm_trace("Cleaning up closed client connection %p", c);
45cd8f
+
45cd8f
+        /* Remove the client from the sync point waitlist if it's present. */
45cd8f
+        attrd_remove_client_from_waitlist(client);
45cd8f
+
45cd8f
         pcmk__free_client(client);
45cd8f
     }
45cd8f
+
45cd8f
     return FALSE;
45cd8f
 }
45cd8f
 
45cd8f
diff --git a/daemons/attrd/attrd_sync.c b/daemons/attrd/attrd_sync.c
45cd8f
index 2981bd0..7293318 100644
45cd8f
--- a/daemons/attrd/attrd_sync.c
45cd8f
+++ b/daemons/attrd/attrd_sync.c
45cd8f
@@ -112,6 +112,27 @@ attrd_add_client_to_waitlist(pcmk__request_t *request)
45cd8f
     crm_xml_add_int(request->xml, XML_LRM_ATTR_CALLID, waitlist_client);
45cd8f
 }
45cd8f
 
45cd8f
+void
45cd8f
+attrd_remove_client_from_waitlist(pcmk__client_t *client)
45cd8f
+{
45cd8f
+    GHashTableIter iter;
45cd8f
+    gpointer value;
45cd8f
+
45cd8f
+    if (waitlist == NULL) {
45cd8f
+        return;
45cd8f
+    }
45cd8f
+
45cd8f
+    g_hash_table_iter_init(&iter, waitlist);
45cd8f
+
45cd8f
+    while (g_hash_table_iter_next(&iter, NULL, &value)) {
45cd8f
+        struct waitlist_node *wl = (struct waitlist_node *) value;
45cd8f
+
45cd8f
+        if (wl->client_id == client->id) {
45cd8f
+            g_hash_table_iter_remove(&iter);
45cd8f
+        }
45cd8f
+    }
45cd8f
+}
45cd8f
+
45cd8f
 void
45cd8f
 attrd_ack_waitlist_clients(enum attrd_sync_point sync_point, const xmlNode *xml)
45cd8f
 {
45cd8f
diff --git a/daemons/attrd/pacemaker-attrd.h b/daemons/attrd/pacemaker-attrd.h
45cd8f
index 9dd8320..b6ecb75 100644
45cd8f
--- a/daemons/attrd/pacemaker-attrd.h
45cd8f
+++ b/daemons/attrd/pacemaker-attrd.h
45cd8f
@@ -189,6 +189,7 @@ enum attrd_sync_point {
45cd8f
 
45cd8f
 void attrd_add_client_to_waitlist(pcmk__request_t *request);
45cd8f
 void attrd_ack_waitlist_clients(enum attrd_sync_point sync_point, const xmlNode *xml);
45cd8f
+void attrd_remove_client_from_waitlist(pcmk__client_t *client);
45cd8f
 const char *attrd_request_sync_point(xmlNode *xml);
45cd8f
 bool attrd_request_has_sync_point(xmlNode *xml);
45cd8f
 
45cd8f
-- 
45cd8f
2.31.1
45cd8f
45cd8f
From b28042e1d64b48c96dbd9da1e9ee3ff481bbf620 Mon Sep 17 00:00:00 2001
45cd8f
From: Chris Lumens <clumens@redhat.com>
45cd8f
Date: Mon, 10 Oct 2022 11:00:20 -0400
45cd8f
Subject: [PATCH 11/26] Feature: daemons: Add support for local sync points on
45cd8f
 clearing failures.
45cd8f
45cd8f
attrd_clear_client_failure just calls attrd_client_update underneath, so
45cd8f
that function will handle all the rest of the sync point functionality
45cd8f
for us.
45cd8f
---
45cd8f
 daemons/attrd/attrd_ipc.c      |  2 --
45cd8f
 daemons/attrd/attrd_messages.c | 19 +++++++++++++++++++
45cd8f
 2 files changed, 19 insertions(+), 2 deletions(-)
45cd8f
45cd8f
diff --git a/daemons/attrd/attrd_ipc.c b/daemons/attrd/attrd_ipc.c
45cd8f
index 8aa39c2..2e614e8 100644
45cd8f
--- a/daemons/attrd/attrd_ipc.c
45cd8f
+++ b/daemons/attrd/attrd_ipc.c
45cd8f
@@ -101,8 +101,6 @@ attrd_client_clear_failure(pcmk__request_t *request)
45cd8f
     xmlNode *xml = request->xml;
45cd8f
     const char *rsc, *op, *interval_spec;
45cd8f
 
45cd8f
-    attrd_send_ack(request->ipc_client, request->ipc_id, request->ipc_flags);
45cd8f
-
45cd8f
     if (minimum_protocol_version >= 2) {
45cd8f
         /* Propagate to all peers (including ourselves).
45cd8f
          * This ends up at attrd_peer_message().
45cd8f
diff --git a/daemons/attrd/attrd_messages.c b/daemons/attrd/attrd_messages.c
45cd8f
index c96700f..3ba14a6 100644
45cd8f
--- a/daemons/attrd/attrd_messages.c
45cd8f
+++ b/daemons/attrd/attrd_messages.c
45cd8f
@@ -42,6 +42,25 @@ handle_clear_failure_request(pcmk__request_t *request)
45cd8f
         pcmk__set_result(&request->result, CRM_EX_OK, PCMK_EXEC_DONE, NULL);
45cd8f
         return NULL;
45cd8f
     } else {
45cd8f
+        if (attrd_request_has_sync_point(request->xml)) {
45cd8f
+            /* If this client supplied a sync point it wants to wait for, add it to
45cd8f
+             * the wait list.  Clients on this list will not receive an ACK until
45cd8f
+             * their sync point is hit which will result in the client stalled there
45cd8f
+             * until it receives a response.
45cd8f
+             *
45cd8f
+             * All other clients will receive the expected response as normal.
45cd8f
+             */
45cd8f
+            attrd_add_client_to_waitlist(request);
45cd8f
+
45cd8f
+        } else {
45cd8f
+            /* If the client doesn't want to wait for a sync point, go ahead and send
45cd8f
+             * the ACK immediately.  Otherwise, we'll send the ACK when the appropriate
45cd8f
+             * sync point is reached.
45cd8f
+             */
45cd8f
+            attrd_send_ack(request->ipc_client, request->ipc_id,
45cd8f
+                           request->ipc_flags);
45cd8f
+        }
45cd8f
+
45cd8f
         return attrd_client_clear_failure(request);
45cd8f
     }
45cd8f
 }
45cd8f
-- 
45cd8f
2.31.1
45cd8f
45cd8f
From 291dc3b91e57f2584bbf88cfbe3a360e0332e814 Mon Sep 17 00:00:00 2001
45cd8f
From: Chris Lumens <clumens@redhat.com>
45cd8f
Date: Mon, 10 Oct 2022 13:17:24 -0400
45cd8f
Subject: [PATCH 12/26] Refactor: daemons: Free the waitlist on attrd exit.
45cd8f
45cd8f
---
45cd8f
 daemons/attrd/attrd_sync.c      | 11 +++++++++++
45cd8f
 daemons/attrd/attrd_utils.c     |  2 ++
45cd8f
 daemons/attrd/pacemaker-attrd.c |  1 +
45cd8f
 daemons/attrd/pacemaker-attrd.h |  1 +
45cd8f
 4 files changed, 15 insertions(+)
45cd8f
45cd8f
diff --git a/daemons/attrd/attrd_sync.c b/daemons/attrd/attrd_sync.c
45cd8f
index 7293318..557e49a 100644
45cd8f
--- a/daemons/attrd/attrd_sync.c
45cd8f
+++ b/daemons/attrd/attrd_sync.c
45cd8f
@@ -112,6 +112,17 @@ attrd_add_client_to_waitlist(pcmk__request_t *request)
45cd8f
     crm_xml_add_int(request->xml, XML_LRM_ATTR_CALLID, waitlist_client);
45cd8f
 }
45cd8f
 
45cd8f
+void
45cd8f
+attrd_free_waitlist(void)
45cd8f
+{
45cd8f
+    if (waitlist == NULL) {
45cd8f
+        return;
45cd8f
+    }
45cd8f
+
45cd8f
+    g_hash_table_destroy(waitlist);
45cd8f
+    waitlist = NULL;
45cd8f
+}
45cd8f
+
45cd8f
 void
45cd8f
 attrd_remove_client_from_waitlist(pcmk__client_t *client)
45cd8f
 {
45cd8f
diff --git a/daemons/attrd/attrd_utils.c b/daemons/attrd/attrd_utils.c
45cd8f
index 6a19009..00b879b 100644
45cd8f
--- a/daemons/attrd/attrd_utils.c
45cd8f
+++ b/daemons/attrd/attrd_utils.c
45cd8f
@@ -93,6 +93,8 @@ attrd_shutdown(int nsig)
45cd8f
     mainloop_destroy_signal(SIGUSR2);
45cd8f
     mainloop_destroy_signal(SIGTRAP);
45cd8f
 
45cd8f
+    attrd_free_waitlist();
45cd8f
+
45cd8f
     if ((mloop == NULL) || !g_main_loop_is_running(mloop)) {
45cd8f
         /* If there's no main loop active, just exit. This should be possible
45cd8f
          * only if we get SIGTERM in brief windows at start-up and shutdown.
45cd8f
diff --git a/daemons/attrd/pacemaker-attrd.c b/daemons/attrd/pacemaker-attrd.c
45cd8f
index 2100db4..1336542 100644
45cd8f
--- a/daemons/attrd/pacemaker-attrd.c
45cd8f
+++ b/daemons/attrd/pacemaker-attrd.c
45cd8f
@@ -300,6 +300,7 @@ main(int argc, char **argv)
45cd8f
         attrd_ipc_fini();
45cd8f
         attrd_lrmd_disconnect();
45cd8f
         attrd_cib_disconnect();
45cd8f
+        attrd_free_waitlist();
45cd8f
         g_hash_table_destroy(attributes);
45cd8f
     }
45cd8f
 
45cd8f
diff --git a/daemons/attrd/pacemaker-attrd.h b/daemons/attrd/pacemaker-attrd.h
45cd8f
index b6ecb75..537bf85 100644
45cd8f
--- a/daemons/attrd/pacemaker-attrd.h
45cd8f
+++ b/daemons/attrd/pacemaker-attrd.h
45cd8f
@@ -52,6 +52,7 @@ void attrd_run_mainloop(void);
45cd8f
 
45cd8f
 void attrd_set_requesting_shutdown(void);
45cd8f
 void attrd_clear_requesting_shutdown(void);
45cd8f
+void attrd_free_waitlist(void);
45cd8f
 bool attrd_requesting_shutdown(void);
45cd8f
 bool attrd_shutting_down(void);
45cd8f
 void attrd_shutdown(int nsig);
45cd8f
-- 
45cd8f
2.31.1
45cd8f
45cd8f
From 7715ce617c520e14687a82e11ff794c93cd7f64a Mon Sep 17 00:00:00 2001
45cd8f
From: Chris Lumens <clumens@redhat.com>
45cd8f
Date: Mon, 10 Oct 2022 13:21:16 -0400
45cd8f
Subject: [PATCH 13/26] Feature: includes: Bump CRM_FEATURE_SET for local sync
45cd8f
 points.
45cd8f
45cd8f
---
45cd8f
 include/crm/crm.h | 2 +-
45cd8f
 1 file changed, 1 insertion(+), 1 deletion(-)
45cd8f
45cd8f
diff --git a/include/crm/crm.h b/include/crm/crm.h
45cd8f
index 5710e4b..7c5c602 100644
45cd8f
--- a/include/crm/crm.h
45cd8f
+++ b/include/crm/crm.h
45cd8f
@@ -66,7 +66,7 @@ extern "C" {
45cd8f
  * >=3.0.13: Fail counts include operation name and interval
45cd8f
  * >=3.2.0:  DC supports PCMK_EXEC_INVALID and PCMK_EXEC_NOT_CONNECTED
45cd8f
  */
45cd8f
-#  define CRM_FEATURE_SET		"3.16.1"
45cd8f
+#  define CRM_FEATURE_SET		"3.16.2"
45cd8f
 
45cd8f
 /* Pacemaker's CPG protocols use fixed-width binary fields for the sender and
45cd8f
  * recipient of a CPG message. This imposes an arbitrary limit on cluster node
45cd8f
-- 
45cd8f
2.31.1
45cd8f
45cd8f
From b9054425a76d03f538cd0b3ae27490b1874eee8a Mon Sep 17 00:00:00 2001
45cd8f
From: Chris Lumens <clumens@redhat.com>
45cd8f
Date: Fri, 28 Oct 2022 14:23:49 -0400
45cd8f
Subject: [PATCH 14/26] Refactor: daemons: Add comments for previously added
45cd8f
 sync point code.
45cd8f
45cd8f
---
45cd8f
 daemons/attrd/attrd_sync.c | 63 ++++++++++++++++++++++++++++++++++++++
45cd8f
 1 file changed, 63 insertions(+)
45cd8f
45cd8f
diff --git a/daemons/attrd/attrd_sync.c b/daemons/attrd/attrd_sync.c
45cd8f
index 557e49a..e9690b5 100644
45cd8f
--- a/daemons/attrd/attrd_sync.c
45cd8f
+++ b/daemons/attrd/attrd_sync.c
45cd8f
@@ -66,6 +66,20 @@ sync_point_str(enum attrd_sync_point sync_point)
45cd8f
     }
45cd8f
 }
45cd8f
 
45cd8f
+/*!
45cd8f
+ * \internal
45cd8f
+ * \brief Add a client to the attrd waitlist
45cd8f
+ *
45cd8f
+ * Typically, a client receives an ACK for its XML IPC request immediately.  However,
45cd8f
+ * some clients want to wait until their request has been processed and taken effect.
45cd8f
+ * This is called a sync point.  Any client placed on this waitlist will have its
45cd8f
+ * ACK message delayed until either its requested sync point is hit, or until it
45cd8f
+ * times out.
45cd8f
+ *
45cd8f
+ * The XML IPC request must specify the type of sync point it wants to wait for.
45cd8f
+ *
45cd8f
+ * \param[in,out] request   The request describing the client to place on the waitlist.
45cd8f
+ */
45cd8f
 void
45cd8f
 attrd_add_client_to_waitlist(pcmk__request_t *request)
45cd8f
 {
45cd8f
@@ -112,6 +126,11 @@ attrd_add_client_to_waitlist(pcmk__request_t *request)
45cd8f
     crm_xml_add_int(request->xml, XML_LRM_ATTR_CALLID, waitlist_client);
45cd8f
 }
45cd8f
 
45cd8f
+/*!
45cd8f
+ * \internal
45cd8f
+ * \brief Free all memory associated with the waitlist.  This is most typically
45cd8f
+ *        used when attrd shuts down.
45cd8f
+ */
45cd8f
 void
45cd8f
 attrd_free_waitlist(void)
45cd8f
 {
45cd8f
@@ -123,6 +142,13 @@ attrd_free_waitlist(void)
45cd8f
     waitlist = NULL;
45cd8f
 }
45cd8f
 
45cd8f
+/*!
45cd8f
+ * \internal
45cd8f
+ * \brief Unconditionally remove a client from the waitlist, such as when the client
45cd8f
+ *        node disconnects from the cluster
45cd8f
+ *
45cd8f
+ * \param[in] client    The client to remove
45cd8f
+ */
45cd8f
 void
45cd8f
 attrd_remove_client_from_waitlist(pcmk__client_t *client)
45cd8f
 {
45cd8f
@@ -144,6 +170,18 @@ attrd_remove_client_from_waitlist(pcmk__client_t *client)
45cd8f
     }
45cd8f
 }
45cd8f
 
45cd8f
+/*!
45cd8f
+ * \internal
45cd8f
+ * \brief Send an IPC ACK message to all awaiting clients
45cd8f
+ *
45cd8f
+ * This function will search the waitlist for all clients that are currently awaiting
45cd8f
+ * an ACK indicating their attrd operation is complete.  Only those clients with a
45cd8f
+ * matching sync point type and callid from their original XML IPC request will be
45cd8f
+ * ACKed.  Once they have received an ACK, they will be removed from the waitlist.
45cd8f
+ *
45cd8f
+ * \param[in] sync_point What kind of sync point have we hit?
45cd8f
+ * \param[in] xml        The original XML IPC request.
45cd8f
+ */
45cd8f
 void
45cd8f
 attrd_ack_waitlist_clients(enum attrd_sync_point sync_point, const xmlNode *xml)
45cd8f
 {
45cd8f
@@ -183,6 +221,23 @@ attrd_ack_waitlist_clients(enum attrd_sync_point sync_point, const xmlNode *xml)
45cd8f
     }
45cd8f
 }
45cd8f
 
45cd8f
+/*!
45cd8f
+ * \internal
45cd8f
+ * \brief Return the sync point attribute for an IPC request
45cd8f
+ *
45cd8f
+ * This function will check both the top-level element of \p xml for a sync
45cd8f
+ * point attribute, as well as all of its \p op children, if any.  The latter
45cd8f
+ * is useful for newer versions of attrd that can put multiple IPC requests
45cd8f
+ * into a single message.
45cd8f
+ *
45cd8f
+ * \param[in] xml   An XML IPC request
45cd8f
+ *
45cd8f
+ * \note It is assumed that if one child element has a sync point attribute,
45cd8f
+ *       all will have a sync point attribute and they will all be the same
45cd8f
+ *       sync point.  No other configuration is supported.
45cd8f
+ *
45cd8f
+ * \return The sync point attribute of \p xml, or NULL if none.
45cd8f
+ */
45cd8f
 const char *
45cd8f
 attrd_request_sync_point(xmlNode *xml)
45cd8f
 {
45cd8f
@@ -200,6 +255,14 @@ attrd_request_sync_point(xmlNode *xml)
45cd8f
     }
45cd8f
 }
45cd8f
 
45cd8f
+/*!
45cd8f
+ * \internal
45cd8f
+ * \brief Does an IPC request contain any sync point attribute?
45cd8f
+ *
45cd8f
+ * \param[in] xml   An XML IPC request
45cd8f
+ *
45cd8f
+ * \return true if there's a sync point attribute, false otherwise
45cd8f
+ */
45cd8f
 bool
45cd8f
 attrd_request_has_sync_point(xmlNode *xml)
45cd8f
 {
45cd8f
-- 
45cd8f
2.31.1
45cd8f
45cd8f
From 64219fb7075ee58d29f94f077a3b8f94174bb32a Mon Sep 17 00:00:00 2001
45cd8f
From: Chris Lumens <clumens@redhat.com>
45cd8f
Date: Wed, 26 Oct 2022 12:43:05 -0400
45cd8f
Subject: [PATCH 15/26] Feature: tools: Add --wait=cluster option to
45cd8f
 attrd_updater.
45cd8f
45cd8f
---
45cd8f
 tools/attrd_updater.c | 10 ++++++++--
45cd8f
 1 file changed, 8 insertions(+), 2 deletions(-)
45cd8f
45cd8f
diff --git a/tools/attrd_updater.c b/tools/attrd_updater.c
45cd8f
index c4779a6..3cd766d 100644
45cd8f
--- a/tools/attrd_updater.c
45cd8f
+++ b/tools/attrd_updater.c
45cd8f
@@ -106,6 +106,10 @@ wait_cb (const gchar *option_name, const gchar *optarg, gpointer data, GError **
45cd8f
         pcmk__clear_node_attr_flags(options.attr_options, pcmk__node_attr_sync_local | pcmk__node_attr_sync_cluster);
45cd8f
         pcmk__set_node_attr_flags(options.attr_options, pcmk__node_attr_sync_local);
45cd8f
         return TRUE;
45cd8f
+    } else if (pcmk__str_eq(optarg, PCMK__VALUE_CLUSTER, pcmk__str_none)) {
45cd8f
+        pcmk__clear_node_attr_flags(options.attr_options, pcmk__node_attr_sync_local | pcmk__node_attr_sync_cluster);
45cd8f
+        pcmk__set_node_attr_flags(options.attr_options, pcmk__node_attr_sync_cluster);
45cd8f
+        return TRUE;
45cd8f
     } else {
45cd8f
         g_set_error(err, PCMK__EXITC_ERROR, CRM_EX_USAGE,
45cd8f
                     "--wait= must be one of 'no', 'local', 'cluster'");
45cd8f
@@ -193,10 +197,12 @@ static GOptionEntry addl_entries[] = {
45cd8f
 
45cd8f
     { "wait", 'W', 0, G_OPTION_ARG_CALLBACK, wait_cb,
45cd8f
       "Wait for some event to occur before returning.  Values are 'no' (wait\n"
45cd8f
-      INDENT "only for the attribute daemon to acknowledge the request) or\n"
45cd8f
+      INDENT "only for the attribute daemon to acknowledge the request),\n"
45cd8f
       INDENT "'local' (wait until the change has propagated to where a local\n"
45cd8f
       INDENT "query will return the request value, or the value set by a\n"
45cd8f
-      INDENT "later request).  Default is 'no'.",
45cd8f
+      INDENT "later request), or 'cluster' (wait until the change has propagated\n"
45cd8f
+      INDENT "to where a query anywhere on the cluster will return the requested\n"
45cd8f
+      INDENT "value, or the value set by a later request).  Default is 'no'.",
45cd8f
       "UNTIL" },
45cd8f
 
45cd8f
     { NULL }
45cd8f
-- 
45cd8f
2.31.1
45cd8f
45cd8f
From 1bc5511fadf6ad670508bd3a2a55129bde16f774 Mon Sep 17 00:00:00 2001
45cd8f
From: Chris Lumens <clumens@redhat.com>
45cd8f
Date: Fri, 16 Sep 2022 14:55:06 -0400
45cd8f
Subject: [PATCH 16/26] Refactor: daemons: Add a confirm= attribute to attrd
45cd8f
 messages.
45cd8f
45cd8f
This allows informing the originator of a message that the message has
45cd8f
been received and processed.  As yet, there is no mechanism for handling
45cd8f
and returning the confirmation, only for requesting it.
45cd8f
---
45cd8f
 daemons/attrd/attrd_corosync.c  |  6 +++---
45cd8f
 daemons/attrd/attrd_ipc.c       | 26 +++++++++++++++++++++-----
45cd8f
 daemons/attrd/attrd_messages.c  | 11 +++++++++--
45cd8f
 daemons/attrd/pacemaker-attrd.h |  7 ++++---
45cd8f
 include/crm_internal.h          |  1 +
45cd8f
 5 files changed, 38 insertions(+), 13 deletions(-)
45cd8f
45cd8f
diff --git a/daemons/attrd/attrd_corosync.c b/daemons/attrd/attrd_corosync.c
45cd8f
index 4337280..e86ca07 100644
45cd8f
--- a/daemons/attrd/attrd_corosync.c
45cd8f
+++ b/daemons/attrd/attrd_corosync.c
45cd8f
@@ -124,7 +124,7 @@ broadcast_local_value(const attribute_t *a)
45cd8f
 
45cd8f
     crm_xml_add(sync, PCMK__XA_TASK, PCMK__ATTRD_CMD_SYNC_RESPONSE);
45cd8f
     attrd_add_value_xml(sync, a, v, false);
45cd8f
-    attrd_send_message(NULL, sync);
45cd8f
+    attrd_send_message(NULL, sync, false);
45cd8f
     free_xml(sync);
45cd8f
     return v;
45cd8f
 }
45cd8f
@@ -387,7 +387,7 @@ broadcast_unseen_local_values(void)
45cd8f
 
45cd8f
     if (sync != NULL) {
45cd8f
         crm_debug("Broadcasting local-only values");
45cd8f
-        attrd_send_message(NULL, sync);
45cd8f
+        attrd_send_message(NULL, sync, false);
45cd8f
         free_xml(sync);
45cd8f
     }
45cd8f
 }
45cd8f
@@ -539,7 +539,7 @@ attrd_peer_sync(crm_node_t *peer, xmlNode *xml)
45cd8f
     }
45cd8f
 
45cd8f
     crm_debug("Syncing values to %s", peer?peer->uname:"everyone");
45cd8f
-    attrd_send_message(peer, sync);
45cd8f
+    attrd_send_message(peer, sync, false);
45cd8f
     free_xml(sync);
45cd8f
 }
45cd8f
 
45cd8f
diff --git a/daemons/attrd/attrd_ipc.c b/daemons/attrd/attrd_ipc.c
45cd8f
index 2e614e8..0fc5e93 100644
45cd8f
--- a/daemons/attrd/attrd_ipc.c
45cd8f
+++ b/daemons/attrd/attrd_ipc.c
45cd8f
@@ -105,7 +105,7 @@ attrd_client_clear_failure(pcmk__request_t *request)
45cd8f
         /* Propagate to all peers (including ourselves).
45cd8f
          * This ends up at attrd_peer_message().
45cd8f
          */
45cd8f
-        attrd_send_message(NULL, xml);
45cd8f
+        attrd_send_message(NULL, xml, false);
45cd8f
         pcmk__set_result(&request->result, CRM_EX_OK, PCMK_EXEC_DONE, NULL);
45cd8f
         return NULL;
45cd8f
     }
45cd8f
@@ -184,7 +184,7 @@ attrd_client_peer_remove(pcmk__request_t *request)
45cd8f
     if (host) {
45cd8f
         crm_info("Client %s is requesting all values for %s be removed",
45cd8f
                  pcmk__client_name(request->ipc_client), host);
45cd8f
-        attrd_send_message(NULL, xml); /* ends up at attrd_peer_message() */
45cd8f
+        attrd_send_message(NULL, xml, false); /* ends up at attrd_peer_message() */
45cd8f
         free(host_alloc);
45cd8f
     } else {
45cd8f
         crm_info("Ignoring request by client %s to remove all peer values without specifying peer",
45cd8f
@@ -314,7 +314,7 @@ attrd_client_update(pcmk__request_t *request)
45cd8f
                 }
45cd8f
             }
45cd8f
 
45cd8f
-            attrd_send_message(NULL, xml);
45cd8f
+            attrd_send_message(NULL, xml, false);
45cd8f
             pcmk__set_result(&request->result, CRM_EX_OK, PCMK_EXEC_DONE, NULL);
45cd8f
 
45cd8f
         } else {
45cd8f
@@ -358,7 +358,7 @@ attrd_client_update(pcmk__request_t *request)
45cd8f
                 if (status == 0) {
45cd8f
                     crm_trace("Matched %s with %s", attr, regex);
45cd8f
                     crm_xml_add(xml, PCMK__XA_ATTR_NAME, attr);
45cd8f
-                    attrd_send_message(NULL, xml);
45cd8f
+                    attrd_send_message(NULL, xml, false);
45cd8f
                 }
45cd8f
             }
45cd8f
 
45cd8f
@@ -388,7 +388,23 @@ attrd_client_update(pcmk__request_t *request)
45cd8f
     crm_debug("Broadcasting %s[%s]=%s%s", attr, crm_element_value(xml, PCMK__XA_ATTR_NODE_NAME),
45cd8f
               value, (attrd_election_won()? " (writer)" : ""));
45cd8f
 
45cd8f
-    attrd_send_message(NULL, xml); /* ends up at attrd_peer_message() */
45cd8f
+    if (pcmk__str_eq(attrd_request_sync_point(xml), PCMK__VALUE_CLUSTER, pcmk__str_none)) {
45cd8f
+        /* The client is waiting on the cluster-wide sync point.  In this case,
45cd8f
+         * the response ACK is not sent until this attrd broadcasts the update
45cd8f
+         * and receives its own confirmation back from all peers.
45cd8f
+         */
45cd8f
+        attrd_send_message(NULL, xml, true); /* ends up at attrd_peer_message() */
45cd8f
+
45cd8f
+    } else {
45cd8f
+        /* The client is either waiting on the local sync point or was not
45cd8f
+         * waiting on any sync point at all.  For the local sync point, the
45cd8f
+         * response ACK is sent in attrd_peer_update.  For clients not
45cd8f
+         * waiting on any sync point, the response ACK is sent in
45cd8f
+         * handle_update_request immediately before this function was called.
45cd8f
+         */
45cd8f
+        attrd_send_message(NULL, xml, false); /* ends up at attrd_peer_message() */
45cd8f
+    }
45cd8f
+
45cd8f
     pcmk__set_result(&request->result, CRM_EX_OK, PCMK_EXEC_DONE, NULL);
45cd8f
     return NULL;
45cd8f
 }
45cd8f
diff --git a/daemons/attrd/attrd_messages.c b/daemons/attrd/attrd_messages.c
45cd8f
index 3ba14a6..78df0d0 100644
45cd8f
--- a/daemons/attrd/attrd_messages.c
45cd8f
+++ b/daemons/attrd/attrd_messages.c
45cd8f
@@ -279,16 +279,23 @@ attrd_broadcast_protocol(void)
45cd8f
     crm_debug("Broadcasting attrd protocol version %s for node %s",
45cd8f
               ATTRD_PROTOCOL_VERSION, attrd_cluster->uname);
45cd8f
 
45cd8f
-    attrd_send_message(NULL, attrd_op); /* ends up at attrd_peer_message() */
45cd8f
+    attrd_send_message(NULL, attrd_op, false); /* ends up at attrd_peer_message() */
45cd8f
 
45cd8f
     free_xml(attrd_op);
45cd8f
 }
45cd8f
 
45cd8f
 gboolean
45cd8f
-attrd_send_message(crm_node_t * node, xmlNode * data)
45cd8f
+attrd_send_message(crm_node_t *node, xmlNode *data, bool confirm)
45cd8f
 {
45cd8f
     crm_xml_add(data, F_TYPE, T_ATTRD);
45cd8f
     crm_xml_add(data, PCMK__XA_ATTR_VERSION, ATTRD_PROTOCOL_VERSION);
45cd8f
+
45cd8f
+    /* Request a confirmation from the destination peer node (which could
45cd8f
+     * be all if node is NULL) that the message has been received and
45cd8f
+     * acted upon.
45cd8f
+     */
45cd8f
+    pcmk__xe_set_bool_attr(data, PCMK__XA_CONFIRM, confirm);
45cd8f
+
45cd8f
     attrd_xml_add_writer(data);
45cd8f
     return send_cluster_message(node, crm_msg_attrd, data, TRUE);
45cd8f
 }
45cd8f
diff --git a/daemons/attrd/pacemaker-attrd.h b/daemons/attrd/pacemaker-attrd.h
45cd8f
index 537bf85..25f7c8a 100644
45cd8f
--- a/daemons/attrd/pacemaker-attrd.h
45cd8f
+++ b/daemons/attrd/pacemaker-attrd.h
45cd8f
@@ -39,10 +39,11 @@
45cd8f
  *                      PCMK__ATTRD_CMD_UPDATE_DELAY
45cd8f
  *     2       1.1.17   PCMK__ATTRD_CMD_CLEAR_FAILURE
45cd8f
  *     3       2.1.1    PCMK__ATTRD_CMD_SYNC_RESPONSE indicates remote nodes
45cd8f
- *     4       2.2.0    Multiple attributes can be updated in a single IPC
45cd8f
+ *     4       2.1.5    Multiple attributes can be updated in a single IPC
45cd8f
  *                      message
45cd8f
+ *     5       2.1.5    Peers can request confirmation of a sent message
45cd8f
  */
45cd8f
-#define ATTRD_PROTOCOL_VERSION "4"
45cd8f
+#define ATTRD_PROTOCOL_VERSION "5"
45cd8f
 
45cd8f
 #define attrd_send_ack(client, id, flags) \
45cd8f
     pcmk__ipc_send_ack((client), (id), (flags), "ack", ATTRD_PROTOCOL_VERSION, CRM_EX_INDETERMINATE)
45cd8f
@@ -162,7 +163,7 @@ xmlNode *attrd_client_clear_failure(pcmk__request_t *request);
45cd8f
 xmlNode *attrd_client_update(pcmk__request_t *request);
45cd8f
 xmlNode *attrd_client_refresh(pcmk__request_t *request);
45cd8f
 xmlNode *attrd_client_query(pcmk__request_t *request);
45cd8f
-gboolean attrd_send_message(crm_node_t * node, xmlNode * data);
45cd8f
+gboolean attrd_send_message(crm_node_t *node, xmlNode *data, bool confirm);
45cd8f
 
45cd8f
 xmlNode *attrd_add_value_xml(xmlNode *parent, const attribute_t *a,
45cd8f
                              const attribute_value_t *v, bool force_write);
45cd8f
diff --git a/include/crm_internal.h b/include/crm_internal.h
45cd8f
index 08193c3..63a1726 100644
45cd8f
--- a/include/crm_internal.h
45cd8f
+++ b/include/crm_internal.h
45cd8f
@@ -79,6 +79,7 @@
45cd8f
 #define PCMK__XA_ATTR_WRITER            "attr_writer"
45cd8f
 #define PCMK__XA_CONFIG_ERRORS          "config-errors"
45cd8f
 #define PCMK__XA_CONFIG_WARNINGS        "config-warnings"
45cd8f
+#define PCMK__XA_CONFIRM                "confirm"
45cd8f
 #define PCMK__XA_GRAPH_ERRORS           "graph-errors"
45cd8f
 #define PCMK__XA_GRAPH_WARNINGS         "graph-warnings"
45cd8f
 #define PCMK__XA_MODE                   "mode"
45cd8f
-- 
45cd8f
2.31.1
45cd8f
45cd8f
From 6f389038fc0b11f6291c022c99f188666c65f530 Mon Sep 17 00:00:00 2001
45cd8f
From: Chris Lumens <clumens@redhat.com>
45cd8f
Date: Wed, 26 Oct 2022 14:44:42 -0400
45cd8f
Subject: [PATCH 17/26] Feature: daemons: Respond to received attrd
45cd8f
 confirmation requests.
45cd8f
45cd8f
On the receiving peer side, if the XML request contains confirm="true",
45cd8f
construct a confirmation message after handling the request completes
45cd8f
and send it back to the originating peer.
45cd8f
45cd8f
On the originating peer side, add a skeleton handler for confirmation
45cd8f
messages.  This does nothing at the moment except log it.
45cd8f
---
45cd8f
 daemons/attrd/attrd_corosync.c | 38 ++++++++++++++++++++++++++++++++++
45cd8f
 daemons/attrd/attrd_messages.c | 13 ++++++++++++
45cd8f
 include/crm_internal.h         |  1 +
45cd8f
 3 files changed, 52 insertions(+)
45cd8f
45cd8f
diff --git a/daemons/attrd/attrd_corosync.c b/daemons/attrd/attrd_corosync.c
45cd8f
index e86ca07..1245d9c 100644
45cd8f
--- a/daemons/attrd/attrd_corosync.c
45cd8f
+++ b/daemons/attrd/attrd_corosync.c
45cd8f
@@ -25,6 +25,19 @@
45cd8f
 
45cd8f
 extern crm_exit_t attrd_exit_status;
45cd8f
 
45cd8f
+static xmlNode *
45cd8f
+attrd_confirmation(int callid)
45cd8f
+{
45cd8f
+    xmlNode *node = create_xml_node(NULL, __func__);
45cd8f
+
45cd8f
+    crm_xml_add(node, F_TYPE, T_ATTRD);
45cd8f
+    crm_xml_add(node, F_ORIG, get_local_node_name());
45cd8f
+    crm_xml_add(node, PCMK__XA_TASK, PCMK__ATTRD_CMD_CONFIRM);
45cd8f
+    crm_xml_add_int(node, XML_LRM_ATTR_CALLID, callid);
45cd8f
+
45cd8f
+    return node;
45cd8f
+}
45cd8f
+
45cd8f
 static void
45cd8f
 attrd_peer_message(crm_node_t *peer, xmlNode *xml)
45cd8f
 {
45cd8f
@@ -57,6 +70,31 @@ attrd_peer_message(crm_node_t *peer, xmlNode *xml)
45cd8f
         CRM_CHECK(request.op != NULL, return);
45cd8f
 
45cd8f
         attrd_handle_request(&request);
45cd8f
+
45cd8f
+        /* Having finished handling the request, check to see if the originating
45cd8f
+         * peer requested confirmation.  If so, send that confirmation back now.
45cd8f
+         */
45cd8f
+        if (pcmk__xe_attr_is_true(xml, PCMK__XA_CONFIRM)) {
45cd8f
+            int callid = 0;
45cd8f
+            xmlNode *reply = NULL;
45cd8f
+
45cd8f
+            /* Add the confirmation ID for the message we are confirming to the
45cd8f
+             * response so the originating peer knows what they're a confirmation
45cd8f
+             * for.
45cd8f
+             */
45cd8f
+            crm_element_value_int(xml, XML_LRM_ATTR_CALLID, &callid);
45cd8f
+            reply = attrd_confirmation(callid);
45cd8f
+
45cd8f
+            /* And then send the confirmation back to the originating peer.  This
45cd8f
+             * ends up right back in this same function (attrd_peer_message) on the
45cd8f
+             * peer where it will have to do something with a PCMK__XA_CONFIRM type
45cd8f
+             * message.
45cd8f
+             */
45cd8f
+            crm_debug("Sending %s a confirmation", peer->uname);
45cd8f
+            attrd_send_message(peer, reply, false);
45cd8f
+            free_xml(reply);
45cd8f
+        }
45cd8f
+
45cd8f
         pcmk__reset_request(&request);
45cd8f
     }
45cd8f
 }
45cd8f
diff --git a/daemons/attrd/attrd_messages.c b/daemons/attrd/attrd_messages.c
45cd8f
index 78df0d0..9c792b2 100644
45cd8f
--- a/daemons/attrd/attrd_messages.c
45cd8f
+++ b/daemons/attrd/attrd_messages.c
45cd8f
@@ -65,6 +65,18 @@ handle_clear_failure_request(pcmk__request_t *request)
45cd8f
     }
45cd8f
 }
45cd8f
 
45cd8f
+static xmlNode *
45cd8f
+handle_confirm_request(pcmk__request_t *request)
45cd8f
+{
45cd8f
+    if (request->peer != NULL) {
45cd8f
+        crm_debug("Received confirmation from %s", request->peer);
45cd8f
+        pcmk__set_result(&request->result, CRM_EX_OK, PCMK_EXEC_DONE, NULL);
45cd8f
+        return NULL;
45cd8f
+    } else {
45cd8f
+        return handle_unknown_request(request);
45cd8f
+    }
45cd8f
+}
45cd8f
+
45cd8f
 static xmlNode *
45cd8f
 handle_flush_request(pcmk__request_t *request)
45cd8f
 {
45cd8f
@@ -190,6 +202,7 @@ attrd_register_handlers(void)
45cd8f
 {
45cd8f
     pcmk__server_command_t handlers[] = {
45cd8f
         { PCMK__ATTRD_CMD_CLEAR_FAILURE, handle_clear_failure_request },
45cd8f
+        { PCMK__ATTRD_CMD_CONFIRM, handle_confirm_request },
45cd8f
         { PCMK__ATTRD_CMD_FLUSH, handle_flush_request },
45cd8f
         { PCMK__ATTRD_CMD_PEER_REMOVE, handle_remove_request },
45cd8f
         { PCMK__ATTRD_CMD_QUERY, handle_query_request },
45cd8f
diff --git a/include/crm_internal.h b/include/crm_internal.h
45cd8f
index 63a1726..f60e7b4 100644
45cd8f
--- a/include/crm_internal.h
45cd8f
+++ b/include/crm_internal.h
45cd8f
@@ -108,6 +108,7 @@
45cd8f
 #define PCMK__ATTRD_CMD_SYNC            "sync"
45cd8f
 #define PCMK__ATTRD_CMD_SYNC_RESPONSE   "sync-response"
45cd8f
 #define PCMK__ATTRD_CMD_CLEAR_FAILURE   "clear-failure"
45cd8f
+#define PCMK__ATTRD_CMD_CONFIRM         "confirm"
45cd8f
 
45cd8f
 #define PCMK__CONTROLD_CMD_NODES        "list-nodes"
45cd8f
 
45cd8f
-- 
45cd8f
2.31.1
45cd8f
45cd8f
From dfb730e9ced9dc75886fda9452c584860573fe30 Mon Sep 17 00:00:00 2001
45cd8f
From: Chris Lumens <clumens@redhat.com>
45cd8f
Date: Wed, 26 Oct 2022 15:58:00 -0400
45cd8f
Subject: [PATCH 18/26] Feature: daemons: Keep track of #attrd-protocol from
45cd8f
 each peer.
45cd8f
45cd8f
This information can be used in the future when dealing with
45cd8f
cluster-wide sync points to know which peers we are waiting on a reply
45cd8f
from.
45cd8f
---
45cd8f
 daemons/attrd/attrd_corosync.c  |  3 +-
45cd8f
 daemons/attrd/attrd_utils.c     | 60 ++++++++++++++++++++++++++++++---
45cd8f
 daemons/attrd/pacemaker-attrd.h |  4 ++-
45cd8f
 3 files changed, 60 insertions(+), 7 deletions(-)
45cd8f
45cd8f
diff --git a/daemons/attrd/attrd_corosync.c b/daemons/attrd/attrd_corosync.c
45cd8f
index 1245d9c..6f88ab6 100644
45cd8f
--- a/daemons/attrd/attrd_corosync.c
45cd8f
+++ b/daemons/attrd/attrd_corosync.c
45cd8f
@@ -268,6 +268,7 @@ attrd_peer_change_cb(enum crm_status_type kind, crm_node_t *peer, const void *da
45cd8f
     // Remove votes from cluster nodes that leave, in case election in progress
45cd8f
     if (gone && !is_remote) {
45cd8f
         attrd_remove_voter(peer);
45cd8f
+        attrd_remove_peer_protocol_ver(peer->uname);
45cd8f
 
45cd8f
     // Ensure remote nodes that come up are in the remote node cache
45cd8f
     } else if (!gone && is_remote) {
45cd8f
@@ -395,7 +396,7 @@ attrd_peer_update_one(const crm_node_t *peer, xmlNode *xml, bool filter)
45cd8f
      * version, check to see if it's a new minimum version.
45cd8f
      */
45cd8f
     if (pcmk__str_eq(attr, CRM_ATTR_PROTOCOL, pcmk__str_none)) {
45cd8f
-        attrd_update_minimum_protocol_ver(value);
45cd8f
+        attrd_update_minimum_protocol_ver(peer->uname, value);
45cd8f
     }
45cd8f
 }
45cd8f
 
45cd8f
diff --git a/daemons/attrd/attrd_utils.c b/daemons/attrd/attrd_utils.c
45cd8f
index 00b879b..421faed 100644
45cd8f
--- a/daemons/attrd/attrd_utils.c
45cd8f
+++ b/daemons/attrd/attrd_utils.c
45cd8f
@@ -29,6 +29,11 @@ static bool requesting_shutdown = false;
45cd8f
 static bool shutting_down = false;
45cd8f
 static GMainLoop *mloop = NULL;
45cd8f
 
45cd8f
+/* A hash table storing information on the protocol version of each peer attrd.
45cd8f
+ * The key is the peer's uname, and the value is the protocol version number.
45cd8f
+ */
45cd8f
+GHashTable *peer_protocol_vers = NULL;
45cd8f
+
45cd8f
 /*!
45cd8f
  * \internal
45cd8f
  * \brief  Set requesting_shutdown state
45cd8f
@@ -94,6 +99,10 @@ attrd_shutdown(int nsig)
45cd8f
     mainloop_destroy_signal(SIGTRAP);
45cd8f
 
45cd8f
     attrd_free_waitlist();
45cd8f
+    if (peer_protocol_vers != NULL) {
45cd8f
+        g_hash_table_destroy(peer_protocol_vers);
45cd8f
+        peer_protocol_vers = NULL;
45cd8f
+    }
45cd8f
 
45cd8f
     if ((mloop == NULL) || !g_main_loop_is_running(mloop)) {
45cd8f
         /* If there's no main loop active, just exit. This should be possible
45cd8f
@@ -273,16 +282,57 @@ attrd_free_attribute(gpointer data)
45cd8f
     }
45cd8f
 }
45cd8f
 
45cd8f
+/*!
45cd8f
+ * \internal
45cd8f
+ * \brief When a peer node leaves the cluster, stop tracking its protocol version.
45cd8f
+ *
45cd8f
+ * \param[in] host  The peer node's uname to be removed
45cd8f
+ */
45cd8f
+void
45cd8f
+attrd_remove_peer_protocol_ver(const char *host)
45cd8f
+{
45cd8f
+    if (peer_protocol_vers != NULL) {
45cd8f
+        g_hash_table_remove(peer_protocol_vers, host);
45cd8f
+    }
45cd8f
+}
45cd8f
+
45cd8f
+/*!
45cd8f
+ * \internal
45cd8f
+ * \brief When a peer node broadcasts a message with its protocol version, keep
45cd8f
+ *        track of that information.
45cd8f
+ *
45cd8f
+ * We keep track of each peer's protocol version so we know which peers to
45cd8f
+ * expect confirmation messages from when handling cluster-wide sync points.
45cd8f
+ * We additionally keep track of the lowest protocol version supported by all
45cd8f
+ * peers so we know when we can send IPC messages containing more than one
45cd8f
+ * request.
45cd8f
+ *
45cd8f
+ * \param[in] host  The peer node's uname to be tracked
45cd8f
+ * \param[in] value The peer node's protocol version
45cd8f
+ */
45cd8f
 void
45cd8f
-attrd_update_minimum_protocol_ver(const char *value)
45cd8f
+attrd_update_minimum_protocol_ver(const char *host, const char *value)
45cd8f
 {
45cd8f
     int ver;
45cd8f
 
45cd8f
+    if (peer_protocol_vers == NULL) {
45cd8f
+        peer_protocol_vers = pcmk__strkey_table(free, NULL);
45cd8f
+    }
45cd8f
+
45cd8f
     pcmk__scan_min_int(value, &ver, 0);
45cd8f
 
45cd8f
-    if (ver > 0 && (minimum_protocol_version == -1 || ver < minimum_protocol_version)) {
45cd8f
-        minimum_protocol_version = ver;
45cd8f
-        crm_trace("Set minimum attrd protocol version to %d",
45cd8f
-                  minimum_protocol_version);
45cd8f
+    if (ver > 0) {
45cd8f
+        char *host_name = strdup(host);
45cd8f
+
45cd8f
+        /* Record the peer attrd's protocol version. */
45cd8f
+        CRM_ASSERT(host_name != NULL);
45cd8f
+        g_hash_table_insert(peer_protocol_vers, host_name, GINT_TO_POINTER(ver));
45cd8f
+
45cd8f
+        /* If the protocol version is a new minimum, record it as such. */
45cd8f
+        if (minimum_protocol_version == -1 || ver < minimum_protocol_version) {
45cd8f
+            minimum_protocol_version = ver;
45cd8f
+            crm_trace("Set minimum attrd protocol version to %d",
45cd8f
+                      minimum_protocol_version);
45cd8f
+        }
45cd8f
     }
45cd8f
 }
45cd8f
diff --git a/daemons/attrd/pacemaker-attrd.h b/daemons/attrd/pacemaker-attrd.h
45cd8f
index 25f7c8a..302ef63 100644
45cd8f
--- a/daemons/attrd/pacemaker-attrd.h
45cd8f
+++ b/daemons/attrd/pacemaker-attrd.h
45cd8f
@@ -145,6 +145,7 @@ typedef struct attribute_value_s {
45cd8f
 
45cd8f
 extern crm_cluster_t *attrd_cluster;
45cd8f
 extern GHashTable *attributes;
45cd8f
+extern GHashTable *peer_protocol_vers;
45cd8f
 
45cd8f
 #define CIB_OP_TIMEOUT_S 120
45cd8f
 
45cd8f
@@ -177,7 +178,8 @@ void attrd_write_attributes(bool all, bool ignore_delay);
45cd8f
 void attrd_write_or_elect_attribute(attribute_t *a);
45cd8f
 
45cd8f
 extern int minimum_protocol_version;
45cd8f
-void attrd_update_minimum_protocol_ver(const char *value);
45cd8f
+void attrd_remove_peer_protocol_ver(const char *host);
45cd8f
+void attrd_update_minimum_protocol_ver(const char *host, const char *value);
45cd8f
 
45cd8f
 mainloop_timer_t *attrd_add_timer(const char *id, int timeout_ms, attribute_t *attr);
45cd8f
 
45cd8f
-- 
45cd8f
2.31.1
45cd8f
45cd8f
From 945f0fe51d3bf69c2cb1258b394f2f11b8996525 Mon Sep 17 00:00:00 2001
45cd8f
From: Chris Lumens <clumens@redhat.com>
45cd8f
Date: Thu, 27 Oct 2022 14:42:59 -0400
45cd8f
Subject: [PATCH 19/26] Feature: daemons: Handle cluster-wide sync points in
45cd8f
 attrd.
45cd8f
45cd8f
When an attrd receives an IPC request to update some value, record the
45cd8f
protocol versions of all peer attrds.  Additionally register a function
45cd8f
that will be called when all confirmations are received.
45cd8f
45cd8f
The originating IPC cilent (attrd_updater for instance) will sit there
45cd8f
waiting for an ACK until its timeout is hit.
45cd8f
45cd8f
As each confirmation message comes back to attrd, mark it off the list
45cd8f
of peers we are waiting on.  When no more peers are expected, call the
45cd8f
previously registered function.
45cd8f
45cd8f
For attribute updates, this function just sends an ack back to
45cd8f
attrd_updater.
45cd8f
45cd8f
Fixes T35
45cd8f
---
45cd8f
 daemons/attrd/attrd_corosync.c  |   1 +
45cd8f
 daemons/attrd/attrd_ipc.c       |   4 +
45cd8f
 daemons/attrd/attrd_messages.c  |  10 ++
45cd8f
 daemons/attrd/attrd_sync.c      | 260 +++++++++++++++++++++++++++++++-
45cd8f
 daemons/attrd/attrd_utils.c     |   2 +
45cd8f
 daemons/attrd/pacemaker-attrd.h |   8 +
45cd8f
 6 files changed, 281 insertions(+), 4 deletions(-)
45cd8f
45cd8f
diff --git a/daemons/attrd/attrd_corosync.c b/daemons/attrd/attrd_corosync.c
45cd8f
index 6f88ab6..37701aa 100644
45cd8f
--- a/daemons/attrd/attrd_corosync.c
45cd8f
+++ b/daemons/attrd/attrd_corosync.c
45cd8f
@@ -269,6 +269,7 @@ attrd_peer_change_cb(enum crm_status_type kind, crm_node_t *peer, const void *da
45cd8f
     if (gone && !is_remote) {
45cd8f
         attrd_remove_voter(peer);
45cd8f
         attrd_remove_peer_protocol_ver(peer->uname);
45cd8f
+        attrd_do_not_expect_from_peer(peer->uname);
45cd8f
 
45cd8f
     // Ensure remote nodes that come up are in the remote node cache
45cd8f
     } else if (!gone && is_remote) {
45cd8f
diff --git a/daemons/attrd/attrd_ipc.c b/daemons/attrd/attrd_ipc.c
45cd8f
index 0fc5e93..c70aa1b 100644
45cd8f
--- a/daemons/attrd/attrd_ipc.c
45cd8f
+++ b/daemons/attrd/attrd_ipc.c
45cd8f
@@ -393,6 +393,7 @@ attrd_client_update(pcmk__request_t *request)
45cd8f
          * the response ACK is not sent until this attrd broadcasts the update
45cd8f
          * and receives its own confirmation back from all peers.
45cd8f
          */
45cd8f
+        attrd_expect_confirmations(request, attrd_cluster_sync_point_update);
45cd8f
         attrd_send_message(NULL, xml, true); /* ends up at attrd_peer_message() */
45cd8f
 
45cd8f
     } else {
45cd8f
@@ -456,6 +457,9 @@ attrd_ipc_closed(qb_ipcs_connection_t *c)
45cd8f
         /* Remove the client from the sync point waitlist if it's present. */
45cd8f
         attrd_remove_client_from_waitlist(client);
45cd8f
 
45cd8f
+        /* And no longer wait for confirmations from any peers. */
45cd8f
+        attrd_do_not_wait_for_client(client);
45cd8f
+
45cd8f
         pcmk__free_client(client);
45cd8f
     }
45cd8f
 
45cd8f
diff --git a/daemons/attrd/attrd_messages.c b/daemons/attrd/attrd_messages.c
45cd8f
index 9c792b2..f7b9c7c 100644
45cd8f
--- a/daemons/attrd/attrd_messages.c
45cd8f
+++ b/daemons/attrd/attrd_messages.c
45cd8f
@@ -69,7 +69,17 @@ static xmlNode *
45cd8f
 handle_confirm_request(pcmk__request_t *request)
45cd8f
 {
45cd8f
     if (request->peer != NULL) {
45cd8f
+        int callid;
45cd8f
+
45cd8f
         crm_debug("Received confirmation from %s", request->peer);
45cd8f
+
45cd8f
+        if (crm_element_value_int(request->xml, XML_LRM_ATTR_CALLID, &callid) == -1) {
45cd8f
+            pcmk__set_result(&request->result, CRM_EX_PROTOCOL, PCMK_EXEC_INVALID,
45cd8f
+                             "Could not get callid from XML");
45cd8f
+        } else {
45cd8f
+            attrd_handle_confirmation(callid, request->peer);
45cd8f
+        }
45cd8f
+
45cd8f
         pcmk__set_result(&request->result, CRM_EX_OK, PCMK_EXEC_DONE, NULL);
45cd8f
         return NULL;
45cd8f
     } else {
45cd8f
diff --git a/daemons/attrd/attrd_sync.c b/daemons/attrd/attrd_sync.c
45cd8f
index e9690b5..d3d7108 100644
45cd8f
--- a/daemons/attrd/attrd_sync.c
45cd8f
+++ b/daemons/attrd/attrd_sync.c
45cd8f
@@ -34,6 +34,51 @@ struct waitlist_node {
45cd8f
     uint32_t flags;
45cd8f
 };
45cd8f
 
45cd8f
+/* A hash table storing information on in-progress IPC requests that are awaiting
45cd8f
+ * confirmations.  These requests are currently being processed by peer attrds and
45cd8f
+ * we are waiting to receive confirmation messages from each peer indicating that
45cd8f
+ * processing is complete.
45cd8f
+ *
45cd8f
+ * Multiple requests could be waiting on confirmations at the same time.
45cd8f
+ *
45cd8f
+ * The key is the unique callid for the IPC request, and the value is a
45cd8f
+ * confirmation_action struct.
45cd8f
+ */
45cd8f
+static GHashTable *expected_confirmations = NULL;
45cd8f
+
45cd8f
+/*!
45cd8f
+ * \internal
45cd8f
+ * \brief A structure describing a single IPC request that is awaiting confirmations
45cd8f
+ */
45cd8f
+struct confirmation_action {
45cd8f
+    /*!
45cd8f
+     * \brief A list of peer attrds that we are waiting to receive confirmation
45cd8f
+     *        messages from
45cd8f
+     *
45cd8f
+     * This list is dynamic - as confirmations arrive from peer attrds, they will
45cd8f
+     * be removed from this list.  When the list is empty, all peers have processed
45cd8f
+     * the request and the associated confirmation action will be taken.
45cd8f
+     */
45cd8f
+    GList *respondents;
45cd8f
+
45cd8f
+    /*!
45cd8f
+     * \brief A function to run when all confirmations have been received
45cd8f
+     */
45cd8f
+    attrd_confirmation_action_fn fn;
45cd8f
+
45cd8f
+    /*!
45cd8f
+     * \brief Information required to construct and send a reply to the client
45cd8f
+     */
45cd8f
+    char *client_id;
45cd8f
+    uint32_t ipc_id;
45cd8f
+    uint32_t flags;
45cd8f
+
45cd8f
+    /*!
45cd8f
+     * \brief The XML request containing the callid associated with this action
45cd8f
+     */
45cd8f
+    void *xml;
45cd8f
+};
45cd8f
+
45cd8f
 static void
45cd8f
 next_key(void)
45cd8f
 {
45cd8f
@@ -114,12 +159,13 @@ attrd_add_client_to_waitlist(pcmk__request_t *request)
45cd8f
     wl->ipc_id = request->ipc_id;
45cd8f
     wl->flags = request->flags;
45cd8f
 
45cd8f
-    crm_debug("Added client %s to waitlist for %s sync point",
45cd8f
-              wl->client_id, sync_point_str(wl->sync_point));
45cd8f
-
45cd8f
     next_key();
45cd8f
     pcmk__intkey_table_insert(waitlist, waitlist_client, wl);
45cd8f
 
45cd8f
+    crm_trace("Added client %s to waitlist for %s sync point",
45cd8f
+              wl->client_id, sync_point_str(wl->sync_point));
45cd8f
+    crm_trace("%d clients now on waitlist", g_hash_table_size(waitlist));
45cd8f
+
45cd8f
     /* And then add the key to the request XML so we can uniquely identify
45cd8f
      * it when it comes time to issue the ACK.
45cd8f
      */
45cd8f
@@ -166,6 +212,7 @@ attrd_remove_client_from_waitlist(pcmk__client_t *client)
45cd8f
 
45cd8f
         if (wl->client_id == client->id) {
45cd8f
             g_hash_table_iter_remove(&iter);
45cd8f
+            crm_trace("%d clients now on waitlist", g_hash_table_size(waitlist));
45cd8f
         }
45cd8f
     }
45cd8f
 }
45cd8f
@@ -206,7 +253,7 @@ attrd_ack_waitlist_clients(enum attrd_sync_point sync_point, const xmlNode *xml)
45cd8f
             return;
45cd8f
         }
45cd8f
 
45cd8f
-        crm_debug("Alerting client %s for reached %s sync point",
45cd8f
+        crm_trace("Alerting client %s for reached %s sync point",
45cd8f
                   wl->client_id, sync_point_str(wl->sync_point));
45cd8f
 
45cd8f
         client = pcmk__find_client_by_id(wl->client_id);
45cd8f
@@ -218,9 +265,28 @@ attrd_ack_waitlist_clients(enum attrd_sync_point sync_point, const xmlNode *xml)
45cd8f
 
45cd8f
         /* And then remove the client so it doesn't get alerted again. */
45cd8f
         pcmk__intkey_table_remove(waitlist, callid);
45cd8f
+
45cd8f
+        crm_trace("%d clients now on waitlist", g_hash_table_size(waitlist));
45cd8f
     }
45cd8f
 }
45cd8f
 
45cd8f
+/*!
45cd8f
+ * \internal
45cd8f
+ * \brief Action to take when a cluster sync point is hit for a
45cd8f
+ *        PCMK__ATTRD_CMD_UPDATE* message.
45cd8f
+ *
45cd8f
+ * \param[in] xml  The request that should be passed along to
45cd8f
+ *                 attrd_ack_waitlist_clients.  This should be the original
45cd8f
+ *                 IPC request containing the callid for this update message.
45cd8f
+ */
45cd8f
+int
45cd8f
+attrd_cluster_sync_point_update(xmlNode *xml)
45cd8f
+{
45cd8f
+    crm_trace("Hit cluster sync point for attribute update");
45cd8f
+    attrd_ack_waitlist_clients(attrd_sync_point_cluster, xml);
45cd8f
+    return pcmk_rc_ok;
45cd8f
+}
45cd8f
+
45cd8f
 /*!
45cd8f
  * \internal
45cd8f
  * \brief Return the sync point attribute for an IPC request
45cd8f
@@ -268,3 +334,189 @@ attrd_request_has_sync_point(xmlNode *xml)
45cd8f
 {
45cd8f
     return attrd_request_sync_point(xml) != NULL;
45cd8f
 }
45cd8f
+
45cd8f
+static void
45cd8f
+free_action(gpointer data)
45cd8f
+{
45cd8f
+    struct confirmation_action *action = (struct confirmation_action *) data;
45cd8f
+    g_list_free_full(action->respondents, free);
45cd8f
+    free_xml(action->xml);
45cd8f
+    free(action->client_id);
45cd8f
+    free(action);
45cd8f
+}
45cd8f
+
45cd8f
+/*!
45cd8f
+ * \internal
45cd8f
+ * \brief When a peer disconnects from the cluster, no longer wait for its confirmation
45cd8f
+ *        for any IPC action.  If this peer is the last one being waited on, this will
45cd8f
+ *        trigger the confirmation action.
45cd8f
+ *
45cd8f
+ * \param[in] host   The disconnecting peer attrd's uname
45cd8f
+ */
45cd8f
+void
45cd8f
+attrd_do_not_expect_from_peer(const char *host)
45cd8f
+{
45cd8f
+    GList *keys = g_hash_table_get_keys(expected_confirmations);
45cd8f
+
45cd8f
+    crm_trace("Removing peer %s from expected confirmations", host);
45cd8f
+
45cd8f
+    for (GList *node = keys; node != NULL; node = node->next) {
45cd8f
+        int callid = *(int *) node->data;
45cd8f
+        attrd_handle_confirmation(callid, host);
45cd8f
+    }
45cd8f
+
45cd8f
+    g_list_free(keys);
45cd8f
+}
45cd8f
+
45cd8f
+/*!
45cd8f
+ * \internal
45cd8f
+ * \brief When a client disconnects from the cluster, no longer wait on confirmations
45cd8f
+ *        for it.  Because the peer attrds may still be processing the original IPC
45cd8f
+ *        message, they may still send us confirmations.  However, we will take no
45cd8f
+ *        action on them.
45cd8f
+ *
45cd8f
+ * \param[in] client    The disconnecting client
45cd8f
+ */
45cd8f
+void
45cd8f
+attrd_do_not_wait_for_client(pcmk__client_t *client)
45cd8f
+{
45cd8f
+    GHashTableIter iter;
45cd8f
+    gpointer value;
45cd8f
+
45cd8f
+    if (expected_confirmations == NULL) {
45cd8f
+        return;
45cd8f
+    }
45cd8f
+
45cd8f
+    g_hash_table_iter_init(&iter, expected_confirmations);
45cd8f
+
45cd8f
+    while (g_hash_table_iter_next(&iter, NULL, &value)) {
45cd8f
+        struct confirmation_action *action = (struct confirmation_action *) value;
45cd8f
+
45cd8f
+        if (pcmk__str_eq(action->client_id, client->id, pcmk__str_none)) {
45cd8f
+            crm_trace("Removing client %s from expected confirmations", client->id);
45cd8f
+            g_hash_table_iter_remove(&iter);
45cd8f
+            crm_trace("%d requests now in expected confirmations table", g_hash_table_size(expected_confirmations));
45cd8f
+            break;
45cd8f
+        }
45cd8f
+    }
45cd8f
+}
45cd8f
+
45cd8f
+/*!
45cd8f
+ * \internal
45cd8f
+ * \brief Register some action to be taken when IPC request confirmations are
45cd8f
+ *        received
45cd8f
+ *
45cd8f
+ * When this function is called, a list of all peer attrds that support confirming
45cd8f
+ * requests is generated.  As confirmations from these peer attrds are received,
45cd8f
+ * they are removed from this list.  When the list is empty, the registered action
45cd8f
+ * will be called.
45cd8f
+ *
45cd8f
+ * \note This function should always be called before attrd_send_message is called
45cd8f
+ *       to broadcast to the peers to ensure that we know what replies we are
45cd8f
+ *       waiting on.  Otherwise, it is possible the peer could finish and confirm
45cd8f
+ *       before we know to expect it.
45cd8f
+ *
45cd8f
+ * \param[in] request The request that is awaiting confirmations
45cd8f
+ * \param[in] fn      A function to be run after all confirmations are received
45cd8f
+ */
45cd8f
+void
45cd8f
+attrd_expect_confirmations(pcmk__request_t *request, attrd_confirmation_action_fn fn)
45cd8f
+{
45cd8f
+    struct confirmation_action *action = NULL;
45cd8f
+    GHashTableIter iter;
45cd8f
+    gpointer host, ver;
45cd8f
+    GList *respondents = NULL;
45cd8f
+    int callid;
45cd8f
+
45cd8f
+    if (expected_confirmations == NULL) {
45cd8f
+        expected_confirmations = pcmk__intkey_table((GDestroyNotify) free_action);
45cd8f
+    }
45cd8f
+
45cd8f
+    if (crm_element_value_int(request->xml, XML_LRM_ATTR_CALLID, &callid) == -1) {
45cd8f
+        crm_err("Could not get callid from xml");
45cd8f
+        return;
45cd8f
+    }
45cd8f
+
45cd8f
+    if (pcmk__intkey_table_lookup(expected_confirmations, callid)) {
45cd8f
+        crm_err("Already waiting on confirmations for call id %d", callid);
45cd8f
+        return;
45cd8f
+    }
45cd8f
+
45cd8f
+    g_hash_table_iter_init(&iter, peer_protocol_vers);
45cd8f
+    while (g_hash_table_iter_next(&iter, &host, &ver)) {
45cd8f
+        if (GPOINTER_TO_INT(ver) >= 5) {
45cd8f
+            char *s = strdup((char *) host);
45cd8f
+
45cd8f
+            CRM_ASSERT(s != NULL);
45cd8f
+            respondents = g_list_prepend(respondents, s);
45cd8f
+        }
45cd8f
+    }
45cd8f
+
45cd8f
+    action = calloc(1, sizeof(struct confirmation_action));
45cd8f
+    CRM_ASSERT(action != NULL);
45cd8f
+
45cd8f
+    action->respondents = respondents;
45cd8f
+    action->fn = fn;
45cd8f
+    action->xml = copy_xml(request->xml);
45cd8f
+
45cd8f
+    action->client_id = strdup(request->ipc_client->id);
45cd8f
+    CRM_ASSERT(action->client_id != NULL);
45cd8f
+
45cd8f
+    action->ipc_id = request->ipc_id;
45cd8f
+    action->flags = request->flags;
45cd8f
+
45cd8f
+    pcmk__intkey_table_insert(expected_confirmations, callid, action);
45cd8f
+    crm_trace("Callid %d now waiting on %d confirmations", callid, g_list_length(respondents));
45cd8f
+    crm_trace("%d requests now in expected confirmations table", g_hash_table_size(expected_confirmations));
45cd8f
+}
45cd8f
+
45cd8f
+void
45cd8f
+attrd_free_confirmations(void)
45cd8f
+{
45cd8f
+    if (expected_confirmations != NULL) {
45cd8f
+        g_hash_table_destroy(expected_confirmations);
45cd8f
+        expected_confirmations = NULL;
45cd8f
+    }
45cd8f
+}
45cd8f
+
45cd8f
+/*!
45cd8f
+ * \internal
45cd8f
+ * \brief Process a confirmation message from a peer attrd
45cd8f
+ *
45cd8f
+ * This function is called every time a PCMK__ATTRD_CMD_CONFIRM message is
45cd8f
+ * received from a peer attrd.  If this is the last confirmation we are waiting
45cd8f
+ * on for a given operation, the registered action will be called.
45cd8f
+ *
45cd8f
+ * \param[in] callid The unique callid for the XML IPC request
45cd8f
+ * \param[in] host   The confirming peer attrd's uname
45cd8f
+ */
45cd8f
+void
45cd8f
+attrd_handle_confirmation(int callid, const char *host)
45cd8f
+{
45cd8f
+    struct confirmation_action *action = NULL;
45cd8f
+    GList *node = NULL;
45cd8f
+
45cd8f
+    if (expected_confirmations == NULL) {
45cd8f
+        return;
45cd8f
+    }
45cd8f
+
45cd8f
+    action = pcmk__intkey_table_lookup(expected_confirmations, callid);
45cd8f
+    if (action == NULL) {
45cd8f
+        return;
45cd8f
+    }
45cd8f
+
45cd8f
+    node = g_list_find_custom(action->respondents, host, (GCompareFunc) strcasecmp);
45cd8f
+
45cd8f
+    if (node == NULL) {
45cd8f
+        return;
45cd8f
+    }
45cd8f
+
45cd8f
+    action->respondents = g_list_remove(action->respondents, node->data);
45cd8f
+    crm_trace("Callid %d now waiting on %d confirmations", callid, g_list_length(action->respondents));
45cd8f
+
45cd8f
+    if (action->respondents == NULL) {
45cd8f
+        action->fn(action->xml);
45cd8f
+        pcmk__intkey_table_remove(expected_confirmations, callid);
45cd8f
+        crm_trace("%d requests now in expected confirmations table", g_hash_table_size(expected_confirmations));
45cd8f
+    }
45cd8f
+}
45cd8f
diff --git a/daemons/attrd/attrd_utils.c b/daemons/attrd/attrd_utils.c
45cd8f
index 421faed..f3a2059 100644
45cd8f
--- a/daemons/attrd/attrd_utils.c
45cd8f
+++ b/daemons/attrd/attrd_utils.c
45cd8f
@@ -99,6 +99,8 @@ attrd_shutdown(int nsig)
45cd8f
     mainloop_destroy_signal(SIGTRAP);
45cd8f
 
45cd8f
     attrd_free_waitlist();
45cd8f
+    attrd_free_confirmations();
45cd8f
+
45cd8f
     if (peer_protocol_vers != NULL) {
45cd8f
         g_hash_table_destroy(peer_protocol_vers);
45cd8f
         peer_protocol_vers = NULL;
45cd8f
diff --git a/daemons/attrd/pacemaker-attrd.h b/daemons/attrd/pacemaker-attrd.h
45cd8f
index 302ef63..bcc329d 100644
45cd8f
--- a/daemons/attrd/pacemaker-attrd.h
45cd8f
+++ b/daemons/attrd/pacemaker-attrd.h
45cd8f
@@ -191,8 +191,16 @@ enum attrd_sync_point {
45cd8f
     attrd_sync_point_cluster,
45cd8f
 };
45cd8f
 
45cd8f
+typedef int (*attrd_confirmation_action_fn)(xmlNode *);
45cd8f
+
45cd8f
 void attrd_add_client_to_waitlist(pcmk__request_t *request);
45cd8f
 void attrd_ack_waitlist_clients(enum attrd_sync_point sync_point, const xmlNode *xml);
45cd8f
+int attrd_cluster_sync_point_update(xmlNode *xml);
45cd8f
+void attrd_do_not_expect_from_peer(const char *host);
45cd8f
+void attrd_do_not_wait_for_client(pcmk__client_t *client);
45cd8f
+void attrd_expect_confirmations(pcmk__request_t *request, attrd_confirmation_action_fn fn);
45cd8f
+void attrd_free_confirmations(void);
45cd8f
+void attrd_handle_confirmation(int callid, const char *host);
45cd8f
 void attrd_remove_client_from_waitlist(pcmk__client_t *client);
45cd8f
 const char *attrd_request_sync_point(xmlNode *xml);
45cd8f
 bool attrd_request_has_sync_point(xmlNode *xml);
45cd8f
-- 
45cd8f
2.31.1
45cd8f
45cd8f
From 07a032a7eb2f03dce18a7c94c56b8c837dedda15 Mon Sep 17 00:00:00 2001
45cd8f
From: Chris Lumens <clumens@redhat.com>
45cd8f
Date: Fri, 28 Oct 2022 14:54:15 -0400
45cd8f
Subject: [PATCH 20/26] Refactor: daemons: Add some attrd version checking
45cd8f
 macros.
45cd8f
45cd8f
These are just to make it a little more obvious what is actually being
45cd8f
asked in the code, instead of having magic numbers sprinkled around.
45cd8f
---
45cd8f
 daemons/attrd/attrd_ipc.c       | 2 +-
45cd8f
 daemons/attrd/attrd_sync.c      | 2 +-
45cd8f
 daemons/attrd/pacemaker-attrd.h | 3 +++
45cd8f
 3 files changed, 5 insertions(+), 2 deletions(-)
45cd8f
45cd8f
diff --git a/daemons/attrd/attrd_ipc.c b/daemons/attrd/attrd_ipc.c
45cd8f
index c70aa1b..16bfff4 100644
45cd8f
--- a/daemons/attrd/attrd_ipc.c
45cd8f
+++ b/daemons/attrd/attrd_ipc.c
45cd8f
@@ -294,7 +294,7 @@ attrd_client_update(pcmk__request_t *request)
45cd8f
      * two ways we can handle that.
45cd8f
      */
45cd8f
     if (xml_has_children(xml)) {
45cd8f
-        if (minimum_protocol_version >= 4) {
45cd8f
+        if (ATTRD_SUPPORTS_MULTI_MESSAGE(minimum_protocol_version)) {
45cd8f
             /* First, if all peers support a certain protocol version, we can
45cd8f
              * just broadcast the big message and they'll handle it.  However,
45cd8f
              * we also need to apply all the transformations in this function
45cd8f
diff --git a/daemons/attrd/attrd_sync.c b/daemons/attrd/attrd_sync.c
45cd8f
index d3d7108..e48f82e 100644
45cd8f
--- a/daemons/attrd/attrd_sync.c
45cd8f
+++ b/daemons/attrd/attrd_sync.c
45cd8f
@@ -444,7 +444,7 @@ attrd_expect_confirmations(pcmk__request_t *request, attrd_confirmation_action_f
45cd8f
 
45cd8f
     g_hash_table_iter_init(&iter, peer_protocol_vers);
45cd8f
     while (g_hash_table_iter_next(&iter, &host, &ver)) {
45cd8f
-        if (GPOINTER_TO_INT(ver) >= 5) {
45cd8f
+        if (ATTRD_SUPPORTS_CONFIRMATION(GPOINTER_TO_INT(ver))) {
45cd8f
             char *s = strdup((char *) host);
45cd8f
 
45cd8f
             CRM_ASSERT(s != NULL);
45cd8f
diff --git a/daemons/attrd/pacemaker-attrd.h b/daemons/attrd/pacemaker-attrd.h
45cd8f
index bcc329d..83d7c6b 100644
45cd8f
--- a/daemons/attrd/pacemaker-attrd.h
45cd8f
+++ b/daemons/attrd/pacemaker-attrd.h
45cd8f
@@ -45,6 +45,9 @@
45cd8f
  */
45cd8f
 #define ATTRD_PROTOCOL_VERSION "5"
45cd8f
 
45cd8f
+#define ATTRD_SUPPORTS_MULTI_MESSAGE(x) ((x) >= 4)
45cd8f
+#define ATTRD_SUPPORTS_CONFIRMATION(x)  ((x) >= 5)
45cd8f
+
45cd8f
 #define attrd_send_ack(client, id, flags) \
45cd8f
     pcmk__ipc_send_ack((client), (id), (flags), "ack", ATTRD_PROTOCOL_VERSION, CRM_EX_INDETERMINATE)
45cd8f
 
45cd8f
-- 
45cd8f
2.31.1
45cd8f
45cd8f
From 811361b96c6f26a1f5eccc54b6e8bf6e6fd003be Mon Sep 17 00:00:00 2001
45cd8f
From: Chris Lumens <clumens@redhat.com>
45cd8f
Date: Mon, 31 Oct 2022 12:53:22 -0400
45cd8f
Subject: [PATCH 21/26] Low: attrd: Fix removing clients from the waitlist when
45cd8f
 they disconnect.
45cd8f
45cd8f
The client ID is a string, so it must be compared like a string.
45cd8f
---
45cd8f
 daemons/attrd/attrd_sync.c | 2 +-
45cd8f
 1 file changed, 1 insertion(+), 1 deletion(-)
45cd8f
45cd8f
diff --git a/daemons/attrd/attrd_sync.c b/daemons/attrd/attrd_sync.c
45cd8f
index e48f82e..c9b4784 100644
45cd8f
--- a/daemons/attrd/attrd_sync.c
45cd8f
+++ b/daemons/attrd/attrd_sync.c
45cd8f
@@ -210,7 +210,7 @@ attrd_remove_client_from_waitlist(pcmk__client_t *client)
45cd8f
     while (g_hash_table_iter_next(&iter, NULL, &value)) {
45cd8f
         struct waitlist_node *wl = (struct waitlist_node *) value;
45cd8f
 
45cd8f
-        if (wl->client_id == client->id) {
45cd8f
+        if (pcmk__str_eq(wl->client_id, client->id, pcmk__str_none)) {
45cd8f
             g_hash_table_iter_remove(&iter);
45cd8f
             crm_trace("%d clients now on waitlist", g_hash_table_size(waitlist));
45cd8f
         }
45cd8f
-- 
45cd8f
2.31.1
45cd8f
45cd8f
From 4e933ad14456af85c60701410c3b23b4eab03f86 Mon Sep 17 00:00:00 2001
45cd8f
From: Chris Lumens <clumens@redhat.com>
45cd8f
Date: Tue, 1 Nov 2022 12:35:12 -0400
45cd8f
Subject: [PATCH 22/26] Feature: daemons: Handle an attrd client timing out.
45cd8f
45cd8f
If the update confirmations do not come back in time, use a main loop
45cd8f
timer to remove the client from the table.
45cd8f
---
45cd8f
 daemons/attrd/attrd_sync.c | 49 ++++++++++++++++++++++++++++++++++++++
45cd8f
 1 file changed, 49 insertions(+)
45cd8f
45cd8f
diff --git a/daemons/attrd/attrd_sync.c b/daemons/attrd/attrd_sync.c
45cd8f
index c9b4784..9d07796 100644
45cd8f
--- a/daemons/attrd/attrd_sync.c
45cd8f
+++ b/daemons/attrd/attrd_sync.c
45cd8f
@@ -61,6 +61,12 @@ struct confirmation_action {
45cd8f
      */
45cd8f
     GList *respondents;
45cd8f
 
45cd8f
+    /*!
45cd8f
+     * \brief A timer that will be used to remove the client should it time out
45cd8f
+     *        before receiving all confirmations
45cd8f
+     */
45cd8f
+    mainloop_timer_t *timer;
45cd8f
+
45cd8f
     /*!
45cd8f
      * \brief A function to run when all confirmations have been received
45cd8f
      */
45cd8f
@@ -340,11 +346,51 @@ free_action(gpointer data)
45cd8f
 {
45cd8f
     struct confirmation_action *action = (struct confirmation_action *) data;
45cd8f
     g_list_free_full(action->respondents, free);
45cd8f
+    mainloop_timer_del(action->timer);
45cd8f
     free_xml(action->xml);
45cd8f
     free(action->client_id);
45cd8f
     free(action);
45cd8f
 }
45cd8f
 
45cd8f
+/* Remove an IPC request from the expected_confirmations table if the peer attrds
45cd8f
+ * don't respond before the timeout is hit.  We set the timeout to 15s.  The exact
45cd8f
+ * number isn't critical - we just want to make sure that the table eventually gets
45cd8f
+ * cleared of things that didn't complete.
45cd8f
+ */
45cd8f
+static gboolean
45cd8f
+confirmation_timeout_cb(gpointer data)
45cd8f
+{
45cd8f
+    struct confirmation_action *action = (struct confirmation_action *) data;
45cd8f
+
45cd8f
+    GHashTableIter iter;
45cd8f
+    gpointer value;
45cd8f
+
45cd8f
+    if (expected_confirmations == NULL) {
45cd8f
+        return G_SOURCE_REMOVE;
45cd8f
+    }
45cd8f
+
45cd8f
+    g_hash_table_iter_init(&iter, expected_confirmations);
45cd8f
+
45cd8f
+    while (g_hash_table_iter_next(&iter, NULL, &value)) {
45cd8f
+        if (value == action) {
45cd8f
+            pcmk__client_t *client = pcmk__find_client_by_id(action->client_id);
45cd8f
+            if (client == NULL) {
45cd8f
+                return G_SOURCE_REMOVE;
45cd8f
+            }
45cd8f
+
45cd8f
+            crm_trace("Timed out waiting for confirmations for client %s", client->id);
45cd8f
+            pcmk__ipc_send_ack(client, action->ipc_id, action->flags | crm_ipc_client_response,
45cd8f
+                               "ack", ATTRD_PROTOCOL_VERSION, CRM_EX_TIMEOUT);
45cd8f
+
45cd8f
+            g_hash_table_iter_remove(&iter);
45cd8f
+            crm_trace("%d requests now in expected confirmations table", g_hash_table_size(expected_confirmations));
45cd8f
+            break;
45cd8f
+        }
45cd8f
+    }
45cd8f
+
45cd8f
+    return G_SOURCE_REMOVE;
45cd8f
+}
45cd8f
+
45cd8f
 /*!
45cd8f
  * \internal
45cd8f
  * \brief When a peer disconnects from the cluster, no longer wait for its confirmation
45cd8f
@@ -465,6 +511,9 @@ attrd_expect_confirmations(pcmk__request_t *request, attrd_confirmation_action_f
45cd8f
     action->ipc_id = request->ipc_id;
45cd8f
     action->flags = request->flags;
45cd8f
 
45cd8f
+    action->timer = mainloop_timer_add(NULL, 15000, FALSE, confirmation_timeout_cb, action);
45cd8f
+    mainloop_timer_start(action->timer);
45cd8f
+
45cd8f
     pcmk__intkey_table_insert(expected_confirmations, callid, action);
45cd8f
     crm_trace("Callid %d now waiting on %d confirmations", callid, g_list_length(respondents));
45cd8f
     crm_trace("%d requests now in expected confirmations table", g_hash_table_size(expected_confirmations));
45cd8f
-- 
45cd8f
2.31.1
45cd8f
45cd8f
From 101896383cbe0103c98078e46540c076af08f040 Mon Sep 17 00:00:00 2001
45cd8f
From: Chris Lumens <clumens@redhat.com>
45cd8f
Date: Wed, 2 Nov 2022 14:40:30 -0400
45cd8f
Subject: [PATCH 23/26] Refactor: Demote a sync point related message to trace.
45cd8f
45cd8f
---
45cd8f
 daemons/attrd/attrd_corosync.c | 2 +-
45cd8f
 1 file changed, 1 insertion(+), 1 deletion(-)
45cd8f
45cd8f
diff --git a/daemons/attrd/attrd_corosync.c b/daemons/attrd/attrd_corosync.c
45cd8f
index 37701aa..5cbed7e 100644
45cd8f
--- a/daemons/attrd/attrd_corosync.c
45cd8f
+++ b/daemons/attrd/attrd_corosync.c
45cd8f
@@ -633,7 +633,7 @@ attrd_peer_update(const crm_node_t *peer, xmlNode *xml, const char *host,
45cd8f
      * point, process that now.
45cd8f
      */
45cd8f
     if (handle_sync_point) {
45cd8f
-        crm_debug("Hit local sync point for attribute update");
45cd8f
+        crm_trace("Hit local sync point for attribute update");
45cd8f
         attrd_ack_waitlist_clients(attrd_sync_point_local, xml);
45cd8f
     }
45cd8f
 }
45cd8f
-- 
45cd8f
2.31.1
45cd8f
45cd8f
From acd13246d4c2bef7982ca103e34896efcad22348 Mon Sep 17 00:00:00 2001
45cd8f
From: Chris Lumens <clumens@redhat.com>
45cd8f
Date: Thu, 3 Nov 2022 10:29:20 -0400
45cd8f
Subject: [PATCH 24/26] Low: daemons: Avoid infinite confirm loops in attrd.
45cd8f
45cd8f
On the sending side, do not add confirm="yes" to a message with
45cd8f
op="confirm".  On the receiving side, do not confirm a message with
45cd8f
op="confirm" even if confirm="yes" is set.
45cd8f
---
45cd8f
 daemons/attrd/attrd_corosync.c | 3 ++-
45cd8f
 daemons/attrd/attrd_messages.c | 6 +++++-
45cd8f
 2 files changed, 7 insertions(+), 2 deletions(-)
45cd8f
45cd8f
diff --git a/daemons/attrd/attrd_corosync.c b/daemons/attrd/attrd_corosync.c
45cd8f
index 5cbed7e..88c1ecc 100644
45cd8f
--- a/daemons/attrd/attrd_corosync.c
45cd8f
+++ b/daemons/attrd/attrd_corosync.c
45cd8f
@@ -74,7 +74,8 @@ attrd_peer_message(crm_node_t *peer, xmlNode *xml)
45cd8f
         /* Having finished handling the request, check to see if the originating
45cd8f
          * peer requested confirmation.  If so, send that confirmation back now.
45cd8f
          */
45cd8f
-        if (pcmk__xe_attr_is_true(xml, PCMK__XA_CONFIRM)) {
45cd8f
+        if (pcmk__xe_attr_is_true(xml, PCMK__XA_CONFIRM) &&
45cd8f
+            !pcmk__str_eq(request.op, PCMK__ATTRD_CMD_CONFIRM, pcmk__str_none)) {
45cd8f
             int callid = 0;
45cd8f
             xmlNode *reply = NULL;
45cd8f
 
45cd8f
diff --git a/daemons/attrd/attrd_messages.c b/daemons/attrd/attrd_messages.c
45cd8f
index f7b9c7c..184176a 100644
45cd8f
--- a/daemons/attrd/attrd_messages.c
45cd8f
+++ b/daemons/attrd/attrd_messages.c
45cd8f
@@ -310,6 +310,8 @@ attrd_broadcast_protocol(void)
45cd8f
 gboolean
45cd8f
 attrd_send_message(crm_node_t *node, xmlNode *data, bool confirm)
45cd8f
 {
45cd8f
+    const char *op = crm_element_value(data, PCMK__XA_TASK);
45cd8f
+
45cd8f
     crm_xml_add(data, F_TYPE, T_ATTRD);
45cd8f
     crm_xml_add(data, PCMK__XA_ATTR_VERSION, ATTRD_PROTOCOL_VERSION);
45cd8f
 
45cd8f
@@ -317,7 +319,9 @@ attrd_send_message(crm_node_t *node, xmlNode *data, bool confirm)
45cd8f
      * be all if node is NULL) that the message has been received and
45cd8f
      * acted upon.
45cd8f
      */
45cd8f
-    pcmk__xe_set_bool_attr(data, PCMK__XA_CONFIRM, confirm);
45cd8f
+    if (!pcmk__str_eq(op, PCMK__ATTRD_CMD_CONFIRM, pcmk__str_none)) {
45cd8f
+        pcmk__xe_set_bool_attr(data, PCMK__XA_CONFIRM, confirm);
45cd8f
+    }
45cd8f
 
45cd8f
     attrd_xml_add_writer(data);
45cd8f
     return send_cluster_message(node, crm_msg_attrd, data, TRUE);
45cd8f
-- 
45cd8f
2.31.1
45cd8f
45cd8f
From 115e6c3a0d8db4df3eccf6da1c344168799f890d Mon Sep 17 00:00:00 2001
45cd8f
From: Chris Lumens <clumens@redhat.com>
45cd8f
Date: Tue, 15 Nov 2022 09:35:28 -0500
45cd8f
Subject: [PATCH 25/26] Fix: daemons: Check for NULL in
45cd8f
 attrd_do_not_expect_from_peer.
45cd8f
45cd8f
---
45cd8f
 daemons/attrd/attrd_sync.c | 8 +++++++-
45cd8f
 1 file changed, 7 insertions(+), 1 deletion(-)
45cd8f
45cd8f
diff --git a/daemons/attrd/attrd_sync.c b/daemons/attrd/attrd_sync.c
45cd8f
index 9d07796..6936771 100644
45cd8f
--- a/daemons/attrd/attrd_sync.c
45cd8f
+++ b/daemons/attrd/attrd_sync.c
45cd8f
@@ -402,7 +402,13 @@ confirmation_timeout_cb(gpointer data)
45cd8f
 void
45cd8f
 attrd_do_not_expect_from_peer(const char *host)
45cd8f
 {
45cd8f
-    GList *keys = g_hash_table_get_keys(expected_confirmations);
45cd8f
+    GList *keys = NULL;
45cd8f
+
45cd8f
+    if (expected_confirmations == NULL) {
45cd8f
+        return;
45cd8f
+    }
45cd8f
+
45cd8f
+    keys = g_hash_table_get_keys(expected_confirmations);
45cd8f
 
45cd8f
     crm_trace("Removing peer %s from expected confirmations", host);
45cd8f
 
45cd8f
-- 
45cd8f
2.31.1
45cd8f
45cd8f
From 05da14f97ccd4f63f53801acc107ad661e5fd0c8 Mon Sep 17 00:00:00 2001
45cd8f
From: Chris Lumens <clumens@redhat.com>
45cd8f
Date: Wed, 16 Nov 2022 17:37:44 -0500
45cd8f
Subject: [PATCH 26/26] Low: daemons: Support cluster-wide sync points for
45cd8f
 multi IPC messages.
45cd8f
45cd8f
Supporting cluster-wide sync points means attrd_expect_confirmations
45cd8f
needs to be called, and then attrd_send_message needs "true" as a third
45cd8f
argument.  This indicates attrd wants confirmations back from all its
45cd8f
peers when they have applied the update.
45cd8f
45cd8f
We're already doing this at the end of attrd_client_update for
45cd8f
single-update IPC messages, and handling it for multi-update messages is
45cd8f
a simple matter of breaking that code out into a function and making
45cd8f
sure it's called.
45cd8f
45cd8f
Note that this leaves two other spots where sync points still need to be
45cd8f
dealt with:
45cd8f
45cd8f
* An update message that uses a regex.  See
45cd8f
  https://projects.clusterlabs.org/T600 for details.
45cd8f
45cd8f
* A multi-update IPC message in a cluster where that is not supported.
45cd8f
  See https://projects.clusterlabs.org/T601 for details.
45cd8f
---
45cd8f
 daemons/attrd/attrd_ipc.c | 43 ++++++++++++++++++++++-----------------
45cd8f
 1 file changed, 24 insertions(+), 19 deletions(-)
45cd8f
45cd8f
diff --git a/daemons/attrd/attrd_ipc.c b/daemons/attrd/attrd_ipc.c
45cd8f
index 16bfff4..8c5660d 100644
45cd8f
--- a/daemons/attrd/attrd_ipc.c
45cd8f
+++ b/daemons/attrd/attrd_ipc.c
45cd8f
@@ -283,6 +283,28 @@ handle_value_expansion(const char **value, xmlNode *xml, const char *op,
45cd8f
     return pcmk_rc_ok;
45cd8f
 }
45cd8f
 
45cd8f
+static void
45cd8f
+send_update_msg_to_cluster(pcmk__request_t *request, xmlNode *xml)
45cd8f
+{
45cd8f
+    if (pcmk__str_eq(attrd_request_sync_point(xml), PCMK__VALUE_CLUSTER, pcmk__str_none)) {
45cd8f
+        /* The client is waiting on the cluster-wide sync point.  In this case,
45cd8f
+         * the response ACK is not sent until this attrd broadcasts the update
45cd8f
+         * and receives its own confirmation back from all peers.
45cd8f
+         */
45cd8f
+        attrd_expect_confirmations(request, attrd_cluster_sync_point_update);
45cd8f
+        attrd_send_message(NULL, xml, true); /* ends up at attrd_peer_message() */
45cd8f
+
45cd8f
+    } else {
45cd8f
+        /* The client is either waiting on the local sync point or was not
45cd8f
+         * waiting on any sync point at all.  For the local sync point, the
45cd8f
+         * response ACK is sent in attrd_peer_update.  For clients not
45cd8f
+         * waiting on any sync point, the response ACK is sent in
45cd8f
+         * handle_update_request immediately before this function was called.
45cd8f
+         */
45cd8f
+        attrd_send_message(NULL, xml, false); /* ends up at attrd_peer_message() */
45cd8f
+    }
45cd8f
+}
45cd8f
+
45cd8f
 xmlNode *
45cd8f
 attrd_client_update(pcmk__request_t *request)
45cd8f
 {
45cd8f
@@ -314,7 +336,7 @@ attrd_client_update(pcmk__request_t *request)
45cd8f
                 }
45cd8f
             }
45cd8f
 
45cd8f
-            attrd_send_message(NULL, xml, false);
45cd8f
+            send_update_msg_to_cluster(request, xml);
45cd8f
             pcmk__set_result(&request->result, CRM_EX_OK, PCMK_EXEC_DONE, NULL);
45cd8f
 
45cd8f
         } else {
45cd8f
@@ -388,24 +410,7 @@ attrd_client_update(pcmk__request_t *request)
45cd8f
     crm_debug("Broadcasting %s[%s]=%s%s", attr, crm_element_value(xml, PCMK__XA_ATTR_NODE_NAME),
45cd8f
               value, (attrd_election_won()? " (writer)" : ""));
45cd8f
 
45cd8f
-    if (pcmk__str_eq(attrd_request_sync_point(xml), PCMK__VALUE_CLUSTER, pcmk__str_none)) {
45cd8f
-        /* The client is waiting on the cluster-wide sync point.  In this case,
45cd8f
-         * the response ACK is not sent until this attrd broadcasts the update
45cd8f
-         * and receives its own confirmation back from all peers.
45cd8f
-         */
45cd8f
-        attrd_expect_confirmations(request, attrd_cluster_sync_point_update);
45cd8f
-        attrd_send_message(NULL, xml, true); /* ends up at attrd_peer_message() */
45cd8f
-
45cd8f
-    } else {
45cd8f
-        /* The client is either waiting on the local sync point or was not
45cd8f
-         * waiting on any sync point at all.  For the local sync point, the
45cd8f
-         * response ACK is sent in attrd_peer_update.  For clients not
45cd8f
-         * waiting on any sync point, the response ACK is sent in
45cd8f
-         * handle_update_request immediately before this function was called.
45cd8f
-         */
45cd8f
-        attrd_send_message(NULL, xml, false); /* ends up at attrd_peer_message() */
45cd8f
-    }
45cd8f
-
45cd8f
+    send_update_msg_to_cluster(request, xml);
45cd8f
     pcmk__set_result(&request->result, CRM_EX_OK, PCMK_EXEC_DONE, NULL);
45cd8f
     return NULL;
45cd8f
 }
45cd8f
-- 
45cd8f
2.31.1
45cd8f