diff options
author | Radoslaw Zarzynski <rzarzynski@mirantis.com> | 2016-05-04 19:21:45 +0200 |
---|---|---|
committer | Radoslaw Zarzynski <rzarzynski@mirantis.com> | 2016-05-30 11:41:00 +0200 |
commit | d07c967d9836bf013d6cba29927290c63f7c3b59 (patch) | |
tree | 8e16406e65b8b3201157025902827334780942c9 /src/rgw/rgw_quota.cc | |
parent | rgw: front-end for bucket quotas of Swift API. (diff) | |
download | ceph-d07c967d9836bf013d6cba29927290c63f7c3b59.tar.xz ceph-d07c967d9836bf013d6cba29927290c63f7c3b59.zip |
rgw: bucket quota can be checked in a way compliant with the Swift API.
Signed-off-by: Radoslaw Zarzynski <rzarzynski@mirantis.com>
Diffstat (limited to 'src/rgw/rgw_quota.cc')
-rw-r--r-- | src/rgw/rgw_quota.cc | 62 |
1 files changed, 61 insertions, 1 deletions
diff --git a/src/rgw/rgw_quota.cc b/src/rgw/rgw_quota.cc index 62233c1d2c3..af5150f1391 100644 --- a/src/rgw/rgw_quota.cc +++ b/src/rgw/rgw_quota.cc @@ -706,6 +706,19 @@ public: const uint64_t num_objs) const; }; +class RGWQuotaInfoRawApplier : public RGWQuotaInfoApplier { +public: + virtual bool is_size_exceeded(const char * const entity, + const RGWQuotaInfo& qinfo, + const RGWStorageStats& stats, + const uint64_t size) const; + + virtual bool is_num_objs_exceeded(const char * const entity, + const RGWQuotaInfo& qinfo, + const RGWStorageStats& stats, + const uint64_t num_objs) const; +}; + bool RGWQuotaInfoDefApplier::is_size_exceeded(const char * const entity, const RGWQuotaInfo& qinfo, @@ -749,12 +762,59 @@ bool RGWQuotaInfoDefApplier::is_num_objs_exceeded(const char * const entity, return false; } +bool RGWQuotaInfoRawApplier::is_size_exceeded(const char * const entity, + const RGWQuotaInfo& qinfo, + const RGWStorageStats& stats, + const uint64_t size) const +{ + if (qinfo.max_size < 0) { + /* The limit is not enabled. */ + return false; + } + + const uint64_t cur_size = stats.size; + + if (cur_size + size > static_cast<uint64_t>(qinfo.max_size)) { + dout(10) << "quota exceeded: stats.size=" << stats.size + << " size=" << size << " " + << entity << "_quota.max_size=" << qinfo.max_size << dendl; + return true; + } + + return false; +} + +bool RGWQuotaInfoRawApplier::is_num_objs_exceeded(const char * const entity, + const RGWQuotaInfo& qinfo, + const RGWStorageStats& stats, + const uint64_t num_objs) const +{ + if (qinfo.max_objects < 0) { + /* The limit is not enabled. */ + return false; + } + + if (stats.num_objects + num_objs > static_cast<uint64_t>(qinfo.max_objects)) { + dout(10) << "quota exceeded: stats.num_objects=" << stats.num_objects + << " " << entity << "_quota.max_objects=" << qinfo.max_objects + << dendl; + return true; + } + + return false; +} + const RGWQuotaInfoApplier& RGWQuotaInfoApplier::get_instance( const RGWQuotaInfo& qinfo) { static RGWQuotaInfoDefApplier default_qapplier; + static RGWQuotaInfoRawApplier raw_qapplier; - return default_qapplier; + if (qinfo.check_on_raw) { + return raw_qapplier; + } else { + return default_qapplier; + } } |