]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
rgw: more quota implementation
authorYehuda Sadeh <yehuda@inktank.com>
Fri, 27 Sep 2013 23:43:10 +0000 (16:43 -0700)
committerYehuda Sadeh <yehuda@inktank.com>
Fri, 27 Sep 2013 23:43:10 +0000 (16:43 -0700)
Signed-off-by: Yehuda Sadeh <yehuda@inktank.com>
src/rgw/rgw_common.h
src/rgw/rgw_op.cc
src/rgw/rgw_op.h
src/rgw/rgw_quota.cc
src/rgw/rgw_quota.h

index 689fabf4c78b881cb2b62b9b6d327c3c6c29f8cb..53f96df1c06ec33b15a96ead520715459114f9ff 100644 (file)
@@ -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
index 114b8709a22338a7e3ec233e520d82f55d1e2de6..54c0a98e1d7495d2b9e01416c2f6390fc5e8bbdc 100644 (file)
@@ -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;
index 948a11830c2c152e7e46e77c3b970c50107b9b53..759192961148423d6410dfe0ab1561ba526c84c4 100644 (file)
@@ -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() {}
index 8bbe905c6d0aeee7fce041681aa4dd75c62b76a5..b73b73e1b2384aa71d8d46d07caee549d983ca30 100644 (file)
@@ -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;
+}
index 939490f75050cf839371692b5f1328c20c66fdf6..babfecc3c9e2e845153bc02609fd206f79d37140 100644 (file)
@@ -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