Blob Blame History Raw
From 693ac3854f5c94ff2e4971c5c9bccc63c7eed8fc Mon Sep 17 00:00:00 2001
From: Krutika Dhananjay <kdhananj@redhat.com>
Date: Tue, 5 Sep 2017 21:42:26 +0530
Subject: [PATCH 611/616] features/shard: Return aggregated size in stbuf of
 LINK fop

>Reviewed-on: https://review.gluster.org/18209
>Smoke: Gluster Build System <jenkins@build.gluster.org>
>CentOS-regression: Gluster Build System <jenkins@build.gluster.org>
>Reviewed-by: Pranith Kumar Karampuri <pkarampu@redhat.com>

Change-Id: I42df7679d63fec9b4c03b8dbc66c5625f097fac0
BUG: 1482994
Signed-off-by: Krutika Dhananjay <kdhananj@redhat.com>
Reviewed-on: https://code.engineering.redhat.com/gerrit/117426
Reviewed-by: Pranith Kumar Karampuri <pkarampu@redhat.com>
Tested-by: Pranith Kumar Karampuri <pkarampu@redhat.com>
Reviewed-by: Atin Mukherjee <amukherj@redhat.com>
---
 tests/bugs/shard/bug-1488546.t     | 25 ++++++++++++++++++++++
 xlators/features/shard/src/shard.c | 44 ++++++++++++++++++++++++++++++++++++--
 2 files changed, 67 insertions(+), 2 deletions(-)
 create mode 100644 tests/bugs/shard/bug-1488546.t

diff --git a/tests/bugs/shard/bug-1488546.t b/tests/bugs/shard/bug-1488546.t
new file mode 100644
index 0000000..60480dc
--- /dev/null
+++ b/tests/bugs/shard/bug-1488546.t
@@ -0,0 +1,25 @@
+#!/bin/bash
+
+. $(dirname $0)/../../include.rc
+. $(dirname $0)/../../volume.rc
+
+cleanup
+
+TEST glusterd
+TEST pidof glusterd
+TEST $CLI volume create $V0 replica 3 $H0:$B0/${V0}{0,1,2}
+TEST $CLI volume set $V0 features.shard on
+TEST $CLI volume set $V0 md-cache-timeout 60
+TEST $CLI volume start $V0
+
+TEST glusterfs --volfile-id=$V0 --volfile-server=$H0 $M0
+
+TEST dd if=/dev/zero of=$M0/file bs=1M count=20
+TEST ln $M0/file $M0/linkey
+
+EXPECT "20971520" stat -c %s $M0/linkey
+
+TEST $CLI volume stop $V0
+TEST $CLI volume delete $V0
+
+cleanup;
diff --git a/xlators/features/shard/src/shard.c b/xlators/features/shard/src/shard.c
index 0d0ab4a..2dca929 100644
--- a/xlators/features/shard/src/shard.c
+++ b/xlators/features/shard/src/shard.c
@@ -2237,11 +2237,16 @@ shard_link_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
                   struct iatt *postparent,
                   dict_t *xdata)
 {
+        shard_local_t *local = NULL;
+
+        local = frame->local;
         if (op_ret < 0)
                 goto err;
 
         shard_inode_ctx_set (inode, this, buf, 0,
                              SHARD_MASK_NLINK | SHARD_MASK_TIMES);
+        buf->ia_size = local->prebuf.ia_size;
+        buf->ia_blocks = local->prebuf.ia_blocks;
 
         SHARD_STACK_UNWIND (link, frame, op_ret, op_errno, inode, buf,
                              preparent, postparent, xdata);
@@ -2252,12 +2257,32 @@ err:
         return 0;
 }
 
+int
+shard_post_lookup_link_handler (call_frame_t *frame, xlator_t *this)
+{
+        shard_local_t *local = NULL;
+
+        local = frame->local;
+
+        if (local->op_ret < 0) {
+                SHARD_STACK_UNWIND (link, frame, local->op_ret, local->op_errno,
+                                    NULL, NULL, NULL, NULL, NULL);
+                return 0;
+        }
+
+        STACK_WIND (frame, shard_link_cbk, FIRST_CHILD(this),
+                    FIRST_CHILD(this)->fops->link, &local->loc, &local->loc2,
+                    local->xattr_req);
+        return 0;
+}
+
 int32_t
 shard_link (call_frame_t *frame, xlator_t *this, loc_t *oldloc, loc_t *newloc,
               dict_t *xdata)
 {
         int                ret        = -1;
         uint64_t           block_size = 0;
+        shard_local_t     *local      = NULL;
 
         ret = shard_inode_ctx_get_block_size (oldloc->inode, this, &block_size);
         if (ret) {
@@ -2275,8 +2300,23 @@ shard_link (call_frame_t *frame, xlator_t *this, loc_t *oldloc, loc_t *newloc,
                 return 0;
         }
 
-        STACK_WIND (frame, shard_link_cbk, FIRST_CHILD(this),
-                    FIRST_CHILD(this)->fops->link, oldloc, newloc, xdata);
+        if (!this->itable)
+                this->itable = oldloc->inode->table;
+
+        local = mem_get0 (this->local_pool);
+        if (!local)
+                goto err;
+
+        frame->local = local;
+
+        loc_copy (&local->loc, oldloc);
+        loc_copy (&local->loc2, newloc);
+        local->xattr_req = (xdata) ? dict_ref (xdata) : dict_new ();
+        if (!local->xattr_req)
+                goto err;
+
+        shard_lookup_base_file (frame, this, &local->loc,
+                                shard_post_lookup_link_handler);
         return 0;
 
 err:
-- 
1.8.3.1