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