256ebe
From 267135e74d94d8a1e56a263b37ca4689020b9e53 Mon Sep 17 00:00:00 2001
256ebe
From: Jiffin Tony Thottan <jthottan@redhat.com>
256ebe
Date: Mon, 16 Oct 2017 16:58:28 +0530
256ebe
Subject: [PATCH 055/124] Revert "storhaug HA: first step, remove resource
256ebe
 agents and setup script"
256ebe
256ebe
This reverts commit c822e354e16646adf18bbc5123798663faa543b2.
256ebe
256ebe
Label: DOWNSTREAM ONLY
256ebe
256ebe
Change-Id: Idd50fe1a5be5a3258d560518d810f9ec4c57621a
256ebe
Signed-off-by: Jiffin Tony Thottan <jthottan@redhat.com>
256ebe
Reviewed-on: https://code.engineering.redhat.com/gerrit/167104
256ebe
Reviewed-by: Soumya Koduri <skoduri@redhat.com>
256ebe
Tested-by: RHGS Build Bot <nigelb@redhat.com>
256ebe
Reviewed-by: Sunil Kumar Heggodu Gopala Acharya <sheggodu@redhat.com>
256ebe
---
256ebe
 configure.ac                         |    1 +
256ebe
 extras/ganesha/Makefile.am           |    2 +-
256ebe
 extras/ganesha/ocf/Makefile.am       |   11 +
256ebe
 extras/ganesha/ocf/ganesha_grace     |  221 +++++++
256ebe
 extras/ganesha/ocf/ganesha_mon       |  234 +++++++
256ebe
 extras/ganesha/ocf/ganesha_nfsd      |  167 +++++
256ebe
 extras/ganesha/scripts/Makefile.am   |    6 +-
256ebe
 extras/ganesha/scripts/ganesha-ha.sh | 1125 ++++++++++++++++++++++++++++++++++
256ebe
 glusterfs.spec.in                    |    8 +-
256ebe
 9 files changed, 1771 insertions(+), 4 deletions(-)
256ebe
 create mode 100644 extras/ganesha/ocf/Makefile.am
256ebe
 create mode 100644 extras/ganesha/ocf/ganesha_grace
256ebe
 create mode 100644 extras/ganesha/ocf/ganesha_mon
256ebe
 create mode 100644 extras/ganesha/ocf/ganesha_nfsd
256ebe
 create mode 100644 extras/ganesha/scripts/ganesha-ha.sh
