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