Blob Blame History Raw
From 1387ed890e3a9e246e9b9f780b2a7cb5379459ab Mon Sep 17 00:00:00 2001
From: Klaus Wenninger <klaus.wenninger@aon.at>
Date: Wed, 5 Jun 2019 11:32:49 +0200
Subject: [PATCH] Fix: sbd-cluster: periodically check corosync-daemon liveness

using votequorum_getinfo.
---
 configure.ac      | 12 +++++++++++-
 src/sbd-cluster.c | 36 ++++++++++++++++++++++++++++++++++--
 2 files changed, 45 insertions(+), 3 deletions(-)

diff --git a/configure.ac b/configure.ac
index fac26a8..c44e747 100644
--- a/configure.ac
+++ b/configure.ac
@@ -33,6 +33,7 @@ PKG_CHECK_MODULES(glib, [glib-2.0])
 dnl PKG_CHECK_MODULES(libcoroipcc, [libcoroipcc])
 
 PKG_CHECK_MODULES(cmap, [libcmap], HAVE_cmap=1, HAVE_cmap=0)
+PKG_CHECK_MODULES(votequorum, [libvotequorum], HAVE_votequorum=1, HAVE_votequorum=0)
 
 dnl pacemaker > 1.1.8
 PKG_CHECK_MODULES(pacemaker, [pacemaker, pacemaker-cib], HAVE_pacemaker=1, HAVE_pacemaker=0)
@@ -49,7 +50,12 @@ elif test $HAVE_pacemaker = 1; then
     if test $HAVE_cmap = 0; then
         AC_MSG_NOTICE(No package 'cmap' found)
     else
-	CPPFLAGS="$CPPFLAGS $cmap_CFLAGS"
+        CPPFLAGS="$CPPFLAGS $cmap_CFLAGS"
+    fi
+    if test $HAVE_votequorum = 0; then
+        AC_MSG_NOTICE(No library 'votequorum' found)
+    else
+        CPPFLAGS="$CPPFLAGS $votequorum_CFLAGS"
     fi
 fi
 
@@ -66,6 +72,7 @@ AC_CHECK_LIB(pe_rules, test_rule, , missing="yes")
 AC_CHECK_LIB(crmcluster, crm_peer_init, , missing="yes")
 AC_CHECK_LIB(uuid, uuid_unparse, , missing="yes")
 AC_CHECK_LIB(cmap, cmap_initialize, , HAVE_cmap=0)
+AC_CHECK_LIB(votequorum, votequorum_getinfo, , HAVE_votequorum=0)
 
 dnl pacemaker >= 1.1.8
 AC_CHECK_HEADERS(pacemaker/crm/cluster.h)
@@ -107,6 +114,9 @@ fi
 AC_DEFINE_UNQUOTED(CHECK_TWO_NODE, $HAVE_cmap, Turn on checking for 2-node cluster)
 AM_CONDITIONAL(CHECK_TWO_NODE, test "$HAVE_cmap" = "1")
 
+AC_DEFINE_UNQUOTED(CHECK_VOTEQUORUM_HANDLE, $HAVE_votequorum, Turn on periodic checking of votequorum-handle)
+AM_CONDITIONAL(CHECK_VOTEQUORUM_HANDLE, test "$HAVE_votequorum" = "1")
+
 CONFIGDIR=""
 AC_ARG_WITH(configdir,
     [  --with-configdir=DIR
diff --git a/src/sbd-cluster.c b/src/sbd-cluster.c
index 541212f..9fb6224 100644
--- a/src/sbd-cluster.c
+++ b/src/sbd-cluster.c
@@ -80,6 +80,12 @@ sbd_plugin_membership_dispatch(cpg_handle_t handle,
 
 #if SUPPORT_COROSYNC
 
+#if CHECK_VOTEQUORUM_HANDLE
+#include <corosync/votequorum.h>
+
+static votequorum_handle_t votequorum_handle = 0;
+#endif
+
 static bool two_node = false;
 static bool ever_seen_both = false;
 static int cpg_membership_entries = -1;
@@ -261,12 +267,32 @@ notify_timer_cb(gpointer data)
 
 #endif
         case pcmk_cluster_corosync:
+            do {
+#if SUPPORT_COROSYNC && CHECK_VOTEQUORUM_HANDLE
+                struct votequorum_info info;
+
+                if (votequorum_getinfo(votequorum_handle, 0, &info) != CS_OK) {
+
+                    votequorum_finalize(votequorum_handle);
+                    if (votequorum_initialize(&votequorum_handle, NULL) != CS_OK) {
+                        votequorum_handle = 0;
+                        break;
+                    }
+                    if (votequorum_getinfo(votequorum_handle, 0, &info) != CS_OK) {
+                        break;
+                    }
+                }
+#endif
+                notify_parent();
+            } while (0);
+            break;
+
 #if HAVE_DECL_PCMK_CLUSTER_CMAN
         case pcmk_cluster_cman:
-#endif
-            /* TODO - Make a CPG call and only call notify_parent() when we get a reply */
+
             notify_parent();
             break;
+#endif
 
         default:
             break;
@@ -533,6 +559,12 @@ find_pacemaker_remote(void)
 static void
 clean_up(int rc)
 {
+#if CHECK_VOTEQUORUM_HANDLE
+    votequorum_finalize(votequorum_handle);
+    votequorum_handle = 0; /* there isn't really an invalid handle value
+                            * just to be back where we started
+                            */
+#endif
     return;
 }
 
-- 
1.8.3.1