From 5248a81bc529bf5e9e59a67e7f5c747f5eb77228 Mon Sep 17 00:00:00 2001 From: Chang Liu Date: Wed, 8 May 2019 17:16:03 +0800 Subject: [PATCH] rgw: make max number of bucket/object tags configurble Signed-off-by: Chang Liu --- src/rgw/rgw_rest_s3.cc | 2 +- src/rgw/rgw_tag.cc | 10 +++------- src/rgw/rgw_tag.h | 11 +++++++++-- 3 files changed, 13 insertions(+), 10 deletions(-) diff --git a/src/rgw/rgw_rest_s3.cc b/src/rgw/rgw_rest_s3.cc index 5855ec26116..dc9a7866b35 100644 --- a/src/rgw/rgw_rest_s3.cc +++ b/src/rgw/rgw_rest_s3.cc @@ -534,7 +534,7 @@ int RGWPutBucketTags_ObjStore_S3::get_params() return -ERR_MALFORMED_XML; } - RGWObjTags obj_tags; + RGWObjTags obj_tags(50); // A tag set can contain as many as 50 tags, or it can be empty. r = tagging.rebuild(obj_tags); if (r < 0) return r; diff --git a/src/rgw/rgw_tag.cc b/src/rgw/rgw_tag.cc index f793c0ab8b1..6aa039ba9d8 100644 --- a/src/rgw/rgw_tag.cc +++ b/src/rgw/rgw_tag.cc @@ -9,10 +9,6 @@ #include "rgw_tag.h" -static constexpr uint32_t MAX_OBJ_TAGS=10; -static constexpr uint32_t MAX_TAG_KEY_SIZE=128; -static constexpr uint32_t MAX_TAG_VAL_SIZE=256; - bool RGWObjTags::add_tag(const string&key, const string& val){ return tag_map.emplace(std::make_pair(key,val)).second; } @@ -22,9 +18,9 @@ bool RGWObjTags::emplace_tag(std::string&& key, std::string&& val){ } int RGWObjTags::check_and_add_tag(const string&key, const string& val){ - if (tag_map.size() == MAX_OBJ_TAGS || - key.size() > MAX_TAG_KEY_SIZE || - val.size() > MAX_TAG_VAL_SIZE || + if (tag_map.size() == max_obj_tags || + key.size() > max_tag_key_size || + val.size() > max_tag_val_size || key.size() == 0){ return -ERR_INVALID_TAG; } diff --git a/src/rgw/rgw_tag.h b/src/rgw/rgw_tag.h index fe8bbc34859..84ddd943bef 100644 --- a/src/rgw/rgw_tag.h +++ b/src/rgw/rgw_tag.h @@ -15,9 +15,16 @@ class RGWObjTags protected: using tag_map_t = boost::container::flat_map ; tag_map_t tag_map; + + uint32_t max_obj_tags{10}; + uint32_t max_tag_key_size{128}; + uint32_t max_tag_val_size{256}; + public: - RGWObjTags() {} - ~RGWObjTags() {} + RGWObjTags() = default; + RGWObjTags(uint32_t max_obj_tags):max_obj_tags(max_obj_tags) {} + + virtual ~RGWObjTags() = default; void encode(bufferlist& bl) const { ENCODE_START(1,1,bl); -- 2.39.5