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