]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | #ifndef CEPH_CLS_RGW_TYPES_H |
2 | #define CEPH_CLS_RGW_TYPES_H | |
3 | ||
7c673cae FG |
4 | #include "common/ceph_time.h" |
5 | #include "common/Formatter.h" | |
6 | ||
7 | #include "rgw/rgw_basic_types.h" | |
8 | ||
9 | #define CEPH_RGW_REMOVE 'r' | |
10 | #define CEPH_RGW_UPDATE 'u' | |
11 | #define CEPH_RGW_TAG_TIMEOUT 120 | |
12 | #define CEPH_RGW_DIR_SUGGEST_LOG_OP 0x80 | |
13 | #define CEPH_RGW_DIR_SUGGEST_OP_MASK 0x7f | |
14 | ||
15 | class JSONObj; | |
16 | ||
17 | namespace ceph { | |
18 | class Formatter; | |
19 | } | |
20 | ||
31f18b77 FG |
21 | using rgw_zone_set = std::set<std::string>; |
22 | ||
7c673cae FG |
23 | enum RGWPendingState { |
24 | CLS_RGW_STATE_PENDING_MODIFY = 0, | |
25 | CLS_RGW_STATE_COMPLETE = 1, | |
26 | CLS_RGW_STATE_UNKNOWN = 2, | |
27 | }; | |
28 | ||
29 | enum RGWModifyOp { | |
30 | CLS_RGW_OP_ADD = 0, | |
31 | CLS_RGW_OP_DEL = 1, | |
32 | CLS_RGW_OP_CANCEL = 2, | |
33 | CLS_RGW_OP_UNKNOWN = 3, | |
34 | CLS_RGW_OP_LINK_OLH = 4, | |
35 | CLS_RGW_OP_LINK_OLH_DM = 5, /* creation of delete marker */ | |
36 | CLS_RGW_OP_UNLINK_INSTANCE = 6, | |
37 | }; | |
38 | ||
39 | enum RGWBILogFlags { | |
40 | RGW_BILOG_FLAG_VERSIONED_OP = 0x1, | |
41 | }; | |
42 | ||
43 | enum RGWCheckMTimeType { | |
44 | CLS_RGW_CHECK_TIME_MTIME_EQ = 0, | |
45 | CLS_RGW_CHECK_TIME_MTIME_LT = 1, | |
46 | CLS_RGW_CHECK_TIME_MTIME_LE = 2, | |
47 | CLS_RGW_CHECK_TIME_MTIME_GT = 3, | |
48 | CLS_RGW_CHECK_TIME_MTIME_GE = 4, | |
49 | }; | |
50 | ||
51 | #define ROUND_BLOCK_SIZE 4096 | |
52 | ||
53 | static inline uint64_t cls_rgw_get_rounded_size(uint64_t size) | |
54 | { | |
55 | return (size + ROUND_BLOCK_SIZE - 1) & ~(ROUND_BLOCK_SIZE - 1); | |
56 | } | |
57 | ||
58 | struct rgw_bucket_pending_info { | |
59 | RGWPendingState state; | |
60 | ceph::real_time timestamp; | |
61 | uint8_t op; | |
62 | ||
63 | rgw_bucket_pending_info() : state(CLS_RGW_STATE_PENDING_MODIFY), op(0) {} | |
64 | ||
65 | void encode(bufferlist &bl) const { | |
66 | ENCODE_START(2, 2, bl); | |
67 | uint8_t s = (uint8_t)state; | |
68 | ::encode(s, bl); | |
69 | ::encode(timestamp, bl); | |
70 | ::encode(op, bl); | |
71 | ENCODE_FINISH(bl); | |
72 | } | |
73 | void decode(bufferlist::iterator &bl) { | |
74 | DECODE_START_LEGACY_COMPAT_LEN(2, 2, 2, bl); | |
75 | uint8_t s; | |
76 | ::decode(s, bl); | |
77 | state = (RGWPendingState)s; | |
78 | ::decode(timestamp, bl); | |
79 | ::decode(op, bl); | |
80 | DECODE_FINISH(bl); | |
81 | } | |
82 | void dump(Formatter *f) const; | |
83 | void decode_json(JSONObj *obj); | |
84 | static void generate_test_instances(list<rgw_bucket_pending_info*>& o); | |
85 | }; | |
86 | WRITE_CLASS_ENCODER(rgw_bucket_pending_info) | |
87 | ||
88 | struct rgw_bucket_dir_entry_meta { | |
89 | uint8_t category; | |
90 | uint64_t size; | |
91 | ceph::real_time mtime; | |
92 | string etag; | |
93 | string owner; | |
94 | string owner_display_name; | |
95 | string content_type; | |
96 | uint64_t accounted_size; | |
97 | string user_data; | |
98 | ||
99 | rgw_bucket_dir_entry_meta() : | |
100 | category(0), size(0), accounted_size(0) { } | |
101 | ||
102 | void encode(bufferlist &bl) const { | |
103 | ENCODE_START(5, 3, bl); | |
104 | ::encode(category, bl); | |
105 | ::encode(size, bl); | |
106 | ::encode(mtime, bl); | |
107 | ::encode(etag, bl); | |
108 | ::encode(owner, bl); | |
109 | ::encode(owner_display_name, bl); | |
110 | ::encode(content_type, bl); | |
111 | ::encode(accounted_size, bl); | |
112 | ::encode(user_data, bl); | |
113 | ENCODE_FINISH(bl); | |
114 | } | |
115 | void decode(bufferlist::iterator &bl) { | |
116 | DECODE_START_LEGACY_COMPAT_LEN(5, 3, 3, bl); | |
117 | ::decode(category, bl); | |
118 | ::decode(size, bl); | |
119 | ::decode(mtime, bl); | |
120 | ::decode(etag, bl); | |
121 | ::decode(owner, bl); | |
122 | ::decode(owner_display_name, bl); | |
123 | if (struct_v >= 2) | |
124 | ::decode(content_type, bl); | |
125 | if (struct_v >= 4) | |
126 | ::decode(accounted_size, bl); | |
127 | else | |
128 | accounted_size = size; | |
129 | if (struct_v >= 5) | |
130 | ::decode(user_data, bl); | |
131 | DECODE_FINISH(bl); | |
132 | } | |
133 | void dump(Formatter *f) const; | |
134 | void decode_json(JSONObj *obj); | |
135 | static void generate_test_instances(list<rgw_bucket_dir_entry_meta*>& o); | |
136 | }; | |
137 | WRITE_CLASS_ENCODER(rgw_bucket_dir_entry_meta) | |
138 | ||
139 | template<class T> | |
140 | void encode_packed_val(T val, bufferlist& bl) | |
141 | { | |
142 | if ((uint64_t)val < 0x80) { | |
143 | ::encode((uint8_t)val, bl); | |
144 | } else { | |
145 | unsigned char c = 0x80; | |
146 | ||
147 | if ((uint64_t)val < 0x100) { | |
148 | c |= 1; | |
149 | ::encode(c, bl); | |
150 | ::encode((uint8_t)val, bl); | |
151 | } else if ((uint64_t)val <= 0x10000) { | |
152 | c |= 2; | |
153 | ::encode(c, bl); | |
154 | ::encode((uint16_t)val, bl); | |
155 | } else if ((uint64_t)val <= 0x1000000) { | |
156 | c |= 4; | |
157 | ::encode(c, bl); | |
158 | ::encode((uint32_t)val, bl); | |
159 | } else { | |
160 | c |= 8; | |
161 | ::encode(c, bl); | |
162 | ::encode((uint64_t)val, bl); | |
163 | } | |
164 | } | |
165 | } | |
166 | ||
167 | template<class T> | |
168 | void decode_packed_val(T& val, bufferlist::iterator& bl) | |
169 | { | |
170 | unsigned char c; | |
171 | ::decode(c, bl); | |
172 | if (c < 0x80) { | |
173 | val = c; | |
174 | return; | |
175 | } | |
176 | ||
177 | c &= ~0x80; | |
178 | ||
179 | switch (c) { | |
180 | case 1: | |
181 | { | |
182 | uint8_t v; | |
183 | ::decode(v, bl); | |
184 | val = v; | |
185 | } | |
186 | break; | |
187 | case 2: | |
188 | { | |
189 | uint16_t v; | |
190 | ::decode(v, bl); | |
191 | val = v; | |
192 | } | |
193 | break; | |
194 | case 4: | |
195 | { | |
196 | uint32_t v; | |
197 | ::decode(v, bl); | |
198 | val = v; | |
199 | } | |
200 | break; | |
201 | case 8: | |
202 | { | |
203 | uint64_t v; | |
204 | ::decode(v, bl); | |
205 | val = v; | |
206 | } | |
207 | break; | |
208 | default: | |
209 | throw buffer::error(); | |
210 | } | |
211 | } | |
212 | ||
213 | struct rgw_bucket_entry_ver { | |
214 | int64_t pool; | |
215 | uint64_t epoch; | |
216 | ||
217 | rgw_bucket_entry_ver() : pool(-1), epoch(0) {} | |
218 | ||
219 | void encode(bufferlist &bl) const { | |
220 | ENCODE_START(1, 1, bl); | |
221 | ::encode_packed_val(pool, bl); | |
222 | ::encode_packed_val(epoch, bl); | |
223 | ENCODE_FINISH(bl); | |
224 | } | |
225 | void decode(bufferlist::iterator &bl) { | |
226 | DECODE_START(1, bl); | |
227 | ::decode_packed_val(pool, bl); | |
228 | ::decode_packed_val(epoch, bl); | |
229 | DECODE_FINISH(bl); | |
230 | } | |
231 | void dump(Formatter *f) const; | |
232 | void decode_json(JSONObj *obj); | |
233 | static void generate_test_instances(list<rgw_bucket_entry_ver*>& o); | |
234 | }; | |
235 | WRITE_CLASS_ENCODER(rgw_bucket_entry_ver) | |
236 | ||
237 | struct cls_rgw_obj_key { | |
238 | string name; | |
239 | string instance; | |
240 | ||
241 | cls_rgw_obj_key() {} | |
242 | cls_rgw_obj_key(const string &_name) : name(_name) {} | |
243 | cls_rgw_obj_key(const string& n, const string& i) : name(n), instance(i) {} | |
244 | ||
245 | void set(const string& _name) { | |
246 | name = _name; | |
247 | } | |
248 | ||
249 | bool operator==(const cls_rgw_obj_key& k) const { | |
250 | return (name.compare(k.name) == 0) && | |
251 | (instance.compare(k.instance) == 0); | |
252 | } | |
253 | bool operator<(const cls_rgw_obj_key& k) const { | |
254 | int r = name.compare(k.name); | |
255 | if (r == 0) { | |
256 | r = instance.compare(k.instance); | |
257 | } | |
258 | return (r < 0); | |
259 | } | |
260 | bool operator<=(const cls_rgw_obj_key& k) const { | |
261 | return !(k < *this); | |
262 | } | |
263 | bool empty() { | |
264 | return name.empty(); | |
265 | } | |
266 | void encode(bufferlist &bl) const { | |
267 | ENCODE_START(1, 1, bl); | |
268 | ::encode(name, bl); | |
269 | ::encode(instance, bl); | |
270 | ENCODE_FINISH(bl); | |
271 | } | |
272 | void decode(bufferlist::iterator &bl) { | |
273 | DECODE_START(1, bl); | |
274 | ::decode(name, bl); | |
275 | ::decode(instance, bl); | |
276 | DECODE_FINISH(bl); | |
277 | } | |
278 | void dump(Formatter *f) const { | |
279 | f->dump_string("name", name); | |
280 | f->dump_string("instance", instance); | |
281 | } | |
282 | void decode_json(JSONObj *obj); | |
283 | static void generate_test_instances(list<cls_rgw_obj_key*>& ls) { | |
284 | ls.push_back(new cls_rgw_obj_key); | |
285 | ls.push_back(new cls_rgw_obj_key); | |
286 | ls.back()->name = "name"; | |
287 | ls.back()->instance = "instance"; | |
288 | } | |
289 | }; | |
290 | WRITE_CLASS_ENCODER(cls_rgw_obj_key) | |
291 | ||
292 | ||
293 | #define RGW_BUCKET_DIRENT_FLAG_VER 0x1 /* a versioned object instance */ | |
294 | #define RGW_BUCKET_DIRENT_FLAG_CURRENT 0x2 /* the last object instance of a versioned object */ | |
295 | #define RGW_BUCKET_DIRENT_FLAG_DELETE_MARKER 0x4 /* delete marker */ | |
296 | #define RGW_BUCKET_DIRENT_FLAG_VER_MARKER 0x8 /* object is versioned, a placeholder for the plain entry */ | |
297 | ||
298 | struct rgw_bucket_dir_entry { | |
299 | cls_rgw_obj_key key; | |
300 | rgw_bucket_entry_ver ver; | |
301 | std::string locator; | |
302 | bool exists; | |
303 | struct rgw_bucket_dir_entry_meta meta; | |
304 | multimap<string, struct rgw_bucket_pending_info> pending_map; | |
305 | uint64_t index_ver; | |
306 | string tag; | |
307 | uint16_t flags; | |
308 | uint64_t versioned_epoch; | |
309 | ||
310 | rgw_bucket_dir_entry() : | |
311 | exists(false), index_ver(0), flags(0), versioned_epoch(0) {} | |
312 | ||
313 | void encode(bufferlist &bl) const { | |
314 | ENCODE_START(8, 3, bl); | |
315 | ::encode(key.name, bl); | |
316 | ::encode(ver.epoch, bl); | |
317 | ::encode(exists, bl); | |
318 | ::encode(meta, bl); | |
319 | ::encode(pending_map, bl); | |
320 | ::encode(locator, bl); | |
321 | ::encode(ver, bl); | |
322 | ::encode_packed_val(index_ver, bl); | |
323 | ::encode(tag, bl); | |
324 | ::encode(key.instance, bl); | |
325 | ::encode(flags, bl); | |
326 | ::encode(versioned_epoch, bl); | |
327 | ENCODE_FINISH(bl); | |
328 | } | |
329 | void decode(bufferlist::iterator &bl) { | |
330 | DECODE_START_LEGACY_COMPAT_LEN(8, 3, 3, bl); | |
331 | ::decode(key.name, bl); | |
332 | ::decode(ver.epoch, bl); | |
333 | ::decode(exists, bl); | |
334 | ::decode(meta, bl); | |
335 | ::decode(pending_map, bl); | |
336 | if (struct_v >= 2) { | |
337 | ::decode(locator, bl); | |
338 | } | |
339 | if (struct_v >= 4) { | |
340 | ::decode(ver, bl); | |
341 | } else { | |
342 | ver.pool = -1; | |
343 | } | |
344 | if (struct_v >= 5) { | |
345 | ::decode_packed_val(index_ver, bl); | |
346 | ::decode(tag, bl); | |
347 | } | |
348 | if (struct_v >= 6) { | |
349 | ::decode(key.instance, bl); | |
350 | } | |
351 | if (struct_v >= 7) { | |
352 | ::decode(flags, bl); | |
353 | } | |
354 | if (struct_v >= 8) { | |
355 | ::decode(versioned_epoch, bl); | |
356 | } | |
357 | DECODE_FINISH(bl); | |
358 | } | |
359 | ||
360 | bool is_current() { | |
361 | int test_flags = RGW_BUCKET_DIRENT_FLAG_VER | RGW_BUCKET_DIRENT_FLAG_CURRENT; | |
362 | return (flags & RGW_BUCKET_DIRENT_FLAG_VER) == 0 || | |
363 | (flags & test_flags) == test_flags; | |
364 | } | |
365 | bool is_delete_marker() { return (flags & RGW_BUCKET_DIRENT_FLAG_DELETE_MARKER) != 0; } | |
366 | bool is_visible() { | |
367 | return is_current() && !is_delete_marker(); | |
368 | } | |
369 | bool is_valid() { return (flags & RGW_BUCKET_DIRENT_FLAG_VER_MARKER) == 0; } | |
370 | ||
371 | void dump(Formatter *f) const; | |
372 | void decode_json(JSONObj *obj); | |
373 | static void generate_test_instances(list<rgw_bucket_dir_entry*>& o); | |
374 | }; | |
375 | WRITE_CLASS_ENCODER(rgw_bucket_dir_entry) | |
376 | ||
377 | enum BIIndexType { | |
378 | InvalidIdx = 0, | |
379 | PlainIdx = 1, | |
380 | InstanceIdx = 2, | |
381 | OLHIdx = 3, | |
382 | }; | |
383 | ||
384 | struct rgw_bucket_category_stats; | |
385 | ||
386 | struct rgw_cls_bi_entry { | |
387 | BIIndexType type; | |
388 | string idx; | |
389 | bufferlist data; | |
390 | ||
391 | rgw_cls_bi_entry() : type(InvalidIdx) {} | |
392 | ||
393 | void encode(bufferlist& bl) const { | |
394 | ENCODE_START(1, 1, bl); | |
395 | ::encode((uint8_t)type, bl); | |
396 | ::encode(idx, bl); | |
397 | ::encode(data, bl); | |
398 | ENCODE_FINISH(bl); | |
399 | } | |
400 | ||
401 | void decode(bufferlist::iterator& bl) { | |
402 | DECODE_START(1, bl); | |
403 | uint8_t c; | |
404 | ::decode(c, bl); | |
405 | type = (BIIndexType)c; | |
406 | ::decode(idx, bl); | |
407 | ::decode(data, bl); | |
408 | DECODE_FINISH(bl); | |
409 | } | |
410 | ||
411 | void dump(Formatter *f) const; | |
412 | void decode_json(JSONObj *obj, cls_rgw_obj_key *effective_key = NULL); | |
413 | ||
414 | bool get_info(cls_rgw_obj_key *key, uint8_t *category, rgw_bucket_category_stats *accounted_stats); | |
415 | }; | |
416 | WRITE_CLASS_ENCODER(rgw_cls_bi_entry) | |
417 | ||
418 | enum OLHLogOp { | |
419 | CLS_RGW_OLH_OP_UNKNOWN = 0, | |
420 | CLS_RGW_OLH_OP_LINK_OLH = 1, | |
421 | CLS_RGW_OLH_OP_UNLINK_OLH = 2, /* object does not exist */ | |
422 | CLS_RGW_OLH_OP_REMOVE_INSTANCE = 3, | |
423 | }; | |
424 | ||
425 | struct rgw_bucket_olh_log_entry { | |
426 | uint64_t epoch; | |
427 | OLHLogOp op; | |
428 | string op_tag; | |
429 | cls_rgw_obj_key key; | |
430 | bool delete_marker; | |
431 | ||
432 | rgw_bucket_olh_log_entry() : epoch(0), op(CLS_RGW_OLH_OP_UNKNOWN), delete_marker(false) {} | |
433 | ||
434 | ||
435 | void encode(bufferlist &bl) const { | |
436 | ENCODE_START(1, 1, bl); | |
437 | ::encode(epoch, bl); | |
438 | ::encode((__u8)op, bl); | |
439 | ::encode(op_tag, bl); | |
440 | ::encode(key, bl); | |
441 | ::encode(delete_marker, bl); | |
442 | ENCODE_FINISH(bl); | |
443 | } | |
444 | void decode(bufferlist::iterator &bl) { | |
445 | DECODE_START(1, bl); | |
446 | ::decode(epoch, bl); | |
447 | uint8_t c; | |
448 | ::decode(c, bl); | |
449 | op = (OLHLogOp)c; | |
450 | ::decode(op_tag, bl); | |
451 | ::decode(key, bl); | |
452 | ::decode(delete_marker, bl); | |
453 | DECODE_FINISH(bl); | |
454 | } | |
455 | static void generate_test_instances(list<rgw_bucket_olh_log_entry*>& o); | |
456 | void dump(Formatter *f) const; | |
457 | void decode_json(JSONObj *obj); | |
458 | }; | |
459 | WRITE_CLASS_ENCODER(rgw_bucket_olh_log_entry) | |
460 | ||
461 | struct rgw_bucket_olh_entry { | |
462 | cls_rgw_obj_key key; | |
463 | bool delete_marker; | |
464 | uint64_t epoch; | |
465 | map<uint64_t, vector<struct rgw_bucket_olh_log_entry> > pending_log; | |
466 | string tag; | |
467 | bool exists; | |
468 | bool pending_removal; | |
469 | ||
470 | rgw_bucket_olh_entry() : delete_marker(false), epoch(0), exists(false), pending_removal(false) {} | |
471 | ||
472 | void encode(bufferlist &bl) const { | |
473 | ENCODE_START(1, 1, bl); | |
474 | ::encode(key, bl); | |
475 | ::encode(delete_marker, bl); | |
476 | ::encode(epoch, bl); | |
477 | ::encode(pending_log, bl); | |
478 | ::encode(tag, bl); | |
479 | ::encode(exists, bl); | |
480 | ::encode(pending_removal, bl); | |
481 | ENCODE_FINISH(bl); | |
482 | } | |
483 | void decode(bufferlist::iterator &bl) { | |
484 | DECODE_START(1, bl); | |
485 | ::decode(key, bl); | |
486 | ::decode(delete_marker, bl); | |
487 | ::decode(epoch, bl); | |
488 | ::decode(pending_log, bl); | |
489 | ::decode(tag, bl); | |
490 | ::decode(exists, bl); | |
491 | ::decode(pending_removal, bl); | |
492 | DECODE_FINISH(bl); | |
493 | } | |
494 | void dump(Formatter *f) const; | |
495 | void decode_json(JSONObj *obj); | |
496 | }; | |
497 | WRITE_CLASS_ENCODER(rgw_bucket_olh_entry) | |
498 | ||
499 | struct rgw_bi_log_entry { | |
500 | string id; | |
501 | string object; | |
502 | string instance; | |
503 | ceph::real_time timestamp; | |
504 | rgw_bucket_entry_ver ver; | |
505 | RGWModifyOp op; | |
506 | RGWPendingState state; | |
507 | uint64_t index_ver; | |
508 | string tag; | |
509 | uint16_t bilog_flags; | |
510 | string owner; /* only being set if it's a delete marker */ | |
511 | string owner_display_name; /* only being set if it's a delete marker */ | |
31f18b77 | 512 | rgw_zone_set zones_trace; |
7c673cae FG |
513 | |
514 | rgw_bi_log_entry() : op(CLS_RGW_OP_UNKNOWN), state(CLS_RGW_STATE_PENDING_MODIFY), index_ver(0), bilog_flags(0) {} | |
515 | ||
516 | void encode(bufferlist &bl) const { | |
31f18b77 | 517 | ENCODE_START(4, 1, bl); |
7c673cae FG |
518 | ::encode(id, bl); |
519 | ::encode(object, bl); | |
520 | ::encode(timestamp, bl); | |
521 | ::encode(ver, bl); | |
522 | ::encode(tag, bl); | |
523 | uint8_t c = (uint8_t)op; | |
524 | ::encode(c, bl); | |
525 | c = (uint8_t)state; | |
526 | ::encode(c, bl); | |
527 | encode_packed_val(index_ver, bl); | |
528 | ::encode(instance, bl); | |
529 | ::encode(bilog_flags, bl); | |
530 | ::encode(owner, bl); | |
531 | ::encode(owner_display_name, bl); | |
31f18b77 | 532 | ::encode(zones_trace, bl); |
7c673cae FG |
533 | ENCODE_FINISH(bl); |
534 | } | |
535 | void decode(bufferlist::iterator &bl) { | |
31f18b77 | 536 | DECODE_START(4, bl); |
7c673cae FG |
537 | ::decode(id, bl); |
538 | ::decode(object, bl); | |
539 | ::decode(timestamp, bl); | |
540 | ::decode(ver, bl); | |
541 | ::decode(tag, bl); | |
542 | uint8_t c; | |
543 | ::decode(c, bl); | |
544 | op = (RGWModifyOp)c; | |
545 | ::decode(c, bl); | |
546 | state = (RGWPendingState)c; | |
547 | decode_packed_val(index_ver, bl); | |
548 | if (struct_v >= 2) { | |
549 | ::decode(instance, bl); | |
550 | ::decode(bilog_flags, bl); | |
551 | } | |
552 | if (struct_v >= 3) { | |
553 | ::decode(owner, bl); | |
554 | ::decode(owner_display_name, bl); | |
555 | } | |
31f18b77 FG |
556 | if (struct_v >= 4) { |
557 | ::decode(zones_trace, bl); | |
558 | } | |
7c673cae FG |
559 | DECODE_FINISH(bl); |
560 | } | |
561 | void dump(Formatter *f) const; | |
562 | void decode_json(JSONObj *obj); | |
563 | static void generate_test_instances(list<rgw_bi_log_entry*>& o); | |
564 | ||
565 | bool is_versioned() { | |
566 | return ((bilog_flags & RGW_BILOG_FLAG_VERSIONED_OP) != 0); | |
567 | } | |
568 | }; | |
569 | WRITE_CLASS_ENCODER(rgw_bi_log_entry) | |
570 | ||
571 | struct rgw_bucket_category_stats { | |
572 | uint64_t total_size; | |
573 | uint64_t total_size_rounded; | |
574 | uint64_t num_entries; | |
575 | uint64_t actual_size{0}; //< account for compression, encryption | |
576 | ||
577 | rgw_bucket_category_stats() : total_size(0), total_size_rounded(0), num_entries(0) {} | |
578 | ||
579 | void encode(bufferlist &bl) const { | |
580 | ENCODE_START(3, 2, bl); | |
581 | ::encode(total_size, bl); | |
582 | ::encode(total_size_rounded, bl); | |
583 | ::encode(num_entries, bl); | |
584 | ::encode(actual_size, bl); | |
585 | ENCODE_FINISH(bl); | |
586 | } | |
587 | void decode(bufferlist::iterator &bl) { | |
588 | DECODE_START_LEGACY_COMPAT_LEN(3, 2, 2, bl); | |
589 | ::decode(total_size, bl); | |
590 | ::decode(total_size_rounded, bl); | |
591 | ::decode(num_entries, bl); | |
592 | if (struct_v >= 3) { | |
593 | ::decode(actual_size, bl); | |
594 | } else { | |
595 | actual_size = total_size; | |
596 | } | |
597 | DECODE_FINISH(bl); | |
598 | } | |
599 | void dump(Formatter *f) const; | |
600 | static void generate_test_instances(list<rgw_bucket_category_stats*>& o); | |
601 | }; | |
602 | WRITE_CLASS_ENCODER(rgw_bucket_category_stats) | |
603 | ||
31f18b77 FG |
604 | enum cls_rgw_reshard_status { |
605 | CLS_RGW_RESHARD_NONE = 0, | |
606 | CLS_RGW_RESHARD_IN_PROGRESS = 1, | |
607 | CLS_RGW_RESHARD_DONE = 2, | |
608 | }; | |
609 | ||
610 | struct cls_rgw_bucket_instance_entry { | |
611 | cls_rgw_reshard_status reshard_status{CLS_RGW_RESHARD_NONE}; | |
612 | string new_bucket_instance_id; | |
613 | int32_t num_shards{-1}; | |
614 | ||
615 | void encode(bufferlist& bl) const { | |
616 | ENCODE_START(1, 1, bl); | |
617 | ::encode((uint8_t)reshard_status, bl); | |
618 | ::encode(new_bucket_instance_id, bl); | |
619 | ::encode(num_shards, bl); | |
620 | ENCODE_FINISH(bl); | |
621 | } | |
622 | ||
623 | void decode(bufferlist::iterator& bl) { | |
624 | DECODE_START(1, bl); | |
625 | uint8_t s; | |
626 | ::decode(s, bl); | |
627 | reshard_status = (cls_rgw_reshard_status)s; | |
628 | ::decode(new_bucket_instance_id, bl); | |
629 | ::decode(num_shards, bl); | |
630 | DECODE_FINISH(bl); | |
631 | } | |
632 | ||
633 | void dump(Formatter *f) const; | |
634 | static void generate_test_instances(list<cls_rgw_bucket_instance_entry*>& o); | |
635 | ||
636 | void clear() { | |
637 | reshard_status = CLS_RGW_RESHARD_NONE; | |
638 | new_bucket_instance_id.clear(); | |
639 | } | |
640 | ||
641 | void set_status(const string& new_instance_id, int32_t new_num_shards, cls_rgw_reshard_status s) { | |
642 | reshard_status = s; | |
643 | new_bucket_instance_id = new_instance_id; | |
644 | num_shards = new_num_shards; | |
645 | } | |
646 | ||
647 | bool resharding() const { | |
648 | return reshard_status != CLS_RGW_RESHARD_NONE; | |
649 | } | |
650 | bool resharding_in_progress() const { | |
651 | return reshard_status == CLS_RGW_RESHARD_IN_PROGRESS; | |
652 | } | |
653 | }; | |
654 | WRITE_CLASS_ENCODER(cls_rgw_bucket_instance_entry) | |
655 | ||
7c673cae FG |
656 | struct rgw_bucket_dir_header { |
657 | map<uint8_t, rgw_bucket_category_stats> stats; | |
658 | uint64_t tag_timeout; | |
659 | uint64_t ver; | |
660 | uint64_t master_ver; | |
661 | string max_marker; | |
31f18b77 | 662 | cls_rgw_bucket_instance_entry new_instance; |
7c673cae FG |
663 | |
664 | rgw_bucket_dir_header() : tag_timeout(0), ver(0), master_ver(0) {} | |
665 | ||
666 | void encode(bufferlist &bl) const { | |
31f18b77 | 667 | ENCODE_START(6, 2, bl); |
7c673cae FG |
668 | ::encode(stats, bl); |
669 | ::encode(tag_timeout, bl); | |
670 | ::encode(ver, bl); | |
671 | ::encode(master_ver, bl); | |
672 | ::encode(max_marker, bl); | |
31f18b77 | 673 | ::encode(new_instance, bl); |
7c673cae FG |
674 | ENCODE_FINISH(bl); |
675 | } | |
676 | void decode(bufferlist::iterator &bl) { | |
31f18b77 | 677 | DECODE_START_LEGACY_COMPAT_LEN(6, 2, 2, bl); |
7c673cae FG |
678 | ::decode(stats, bl); |
679 | if (struct_v > 2) { | |
680 | ::decode(tag_timeout, bl); | |
681 | } else { | |
682 | tag_timeout = 0; | |
683 | } | |
684 | if (struct_v >= 4) { | |
685 | ::decode(ver, bl); | |
686 | ::decode(master_ver, bl); | |
687 | } else { | |
688 | ver = 0; | |
689 | } | |
690 | if (struct_v >= 5) { | |
691 | ::decode(max_marker, bl); | |
692 | } | |
31f18b77 FG |
693 | if (struct_v >= 6) { |
694 | ::decode(new_instance, bl); | |
695 | } else { | |
696 | new_instance = cls_rgw_bucket_instance_entry(); | |
697 | } | |
7c673cae FG |
698 | DECODE_FINISH(bl); |
699 | } | |
700 | void dump(Formatter *f) const; | |
701 | static void generate_test_instances(list<rgw_bucket_dir_header*>& o); | |
31f18b77 FG |
702 | |
703 | bool resharding() const { | |
704 | return new_instance.resharding(); | |
705 | } | |
706 | bool resharding_in_progress() const { | |
707 | return new_instance.resharding_in_progress(); | |
708 | } | |
7c673cae FG |
709 | }; |
710 | WRITE_CLASS_ENCODER(rgw_bucket_dir_header) | |
711 | ||
712 | struct rgw_bucket_dir { | |
713 | struct rgw_bucket_dir_header header; | |
714 | std::map<string, struct rgw_bucket_dir_entry> m; | |
715 | ||
716 | void encode(bufferlist &bl) const { | |
717 | ENCODE_START(2, 2, bl); | |
718 | ::encode(header, bl); | |
719 | ::encode(m, bl); | |
720 | ENCODE_FINISH(bl); | |
721 | } | |
722 | void decode(bufferlist::iterator &bl) { | |
723 | DECODE_START_LEGACY_COMPAT_LEN(2, 2, 2, bl); | |
724 | ::decode(header, bl); | |
725 | ::decode(m, bl); | |
726 | DECODE_FINISH(bl); | |
727 | } | |
728 | void dump(Formatter *f) const; | |
729 | static void generate_test_instances(list<rgw_bucket_dir*>& o); | |
730 | }; | |
731 | WRITE_CLASS_ENCODER(rgw_bucket_dir) | |
732 | ||
733 | struct rgw_usage_data { | |
734 | uint64_t bytes_sent; | |
735 | uint64_t bytes_received; | |
736 | uint64_t ops; | |
737 | uint64_t successful_ops; | |
738 | ||
739 | rgw_usage_data() : bytes_sent(0), bytes_received(0), ops(0), successful_ops(0) {} | |
740 | rgw_usage_data(uint64_t sent, uint64_t received) : bytes_sent(sent), bytes_received(received), ops(0), successful_ops(0) {} | |
741 | ||
742 | void encode(bufferlist& bl) const { | |
743 | ENCODE_START(1, 1, bl); | |
744 | ::encode(bytes_sent, bl); | |
745 | ::encode(bytes_received, bl); | |
746 | ::encode(ops, bl); | |
747 | ::encode(successful_ops, bl); | |
748 | ENCODE_FINISH(bl); | |
749 | } | |
750 | ||
751 | void decode(bufferlist::iterator& bl) { | |
752 | DECODE_START(1, bl); | |
753 | ::decode(bytes_sent, bl); | |
754 | ::decode(bytes_received, bl); | |
755 | ::decode(ops, bl); | |
756 | ::decode(successful_ops, bl); | |
757 | DECODE_FINISH(bl); | |
758 | } | |
759 | ||
760 | void aggregate(const rgw_usage_data& usage) { | |
761 | bytes_sent += usage.bytes_sent; | |
762 | bytes_received += usage.bytes_received; | |
763 | ops += usage.ops; | |
764 | successful_ops += usage.successful_ops; | |
765 | } | |
766 | }; | |
767 | WRITE_CLASS_ENCODER(rgw_usage_data) | |
768 | ||
769 | ||
770 | struct rgw_usage_log_entry { | |
771 | rgw_user owner; | |
772 | rgw_user payer; /* if empty, same as owner */ | |
773 | string bucket; | |
774 | uint64_t epoch; | |
775 | rgw_usage_data total_usage; /* this one is kept for backwards compatibility */ | |
776 | map<string, rgw_usage_data> usage_map; | |
777 | ||
778 | rgw_usage_log_entry() : epoch(0) {} | |
779 | rgw_usage_log_entry(string& o, string& b) : owner(o), bucket(b), epoch(0) {} | |
780 | rgw_usage_log_entry(string& o, string& p, string& b) : owner(o), payer(p), bucket(b), epoch(0) {} | |
781 | ||
782 | void encode(bufferlist& bl) const { | |
783 | ENCODE_START(3, 1, bl); | |
784 | ::encode(owner.to_str(), bl); | |
785 | ::encode(bucket, bl); | |
786 | ::encode(epoch, bl); | |
787 | ::encode(total_usage.bytes_sent, bl); | |
788 | ::encode(total_usage.bytes_received, bl); | |
789 | ::encode(total_usage.ops, bl); | |
790 | ::encode(total_usage.successful_ops, bl); | |
791 | ::encode(usage_map, bl); | |
792 | ::encode(payer.to_str(), bl); | |
793 | ENCODE_FINISH(bl); | |
794 | } | |
795 | ||
796 | ||
797 | void decode(bufferlist::iterator& bl) { | |
798 | DECODE_START(3, bl); | |
799 | string s; | |
800 | ::decode(s, bl); | |
801 | owner.from_str(s); | |
802 | ::decode(bucket, bl); | |
803 | ::decode(epoch, bl); | |
804 | ::decode(total_usage.bytes_sent, bl); | |
805 | ::decode(total_usage.bytes_received, bl); | |
806 | ::decode(total_usage.ops, bl); | |
807 | ::decode(total_usage.successful_ops, bl); | |
808 | if (struct_v < 2) { | |
809 | usage_map[""] = total_usage; | |
810 | } else { | |
811 | ::decode(usage_map, bl); | |
812 | } | |
813 | if (struct_v >= 3) { | |
814 | string p; | |
815 | ::decode(p, bl); | |
816 | payer.from_str(p); | |
817 | } | |
818 | DECODE_FINISH(bl); | |
819 | } | |
820 | ||
821 | void aggregate(const rgw_usage_log_entry& e, map<string, bool> *categories = NULL) { | |
822 | if (owner.empty()) { | |
823 | owner = e.owner; | |
824 | bucket = e.bucket; | |
825 | epoch = e.epoch; | |
826 | payer = e.payer; | |
827 | } | |
828 | ||
829 | map<string, rgw_usage_data>::const_iterator iter; | |
830 | for (iter = e.usage_map.begin(); iter != e.usage_map.end(); ++iter) { | |
831 | if (!categories || !categories->size() || categories->count(iter->first)) { | |
832 | add(iter->first, iter->second); | |
833 | } | |
834 | } | |
835 | } | |
836 | ||
837 | void sum(rgw_usage_data& usage, map<string, bool>& categories) const { | |
838 | usage = rgw_usage_data(); | |
839 | for (map<string, rgw_usage_data>::const_iterator iter = usage_map.begin(); iter != usage_map.end(); ++iter) { | |
840 | if (!categories.size() || categories.count(iter->first)) { | |
841 | usage.aggregate(iter->second); | |
842 | } | |
843 | } | |
844 | } | |
845 | ||
846 | void add(const string& category, const rgw_usage_data& data) { | |
847 | usage_map[category].aggregate(data); | |
848 | total_usage.aggregate(data); | |
849 | } | |
850 | }; | |
851 | WRITE_CLASS_ENCODER(rgw_usage_log_entry) | |
852 | ||
853 | struct rgw_usage_log_info { | |
854 | vector<rgw_usage_log_entry> entries; | |
855 | ||
856 | void encode(bufferlist& bl) const { | |
857 | ENCODE_START(1, 1, bl); | |
858 | ::encode(entries, bl); | |
859 | ENCODE_FINISH(bl); | |
860 | } | |
861 | ||
862 | void decode(bufferlist::iterator& bl) { | |
863 | DECODE_START(1, bl); | |
864 | ::decode(entries, bl); | |
865 | DECODE_FINISH(bl); | |
866 | } | |
867 | ||
868 | rgw_usage_log_info() {} | |
869 | }; | |
870 | WRITE_CLASS_ENCODER(rgw_usage_log_info) | |
871 | ||
872 | struct rgw_user_bucket { | |
873 | string user; | |
874 | string bucket; | |
875 | ||
876 | rgw_user_bucket() {} | |
877 | rgw_user_bucket(const string& u, const string& b) : user(u), bucket(b) {} | |
878 | ||
879 | void encode(bufferlist& bl) const { | |
880 | ENCODE_START(1, 1, bl); | |
881 | ::encode(user, bl); | |
882 | ::encode(bucket, bl); | |
883 | ENCODE_FINISH(bl); | |
884 | } | |
885 | ||
886 | void decode(bufferlist::iterator& bl) { | |
887 | DECODE_START(1, bl); | |
888 | ::decode(user, bl); | |
889 | ::decode(bucket, bl); | |
890 | DECODE_FINISH(bl); | |
891 | } | |
892 | ||
893 | bool operator<(const rgw_user_bucket& ub2) const { | |
894 | int comp = user.compare(ub2.user); | |
895 | if (comp < 0) | |
896 | return true; | |
897 | else if (!comp) | |
898 | return bucket.compare(ub2.bucket) < 0; | |
899 | ||
900 | return false; | |
901 | } | |
902 | }; | |
903 | WRITE_CLASS_ENCODER(rgw_user_bucket) | |
904 | ||
905 | enum cls_rgw_gc_op { | |
906 | CLS_RGW_GC_DEL_OBJ, | |
907 | CLS_RGW_GC_DEL_BUCKET, | |
908 | }; | |
909 | ||
910 | struct cls_rgw_obj { | |
911 | string pool; | |
912 | cls_rgw_obj_key key; | |
913 | string loc; | |
914 | ||
915 | cls_rgw_obj() {} | |
916 | cls_rgw_obj(string& _p, cls_rgw_obj_key& _k) : pool(_p), key(_k) {} | |
917 | ||
918 | void encode(bufferlist& bl) const { | |
919 | ENCODE_START(2, 1, bl); | |
920 | ::encode(pool, bl); | |
921 | ::encode(key.name, bl); | |
922 | ::encode(loc, bl); | |
923 | ::encode(key, bl); | |
924 | ENCODE_FINISH(bl); | |
925 | } | |
926 | ||
927 | void decode(bufferlist::iterator& bl) { | |
928 | DECODE_START(2, bl); | |
929 | ::decode(pool, bl); | |
930 | ::decode(key.name, bl); | |
931 | ::decode(loc, bl); | |
932 | if (struct_v >= 2) { | |
933 | ::decode(key, bl); | |
934 | } | |
935 | DECODE_FINISH(bl); | |
936 | } | |
937 | ||
938 | void dump(Formatter *f) const { | |
939 | f->dump_string("pool", pool); | |
940 | f->dump_string("oid", key.name); | |
941 | f->dump_string("key", loc); | |
942 | f->dump_string("instance", key.instance); | |
943 | } | |
944 | static void generate_test_instances(list<cls_rgw_obj*>& ls) { | |
945 | ls.push_back(new cls_rgw_obj); | |
946 | ls.push_back(new cls_rgw_obj); | |
947 | ls.back()->pool = "mypool"; | |
948 | ls.back()->key.name = "myoid"; | |
949 | ls.back()->loc = "mykey"; | |
950 | } | |
951 | }; | |
952 | WRITE_CLASS_ENCODER(cls_rgw_obj) | |
953 | ||
954 | struct cls_rgw_obj_chain { | |
955 | list<cls_rgw_obj> objs; | |
956 | ||
957 | cls_rgw_obj_chain() {} | |
958 | ||
959 | void push_obj(const string& pool, const cls_rgw_obj_key& key, const string& loc) { | |
960 | cls_rgw_obj obj; | |
961 | obj.pool = pool; | |
962 | obj.key = key; | |
963 | obj.loc = loc; | |
964 | objs.push_back(obj); | |
965 | } | |
966 | ||
967 | void encode(bufferlist& bl) const { | |
968 | ENCODE_START(1, 1, bl); | |
969 | ::encode(objs, bl); | |
970 | ENCODE_FINISH(bl); | |
971 | } | |
972 | ||
973 | void decode(bufferlist::iterator& bl) { | |
974 | DECODE_START(1, bl); | |
975 | ::decode(objs, bl); | |
976 | DECODE_FINISH(bl); | |
977 | } | |
978 | ||
979 | void dump(Formatter *f) const { | |
980 | f->open_array_section("objs"); | |
981 | for (list<cls_rgw_obj>::const_iterator p = objs.begin(); p != objs.end(); ++p) { | |
982 | f->open_object_section("obj"); | |
983 | p->dump(f); | |
984 | f->close_section(); | |
985 | } | |
986 | f->close_section(); | |
987 | } | |
988 | static void generate_test_instances(list<cls_rgw_obj_chain*>& ls) { | |
989 | ls.push_back(new cls_rgw_obj_chain); | |
990 | } | |
991 | ||
992 | bool empty() { | |
993 | return objs.empty(); | |
994 | } | |
995 | }; | |
996 | WRITE_CLASS_ENCODER(cls_rgw_obj_chain) | |
997 | ||
998 | struct cls_rgw_gc_obj_info | |
999 | { | |
1000 | string tag; | |
1001 | cls_rgw_obj_chain chain; | |
1002 | ceph::real_time time; | |
1003 | ||
1004 | cls_rgw_gc_obj_info() {} | |
1005 | ||
1006 | void encode(bufferlist& bl) const { | |
1007 | ENCODE_START(1, 1, bl); | |
1008 | ::encode(tag, bl); | |
1009 | ::encode(chain, bl); | |
1010 | ::encode(time, bl); | |
1011 | ENCODE_FINISH(bl); | |
1012 | } | |
1013 | ||
1014 | void decode(bufferlist::iterator& bl) { | |
1015 | DECODE_START(1, bl); | |
1016 | ::decode(tag, bl); | |
1017 | ::decode(chain, bl); | |
1018 | ::decode(time, bl); | |
1019 | DECODE_FINISH(bl); | |
1020 | } | |
1021 | ||
1022 | void dump(Formatter *f) const { | |
1023 | f->dump_string("tag", tag); | |
1024 | f->open_object_section("chain"); | |
1025 | chain.dump(f); | |
1026 | f->close_section(); | |
1027 | f->dump_stream("time") << time; | |
1028 | } | |
1029 | static void generate_test_instances(list<cls_rgw_gc_obj_info*>& ls) { | |
1030 | ls.push_back(new cls_rgw_gc_obj_info); | |
1031 | ls.push_back(new cls_rgw_gc_obj_info); | |
1032 | ls.back()->tag = "footag"; | |
1033 | ceph_timespec ts{21, 32}; | |
1034 | ls.back()->time = ceph::real_clock::from_ceph_timespec(ts); | |
1035 | } | |
1036 | }; | |
1037 | WRITE_CLASS_ENCODER(cls_rgw_gc_obj_info) | |
1038 | ||
1039 | struct cls_rgw_lc_obj_head | |
1040 | { | |
1041 | time_t start_date; | |
1042 | string marker; | |
1043 | ||
1044 | cls_rgw_lc_obj_head() {} | |
1045 | ||
1046 | void encode(bufferlist& bl) const { | |
1047 | ENCODE_START(1, 1, bl); | |
1048 | uint64_t t = start_date; | |
1049 | ::encode(t, bl); | |
1050 | ::encode(marker, bl); | |
1051 | ENCODE_FINISH(bl); | |
1052 | } | |
1053 | ||
1054 | void decode(bufferlist::iterator& bl) { | |
1055 | DECODE_START(1, bl); | |
1056 | uint64_t t; | |
1057 | ::decode(t, bl); | |
1058 | start_date = static_cast<time_t>(t); | |
1059 | ::decode(marker, bl); | |
1060 | DECODE_FINISH(bl); | |
1061 | } | |
1062 | ||
1063 | }; | |
1064 | WRITE_CLASS_ENCODER(cls_rgw_lc_obj_head) | |
1065 | ||
31f18b77 FG |
1066 | struct cls_rgw_reshard_entry |
1067 | { | |
1068 | ceph::real_time time; | |
1069 | string tenant; | |
1070 | string bucket_name; | |
1071 | string bucket_id; | |
1072 | string new_instance_id; | |
1073 | uint32_t old_num_shards{0}; | |
1074 | uint32_t new_num_shards{0}; | |
1075 | ||
1076 | cls_rgw_reshard_entry() {} | |
1077 | ||
1078 | void encode(bufferlist& bl) const { | |
1079 | ENCODE_START(1, 1, bl); | |
1080 | ::encode(time, bl); | |
1081 | ::encode(tenant, bl); | |
1082 | ::encode(bucket_name, bl); | |
1083 | ::encode(bucket_id, bl); | |
1084 | ::encode(new_instance_id, bl); | |
1085 | ::encode(old_num_shards, bl); | |
1086 | ::encode(new_num_shards, bl); | |
1087 | ENCODE_FINISH(bl); | |
1088 | } | |
1089 | ||
1090 | void decode(bufferlist::iterator& bl) { | |
1091 | DECODE_START(1, bl); | |
1092 | ::decode(time, bl); | |
1093 | ::decode(tenant, bl); | |
1094 | ::decode(bucket_name, bl); | |
1095 | ::decode(bucket_id, bl); | |
1096 | ::decode(new_instance_id, bl); | |
1097 | ::decode(old_num_shards, bl); | |
1098 | ::decode(new_num_shards, bl); | |
1099 | DECODE_FINISH(bl); | |
1100 | } | |
1101 | ||
1102 | void dump(Formatter *f) const; | |
1103 | static void generate_test_instances(list<cls_rgw_reshard_entry*>& o); | |
1104 | ||
1105 | static void generate_key(const string& tenant, const string& bucket_name, string *key); | |
1106 | void get_key(string *key) const; | |
1107 | }; | |
1108 | WRITE_CLASS_ENCODER(cls_rgw_reshard_entry) | |
1109 | ||
7c673cae | 1110 | #endif |