From c2d226adb00f37060c54c7de5732f814666fd17b Mon Sep 17 00:00:00 2001 From: Soumya Koduri Date: Wed, 29 Jan 2025 21:47:45 +0530 Subject: [PATCH] rgw/cloudtier: Correct option ordering in RGWZoneGroupPlacementTier Two tier-config options (related to `cloud-restore`) were incorrectly added in the middle of the encoding and decoding methods of RGWZoneGroupPlacementTier. This modification can cause compatibility issues with older decoders when attempting to read v2-encoded REST objects. The fix is to correct the option order and update the decode() function to properly interpret the structure based on the encoded version. Signed-off-by: Soumya Koduri --- src/rgw/rgw_zone_types.h | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/src/rgw/rgw_zone_types.h b/src/rgw/rgw_zone_types.h index d44761d7f5a95..41c015692a90c 100644 --- a/src/rgw/rgw_zone_types.h +++ b/src/rgw/rgw_zone_types.h @@ -548,26 +548,27 @@ struct RGWZoneGroupPlacementTier { std::string tier_type; std::string storage_class; bool retain_head_object = false; - bool allow_read_through = false; - uint64_t read_through_restore_days = 1; struct _tier { RGWZoneGroupPlacementTierS3 s3; } t; + bool allow_read_through = false; + uint64_t read_through_restore_days = 1; + int update_params(const JSONFormattable& config); int clear_params(const JSONFormattable& config); void encode(bufferlist& bl) const { - ENCODE_START(2, 1, bl); + ENCODE_START(3, 1, bl); encode(tier_type, bl); encode(storage_class, bl); encode(retain_head_object, bl); - encode(allow_read_through, bl); - encode(read_through_restore_days, bl); if (tier_type == "cloud-s3") { encode(t.s3, bl); } + encode(allow_read_through, bl); + encode(read_through_restore_days, bl); ENCODE_FINISH(bl); } @@ -576,12 +577,22 @@ struct RGWZoneGroupPlacementTier { decode(tier_type, bl); decode(storage_class, bl); decode(retain_head_object, bl); - if (struct_v >= 2) { + if (struct_v == 1) { + if (tier_type == "cloud-s3") { + decode(t.s3, bl); + } + } else if (struct_v == 2) { + decode(allow_read_through, bl); + decode(read_through_restore_days, bl); + if (tier_type == "cloud-s3") { + decode(t.s3, bl); + } + } else if (struct_v >= 3) { + if (tier_type == "cloud-s3") { + decode(t.s3, bl); + } decode(allow_read_through, bl); decode(read_through_restore_days, bl); - } - if (tier_type == "cloud-s3") { - decode(t.s3, bl); } DECODE_FINISH(bl); } -- 2.39.5