diff options
author | Yehuda Sadeh <yehuda@inktank.com> | 2013-09-27 16:43:10 -0700 |
---|---|---|
committer | Yehuda Sadeh <yehuda@inktank.com> | 2013-09-27 16:43:10 -0700 |
commit | c821da950ec960ef2353ca26424cd9b37ec99746 (patch) | |
tree | b8347c80e4649919a9f139309e8da1ba78a73b21 | |
parent | 434ad764a1fae9715bfbec1667e73856021d24d2 (diff) | |
download | ceph-c821da950ec960ef2353ca26424cd9b37ec99746.tar.gz |
rgw: more quota implementation
Signed-off-by: Yehuda Sadeh <yehuda@inktank.com>
-rw-r--r-- | src/rgw/rgw_common.h | 1 | ||||
-rw-r--r-- | src/rgw/rgw_op.cc | 37 | ||||
-rw-r--r-- | src/rgw/rgw_op.h | 4 | ||||
-rw-r--r-- | src/rgw/rgw_quota.cc | 21 | ||||
-rw-r--r-- | src/rgw/rgw_quota.h | 11 |
5 files changed, 73 insertions, 1 deletions
diff --git a/src/rgw/rgw_common.h b/src/rgw/rgw_common.h index 689fabf4c78..53f96df1c06 100644 --- a/src/rgw/rgw_common.h +++ b/src/rgw/rgw_common.h @@ -91,6 +91,7 @@ using ceph::crypto::MD5; #define RGW_OP_TYPE_WRITE 0x02 #define RGW_OP_TYPE_DELETE 0x04 +#define RGW_OP_TYPE_MODIFY (RGW_OP_TYPE_WRITE | RGW_OP_TYPE_DELETE) #define RGW_OP_TYPE_ALL (RGW_OP_TYPE_READ | RGW_OP_TYPE_WRITE | RGW_OP_TYPE_DELETE) #define RGW_DEFAULT_MAX_BUCKETS 1000 diff --git a/src/rgw/rgw_op.cc b/src/rgw/rgw_op.cc index 114b8709a22..54c0a98e1d7 100644 --- a/src/rgw/rgw_op.cc +++ b/src/rgw/rgw_op.cc @@ -421,6 +421,43 @@ int RGWOp::verify_op_mask() return 0; } +int RGWOp::init_quota() +{ + /* init quota related stuff */ + if (!(s->user.op_mask & RGW_OP_TYPE_MODIFY)) { + return 0; + } + + /* only interested in object related ops */ + if (s->object_str.empty()) { + return 0; + } + + if (s->bucket_info.quota.enabled) { + bucket_quota = s->bucket_info.quota; + return 0; + } + if (s->user.user_id == s->bucket_owner.get_id()) { + if (s->user.bucket_quota.enabled) { + bucket_quota = s->user.bucket_quota; + return 0; + } + } else { + RGWUserInfo owner_info; + int r = rgw_get_user_info_by_uid(store, s->bucket_info.owner, owner_info); + if (r < 0) + return r; + + if (owner_info.bucket_quota.enabled) { + bucket_quota = owner_info.bucket_quota; + return 0; + } + } + + bucket_quota = store->region_map.bucket_quota; + return 0; +} + static bool validate_cors_rule_method(RGWCORSRule *rule, const char *req_meth) { uint8_t flags = 0; if (strcmp(req_meth, "GET") == 0) flags = RGW_CORS_GET; diff --git a/src/rgw/rgw_op.h b/src/rgw/rgw_op.h index 948a11830c2..75919296114 100644 --- a/src/rgw/rgw_op.h +++ b/src/rgw/rgw_op.h @@ -20,6 +20,7 @@ #include "rgw_bucket.h" #include "rgw_acl.h" #include "rgw_cors.h" +#include "rgw_quota.h" using namespace std; @@ -36,6 +37,9 @@ protected: RGWRados *store; RGWCORSConfiguration bucket_cors; bool cors_exist; + RGWQuotaInfo bucket_quota; + + virtual int init_quota(); public: RGWOp() : s(NULL), dialect_handler(NULL), store(NULL), cors_exist(false) {} virtual ~RGWOp() {} diff --git a/src/rgw/rgw_quota.cc b/src/rgw/rgw_quota.cc index 8bbe905c6d0..b73b73e1b23 100644 --- a/src/rgw/rgw_quota.cc +++ b/src/rgw/rgw_quota.cc @@ -28,7 +28,6 @@ public: void adjust_bucket_stats(rgw_bucket& bucket, int objs_delta, uint64_t added_bytes, uint64_t removed_bytes); }; - int RGWBucketStatsCache::fetch_bucket_totals(rgw_bucket& bucket, RGWBucketStats& stats) { RGWBucketInfo bucket_info; @@ -95,3 +94,23 @@ void RGWBucketStatsCache::adjust_bucket_stats(rgw_bucket& bucket, int objs_delta } +class RGWQuotaHandlerImpl : public RGWQuotaHandler { + RGWBucketStatsCache stats_cache; +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) { + return 0; + } +}; + + +RGWQuotaHandler *RGWQuotaHandler::generate_handler(RGWRados *store) +{ + return new RGWQuotaHandlerImpl(store); +}; + +void RGWQuotaHandler::free_handler(RGWQuotaHandler *handler) +{ + delete handler; +} diff --git a/src/rgw/rgw_quota.h b/src/rgw/rgw_quota.h index 939490f7505..babfecc3c9e 100644 --- a/src/rgw/rgw_quota.h +++ b/src/rgw/rgw_quota.h @@ -37,5 +37,16 @@ struct RGWQuotaInfo { }; WRITE_CLASS_ENCODER(RGWQuotaInfo) +class rgw_bucket; + +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; + + static RGWQuotaHandler *generate_handler(RGWRados *store); + static void free_handler(RGWQuotaHandler *handler); +}; #endif |