]>
git.proxmox.com Git - ceph.git/blob - 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
5 * Ceph - scalable distributed file system
7 * Copyright (C) 2013 Inktank, Inc
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.
16 #ifndef CEPH_RGW_QUOTA_H
17 #define CEPH_RGW_QUOTA_H
19 #include "include/utime.h"
20 #include "common/config_fwd.h"
21 #include "common/lru_map.h"
25 #include "rgw/rgw_basic_types.h"
26 #include "common/async/yield_context.h"
28 static inline int64_t rgw_rounded_kb(int64_t bytes
)
30 return (bytes
+ 1023) / 1024;
34 namespace rgw
{ namespace sal
{
39 template<class T
> friend class RGWQuotaCache
;
44 /* Do we want to compare with raw, not rounded RGWStorageStats::size (true)
45 * or maybe rounded-to-4KiB RGWStorageStats::size_rounded (false)? */
55 void encode(bufferlist
& bl
) const {
56 ENCODE_START(3, 1, bl
);
58 encode(-rgw_rounded_kb(abs(max_size
)), bl
);
60 encode(rgw_rounded_kb(max_size
), bl
);
62 encode(max_objects
, bl
);
65 encode(check_on_raw
, bl
);
68 void decode(bufferlist::const_iterator
& bl
) {
69 DECODE_START_LEGACY_COMPAT_LEN(3, 1, 1, bl
);
71 decode(max_size_kb
, bl
);
72 decode(max_objects
, bl
);
75 max_size
= max_size_kb
* 1024;
80 decode(check_on_raw
, bl
);
85 void dump(Formatter
*f
) const;
87 void decode_json(JSONObj
*obj
);
90 WRITE_CLASS_ENCODER(RGWQuotaInfo
)
94 class RGWQuotaHandler
{
97 virtual ~RGWQuotaHandler() {
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;
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;
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;
108 static RGWQuotaHandler
*generate_handler(const DoutPrefixProvider
*dpp
, rgw::sal::Store
* store
, bool quota_threads
);
109 static void free_handler(RGWQuotaHandler
*handler
);
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
);