summaryrefslogtreecommitdiff
path: root/src/rgw/rgw_quota.h
blob: 6cdc21c52a572b21d025d25287abb58bd6b62578 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#ifndef CEPH_RGW_QUOTA_H
#define CEPH_RGW_QUOTA_H


#include "include/utime.h"
#include "include/atomic.h"
#include "common/lru_map.h"
#include "common/RefCountedObj.h"

class RGWRados;
class JSONObj;

struct RGWQuotaInfo {
  int64_t max_size_kb;
  int64_t max_objects;
  bool enabled;

  RGWQuotaInfo() : max_size_kb(-1), max_objects(-1), enabled(false) {}

  void encode(bufferlist& bl) const {
    ENCODE_START(1, 1, bl);
    ::encode(max_size_kb, bl);
    ::encode(max_objects, bl);
    ::encode(enabled, bl);
    ENCODE_FINISH(bl);
  }
  void decode(bufferlist::iterator& bl) {
    DECODE_START(1, bl);
    ::decode(max_size_kb, bl);
    ::decode(max_objects, bl);
    ::decode(enabled, bl);
    DECODE_FINISH(bl);
  }

  void dump(Formatter *f) const;

  void decode_json(JSONObj *obj);

};
WRITE_CLASS_ENCODER(RGWQuotaInfo)

class rgw_bucket;

class RGWQuotaHandler {
  RefCountedWaitObject async_refcount;
public:
  RGWQuotaHandler() {}
  virtual ~RGWQuotaHandler() {
    async_refcount.put_wait(); /* wait for all pending async requests to complete */
  }
  virtual int check_quota(rgw_bucket& bucket, RGWQuotaInfo& bucket_quota,
			  uint64_t num_objs, uint64_t size) = 0;

  virtual void update_stats(rgw_bucket& bucket, int obj_delta, uint64_t added_bytes, uint64_t removed_bytes) = 0;

  static RGWQuotaHandler *generate_handler(RGWRados *store);
  static void free_handler(RGWQuotaHandler *handler);
};

#endif