Blame SOURCES/009-dup-stonith.patch

60de42
From 969bbfd06476a71f66882964e5ea92b0bebbcc5b Mon Sep 17 00:00:00 2001
60de42
From: Nate Clark <nate@neworld.us>
60de42
Date: Thu, 1 Dec 2016 11:00:38 -0500
60de42
Subject: [PATCH] stonith: Check for missing params in new device and dup
60de42
60de42
device_has_duplicate would return a dup if all params in device where in dup with the same value but
60de42
if dup had a param that device did not the dup would still be considered a duplicate. This updates
60de42
the duplicate check to make sure that all keys and values overlap in both device and dup params.
60de42
---
60de42
 fencing/commands.c | 51 +++++++++++++++++++++++++++++++++------------------
60de42
 1 file changed, 33 insertions(+), 18 deletions(-)
60de42
60de42
diff --git a/fencing/commands.c b/fencing/commands.c
60de42
index a4699ee..d21e5a8 100644
60de42
--- a/fencing/commands.c
60de42
+++ b/fencing/commands.c
60de42
@@ -988,27 +988,15 @@ dynamic_list_search_cb(GPid pid, int rc, const char *output, gpointer user_data)
60de42
 
60de42
 /*!
60de42
  * \internal
60de42
- * \brief Checks to see if an identical device already exists in the device_list
60de42
+ * \brief Returns true if any key in first is not is second or second has a different value for key
60de42
  */
60de42
-static stonith_device_t *
60de42
-device_has_duplicate(stonith_device_t * device)
60de42
-{
60de42
+static int
60de42
+device_params_diff(GHashTable *first, GHashTable *second) {
60de42
     char *key = NULL;
60de42
     char *value = NULL;
60de42
     GHashTableIter gIter;
60de42
-    stonith_device_t *dup = g_hash_table_lookup(device_list, device->id);
60de42
 
60de42
-    if (!dup) {
60de42
-        crm_trace("No match for %s", device->id);
60de42
-        return NULL;
60de42
-
60de42
-    } else if (safe_str_neq(dup->agent, device->agent)) {
60de42
-        crm_trace("Different agent: %s != %s", dup->agent, device->agent);
60de42
-        return NULL;
60de42
-    }
60de42
-
60de42
-    /* Use calculate_operation_digest() here? */
60de42
-    g_hash_table_iter_init(&gIter, device->params);
60de42
+    g_hash_table_iter_init(&gIter, first);
60de42
     while (g_hash_table_iter_next(&gIter, (void **)&key, (void **)&value)) {
60de42
 
60de42
         if(strstr(key, "CRM_meta") == key) {
60de42
@@ -1016,15 +1004,42 @@ device_has_duplicate(stonith_device_t * device)
60de42
         } else if(strcmp(key, "crm_feature_set") == 0) {
60de42
             continue;
60de42
         } else {
60de42
-            char *other_value = g_hash_table_lookup(dup->params, key);
60de42
+            char *other_value = g_hash_table_lookup(second, key);
60de42
 
60de42
             if (!other_value || safe_str_neq(other_value, value)) {
60de42
                 crm_trace("Different value for %s: %s != %s", key, other_value, value);
60de42
-                return NULL;
60de42
+                return 1;
60de42
             }
60de42
         }
60de42
     }
60de42
 
60de42
+    return 0;
60de42
+}
60de42
+
60de42
+/*!
60de42
+ * \internal
60de42
+ * \brief Checks to see if an identical device already exists in the device_list
60de42
+ */
60de42
+static stonith_device_t *
60de42
+device_has_duplicate(stonith_device_t * device)
60de42
+{
60de42
+    stonith_device_t *dup = g_hash_table_lookup(device_list, device->id);
60de42
+
60de42
+    if (!dup) {
60de42
+        crm_trace("No match for %s", device->id);
60de42
+        return NULL;
60de42
+
60de42
+    } else if (safe_str_neq(dup->agent, device->agent)) {
60de42
+        crm_trace("Different agent: %s != %s", dup->agent, device->agent);
60de42
+        return NULL;
60de42
+    }
60de42
+
60de42
+    /* Use calculate_operation_digest() here? */
60de42
+    if (device_params_diff(device->params, dup->params) ||
60de42
+        device_params_diff(dup->params, device->params)) {
60de42
+        return NULL;
60de42
+    }
60de42
+
60de42
     crm_trace("Match");
60de42
     return dup;
60de42
 }
60de42
-- 
60de42
1.8.3.1
60de42