]>
Commit | Line | Data |
---|---|---|
7c673cae | 1 | // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- |
9f95a23c | 2 | // vim: ts=8 sw=2 smarttab ft=cpp |
11fdf7f2 | 3 | |
7c673cae FG |
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" | |
11fdf7f2 | 20 | #include "common/config_fwd.h" |
7c673cae FG |
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 | ||
7c673cae | 30 | class JSONObj; |
9f95a23c TL |
31 | namespace rgw { namespace sal { |
32 | class RGWRadosStore; | |
33 | } } | |
7c673cae FG |
34 | |
35 | struct RGWQuotaInfo { | |
36 | template<class T> friend class RGWQuotaCache; | |
37 | protected: | |
38 | /* The quota thresholds after which comparing against cached storage stats | |
39 | * is disallowed. Those fields may be accessed only by the RGWQuotaCache. | |
40 | * They are not intended as tunables but rather as a mean to store results | |
41 | * of repeating calculations in the quota cache subsystem. */ | |
42 | int64_t max_size_soft_threshold; | |
43 | int64_t max_objs_soft_threshold; | |
44 | ||
45 | public: | |
46 | int64_t max_size; | |
47 | int64_t max_objects; | |
48 | bool enabled; | |
49 | /* Do we want to compare with raw, not rounded RGWStorageStats::size (true) | |
50 | * or maybe rounded-to-4KiB RGWStorageStats::size_rounded (false)? */ | |
51 | bool check_on_raw; | |
52 | ||
53 | RGWQuotaInfo() | |
54 | : max_size_soft_threshold(-1), | |
55 | max_objs_soft_threshold(-1), | |
56 | max_size(-1), | |
57 | max_objects(-1), | |
58 | enabled(false), | |
59 | check_on_raw(false) { | |
60 | } | |
61 | ||
62 | void encode(bufferlist& bl) const { | |
63 | ENCODE_START(3, 1, bl); | |
64 | if (max_size < 0) { | |
11fdf7f2 | 65 | encode(-rgw_rounded_kb(abs(max_size)), bl); |
7c673cae | 66 | } else { |
11fdf7f2 | 67 | encode(rgw_rounded_kb(max_size), bl); |
7c673cae | 68 | } |
11fdf7f2 TL |
69 | encode(max_objects, bl); |
70 | encode(enabled, bl); | |
71 | encode(max_size, bl); | |
72 | encode(check_on_raw, bl); | |
7c673cae FG |
73 | ENCODE_FINISH(bl); |
74 | } | |
11fdf7f2 | 75 | void decode(bufferlist::const_iterator& bl) { |
7c673cae FG |
76 | DECODE_START_LEGACY_COMPAT_LEN(3, 1, 1, bl); |
77 | int64_t max_size_kb; | |
11fdf7f2 TL |
78 | decode(max_size_kb, bl); |
79 | decode(max_objects, bl); | |
80 | decode(enabled, bl); | |
7c673cae FG |
81 | if (struct_v < 2) { |
82 | max_size = max_size_kb * 1024; | |
83 | } else { | |
11fdf7f2 | 84 | decode(max_size, bl); |
7c673cae FG |
85 | } |
86 | if (struct_v >= 3) { | |
11fdf7f2 | 87 | decode(check_on_raw, bl); |
7c673cae FG |
88 | } |
89 | DECODE_FINISH(bl); | |
90 | } | |
91 | ||
92 | void dump(Formatter *f) const; | |
93 | ||
94 | void decode_json(JSONObj *obj); | |
95 | ||
96 | }; | |
97 | WRITE_CLASS_ENCODER(RGWQuotaInfo) | |
98 | ||
99 | struct rgw_bucket; | |
100 | ||
101 | class RGWQuotaHandler { | |
102 | public: | |
103 | RGWQuotaHandler() {} | |
104 | virtual ~RGWQuotaHandler() { | |
105 | } | |
106 | virtual int check_quota(const rgw_user& bucket_owner, rgw_bucket& bucket, | |
107 | RGWQuotaInfo& user_quota, RGWQuotaInfo& bucket_quota, | |
108 | uint64_t num_objs, uint64_t size) = 0; | |
109 | ||
9f95a23c TL |
110 | virtual void check_bucket_shards(uint64_t max_objs_per_shard, uint64_t num_shards, |
111 | uint64_t num_objs, bool& need_resharding, uint32_t *suggested_num_shards) = 0; | |
31f18b77 | 112 | |
7c673cae FG |
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 | ||
9f95a23c | 115 | static RGWQuotaHandler *generate_handler(rgw::sal::RGWRadosStore *store, bool quota_threads); |
7c673cae FG |
116 | static void free_handler(RGWQuotaHandler *handler); |
117 | }; | |
118 | ||
f64942e4 | 119 | // apply default quotas from configuration |
11fdf7f2 TL |
120 | void rgw_apply_default_bucket_quota(RGWQuotaInfo& quota, const ConfigProxy& conf); |
121 | void rgw_apply_default_user_quota(RGWQuotaInfo& quota, const ConfigProxy& conf); | |
f64942e4 | 122 | |
7c673cae | 123 | #endif |