12a457
From 53d5b5edb7994ad28c8b1faa564c023c20cf9b69 Mon Sep 17 00:00:00 2001
12a457
From: Kotresh HR <khiremat@redhat.com>
12a457
Date: Tue, 29 Mar 2016 19:06:46 +0530
12a457
Subject: [PATCH 63/80] features/changelog: Don't modify 'pargfid' in 'resolve_pargfid_to_path'
12a457
12a457
Backport of http://review.gluster.org/#/c/13845/
12a457
12a457
If 'changelog' is enabled and 'changelog.capture-del-path' option is on
12a457
it calls 'resolve_pargfid_to_path' which modifies 'pargfid' sent by
12a457
caller.  'changelog_unlink' calls this routine directly with
12a457
'loc->pargfid' resulting it being modified and point to root instead of
12a457
actual pargfid. This is a nasty bug and could cause the deletion of
12a457
entry on root directory instead on actual parent when 'loc->path' is
12a457
not present.  Hence this fix to make 'pargfid' a const pointer and
12a457
'resolve_pargfid' to work on copy of pargfid.
12a457
12a457
Glusterfind session creation enables these options by default to
12a457
capture deleted entry path in changelog.
12a457
12a457
Thanks Pranith for root causing this.
12a457
12a457
Upstream Reference:
12a457
>BUG: 1322552
12a457
>Change-Id: I9f2bc44b5604b224462594c12b7d79e68198d693
12a457
>Signed-off-by: Kotresh HR <khiremat@redhat.com>
12a457
>Reviewed-on: http://review.gluster.org/13861
12a457
>Smoke: Gluster Build System <jenkins@build.gluster.com>
12a457
>NetBSD-regression: NetBSD Build System <jenkins@build.gluster.org>
12a457
>CentOS-regression: Gluster Build System <jenkins@build.gluster.com>
12a457
>Reviewed-by: Venky Shankar <vshankar@redhat.com>
12a457
12a457
BUG: 1317908
12a457
Change-Id: I61fa1d322f949bc4d5dd572b3eff30043e7815f6
12a457
Signed-off-by: Kotresh HR <khiremat@redhat.com>
12a457
Reviewed-on: https://code.engineering.redhat.com/gerrit/71873
12a457
Reviewed-by: Aravinda Vishwanathapura Krishna Murthy <avishwan@redhat.com>
12a457
Tested-by: Aravinda Vishwanathapura Krishna Murthy <avishwan@redhat.com>
12a457
---
12a457
 libglusterfs/src/compat-uuid.h                     |    2 +-
12a457
 tests/bugs/changelog/bug-1321955.t                 |   60 ++++++++++++++++++++
12a457
 xlators/features/changelog/src/changelog-helpers.c |    4 +-
12a457
 xlators/features/changelog/src/changelog-helpers.h |    3 +-
12a457
 4 files changed, 66 insertions(+), 3 deletions(-)
12a457
 create mode 100644 tests/bugs/changelog/bug-1321955.t
12a457
12a457
diff --git a/libglusterfs/src/compat-uuid.h b/libglusterfs/src/compat-uuid.h
12a457
index 4161b95..8dac699 100644
12a457
--- a/libglusterfs/src/compat-uuid.h
12a457
+++ b/libglusterfs/src/compat-uuid.h
12a457
@@ -28,7 +28,7 @@ gf_uuid_compare (uuid_t u1, uuid_t u2)
12a457
 }
12a457
 
12a457
 static inline void
12a457
-gf_uuid_copy (uuid_t dst, uuid_t src)
12a457
+gf_uuid_copy (uuid_t dst, const uuid_t src)
12a457
 {
12a457
         uuid_copy (dst, src);
12a457
 }
