summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--tests/bugs/shard/bug-1256580.t36
-rw-r--r--xlators/features/shard/src/shard.c11
-rw-r--r--xlators/features/shard/src/shard.h1
3 files changed, 46 insertions, 2 deletions
diff --git a/tests/bugs/shard/bug-1256580.t b/tests/bugs/shard/bug-1256580.t
new file mode 100644
index 00000000000..c1704e2022a
--- /dev/null
+++ b/tests/bugs/shard/bug-1256580.t
@@ -0,0 +1,36 @@
+#!/bin/bash
+
+. $(dirname $0)/../../include.rc
+
+cleanup
+
+TEST glusterd
+TEST pidof glusterd
+TEST $CLI volume create $V0 $H0:$B0/${V0}{0,1}
+TEST $CLI volume set $V0 features.shard on
+TEST $CLI volume set $V0 performance.strict-write-ordering on
+TEST $CLI volume start $V0
+
+TEST glusterfs --volfile-id=$V0 --volfile-server=$H0 $M0
+
+TEST mkdir $M0/dir
+TEST touch $M0/dir/file
+
+# Create "file" with holes.
+TEST truncate -s 6M $M0/dir/file
+EXPECT '6291456' stat -c %s $M0/dir/file
+
+# Perform writes that do not cross the 6M boundary
+TEST dd if=/dev/zero of=$M0/dir/file bs=1024 seek=3072 count=2048 conv=notrunc
+
+# Ensure that the file size is 6M (as opposed to 8M that would appear in the
+# presence of this bug).
+EXPECT '6291456' stat -c %s $M0/dir/file
+
+#Extend the write beyond EOF such that it again creates a hole of 1M size
+TEST dd if=/dev/zero of=$M0/dir/file bs=1024 seek=7168 count=2048 conv=notrunc
+
+# Ensure that the file size is not greater than 9M.
+EXPECT '9437184' stat -c %s $M0/dir/file
+
+cleanup
diff --git a/xlators/features/shard/src/shard.c b/xlators/features/shard/src/shard.c
index ba1579f1170..2c893cc1101 100644
--- a/xlators/features/shard/src/shard.c
+++ b/xlators/features/shard/src/shard.c
@@ -2929,6 +2929,13 @@ shard_writev_do_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
SHARD_STACK_UNWIND (writev, frame, local->written_size,
local->op_errno, NULL, NULL, NULL);
} else {
+ if (local->is_write_extending)
+ local->delta_size = (local->offset +
+ local->total_size) -
+ local->prebuf.ia_size;
+ else
+ local->delta_size = 0;
+ local->hole_size = 0;
if (xdata)
local->xattr_rsp = dict_ref (xdata);
shard_update_file_size (frame, this, local->fd, NULL,
@@ -3102,8 +3109,8 @@ shard_post_lookup_writev_handler (call_frame_t *frame, xlator_t *this)
/* At this point, calculate the size of the hole if it is going to be
* created as part of this write.
*/
- if (local->offset > local->prebuf.ia_size)
- local->hole_size = local->offset - local->prebuf.ia_size;
+ if (local->offset + local->total_size > local->prebuf.ia_size)
+ local->is_write_extending = _gf_true;
if (local->create_count)
shard_common_resume_mknod (frame, this,
diff --git a/xlators/features/shard/src/shard.h b/xlators/features/shard/src/shard.h
index e6144a29e68..f480c2912b6 100644
--- a/xlators/features/shard/src/shard.h
+++ b/xlators/features/shard/src/shard.h
@@ -185,6 +185,7 @@ typedef struct shard_local {
struct iobuf *iobuf;
gf_dirent_t entries_head;
gf_boolean_t list_inited;
+ gf_boolean_t is_write_extending;
shard_post_fop_handler_t handler;
shard_post_lookup_shards_fop_handler_t pls_fop_handler;
shard_post_resolve_fop_handler_t post_res_handler;