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