12a457
From 8e22047bae9d51e0e67f455eb88c46c0b7ca0226 Mon Sep 17 00:00:00 2001
12a457
From: Soumya Koduri <skoduri@redhat.com>
12a457
Date: Mon, 14 Mar 2016 16:36:33 +0530
12a457
Subject: [PATCH 68/80] ganesha: Include a script to generate epoch value
12a457
12a457
This is a backport of the below upstream fix -
12a457
        http://review.gluster.org/13744
12a457
12a457
In a NFS-Ganesha HA cluster setup, for NFS clients to recover state
12a457
succesfully post failover, the NFS-servers should start with a unique
12a457
epoch value.
12a457
12a457
With NFS-Ganesha 2.3, the service accepts an option "EPOCH_EXEC" which
12a457
takes path of the script, generating epoch value. This script is executed before
12a457
starting nfs-ganesha service so that the generated epoch value is used
12a457
while bringing up the service.
12a457
12a457
This patch includes the script to be used by nfs-ganesha+gluster setup.
12a457
12a457
The epoch value is computed as follows -
12a457
       - first 32-bit contains the now() time
12a457
       - rest 32-bit value contains the local glusterd node uuid
12a457
12a457
Change-Id: I876ea5a3730d7c6b40503e0fec16a4a142c54a36
12a457
BUG: 1242358
12a457
Signed-off-by: Soumya Koduri <skoduri@redhat.com>
12a457
Reviewed-on: http://review.gluster.org/13744
12a457
Reviewed-by: jiffin tony Thottan <jthottan@redhat.com>
12a457
Reviewed-by: Kaleb KEITHLEY <kkeithle@redhat.com>
12a457
Reviewed-on: https://code.engineering.redhat.com/gerrit/71836
12a457
Reviewed-by: Kaleb Keithley <kkeithle@redhat.com>
12a457
Tested-by: Kaleb Keithley <kkeithle@redhat.com>
12a457
---
12a457
 extras/ganesha/scripts/Makefile.am       |    6 ++-
12a457
 extras/ganesha/scripts/generate-epoch.py |   48 ++++++++++++++++++++++++++++++
12a457
 2 files changed, 52 insertions(+), 2 deletions(-)
12a457
 create mode 100755 extras/ganesha/scripts/generate-epoch.py
12a457
12a457
diff --git a/extras/ganesha/scripts/Makefile.am b/extras/ganesha/scripts/Makefile.am
12a457
index e71e2f6..224ed26 100644
12a457
--- a/extras/ganesha/scripts/Makefile.am
12a457
+++ b/extras/ganesha/scripts/Makefile.am
12a457
@@ -1,4 +1,6 @@
12a457
-EXTRA_DIST= ganesha-ha.sh dbus-send.sh create-export-ganesha.sh
12a457
+EXTRA_DIST= ganesha-ha.sh dbus-send.sh create-export-ganesha.sh \
12a457
+            generate-epoch.py
12a457
 
12a457
 scriptsdir = $(libexecdir)/ganesha
12a457
-scripts_SCRIPTS = create-export-ganesha.sh dbus-send.sh ganesha-ha.sh
12a457
+scripts_SCRIPTS = create-export-ganesha.sh dbus-send.sh ganesha-ha.sh \
12a457
+                  generate-epoch.py
12a457
diff --git a/extras/ganesha/scripts/generate-epoch.py b/extras/ganesha/scripts/generate-epoch.py
12a457
new file mode 100755
12a457
index 0000000..5db5e56
12a457
--- /dev/null
12a457
+++ b/extras/ganesha/scripts/generate-epoch.py
12a457
@@ -0,0 +1,48 @@
12a457
+#!/usr/bin/python
12a457
+#
12a457
+# Copyright (c) 2016 Red Hat, Inc. <http://www.redhat.com>
12a457
+# This file is part of GlusterFS.
12a457
+#
12a457
+# This file is licensed to you under your choice of the GNU Lesser
12a457
+# General Public License, version 3 or any later version (LGPLv3 or
12a457
+# later), or the GNU General Public License, version 2 (GPLv2), in all
12a457
+# cases as published by the Free Software Foundation.
12a457
+#
12a457
+# Generates unique epoch value on each gluster node to be used by
12a457
+# nfs-ganesha service on that node.
12a457
+#
12a457
+# Configure 'EPOCH_EXEC' option to this script path in
12a457
+# '/etc/sysconfig/ganesha' file used by nfs-ganesha service.
12a457
+#
12a457
+# Construct epoch as follows -
12a457
+#        first 32-bit contains the now() time
12a457
+#        rest 32-bit value contains the local glusterd node uuid
12a457
+
12a457
+import time
12a457
+import binascii
12a457
+
12a457
+# Calculate the now() time into a 64-bit integer value
12a457
+def epoch_now():
12a457
+        epoch_time = int(time.mktime(time.localtime())) << 32
12a457
+        return epoch_time
12a457
+
12a457
+# Read glusterd UUID and extract first 32-bit of it
12a457
+def epoch_uuid():
12a457
+        file_name = '/var/lib/glusterd/glusterd.info'
12a457
+
12a457
+        for line in open(file_name):
12a457
+                if "UUID" in line:
12a457
+                        glusterd_uuid = line.split('=')[1].strip()
12a457
+
12a457
+        uuid_bin = binascii.unhexlify(glusterd_uuid.replace("-",""))
12a457
+
12a457
+        epoch_uuid = int(uuid_bin.encode('hex'), 32) & 0xFFFF0000
12a457
+        return epoch_uuid
12a457
+
12a457
+# Construct epoch as follows -
12a457
+#        first 32-bit contains the now() time
12a457
+#        rest 32-bit value contains the local glusterd node uuid
12a457
+epoch = (epoch_now() | epoch_uuid())
12a457
+print str(epoch)
12a457
+
12a457
+exit(0)
12a457
-- 
12a457
1.7.1
12a457