Blob Blame History Raw
From 8e22047bae9d51e0e67f455eb88c46c0b7ca0226 Mon Sep 17 00:00:00 2001
From: Soumya Koduri <skoduri@redhat.com>
Date: Mon, 14 Mar 2016 16:36:33 +0530
Subject: [PATCH 68/80] ganesha: Include a script to generate epoch value

This is a backport of the below upstream fix -
        http://review.gluster.org/13744

In a NFS-Ganesha HA cluster setup, for NFS clients to recover state
succesfully post failover, the NFS-servers should start with a unique
epoch value.

With NFS-Ganesha 2.3, the service accepts an option "EPOCH_EXEC" which
takes path of the script, generating epoch value. This script is executed before
starting nfs-ganesha service so that the generated epoch value is used
while bringing up the service.

This patch includes the script to be used by nfs-ganesha+gluster setup.

The epoch value is computed as follows -
       - first 32-bit contains the now() time
       - rest 32-bit value contains the local glusterd node uuid

Change-Id: I876ea5a3730d7c6b40503e0fec16a4a142c54a36
BUG: 1242358
Signed-off-by: Soumya Koduri <skoduri@redhat.com>
Reviewed-on: http://review.gluster.org/13744
Reviewed-by: jiffin tony Thottan <jthottan@redhat.com>
Reviewed-by: Kaleb KEITHLEY <kkeithle@redhat.com>
Reviewed-on: https://code.engineering.redhat.com/gerrit/71836
Reviewed-by: Kaleb Keithley <kkeithle@redhat.com>
Tested-by: Kaleb Keithley <kkeithle@redhat.com>
---
 extras/ganesha/scripts/Makefile.am       |    6 ++-
 extras/ganesha/scripts/generate-epoch.py |   48 ++++++++++++++++++++++++++++++
 2 files changed, 52 insertions(+), 2 deletions(-)
 create mode 100755 extras/ganesha/scripts/generate-epoch.py

diff --git a/extras/ganesha/scripts/Makefile.am b/extras/ganesha/scripts/Makefile.am
index e71e2f6..224ed26 100644
--- a/extras/ganesha/scripts/Makefile.am
+++ b/extras/ganesha/scripts/Makefile.am
@@ -1,4 +1,6 @@
-EXTRA_DIST= ganesha-ha.sh dbus-send.sh create-export-ganesha.sh
+EXTRA_DIST= ganesha-ha.sh dbus-send.sh create-export-ganesha.sh \
+            generate-epoch.py
 
 scriptsdir = $(libexecdir)/ganesha
-scripts_SCRIPTS = create-export-ganesha.sh dbus-send.sh ganesha-ha.sh
+scripts_SCRIPTS = create-export-ganesha.sh dbus-send.sh ganesha-ha.sh \
+                  generate-epoch.py
diff --git a/extras/ganesha/scripts/generate-epoch.py b/extras/ganesha/scripts/generate-epoch.py
new file mode 100755
index 0000000..5db5e56
--- /dev/null
+++ b/extras/ganesha/scripts/generate-epoch.py
@@ -0,0 +1,48 @@
+#!/usr/bin/python
+#
+# Copyright (c) 2016 Red Hat, Inc. <http://www.redhat.com>
+# This file is part of GlusterFS.
+#
+# This file is licensed to you under your choice of the GNU Lesser
+# General Public License, version 3 or any later version (LGPLv3 or
+# later), or the GNU General Public License, version 2 (GPLv2), in all
+# cases as published by the Free Software Foundation.
+#
+# Generates unique epoch value on each gluster node to be used by
+# nfs-ganesha service on that node.
+#
+# Configure 'EPOCH_EXEC' option to this script path in
+# '/etc/sysconfig/ganesha' file used by nfs-ganesha service.
+#
+# Construct epoch as follows -
+#        first 32-bit contains the now() time
+#        rest 32-bit value contains the local glusterd node uuid
+
+import time
+import binascii
+
+# Calculate the now() time into a 64-bit integer value
+def epoch_now():
+        epoch_time = int(time.mktime(time.localtime())) << 32
+        return epoch_time
+
+# Read glusterd UUID and extract first 32-bit of it
+def epoch_uuid():
+        file_name = '/var/lib/glusterd/glusterd.info'
+
+        for line in open(file_name):
+                if "UUID" in line:
+                        glusterd_uuid = line.split('=')[1].strip()
+
+        uuid_bin = binascii.unhexlify(glusterd_uuid.replace("-",""))
+
+        epoch_uuid = int(uuid_bin.encode('hex'), 32) & 0xFFFF0000
+        return epoch_uuid
+
+# Construct epoch as follows -
+#        first 32-bit contains the now() time
+#        rest 32-bit value contains the local glusterd node uuid
+epoch = (epoch_now() | epoch_uuid())
+print str(epoch)
+
+exit(0)
-- 
1.7.1