256ebe
256ebe
diff --git a/configure.ac b/configure.ac
256ebe
index 125ae29..baa811a 100644
256ebe
--- a/configure.ac
256ebe
+++ b/configure.ac
256ebe
@@ -199,6 +199,7 @@ AC_CONFIG_FILES([Makefile
256ebe
                 extras/ganesha/Makefile
256ebe
                 extras/ganesha/config/Makefile
256ebe
                 extras/ganesha/scripts/Makefile
256ebe
+                extras/ganesha/ocf/Makefile
256ebe
                 extras/systemd/Makefile
256ebe
                 extras/systemd/glusterd.service
256ebe
                 extras/systemd/glustereventsd.service
256ebe
diff --git a/extras/ganesha/Makefile.am b/extras/ganesha/Makefile.am
256ebe
index 542de68..9eaa401 100644
256ebe
--- a/extras/ganesha/Makefile.am
256ebe
+++ b/extras/ganesha/Makefile.am
256ebe
@@ -1,2 +1,2 @@
256ebe
-SUBDIRS = scripts config
256ebe
+SUBDIRS = scripts config ocf
256ebe
 CLEANFILES =
256ebe
diff --git a/extras/ganesha/ocf/Makefile.am b/extras/ganesha/ocf/Makefile.am
256ebe
new file mode 100644
256ebe
index 0000000..990a609
256ebe
--- /dev/null
256ebe
+++ b/extras/ganesha/ocf/Makefile.am
256ebe
@@ -0,0 +1,11 @@
256ebe
+EXTRA_DIST= ganesha_grace ganesha_mon ganesha_nfsd
256ebe
+
256ebe
+# The root of the OCF resource agent hierarchy
256ebe
+# Per the OCF standard, it's always "lib",
256ebe
+# not "lib64" (even on 64-bit platforms).
256ebe
+ocfdir = $(prefix)/lib/ocf
256ebe
+
256ebe
+# The provider directory
256ebe
+radir = $(ocfdir)/resource.d/heartbeat
256ebe
+
256ebe
+ra_SCRIPTS = ganesha_grace ganesha_mon ganesha_nfsd
256ebe
diff --git a/extras/ganesha/ocf/ganesha_grace b/extras/ganesha/ocf/ganesha_grace
256ebe
new file mode 100644
256ebe
index 0000000..825f716
256ebe
--- /dev/null
256ebe
+++ b/extras/ganesha/ocf/ganesha_grace
256ebe
@@ -0,0 +1,221 @@
256ebe
+#!/bin/bash
256ebe
+#
256ebe
+# Copyright (c) 2014 Anand Subramanian anands@redhat.com
256ebe
+# Copyright (c) 2015 Red Hat Inc.
256ebe
+#                    All Rights Reserved.
256ebe
+#
256ebe
+# This program is free software; you can redistribute it and/or modify
256ebe
+# it under the terms of version 2 of the GNU General Public License as
256ebe
+# published by the Free Software Foundation.
256ebe
+#
256ebe
+# This program is distributed in the hope that it would be useful, but
256ebe
+# WITHOUT ANY WARRANTY; without even the implied warranty of
256ebe
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
256ebe
+#
256ebe
+# Further, this software is distributed without any warranty that it is
256ebe
+# free of the rightful claim of any third person regarding infringement
256ebe
+# or the like.  Any license provided herein, whether implied or
256ebe
+# otherwise, applies only to this software file.  Patent licenses, if
256ebe
+# any, provided herein do not apply to combinations of this program with
256ebe
+# other software, or any other product whatsoever.
256ebe
+#
256ebe
+# You should have received a copy of the GNU General Public License
256ebe
+# along with this program; if not, write the Free Software Foundation,
256ebe
+# Inc., 59 Temple Place - Suite 330, Boston MA 02111-1307, USA.
256ebe
+#
256ebe
+#
256ebe
+
256ebe
+# Initialization:
256ebe
+: ${OCF_FUNCTIONS_DIR=${OCF_ROOT}/lib/heartbeat}
256ebe
+. ${OCF_FUNCTIONS_DIR}/ocf-shellfuncs
256ebe
+
256ebe
+if [ -n "$OCF_DEBUG_LIBRARY" ]; then
256ebe
+	. $OCF_DEBUG_LIBRARY
256ebe
+else
256ebe
+	: ${OCF_FUNCTIONS_DIR=${OCF_ROOT}/lib/heartbeat}
256ebe
+	. ${OCF_FUNCTIONS_DIR}/ocf-shellfuncs
256ebe
+fi
256ebe
+
256ebe
+OCF_RESKEY_grace_active_default="grace-active"
256ebe
+: ${OCF_RESKEY_grace_active=${OCF_RESKEY_grace_active_default}}
256ebe
+
256ebe
+ganesha_meta_data() {
256ebe
+	cat <
256ebe
+
256ebe
+
256ebe
+<resource-agent name="ganesha_grace">
256ebe
+<version>1.0</version>
256ebe
+
256ebe
+<longdesc lang="en">
256ebe
+This Linux-specific resource agent acts as a dummy
256ebe
+resource agent for nfs-ganesha.
256ebe
+</longdesc>
256ebe
+
256ebe
+<shortdesc lang="en">Manages the user-space nfs-ganesha NFS server</shortdesc>
256ebe
+
256ebe
+<parameters>
256ebe
+<parameter name="grace_active">
256ebe
+<longdesc lang="en">NFS-Ganesha grace active attribute</longdesc>
256ebe
+<shortdesc lang="en">NFS-Ganesha grace active attribute</shortdesc>
256ebe
+<content type="string" default="grace-active" />
256ebe
+</parameter>
256ebe
+</parameters>
256ebe
+
256ebe
+<actions>
256ebe
+<action name="start"   timeout="40s" />
256ebe
+<action name="stop"    timeout="40s" />
256ebe
+<action name="status"  timeout="20s" interval="60s" />
256ebe
+<action name="monitor" depth="0" timeout="10s" interval="5s" />
256ebe
+<action name="notify"  timeout="10s" />
256ebe
+<action name="meta-data"  timeout="20s" />
256ebe
+</actions>
256ebe
+</resource-agent>
256ebe
+END
256ebe
+
256ebe
+return ${OCF_SUCCESS}
256ebe
+}
256ebe
+
256ebe
+ganesha_grace_usage() {
256ebe
+	echo "ganesha.nfsd USAGE"
256ebe
+}
256ebe
+
256ebe
+# Make sure meta-data and usage always succeed
256ebe
+case $__OCF_ACTION in
256ebe
+	meta-data)	ganesha_meta_data
256ebe
+			exit ${OCF_SUCCESS}
256ebe
+			;;
256ebe
+	usage|help)	ganesha_usage
256ebe
+			exit ${OCF_SUCCESS}
256ebe
+			;;
256ebe
+	*)
256ebe
+			;;
256ebe
+esac
256ebe
+
256ebe
+ganesha_grace_start()
256ebe
+{
256ebe
+	local rc=${OCF_ERR_GENERIC}
256ebe
+	local host=$(hostname -s)
256ebe
+
256ebe
+	ocf_log debug "ganesha_grace_start()"
256ebe
+	# give ganesha_mon RA a chance to set the crm_attr first
256ebe
+	# I mislike the sleep, but it's not clear that looping
256ebe
+	# with a small sleep is necessarily better
256ebe
+	# start has a 40sec timeout, so a 5sec sleep here is okay
256ebe
+        sleep 5
256ebe
+	attr=$(crm_attribute --query --node=${host} --name=${OCF_RESKEY_grace_active} 2> /dev/null)
256ebe
+        if [ $? -ne 0 ]; then
256ebe
+		host=$(hostname)
256ebe
+		attr=$(crm_attribute --query --node=${host} --name=${OCF_RESKEY_grace_active} 2> /dev/null )
256ebe
+                if [ $? -ne 0 ]; then
256ebe
+	                ocf_log info "grace start: crm_attribute --query --node=${host} --name=${OCF_RESKEY_grace_active} failed"
256ebe
+                fi
256ebe
+        fi
256ebe
+
256ebe
+	# Three possibilities:
256ebe
+	# 1. There is no attribute at all and attr_updater returns
256ebe
+	#    a zero length string. This happens when
256ebe
+	#    ganesha_mon::monitor hasn't run at least once to set
256ebe
+	#    the attribute. The assumption here is that the system
256ebe
+	#    is coming up. We pretend, for now, that the node is
256ebe
+	#    healthy, to allow the system to continue coming up.
256ebe
+	#    It will cure itself in a few seconds
256ebe
+	# 2. There is an attribute, and it has the value "1"; this
256ebe
+	#    node is healthy.
256ebe
+	# 3. There is an attribute, but it has no value or the value
256ebe
+	#    "0"; this node is not healthy.
256ebe
+
256ebe
+	# case 1
256ebe
+	if [[ -z "${attr}" ]]; then
256ebe
+		return ${OCF_SUCCESS}
256ebe
+	fi
256ebe
+
256ebe
+	# case 2
256ebe
+	if [[ "${attr}" = *"value=1" ]]; then
256ebe
+		return ${OCF_SUCCESS}
256ebe
+	fi
256ebe
+
256ebe
+	# case 3
256ebe
+	return ${OCF_NOT_RUNNING}
256ebe
+}
256ebe
+
256ebe
+ganesha_grace_stop()
256ebe
+{
256ebe
+
256ebe
+	ocf_log debug "ganesha_grace_stop()"
256ebe
+	return ${OCF_SUCCESS}
256ebe
+}
256ebe
+
256ebe
+ganesha_grace_notify()
256ebe
+{
256ebe
+        # since this is a clone RA we should only ever see pre-start
256ebe
+        # or post-stop
256ebe
+	mode="${OCF_RESKEY_CRM_meta_notify_type}-${OCF_RESKEY_CRM_meta_notify_operation}"
256ebe
+	case "${mode}" in
256ebe
+	pre-start | post-stop)
256ebe
+		dbus-send --print-reply --system --dest=org.ganesha.nfsd /org/ganesha/nfsd/admin org.ganesha.nfsd.admin.grace string:${OCF_RESKEY_CRM_meta_notify_stop_uname}
256ebe
+		if [ $? -ne 0 ]; then
256ebe
+			ocf_log info "dbus-send --print-reply --system --dest=org.ganesha.nfsd /org/ganesha/nfsd/admin org.ganesha.nfsd.admin.grace string:${OCF_RESKEY_CRM_meta_notify_stop_uname} failed"
256ebe
+		fi
256ebe
+		;;
256ebe
+	esac
256ebe
+
256ebe
+	return ${OCF_SUCCESS}
256ebe
+}
256ebe
+
256ebe
+ganesha_grace_monitor()
256ebe
+{
256ebe
+	local host=$(hostname -s)
256ebe
+
256ebe
+	ocf_log debug "monitor"
256ebe
+
256ebe
+	attr=$(crm_attribute --query --node=${host} --name=${OCF_RESKEY_grace_active} 2> /dev/null)
256ebe
+        if [ $? -ne 0 ]; then
256ebe
+		host=$(hostname)
256ebe
+	        attr=$(crm_attribute --query --node=${host} --name=${OCF_RESKEY_grace_active} 2> /dev/null)
256ebe
+                if [ $? -ne 0 ]; then
256ebe
+	                ocf_log info "crm_attribute --query --node=${host} --name=${OCF_RESKEY_grace_active} failed"
256ebe
+                fi
256ebe
+        fi
256ebe
+
256ebe
+	# if there is no attribute (yet), maybe it's because
256ebe
+	# this RA started before ganesha_mon (nfs-mon) has had
256ebe
+	# chance to create it. In which case we'll pretend
256ebe
+	# everything is okay this time around
256ebe
+	if [[ -z "${attr}" ]]; then
256ebe
+		return ${OCF_SUCCESS}
256ebe
+	fi
256ebe
+
256ebe
+	if [[ "${attr}" = *"value=1" ]]; then
256ebe
+		return ${OCF_SUCCESS}
256ebe
+	fi
256ebe
+
256ebe
+	return ${OCF_NOT_RUNNING}
256ebe
+}
256ebe
+
256ebe
+ganesha_grace_validate()
256ebe
+{
256ebe
+	return ${OCF_SUCCESS}
256ebe
+}
256ebe
+
256ebe
+ganesha_grace_validate
256ebe
+
256ebe
+# Translate each action into the appropriate function call
256ebe
+case $__OCF_ACTION in
256ebe
+start)          ganesha_grace_start
256ebe
+		;;
256ebe
+stop)           ganesha_grace_stop
256ebe
+		;;
256ebe
+status|monitor) ganesha_grace_monitor
256ebe
+		;;
256ebe
+notify)         ganesha_grace_notify
256ebe
+		;;
256ebe
+*)              ganesha_grace_usage
256ebe
+		exit ${OCF_ERR_UNIMPLEMENTED}
256ebe
+		;;
256ebe
+esac
256ebe
+
256ebe
+rc=$?
256ebe
+
256ebe
+# The resource agent may optionally log a debug message
256ebe
+ocf_log debug "${OCF_RESOURCE_INSTANCE} ${__OCF_ACTION} returned $rc"
256ebe
+exit $rc
256ebe
diff --git a/extras/ganesha/ocf/ganesha_mon b/extras/ganesha/ocf/ganesha_mon
256ebe
new file mode 100644
256ebe
index 0000000..2b4a9d6
256ebe
--- /dev/null
256ebe
+++ b/extras/ganesha/ocf/ganesha_mon
256ebe
@@ -0,0 +1,234 @@
256ebe
+#!/bin/bash
256ebe
+#
256ebe
+# Copyright (c) 2014 Anand Subramanian anands@redhat.com
256ebe
+# Copyright (c) 2015 Red Hat Inc.
256ebe
+#                    All Rights Reserved.
256ebe
+#
256ebe
+# This program is free software; you can redistribute it and/or modify
256ebe
+# it under the terms of version 2 of the GNU General Public License as
256ebe
+# published by the Free Software Foundation.
256ebe
+#
256ebe
+# This program is distributed in the hope that it would be useful, but
256ebe
+# WITHOUT ANY WARRANTY; without even the implied warranty of
256ebe
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
256ebe
+#
256ebe
+# Further, this software is distributed without any warranty that it is
256ebe
+# free of the rightful claim of any third person regarding infringement
256ebe
+# or the like.  Any license provided herein, whether implied or
256ebe
+# otherwise, applies only to this software file.  Patent licenses, if
256ebe
+# any, provided herein do not apply to combinations of this program with
256ebe
+# other software, or any other product whatsoever.
256ebe
+#
256ebe
+# You should have received a copy of the GNU General Public License
256ebe
+# along with this program; if not, write the Free Software Foundation,
256ebe
+# Inc., 59 Temple Place - Suite 330, Boston MA 02111-1307, USA.
256ebe
+#
256ebe
+#
256ebe
+
256ebe
+# Initialization:
256ebe
+: ${OCF_FUNCTIONS_DIR=${OCF_ROOT}/lib/heartbeat}
256ebe
+. ${OCF_FUNCTIONS_DIR}/ocf-shellfuncs
256ebe
+
256ebe
+if [ -n "${OCF_DEBUG_LIBRARY}" ]; then
256ebe
+	. ${OCF_DEBUG_LIBRARY}
256ebe
+else
256ebe
+	: ${OCF_FUNCTIONS_DIR=${OCF_ROOT}/lib/heartbeat}
256ebe
+	. ${OCF_FUNCTIONS_DIR}/ocf-shellfuncs
256ebe
+fi
256ebe
+
256ebe
+# Defaults
256ebe
+OCF_RESKEY_ganesha_active_default="ganesha-active"
256ebe
+OCF_RESKEY_grace_active_default="grace-active"
256ebe
+OCF_RESKEY_grace_delay_default="5"
256ebe
+
256ebe
+: ${OCF_RESKEY_ganesha_active=${OCF_RESKEY_ganesha_active_default}}
256ebe
+: ${OCF_RESKEY_grace_active=${OCF_RESKEY_grace_active_default}}
256ebe
+: ${OCF_RESKEY_grace_delay=${OCF_RESKEY_grace_delay_default}}
256ebe
+
256ebe
+ganesha_meta_data() {
256ebe
+	cat <
256ebe
+
256ebe
+
256ebe
+<resource-agent name="ganesha_mon">
256ebe
+<version>1.0</version>
256ebe
+
256ebe
+<longdesc lang="en">
256ebe
+This Linux-specific resource agent acts as a dummy
256ebe
+resource agent for nfs-ganesha.
256ebe
+</longdesc>
256ebe
+
256ebe
+<shortdesc lang="en">Manages the user-space nfs-ganesha NFS server</shortdesc>
256ebe
+
256ebe
+<parameters>
256ebe
+<parameter name="ganesha_active">
256ebe
+<longdesc lang="en">NFS-Ganesha daemon active attribute</longdesc>
256ebe
+<shortdesc lang="en">NFS-Ganesha daemon active attribute</shortdesc>
256ebe
+<content type="string" default="ganesha-active" />
256ebe
+</parameter>
256ebe
+<parameter name="grace_active">
256ebe
+<longdesc lang="en">NFS-Ganesha grace active attribute</longdesc>
256ebe
+<shortdesc lang="en">NFS-Ganesha grace active attribute</shortdesc>
256ebe
+<content type="string" default="grace-active" />
256ebe
+</parameter>
256ebe
+<parameter name="grace_delay">
256ebe
+<longdesc lang="en">
256ebe
+NFS-Ganesha grace delay.
256ebe
+When changing this, adjust the ganesha_grace RA's monitor interval to match.
256ebe
+</longdesc>
256ebe
+<shortdesc lang="en">NFS-Ganesha grace delay</shortdesc>
256ebe
+<content type="string" default="5" />
256ebe
+</parameter>
256ebe
+</parameters>
256ebe
+
256ebe
+<actions>
256ebe
+<action name="start"   timeout="40s" />
256ebe
+<action name="stop"    timeout="40s" />
256ebe
+<action name="status"  timeout="20s" interval="60s" />
256ebe
+<action name="monitor" depth="0"  timeout="10s" interval="10s" />
256ebe
+<action name="meta-data"  timeout="20s" />
256ebe
+</actions>
256ebe
+</resource-agent>
256ebe
+END
256ebe
+
256ebe
+return ${OCF_SUCCESS}
256ebe
+}
256ebe
+
256ebe
+ganesha_mon_usage() {
256ebe
+	echo "ganesha.nfsd USAGE"
256ebe
+}
256ebe
+
256ebe
+# Make sure meta-data and usage always succeed
256ebe
+case ${__OCF_ACTION} in
256ebe
+	meta-data)	ganesha_meta_data
256ebe
+			exit ${OCF_SUCCESS}
256ebe
+			;;
256ebe
+	usage|help)	ganesha_usage
256ebe
+			exit ${OCF_SUCCESS}
256ebe
+			;;
256ebe
+	*)
256ebe
+			;;
256ebe
+esac
256ebe
+
256ebe
+ganesha_mon_start()
256ebe
+{
256ebe
+	ocf_log debug "ganesha_mon_start"
256ebe
+	ganesha_mon_monitor
256ebe
+	return $OCF_SUCCESS
256ebe
+}
256ebe
+
256ebe
+ganesha_mon_stop()
256ebe
+{
256ebe
+	ocf_log debug "ganesha_mon_stop"
256ebe
+	return $OCF_SUCCESS
256ebe
+}
256ebe
+
256ebe
+ganesha_mon_monitor()
256ebe
+{
256ebe
+	local host=$(hostname -s)
256ebe
+	local pid_file="/var/run/ganesha.pid"
256ebe
+	local rhel6_pid_file="/var/run/ganesha.nfsd.pid"
256ebe
+	local proc_pid="/proc/"
256ebe
+
256ebe
+	# RHEL6 /etc/init.d/nfs-ganesha adds -p /var/run/ganesha.nfsd.pid
256ebe
+	# RHEL7 systemd does not. Would be nice if all distros used the
256ebe
+	# same pid file.
256ebe
+	if [ -e ${rhel6_pid_file} ]; then
256ebe
+		pid_file=${rhel6_pid_file}
256ebe
+	fi
256ebe
+	if [ -e ${pid_file} ]; then
256ebe
+		proc_pid="${proc_pid}$(cat ${pid_file})"
256ebe
+	fi
256ebe
+
256ebe
+	if [ "x${proc_pid}" != "x/proc/" -a -d ${proc_pid} ]; then
256ebe
+
256ebe
+		attrd_updater -n ${OCF_RESKEY_ganesha_active} -v 1
256ebe
+		if [ $? -ne 0 ]; then
256ebe
+			ocf_log info "warning: attrd_updater -n ${OCF_RESKEY_ganesha_active} -v 1 failed"
256ebe
+		fi
256ebe
+
256ebe
+		# ganesha_grace (nfs-grace) RA follows grace-active attr
256ebe
+		# w/ constraint location
256ebe
+		attrd_updater -n ${OCF_RESKEY_grace_active} -v 1
256ebe
+		if [ $? -ne 0 ]; then
256ebe
+			ocf_log info "warning: attrd_updater -n ${OCF_RESKEY_grace_active} -v 1 failed"
256ebe
+		fi
256ebe
+
256ebe
+		# ganesha_mon (nfs-mon) and ganesha_grace (nfs-grace)
256ebe
+		# track grace-active crm_attr (attr != crm_attr)
256ebe
+		# we can't just use the attr as there's no way to query
256ebe
+		# its value in RHEL6 pacemaker
256ebe
+
256ebe
+		crm_attribute --node=${host} --lifetime=forever --name=${OCF_RESKEY_grace_active} --update=1 2> /dev/null
256ebe
+		if [ $? -ne 0 ]; then
256ebe
+			host=$(hostname)
256ebe
+			crm_attribute --node=${host} --lifetime=forever --name=${OCF_RESKEY_grace_active} --update=1 2> /dev/null
256ebe
+			if [ $? -ne 0 ]; then
256ebe
+				ocf_log info "mon monitor warning: crm_attribute --node=${host} --lifetime=forever --name=${OCF_RESKEY_grace_active} --update=1 failed"
256ebe
+			fi
256ebe
+		fi
256ebe
+
256ebe
+		return ${OCF_SUCCESS}
256ebe
+	fi
256ebe
+
256ebe
+	# VIP fail-over is triggered by clearing the
256ebe
+	# ganesha-active node attribute on this node.
256ebe
+	#
256ebe
+	# Meanwhile the ganesha_grace notify() runs when its
256ebe
+	# nfs-grace resource is disabled on a node; which
256ebe
+	# is triggered by clearing the grace-active attribute
256ebe
+	# on this node.
256ebe
+	#
256ebe
+	# We need to allow time for it to run and put
256ebe
+	# the remaining ganesha.nfsds into grace before
256ebe
+	# initiating the VIP fail-over.
256ebe
+
256ebe
+	attrd_updater -D -n ${OCF_RESKEY_grace_active}
256ebe
+	if [ $? -ne 0 ]; then
256ebe
+		ocf_log info "warning: attrd_updater -D -n ${OCF_RESKEY_grace_active} failed"
256ebe
+	fi
256ebe
+
256ebe
+	host=$(hostname -s)
256ebe
+	crm_attribute --node=${host} --name=${OCF_RESKEY_grace_active} --update=0 2> /dev/null
256ebe
+	if [ $? -ne 0 ]; then
256ebe
+		host=$(hostname)
256ebe
+		crm_attribute --node=${host} --name=${OCF_RESKEY_grace_active} --update=0 2> /dev/null
256ebe
+		if [ $? -ne 0 ]; then
256ebe
+			ocf_log info "mon monitor warning: crm_attribute --node=${host} --name=${OCF_RESKEY_grace_active} --update=0 failed"
256ebe
+		fi
256ebe
+	fi
256ebe
+
256ebe
+	sleep ${OCF_RESKEY_grace_delay}
256ebe
+
256ebe
+	attrd_updater -D -n ${OCF_RESKEY_ganesha_active}
256ebe
+	if [ $? -ne 0 ]; then
256ebe
+		ocf_log info "warning: attrd_updater -D -n ${OCF_RESKEY_ganesha_active} failed"
256ebe
+	fi
256ebe
+
256ebe
+	return ${OCF_SUCCESS}
256ebe
+}
256ebe
+
256ebe
+ganesha_mon_validate()
256ebe
+{
256ebe
+	return ${OCF_SUCCESS}
256ebe
+}
256ebe
+
256ebe
+ganesha_mon_validate
256ebe
+
256ebe
+# Translate each action into the appropriate function call
256ebe
+case ${__OCF_ACTION} in
256ebe
+start)          ganesha_mon_start
256ebe
+		;;
256ebe
+stop)           ganesha_mon_stop
256ebe
+		;;
256ebe
+status|monitor) ganesha_mon_monitor
256ebe
+		;;
256ebe
+*)              ganesha_mon_usage
256ebe
+		exit ${OCF_ERR_UNIMPLEMENTED}
256ebe
+		;;
256ebe
+esac
256ebe
+
256ebe
+rc=$?
256ebe
+
256ebe
+# The resource agent may optionally log a debug message
256ebe
+ocf_log debug "${OCF_RESOURCE_INSTANCE} ${__OCF_ACTION} returned $rc"
256ebe
+exit $rc
256ebe
diff --git a/extras/ganesha/ocf/ganesha_nfsd b/extras/ganesha/ocf/ganesha_nfsd
256ebe
new file mode 100644
256ebe
index 0000000..93fc8be
256ebe
--- /dev/null
256ebe
+++ b/extras/ganesha/ocf/ganesha_nfsd
256ebe
@@ -0,0 +1,167 @@
256ebe
+#!/bin/bash
256ebe
+#
256ebe
+# Copyright (c) 2014 Anand Subramanian anands@redhat.com
256ebe
+# Copyright (c) 2015 Red Hat Inc.
256ebe
+#                    All Rights Reserved.
256ebe
+#
256ebe
+# This program is free software; you can redistribute it and/or modify
256ebe
+# it under the terms of version 2 of the GNU General Public License as
256ebe
+# published by the Free Software Foundation.
256ebe
+#
256ebe
+# This program is distributed in the hope that it would be useful, but
256ebe
+# WITHOUT ANY WARRANTY; without even the implied warranty of
256ebe
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
256ebe
+#
256ebe
+# Further, this software is distributed without any warranty that it is
256ebe
+# free of the rightful claim of any third person regarding infringement
256ebe
+# or the like.  Any license provided herein, whether implied or
256ebe
+# otherwise, applies only to this software file.  Patent licenses, if
256ebe
+# any, provided herein do not apply to combinations of this program with
256ebe
+# other software, or any other product whatsoever.
256ebe
+#
256ebe
+# You should have received a copy of the GNU General Public License
256ebe
+# along with this program; if not, write the Free Software Foundation,
256ebe
+# Inc., 59 Temple Place - Suite 330, Boston MA 02111-1307, USA.
256ebe
+#
256ebe
+#
256ebe
+
256ebe
+# Initialization:
256ebe
+: ${OCF_FUNCTIONS_DIR=${OCF_ROOT}/lib/heartbeat}
256ebe
+. ${OCF_FUNCTIONS_DIR}/ocf-shellfuncs
256ebe
+
256ebe
+if [ -n "${OCF_DEBUG_LIBRARY}" ]; then
256ebe
+	. ${OCF_DEBUG_LIBRARY}
256ebe
+else
256ebe
+	: ${OCF_FUNCTIONS_DIR=${OCF_ROOT}/lib/heartbeat}
256ebe
+	. ${OCF_FUNCTIONS_DIR}/ocf-shellfuncs
256ebe
+fi
256ebe
+
256ebe
+OCF_RESKEY_ha_vol_mnt_default="/var/run/gluster/shared_storage"
256ebe
+: ${OCF_RESKEY_ha_vol_mnt=${OCF_RESKEY_ha_vol_mnt_default}}
256ebe
+
256ebe
+ganesha_meta_data() {
256ebe
+	cat <
256ebe
+
256ebe
+
256ebe
+<resource-agent name="ganesha_nfsd">
256ebe
+<version>1.0</version>
256ebe
+
256ebe
+<longdesc lang="en">
256ebe
+This Linux-specific resource agent acts as a dummy
256ebe
+resource agent for nfs-ganesha.
256ebe
+</longdesc>
256ebe
+
256ebe
+<shortdesc lang="en">Manages the user-space nfs-ganesha NFS server</shortdesc>
256ebe
+
256ebe
+<parameters>
256ebe
+<parameter name="ha_vol_mnt">
256ebe
+<longdesc lang="en">HA State Volume Mount Point</longdesc>
256ebe
+<shortdesc lang="en">HA_State Volume Mount Point</shortdesc>
256ebe
+<content type="string" default="" />
256ebe
+</parameter>
256ebe
+</parameters>
256ebe
+
256ebe
+<actions>
256ebe
+<action name="start"   timeout="5s" />
256ebe
+<action name="stop"    timeout="5s" />
256ebe
+<action name="status" depth="0"  timeout="5s" interval="0" />
256ebe
+<action name="monitor" depth="0"  timeout="5s" interval="0" />
256ebe
+<action name="meta-data"  timeout="20s" />
256ebe
+</actions>
256ebe
+</resource-agent>
256ebe
+END
256ebe
+
256ebe
+return ${OCF_SUCCESS}
256ebe
+}
256ebe
+
256ebe
+ganesha_nfsd_usage() {
256ebe
+	echo "ganesha.nfsd USAGE"
256ebe
+}
256ebe
+
256ebe
+# Make sure meta-data and usage always succeed
256ebe
+case $__OCF_ACTION in
256ebe
+	meta-data)	ganesha_meta_data
256ebe
+			exit ${OCF_SUCCESS}
256ebe
+			;;
256ebe
+	usage|help)	ganesha_usage
256ebe
+			exit ${OCF_SUCCESS}
256ebe
+			;;
256ebe
+	*)
256ebe
+			;;
256ebe
+esac
256ebe
+
256ebe
+ganesha_nfsd_start()
256ebe
+{
256ebe
+	local long_host=$(hostname)
256ebe
+
256ebe
+	if [[ -d /var/lib/nfs ]]; then
256ebe
+		mv /var/lib/nfs /var/lib/nfs.backup
256ebe
+		if [ $? -ne 0 ]; then
256ebe
+			ocf_log notice "mv /var/lib/nfs /var/lib/nfs.backup failed"
256ebe
+		fi
256ebe
+		ln -s ${OCF_RESKEY_ha_vol_mnt}/nfs-ganesha/${long_host}/nfs /var/lib/nfs
256ebe
+		if [ $? -ne 0 ]; then
256ebe
+			ocf_log notice "ln -s ${OCF_RESKEY_ha_vol_mnt}/nfs-ganesha/${long_host}/nfs /var/lib/nfs failed"
256ebe
+		fi
256ebe
+	fi
256ebe
+
256ebe
+	return ${OCF_SUCCESS}
256ebe
+}
256ebe
+
256ebe
+ganesha_nfsd_stop()
256ebe
+{
256ebe
+
256ebe
+	if [ -L /var/lib/nfs -a -d /var/lib/nfs.backup ]; then
256ebe
+		rm -f /var/lib/nfs
256ebe
+		if [ $? -ne 0 ]; then
256ebe
+			ocf_log notice "rm -f /var/lib/nfs failed"
256ebe
+		fi
256ebe
+		mv /var/lib/nfs.backup /var/lib/nfs
256ebe
+		if [ $? -ne 0 ]; then
256ebe
+			ocf_log notice "mv /var/lib/nfs.backup /var/lib/nfs failed"
256ebe
+		fi
256ebe
+	fi
256ebe
+
256ebe
+	return ${OCF_SUCCESS}
256ebe
+}
256ebe
+
256ebe
+ganesha_nfsd_monitor()
256ebe
+{
256ebe
+	# pacemaker checks to see if RA is already running before starting it.
256ebe
+	# if we return success, then it's presumed it's already running and
256ebe
+	# doesn't need to be started, i.e. invoke the start action.
256ebe
+	# return something other than success to make pacemaker invoke the
256ebe
+	# start action
256ebe
+	if [[ -L /var/lib/nfs ]]; then
256ebe
+		return ${OCF_SUCCESS}
256ebe
+	fi
256ebe
+	return ${OCF_NOT_RUNNING}
256ebe
+}
256ebe
+
256ebe
+ganesha_nfsd_validate()
256ebe
+{
256ebe
+	return ${OCF_SUCCESS}
256ebe
+}
256ebe
+
256ebe
+ganesha_nfsd_validate
256ebe
+
256ebe
+# ocf_log notice "ganesha_nfsd ${OCF_RESOURCE_INSTANCE} $__OCF_ACTION"
256ebe
+
256ebe
+# Translate each action into the appropriate function call
256ebe
+case $__OCF_ACTION in
256ebe
+start)          ganesha_nfsd_start
256ebe
+		;;
256ebe
+stop)           ganesha_nfsd_stop
256ebe
+		;;
256ebe
+status|monitor) ganesha_nfsd_monitor
256ebe
+		;;
256ebe
+*)              ganesha_nfsd_usage
256ebe
+		exit ${OCF_ERR_UNIMPLEMENTED}
256ebe
+		;;
256ebe
+esac
256ebe
+
256ebe
+rc=$?
256ebe
+
256ebe
+# The resource agent may optionally log a debug message
256ebe
+ocf_log debug "${OCF_RESOURCE_INSTANCE} ${__OCF_ACTION} returned $rc"
256ebe
+exit $rc
256ebe
diff --git a/extras/ganesha/scripts/Makefile.am b/extras/ganesha/scripts/Makefile.am
256ebe
index 00a2c45..7e345fd 100644
256ebe
--- a/extras/ganesha/scripts/Makefile.am
256ebe
+++ b/extras/ganesha/scripts/Makefile.am
256ebe
@@ -1,4 +1,6 @@
256ebe
-EXTRA_DIST= create-export-ganesha.sh generate-epoch.py dbus-send.sh
256ebe
+EXTRA_DIST= create-export-ganesha.sh generate-epoch.py dbus-send.sh \
256ebe
+			ganesha-ha.sh
256ebe
 
