7f4c2a
From 4abf18c10a0949ce30e3413071778f5f33449b1f Mon Sep 17 00:00:00 2001
7f4c2a
From: Ravishankar N <ravishankar@redhat.com>
7f4c2a
Date: Mon, 17 Aug 2015 10:29:19 +0000
7f4c2a
Subject: [PATCH 295/304] heal: Add check for healing directories in split-brain
7f4c2a
7f4c2a
Patch in master: http://review.gluster.org/#/c/11937/
7f4c2a
Patch in release-3.7: http://review.gluster.org/#/c/12007/
7f4c2a
7f4c2a
1. Healing using  `bigger-file' option does not make much sense for directories,
7f4c2a
hence disallow it and notify the user.
7f4c2a
2. Healing using 'source-brick' option for directories performs a conservative
7f4c2a
merge. Notify the user about it.
7f4c2a
7f4c2a
Change-Id: Iafaa7a7ed2ab2c97472cd29efefb318bcfee3dbb
7f4c2a
BUG: 1234399
7f4c2a
Signed-off-by: Ravishankar N <ravishankar@redhat.com>
7f4c2a
Reviewed-on: https://code.engineering.redhat.com/gerrit/56153
7f4c2a
Reviewed-by: Pranith Kumar Karampuri <pkarampu@redhat.com>
7f4c2a
Tested-by: Pranith Kumar Karampuri <pkarampu@redhat.com>
7f4c2a
---
7f4c2a
 heal/src/glfs-heal.c |   28 +++++++++++++++++++++++++++-
7f4c2a
 1 files changed, 27 insertions(+), 1 deletions(-)
7f4c2a
7f4c2a
diff --git a/heal/src/glfs-heal.c b/heal/src/glfs-heal.c
7f4c2a
index bc76518..3b3003e 100644
7f4c2a
--- a/heal/src/glfs-heal.c
7f4c2a
+++ b/heal/src/glfs-heal.c
7f4c2a
@@ -535,6 +535,27 @@ glfsh_gather_heal_info (glfs_t *fs, xlator_t *top_subvol, loc_t *rootloc,
7f4c2a
 }
7f4c2a
 
7f4c2a
 int
7f4c2a
+_validate_directory (dict_t *xattr_req, char *file)
7f4c2a
+{
7f4c2a
+        int heal_op = -1;
7f4c2a
+        int ret = 0;
7f4c2a
+
7f4c2a
+        ret = dict_get_int32 (xattr_req, "heal-op", &heal_op);
7f4c2a
+        if (ret)
7f4c2a
+                return ret;
7f4c2a
+
7f4c2a
+        if (heal_op == GF_SHD_OP_SBRAIN_HEAL_FROM_BIGGER_FILE) {
7f4c2a
+                printf ("'bigger-file' not a valid option for directories.\n");
7f4c2a
+                ret = -1;
7f4c2a
+        } else if (heal_op == GF_SHD_OP_SBRAIN_HEAL_FROM_BRICK) {
7f4c2a
+                printf ("'source-brick' option used on a directory (%s). "
7f4c2a
+                        "Performing conservative merge.\n", file);
7f4c2a
+        }
7f4c2a
+
7f4c2a
+        return ret;
7f4c2a
+}
7f4c2a
+
7f4c2a
+int
7f4c2a
 glfsh_heal_splitbrain_file (glfs_t *fs, xlator_t *top_subvol, loc_t *rootloc,
7f4c2a
                            char *file, dict_t *xattr_req)
7f4c2a
 {
7f4c2a
@@ -556,7 +577,7 @@ glfsh_heal_splitbrain_file (glfs_t *fs, xlator_t *top_subvol, loc_t *rootloc,
7f4c2a
                 gf_uuid_parse (path, loc.gfid);
7f4c2a
                 loc.path = gf_strdup (uuid_utoa (loc.gfid));
7f4c2a
                 loc.inode = inode_new (rootloc->inode->table);
7f4c2a
-                ret = syncop_lookup (xl, &loc, 0, 0, xattr_req, &xattr_rsp);
7f4c2a
+                ret = syncop_lookup (xl, &loc, &iatt, 0, xattr_req, &xattr_rsp);
7f4c2a
                 if (ret) {
7f4c2a
                         op_errno = -ret;
7f4c2a
                         printf ("Lookup failed on %s:%s.\n", file,
7f4c2a
@@ -580,6 +601,11 @@ retry:
7f4c2a
                 }
7f4c2a
         }
7f4c2a
 
7f4c2a
+        if (iatt.ia_type == IA_IFDIR) {
7f4c2a
+                ret = _validate_directory (xattr_req, file);
7f4c2a
+                if (ret)
7f4c2a
+                        goto out;
7f4c2a
+        }
7f4c2a
         ret = syncop_getxattr (xl, &loc, &xattr_rsp, GF_AFR_HEAL_SBRAIN,
7f4c2a
                                xattr_req, NULL);
7f4c2a
         if (ret) {
7f4c2a
-- 
7f4c2a
1.7.1
7f4c2a