21ab4e
From 693ac3854f5c94ff2e4971c5c9bccc63c7eed8fc Mon Sep 17 00:00:00 2001
21ab4e
From: Krutika Dhananjay <kdhananj@redhat.com>
21ab4e
Date: Tue, 5 Sep 2017 21:42:26 +0530
21ab4e
Subject: [PATCH 611/616] features/shard: Return aggregated size in stbuf of
21ab4e
 LINK fop
21ab4e
21ab4e
>Reviewed-on: https://review.gluster.org/18209
21ab4e
>Smoke: Gluster Build System <jenkins@build.gluster.org>
21ab4e
>CentOS-regression: Gluster Build System <jenkins@build.gluster.org>
21ab4e
>Reviewed-by: Pranith Kumar Karampuri <pkarampu@redhat.com>
21ab4e
21ab4e
Change-Id: I42df7679d63fec9b4c03b8dbc66c5625f097fac0
21ab4e
BUG: 1482994
21ab4e
Signed-off-by: Krutika Dhananjay <kdhananj@redhat.com>
21ab4e
Reviewed-on: https://code.engineering.redhat.com/gerrit/117426
21ab4e
Reviewed-by: Pranith Kumar Karampuri <pkarampu@redhat.com>
21ab4e
Tested-by: Pranith Kumar Karampuri <pkarampu@redhat.com>
21ab4e
Reviewed-by: Atin Mukherjee <amukherj@redhat.com>
21ab4e
---
21ab4e
 tests/bugs/shard/bug-1488546.t     | 25 ++++++++++++++++++++++
21ab4e
 xlators/features/shard/src/shard.c | 44 ++++++++++++++++++++++++++++++++++++--
21ab4e
 2 files changed, 67 insertions(+), 2 deletions(-)
21ab4e
 create mode 100644 tests/bugs/shard/bug-1488546.t
21ab4e
21ab4e
diff --git a/tests/bugs/shard/bug-1488546.t b/tests/bugs/shard/bug-1488546.t
21ab4e
new file mode 100644
21ab4e
index 0000000..60480dc
21ab4e
--- /dev/null
21ab4e
+++ b/tests/bugs/shard/bug-1488546.t
21ab4e
@@ -0,0 +1,25 @@
21ab4e
+#!/bin/bash
21ab4e
+
21ab4e
+. $(dirname $0)/../../include.rc
21ab4e
+. $(dirname $0)/../../volume.rc
21ab4e
+
21ab4e
+cleanup
21ab4e
+
21ab4e
+TEST glusterd
21ab4e
+TEST pidof glusterd
21ab4e
+TEST $CLI volume create $V0 replica 3 $H0:$B0/${V0}{0,1,2}
21ab4e
+TEST $CLI volume set $V0 features.shard on
21ab4e
+TEST $CLI volume set $V0 md-cache-timeout 60
21ab4e
+TEST $CLI volume start $V0
21ab4e
+
21ab4e
+TEST glusterfs --volfile-id=$V0 --volfile-server=$H0 $M0
21ab4e
+
21ab4e
+TEST dd if=/dev/zero of=$M0/file bs=1M count=20
21ab4e
+TEST ln $M0/file $M0/linkey
21ab4e
+
21ab4e
+EXPECT "20971520" stat -c %s $M0/linkey
21ab4e
+
21ab4e
+TEST $CLI volume stop $V0
21ab4e
+TEST $CLI volume delete $V0
21ab4e
+
21ab4e
+cleanup;
21ab4e
diff --git a/xlators/features/shard/src/shard.c b/xlators/features/shard/src/shard.c
21ab4e
index 0d0ab4a..2dca929 100644
21ab4e
--- a/xlators/features/shard/src/shard.c
21ab4e
+++ b/xlators/features/shard/src/shard.c
21ab4e
@@ -2237,11 +2237,16 @@ shard_link_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
21ab4e
                   struct iatt *postparent,
21ab4e
                   dict_t *xdata)
21ab4e
 {
21ab4e
+        shard_local_t *local = NULL;
21ab4e
+
21ab4e
+        local = frame->local;
21ab4e
         if (op_ret < 0)
21ab4e
                 goto err;
21ab4e
 
21ab4e
         shard_inode_ctx_set (inode, this, buf, 0,
21ab4e
                              SHARD_MASK_NLINK | SHARD_MASK_TIMES);
21ab4e
+        buf->ia_size = local->prebuf.ia_size;
21ab4e
+        buf->ia_blocks = local->prebuf.ia_blocks;
21ab4e
 
21ab4e
         SHARD_STACK_UNWIND (link, frame, op_ret, op_errno, inode, buf,
21ab4e
                              preparent, postparent, xdata);
21ab4e
@@ -2252,12 +2257,32 @@ err:
21ab4e
         return 0;
21ab4e
 }
21ab4e
 
21ab4e
+int
21ab4e
+shard_post_lookup_link_handler (call_frame_t *frame, xlator_t *this)
21ab4e
+{
21ab4e
+        shard_local_t *local = NULL;
21ab4e
+
21ab4e
+        local = frame->local;
21ab4e
+
21ab4e
+        if (local->op_ret < 0) {
21ab4e
+                SHARD_STACK_UNWIND (link, frame, local->op_ret, local->op_errno,
21ab4e
+                                    NULL, NULL, NULL, NULL, NULL);
21ab4e
+                return 0;
21ab4e
+        }
21ab4e
+
21ab4e
+        STACK_WIND (frame, shard_link_cbk, FIRST_CHILD(this),
21ab4e
+                    FIRST_CHILD(this)->fops->link, &local->loc, &local->loc2,
21ab4e
+                    local->xattr_req);
21ab4e
+        return 0;
21ab4e
+}
21ab4e
+
21ab4e
 int32_t
21ab4e
 shard_link (call_frame_t *frame, xlator_t *this, loc_t *oldloc, loc_t *newloc,
21ab4e
               dict_t *xdata)
21ab4e
 {
21ab4e
         int                ret        = -1;
21ab4e
         uint64_t           block_size = 0;
21ab4e
+        shard_local_t     *local      = NULL;
21ab4e
 
21ab4e
         ret = shard_inode_ctx_get_block_size (oldloc->inode, this, &block_size);
21ab4e
         if (ret) {
21ab4e
@@ -2275,8 +2300,23 @@ shard_link (call_frame_t *frame, xlator_t *this, loc_t *oldloc, loc_t *newloc,
21ab4e
                 return 0;
21ab4e
         }
21ab4e
 
21ab4e
-        STACK_WIND (frame, shard_link_cbk, FIRST_CHILD(this),
21ab4e
-                    FIRST_CHILD(this)->fops->link, oldloc, newloc, xdata);
21ab4e
+        if (!this->itable)
21ab4e
+                this->itable = oldloc->inode->table;
21ab4e
+
21ab4e
+        local = mem_get0 (this->local_pool);
21ab4e
+        if (!local)
21ab4e
+                goto err;
21ab4e
+
21ab4e
+        frame->local = local;
21ab4e
+
21ab4e
+        loc_copy (&local->loc, oldloc);
21ab4e
+        loc_copy (&local->loc2, newloc);
21ab4e
+        local->xattr_req = (xdata) ? dict_ref (xdata) : dict_new ();
21ab4e
+        if (!local->xattr_req)
21ab4e
+                goto err;
21ab4e
+
21ab4e
+        shard_lookup_base_file (frame, this, &local->loc,
21ab4e
+                                shard_post_lookup_link_handler);
21ab4e
         return 0;
21ab4e
 
21ab4e
 err:
21ab4e
-- 
21ab4e
1.8.3.1
21ab4e