d2787b
From 60789c658ea22063c26168cb4ce15ac5fd279e58 Mon Sep 17 00:00:00 2001
d2787b
From: Ravishankar N <ravishankar@redhat.com>
d2787b
Date: Mon, 14 Dec 2020 10:57:03 +0530
d2787b
Subject: [PATCH 500/511] features/shard: Convert shard block indices to uint64
d2787b
d2787b
This patch fixes a crash in FOPs that operate on really large sharded
d2787b
files where number of participant shards could sometimes exceed
d2787b
signed int32 max.
d2787b
d2787b
The patch also adds GF_ASSERTs to ensure that number of participating
d2787b
shards is always greater than 0 for files that do have more than one
d2787b
shard.
d2787b
d2787b
Upstream:
d2787b
> https://review.gluster.org/#/c/glusterfs/+/23407/
d2787b
> Change-Id: I354de58796f350eb1aa42fcdf8092ca2e69ccbb6
d2787b
> Fixes: #1348
d2787b
> Signed-off-by: Krutika Dhananjay <kdhananj@redhat.com>
d2787b
d2787b
BUG: 1752739
d2787b
Change-Id: I354de58796f350eb1aa42fcdf8092ca2e69ccbb6
d2787b
Signed-off-by: Vinayakswami Hariharmath <vharihar@redhat.com>
d2787b
Reviewed-on: https://code.engineering.redhat.com/gerrit/221061
d2787b
Tested-by: Ravishankar Narayanankutty <ravishankar@redhat.com>
d2787b
Tested-by: RHGS Build Bot <nigelb@redhat.com>
d2787b
Reviewed-by: Ravishankar Narayanankutty <ravishankar@redhat.com>
d2787b
---
d2787b
 xlators/features/shard/src/shard.c | 14 ++++++++------
d2787b
 xlators/features/shard/src/shard.h |  6 +++---
d2787b
 2 files changed, 11 insertions(+), 9 deletions(-)
d2787b
d2787b
diff --git a/xlators/features/shard/src/shard.c b/xlators/features/shard/src/shard.c
d2787b
index 16d557b..a967f35 100644
d2787b
--- a/xlators/features/shard/src/shard.c
d2787b
+++ b/xlators/features/shard/src/shard.c
d2787b
@@ -1855,10 +1855,9 @@ int shard_truncate_last_shard(call_frame_t *frame, xlator_t *this,
d2787b
    */
d2787b
   if (!inode) {
d2787b
     gf_msg_debug(this->name, 0,
d2787b
-                 "Last shard to be truncated absent"
d2787b
-                 " in backend: %s. Directly proceeding to update "
d2787b
-                 "file size",
d2787b
-                 uuid_utoa(inode->gfid));
d2787b
+                 "Last shard to be truncated absent in backend: " PRIu64
d2787b
+                 " of gfid: %s. Directly proceeding to update file size",
d2787b
+                 local->first_block, uuid_utoa(local->loc.inode->gfid));
d2787b
     shard_update_file_size(frame, this, NULL, &local->loc,
d2787b
                            shard_post_update_size_truncate_handler);
d2787b
     return 0;
d2787b
@@ -2389,6 +2388,7 @@ int shard_truncate_begin(call_frame_t *frame, xlator_t *this) {
d2787b
       get_highest_block(0, local->prebuf.ia_size, local->block_size);
d2787b
 
d2787b
   local->num_blocks = local->last_block - local->first_block + 1;
d2787b
+  GF_ASSERT(local->num_blocks > 0);
d2787b
   local->resolver_base_inode =
d2787b
       (local->fop == GF_FOP_TRUNCATE) ? local->loc.inode : local->fd->inode;
d2787b
 
d2787b
@@ -4809,6 +4809,7 @@ int shard_post_lookup_readv_handler(call_frame_t *frame, xlator_t *this) {
d2787b
       get_highest_block(local->offset, local->total_size, local->block_size);
d2787b
 
d2787b
   local->num_blocks = local->last_block - local->first_block + 1;
d2787b
+  GF_ASSERT(local->num_blocks > 0);
d2787b
   local->resolver_base_inode = local->loc.inode;
d2787b
 
d2787b
   local->inode_list =
d2787b
@@ -5266,6 +5267,7 @@ int shard_common_inode_write_post_lookup_handler(call_frame_t *frame,
d2787b
   local->last_block =
d2787b
       get_highest_block(local->offset, local->total_size, local->block_size);
d2787b
   local->num_blocks = local->last_block - local->first_block + 1;
d2787b
+  GF_ASSERT(local->num_blocks > 0);
d2787b
   local->inode_list =
d2787b
       GF_CALLOC(local->num_blocks, sizeof(inode_t *), gf_shard_mt_inode_list);
d2787b
   if (!local->inode_list) {
d2787b
@@ -5274,8 +5276,8 @@ int shard_common_inode_write_post_lookup_handler(call_frame_t *frame,
d2787b
   }
d2787b
 
d2787b
   gf_msg_trace(
d2787b
-      this->name, 0, "%s: gfid=%s first_block=%" PRIu32 " "
d2787b
-                     "last_block=%" PRIu32 " num_blocks=%" PRIu32
d2787b
+      this->name, 0, "%s: gfid=%s first_block=%" PRIu64 " "
d2787b
+                     "last_block=%" PRIu64 " num_blocks=%" PRIu64
d2787b
                      " offset=%" PRId64 " total_size=%zu flags=%" PRId32 "",
d2787b
       gf_fop_list[local->fop], uuid_utoa(local->resolver_base_inode->gfid),
d2787b
       local->first_block, local->last_block, local->num_blocks, local->offset,
d2787b
diff --git a/xlators/features/shard/src/shard.h b/xlators/features/shard/src/shard.h
d2787b
index 1721417..4fe181b 100644
d2787b
--- a/xlators/features/shard/src/shard.h
d2787b
+++ b/xlators/features/shard/src/shard.h
d2787b
@@ -254,9 +254,9 @@ typedef int32_t (*shard_post_update_size_fop_handler_t)(call_frame_t *frame,
d2787b
 typedef struct shard_local {
d2787b
     int op_ret;
d2787b
     int op_errno;
d2787b
-    int first_block;
d2787b
-    int last_block;
d2787b
-    int num_blocks;
d2787b
+    uint64_t first_block;
d2787b
+    uint64_t last_block;
d2787b
+    uint64_t num_blocks;
d2787b
     int call_count;
d2787b
     int eexist_count;
d2787b
     int create_count;
d2787b
-- 
d2787b
1.8.3.1
d2787b