1 // -*- mode:C; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
4 #ifndef CEPH_CLS_USER_TYPES_H
5 #define CEPH_CLS_USER_TYPES_H
7 #include "include/encoding.h"
8 #include "include/types.h"
9 #include "include/utime.h"
10 #include "common/ceph_time.h"
13 * this needs to be compatible with rgw_bucket, as it replaces it
15 struct cls_user_bucket {
18 std::string bucket_id;
19 std::string placement_id;
21 std::string data_pool;
22 std::string index_pool;
23 std::string data_extra_pool;
26 void encode(bufferlist& bl) const {
27 /* since new version of this structure is not backward compatible,
28 * we have older rgw running against newer osd if we encode it
29 * in the new way. Only encode newer version if placement_id is
30 * not empty, otherwise keep handling it as before
32 if (!placement_id.empty()) {
33 ENCODE_START(9, 8, bl);
36 ::encode(bucket_id, bl);
37 ::encode(placement_id, bl);
40 ENCODE_START(7, 3, bl);
42 ::encode(explicit_placement.data_pool, bl);
44 ::encode(bucket_id, bl);
45 ::encode(explicit_placement.index_pool, bl);
46 ::encode(explicit_placement.data_extra_pool, bl);
50 void decode(bufferlist::iterator& bl) {
51 DECODE_START_LEGACY_COMPAT_LEN(8, 3, 3, bl);
54 ::decode(explicit_placement.data_pool, bl);
62 snprintf(buf, sizeof(buf), "%llu", (long long)id);
65 ::decode(bucket_id, bl);
70 ::decode(explicit_placement.index_pool, bl);
72 explicit_placement.index_pool = explicit_placement.data_pool;
75 ::decode(explicit_placement.data_extra_pool, bl);
78 ::decode(placement_id, bl);
79 if (struct_v == 8 && placement_id.empty()) {
80 ::decode(explicit_placement.data_pool, bl);
81 ::decode(explicit_placement.index_pool, bl);
82 ::decode(explicit_placement.data_extra_pool, bl);
88 bool operator<(const cls_user_bucket& b) const {
89 return name.compare(b.name) < 0;
92 void dump(Formatter *f) const;
93 static void generate_test_instances(list<cls_user_bucket*>& ls);
95 WRITE_CLASS_ENCODER(cls_user_bucket)
98 * this structure overrides RGWBucketEnt
100 struct cls_user_bucket_entry {
101 cls_user_bucket bucket;
104 ceph::real_time creation_time;
106 bool user_stats_sync;
108 cls_user_bucket_entry() : size(0), size_rounded(0), count(0), user_stats_sync(false) {}
110 void encode(bufferlist& bl) const {
111 ENCODE_START(9, 5, bl);
113 __u32 mt = ceph::real_clock::to_time_t(creation_time);
114 string empty_str; // originally had the bucket name here, but we encode bucket later
115 ::encode(empty_str, bl);
119 ::encode(bucket, bl);
122 ::encode(user_stats_sync, bl);
123 ::encode(creation_time, bl);
124 //::encode(placement_rule, bl); removed in v9
127 void decode(bufferlist::iterator& bl) {
128 DECODE_START_LEGACY_COMPAT_LEN(9, 5, 5, bl);
131 string empty_str; // backward compatibility
132 ::decode(empty_str, bl);
137 creation_time = ceph::real_clock::from_time_t(mt);
142 ::decode(bucket, bl);
147 ::decode(user_stats_sync, bl);
149 ::decode(creation_time, bl);
150 if (struct_v == 8) { // added in v8, removed in v9
151 std::string placement_rule;
152 ::decode(placement_rule, bl);
156 void dump(Formatter *f) const;
157 static void generate_test_instances(list<cls_user_bucket_entry*>& ls);
159 WRITE_CLASS_ENCODER(cls_user_bucket_entry)
161 struct cls_user_stats {
162 uint64_t total_entries;
163 uint64_t total_bytes;
164 uint64_t total_bytes_rounded;
169 total_bytes_rounded(0) {}
171 void encode(bufferlist& bl) const {
172 ENCODE_START(1, 1, bl);
173 ::encode(total_entries, bl);
174 ::encode(total_bytes, bl);
175 ::encode(total_bytes_rounded, bl);
178 void decode(bufferlist::iterator& bl) {
180 ::decode(total_entries, bl);
181 ::decode(total_bytes, bl);
182 ::decode(total_bytes_rounded, bl);
186 void dump(Formatter *f) const;
187 static void generate_test_instances(list<cls_user_stats*>& ls);
189 WRITE_CLASS_ENCODER(cls_user_stats)
192 * this needs to be compatible with rgw_bucket, as it replaces it
194 struct cls_user_header {
195 cls_user_stats stats;
196 ceph::real_time last_stats_sync; /* last time a full stats sync completed */
197 ceph::real_time last_stats_update; /* last time a stats update was done */
199 void encode(bufferlist& bl) const {
200 ENCODE_START(1, 1, bl);
202 ::encode(last_stats_sync, bl);
203 ::encode(last_stats_update, bl);
206 void decode(bufferlist::iterator& bl) {
209 ::decode(last_stats_sync, bl);
210 ::decode(last_stats_update, bl);
214 void dump(Formatter *f) const;
215 static void generate_test_instances(list<cls_user_header*>& ls);
217 WRITE_CLASS_ENCODER(cls_user_header)
219 void cls_user_gen_test_bucket(cls_user_bucket *bucket, int i);
220 void cls_user_gen_test_bucket_entry(cls_user_bucket_entry *entry, int i);
221 void cls_user_gen_test_stats(cls_user_stats *stats);
222 void cls_user_gen_test_header(cls_user_header *h);