256ebe
 scriptsdir = $(libexecdir)/ganesha
256ebe
-scripts_SCRIPTS = create-export-ganesha.sh dbus-send.sh generate-epoch.py
256ebe
+scripts_SCRIPTS = create-export-ganesha.sh dbus-send.sh generate-epoch.py \
256ebe
+				  ganesha-ha.sh
256ebe
diff --git a/extras/ganesha/scripts/ganesha-ha.sh b/extras/ganesha/scripts/ganesha-ha.sh
256ebe
new file mode 100644
256ebe
index 0000000..6b011be
256ebe
--- /dev/null
256ebe
+++ b/extras/ganesha/scripts/ganesha-ha.sh
256ebe
@@ -0,0 +1,1125 @@
256ebe
+#!/bin/bash
256ebe
+
256ebe
+# Copyright 2015-2016 Red Hat Inc.  All Rights Reserved
256ebe
+#
256ebe
+# Pacemaker+Corosync High Availability for NFS-Ganesha
256ebe
+#
256ebe
+# setup, teardown, add, delete, refresh-config, and status
256ebe
+#
256ebe
+# Each participating node in the cluster is assigned a virtual IP (VIP)
256ebe
+# which fails over to another node when its associated ganesha.nfsd dies
256ebe
+# for any reason. After the VIP is moved to another node all the
256ebe
+# ganesha.nfsds are send a signal using DBUS to put them into NFS GRACE.
256ebe
+#
256ebe
+# There are six resource agent types used: ganesha_mon, ganesha_grace,
256ebe
+# ganesha_nfsd, IPaddr, and Dummy. ganesha_mon is used to monitor the
256ebe
+# ganesha.nfsd. ganesha_grace is used to send the DBUS signal to put
256ebe
+# the remaining ganesha.nfsds into grace. ganesha_nfsd is used to start
256ebe
+# and stop the ganesha.nfsd during setup and teardown. IPaddr manages
256ebe
+# the VIP. A Dummy resource named $hostname-trigger_ip-1 is used to
256ebe
+# ensure that the NFS GRACE DBUS signal is sent after the VIP moves to
256ebe
+# the new host.
256ebe
+
256ebe
+HA_NUM_SERVERS=0
256ebe
+HA_SERVERS=""
256ebe
+HA_VOL_NAME="gluster_shared_storage"
256ebe
+HA_VOL_MNT="/var/run/gluster/shared_storage"
256ebe
+HA_CONFDIR=$HA_VOL_MNT"/nfs-ganesha"
256ebe
+SERVICE_MAN="DISTRO_NOT_FOUND"
256ebe
+
256ebe
+RHEL6_PCS_CNAME_OPTION="--name"
256ebe
+SECRET_PEM="/var/lib/glusterd/nfs/secret.pem"
256ebe
+
256ebe
+# UNBLOCK RA uses shared_storage which may become unavailable
256ebe
+# during any of the nodes reboot. Hence increase timeout value.
256ebe
+PORTBLOCK_UNBLOCK_TIMEOUT="60s"
256ebe
+
256ebe
+# Try loading the config from any of the distro
256ebe
+# specific configuration locations
256ebe
+if [ -f /etc/sysconfig/ganesha ]
256ebe
+        then
256ebe
+        . /etc/sysconfig/ganesha
256ebe
+fi
256ebe
+if [ -f /etc/conf.d/ganesha ]
256ebe
+        then
256ebe
+        . /etc/conf.d/ganesha
256ebe
+fi
256ebe
+if [ -f /etc/default/ganesha ]
256ebe
+        then
256ebe
+        . /etc/default/ganesha
256ebe
+fi
256ebe
+
256ebe
+GANESHA_CONF=
256ebe
+
256ebe
+function find_rhel7_conf
256ebe
+{
256ebe
+ while [[ $# > 0 ]]
256ebe
+        do
256ebe
+                key="$1"
256ebe
+                case $key in
256ebe
+                        -f)
256ebe
+                         CONFFILE="$2"
256ebe
+                         break;
256ebe
+                         ;;
256ebe
+                         *)
256ebe
+                         ;;
256ebe
+                 esac
256ebe
+                 shift
256ebe
+         done
256ebe
+}
256ebe
+
256ebe
+if [ -z $CONFFILE ]
256ebe
+        then
256ebe
+        find_rhel7_conf $OPTIONS
256ebe
+
256ebe
+fi
256ebe
+
256ebe
+GANESHA_CONF=${CONFFILE:-/etc/ganesha/ganesha.conf}
256ebe
+
256ebe
+usage() {
256ebe
+
256ebe
+        echo "Usage      : add|delete|refresh-config|status"
256ebe
+        echo "Add-node   : ganesha-ha.sh --add <HA_CONF_DIR> \
256ebe
+<NODE-HOSTNAME>  <NODE-VIP>"
256ebe
+        echo "Delete-node: ganesha-ha.sh --delete <HA_CONF_DIR> \
256ebe
+<NODE-HOSTNAME>"
256ebe
+        echo "Refresh-config : ganesha-ha.sh --refresh-config <HA_CONFDIR> \
256ebe
+<volume>"
256ebe
+        echo "Status : ganesha-ha.sh --status <HA_CONFDIR>"
256ebe
+}
256ebe
+
256ebe
+determine_service_manager () {
256ebe
+
256ebe
+        if [ -e "/usr/bin/systemctl" ];
256ebe
+        then
256ebe
+                SERVICE_MAN="/usr/bin/systemctl"
256ebe
+        elif [ -e "/sbin/invoke-rc.d" ];
256ebe
+        then
256ebe
+                SERVICE_MAN="/sbin/invoke-rc.d"
256ebe
+        elif [ -e "/sbin/service" ];
256ebe
+        then
256ebe
+                SERVICE_MAN="/sbin/service"
256ebe
+        fi
256ebe
+        if [ "$SERVICE_MAN" == "DISTRO_NOT_FOUND" ]
256ebe
+        then
256ebe
+                echo "Service manager not recognized, exiting"
256ebe
+                exit 1
256ebe
+        fi
256ebe
+}
256ebe
+
256ebe
+manage_service ()
256ebe
+{
256ebe
+        local action=${1}
256ebe
+        local new_node=${2}
256ebe
+        local option=
256ebe
+
256ebe
+        if [ "$action" == "start" ]; then
256ebe
+                option="yes"
256ebe
+        else
256ebe
+                option="no"
256ebe
+        fi
256ebe
+        ssh -oPasswordAuthentication=no -oStrictHostKeyChecking=no -i \
256ebe
+${SECRET_PEM} root@${new_node} "/usr/libexec/ganesha/ganesha-ha.sh --setup-ganesha-conf-files $HA_CONFDIR $option"
256ebe
+
256ebe
+        if [ "$SERVICE_MAN" == "/usr/bin/systemctl" ]
256ebe
+        then
256ebe
+                ssh -oPasswordAuthentication=no -oStrictHostKeyChecking=no -i \
256ebe
+${SECRET_PEM} root@${new_node} "$SERVICE_MAN  ${action} nfs-ganesha"
256ebe
+        else
256ebe
+                ssh -oPasswordAuthentication=no -oStrictHostKeyChecking=no -i \
256ebe
+${SECRET_PEM} root@${new_node} "$SERVICE_MAN nfs-ganesha ${action}"
256ebe
+        fi
256ebe
+}
256ebe
+
256ebe
+
256ebe
+check_cluster_exists()
256ebe
+{
256ebe
+    local name=${1}
256ebe
+    local cluster_name=""
256ebe
+
256ebe
+    if [ -e /var/run/corosync.pid ]; then
256ebe
+        cluster_name=$(pcs status | grep "Cluster name:" | cut -d ' ' -f 3)
256ebe
+        if [ ${cluster_name} -a ${cluster_name} = ${name} ]; then
256ebe
+            logger "$name already exists, exiting"
256ebe
+            exit 0
256ebe
+        fi
256ebe
+    fi
256ebe
+}
256ebe
+
256ebe
+
256ebe
+determine_servers()
256ebe
+{
256ebe
+    local cmd=${1}
256ebe
+    local num_servers=0
256ebe
+    local tmp_ifs=${IFS}
256ebe
+    local ha_servers=""
256ebe
+
256ebe
+    if [ "X${cmd}X" != "XsetupX" -a "X${cmd}X" != "XstatusX" ]; then
256ebe
+        ha_servers=$(pcs status | grep "Online:" | grep -o '\[.*\]' | sed -e 's/\[//' | sed -e 's/\]//')
256ebe
+        IFS=$' '
256ebe
+        for server in ${ha_servers} ; do
256ebe
+            num_servers=$(expr ${num_servers} + 1)
256ebe
+        done
256ebe
+        IFS=${tmp_ifs}
256ebe
+        HA_NUM_SERVERS=${num_servers}
256ebe
+        HA_SERVERS="${ha_servers}"
256ebe
+    else
256ebe
+        IFS=$','
256ebe
+        for server in ${HA_CLUSTER_NODES} ; do
256ebe
+            num_servers=$(expr ${num_servers} + 1)
256ebe
+        done
256ebe
+        IFS=${tmp_ifs}
256ebe
+        HA_NUM_SERVERS=${num_servers}
256ebe
+        HA_SERVERS="${HA_CLUSTER_NODES//,/ }"
256ebe
+    fi
256ebe
+}
256ebe
+
256ebe
+
256ebe
+setup_cluster()
256ebe
+{
256ebe
+    local name=${1}
256ebe
+    local num_servers=${2}
256ebe
+    local servers=${3}
256ebe
+    local unclean=""
256ebe
+    local quorum_policy="stop"
256ebe
+
256ebe
+    logger "setting up cluster ${name} with the following ${servers}"
256ebe
+
256ebe
+    pcs cluster auth ${servers}
256ebe
+    # pcs cluster setup --name ${name} ${servers}
256ebe
+    pcs cluster setup ${RHEL6_PCS_CNAME_OPTION} ${name} --transport udpu ${servers}
256ebe
+    if [ $? -ne 0 ]; then
256ebe
+        logger "pcs cluster setup ${RHEL6_PCS_CNAME_OPTION} ${name} ${servers} failed"
256ebe
+        exit 1;
256ebe
+    fi
256ebe
+    pcs cluster start --all
256ebe
+    if [ $? -ne 0 ]; then
256ebe
+        logger "pcs cluster start failed"
256ebe
+        exit 1;
256ebe
+    fi
256ebe
+
256ebe
+    sleep 1
256ebe
+    # wait for the cluster to elect a DC before querying or writing
256ebe
+    # to the CIB. BZ 1334092
256ebe
+    crmadmin --dc_lookup --timeout=5000 > /dev/null 2>&1
256ebe
+    while [ $? -ne 0 ]; do
256ebe
+        crmadmin --dc_lookup --timeout=5000 > /dev/null 2>&1
256ebe
+    done
256ebe
+
256ebe
+    unclean=$(pcs status | grep -u "UNCLEAN")
256ebe
+    while [[ "${unclean}X" = "UNCLEANX" ]]; do
256ebe
+         sleep 1
256ebe
+         unclean=$(pcs status | grep -u "UNCLEAN")
256ebe
+    done
256ebe
+    sleep 1
256ebe
+
256ebe
+    if [ ${num_servers} -lt 3 ]; then
256ebe
+        quorum_policy="ignore"
256ebe
+    fi
256ebe
+    pcs property set no-quorum-policy=${quorum_policy}
256ebe
+    if [ $? -ne 0 ]; then
256ebe
+        logger "warning: pcs property set no-quorum-policy=${quorum_policy} failed"
256ebe
+    fi
256ebe
+
256ebe
+    pcs property set stonith-enabled=false
256ebe
+    if [ $? -ne 0 ]; then
256ebe
+        logger "warning: pcs property set stonith-enabled=false failed"
256ebe
+    fi
256ebe
+}
256ebe
+
256ebe
+
256ebe
+setup_finalize_ha()
256ebe
+{
256ebe
+    local cibfile=${1}
256ebe
+    local stopped=""
256ebe
+
256ebe
+    stopped=$(pcs status | grep -u "Stopped")
256ebe
+    while [[ "${stopped}X" = "StoppedX" ]]; do
256ebe
+         sleep 1
256ebe
+         stopped=$(pcs status | grep -u "Stopped")
256ebe
+    done
256ebe
+}
256ebe
+
256ebe
+
256ebe
+refresh_config ()
256ebe
+{
256ebe
+        local short_host=$(hostname -s)
256ebe
+        local VOL=${1}
256ebe
+        local HA_CONFDIR=${2}
256ebe
+        local short_host=$(hostname -s)
256ebe
+
256ebe
+        local export_id=$(grep ^[[:space:]]*Export_Id $HA_CONFDIR/exports/export.$VOL.conf |\
256ebe
+                          awk -F"[=,;]" '{print $2}' | tr -d '[[:space:]]')
256ebe
+
256ebe
+
256ebe
+        if [ -e ${SECRET_PEM} ]; then
256ebe
+        while [[ ${3} ]]; do
256ebe
+            current_host=`echo ${3} | cut -d "." -f 1`
256ebe
+            if [ ${short_host} != ${current_host} ]; then
256ebe
+                output=$(ssh -oPasswordAuthentication=no \
256ebe
+-oStrictHostKeyChecking=no -i ${SECRET_PEM} root@${current_host} \
256ebe
+"dbus-send --print-reply --system --dest=org.ganesha.nfsd \
256ebe
+/org/ganesha/nfsd/ExportMgr org.ganesha.nfsd.exportmgr.UpdateExport \
256ebe
+string:$HA_CONFDIR/exports/export.$VOL.conf \
256ebe
+string:\"EXPORT(Export_Id=$export_id)\" 2>&1")
256ebe
+                ret=$?
256ebe
+                logger <<< "${output}"
256ebe
+                if [ ${ret} -ne 0 ]; then
256ebe
+                        echo "Error: refresh-config failed on ${current_host}."
256ebe
+                        exit 1
256ebe
+                else
256ebe
+                        echo "Refresh-config completed on ${current_host}."
256ebe
+                fi
256ebe
+
256ebe
+          fi
256ebe
+          shift
256ebe
+        done
256ebe
+    else
256ebe
+        echo "Error: refresh-config failed. Passwordless ssh is not enabled."
256ebe
+        exit 1
256ebe
+    fi
256ebe
+
256ebe
+    # Run the same command on the localhost,
256ebe
+        output=$(dbus-send --print-reply --system --dest=org.ganesha.nfsd \
256ebe
+/org/ganesha/nfsd/ExportMgr org.ganesha.nfsd.exportmgr.UpdateExport \
256ebe
+string:$HA_CONFDIR/exports/export.$VOL.conf \
256ebe
+string:"EXPORT(Export_Id=$export_id)" 2>&1)
256ebe
+        ret=$?
256ebe
+        logger <<< "${output}"
256ebe
+        if [ ${ret} -ne 0 ] ; then
256ebe
+                echo "Error: refresh-config failed on localhost."
256ebe
+                exit 1
256ebe
+        else
256ebe
+                echo "Success: refresh-config completed."
256ebe
+        fi
256ebe
+}
256ebe
+
256ebe
+
256ebe
+teardown_cluster()
256ebe
+{
256ebe
+    local name=${1}
256ebe
+
256ebe
+    for server in ${HA_SERVERS} ; do
256ebe
+        if [[ ${HA_CLUSTER_NODES} != *${server}* ]]; then
256ebe
+            logger "info: ${server} is not in config, removing"
256ebe
+
256ebe
+            pcs cluster stop ${server} --force
256ebe
+            if [ $? -ne 0 ]; then
256ebe
+                logger "warning: pcs cluster stop ${server} failed"
256ebe
+            fi
256ebe
+
256ebe
+            pcs cluster node remove ${server}
256ebe
+            if [ $? -ne 0 ]; then
256ebe
+                logger "warning: pcs cluster node remove ${server} failed"
256ebe
+            fi
256ebe
+        fi
256ebe
+    done
256ebe
+
256ebe
+    # BZ 1193433 - pcs doesn't reload cluster.conf after modification
256ebe
+    # after teardown completes, a subsequent setup will appear to have
256ebe
+    # 'remembered' the deleted node. You can work around this by
256ebe
+    # issuing another `pcs cluster node remove $node`,
256ebe
+    # `crm_node -f -R $server`, or
256ebe
+    # `cibadmin --delete --xml-text '
256ebe
+    # uname="$server"/>'
256ebe
+
256ebe
+    pcs cluster stop --all
256ebe
+    if [ $? -ne 0 ]; then
256ebe
+        logger "warning pcs cluster stop --all failed"
256ebe
+    fi
256ebe
+
256ebe
+    pcs cluster destroy
256ebe
+    if [ $? -ne 0 ]; then
256ebe
+        logger "error pcs cluster destroy failed"
256ebe
+        exit 1
256ebe
+    fi
256ebe
+}
256ebe
+
256ebe
+
256ebe
+cleanup_ganesha_config ()
256ebe
+{
256ebe
+    rm -f /etc/corosync/corosync.conf
256ebe
+    rm -rf /etc/cluster/cluster.conf*
256ebe
+    rm -rf /var/lib/pacemaker/cib/*
256ebe
+}
256ebe
+
256ebe
+do_create_virt_ip_constraints()
256ebe
+{
256ebe
+    local cibfile=${1}; shift
256ebe
+    local primary=${1}; shift
256ebe
+    local weight="1000"
256ebe
+
256ebe
+    # first a constraint location rule that says the VIP must be where
256ebe
+    # there's a ganesha.nfsd running
256ebe
+    pcs -f ${cibfile} constraint location ${primary}-group rule score=-INFINITY ganesha-active ne 1
256ebe
+    if [ $? -ne 0 ]; then
256ebe
+        logger "warning: pcs constraint location ${primary}-group rule score=-INFINITY ganesha-active ne 1 failed"
256ebe
+    fi
256ebe
+
256ebe
+    # then a set of constraint location prefers to set the prefered order
256ebe
+    # for where a VIP should move
256ebe
+    while [[ ${1} ]]; do
256ebe
+        pcs -f ${cibfile} constraint location ${primary}-group prefers ${1}=${weight}
256ebe
+        if [ $? -ne 0 ]; then
256ebe
+            logger "warning: pcs constraint location ${primary}-group prefers ${1}=${weight} failed"
256ebe
+        fi
256ebe
+        weight=$(expr ${weight} + 1000)
256ebe
+        shift
256ebe
+    done
256ebe
+    # and finally set the highest preference for the VIP to its home node
256ebe
+    # default weight when created is/was 100.
256ebe
+    # on Fedora setting appears to be additive, so to get the desired
256ebe
+    # value we adjust the weight
256ebe
+    # weight=$(expr ${weight} - 100)
256ebe
+    pcs -f ${cibfile} constraint location ${primary}-group prefers ${primary}=${weight}
256ebe
+    if [ $? -ne 0 ]; then
256ebe
+        logger "warning: pcs constraint location ${primary}-group prefers ${primary}=${weight} failed"
256ebe
+    fi
256ebe
+}
256ebe
+
256ebe
+
256ebe
+wrap_create_virt_ip_constraints()
256ebe
+{
256ebe
+    local cibfile=${1}; shift
256ebe
+    local primary=${1}; shift
256ebe
+    local head=""
256ebe
+    local tail=""
256ebe
+
256ebe
+    # build a list of peers, e.g. for a four node cluster, for node1,
256ebe
+    # the result is "node2 node3 node4"; for node2, "node3 node4 node1"
256ebe
+    # and so on.
256ebe
+    while [[ ${1} ]]; do
256ebe
+        if [ "${1}" = "${primary}" ]; then
256ebe
+            shift
256ebe
+            while [[ ${1} ]]; do
256ebe
+                tail=${tail}" "${1}
256ebe
+                shift
256ebe
+            done
256ebe
+        else
256ebe
+            head=${head}" "${1}
256ebe
+        fi
256ebe
+        shift
256ebe
+    done
256ebe
+    do_create_virt_ip_constraints ${cibfile} ${primary} ${tail} ${head}
256ebe
+}
256ebe
+
256ebe
+
256ebe
+create_virt_ip_constraints()
256ebe
+{
256ebe
+    local cibfile=${1}; shift
256ebe
+
256ebe
+    while [[ ${1} ]]; do
256ebe
+        wrap_create_virt_ip_constraints ${cibfile} ${1} ${HA_SERVERS}
256ebe
+        shift
256ebe
+    done
256ebe
+}
256ebe
+
256ebe
+
256ebe
+setup_create_resources()
256ebe
+{
256ebe
+    local cibfile=$(mktemp -u)
256ebe
+
256ebe
+    # fixup /var/lib/nfs
256ebe
+    logger "pcs resource create nfs_setup ocf:heartbeat:ganesha_nfsd ha_vol_mnt=${HA_VOL_MNT} --clone"
256ebe
+    pcs resource create nfs_setup ocf:heartbeat:ganesha_nfsd ha_vol_mnt=${HA_VOL_MNT} --clone
256ebe
+    if [ $? -ne 0 ]; then
256ebe
+        logger "warning: pcs resource create nfs_setup ocf:heartbeat:ganesha_nfsd ha_vol_mnt=${HA_VOL_MNT} --clone failed"
256ebe
+    fi
256ebe
+
256ebe
+    pcs resource create nfs-mon ocf:heartbeat:ganesha_mon --clone
256ebe
+    if [ $? -ne 0 ]; then
256ebe
+        logger "warning: pcs resource create nfs-mon ocf:heartbeat:ganesha_mon --clone failed"
256ebe
+    fi
256ebe
+
256ebe
+    # see comment in (/usr/lib/ocf/resource.d/heartbeat/ganesha_grace
256ebe
+    # start method. Allow time for ganesha_mon to start and set the
256ebe
+    # ganesha-active crm_attribute
256ebe
+    sleep 5
256ebe
+
256ebe
+    pcs resource create nfs-grace ocf:heartbeat:ganesha_grace --clone meta notify=true
256ebe
+    if [ $? -ne 0 ]; then
256ebe
+        logger "warning: pcs resource create nfs-grace ocf:heartbeat:ganesha_grace --clone failed"
256ebe
+    fi
256ebe
+
256ebe
+    pcs constraint location nfs-grace-clone rule score=-INFINITY grace-active ne 1
256ebe
+    if [ $? -ne 0 ]; then
256ebe
+        logger "warning: pcs constraint location nfs-grace-clone rule score=-INFINITY grace-active ne 1"
256ebe
+    fi
256ebe
+
256ebe
+    pcs cluster cib ${cibfile}
256ebe
+
256ebe
+    while [[ ${1} ]]; do
256ebe
+
256ebe
+        # this is variable indirection
256ebe
+        # from a nvs like 'VIP_host1=10.7.6.5' or 'VIP_host1="10.7.6.5"'
256ebe
+        # (or VIP_host-1=..., or VIP_host-1.my.domain.name=...)
256ebe
+        # a variable 'clean_name' is created (e.g. w/ value 'VIP_host_1')
256ebe
+        # and a clean nvs (e.g. w/ value 'VIP_host_1="10_7_6_5"')
256ebe
+        # after the `eval ${clean_nvs}` there is a variable VIP_host_1
256ebe
+        # with the value '10_7_6_5', and the following \$$ magic to
256ebe
+        # reference it, i.e. `eval tmp_ipaddr=\$${clean_name}` gives us
256ebe
+        # ${tmp_ipaddr} with 10_7_6_5 and then convert the _s back to .s
256ebe
+        # to give us ipaddr="10.7.6.5". whew!
256ebe
+        name="VIP_${1}"
256ebe
+        clean_name=${name//[-.]/_}
256ebe
+        nvs=$(grep "^${name}=" ${HA_CONFDIR}/ganesha-ha.conf)
256ebe
+        clean_nvs=${nvs//[-.]/_}
256ebe
+        eval ${clean_nvs}
256ebe
+        eval tmp_ipaddr=\$${clean_name}
256ebe
+        ipaddr=${tmp_ipaddr//_/.}
256ebe
+
256ebe
+        pcs -f ${cibfile} resource create ${1}-nfs_block ocf:heartbeat:portblock protocol=tcp \
256ebe
+        portno=2049 action=block ip=${ipaddr} --group ${1}-group
256ebe
+        if [ $? -ne 0 ]; then
256ebe
+            logger "warning pcs resource create ${1}-nfs_block failed"
256ebe
+        fi
256ebe
+        pcs -f ${cibfile} resource create ${1}-cluster_ip-1 ocf:heartbeat:IPaddr ip=${ipaddr} \
256ebe
+        cidr_netmask=32 op monitor interval=15s --group ${1}-group --after ${1}-nfs_block
256ebe
+        if [ $? -ne 0 ]; then
256ebe
+            logger "warning pcs resource create ${1}-cluster_ip-1 ocf:heartbeat:IPaddr ip=${ipaddr} \
256ebe
+            cidr_netmask=32 op monitor interval=15s failed"
256ebe
+        fi
256ebe
+
256ebe
+        pcs -f ${cibfile} constraint order nfs-grace-clone then ${1}-cluster_ip-1
256ebe
+        if [ $? -ne 0 ]; then
256ebe
+            logger "warning: pcs constraint order nfs-grace-clone then ${1}-cluster_ip-1 failed"
256ebe
+        fi
256ebe
+
256ebe
+        pcs -f ${cibfile} resource create ${1}-nfs_unblock ocf:heartbeat:portblock protocol=tcp \
256ebe
+        portno=2049 action=unblock ip=${ipaddr} reset_local_on_unblock_stop=true \
256ebe
+        tickle_dir=${HA_VOL_MNT}/nfs-ganesha/tickle_dir/ --group ${1}-group --after ${1}-cluster_ip-1 \
256ebe
+        op stop timeout=${PORTBLOCK_UNBLOCK_TIMEOUT} op start timeout=${PORTBLOCK_UNBLOCK_TIMEOUT} \
256ebe
+        op monitor interval=10s timeout=${PORTBLOCK_UNBLOCK_TIMEOUT}
256ebe
+        if [ $? -ne 0 ]; then
256ebe
+            logger "warning pcs resource create ${1}-nfs_unblock failed"
256ebe
+        fi
256ebe
+
256ebe
+
256ebe
+        shift
256ebe
+    done
256ebe
+
256ebe
+    create_virt_ip_constraints ${cibfile} ${HA_SERVERS}
256ebe
+
256ebe
+    pcs cluster cib-push ${cibfile}
256ebe
+    if [ $? -ne 0 ]; then
256ebe
+        logger "warning pcs cluster cib-push ${cibfile} failed"
256ebe
+    fi
256ebe
+    rm -f ${cibfile}
256ebe
+}
256ebe
+
256ebe
+
256ebe
+teardown_resources()
256ebe
+{
256ebe
+    # local mntpt=$(grep ha-vol-mnt ${HA_CONFIG_FILE} | cut -d = -f 2)
256ebe
+
256ebe
+    # restore /var/lib/nfs
256ebe
+    logger "notice: pcs resource delete nfs_setup-clone"
256ebe
+    pcs resource delete nfs_setup-clone
256ebe
+    if [ $? -ne 0 ]; then
256ebe
+        logger "warning: pcs resource delete nfs_setup-clone failed"
256ebe
+    fi
256ebe
+
256ebe
+    # delete -clone resource agents
256ebe
+    # in particular delete the ganesha monitor so we don't try to
256ebe
+    # trigger anything when we shut down ganesha next.
256ebe
+    pcs resource delete nfs-mon-clone
256ebe
+    if [ $? -ne 0 ]; then
256ebe
+        logger "warning: pcs resource delete nfs-mon-clone failed"
256ebe
+    fi
256ebe
+
256ebe
+    pcs resource delete nfs-grace-clone
256ebe
+    if [ $? -ne 0 ]; then
256ebe
+        logger "warning: pcs resource delete nfs-grace-clone failed"
256ebe
+    fi
256ebe
+
256ebe
+    while [[ ${1} ]]; do
256ebe
+        pcs resource delete ${1}-group
256ebe
+        if [ $? -ne 0 ]; then
256ebe
+            logger "warning: pcs resource delete ${1}-group failed"
256ebe
+        fi
256ebe
+        shift
256ebe
+    done
256ebe
+
256ebe
+}
256ebe
+
256ebe
+
256ebe
+recreate_resources()
256ebe
+{
256ebe
+    local cibfile=${1}; shift
256ebe
+
256ebe
+    while [[ ${1} ]]; do
256ebe
+        # this is variable indirection
256ebe
+        # see the comment on the same a few lines up
256ebe
+        name="VIP_${1}"
256ebe
+        clean_name=${name//[-.]/_}
256ebe
+        nvs=$(grep "^${name}=" ${HA_CONFDIR}/ganesha-ha.conf)
256ebe
+        clean_nvs=${nvs//[-.]/_}
256ebe
+        eval ${clean_nvs}
256ebe
+        eval tmp_ipaddr=\$${clean_name}
256ebe
+        ipaddr=${tmp_ipaddr//_/.}
256ebe
+
256ebe
+        pcs -f ${cibfile} resource create ${1}-nfs_block ocf:heartbeat:portblock protocol=tcp \
256ebe
+        portno=2049 action=block ip=${ipaddr} --group ${1}-group
256ebe
+        if [ $? -ne 0 ]; then
256ebe
+            logger "warning pcs resource create ${1}-nfs_block failed"
256ebe
+        fi
256ebe
+        pcs -f ${cibfile} resource create ${1}-cluster_ip-1 ocf:heartbeat:IPaddr ip=${ipaddr} \
256ebe
+        cidr_netmask=32 op monitor interval=15s --group ${1}-group --after ${1}-nfs_block
256ebe
+        if [ $? -ne 0 ]; then
256ebe
+            logger "warning pcs resource create ${1}-cluster_ip-1 ocf:heartbeat:IPaddr ip=${ipaddr} \
256ebe
+            cidr_netmask=32 op monitor interval=15s failed"
256ebe
+        fi
256ebe
+
256ebe
+        pcs -f ${cibfile} constraint order nfs-grace-clone then ${1}-cluster_ip-1
256ebe
+        if [ $? -ne 0 ]; then
256ebe
+            logger "warning: pcs constraint order nfs-grace-clone then ${1}-cluster_ip-1 failed"
256ebe
+        fi
256ebe
+
256ebe
+        pcs -f ${cibfile} resource create ${1}-nfs_unblock ocf:heartbeat:portblock protocol=tcp \
256ebe
+        portno=2049 action=unblock ip=${ipaddr} reset_local_on_unblock_stop=true \
256ebe
+        tickle_dir=${HA_VOL_MNT}/nfs-ganesha/tickle_dir/ --group ${1}-group --after ${1}-cluster_ip-1 \
256ebe
+        op stop timeout=${PORTBLOCK_UNBLOCK_TIMEOUT} op start timeout=${PORTBLOCK_UNBLOCK_TIMEOUT} \
256ebe
+        op monitor interval=10s timeout=${PORTBLOCK_UNBLOCK_TIMEOUT}
256ebe
+        if [ $? -ne 0 ]; then
256ebe
+            logger "warning pcs resource create ${1}-nfs_unblock failed"
256ebe
+        fi
256ebe
+
256ebe
+        shift
256ebe
+    done
256ebe
+}
256ebe
+
256ebe
+
256ebe
+addnode_recreate_resources()
256ebe
+{
256ebe
+    local cibfile=${1}; shift
256ebe
+    local add_node=${1}; shift
256ebe
+    local add_vip=${1}; shift
256ebe
+
256ebe
+    recreate_resources ${cibfile} ${HA_SERVERS}
256ebe
+
256ebe
+    pcs -f ${cibfile} resource create ${add_node}-nfs_block ocf:heartbeat:portblock \
256ebe
+    protocol=tcp portno=2049 action=block ip=${add_vip} --group ${add_node}-group
256ebe
+    if [ $? -ne 0 ]; then
256ebe
+        logger "warning pcs resource create ${add_node}-nfs_block failed"
256ebe
+    fi
256ebe
+    pcs -f ${cibfile} resource create ${add_node}-cluster_ip-1 ocf:heartbeat:IPaddr \
256ebe
+    ip=${add_vip} cidr_netmask=32 op monitor interval=15s --group ${add_node}-group \
256ebe
+    --after ${add_node}-nfs_block
256ebe
+    if [ $? -ne 0 ]; then
256ebe
+        logger "warning pcs resource create ${add_node}-cluster_ip-1 ocf:heartbeat:IPaddr \
256ebe
+	ip=${add_vip} cidr_netmask=32 op monitor interval=15s failed"
256ebe
+    fi
256ebe
+
256ebe
+    pcs -f ${cibfile} constraint order nfs-grace-clone then ${add_node}-cluster_ip-1
256ebe
+    if [ $? -ne 0 ]; then
256ebe
+        logger "warning: pcs constraint order nfs-grace-clone then ${add_node}-cluster_ip-1 failed"
256ebe
+    fi
256ebe
+    pcs -f ${cibfile} resource create ${add_node}-nfs_unblock ocf:heartbeat:portblock \
256ebe
+    protocol=tcp portno=2049 action=unblock ip=${add_vip} reset_local_on_unblock_stop=true \
256ebe
+    tickle_dir=${HA_VOL_MNT}/nfs-ganesha/tickle_dir/ --group ${add_node}-group --after \
256ebe
+    ${add_node}-cluster_ip-1 op stop timeout=${PORTBLOCK_UNBLOCK_TIMEOUT} op start \
256ebe
+    timeout=${PORTBLOCK_UNBLOCK_TIMEOUT} op monitor interval=10s \
256ebe
+    timeout=${PORTBLOCK_UNBLOCK_TIMEOUT}
256ebe
+    if [ $? -ne 0 ]; then
256ebe
+        logger "warning pcs resource create ${add_node}-nfs_unblock failed"
256ebe
+    fi
256ebe
+}
256ebe
+
256ebe
+
256ebe
+clear_resources()
256ebe
+{
256ebe
+    local cibfile=${1}; shift
256ebe
+
256ebe
+    while [[ ${1} ]]; do
256ebe
+        pcs -f ${cibfile} resource delete ${1}-group
256ebe
+        if [ $? -ne 0 ]; then
256ebe
+            logger "warning: pcs -f ${cibfile} resource delete ${1}-group"
256ebe
+        fi
256ebe
+
256ebe
+        shift
256ebe
+    done
256ebe
+}
256ebe
+
256ebe
+
256ebe
+addnode_create_resources()
256ebe
+{
256ebe
+    local add_node=${1}; shift
256ebe
+    local add_vip=${1}; shift
256ebe
+    local cibfile=$(mktemp -u)
256ebe
+
256ebe
+    # start HA on the new node
256ebe
+    pcs cluster start ${add_node}
256ebe
+    if [ $? -ne 0 ]; then
256ebe
+       logger "warning: pcs cluster start ${add_node} failed"
256ebe
+    fi
256ebe
+
256ebe
+    pcs cluster cib ${cibfile}
256ebe
+    if [ $? -ne 0 ]; then
256ebe
+        logger "warning: pcs cluster cib ${cibfile} failed"
256ebe
+    fi
256ebe
+
256ebe
+    # delete all the -cluster_ip-1 resources, clearing
256ebe
+    # their constraints, then create them again so we can
256ebe
+    # recompute their constraints
256ebe
+    clear_resources ${cibfile} ${HA_SERVERS}
256ebe
+    addnode_recreate_resources ${cibfile} ${add_node} ${add_vip}
256ebe
+
256ebe
+    HA_SERVERS="${HA_SERVERS} ${add_node}"
256ebe
+    create_virt_ip_constraints ${cibfile} ${HA_SERVERS}
256ebe
+
256ebe
+    pcs cluster cib-push ${cibfile}
256ebe
+    if [ $? -ne 0 ]; then
256ebe
+        logger "warning: pcs cluster cib-push ${cibfile} failed"
256ebe
+    fi
256ebe
+    rm -f ${cibfile}
256ebe
+}
256ebe
+
256ebe
+
256ebe
+deletenode_delete_resources()
256ebe
+{
256ebe
+    local node=${1}; shift
256ebe
+    local ha_servers=$(echo "${HA_SERVERS}" | sed s/${node}//)
256ebe
+    local cibfile=$(mktemp -u)
256ebe
+
256ebe
+    pcs cluster cib ${cibfile}
256ebe
+    if [ $? -ne 0 ]; then
256ebe
+        logger "warning: pcs cluster cib ${cibfile} failed"
256ebe
+    fi
256ebe
+
256ebe
+    # delete all the -cluster_ip-1 and -trigger_ip-1 resources,
256ebe
+    # clearing their constraints, then create them again so we can
256ebe
+    # recompute their constraints
256ebe
+    clear_resources ${cibfile} ${HA_SERVERS}
256ebe
+    recreate_resources ${cibfile} ${ha_servers}
256ebe
+    HA_SERVERS=$(echo "${ha_servers}" | sed -e "s/  / /")
256ebe
+
256ebe
+    create_virt_ip_constraints ${cibfile} ${HA_SERVERS}
256ebe
+
256ebe
+    pcs cluster cib-push ${cibfile}
256ebe
+    if [ $? -ne 0 ]; then
256ebe
+        logger "warning: pcs cluster cib-push ${cibfile} failed"
256ebe
+    fi
256ebe
+    rm -f ${cibfile}
256ebe
+
256ebe
+}
256ebe
+
256ebe
+
256ebe
+deletenode_update_haconfig()
256ebe
+{
256ebe
+    local name="VIP_${1}"
256ebe
+    local clean_name=${name//[-.]/_}
256ebe
+
256ebe
+    ha_servers=$(echo ${HA_SERVERS} | sed -e "s/ /,/")
256ebe
+    sed -i -e "s/^HA_CLUSTER_NODES=.*$/HA_CLUSTER_NODES=\"${ha_servers// /,}\"/" -e "s/^${name}=.*$//" -e "/^$/d" ${HA_CONFDIR}/ganesha-ha.conf
256ebe
+}
256ebe
+
256ebe
+
256ebe
+setup_state_volume()
256ebe
+{
256ebe
+    local mnt=${HA_VOL_MNT}
256ebe
+    local longname=""
256ebe
+    local shortname=""
256ebe
+    local dname=""
256ebe
+    local dirname=""
256ebe
+
256ebe
+    longname=$(hostname)
256ebe
+    dname=${longname#$(hostname -s)}
256ebe
+
256ebe
+    while [[ ${1} ]]; do
256ebe
+
256ebe
+        if [[ ${1} == *${dname} ]]; then
256ebe
+            dirname=${1}
256ebe
+        else
256ebe
+            dirname=${1}${dname}
256ebe
+        fi
256ebe
+
256ebe
+        if [ ! -d ${mnt}/nfs-ganesha/tickle_dir ]; then
256ebe
+            mkdir ${mnt}/nfs-ganesha/tickle_dir
256ebe
+        fi
256ebe
+        if [ ! -d ${mnt}/nfs-ganesha/${dirname} ]; then
256ebe
+            mkdir ${mnt}/nfs-ganesha/${dirname}
256ebe
+        fi
256ebe
+        if [ ! -d ${mnt}/nfs-ganesha/${dirname}/nfs ]; then
256ebe
+            mkdir ${mnt}/nfs-ganesha/${dirname}/nfs
256ebe
+        fi
256ebe
+        if [ ! -d ${mnt}/nfs-ganesha/${dirname}/nfs/ganesha ]; then
256ebe
+            mkdir ${mnt}/nfs-ganesha/${dirname}/nfs/ganesha
256ebe
+        fi
256ebe
+        if [ ! -d ${mnt}/nfs-ganesha/${dirname}/nfs/statd ]; then
256ebe
+            mkdir ${mnt}/nfs-ganesha/${dirname}/nfs/statd
256ebe
+        fi
256ebe
+        if [ ! -e ${mnt}/nfs-ganesha/${dirname}/nfs/state ]; then
256ebe
+            touch ${mnt}/nfs-ganesha/${dirname}/nfs/state
256ebe
+        fi
256ebe
+        if [ ! -d ${mnt}/nfs-ganesha/${dirname}/nfs/ganesha/v4recov ]; then
256ebe
+            mkdir ${mnt}/nfs-ganesha/${dirname}/nfs/ganesha/v4recov
256ebe
+        fi
256ebe
+        if [ ! -d ${mnt}/nfs-ganesha/${dirname}/nfs/ganesha/v4old ]; then
256ebe
+            mkdir ${mnt}/nfs-ganesha/${dirname}/nfs/ganesha/v4old
256ebe
+        fi
256ebe
+        if [ ! -d ${mnt}/nfs-ganesha/${dirname}/nfs/statd/sm ]; then
256ebe
+            mkdir ${mnt}/nfs-ganesha/${dirname}/nfs/statd/sm
256ebe
+        fi
256ebe
+        if [ ! -d ${mnt}/nfs-ganesha/${dirname}/nfs/statd/sm.bak ]; then
256ebe
+            mkdir ${mnt}/nfs-ganesha/${dirname}/nfs/statd/sm.bak
256ebe
+        fi
256ebe
+        if [ ! -e ${mnt}/nfs-ganesha/${dirname}/nfs/statd/state ]; then
256ebe
+            touch ${mnt}/nfs-ganesha/${dirname}/nfs/statd/state
256ebe
+        fi
256ebe
+        for server in ${HA_SERVERS} ; do
256ebe
+            if [ ${server} != ${dirname} ]; then
256ebe
+                ln -s ${mnt}/nfs-ganesha/${server}/nfs/ganesha ${mnt}/nfs-ganesha/${dirname}/nfs/ganesha/${server}
256ebe
+                ln -s ${mnt}/nfs-ganesha/${server}/nfs/statd ${mnt}/nfs-ganesha/${dirname}/nfs/statd/${server}
256ebe
+            fi
256ebe
+        done
256ebe
+        shift
256ebe
+    done
256ebe
+
256ebe
+}
256ebe
+
256ebe
+
256ebe
+addnode_state_volume()
256ebe
+{
256ebe
+    local newnode=${1}; shift
256ebe
+    local mnt=${HA_VOL_MNT}
256ebe
+    local longname=""
256ebe
+    local dname=""
256ebe
+    local dirname=""
256ebe
+
256ebe
+    longname=$(hostname)
256ebe
+    dname=${longname#$(hostname -s)}
256ebe
+
256ebe
+    if [[ ${newnode} == *${dname} ]]; then
256ebe
+        dirname=${newnode}
256ebe
+    else
256ebe
+        dirname=${newnode}${dname}
256ebe
+    fi
256ebe
+
256ebe
+    if [ ! -d ${mnt}/nfs-ganesha/${dirname} ]; then
256ebe
+        mkdir ${mnt}/nfs-ganesha/${dirname}
256ebe
+    fi
256ebe
+    if [ ! -d ${mnt}/nfs-ganesha/${dirname}/nfs ]; then
256ebe
+        mkdir ${mnt}/nfs-ganesha/${dirname}/nfs
256ebe
+    fi
256ebe
+    if [ ! -d ${mnt}/nfs-ganesha/${dirname}/nfs/ganesha ]; then
256ebe
+        mkdir ${mnt}/nfs-ganesha/${dirname}/nfs/ganesha
256ebe
+    fi
256ebe
+    if [ ! -d ${mnt}/nfs-ganesha/${dirname}/nfs/statd ]; then
256ebe
+        mkdir ${mnt}/nfs-ganesha/${dirname}/nfs/statd
256ebe
+    fi
256ebe
+    if [ ! -e ${mnt}/nfs-ganesha/${dirname}/nfs/state ]; then
256ebe
+        touch ${mnt}/nfs-ganesha/${dirname}/nfs/state
256ebe
+    fi
256ebe
+    if [ ! -d ${mnt}/nfs-ganesha/${dirname}/nfs/ganesha/v4recov ]; then
256ebe
+        mkdir ${mnt}/nfs-ganesha/${dirname}/nfs/ganesha/v4recov
256ebe
+    fi
256ebe
+    if [ ! -d ${mnt}/nfs-ganesha/${dirname}/nfs/ganesha/v4old ]; then
256ebe
+        mkdir ${mnt}/nfs-ganesha/${dirname}/nfs/ganesha/v4old
256ebe
+    fi
256ebe
+    if [ ! -d ${mnt}/nfs-ganesha/${dirname}/nfs/statd/sm ]; then
256ebe
+        mkdir ${mnt}/nfs-ganesha/${dirname}/nfs/statd/sm
256ebe
+    fi
256ebe
+    if [ ! -d ${mnt}/nfs-ganesha/${dirname}/nfs/statd/sm.bak ]; then
256ebe
+        mkdir ${mnt}/nfs-ganesha/${dirname}/nfs/statd/sm.bak
256ebe
+    fi
256ebe
+    if [ ! -e ${mnt}/nfs-ganesha/${dirname}/nfs/statd/state ]; then
256ebe
+        touch ${mnt}/nfs-ganesha/${dirname}/nfs/statd/state
256ebe
+    fi
256ebe
+
256ebe
+    for server in ${HA_SERVERS} ; do
256ebe
+
256ebe
+        if [[ ${server} != ${dirname} ]]; then
256ebe
+            ln -s ${mnt}/nfs-ganesha/${server}/nfs/ganesha ${mnt}/nfs-ganesha/${dirname}/nfs/ganesha/${server}
256ebe
+            ln -s ${mnt}/nfs-ganesha/${server}/nfs/statd ${mnt}/nfs-ganesha/${dirname}/nfs/statd/${server}
256ebe
+
256ebe
+            ln -s ${mnt}/nfs-ganesha/${dirname}/nfs/ganesha ${mnt}/nfs-ganesha/${server}/nfs/ganesha/${dirname}
256ebe
+            ln -s ${mnt}/nfs-ganesha/${dirname}/nfs/statd ${mnt}/nfs-ganesha/${server}/nfs/statd/${dirname}
256ebe
+        fi
256ebe
+    done
256ebe
+
256ebe
+}
256ebe
+
256ebe
+
256ebe
+delnode_state_volume()
256ebe
+{
256ebe
+    local delnode=${1}; shift
256ebe
+    local mnt=${HA_VOL_MNT}
256ebe
+    local longname=""
256ebe
+    local dname=""
256ebe
+    local dirname=""
256ebe
+
256ebe
+    longname=$(hostname)
256ebe
+    dname=${longname#$(hostname -s)}
256ebe
+
256ebe
+    if [[ ${delnode} == *${dname} ]]; then
256ebe
+        dirname=${delnode}
256ebe
+    else
256ebe
+        dirname=${delnode}${dname}
256ebe
+    fi
256ebe
+
256ebe
+    rm -rf ${mnt}/nfs-ganesha/${dirname}
256ebe
+
256ebe
+    for server in ${HA_SERVERS} ; do
256ebe
+        if [[ "${server}" != "${dirname}" ]]; then
256ebe
+            rm -f ${mnt}/nfs-ganesha/${server}/nfs/ganesha/${dirname}
256ebe
+            rm -f ${mnt}/nfs-ganesha/${server}/nfs/statd/${dirname}
256ebe
+        fi
256ebe
+    done
256ebe
+}
256ebe
+
256ebe
+
256ebe
+status()
256ebe
+{
256ebe
+    local scratch=$(mktemp)
256ebe
+    local regex_str="^${1}-cluster_ip-1"
256ebe
+    local healthy=0
256ebe
+    local index=1
256ebe
+    local nodes
256ebe
+
256ebe
+    # change tabs to spaces, strip leading spaces
256ebe
+    pcs status | sed -e "s/\t/ /g" -e "s/^[ ]*//" > ${scratch}
256ebe
+
256ebe
+    nodes[0]=${1}; shift
256ebe
+
256ebe
+    # make a regex of the configured nodes
256ebe
+    # and initalize the nodes array for later
256ebe
+    while [[ ${1} ]]; do
256ebe
+
256ebe
+        regex_str="${regex_str}|^${1}-cluster_ip-1"
256ebe
+        nodes[${index}]=${1}
256ebe
+        ((index++))
256ebe
+        shift
256ebe
+    done
256ebe
+
256ebe
+    # print the nodes that are expected to be online
256ebe
+    grep -E "^Online:" ${scratch}
256ebe
+
256ebe
+    echo
256ebe
+
256ebe
+    # print the VIPs and which node they are on
256ebe
+    grep -E "${regex_str}" < ${scratch} | cut -d ' ' -f 1,4
256ebe
+
256ebe
+    echo
256ebe
+
256ebe
+    # check if the VIP and port block/unblock RAs are on the expected nodes
256ebe
+    for n in ${nodes[*]}; do
256ebe
+
256ebe
+        grep -E -x "${n}-nfs_block \(ocf::heartbeat:portblock\): Started ${n}" > /dev/null 2>&1 ${scratch}
256ebe
+        result=$?
256ebe
+        ((healthy+=${result}))
256ebe
+        grep -E -x "${n}-cluster_ip-1 \(ocf::heartbeat:IPaddr\): Started ${n}" > /dev/null 2>&1 ${scratch}
256ebe
+        result=$?
256ebe
+        ((healthy+=${result}))
256ebe
+        grep -E -x "${n}-nfs_unblock \(ocf::heartbeat:portblock\): Started ${n}" > /dev/null 2>&1 ${scratch}
256ebe
+        result=$?
256ebe
+        ((healthy+=${result}))
256ebe
+    done
256ebe
+
256ebe
+    grep -E "\):\ Stopped|FAILED" > /dev/null 2>&1 ${scratch}
256ebe
+    result=$?
256ebe
+
256ebe
+    if [ ${result} -eq 0 ]; then
256ebe
+        echo "Cluster HA Status: BAD"
256ebe
+    elif [ ${healthy} -eq 0 ]; then
256ebe
+        echo "Cluster HA Status: HEALTHY"
256ebe
+    else
256ebe
+        echo "Cluster HA Status: FAILOVER"
256ebe
+    fi
256ebe
+
256ebe
+    rm -f ${scratch}
256ebe
+}
256ebe
+
256ebe
+create_ganesha_conf_file()
256ebe
+{
256ebe
+        if [ $1 == "yes" ];
256ebe
+        then
256ebe
+                if [  -e $GANESHA_CONF ];
256ebe
+                then
256ebe
+                        rm -rf $GANESHA_CONF
256ebe
+                fi
256ebe
+        # The symlink /etc/ganesha/ganesha.conf need to be
256ebe
+        # created using ganesha conf file mentioned in the
256ebe
+        # shared storage. Every node will only have this
256ebe
+        # link and actual file will stored in shared storage,
256ebe
+        # so that ganesha conf editing of ganesha conf will
256ebe
+        # be easy as well as it become more consistent.
256ebe
+
256ebe
+                ln -s $HA_CONFDIR/ganesha.conf $GANESHA_CONF
256ebe
+        else
256ebe
+        # Restoring previous file
256ebe
+                rm -rf $GANESHA_CONF
256ebe
+                cp $HA_CONFDIR/ganesha.conf $GANESHA_CONF
256ebe
+                sed -r -i -e '/^%include[[:space:]]+".+\.conf"$/d' $GANESHA_CONF
256ebe
+        fi
256ebe
+}
256ebe
+
256ebe
+set_quorum_policy()
256ebe
+{
256ebe
+    local quorum_policy="stop"
256ebe
+    local num_servers=${1}
256ebe
+
256ebe
+    if [ ${num_servers} -lt 3 ]; then
256ebe
+        quorum_policy="ignore"
256ebe
+    fi
256ebe
+    pcs property set no-quorum-policy=${quorum_policy}
256ebe
+    if [ $? -ne 0 ]; then
256ebe
+        logger "warning: pcs property set no-quorum-policy=${quorum_policy} failed"
256ebe
+    fi
256ebe
+}
256ebe
+
256ebe
+main()
256ebe
+{
256ebe
+
256ebe
+    local cmd=${1}; shift
256ebe
+    if [[ ${cmd} == *help ]]; then
256ebe
+        usage
256ebe
+        exit 0
256ebe
+    fi
256ebe
+    HA_CONFDIR=${1%/}; shift
256ebe
+    local ha_conf=${HA_CONFDIR}/ganesha-ha.conf
256ebe
+    local node=""
256ebe
+    local vip=""
256ebe
+
256ebe
+    # ignore any comment lines
256ebe
+    cfgline=$(grep  ^HA_NAME= ${ha_conf})
256ebe
+    eval $(echo ${cfgline} | grep -F HA_NAME=)
256ebe
+    cfgline=$(grep  ^HA_CLUSTER_NODES= ${ha_conf})
256ebe
+    eval $(echo ${cfgline} | grep -F HA_CLUSTER_NODES=)
256ebe
+
256ebe
+    case "${cmd}" in
256ebe
+
256ebe
+    setup | --setup)
256ebe
+        logger "setting up ${HA_NAME}"
256ebe
+
256ebe
+        check_cluster_exists ${HA_NAME}
256ebe
+
256ebe
+        determine_servers "setup"
256ebe
+
256ebe
+        if [ "X${HA_NUM_SERVERS}X" != "X1X" ]; then
256ebe
+
256ebe
+            setup_cluster ${HA_NAME} ${HA_NUM_SERVERS} "${HA_SERVERS}"
256ebe
+
256ebe
+            setup_create_resources ${HA_SERVERS}
256ebe
+
256ebe
+            setup_finalize_ha
256ebe
+
256ebe
+            setup_state_volume ${HA_SERVERS}
256ebe
+
256ebe
+        else
256ebe
+
256ebe
+            logger "insufficient servers for HA, aborting"
256ebe
+        fi
256ebe
+        ;;
256ebe
+
256ebe
+    teardown | --teardown)
256ebe
+        logger "tearing down ${HA_NAME}"
256ebe
+
256ebe
+        determine_servers "teardown"
256ebe
+
256ebe
+        teardown_resources ${HA_SERVERS}
256ebe
+
256ebe
+        teardown_cluster ${HA_NAME}
256ebe
+
256ebe
+        cleanup_ganesha_config ${HA_CONFDIR}
256ebe
+        ;;
256ebe
+
256ebe
+    cleanup | --cleanup)
256ebe
+        cleanup_ganesha_config ${HA_CONFDIR}
256ebe
+        ;;
256ebe
+
256ebe
+    add | --add)
256ebe
+        node=${1}; shift
256ebe
+        vip=${1}; shift
256ebe
+
256ebe
+        logger "adding ${node} with ${vip} to ${HA_NAME}"
256ebe
+
256ebe
+        determine_service_manager
256ebe
+
256ebe
+        manage_service "start" ${node}
256ebe
+
256ebe
+        determine_servers "add"
256ebe
+
256ebe
+        pcs cluster node add ${node}
256ebe
+        if [ $? -ne 0 ]; then
256ebe
+            logger "warning: pcs cluster node add ${node} failed"
256ebe
+        fi
256ebe
+
256ebe
+        addnode_create_resources ${node} ${vip}
256ebe
+        # Subsequent add-node recreates resources for all the nodes
256ebe
+        # that already exist in the cluster. The nodes are picked up
256ebe
+        # from the entries in the ganesha-ha.conf file. Adding the
256ebe
+        # newly added node to the file so that the resources specfic
256ebe
+        # to this node is correctly recreated in the future.
256ebe
+        clean_node=${node//[-.]/_}
256ebe
+        echo "VIP_${node}=\"${vip}\"" >> ${HA_CONFDIR}/ganesha-ha.conf
256ebe
+
256ebe
+        NEW_NODES="$HA_CLUSTER_NODES,${node}"
256ebe
+
256ebe
+        sed -i s/HA_CLUSTER_NODES.*/"HA_CLUSTER_NODES=\"$NEW_NODES\""/ \
256ebe
+$HA_CONFDIR/ganesha-ha.conf
256ebe
+
256ebe
+        addnode_state_volume ${node}
256ebe
+
256ebe
+        # addnode_create_resources() already appended ${node} to
256ebe
+        # HA_SERVERS, so only need to increment HA_NUM_SERVERS
256ebe
+        # and set quorum policy
256ebe
+        HA_NUM_SERVERS=$(expr ${HA_NUM_SERVERS} + 1)
256ebe
+        set_quorum_policy ${HA_NUM_SERVERS}
256ebe
+        ;;
256ebe
+
256ebe
+    delete | --delete)
256ebe
+        node=${1}; shift
256ebe
+
256ebe
+        logger "deleting ${node} from ${HA_NAME}"
256ebe
+
256ebe
+        determine_servers "delete"
256ebe
+
256ebe
+        deletenode_delete_resources ${node}
256ebe
+
256ebe
+        pcs cluster node remove ${node}
256ebe
+        if [ $? -ne 0 ]; then
256ebe
+            logger "warning: pcs cluster node remove ${node} failed"
256ebe
+        fi
256ebe
+
256ebe
+        deletenode_update_haconfig ${node}
256ebe
+
256ebe
+        delnode_state_volume ${node}
256ebe
+
256ebe
+        determine_service_manager
256ebe
+
256ebe
+        manage_service "stop" ${node}
256ebe
+
256ebe
+        HA_NUM_SERVERS=$(expr ${HA_NUM_SERVERS} - 1)
256ebe
+        set_quorum_policy ${HA_NUM_SERVERS}
256ebe
+        ;;
256ebe
+
256ebe
+    status | --status)
256ebe
+        determine_servers "status"
256ebe
+
256ebe
+        status ${HA_SERVERS}
256ebe
+        ;;
256ebe
+
256ebe
+    refresh-config | --refresh-config)
256ebe
+        VOL=${1}
256ebe
+
256ebe
+        determine_servers "refresh-config"
256ebe
+
256ebe
+        refresh_config ${VOL} ${HA_CONFDIR} ${HA_SERVERS}
256ebe
+        ;;
256ebe
+
256ebe
+    setup-ganesha-conf-files | --setup-ganesha-conf-files)
256ebe
+
256ebe
+        create_ganesha_conf_file ${1}
256ebe
+        ;;
256ebe
+
256ebe
+    *)
256ebe
+        # setup and teardown are not intended to be used by a
256ebe
+        # casual user
256ebe
+        usage
256ebe
+        logger "Usage: ganesha-ha.sh add|delete|status"
256ebe
+        ;;
256ebe
+
256ebe
+    esac
256ebe
+}
256ebe
+
256ebe
+main $*
256ebe
diff --git a/glusterfs.spec.in b/glusterfs.spec.in
256ebe
index dd7438c..d748ebc 100644
256ebe
--- a/glusterfs.spec.in
256ebe
+++ b/glusterfs.spec.in
256ebe
@@ -460,7 +460,8 @@ Summary:          NFS-Ganesha configuration
256ebe
 Group:            Applications/File
