]> git.proxmox.com Git - ceph.git/blob - ceph/src/rgw/rgw_quota.h
import ceph quincy 17.2.6
[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 ft=cpp
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 #include "rgw/rgw_basic_types.h"
26 #include "common/async/yield_context.h"
27
28 static inline int64_t rgw_rounded_kb(int64_t bytes)
29 {
30 return (bytes + 1023) / 1024;
31 }
32
33 class JSONObj;
34 namespace rgw { namespace sal {
35 class Store;
36 } }
37
38 struct RGWQuotaInfo {
39 template<class T> friend class RGWQuotaCache;
40 public:
41 int64_t max_size;
42 int64_t max_objects;
43 bool enabled;
44 /* Do we want to compare with raw, not rounded RGWStorageStats::size (true)
45 * or maybe rounded-to-4KiB RGWStorageStats::size_rounded (false)? */
46 bool check_on_raw;
47
48 RGWQuotaInfo()
49 : max_size(-1),
50 max_objects(-1),
51 enabled(false),
52 check_on_raw(false) {
53 }
54
55 void encode(bufferlist& bl) const {
56 ENCODE_START(3, 1, bl);
57 if (max_size < 0) {
58 encode(-rgw_rounded_kb(abs(max_size)), bl);
59 } else {
60 encode(rgw_rounded_kb(max_size), bl);
61 }
62 encode(max_objects, bl);
63 encode(enabled, bl);
64 encode(max_size, bl);
65 encode(check_on_raw, bl);
66 ENCODE_FINISH(bl);
67 }
68 void decode(bufferlist::const_iterator& bl) {
69 DECODE_START_LEGACY_COMPAT_LEN(3, 1, 1, bl);
70 int64_t max_size_kb;
71 decode(max_size_kb, bl);
72 decode(max_objects, bl);
73 decode(enabled, bl);
74 if (struct_v < 2) {
75 max_size = max_size_kb * 1024;
76 } else {
77 decode(max_size, bl);
78 }
79 if (struct_v >= 3) {
80 decode(check_on_raw, bl);
81 }
82 DECODE_FINISH(bl);
83 }
84
85 void dump(Formatter *f) const;
86
87 void decode_json(JSONObj *obj);
88
89 };
90 WRITE_CLASS_ENCODER(RGWQuotaInfo)
91
92 struct rgw_bucket;
93
94 class RGWQuotaHandler {
95 public:
96 RGWQuotaHandler() {}
97 virtual ~RGWQuotaHandler() {
98 }
99 virtual int check_quota(const DoutPrefixProvider *dpp, const rgw_user& bucket_owner, rgw_bucket& bucket,
100 RGWQuotaInfo& user_quota, RGWQuotaInfo& bucket_quota,
101 uint64_t num_objs, uint64_t size, optional_yield y) = 0;
102
103 virtual void check_bucket_shards(const DoutPrefixProvider *dpp, uint64_t max_objs_per_shard, uint64_t num_shards,
104 uint64_t num_objs, bool& need_resharding, uint32_t *suggested_num_shards) = 0;
105
106 virtual void update_stats(const rgw_user& bucket_owner, rgw_bucket& bucket, int obj_delta, uint64_t added_bytes, uint64_t removed_bytes) = 0;
107
108 static RGWQuotaHandler *generate_handler(const DoutPrefixProvider *dpp, rgw::sal::Store* store, bool quota_threads);
109 static void free_handler(RGWQuotaHandler *handler);
110 };
111
112 // apply default quotas from configuration
113 void rgw_apply_default_bucket_quota(RGWQuotaInfo& quota, const ConfigProxy& conf);
114 void rgw_apply_default_user_quota(RGWQuotaInfo& quota, const ConfigProxy& conf);
115
116 #endif