From aee2a5af668b6e15d9da6ecbbba7521acd1f0ea1 Mon Sep 17 00:00:00 2001
From: Ken Gaillot <kgaillot@redhat.com>
Date: Wed, 7 Feb 2024 16:05:50 -0600
Subject: [PATCH 10/16] Refactor: pacemaker-attrd: rename flag to match recent
 change

---
 daemons/attrd/attrd_cib.c       | 15 +++++++++------
 daemons/attrd/pacemaker-attrd.h | 16 ++++++++++++----
 2 files changed, 21 insertions(+), 10 deletions(-)

diff --git a/daemons/attrd/attrd_cib.c b/daemons/attrd/attrd_cib.c
index 665af3625d..e7eeaa96d9 100644
--- a/daemons/attrd/attrd_cib.c
+++ b/daemons/attrd/attrd_cib.c
@@ -532,10 +532,13 @@ write_attribute(attribute_t *a, bool ignore_delay)
         }
     }
 
-    /* Attribute will be written shortly, so clear changed flag and force
-     * write flag, and initialize UUID missing flag to false.
+    /* The changed and force-write flags apply only to the next write,
+     * which this is, so clear them now. Also clear the "node unknown" flag
+     * because we will check whether it is known below and reset if appopriate.
      */
-    attrd_clear_attr_flags(a, attrd_attr_changed|attrd_attr_uuid_missing|attrd_attr_force_write);
+    attrd_clear_attr_flags(a, attrd_attr_changed
+                              |attrd_attr_force_write
+                              |attrd_attr_node_unknown);
 
     /* Make the table for the attribute trap */
     alert_attribute_value = pcmk__strikey_table(NULL,
@@ -576,7 +579,7 @@ write_attribute(attribute_t *a, bool ignore_delay)
 
         // Defer write if this is a cluster node that's never been seen
         if (node_xml_id == NULL) {
-            attrd_set_attr_flags(a, attrd_attr_uuid_missing);
+            attrd_set_attr_flags(a, attrd_attr_node_unknown);
             crm_notice("Cannot write %s[%s]='%s' to CIB because node's XML ID "
                        "is unknown (will retry if learned)",
                        a->id, v->nodename, v->current);
@@ -668,8 +671,8 @@ attrd_write_attributes(uint32_t options)
               pcmk_is_set(options, attrd_write_all)? "all" : "changed");
     g_hash_table_iter_init(&iter, attributes);
     while (g_hash_table_iter_next(&iter, NULL, (gpointer *) & a)) {
-        if (!pcmk_is_set(options, attrd_write_all) &&
-            pcmk_is_set(a->flags, attrd_attr_uuid_missing)) {
+        if (!pcmk_is_set(options, attrd_write_all)
+            && pcmk_is_set(a->flags, attrd_attr_node_unknown)) {
             // Try writing this attribute again, in case peer ID was learned
             attrd_set_attr_flags(a, attrd_attr_changed);
         } else if (pcmk_is_set(a->flags, attrd_attr_force_write)) {
diff --git a/daemons/attrd/pacemaker-attrd.h b/daemons/attrd/pacemaker-attrd.h
index 07103a6b01..f0535eabaa 100644
--- a/daemons/attrd/pacemaker-attrd.h
+++ b/daemons/attrd/pacemaker-attrd.h
@@ -115,10 +115,18 @@ void attrd_xml_add_writer(xmlNode *xml);
 
 enum attrd_attr_flags {
     attrd_attr_none         = 0U,
-    attrd_attr_changed      = (1U << 0),    // Attribute value has changed since last write
-    attrd_attr_uuid_missing = (1U << 1),    // Whether we know we're missing a peer UUID
-    attrd_attr_is_private   = (1U << 2),    // Whether to keep this attribute out of the CIB
-    attrd_attr_force_write  = (1U << 3),    // Update attribute by ignoring delay
+
+    // At least one of attribute's values has changed since last write
+    attrd_attr_changed      = (1U << 0),
+
+    // At least one of attribute's values has an unknown node XML ID
+    attrd_attr_node_unknown = (1U << 1),
+
+    // This attribute should never be written to the CIB
+    attrd_attr_is_private   = (1U << 2),
+
+    // Ignore any configured delay for next write of this attribute
+    attrd_attr_force_write  = (1U << 3),
 };
 
 typedef struct attribute_s {
-- 
2.43.0

