summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYehuda Sadeh <yehuda@inktank.com>2013-10-01 11:45:03 -0700
committerYehuda Sadeh <yehuda@inktank.com>2013-10-01 11:45:03 -0700
commitbc98013f4ff7bd2be9648eedfc990dbf57bfe878 (patch)
tree06dcf78b5e5e1de754aed494645075a64ae1a748
parentc821da950ec960ef2353ca26424cd9b37ec99746 (diff)
downloadceph-bc98013f4ff7bd2be9648eedfc990dbf57bfe878.tar.gz
rgw: higher level quota check functionality
Signed-off-by: Yehuda Sadeh <yehuda@inktank.com>
-rw-r--r--src/rgw/rgw_common.h1
-rw-r--r--src/rgw/rgw_http_errors.h1
-rw-r--r--src/rgw/rgw_quota.cc21
-rw-r--r--src/rgw/rgw_quota.h2
4 files changed, 23 insertions, 2 deletions
diff --git a/src/rgw/rgw_common.h b/src/rgw/rgw_common.h
index 53f96df1c06..f27a9c8348a 100644
--- a/src/rgw/rgw_common.h
+++ b/src/rgw/rgw_common.h
@@ -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
diff --git a/src/rgw/rgw_http_errors.h b/src/rgw/rgw_http_errors.h
index 6cb9fabf6c0..ba3e522651f 100644
--- a/src/rgw/rgw_http_errors.h
+++ b/src/rgw/rgw_http_errors.h
@@ -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" },
diff --git a/src/rgw/rgw_quota.cc b/src/rgw/rgw_quota.cc
index b73b73e1b23..56ce60f56b9 100644
--- a/src/rgw/rgw_quota.cc
+++ b/src/rgw/rgw_quota.cc
@@ -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;
}
};
diff --git a/src/rgw/rgw_quota.h b/src/rgw/rgw_quota.h
index babfecc3c9e..0c686f0eae4 100644
--- a/src/rgw/rgw_quota.h
+++ b/src/rgw/rgw_quota.h
@@ -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);