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