From: Radoslaw Zarzynski Date: Tue, 10 May 2016 13:29:16 +0000 (+0200) Subject: rgw: switch to byte-precision in RGWQuotaInfo. X-Git-Tag: v11.0.0~349^2~9 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=54aab87efc3093cdf66d1051475cde08c10810f1;p=ceph.git rgw: switch to byte-precision in RGWQuotaInfo. Signed-off-by: Radoslaw Zarzynski --- diff --git a/src/rgw/rgw_admin.cc b/src/rgw/rgw_admin.cc index bdc4e313c4b3..86a8da43ee86 100644 --- a/src/rgw/rgw_admin.cc +++ b/src/rgw/rgw_admin.cc @@ -1033,9 +1033,9 @@ void set_quota_info(RGWQuotaInfo& quota, int opt_cmd, int64_t max_size, int64_t } if (have_max_size) { if (max_size < 0) { - quota.max_size_kb = -1; + quota.max_size = -1; } else { - quota.max_size_kb = rgw_rounded_kb(max_size); + quota.max_size = rgw_rounded_kb(max_size) * 1024; } } break; diff --git a/src/rgw/rgw_json_enc.cc b/src/rgw/rgw_json_enc.cc index 333cf1bb4471..24eaef8effb9 100644 --- a/src/rgw/rgw_json_enc.cc +++ b/src/rgw/rgw_json_enc.cc @@ -488,13 +488,20 @@ void RGWUserInfo::decode_json(JSONObj *obj) void RGWQuotaInfo::dump(Formatter *f) const { f->dump_bool("enabled", enabled); - f->dump_int("max_size_kb", max_size_kb); + f->dump_int("max_size", max_size); + f->dump_int("max_size_kb", rgw_rounded_kb(max_size)); f->dump_int("max_objects", max_objects); } void RGWQuotaInfo::decode_json(JSONObj *obj) { - JSONDecoder::decode_json("max_size_kb", max_size_kb, obj); + if (false == JSONDecoder::decode_json("max_size", max_size, obj)) { + /* We're parsing an older version of the struct. */ + int64_t max_size_kb = 0; + + JSONDecoder::decode_json("max_size_kb", max_size_kb, obj); + max_size = max_size_kb * 1024; + } JSONDecoder::decode_json("max_objects", max_objects, obj); JSONDecoder::decode_json("enabled", enabled, obj); } diff --git a/src/rgw/rgw_quota.cc b/src/rgw/rgw_quota.cc index 0da2d87e92b4..62233c1d2c3c 100644 --- a/src/rgw/rgw_quota.cc +++ b/src/rgw/rgw_quota.cc @@ -101,9 +101,9 @@ public: template bool RGWQuotaCache::can_use_cached_stats(RGWQuotaInfo& quota, RGWStorageStats& cached_stats) { - if (quota.max_size_kb >= 0) { + if (quota.max_size >= 0) { if (quota.max_size_soft_threshold < 0) { - quota.max_size_soft_threshold = quota.max_size_kb * store->ctx()->_conf->rgw_bucket_quota_soft_threshold; + quota.max_size_soft_threshold = quota.max_size * store->ctx()->_conf->rgw_bucket_quota_soft_threshold; } const auto cached_stats_num_kb_rounded = rgw_rounded_kb(cached_stats.size_rounded); @@ -712,21 +712,17 @@ bool RGWQuotaInfoDefApplier::is_size_exceeded(const char * const entity, const RGWStorageStats& stats, const uint64_t size) const { - if (qinfo.max_size_kb < 0) { + if (qinfo.max_size < 0) { /* The limit is not enabled. */ return false; } - /* Handling quota in KiBs due to backward compatibility. */ - const uint64_t add_size_kb = rgw_rounded_objsize_kb(size); - /* XXX: just div 1024 should be enough. */ - const uint64_t cur_size_kb = rgw_rounded_kb(stats.size_rounded); - const uint64_t stats_num_kb_rounded = rgw_rounded_kb(stats.size_rounded); + const uint64_t cur_size = stats.size_rounded; - if (cur_size_kb + add_size_kb > static_cast(qinfo.max_size_kb)) { - dout(10) << "quota exceeded: stats_num_kb_rounded=" << stats_num_kb_rounded - << " size_kb=" << add_size_kb << " " - << entity << "_quota.max_size_kb=" << qinfo.max_size_kb << dendl; + if (cur_size + size > static_cast(qinfo.max_size)) { + dout(10) << "quota exceeded: stats.size_rounded=" << stats.size_rounded + << " size=" << size << " " + << entity << "_quota.max_size=" << qinfo.max_size << dendl; return true; } @@ -782,7 +778,7 @@ class RGWQuotaHandlerImpl : public RGWQuotaHandler { ldout(store->ctx(), 20) << entity << " quota: max_objects=" << quota.max_objects - << " max_size_kb=" << quota.max_size_kb << dendl; + << " max_size=" << quota.max_size << dendl; if (quota_applier.is_num_objs_exceeded(entity, quota, stats, num_objs)) { @@ -805,7 +801,7 @@ public: def_bucket_quota.enabled = true; } if (store->ctx()->_conf->rgw_bucket_default_quota_max_size >= 0) { - def_bucket_quota.max_size_kb = store->ctx()->_conf->rgw_bucket_default_quota_max_size; + def_bucket_quota.max_size = store->ctx()->_conf->rgw_bucket_default_quota_max_size * 1024; def_bucket_quota.enabled = true; } if (store->ctx()->_conf->rgw_user_default_quota_max_objects >= 0) { @@ -813,7 +809,7 @@ public: def_user_quota.enabled = true; } if (store->ctx()->_conf->rgw_user_default_quota_max_size >= 0) { - def_user_quota.max_size_kb = store->ctx()->_conf->rgw_user_default_quota_max_size; + def_user_quota.max_size = store->ctx()->_conf->rgw_user_default_quota_max_size * 1024; def_user_quota.enabled = true; } } diff --git a/src/rgw/rgw_quota.h b/src/rgw/rgw_quota.h index 43f22dfabb10..767df7ce79b9 100644 --- a/src/rgw/rgw_quota.h +++ b/src/rgw/rgw_quota.h @@ -20,6 +20,11 @@ #include "include/atomic.h" #include "common/lru_map.h" +static inline int64_t rgw_rounded_kb(int64_t bytes) +{ + return (bytes + 1023) / 1024; +} + class RGWRados; class JSONObj; @@ -34,30 +39,41 @@ protected: int64_t max_objs_soft_threshold; public: - int64_t max_size_kb; + int64_t max_size; int64_t max_objects; bool enabled; RGWQuotaInfo() : max_size_soft_threshold(-1), max_objs_soft_threshold(-1), - max_size_kb(-1), + max_size(-1), max_objects(-1), enabled(false) { } void encode(bufferlist& bl) const { - ENCODE_START(1, 1, bl); - ::encode(max_size_kb, bl); + ENCODE_START(2, 1, bl); + if (max_size < 0) { + ::encode(-rgw_rounded_kb(abs(max_size)), bl); + } else { + ::encode(rgw_rounded_kb(max_size), bl); + } ::encode(max_objects, bl); ::encode(enabled, bl); + ::encode(max_size, bl); ENCODE_FINISH(bl); } void decode(bufferlist::iterator& bl) { - DECODE_START(1, bl); + DECODE_START_LEGACY_COMPAT_LEN(2, 1, 1, bl); + int64_t max_size_kb; ::decode(max_size_kb, bl); ::decode(max_objects, bl); ::decode(enabled, bl); + if (struct_v < 2) { + max_size = max_size_kb * 1024; + } else { + ::decode(max_size, bl); + } DECODE_FINISH(bl); } diff --git a/src/rgw/rgw_rest_user.cc b/src/rgw/rgw_rest_user.cc index 995ea61b3106..2547c6639329 100644 --- a/src/rgw/rgw_rest_user.cc +++ b/src/rgw/rgw_rest_user.cc @@ -891,8 +891,11 @@ void RGWOp_Quota_Set::execute() old_quota = &info.bucket_quota; } + int64_t old_max_size_kb = rgw_rounded_kb(old_quota->max_size); + int64_t max_size_kb; RESTArgs::get_int64(s, "max-objects", old_quota->max_objects, "a.max_objects); - RESTArgs::get_int64(s, "max-size-kb", old_quota->max_size_kb, "a.max_size_kb); + RESTArgs::get_int64(s, "max-size-kb", old_max_size_kb, &max_size_kb); + quota.max_size = max_size_kb * 1024; RESTArgs::get_bool(s, "enabled", old_quota->enabled, "a.enabled); }