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