Blob Blame History Raw
From 3a98eaa0735fbe272525729e54497088d699005c Mon Sep 17 00:00:00 2001
From: Pranith Kumar K <pkarampu@redhat.com>
Date: Thu, 19 May 2016 16:24:09 +0530
Subject: [PATCH 162/167] cluster/afr: Do not inode_link in afr

Race is explained at
https://bugzilla.redhat.com/show_bug.cgi?id=1337405#c0

This patch also handles performing of self-heal with shd-pid.
Also performs the healing with this->itable's inode rather than
main itable.

 >BUG: 1337405
 >Change-Id: Id657a6623b71998b027b1dff6af5bbdf8cab09c9
 >Signed-off-by: Pranith Kumar K <pkarampu@redhat.com>
 >Reviewed-on: http://review.gluster.org/14422
 >Smoke: Gluster Build System <jenkins@build.gluster.com>
 >NetBSD-regression: NetBSD Build System <jenkins@build.gluster.org>
 >CentOS-regression: Gluster Build System <jenkins@build.gluster.com>
 >Reviewed-by: Krutika Dhananjay <kdhananj@redhat.com>

release-3.7: https://review.gluster.org/14456

BUG: 1331280
Change-Id: Ibd9c0e70b82fca3719bed0cfd1313ed6a3065da9
Signed-off-by: Pranith Kumar K <pkarampu@redhat.com>
Reviewed-on: https://code.engineering.redhat.com/gerrit/74772
---
 .../bug-1134691-afr-lookup-metadata-heal.t         |    3 +-
 xlators/cluster/afr/src/afr-common.c               |    6 +--
 xlators/cluster/afr/src/afr-self-heal-metadata.c   |   42 ++++++++++++++++++++
 xlators/cluster/afr/src/afr-self-heal.h            |    3 +
 4 files changed, 48 insertions(+), 6 deletions(-)

diff --git a/tests/bugs/replicate/bug-1134691-afr-lookup-metadata-heal.t b/tests/bugs/replicate/bug-1134691-afr-lookup-metadata-heal.t
index f43c7ce..44c2ed2 100644
--- a/tests/bugs/replicate/bug-1134691-afr-lookup-metadata-heal.t
+++ b/tests/bugs/replicate/bug-1134691-afr-lookup-metadata-heal.t
@@ -8,8 +8,9 @@ cleanup;
 TEST glusterd
 TEST pidof glusterd
 TEST $CLI volume create $V0 replica 3 $H0:$B0/brick{0,1,2}
-TEST $CLI volume start $V0
+TEST $CLI volume set $V0 performance.stat-prefetch off
 TEST $CLI volume set $V0 cluster.self-heal-daemon off
+TEST $CLI volume start $V0
 TEST glusterfs --volfile-id=/$V0 --volfile-server=$H0 $M0 --attribute-timeout=0 --entry-timeout=0
 
 cd $M0
diff --git a/xlators/cluster/afr/src/afr-common.c b/xlators/cluster/afr/src/afr-common.c
index 6e84b81..3bed0c5 100644
--- a/xlators/cluster/afr/src/afr-common.c
+++ b/xlators/cluster/afr/src/afr-common.c
@@ -1962,13 +1962,9 @@ afr_lookup_sh_metadata_wrap (void *opaque)
         if (first == -1)
                 goto out;
 
-        inode = inode_link (local->inode, NULL, NULL, &replies[first].poststat);
-        if(!inode)
+        if (afr_selfheal_metadata_by_stbuf (this, &replies[first].poststat))
                 goto out;
 
-        afr_selfheal_metadata (frame, this, inode);
-        inode_unref (inode);
-
         afr_local_replies_wipe (local, this->private);
 
         dict = dict_new ();
diff --git a/xlators/cluster/afr/src/afr-self-heal-metadata.c b/xlators/cluster/afr/src/afr-self-heal-metadata.c
index d6daadc..014d53b 100644
--- a/xlators/cluster/afr/src/afr-self-heal-metadata.c
+++ b/xlators/cluster/afr/src/afr-self-heal-metadata.c
@@ -435,3 +435,45 @@ unlock:
                 afr_replies_wipe (locked_replies, priv->child_count);
 	return ret;
 }
+
+int
+afr_selfheal_metadata_by_stbuf (xlator_t *this, struct iatt *stbuf)
+{
+        inode_t      *inode      = NULL;
+        inode_t      *link_inode = NULL;
+        call_frame_t *frame      = NULL;
+        int          ret         = 0;
+
+        if (gf_uuid_is_null (stbuf->ia_gfid)) {
+                ret = -EINVAL;
+                goto out;
+        }
+
+        inode = inode_new (this->itable);
+        if (!inode) {
+                ret = -ENOMEM;
+                goto out;
+        }
+
+        link_inode = inode_link (inode, NULL, NULL, stbuf);
+        if (!link_inode) {
+                ret = -ENOMEM;
+                goto out;
+        }
+
+        frame = afr_frame_create (this);
+        if (!frame) {
+                ret = -ENOMEM;
+                goto out;
+        }
+
+        ret = afr_selfheal_metadata (frame, this, link_inode);
+out:
+        if (inode)
+                inode_unref (inode);
+        if (link_inode)
+                inode_unref (link_inode);
+        if (frame)
+                AFR_STACK_DESTROY (frame);
+        return ret;
+}
diff --git a/xlators/cluster/afr/src/afr-self-heal.h b/xlators/cluster/afr/src/afr-self-heal.h
index afc086c..f54eb9c 100644
--- a/xlators/cluster/afr/src/afr-self-heal.h
+++ b/xlators/cluster/afr/src/afr-self-heal.h
@@ -277,4 +277,7 @@ afr_locked_fill (call_frame_t *frame, xlator_t *this,
 int
 afr_choose_source_by_policy (afr_private_t *priv, unsigned char *sources,
                              afr_transaction_type type);
+
+int
+afr_selfheal_metadata_by_stbuf (xlator_t *this, struct iatt *stbuf);
 #endif /* !_AFR_SELFHEAL_H */
-- 
1.7.1