Blob Blame History Raw
From ba1cff27de61cc64147bd38fc13de9a1e02f5b71 Mon Sep 17 00:00:00 2001
From: Ravishankar N <ravishankar@redhat.com>
Date: Wed, 14 Dec 2016 22:48:20 +0530
Subject: [PATCH 243/246] glfsheal: Explicitly enable self-heal xlator options

Backport of : http://review.gluster.org/11333

Enable data, metadata and entry self-heal as xlator-options so that glfs-heal.c
can heal split-brain files even if they are disabled on the volume via volume
set commands.

Change-Id: I382f523aac2a30fc60e2d37c9f1ca3a64ac40d13
BUG: 1403840
Signed-off-by: Ravishankar N <ravishankar@redhat.com>
Reviewed-on: https://code.engineering.redhat.com/gerrit/93108
Reviewed-by: Pranith Kumar Karampuri <pkarampu@redhat.com>
Tested-by: Pranith Kumar Karampuri <pkarampu@redhat.com>
---
 heal/src/glfs-heal.c                  | 32 ++++++++++++++++++++++++++++++++
 tests/basic/afr/split-brain-healing.t |  3 +++
 2 files changed, 35 insertions(+)

diff --git a/heal/src/glfs-heal.c b/heal/src/glfs-heal.c
index 94cb6b0..07fc6ac 100644
--- a/heal/src/glfs-heal.c
+++ b/heal/src/glfs-heal.c
@@ -877,6 +877,31 @@ out:
 }
 
 static int
+glfsh_set_heal_options (glfs_t *fs, gf_xl_afr_op_t heal_op)
+{
+        int ret = 0;
+
+        if ((heal_op != GF_SHD_OP_SBRAIN_HEAL_FROM_BIGGER_FILE) &&
+            (heal_op != GF_SHD_OP_SBRAIN_HEAL_FROM_BRICK) &&
+            (heal_op != GF_SHD_OP_SBRAIN_HEAL_FROM_LATEST_MTIME))
+                return 0;
+        ret = glfs_set_xlator_option (fs, "*-replicate-*", "data-self-heal",
+                                      "on");
+        if (ret)
+                goto out;
+
+        ret = glfs_set_xlator_option (fs, "*-replicate-*", "metadata-self-heal",
+                                      "on");
+        if (ret)
+                goto out;
+
+        ret = glfs_set_xlator_option (fs, "*-replicate-*", "entry-self-heal",
+                                      "on");
+out:
+        return ret;
+}
+
+static int
 glfsh_validate_volume (xlator_t *xl, gf_xl_afr_op_t heal_op)
 {
         xlator_t        *heal_xl = NULL;
@@ -1348,6 +1373,13 @@ main (int argc, char **argv)
                              "%s", strerror (errno));
                 goto out;
         }
+
+        ret = glfsh_set_heal_options (fs, heal_op);
+        if (ret) {
+                printf ("Setting xlator heal options failed, %s\n",
+                        strerror(errno));
+                goto out;
+        }
         snprintf (logfilepath, sizeof (logfilepath),
                   DEFAULT_HEAL_LOG_FILE_DIRECTORY"/glfsheal-%s.log", volname);
         ret = glfs_set_logging(fs, logfilepath, GF_LOG_INFO);
diff --git a/tests/basic/afr/split-brain-healing.t b/tests/basic/afr/split-brain-healing.t
index 302a3e6..c66bb5d 100644
--- a/tests/basic/afr/split-brain-healing.t
+++ b/tests/basic/afr/split-brain-healing.t
@@ -31,6 +31,9 @@ TEST glusterd
 TEST pidof glusterd
 TEST $CLI volume create $V0 replica 2 $H0:$B0/${V0}{1,2,3,4}
 TEST $CLI volume set $V0 cluster.self-heal-daemon off
+TEST $CLI volume set $V0 cluster.data-self-heal off
+TEST $CLI volume set $V0 cluster.metadata-self-heal off
+TEST $CLI volume set $V0 cluster.entry-self-heal off
 TEST $CLI volume start $V0
 TEST glusterfs --volfile-id=/$V0 --volfile-server=$H0 $M0 --attribute-timeout=0 --entry-timeout=0
 
-- 
2.9.3