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