From: Yehuda Sadeh Date: Tue, 1 Oct 2013 18:45:03 +0000 (-0700) Subject: rgw: higher level quota check functionality X-Git-Tag: v0.72-rc1~65^2~25 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=bc98013f4ff7bd2be9648eedfc990dbf57bfe878;p=ceph.git rgw: higher level quota check functionality Signed-off-by: Yehuda Sadeh --- diff --git a/src/rgw/rgw_common.h b/src/rgw/rgw_common.h index 53f96df1c06e..f27a9c8348ac 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 6cb9fabf6c0e..ba3e522651f9 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 b73b73e1b238..56ce60f56b92 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 babfecc3c9e2..0c686f0eae4d 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);