9f5ccc
From ac5b1b38e705bd0e4c00cc50580a71dfaa4d3b5f Mon Sep 17 00:00:00 2001
9f5ccc
From: Krutika Dhananjay <kdhananj@redhat.com>
9f5ccc
Date: Wed, 7 Aug 2019 12:12:43 +0530
9f5ccc
Subject: [PATCH 375/375] features/shard: Send correct size when reads are sent
9f5ccc
 beyond file size
9f5ccc
9f5ccc
Backport of:
9f5ccc
> https://review.gluster.org/c/glusterfs/+/23175
9f5ccc
> Change-Id: I0cebaaf55c09eb1fb77a274268ff564e871b743b
9f5ccc
> fixes bz#1738419
9f5ccc
> Signed-off-by: Krutika Dhananjay <kdhananj@redhat.com>
9f5ccc
9f5ccc
Change-Id: I0cebaaf55c09eb1fb77a274268ff564e871b743b
9f5ccc
BUG: 1802013
9f5ccc
Signed-off-by: Krutika Dhananjay <kdhananj@redhat.com>
9f5ccc
Reviewed-on: https://code.engineering.redhat.com/gerrit/199570
9f5ccc
Tested-by: RHGS Build Bot <nigelb@redhat.com>
9f5ccc
Reviewed-by: Sunil Kumar Heggodu Gopala Acharya <sheggodu@redhat.com>
9f5ccc
---
9f5ccc
 tests/bugs/shard/bug-1738419.t     | 29 +++++++++++++++++++++++++++++
9f5ccc
 xlators/features/shard/src/shard.c |  2 ++
9f5ccc
 2 files changed, 31 insertions(+)
9f5ccc
 create mode 100644 tests/bugs/shard/bug-1738419.t
9f5ccc
9f5ccc
diff --git a/tests/bugs/shard/bug-1738419.t b/tests/bugs/shard/bug-1738419.t
9f5ccc
new file mode 100644
9f5ccc
index 0000000..8d0a31d
9f5ccc
--- /dev/null
9f5ccc
+++ b/tests/bugs/shard/bug-1738419.t
9f5ccc
@@ -0,0 +1,29 @@
9f5ccc
+#!/bin/bash
9f5ccc
+
9f5ccc
+. $(dirname $0)/../../include.rc
9f5ccc
+. $(dirname $0)/../../volume.rc
9f5ccc
+
9f5ccc
+cleanup
9f5ccc
+
9f5ccc
+TEST glusterd
9f5ccc
+TEST pidof glusterd
9f5ccc
+TEST $CLI volume create $V0 replica 3 $H0:$B0/${V0}{0,1,2}
9f5ccc
+TEST $CLI volume set $V0 features.shard on
9f5ccc
+TEST $CLI volume set $V0 network.remote-dio off
9f5ccc
+TEST $CLI volume set $V0 performance.io-cache off
9f5ccc
+TEST $CLI volume set $V0 performance.quick-read off
9f5ccc
+TEST $CLI volume set $V0 performance.read-ahead off
9f5ccc
+TEST $CLI volume set $V0 performance.strict-o-direct on
9f5ccc
+TEST $CLI volume start $V0
9f5ccc
+
9f5ccc
+TEST $GFS --volfile-id=$V0 --volfile-server=$H0 $M0
9f5ccc
+
9f5ccc
+TEST dd if=/dev/zero of=$M0/metadata bs=501 count=1
9f5ccc
+
9f5ccc
+EXPECT "501" echo $("dd" if=$M0/metadata bs=4096 count=1 of=/dev/null iflag=direct 2>&1 | awk '/bytes/ {print $1}')
9f5ccc
+
9f5ccc
+EXPECT_WITHIN $UMOUNT_TIMEOUT "Y" force_umount $M0
9f5ccc
+TEST $CLI volume stop $V0
9f5ccc
+TEST $CLI volume delete $V0
9f5ccc
+
9f5ccc
+cleanup
9f5ccc
diff --git a/xlators/features/shard/src/shard.c b/xlators/features/shard/src/shard.c
9f5ccc
index b224abd..9ed597b 100644
9f5ccc
--- a/xlators/features/shard/src/shard.c
9f5ccc
+++ b/xlators/features/shard/src/shard.c
9f5ccc
@@ -4433,6 +4433,8 @@ out:
9f5ccc
       if (xdata)
9f5ccc
         local->xattr_rsp = dict_ref(xdata);
9f5ccc
       vec.iov_base = local->iobuf->ptr;
9f5ccc
+      if (local->offset + local->req_size > local->prebuf.ia_size)
9f5ccc
+          local->total_size = local->prebuf.ia_size - local->offset;
9f5ccc
       vec.iov_len = local->total_size;
9f5ccc
       local->op_ret = local->total_size;
9f5ccc
       SHARD_STACK_UNWIND(readv, frame, local->op_ret, local->op_errno, &vec, 1,
9f5ccc
-- 
9f5ccc
1.8.3.1
9f5ccc