Blob Blame History Raw
From a34cafa9d69194e3cbfe3af20ceb2d08848c483c Mon Sep 17 00:00:00 2001
From: Klaus Wenninger <klaus.wenninger@aon.at>
Date: Mon, 19 Nov 2018 20:56:35 +0100
Subject: [PATCH] Refactor: use pacemaker's new pe api with
 constructors/destructors

For backward compatibility add some compatibility code
for if pe_new_working_set isn't available.
---
 configure.ac        |  3 +++
 src/sbd-pacemaker.c | 61 +++++++++++++++++++++++++++++++++++++++++++++++------
 2 files changed, 57 insertions(+), 7 deletions(-)

diff --git a/configure.ac b/configure.ac
index 1f328c2..1dc273b 100644
--- a/configure.ac
+++ b/configure.ac
@@ -76,6 +76,9 @@ dnl pacemaker-2.0 removed support for corosync 1 cluster layer
 AC_CHECK_DECLS([pcmk_cluster_classic_ais, pcmk_cluster_cman],,,
 	       [#include <pacemaker/crm/cluster.h>])
 
+dnl check for new pe-API
+AC_CHECK_FUNCS(pe_new_working_set)
+
 if test "$missing" = "yes"; then
    AC_MSG_ERROR([Missing required libraries or functions.])
 fi
diff --git a/src/sbd-pacemaker.c b/src/sbd-pacemaker.c
index a435d01..aac355a 100644
--- a/src/sbd-pacemaker.c
+++ b/src/sbd-pacemaker.c
@@ -58,6 +58,31 @@
 
 #include "sbd.h"
 
+#ifndef HAVE_PE_NEW_WORKING_SET
+
+#define pe_reset_working_set(data_set) cleanup_calculations(data_set)
+
+static pe_working_set_t *
+pe_new_working_set()
+{
+	pe_working_set_t *data_set = calloc(1, sizeof(pe_working_set_t));
+	if (data_set != NULL) {
+		set_working_set_defaults(data_set);
+	}
+	return data_set;
+}
+
+static void
+pe_free_working_set(pe_working_set_t *data_set)
+{
+	if (data_set != NULL) {
+		pe_reset_working_set(data_set);
+		free(data_set);
+	}
+}
+
+#endif
+
 extern int disk_count;
 
 static void clean_up(int rc);
@@ -74,6 +99,7 @@ static int cib_connected = 0;
 
 static cib_t *cib = NULL;
 static xmlNode *current_cib = NULL;
+static pe_working_set_t *data_set = NULL;
 
 static long last_refresh = 0;
 
@@ -361,7 +387,6 @@ static gboolean
 mon_refresh_state(gpointer user_data)
 {
     xmlNode *cib_copy = NULL;
-    pe_working_set_t data_set;
 
     if(current_cib == NULL) {
         return FALSE;
@@ -382,14 +407,13 @@ mon_refresh_state(gpointer user_data)
 
     } else {
         last_refresh = time(NULL);
-        set_working_set_defaults(&data_set);
-        data_set.input = cib_copy;
-        data_set.flags |= pe_flag_have_stonith_resource;
-        cluster_status(&data_set);
+        data_set->input = cib_copy;
+        data_set->flags |= pe_flag_have_stonith_resource;
+        cluster_status(data_set);
 
-        compute_status(&data_set);
+        compute_status(data_set);
 
-        cleanup_calculations(&data_set);
+        pe_reset_working_set(data_set);
     }
 
     return FALSE;
@@ -398,6 +422,21 @@ mon_refresh_state(gpointer user_data)
 static void
 clean_up(int rc)
 {
+	if (timer_id_reconnect > 0) {
+		g_source_remove(timer_id_reconnect);
+		timer_id_reconnect = 0;
+	}
+
+	if (timer_id_notify > 0) {
+		g_source_remove(timer_id_notify);
+		timer_id_notify = 0;
+	}
+
+	if (data_set != NULL) {
+		pe_free_working_set(data_set);
+		data_set = NULL;
+	}
+
 	if (cib != NULL) {
 		cib->cmds->signoff(cib);
 		cib_delete(cib);
@@ -425,6 +464,14 @@ servant_pcmk(const char *diskname, int mode, const void* argp)
             set_crm_log_level(LOG_CRIT);
         }
 
+
+	if (data_set == NULL) {
+		data_set = pe_new_working_set();
+	}
+	if (data_set == NULL) {
+		return -1;
+	}
+
 	if (current_cib == NULL) {
 		cib = cib_new();
 
-- 
1.8.3.1