]>
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 | ||
f67539c2 TL |
25 | #include "rgw/rgw_basic_types.h" |
26 | #include "common/async/yield_context.h" | |
27 | ||
7c673cae FG |
28 | static inline int64_t rgw_rounded_kb(int64_t bytes) |
29 | { | |
30 | return (bytes + 1023) / 1024; | |
31 | } | |
32 | ||
7c673cae | 33 | class JSONObj; |
9f95a23c | 34 | namespace rgw { namespace sal { |
20effc67 | 35 | class Store; |
9f95a23c | 36 | } } |
7c673cae FG |
37 | |
38 | struct RGWQuotaInfo { | |
39 | template<class T> friend class RGWQuotaCache; | |
7c673cae FG |
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() | |
522d829b | 49 | : max_size(-1), |
7c673cae FG |
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) { | |
11fdf7f2 | 58 | encode(-rgw_rounded_kb(abs(max_size)), bl); |
7c673cae | 59 | } else { |
11fdf7f2 | 60 | encode(rgw_rounded_kb(max_size), bl); |
7c673cae | 61 | } |
11fdf7f2 TL |
62 | encode(max_objects, bl); |
63 | encode(enabled, bl); | |
64 | encode(max_size, bl); | |
65 | encode(check_on_raw, bl); | |
7c673cae FG |
66 | ENCODE_FINISH(bl); |
67 | } | |
11fdf7f2 | 68 | void decode(bufferlist::const_iterator& bl) { |
7c673cae FG |
69 | DECODE_START_LEGACY_COMPAT_LEN(3, 1, 1, bl); |
70 | int64_t max_size_kb; | |
11fdf7f2 TL |
71 | decode(max_size_kb, bl); |
72 | decode(max_objects, bl); | |
73 | decode(enabled, bl); | |
7c673cae FG |
74 | if (struct_v < 2) { |
75 | max_size = max_size_kb * 1024; | |
76 | } else { | |
11fdf7f2 | 77 | decode(max_size, bl); |
7c673cae FG |
78 | } |
79 | if (struct_v >= 3) { | |
11fdf7f2 | 80 | decode(check_on_raw, bl); |
7c673cae FG |
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 | } | |
20effc67 | 99 | virtual int check_quota(const DoutPrefixProvider *dpp, const rgw_user& bucket_owner, rgw_bucket& bucket, |
7c673cae | 100 | RGWQuotaInfo& user_quota, RGWQuotaInfo& bucket_quota, |
f67539c2 | 101 | uint64_t num_objs, uint64_t size, optional_yield y) = 0; |
7c673cae | 102 | |
20effc67 | 103 | virtual void check_bucket_shards(const DoutPrefixProvider *dpp, uint64_t max_objs_per_shard, uint64_t num_shards, |
9f95a23c | 104 | uint64_t num_objs, bool& need_resharding, uint32_t *suggested_num_shards) = 0; |
31f18b77 | 105 | |
7c673cae FG |
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 | ||
20effc67 | 108 | static RGWQuotaHandler *generate_handler(const DoutPrefixProvider *dpp, rgw::sal::Store* store, bool quota_threads); |
7c673cae FG |
109 | static void free_handler(RGWQuotaHandler *handler); |
110 | }; | |
111 | ||
f64942e4 | 112 | // apply default quotas from configuration |
11fdf7f2 TL |
113 | void rgw_apply_default_bucket_quota(RGWQuotaInfo& quota, const ConfigProxy& conf); |
114 | void rgw_apply_default_user_quota(RGWQuotaInfo& quota, const ConfigProxy& conf); | |
f64942e4 | 115 | |
7c673cae | 116 | #endif |