]> git.proxmox.com Git - ceph.git/blob - ceph/src/librbd/journal/Types.cc
import 15.2.0 Octopus source
[ceph.git] / ceph / src / librbd / journal / Types.cc
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
3
4 #include "librbd/journal/Types.h"
5 #include "include/ceph_assert.h"
6 #include "include/stringify.h"
7 #include "include/types.h"
8 #include "common/Formatter.h"
9
10 namespace librbd {
11 namespace journal {
12
13 using ceph::encode;
14 using ceph::decode;
15
16 namespace {
17
18 template <typename E>
19 class GetTypeVisitor : public boost::static_visitor<E> {
20 public:
21 template <typename T>
22 inline E operator()(const T&) const {
23 return T::TYPE;
24 }
25 };
26
27 class EncodeVisitor : public boost::static_visitor<void> {
28 public:
29 explicit EncodeVisitor(bufferlist &bl) : m_bl(bl) {
30 }
31
32 template <typename T>
33 inline void operator()(const T& t) const {
34 encode(static_cast<uint32_t>(T::TYPE), m_bl);
35 t.encode(m_bl);
36 }
37 private:
38 bufferlist &m_bl;
39 };
40
41 class DecodeVisitor : public boost::static_visitor<void> {
42 public:
43 DecodeVisitor(__u8 version, bufferlist::const_iterator &iter)
44 : m_version(version), m_iter(iter) {
45 }
46
47 template <typename T>
48 inline void operator()(T& t) const {
49 t.decode(m_version, m_iter);
50 }
51 private:
52 __u8 m_version;
53 bufferlist::const_iterator &m_iter;
54 };
55
56 class DumpVisitor : public boost::static_visitor<void> {
57 public:
58 explicit DumpVisitor(Formatter *formatter, const std::string &key)
59 : m_formatter(formatter), m_key(key) {}
60
61 template <typename T>
62 inline void operator()(const T& t) const {
63 auto type = T::TYPE;
64 m_formatter->dump_string(m_key.c_str(), stringify(type));
65 t.dump(m_formatter);
66 }
67 private:
68 ceph::Formatter *m_formatter;
69 std::string m_key;
70 };
71
72 } // anonymous namespace
73
74 void AioDiscardEvent::encode(bufferlist& bl) const {
75 using ceph::encode;
76 encode(offset, bl);
77 encode(length, bl);
78 bool skip_partial_discard = (discard_granularity_bytes > 0);
79 encode(skip_partial_discard, bl);
80 encode(discard_granularity_bytes, bl);
81 }
82
83 void AioDiscardEvent::decode(__u8 version, bufferlist::const_iterator& it) {
84 using ceph::decode;
85 decode(offset, it);
86 decode(length, it);
87
88 bool skip_partial_discard = false;
89 if (version >= 4) {
90 decode(skip_partial_discard, it);
91 }
92
93 if (version >= 5) {
94 decode(discard_granularity_bytes, it);
95 } else {
96 if (skip_partial_discard) {
97 // use a size larger than the maximum object size which will
98 // truncated down to object size during IO processing
99 discard_granularity_bytes = std::numeric_limits<uint32_t>::max();
100 } else {
101 discard_granularity_bytes = 0;
102 }
103 }
104 }
105
106 void AioDiscardEvent::dump(Formatter *f) const {
107 f->dump_unsigned("offset", offset);
108 f->dump_unsigned("length", length);
109 f->dump_unsigned("discard_granularity_bytes", discard_granularity_bytes);
110 }
111
112 uint32_t AioWriteEvent::get_fixed_size() {
113 return EventEntry::get_fixed_size() + 16 /* offset, length */;
114 }
115
116 void AioWriteEvent::encode(bufferlist& bl) const {
117 using ceph::encode;
118 encode(offset, bl);
119 encode(length, bl);
120 encode(data, bl);
121 }
122
123 void AioWriteEvent::decode(__u8 version, bufferlist::const_iterator& it) {
124 using ceph::decode;
125 decode(offset, it);
126 decode(length, it);
127 decode(data, it);
128 }
129
130 void AioWriteEvent::dump(Formatter *f) const {
131 f->dump_unsigned("offset", offset);
132 f->dump_unsigned("length", length);
133 }
134
135 void AioWriteSameEvent::encode(bufferlist& bl) const {
136 using ceph::encode;
137 encode(offset, bl);
138 encode(length, bl);
139 encode(data, bl);
140 }
141
142 void AioWriteSameEvent::decode(__u8 version, bufferlist::const_iterator& it) {
143 using ceph::decode;
144 decode(offset, it);
145 decode(length, it);
146 decode(data, it);
147 }
148
149 void AioWriteSameEvent::dump(Formatter *f) const {
150 f->dump_unsigned("offset", offset);
151 f->dump_unsigned("length", length);
152 }
153
154 uint32_t AioCompareAndWriteEvent::get_fixed_size() {
155 return EventEntry::get_fixed_size() + 32 /* offset, length */;
156 }
157
158 void AioCompareAndWriteEvent::encode(bufferlist& bl) const {
159 using ceph::encode;
160 encode(offset, bl);
161 encode(length, bl);
162 encode(cmp_data, bl);
163 encode(write_data, bl);
164 }
165
166 void AioCompareAndWriteEvent::decode(__u8 version, bufferlist::const_iterator& it) {
167 using ceph::decode;
168 decode(offset, it);
169 decode(length, it);
170 decode(cmp_data, it);
171 decode(write_data, it);
172 }
173
174 void AioCompareAndWriteEvent::dump(Formatter *f) const {
175 f->dump_unsigned("offset", offset);
176 f->dump_unsigned("length", length);
177 }
178
179 void AioFlushEvent::encode(bufferlist& bl) const {
180 }
181
182 void AioFlushEvent::decode(__u8 version, bufferlist::const_iterator& it) {
183 }
184
185 void AioFlushEvent::dump(Formatter *f) const {
186 }
187
188 void OpEventBase::encode(bufferlist& bl) const {
189 using ceph::encode;
190 encode(op_tid, bl);
191 }
192
193 void OpEventBase::decode(__u8 version, bufferlist::const_iterator& it) {
194 using ceph::decode;
195 decode(op_tid, it);
196 }
197
198 void OpEventBase::dump(Formatter *f) const {
199 f->dump_unsigned("op_tid", op_tid);
200 }
201
202 void OpFinishEvent::encode(bufferlist& bl) const {
203 OpEventBase::encode(bl);
204 using ceph::encode;
205 encode(op_tid, bl);
206 encode(r, bl);
207 }
208
209 void OpFinishEvent::decode(__u8 version, bufferlist::const_iterator& it) {
210 OpEventBase::decode(version, it);
211 using ceph::decode;
212 decode(op_tid, it);
213 decode(r, it);
214 }
215
216 void OpFinishEvent::dump(Formatter *f) const {
217 OpEventBase::dump(f);
218 f->dump_unsigned("op_tid", op_tid);
219 f->dump_int("result", r);
220 }
221
222 void SnapEventBase::encode(bufferlist& bl) const {
223 using ceph::encode;
224 OpEventBase::encode(bl);
225 encode(snap_name, bl);
226 encode(snap_namespace, bl);
227 }
228
229 void SnapEventBase::decode(__u8 version, bufferlist::const_iterator& it) {
230 using ceph::decode;
231 OpEventBase::decode(version, it);
232 using ceph::decode;
233 decode(snap_name, it);
234 if (version >= 4) {
235 decode(snap_namespace, it);
236 }
237 }
238
239 void SnapEventBase::dump(Formatter *f) const {
240 OpEventBase::dump(f);
241 f->dump_string("snap_name", snap_name);
242 snap_namespace.dump(f);
243 }
244
245 void SnapCreateEvent::encode(bufferlist &bl) const {
246 SnapEventBase::encode(bl);
247 }
248
249 void SnapCreateEvent::decode(__u8 version, bufferlist::const_iterator& it) {
250 using ceph::decode;
251 SnapEventBase::decode(version, it);
252 if (version == 3) {
253 decode(snap_namespace, it);
254 }
255 }
256
257 void SnapCreateEvent::dump(Formatter *f) const {
258 SnapEventBase::dump(f);
259 }
260
261 void SnapLimitEvent::encode(bufferlist &bl) const {
262 OpEventBase::encode(bl);
263 using ceph::encode;
264 encode(limit, bl);
265 }
266
267 void SnapLimitEvent::decode(__u8 version, bufferlist::const_iterator& it) {
268 OpEventBase::decode(version, it);
269 using ceph::decode;
270 decode(limit, it);
271 }
272
273 void SnapLimitEvent::dump(Formatter *f) const {
274 OpEventBase::dump(f);
275 f->dump_unsigned("limit", limit);
276 }
277
278 void SnapRenameEvent::encode(bufferlist& bl) const {
279 OpEventBase::encode(bl);
280 using ceph::encode;
281 encode(dst_snap_name, bl);
282 encode(snap_id, bl);
283 encode(src_snap_name, bl);
284 }
285
286 void SnapRenameEvent::decode(__u8 version, bufferlist::const_iterator& it) {
287 using ceph::decode;
288 OpEventBase::decode(version, it);
289 decode(dst_snap_name, it);
290 decode(snap_id, it);
291 if (version >= 2) {
292 decode(src_snap_name, it);
293 }
294 }
295
296 void SnapRenameEvent::dump(Formatter *f) const {
297 OpEventBase::dump(f);
298 f->dump_unsigned("src_snap_id", snap_id);
299 f->dump_string("src_snap_name", src_snap_name);
300 f->dump_string("dest_snap_name", dst_snap_name);
301 }
302
303 void RenameEvent::encode(bufferlist& bl) const {
304 OpEventBase::encode(bl);
305 using ceph::encode;
306 encode(image_name, bl);
307 }
308
309 void RenameEvent::decode(__u8 version, bufferlist::const_iterator& it) {
310 OpEventBase::decode(version, it);
311 using ceph::decode;
312 decode(image_name, it);
313 }
314
315 void RenameEvent::dump(Formatter *f) const {
316 OpEventBase::dump(f);
317 f->dump_string("image_name", image_name);
318 }
319
320 void ResizeEvent::encode(bufferlist& bl) const {
321 OpEventBase::encode(bl);
322 using ceph::encode;
323 encode(size, bl);
324 }
325
326 void ResizeEvent::decode(__u8 version, bufferlist::const_iterator& it) {
327 OpEventBase::decode(version, it);
328 using ceph::decode;
329 decode(size, it);
330 }
331
332 void ResizeEvent::dump(Formatter *f) const {
333 OpEventBase::dump(f);
334 f->dump_unsigned("size", size);
335 }
336
337 void DemotePromoteEvent::encode(bufferlist& bl) const {
338 }
339
340 void DemotePromoteEvent::decode(__u8 version, bufferlist::const_iterator& it) {
341 }
342
343 void DemotePromoteEvent::dump(Formatter *f) const {
344 }
345
346 void UpdateFeaturesEvent::encode(bufferlist& bl) const {
347 OpEventBase::encode(bl);
348 using ceph::encode;
349 encode(features, bl);
350 encode(enabled, bl);
351 }
352
353 void UpdateFeaturesEvent::decode(__u8 version, bufferlist::const_iterator& it) {
354 OpEventBase::decode(version, it);
355 using ceph::decode;
356 decode(features, it);
357 decode(enabled, it);
358 }
359
360 void UpdateFeaturesEvent::dump(Formatter *f) const {
361 OpEventBase::dump(f);
362 f->dump_unsigned("features", features);
363 f->dump_bool("enabled", enabled);
364 }
365
366 void MetadataSetEvent::encode(bufferlist& bl) const {
367 OpEventBase::encode(bl);
368 using ceph::encode;
369 encode(key, bl);
370 encode(value, bl);
371 }
372
373 void MetadataSetEvent::decode(__u8 version, bufferlist::const_iterator& it) {
374 OpEventBase::decode(version, it);
375 using ceph::decode;
376 decode(key, it);
377 decode(value, it);
378 }
379
380 void MetadataSetEvent::dump(Formatter *f) const {
381 OpEventBase::dump(f);
382 f->dump_string("key", key);
383 f->dump_string("value", value);
384 }
385
386 void MetadataRemoveEvent::encode(bufferlist& bl) const {
387 OpEventBase::encode(bl);
388 using ceph::encode;
389 encode(key, bl);
390 }
391
392 void MetadataRemoveEvent::decode(__u8 version, bufferlist::const_iterator& it) {
393 OpEventBase::decode(version, it);
394 using ceph::decode;
395 decode(key, it);
396 }
397
398 void MetadataRemoveEvent::dump(Formatter *f) const {
399 OpEventBase::dump(f);
400 f->dump_string("key", key);
401 }
402
403 void UnknownEvent::encode(bufferlist& bl) const {
404 ceph_abort();
405 }
406
407 void UnknownEvent::decode(__u8 version, bufferlist::const_iterator& it) {
408 }
409
410 void UnknownEvent::dump(Formatter *f) const {
411 }
412
413 EventType EventEntry::get_event_type() const {
414 return boost::apply_visitor(GetTypeVisitor<EventType>(), event);
415 }
416
417 void EventEntry::encode(bufferlist& bl) const {
418 ENCODE_START(5, 1, bl);
419 boost::apply_visitor(EncodeVisitor(bl), event);
420 ENCODE_FINISH(bl);
421 encode_metadata(bl);
422 }
423
424 void EventEntry::decode(bufferlist::const_iterator& it) {
425 DECODE_START(1, it);
426
427 uint32_t event_type;
428 decode(event_type, it);
429
430 // select the correct payload variant based upon the encoded op
431 switch (event_type) {
432 case EVENT_TYPE_AIO_DISCARD:
433 event = AioDiscardEvent();
434 break;
435 case EVENT_TYPE_AIO_WRITE:
436 event = AioWriteEvent();
437 break;
438 case EVENT_TYPE_AIO_FLUSH:
439 event = AioFlushEvent();
440 break;
441 case EVENT_TYPE_OP_FINISH:
442 event = OpFinishEvent();
443 break;
444 case EVENT_TYPE_SNAP_CREATE:
445 event = SnapCreateEvent();
446 break;
447 case EVENT_TYPE_SNAP_REMOVE:
448 event = SnapRemoveEvent();
449 break;
450 case EVENT_TYPE_SNAP_RENAME:
451 event = SnapRenameEvent();
452 break;
453 case EVENT_TYPE_SNAP_PROTECT:
454 event = SnapProtectEvent();
455 break;
456 case EVENT_TYPE_SNAP_UNPROTECT:
457 event = SnapUnprotectEvent();
458 break;
459 case EVENT_TYPE_SNAP_ROLLBACK:
460 event = SnapRollbackEvent();
461 break;
462 case EVENT_TYPE_RENAME:
463 event = RenameEvent();
464 break;
465 case EVENT_TYPE_RESIZE:
466 event = ResizeEvent();
467 break;
468 case EVENT_TYPE_FLATTEN:
469 event = FlattenEvent();
470 break;
471 case EVENT_TYPE_DEMOTE_PROMOTE:
472 event = DemotePromoteEvent();
473 break;
474 case EVENT_TYPE_SNAP_LIMIT:
475 event = SnapLimitEvent();
476 break;
477 case EVENT_TYPE_UPDATE_FEATURES:
478 event = UpdateFeaturesEvent();
479 break;
480 case EVENT_TYPE_METADATA_SET:
481 event = MetadataSetEvent();
482 break;
483 case EVENT_TYPE_METADATA_REMOVE:
484 event = MetadataRemoveEvent();
485 break;
486 case EVENT_TYPE_AIO_WRITESAME:
487 event = AioWriteSameEvent();
488 break;
489 case EVENT_TYPE_AIO_COMPARE_AND_WRITE:
490 event = AioCompareAndWriteEvent();
491 break;
492 default:
493 event = UnknownEvent();
494 break;
495 }
496
497 boost::apply_visitor(DecodeVisitor(struct_v, it), event);
498 DECODE_FINISH(it);
499 if (struct_v >= 4) {
500 decode_metadata(it);
501 }
502 }
503
504 void EventEntry::dump(Formatter *f) const {
505 boost::apply_visitor(DumpVisitor(f, "event_type"), event);
506 f->dump_stream("timestamp") << timestamp;
507 }
508
509 void EventEntry::encode_metadata(bufferlist& bl) const {
510 ENCODE_START(1, 1, bl);
511 encode(timestamp, bl);
512 ENCODE_FINISH(bl);
513 }
514
515 void EventEntry::decode_metadata(bufferlist::const_iterator& it) {
516 DECODE_START(1, it);
517 decode(timestamp, it);
518 DECODE_FINISH(it);
519 }
520
521 void EventEntry::generate_test_instances(std::list<EventEntry *> &o) {
522 o.push_back(new EventEntry(AioDiscardEvent()));
523 o.push_back(new EventEntry(AioDiscardEvent(123, 345, 4096), utime_t(1, 1)));
524
525 bufferlist bl;
526 bl.append(std::string(32, '1'));
527 o.push_back(new EventEntry(AioWriteEvent()));
528 o.push_back(new EventEntry(AioWriteEvent(123, 456, bl), utime_t(1, 1)));
529
530 o.push_back(new EventEntry(AioFlushEvent()));
531
532 o.push_back(new EventEntry(OpFinishEvent(123, -1), utime_t(1, 1)));
533
534 o.push_back(new EventEntry(SnapCreateEvent(), utime_t(1, 1)));
535 o.push_back(new EventEntry(SnapCreateEvent(234, cls::rbd::UserSnapshotNamespace(), "snap"), utime_t(1, 1)));
536
537 o.push_back(new EventEntry(SnapRemoveEvent()));
538 o.push_back(new EventEntry(SnapRemoveEvent(345, cls::rbd::UserSnapshotNamespace(), "snap"), utime_t(1, 1)));
539
540 o.push_back(new EventEntry(SnapRenameEvent()));
541 o.push_back(new EventEntry(SnapRenameEvent(456, 1, "src snap", "dest snap"),
542 utime_t(1, 1)));
543
544 o.push_back(new EventEntry(SnapProtectEvent()));
545 o.push_back(new EventEntry(SnapProtectEvent(567, cls::rbd::UserSnapshotNamespace(), "snap"), utime_t(1, 1)));
546
547 o.push_back(new EventEntry(SnapUnprotectEvent()));
548 o.push_back(new EventEntry(SnapUnprotectEvent(678, cls::rbd::UserSnapshotNamespace(), "snap"), utime_t(1, 1)));
549
550 o.push_back(new EventEntry(SnapRollbackEvent()));
551 o.push_back(new EventEntry(SnapRollbackEvent(789, cls::rbd::UserSnapshotNamespace(), "snap"), utime_t(1, 1)));
552
553 o.push_back(new EventEntry(RenameEvent()));
554 o.push_back(new EventEntry(RenameEvent(890, "image name"), utime_t(1, 1)));
555
556 o.push_back(new EventEntry(ResizeEvent()));
557 o.push_back(new EventEntry(ResizeEvent(901, 1234), utime_t(1, 1)));
558
559 o.push_back(new EventEntry(FlattenEvent(123), utime_t(1, 1)));
560
561 o.push_back(new EventEntry(DemotePromoteEvent()));
562
563 o.push_back(new EventEntry(UpdateFeaturesEvent()));
564 o.push_back(new EventEntry(UpdateFeaturesEvent(123, 127, true), utime_t(1, 1)));
565
566 o.push_back(new EventEntry(MetadataSetEvent()));
567 o.push_back(new EventEntry(MetadataSetEvent(123, "key", "value"), utime_t(1, 1)));
568
569 o.push_back(new EventEntry(MetadataRemoveEvent()));
570 o.push_back(new EventEntry(MetadataRemoveEvent(123, "key"), utime_t(1, 1)));
571 }
572
573 // Journal Client
574
575 void ImageClientMeta::encode(bufferlist& bl) const {
576 using ceph::encode;
577 encode(tag_class, bl);
578 encode(resync_requested, bl);
579 }
580
581 void ImageClientMeta::decode(__u8 version, bufferlist::const_iterator& it) {
582 using ceph::decode;
583 decode(tag_class, it);
584 decode(resync_requested, it);
585 }
586
587 void ImageClientMeta::dump(Formatter *f) const {
588 f->dump_unsigned("tag_class", tag_class);
589 f->dump_bool("resync_requested", resync_requested);
590 }
591
592 void MirrorPeerSyncPoint::encode(bufferlist& bl) const {
593 using ceph::encode;
594 encode(snap_name, bl);
595 encode(from_snap_name, bl);
596 encode(object_number, bl);
597 encode(snap_namespace, bl);
598 }
599
600 void MirrorPeerSyncPoint::decode(__u8 version, bufferlist::const_iterator& it) {
601 using ceph::decode;
602 decode(snap_name, it);
603 decode(from_snap_name, it);
604 decode(object_number, it);
605 if (version >= 2) {
606 decode(snap_namespace, it);
607 }
608 }
609
610 void MirrorPeerSyncPoint::dump(Formatter *f) const {
611 f->dump_string("snap_name", snap_name);
612 f->dump_string("from_snap_name", from_snap_name);
613 if (object_number) {
614 f->dump_unsigned("object_number", *object_number);
615 }
616 snap_namespace.dump(f);
617 }
618
619 void MirrorPeerClientMeta::encode(bufferlist& bl) const {
620 using ceph::encode;
621 encode(image_id, bl);
622 encode(static_cast<uint32_t>(state), bl);
623 encode(sync_object_count, bl);
624 encode(static_cast<uint32_t>(sync_points.size()), bl);
625 for (auto &sync_point : sync_points) {
626 sync_point.encode(bl);
627 }
628 encode(snap_seqs, bl);
629 }
630
631 void MirrorPeerClientMeta::decode(__u8 version, bufferlist::const_iterator& it) {
632 using ceph::decode;
633 decode(image_id, it);
634
635 uint32_t decode_state;
636 decode(decode_state, it);
637 state = static_cast<MirrorPeerState>(decode_state);
638
639 decode(sync_object_count, it);
640
641 uint32_t sync_point_count;
642 decode(sync_point_count, it);
643 sync_points.resize(sync_point_count);
644 for (auto &sync_point : sync_points) {
645 sync_point.decode(version, it);
646 }
647
648 decode(snap_seqs, it);
649 }
650
651 void MirrorPeerClientMeta::dump(Formatter *f) const {
652 f->dump_string("image_id", image_id);
653 f->dump_stream("state") << state;
654 f->dump_unsigned("sync_object_count", sync_object_count);
655 f->open_array_section("sync_points");
656 for (auto &sync_point : sync_points) {
657 f->open_object_section("sync_point");
658 sync_point.dump(f);
659 f->close_section();
660 }
661 f->close_section();
662 f->open_array_section("snap_seqs");
663 for (auto &pair : snap_seqs) {
664 f->open_object_section("snap_seq");
665 f->dump_unsigned("local_snap_seq", pair.first);
666 f->dump_unsigned("peer_snap_seq", pair.second);
667 f->close_section();
668 }
669 f->close_section();
670 }
671
672 void CliClientMeta::encode(bufferlist& bl) const {
673 }
674
675 void CliClientMeta::decode(__u8 version, bufferlist::const_iterator& it) {
676 }
677
678 void CliClientMeta::dump(Formatter *f) const {
679 }
680
681 void UnknownClientMeta::encode(bufferlist& bl) const {
682 ceph_abort();
683 }
684
685 void UnknownClientMeta::decode(__u8 version, bufferlist::const_iterator& it) {
686 }
687
688 void UnknownClientMeta::dump(Formatter *f) const {
689 }
690
691 ClientMetaType ClientData::get_client_meta_type() const {
692 return boost::apply_visitor(GetTypeVisitor<ClientMetaType>(), client_meta);
693 }
694
695 void ClientData::encode(bufferlist& bl) const {
696 ENCODE_START(2, 1, bl);
697 boost::apply_visitor(EncodeVisitor(bl), client_meta);
698 ENCODE_FINISH(bl);
699 }
700
701 void ClientData::decode(bufferlist::const_iterator& it) {
702 DECODE_START(1, it);
703
704 uint32_t client_meta_type;
705 decode(client_meta_type, it);
706
707 // select the correct payload variant based upon the encoded op
708 switch (client_meta_type) {
709 case IMAGE_CLIENT_META_TYPE:
710 client_meta = ImageClientMeta();
711 break;
712 case MIRROR_PEER_CLIENT_META_TYPE:
713 client_meta = MirrorPeerClientMeta();
714 break;
715 case CLI_CLIENT_META_TYPE:
716 client_meta = CliClientMeta();
717 break;
718 default:
719 client_meta = UnknownClientMeta();
720 break;
721 }
722
723 boost::apply_visitor(DecodeVisitor(struct_v, it), client_meta);
724 DECODE_FINISH(it);
725 }
726
727 void ClientData::dump(Formatter *f) const {
728 boost::apply_visitor(DumpVisitor(f, "client_meta_type"), client_meta);
729 }
730
731 void ClientData::generate_test_instances(std::list<ClientData *> &o) {
732 o.push_back(new ClientData(ImageClientMeta()));
733 o.push_back(new ClientData(ImageClientMeta(123)));
734 o.push_back(new ClientData(MirrorPeerClientMeta()));
735 o.push_back(new ClientData(MirrorPeerClientMeta("image_id",
736 {{{}, "snap 2", "snap 1", 123}},
737 {{1, 2}, {3, 4}})));
738 o.push_back(new ClientData(CliClientMeta()));
739 }
740
741 // Journal Tag
742
743 void TagPredecessor::encode(bufferlist& bl) const {
744 using ceph::encode;
745 encode(mirror_uuid, bl);
746 encode(commit_valid, bl);
747 encode(tag_tid, bl);
748 encode(entry_tid, bl);
749 }
750
751 void TagPredecessor::decode(bufferlist::const_iterator& it) {
752 using ceph::decode;
753 decode(mirror_uuid, it);
754 decode(commit_valid, it);
755 decode(tag_tid, it);
756 decode(entry_tid, it);
757 }
758
759 void TagPredecessor::dump(Formatter *f) const {
760 f->dump_string("mirror_uuid", mirror_uuid);
761 f->dump_string("commit_valid", commit_valid ? "true" : "false");
762 f->dump_unsigned("tag_tid", tag_tid);
763 f->dump_unsigned("entry_tid", entry_tid);
764 }
765
766 void TagData::encode(bufferlist& bl) const {
767 using ceph::encode;
768 encode(mirror_uuid, bl);
769 predecessor.encode(bl);
770 }
771
772 void TagData::decode(bufferlist::const_iterator& it) {
773 using ceph::decode;
774 decode(mirror_uuid, it);
775 predecessor.decode(it);
776 }
777
778 void TagData::dump(Formatter *f) const {
779 f->dump_string("mirror_uuid", mirror_uuid);
780 f->open_object_section("predecessor");
781 predecessor.dump(f);
782 f->close_section();
783 }
784
785 void TagData::generate_test_instances(std::list<TagData *> &o) {
786 o.push_back(new TagData());
787 o.push_back(new TagData("mirror-uuid"));
788 o.push_back(new TagData("mirror-uuid", "remote-mirror-uuid", true, 123, 234));
789 }
790
791 std::ostream &operator<<(std::ostream &out, const EventType &type) {
792 using namespace librbd::journal;
793
794 switch (type) {
795 case EVENT_TYPE_AIO_DISCARD:
796 out << "AioDiscard";
797 break;
798 case EVENT_TYPE_AIO_WRITE:
799 out << "AioWrite";
800 break;
801 case EVENT_TYPE_AIO_FLUSH:
802 out << "AioFlush";
803 break;
804 case EVENT_TYPE_OP_FINISH:
805 out << "OpFinish";
806 break;
807 case EVENT_TYPE_SNAP_CREATE:
808 out << "SnapCreate";
809 break;
810 case EVENT_TYPE_SNAP_REMOVE:
811 out << "SnapRemove";
812 break;
813 case EVENT_TYPE_SNAP_RENAME:
814 out << "SnapRename";
815 break;
816 case EVENT_TYPE_SNAP_PROTECT:
817 out << "SnapProtect";
818 break;
819 case EVENT_TYPE_SNAP_UNPROTECT:
820 out << "SnapUnprotect";
821 break;
822 case EVENT_TYPE_SNAP_ROLLBACK:
823 out << "SnapRollback";
824 break;
825 case EVENT_TYPE_RENAME:
826 out << "Rename";
827 break;
828 case EVENT_TYPE_RESIZE:
829 out << "Resize";
830 break;
831 case EVENT_TYPE_FLATTEN:
832 out << "Flatten";
833 break;
834 case EVENT_TYPE_DEMOTE_PROMOTE:
835 out << "Demote/Promote";
836 break;
837 case EVENT_TYPE_SNAP_LIMIT:
838 out << "SnapLimit";
839 break;
840 case EVENT_TYPE_UPDATE_FEATURES:
841 out << "UpdateFeatures";
842 break;
843 case EVENT_TYPE_METADATA_SET:
844 out << "MetadataSet";
845 break;
846 case EVENT_TYPE_METADATA_REMOVE:
847 out << "MetadataRemove";
848 break;
849 case EVENT_TYPE_AIO_WRITESAME:
850 out << "AioWriteSame";
851 break;
852 case EVENT_TYPE_AIO_COMPARE_AND_WRITE:
853 out << "AioCompareAndWrite";
854 break;
855 default:
856 out << "Unknown (" << static_cast<uint32_t>(type) << ")";
857 break;
858 }
859 return out;
860 }
861
862 std::ostream &operator<<(std::ostream &out, const ClientMetaType &type) {
863 using namespace librbd::journal;
864
865 switch (type) {
866 case IMAGE_CLIENT_META_TYPE:
867 out << "Master Image";
868 break;
869 case MIRROR_PEER_CLIENT_META_TYPE:
870 out << "Mirror Peer";
871 break;
872 case CLI_CLIENT_META_TYPE:
873 out << "CLI Tool";
874 break;
875 default:
876 out << "Unknown (" << static_cast<uint32_t>(type) << ")";
877 break;
878 }
879 return out;
880 }
881
882 std::ostream &operator<<(std::ostream &out, const ImageClientMeta &meta) {
883 out << "[tag_class=" << meta.tag_class << "]";
884 return out;
885 }
886
887 std::ostream &operator<<(std::ostream &out, const MirrorPeerSyncPoint &sync) {
888 out << "[snap_name=" << sync.snap_name << ", "
889 << "from_snap_name=" << sync.from_snap_name;
890 if (sync.object_number) {
891 out << ", " << *sync.object_number;
892 }
893 out << "]";
894 return out;
895 }
896
897 std::ostream &operator<<(std::ostream &out, const MirrorPeerState &state) {
898 switch (state) {
899 case MIRROR_PEER_STATE_SYNCING:
900 out << "Syncing";
901 break;
902 case MIRROR_PEER_STATE_REPLAYING:
903 out << "Replaying";
904 break;
905 default:
906 out << "Unknown (" << static_cast<uint32_t>(state) << ")";
907 break;
908 }
909 return out;
910 }
911
912 std::ostream &operator<<(std::ostream &out, const MirrorPeerClientMeta &meta) {
913 out << "[image_id=" << meta.image_id << ", "
914 << "state=" << meta.state << ", "
915 << "sync_object_count=" << meta.sync_object_count << ", "
916 << "sync_points=[";
917 std::string delimiter;
918 for (auto &sync_point : meta.sync_points) {
919 out << delimiter << "[" << sync_point << "]";
920 delimiter = ", ";
921 }
922 out << "], snap_seqs=[";
923 delimiter = "";
924 for (auto &pair : meta.snap_seqs) {
925 out << delimiter << "["
926 << "local_snap_seq=" << pair.first << ", "
927 << "peer_snap_seq" << pair.second << "]";
928 delimiter = ", ";
929 }
930 out << "]";
931 return out;
932 }
933
934 std::ostream &operator<<(std::ostream &out, const TagPredecessor &predecessor) {
935 out << "["
936 << "mirror_uuid=" << predecessor.mirror_uuid;
937 if (predecessor.commit_valid) {
938 out << ", "
939 << "tag_tid=" << predecessor.tag_tid << ", "
940 << "entry_tid=" << predecessor.entry_tid;
941 }
942 out << "]";
943 return out;
944 }
945
946 std::ostream &operator<<(std::ostream &out, const TagData &tag_data) {
947 out << "["
948 << "mirror_uuid=" << tag_data.mirror_uuid << ", "
949 << "predecessor=" << tag_data.predecessor
950 << "]";
951 return out;
952 }
953
954 } // namespace journal
955 } // namespace librbd
956