]>
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
4 * Ceph - scalable distributed file system
6 * Copyright (C) 2013 Inktank, Inc
8 * This is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License version 2.1, as published by the Free Software
11 * Foundation. See file COPYING.
15 #ifndef CEPH_RGW_QUOTA_H
16 #define CEPH_RGW_QUOTA_H
18 #include "include/utime.h"
19 #include "common/lru_map.h"
23 static inline int64_t rgw_rounded_kb(int64_t bytes
)
25 return (bytes
+ 1023) / 1024;
32 template<class T
> friend class RGWQuotaCache
;
34 /* The quota thresholds after which comparing against cached storage stats
35 * is disallowed. Those fields may be accessed only by the RGWQuotaCache.
36 * They are not intended as tunables but rather as a mean to store results
37 * of repeating calculations in the quota cache subsystem. */
38 int64_t max_size_soft_threshold
;
39 int64_t max_objs_soft_threshold
;
45 /* Do we want to compare with raw, not rounded RGWStorageStats::size (true)
46 * or maybe rounded-to-4KiB RGWStorageStats::size_rounded (false)? */
50 : max_size_soft_threshold(-1),
51 max_objs_soft_threshold(-1),
58 void encode(bufferlist
& bl
) const {
59 ENCODE_START(3, 1, bl
);
61 ::encode(-rgw_rounded_kb(abs(max_size
)), bl
);
63 ::encode(rgw_rounded_kb(max_size
), bl
);
65 ::encode(max_objects
, bl
);
66 ::encode(enabled
, bl
);
67 ::encode(max_size
, bl
);
68 ::encode(check_on_raw
, bl
);
71 void decode(bufferlist::iterator
& bl
) {
72 DECODE_START_LEGACY_COMPAT_LEN(3, 1, 1, bl
);
74 ::decode(max_size_kb
, bl
);
75 ::decode(max_objects
, bl
);
76 ::decode(enabled
, bl
);
78 max_size
= max_size_kb
* 1024;
80 ::decode(max_size
, bl
);
83 ::decode(check_on_raw
, bl
);
88 void dump(Formatter
*f
) const;
90 void decode_json(JSONObj
*obj
);
93 WRITE_CLASS_ENCODER(RGWQuotaInfo
)
97 class RGWQuotaHandler
{
100 virtual ~RGWQuotaHandler() {
102 virtual int check_quota(const rgw_user
& bucket_owner
, rgw_bucket
& bucket
,
103 RGWQuotaInfo
& user_quota
, RGWQuotaInfo
& bucket_quota
,
104 uint64_t num_objs
, uint64_t size
) = 0;
106 virtual int check_bucket_shards(uint64_t max_objs_per_shard
, uint64_t num_shards
,
107 const rgw_user
& bucket_owner
, const rgw_bucket
& bucket
,
108 RGWQuotaInfo
& bucket_quota
, uint64_t num_objs
, bool& need_resharding
,
109 uint32_t *suggested_num_shards
) = 0;
111 virtual void update_stats(const rgw_user
& bucket_owner
, rgw_bucket
& bucket
, int obj_delta
, uint64_t added_bytes
, uint64_t removed_bytes
) = 0;
113 static RGWQuotaHandler
*generate_handler(RGWRados
*store
, bool quota_threads
);
114 static void free_handler(RGWQuotaHandler
*handler
);