12a457
diff --git a/tests/bugs/changelog/bug-1321955.t b/tests/bugs/changelog/bug-1321955.t
12a457
new file mode 100644
12a457
index 0000000..9e3752b
12a457
--- /dev/null
12a457
+++ b/tests/bugs/changelog/bug-1321955.t
12a457
@@ -0,0 +1,60 @@
12a457
+#!/bin/bash
12a457
+
12a457
+#This file checks if missing entry self-heal and entry self-heal are working
12a457
+#as expected.
12a457
+. $(dirname $0)/../../include.rc
12a457
+. $(dirname $0)/../../volume.rc
12a457
+. $(dirname $0)/../../afr.rc
12a457
+
12a457
+cleanup;
12a457
+
12a457
+TEST glusterd
12a457
+TEST pidof glusterd
12a457
+TEST $CLI volume create $V0 replica 2 $H0:$B0/${V0}{0,1}
12a457
+TEST $CLI volume set $V0 changelog.changelog enable
12a457
+TEST $CLI volume set $V0 changelog.capture-del-path on
12a457
+TEST $CLI volume start $V0
12a457
+
12a457
+#Mount the volume
12a457
+TEST glusterfs --volfile-id=/$V0 --volfile-server=$H0 $M0 --attribute-timeout=0 --entry-timeout=0
12a457
+
12a457
+#Create files
12a457
+TEST touch $M0/file1
12a457
+TEST mkdir $M0/dir1
12a457
+TEST touch $M0/dir1/file1
12a457
+
12a457
+#Check for presence of files
12a457
+TEST stat $B0/${V0}0/dir1/file1
12a457
+TEST stat $B0/${V0}1/dir1/file1
12a457
+TEST stat $B0/${V0}0/file1
12a457
+TEST stat $B0/${V0}1/file1
12a457
+
12a457
+#Kill brick1
12a457
+TEST kill_brick $V0 $H0 $B0/${V0}1
12a457
+
12a457
+#Del dir1/file1
12a457
+TEST rm -f $M0/dir1/file1
12a457
+
12a457
+#file1 should be present in brick1 and not in brick0
12a457
+TEST ! stat $B0/${V0}0/dir1/file1
12a457
+TEST stat $B0/${V0}1/dir1/file1
12a457
+
12a457
+#Bring up the brick which is down
12a457
+TEST $CLI volume start $V0 force
12a457
+EXPECT_WITHIN $CHILD_UP_TIMEOUT "1" afr_child_up_status $V0 0
12a457
+EXPECT_WITHIN $CHILD_UP_TIMEOUT "1" afr_child_up_status $V0 1
12a457
+EXPECT_WITHIN $CHILD_UP_TIMEOUT "1" afr_child_up_status_in_shd $V0 0
12a457
+EXPECT_WITHIN $CHILD_UP_TIMEOUT "1" afr_child_up_status_in_shd $V0 1
12a457
+
12a457
+#Initiate heal
12a457
+TEST $CLI volume heal $V0
12a457
+
12a457
+EXPECT_WITHIN $HEAL_TIMEOUT "0" get_pending_heal_count $V0
12a457
+
12a457
+#dir1/file1 in brick1 should be deleted
12a457
+TEST ! stat $B0/${V0}1/dir1/file1
12a457
+
12a457
+#file1 under root should not be deleted in brick1
12a457
+TEST stat $B0/${V0}1/file1
12a457
+
12a457
+cleanup;
12a457
diff --git a/xlators/features/changelog/src/changelog-helpers.c b/xlators/features/changelog/src/changelog-helpers.c
12a457
index d692753..ba98021 100644
12a457
--- a/xlators/features/changelog/src/changelog-helpers.c
12a457
+++ b/xlators/features/changelog/src/changelog-helpers.c
12a457
@@ -1847,7 +1847,7 @@ err:
12a457
  */
12a457
 
12a457
 int
12a457
-resolve_pargfid_to_path (xlator_t *this, uuid_t pargfid,
12a457
+resolve_pargfid_to_path (xlator_t *this, const uuid_t pgfid,
12a457
                          char **path, char *bname)
12a457
 {
12a457
         char             *linkname                  = NULL;
12a457
@@ -1857,6 +1857,7 @@ resolve_pargfid_to_path (xlator_t *this, uuid_t pargfid,
12a457
         ssize_t           len                       = 0;
12a457
         int               ret                       = 0;
12a457
         uuid_t            tmp_gfid                  = {0, };
12a457
+        uuid_t            pargfid                   = {0, };
12a457
         changelog_priv_t *priv                      = NULL;
12a457
         char              gpath[PATH_MAX]           = {0,};
12a457
         char              result[PATH_MAX]          = {0,};
12a457
@@ -1867,6 +1868,7 @@ resolve_pargfid_to_path (xlator_t *this, uuid_t pargfid,
12a457
         priv = this->private;
12a457
         GF_ASSERT (priv);
12a457
 
12a457
+        gf_uuid_copy (pargfid, pgfid);
12a457
         if (!path || gf_uuid_is_null (pargfid)) {
12a457
                 ret = -1;
12a457
                 goto out;
12a457
diff --git a/xlators/features/changelog/src/changelog-helpers.h b/xlators/features/changelog/src/changelog-helpers.h
12a457
index b4f0ed0..1d548ca 100644
12a457
--- a/xlators/features/changelog/src/changelog-helpers.h
12a457
+++ b/xlators/features/changelog/src/changelog-helpers.h
12a457
@@ -503,7 +503,8 @@ changelog_inode_ctx_t *
12a457
 __changelog_inode_ctx_get (xlator_t *, inode_t *, unsigned long **,
12a457
                            unsigned long *, changelog_log_type);
12a457
 int
12a457
-resolve_pargfid_to_path (xlator_t *this, uuid_t gfid, char **path, char *bname);
12a457
+resolve_pargfid_to_path (xlator_t *this, const uuid_t gfid, char **path,
12a457
+                         char *bname);
12a457
 
12a457
 /* macros */
12a457
 
12a457
-- 
12a457
1.7.1
12a457