]> git.proxmox.com Git - ceph.git/blob - ceph/src/rgw/rgw_quota.h
update sources to v12.1.1
[ceph.git] / ceph / src / rgw / rgw_quota.h
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
3 /*
4 * Ceph - scalable distributed file system
5 *
6 * Copyright (C) 2013 Inktank, Inc
7 *
8 * This is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License version 2.1, as published by the Free Software
11 * Foundation. See file COPYING.
12 *
13 */
14
15 #ifndef CEPH_RGW_QUOTA_H
16 #define CEPH_RGW_QUOTA_H
17
18 #include "include/utime.h"
19 #include "common/lru_map.h"
20
21 #include <atomic>
22
23 static inline int64_t rgw_rounded_kb(int64_t bytes)
24 {
25 return (bytes + 1023) / 1024;
26 }
27
28 class RGWRados;
29 class JSONObj;
30
31 struct RGWQuotaInfo {
32 template<class T> friend class RGWQuotaCache;
33 protected:
34 /* The quota thresholds after which comparing against cached storage stats
35 * is disallowed. Those fields may be accessed only by the RGWQuotaCache.
36 * They are not intended as tunables but rather as a mean to store results
37 * of repeating calculations in the quota cache subsystem. */
38 int64_t max_size_soft_threshold;
39 int64_t max_objs_soft_threshold;
40
41 public:
42 int64_t max_size;
43 int64_t max_objects;
44 bool enabled;
45 /* Do we want to compare with raw, not rounded RGWStorageStats::size (true)
46 * or maybe rounded-to-4KiB RGWStorageStats::size_rounded (false)? */
47 bool check_on_raw;
48
49 RGWQuotaInfo()
50 : max_size_soft_threshold(-1),
51 max_objs_soft_threshold(-1),
52 max_size(-1),
53 max_objects(-1),
54 enabled(false),
55 check_on_raw(false) {
56 }
57
58 void encode(bufferlist& bl) const {
59 ENCODE_START(3, 1, bl);
60 if (max_size < 0) {
61 ::encode(-rgw_rounded_kb(abs(max_size)), bl);
62 } else {
63 ::encode(rgw_rounded_kb(max_size), bl);
64 }
65 ::encode(max_objects, bl);
66 ::encode(enabled, bl);
67 ::encode(max_size, bl);
68 ::encode(check_on_raw, bl);
69 ENCODE_FINISH(bl);
70 }
71 void decode(bufferlist::iterator& bl) {
72 DECODE_START_LEGACY_COMPAT_LEN(3, 1, 1, bl);
73 int64_t max_size_kb;
74 ::decode(max_size_kb, bl);
75 ::decode(max_objects, bl);
76 ::decode(enabled, bl);
77 if (struct_v < 2) {
78 max_size = max_size_kb * 1024;
79 } else {
80 ::decode(max_size, bl);
81 }
82 if (struct_v >= 3) {
83 ::decode(check_on_raw, bl);
84 }
85 DECODE_FINISH(bl);
86 }
87
88 void dump(Formatter *f) const;
89
90 void decode_json(JSONObj *obj);
91
92 };
93 WRITE_CLASS_ENCODER(RGWQuotaInfo)
94
95 struct rgw_bucket;
96
97 class RGWQuotaHandler {
98 public:
99 RGWQuotaHandler() {}
100 virtual ~RGWQuotaHandler() {
101 }
102 virtual int check_quota(const rgw_user& bucket_owner, rgw_bucket& bucket,
103 RGWQuotaInfo& user_quota, RGWQuotaInfo& bucket_quota,
104 uint64_t num_objs, uint64_t size) = 0;
105
106 virtual int check_bucket_shards(uint64_t max_objs_per_shard, uint64_t num_shards,
107 const rgw_user& bucket_owner, const rgw_bucket& bucket,
108 RGWQuotaInfo& bucket_quota, uint64_t num_objs, bool& need_resharding,
109 uint32_t *suggested_num_shards) = 0;
110
111 virtual void update_stats(const rgw_user& bucket_owner, rgw_bucket& bucket, int obj_delta, uint64_t added_bytes, uint64_t removed_bytes) = 0;
112
113 static RGWQuotaHandler *generate_handler(RGWRados *store, bool quota_threads);
114 static void free_handler(RGWQuotaHandler *handler);
115 };
116
117 #endif