]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
rgw: switch to byte-precision in RGWQuotaInfo.
authorRadoslaw Zarzynski <rzarzynski@mirantis.com>
Tue, 10 May 2016 13:29:16 +0000 (15:29 +0200)
committerRadoslaw Zarzynski <rzarzynski@mirantis.com>
Mon, 30 May 2016 09:33:51 +0000 (11:33 +0200)
Signed-off-by: Radoslaw Zarzynski <rzarzynski@mirantis.com>
src/rgw/rgw_admin.cc
src/rgw/rgw_json_enc.cc
src/rgw/rgw_quota.cc
src/rgw/rgw_quota.h
src/rgw/rgw_rest_user.cc

index bdc4e313c4b3a39e57f5e5542afec55f0a4c6c8f..86a8da43ee8623b5335eaf432cfeb2151e1011a0 100644 (file)
@@ -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;
index 333cf1bb447180de6ee428756d15c6a97530fdac..24eaef8effb901e7caecfbdc0b1fe608c5618da1 100644 (file)
@@ -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);
 }
index 0da2d87e92b43e8d08ac1307e9ef45523a4bfb7d..62233c1d2c3c2cffb0876cbec2d43696756165ea 100644 (file)
@@ -101,9 +101,9 @@ public:
 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);
@@ -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<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;
   }
 
@@ -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;
     }
   }
index 43f22dfabb109a7c1af645071a8124f856e2eff3..767df7ce79b9f0931322cc9f64ae97682860a8bc 100644 (file)
 #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);
   }
 
index 995ea61b3106dcb3222b1bd7c72004bb1e29b703..2547c6639329e29e72f1dcaf55615a4f1203f5d7 100644 (file)
@@ -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, &quota.max_objects);
-      RESTArgs::get_int64(s, "max-size-kb", old_quota->max_size_kb, &quota.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, &quota.enabled);
     }