}
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;
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);
}
template<class T>
bool RGWQuotaCache<T>::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);
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<uint64_t>(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<uint64_t>(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;
}
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)) {
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) {
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;
}
}
#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;
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);
}
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);
}