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