]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
rgw: higher level quota check functionality
authorYehuda Sadeh <yehuda@inktank.com>
Tue, 1 Oct 2013 18:45:03 +0000 (11:45 -0700)
committerYehuda Sadeh <yehuda@inktank.com>
Tue, 1 Oct 2013 18:45:03 +0000 (11:45 -0700)
Signed-off-by: Yehuda Sadeh <yehuda@inktank.com>
src/rgw/rgw_common.h
src/rgw/rgw_http_errors.h
src/rgw/rgw_quota.cc
src/rgw/rgw_quota.h

index 53f96df1c06ec33b15a96ead520715459114f9ff..f27a9c8348acdc4c8faf7ed87da4cc07e7a64de2 100644 (file)
@@ -130,6 +130,7 @@ using ceph::crypto::MD5;
 #define ERR_NOT_FOUND            2023
 #define ERR_PERMANENT_REDIRECT   2024
 #define ERR_LOCKED               2025
+#define ERR_QUOTA_EXCEEDED       2026
 #define ERR_USER_SUSPENDED       2100
 #define ERR_INTERNAL_ERROR       2200
 
index 6cb9fabf6c0e0393bd55d2380853f4bcad8e99da..ba3e522651f95973767aed08812e07767ec38d8d 100644 (file)
@@ -36,6 +36,7 @@ const static struct rgw_http_errors RGW_HTTP_ERRORS[] = {
     { EPERM, 403, "AccessDenied" },
     { ERR_USER_SUSPENDED, 403, "UserSuspended" },
     { ERR_REQUEST_TIME_SKEWED, 403, "RequestTimeTooSkewed" },
+    { ERR_QUOTA_EXCEEDED, 403, "QuotaExceeded" },
     { ENOENT, 404, "NoSuchKey" },
     { ERR_NO_SUCH_BUCKET, 404, "NoSuchBucket" },
     { ERR_NO_SUCH_UPLOAD, 404, "NoSuchUpload" },
index b73b73e1b2384aa71d8d46d07caee549d983ca30..56ce60f56b92775223d84ae8156cb71fd29b7f82 100644 (file)
@@ -99,7 +99,26 @@ class RGWQuotaHandlerImpl : public RGWQuotaHandler {
 public:
   RGWQuotaHandlerImpl(RGWRados *store) : stats_cache(store) {}
   virtual int check_quota(rgw_bucket& bucket, RGWQuotaInfo& bucket_quota,
-                         uint64_t num_objs, uint64_t size, bool *result) {
+                         uint64_t num_objs, uint64_t size) {
+    if (!bucket_quota.enabled) {
+      return 0;
+    }
+
+    RGWBucketStats stats;
+
+    int ret = stats_cache.get_bucket_stats(bucket, stats);
+    if (ret < 0)
+      return ret;
+
+    if (bucket_quota.max_objects &&
+        stats.num_objects + num_objs > bucket_quota.max_objects) {
+      return -ERR_QUOTA_EXCEEDED;
+    }
+    if (bucket_quota.max_size_kb &&
+               stats.num_kb_rounded + size > bucket_quota.max_size_kb) {
+      return -ERR_QUOTA_EXCEEDED;
+    }
+
     return 0;
   }
 };
index babfecc3c9e2e845153bc02609fd206f79d37140..0c686f0eae4d47c29892d112258468f798a50cde 100644 (file)
@@ -43,7 +43,7 @@ class RGWQuotaHandler {
 public:
   virtual ~RGWQuotaHandler() {}
   virtual int check_quota(rgw_bucket& bucket, RGWQuotaInfo& bucket_quota,
-                         uint64_t num_objs, uint64_t size, bool *result) =  0;
+                         uint64_t num_objs, uint64_t size) = 0;
 
   static RGWQuotaHandler *generate_handler(RGWRados *store);
   static void free_handler(RGWQuotaHandler *handler);