Blame SOURCES/0015-Refactor-use-pacemaker-s-new-pe-api-with-constructor.patch

6f8c14
From a34cafa9d69194e3cbfe3af20ceb2d08848c483c Mon Sep 17 00:00:00 2001
6f8c14
From: Klaus Wenninger <klaus.wenninger@aon.at>
6f8c14
Date: Mon, 19 Nov 2018 20:56:35 +0100
6f8c14
Subject: [PATCH] Refactor: use pacemaker's new pe api with
6f8c14
 constructors/destructors
6f8c14
6f8c14
For backward compatibility add some compatibility code
6f8c14
for if pe_new_working_set isn't available.
6f8c14
---
6f8c14
 configure.ac        |  3 +++
6f8c14
 src/sbd-pacemaker.c | 61 +++++++++++++++++++++++++++++++++++++++++++++++------
6f8c14
 2 files changed, 57 insertions(+), 7 deletions(-)
6f8c14
6f8c14
diff --git a/configure.ac b/configure.ac
6f8c14
index 1f328c2..1dc273b 100644
6f8c14
--- a/configure.ac
6f8c14
+++ b/configure.ac
6f8c14
@@ -76,6 +76,9 @@ dnl pacemaker-2.0 removed support for corosync 1 cluster layer
6f8c14
 AC_CHECK_DECLS([pcmk_cluster_classic_ais, pcmk_cluster_cman],,,
6f8c14
 	       [#include <pacemaker/crm/cluster.h>])
6f8c14
 
6f8c14
+dnl check for new pe-API
6f8c14
+AC_CHECK_FUNCS(pe_new_working_set)
6f8c14
+
6f8c14
 if test "$missing" = "yes"; then
6f8c14
    AC_MSG_ERROR([Missing required libraries or functions.])
6f8c14
 fi
6f8c14
diff --git a/src/sbd-pacemaker.c b/src/sbd-pacemaker.c
6f8c14
index a435d01..aac355a 100644
6f8c14
--- a/src/sbd-pacemaker.c
6f8c14
+++ b/src/sbd-pacemaker.c
6f8c14
@@ -58,6 +58,31 @@
6f8c14
 
6f8c14
 #include "sbd.h"
6f8c14
 
6f8c14
+#ifndef HAVE_PE_NEW_WORKING_SET
6f8c14
+
6f8c14
+#define pe_reset_working_set(data_set) cleanup_calculations(data_set)
6f8c14
+
6f8c14
+static pe_working_set_t *
6f8c14
+pe_new_working_set()
6f8c14
+{
6f8c14
+	pe_working_set_t *data_set = calloc(1, sizeof(pe_working_set_t));
6f8c14
+	if (data_set != NULL) {
6f8c14
+		set_working_set_defaults(data_set);
6f8c14
+	}
6f8c14
+	return data_set;
6f8c14
+}
6f8c14
+
6f8c14
+static void
6f8c14
+pe_free_working_set(pe_working_set_t *data_set)
6f8c14
+{
6f8c14
+	if (data_set != NULL) {
6f8c14
+		pe_reset_working_set(data_set);
6f8c14
+		free(data_set);
6f8c14
+	}
6f8c14
+}
6f8c14
+
6f8c14
+#endif
6f8c14
+
6f8c14
 extern int disk_count;
6f8c14
 
6f8c14
 static void clean_up(int rc);
6f8c14
@@ -74,6 +99,7 @@ static int cib_connected = 0;
6f8c14
 
6f8c14
 static cib_t *cib = NULL;
6f8c14
 static xmlNode *current_cib = NULL;
6f8c14
+static pe_working_set_t *data_set = NULL;
6f8c14
 
6f8c14
 static long last_refresh = 0;
6f8c14
 
6f8c14
@@ -361,7 +387,6 @@ static gboolean
6f8c14
 mon_refresh_state(gpointer user_data)
6f8c14
 {
6f8c14
     xmlNode *cib_copy = NULL;
6f8c14
-    pe_working_set_t data_set;
6f8c14
 
6f8c14
     if(current_cib == NULL) {
6f8c14
         return FALSE;
6f8c14
@@ -382,14 +407,13 @@ mon_refresh_state(gpointer user_data)
6f8c14
 
6f8c14
     } else {
6f8c14
         last_refresh = time(NULL);
6f8c14
-        set_working_set_defaults(&data_set);
6f8c14
-        data_set.input = cib_copy;
6f8c14
-        data_set.flags |= pe_flag_have_stonith_resource;
6f8c14
-        cluster_status(&data_set);
6f8c14
+        data_set->input = cib_copy;
6f8c14
+        data_set->flags |= pe_flag_have_stonith_resource;
6f8c14
+        cluster_status(data_set);
6f8c14
 
6f8c14
-        compute_status(&data_set);
6f8c14
+        compute_status(data_set);
6f8c14
 
6f8c14
-        cleanup_calculations(&data_set);
6f8c14
+        pe_reset_working_set(data_set);
6f8c14
     }
6f8c14
 
6f8c14
     return FALSE;
6f8c14
@@ -398,6 +422,21 @@ mon_refresh_state(gpointer user_data)
6f8c14
 static void
6f8c14
 clean_up(int rc)
6f8c14
 {
6f8c14
+	if (timer_id_reconnect > 0) {
6f8c14
+		g_source_remove(timer_id_reconnect);
6f8c14
+		timer_id_reconnect = 0;
6f8c14
+	}
6f8c14
+
6f8c14
+	if (timer_id_notify > 0) {
6f8c14
+		g_source_remove(timer_id_notify);
6f8c14
+		timer_id_notify = 0;
6f8c14
+	}
6f8c14
+
6f8c14
+	if (data_set != NULL) {
6f8c14
+		pe_free_working_set(data_set);
6f8c14
+		data_set = NULL;
6f8c14
+	}
6f8c14
+
6f8c14
 	if (cib != NULL) {
6f8c14
 		cib->cmds->signoff(cib);
6f8c14
 		cib_delete(cib);
6f8c14
@@ -425,6 +464,14 @@ servant_pcmk(const char *diskname, int mode, const void* argp)
6f8c14
             set_crm_log_level(LOG_CRIT);
6f8c14
         }
6f8c14
 
6f8c14
+
6f8c14
+	if (data_set == NULL) {
6f8c14
+		data_set = pe_new_working_set();
6f8c14
+	}
6f8c14
+	if (data_set == NULL) {
6f8c14
+		return -1;
6f8c14
+	}
6f8c14
+
6f8c14
 	if (current_cib == NULL) {
6f8c14
 		cib = cib_new();
6f8c14
 
6f8c14
-- 
6f8c14
1.8.3.1
6f8c14