256ebe
 
256ebe
 Requires:         %{name}-server%{?_isa} = %{version}-%{release}
256ebe
-Requires:         nfs-ganesha-gluster, pcs, dbus
256ebe
+Requires:         nfs-ganesha-gluster >= 2.4.1
256ebe
+Requires:         pcs, dbus
256ebe
 %if ( 0%{?rhel} && 0%{?rhel} == 6 )
256ebe
 Requires:         cman, pacemaker, corosync
256ebe
 %endif
256ebe
@@ -1138,6 +1139,7 @@ exit 0
256ebe
 #exclude ganesha related files
256ebe
 %exclude %{_sysconfdir}/ganesha/*
256ebe
 %exclude %{_libexecdir}/ganesha/*
256ebe
+%exclude %{_prefix}/lib/ocf/resource.d/heartbeat/*
256ebe
 %endif
256ebe
 
256ebe
 %files api
256ebe
@@ -1306,6 +1308,7 @@ exit 0
256ebe
 %files ganesha
256ebe
 %{_sysconfdir}/ganesha/*
256ebe
 %{_libexecdir}/ganesha/*
256ebe
+%{_prefix}/lib/ocf/resource.d/heartbeat/*
256ebe
 %endif
256ebe
 
256ebe
 %if ( 0%{!?_without_ocf:1} )
256ebe
@@ -1904,6 +1907,9 @@ fi
256ebe
 %endif
256ebe
 
256ebe
 %changelog
256ebe
+* Sat Apr 6 2019 Jiffin Tony Thottan <jthottan@redhat.com>
256ebe
+- Adding ganesha ha resources back in gluster repository
256ebe
+
256ebe
 * Fri Apr 5 2019 Jiffin Tony Thottan <jthottan@redhat.com>
256ebe
 - Adding ganesha bits back in gluster repository
256ebe
 
256ebe
-- 
256ebe
1.8.3.1
256ebe