From c821da950ec960ef2353ca26424cd9b37ec99746 Mon Sep 17 00:00:00 2001 From: Yehuda Sadeh Date: Fri, 27 Sep 2013 16:43:10 -0700 Subject: [PATCH] rgw: more quota implementation Signed-off-by: Yehuda Sadeh --- src/rgw/rgw_common.h | 1 + src/rgw/rgw_op.cc | 37 +++++++++++++++++++++++++++++++++++++ src/rgw/rgw_op.h | 4 ++++ src/rgw/rgw_quota.cc | 21 ++++++++++++++++++++- src/rgw/rgw_quota.h | 11 +++++++++++ 5 files changed, 73 insertions(+), 1 deletion(-) diff --git a/src/rgw/rgw_common.h b/src/rgw/rgw_common.h index 689fabf4c78b8..53f96df1c06ec 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 114b8709a2233..54c0a98e1d749 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 948a11830c2c1..7591929611484 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 8bbe905c6d0ae..b73b73e1b2384 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 939490f75050c..babfecc3c9e2e 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 -- 2.39.5