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