1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
4 #include <boost/variant.hpp>
5 #include "cls/rbd/cls_rbd_types.h"
6 #include "common/Formatter.h"
11 void MirrorPeer::encode(bufferlist
&bl
) const {
12 ENCODE_START(1, 1, bl
);
14 encode(cluster_name
, bl
);
15 encode(client_name
, bl
);
20 void MirrorPeer::decode(bufferlist::const_iterator
&it
) {
23 decode(cluster_name
, it
);
24 decode(client_name
, it
);
29 void MirrorPeer::dump(Formatter
*f
) const {
30 f
->dump_string("uuid", uuid
);
31 f
->dump_string("cluster_name", cluster_name
);
32 f
->dump_string("client_name", client_name
);
33 f
->dump_int("pool_id", pool_id
);
36 void MirrorPeer::generate_test_instances(std::list
<MirrorPeer
*> &o
) {
37 o
.push_back(new MirrorPeer());
38 o
.push_back(new MirrorPeer("uuid-123", "cluster name", "client name", 123));
41 bool MirrorPeer::operator==(const MirrorPeer
&rhs
) const {
42 return (uuid
== rhs
.uuid
&&
43 cluster_name
== rhs
.cluster_name
&&
44 client_name
== rhs
.client_name
&&
45 pool_id
== rhs
.pool_id
);
48 std::ostream
& operator<<(std::ostream
& os
, const MirrorMode
& mirror_mode
) {
49 switch (mirror_mode
) {
50 case MIRROR_MODE_DISABLED
:
53 case MIRROR_MODE_IMAGE
:
56 case MIRROR_MODE_POOL
:
60 os
<< "unknown (" << static_cast<uint32_t>(mirror_mode
) << ")";
66 std::ostream
& operator<<(std::ostream
& os
, const MirrorPeer
& peer
) {
68 << "uuid=" << peer
.uuid
<< ", "
69 << "cluster_name=" << peer
.cluster_name
<< ", "
70 << "client_name=" << peer
.client_name
;
71 if (peer
.pool_id
!= -1) {
72 os
<< ", pool_id=" << peer
.pool_id
;
78 void MirrorImage::encode(bufferlist
&bl
) const {
79 ENCODE_START(1, 1, bl
);
80 encode(global_image_id
, bl
);
81 encode(static_cast<uint8_t>(state
), bl
);
85 void MirrorImage::decode(bufferlist::const_iterator
&it
) {
88 decode(global_image_id
, it
);
89 decode(int_state
, it
);
90 state
= static_cast<MirrorImageState
>(int_state
);
94 void MirrorImage::dump(Formatter
*f
) const {
95 f
->dump_string("global_image_id", global_image_id
);
96 f
->dump_int("state", state
);
99 void MirrorImage::generate_test_instances(std::list
<MirrorImage
*> &o
) {
100 o
.push_back(new MirrorImage());
101 o
.push_back(new MirrorImage("uuid-123", MIRROR_IMAGE_STATE_ENABLED
));
102 o
.push_back(new MirrorImage("uuid-abc", MIRROR_IMAGE_STATE_DISABLING
));
105 bool MirrorImage::operator==(const MirrorImage
&rhs
) const {
106 return global_image_id
== rhs
.global_image_id
&& state
== rhs
.state
;
109 bool MirrorImage::operator<(const MirrorImage
&rhs
) const {
110 return global_image_id
< rhs
.global_image_id
||
111 (global_image_id
== rhs
.global_image_id
&& state
< rhs
.state
);
114 std::ostream
& operator<<(std::ostream
& os
, const MirrorImageState
& mirror_state
) {
115 switch (mirror_state
) {
116 case MIRROR_IMAGE_STATE_DISABLING
:
119 case MIRROR_IMAGE_STATE_ENABLED
:
123 os
<< "unknown (" << static_cast<uint32_t>(mirror_state
) << ")";
129 std::ostream
& operator<<(std::ostream
& os
, const MirrorImage
& mirror_image
) {
131 << "global_image_id=" << mirror_image
.global_image_id
<< ", "
132 << "state=" << mirror_image
.state
<< "]";
136 void MirrorImageStatus::encode(bufferlist
&bl
) const {
137 ENCODE_START(1, 1, bl
);
139 encode(description
, bl
);
140 encode(last_update
, bl
);
145 void MirrorImageStatus::decode(bufferlist::const_iterator
&it
) {
148 decode(description
, it
);
149 decode(last_update
, it
);
154 void MirrorImageStatus::dump(Formatter
*f
) const {
155 f
->dump_string("state", state_to_string());
156 f
->dump_string("description", description
);
157 f
->dump_stream("last_update") << last_update
;
160 std::string
MirrorImageStatus::state_to_string() const {
161 std::stringstream ss
;
162 ss
<< (up
? "up+" : "down+") << state
;
166 void MirrorImageStatus::generate_test_instances(
167 std::list
<MirrorImageStatus
*> &o
) {
168 o
.push_back(new MirrorImageStatus());
169 o
.push_back(new MirrorImageStatus(MIRROR_IMAGE_STATUS_STATE_REPLAYING
));
170 o
.push_back(new MirrorImageStatus(MIRROR_IMAGE_STATUS_STATE_ERROR
, "error"));
173 bool MirrorImageStatus::operator==(const MirrorImageStatus
&rhs
) const {
174 return state
== rhs
.state
&& description
== rhs
.description
&& up
== rhs
.up
;
177 std::ostream
& operator<<(std::ostream
& os
, const MirrorImageStatusState
& state
) {
179 case MIRROR_IMAGE_STATUS_STATE_UNKNOWN
:
182 case MIRROR_IMAGE_STATUS_STATE_ERROR
:
185 case MIRROR_IMAGE_STATUS_STATE_SYNCING
:
188 case MIRROR_IMAGE_STATUS_STATE_STARTING_REPLAY
:
189 os
<< "starting_replay";
191 case MIRROR_IMAGE_STATUS_STATE_REPLAYING
:
194 case MIRROR_IMAGE_STATUS_STATE_STOPPING_REPLAY
:
195 os
<< "stopping_replay";
197 case MIRROR_IMAGE_STATUS_STATE_STOPPED
:
201 os
<< "unknown (" << static_cast<uint32_t>(state
) << ")";
207 std::ostream
& operator<<(std::ostream
& os
, const MirrorImageStatus
& status
) {
209 << "state=" << status
.state_to_string() << ", "
210 << "description=" << status
.description
<< ", "
211 << "last_update=" << status
.last_update
<< "]";
215 void ParentImageSpec::encode(bufferlist
& bl
) const {
216 ENCODE_START(1, 1, bl
);
218 encode(pool_namespace
, bl
);
219 encode(image_id
, bl
);
224 void ParentImageSpec::decode(bufferlist::const_iterator
& bl
) {
227 decode(pool_namespace
, bl
);
228 decode(image_id
, bl
);
233 void ParentImageSpec::dump(Formatter
*f
) const {
234 f
->dump_int("pool_id", pool_id
);
235 f
->dump_string("pool_namespace", pool_namespace
);
236 f
->dump_string("image_id", image_id
);
237 f
->dump_unsigned("snap_id", snap_id
);
240 void ParentImageSpec::generate_test_instances(std::list
<ParentImageSpec
*>& o
) {
241 o
.push_back(new ParentImageSpec
{});
242 o
.push_back(new ParentImageSpec
{1, "", "foo", 3});
243 o
.push_back(new ParentImageSpec
{1, "ns", "foo", 3});
246 void ChildImageSpec::encode(bufferlist
&bl
) const {
247 ENCODE_START(2, 1, bl
);
249 encode(image_id
, bl
);
250 encode(pool_namespace
, bl
);
254 void ChildImageSpec::decode(bufferlist::const_iterator
&it
) {
257 decode(image_id
, it
);
259 decode(pool_namespace
, it
);
264 void ChildImageSpec::dump(Formatter
*f
) const {
265 f
->dump_int("pool_id", pool_id
);
266 f
->dump_string("pool_namespace", pool_namespace
);
267 f
->dump_string("image_id", image_id
);
270 void ChildImageSpec::generate_test_instances(std::list
<ChildImageSpec
*> &o
) {
271 o
.push_back(new ChildImageSpec());
272 o
.push_back(new ChildImageSpec(123, "", "abc"));
273 o
.push_back(new ChildImageSpec(123, "ns", "abc"));
276 void GroupImageSpec::encode(bufferlist
&bl
) const {
277 ENCODE_START(1, 1, bl
);
278 encode(image_id
, bl
);
283 void GroupImageSpec::decode(bufferlist::const_iterator
&it
) {
285 decode(image_id
, it
);
290 void GroupImageSpec::dump(Formatter
*f
) const {
291 f
->dump_string("image_id", image_id
);
292 f
->dump_int("pool_id", pool_id
);
295 int GroupImageSpec::from_key(const std::string
&image_key
,
296 GroupImageSpec
*spec
) {
297 if (nullptr == spec
) return -EINVAL
;
298 int prefix_len
= cls::rbd::RBD_GROUP_IMAGE_KEY_PREFIX
.size();
299 std::string data_string
= image_key
.substr(prefix_len
,
300 image_key
.size() - prefix_len
);
301 size_t p
= data_string
.find("_");
302 if (std::string::npos
== p
) {
305 data_string
[p
] = ' ';
307 istringstream
iss(data_string
);
310 iss
>> std::hex
>> pool_id
>> image_id
;
312 spec
->image_id
= image_id
;
313 spec
->pool_id
= pool_id
;
317 std::string
GroupImageSpec::image_key() {
322 oss
<< RBD_GROUP_IMAGE_KEY_PREFIX
<< std::setw(16)
323 << std::setfill('0') << std::hex
<< pool_id
<< "_" << image_id
;
328 void GroupImageSpec::generate_test_instances(std::list
<GroupImageSpec
*> &o
) {
329 o
.push_back(new GroupImageSpec("10152ae8944a", 0));
330 o
.push_back(new GroupImageSpec("1018643c9869", 3));
333 void GroupImageStatus::encode(bufferlist
&bl
) const {
334 ENCODE_START(1, 1, bl
);
340 void GroupImageStatus::decode(bufferlist::const_iterator
&it
) {
347 std::string
GroupImageStatus::state_to_string() const {
348 std::stringstream ss
;
349 if (state
== GROUP_IMAGE_LINK_STATE_INCOMPLETE
) {
352 if (state
== GROUP_IMAGE_LINK_STATE_ATTACHED
) {
358 void GroupImageStatus::dump(Formatter
*f
) const {
360 f
->dump_string("state", state_to_string());
363 void GroupImageStatus::generate_test_instances(std::list
<GroupImageStatus
*> &o
) {
364 o
.push_back(new GroupImageStatus(GroupImageSpec("10152ae8944a", 0), GROUP_IMAGE_LINK_STATE_ATTACHED
));
365 o
.push_back(new GroupImageStatus(GroupImageSpec("1018643c9869", 3), GROUP_IMAGE_LINK_STATE_ATTACHED
));
366 o
.push_back(new GroupImageStatus(GroupImageSpec("10152ae8944a", 0), GROUP_IMAGE_LINK_STATE_INCOMPLETE
));
367 o
.push_back(new GroupImageStatus(GroupImageSpec("1018643c9869", 3), GROUP_IMAGE_LINK_STATE_INCOMPLETE
));
371 void GroupSpec::encode(bufferlist
&bl
) const {
372 ENCODE_START(1, 1, bl
);
374 encode(group_id
, bl
);
378 void GroupSpec::decode(bufferlist::const_iterator
&it
) {
381 decode(group_id
, it
);
385 void GroupSpec::dump(Formatter
*f
) const {
386 f
->dump_string("group_id", group_id
);
387 f
->dump_int("pool_id", pool_id
);
390 bool GroupSpec::is_valid() const {
391 return (!group_id
.empty()) && (pool_id
!= -1);
394 void GroupSpec::generate_test_instances(std::list
<GroupSpec
*> &o
) {
395 o
.push_back(new GroupSpec("10152ae8944a", 0));
396 o
.push_back(new GroupSpec("1018643c9869", 3));
399 void GroupSnapshotNamespace::encode(bufferlist
& bl
) const {
401 encode(group_pool
, bl
);
402 encode(group_id
, bl
);
403 encode(group_snapshot_id
, bl
);
406 void GroupSnapshotNamespace::decode(bufferlist::const_iterator
& it
) {
408 decode(group_pool
, it
);
409 decode(group_id
, it
);
410 decode(group_snapshot_id
, it
);
413 void GroupSnapshotNamespace::dump(Formatter
*f
) const {
414 f
->dump_int("group_pool", group_pool
);
415 f
->dump_string("group_id", group_id
);
416 f
->dump_string("group_snapshot_id", group_snapshot_id
);
419 void TrashSnapshotNamespace::encode(bufferlist
& bl
) const {
421 encode(original_name
, bl
);
422 encode(static_cast<uint32_t>(original_snapshot_namespace_type
), bl
);
425 void TrashSnapshotNamespace::decode(bufferlist::const_iterator
& it
) {
427 decode(original_name
, it
);
429 decode(snap_type
, it
);
430 original_snapshot_namespace_type
= static_cast<SnapshotNamespaceType
>(
434 void TrashSnapshotNamespace::dump(Formatter
*f
) const {
435 f
->dump_string("original_name", original_name
);
436 f
->dump_stream("original_snapshot_namespace")
437 << original_snapshot_namespace_type
;
440 class EncodeSnapshotNamespaceVisitor
: public boost::static_visitor
<void> {
442 explicit EncodeSnapshotNamespaceVisitor(bufferlist
&bl
) : m_bl(bl
) {
445 template <typename T
>
446 inline void operator()(const T
& t
) const {
448 encode(static_cast<uint32_t>(T::SNAPSHOT_NAMESPACE_TYPE
), m_bl
);
456 class DecodeSnapshotNamespaceVisitor
: public boost::static_visitor
<void> {
458 DecodeSnapshotNamespaceVisitor(bufferlist::const_iterator
&iter
)
462 template <typename T
>
463 inline void operator()(T
& t
) const {
467 bufferlist::const_iterator
&m_iter
;
470 class DumpSnapshotNamespaceVisitor
: public boost::static_visitor
<void> {
472 explicit DumpSnapshotNamespaceVisitor(Formatter
*formatter
, const std::string
&key
)
473 : m_formatter(formatter
), m_key(key
) {}
475 template <typename T
>
476 inline void operator()(const T
& t
) const {
477 auto type
= T::SNAPSHOT_NAMESPACE_TYPE
;
478 m_formatter
->dump_string(m_key
.c_str(), stringify(type
));
482 ceph::Formatter
*m_formatter
;
486 class GetTypeVisitor
: public boost::static_visitor
<SnapshotNamespaceType
> {
488 template <typename T
>
489 inline SnapshotNamespaceType
operator()(const T
&) const {
490 return static_cast<SnapshotNamespaceType
>(T::SNAPSHOT_NAMESPACE_TYPE
);
494 SnapshotNamespaceType
get_snap_namespace_type(
495 const SnapshotNamespace
& snapshot_namespace
) {
496 return static_cast<SnapshotNamespaceType
>(boost::apply_visitor(
497 GetTypeVisitor(), snapshot_namespace
));
500 void SnapshotInfo::encode(bufferlist
& bl
) const {
501 ENCODE_START(1, 1, bl
);
503 encode(snapshot_namespace
, bl
);
505 encode(image_size
, bl
);
506 encode(timestamp
, bl
);
507 encode(child_count
, bl
);
511 void SnapshotInfo::decode(bufferlist::const_iterator
& it
) {
514 decode(snapshot_namespace
, it
);
516 decode(image_size
, it
);
517 decode(timestamp
, it
);
518 decode(child_count
, it
);
522 void SnapshotInfo::dump(Formatter
*f
) const {
523 f
->dump_unsigned("id", id
);
524 f
->open_object_section("namespace");
525 boost::apply_visitor(DumpSnapshotNamespaceVisitor(f
, "type"),
528 f
->dump_string("name", name
);
529 f
->dump_unsigned("image_size", image_size
);
530 f
->dump_stream("timestamp") << timestamp
;
533 void SnapshotInfo::generate_test_instances(std::list
<SnapshotInfo
*> &o
) {
534 o
.push_back(new SnapshotInfo(1ULL, UserSnapshotNamespace
{}, "snap1", 123,
536 o
.push_back(new SnapshotInfo(2ULL,
537 GroupSnapshotNamespace
{567, "group1", "snap1"},
538 "snap1", 123, {123456, 0}, 987));
539 o
.push_back(new SnapshotInfo(3ULL,
540 TrashSnapshotNamespace
{
541 SNAPSHOT_NAMESPACE_TYPE_USER
, "snap1"},
542 "12345", 123, {123456, 0}, 429));
545 void SnapshotNamespace::encode(bufferlist
& bl
) const {
546 ENCODE_START(1, 1, bl
);
547 boost::apply_visitor(EncodeSnapshotNamespaceVisitor(bl
), *this);
551 void SnapshotNamespace::decode(bufferlist::const_iterator
&p
)
555 decode(snap_type
, p
);
557 case cls::rbd::SNAPSHOT_NAMESPACE_TYPE_USER
:
558 *this = UserSnapshotNamespace();
560 case cls::rbd::SNAPSHOT_NAMESPACE_TYPE_GROUP
:
561 *this = GroupSnapshotNamespace();
563 case cls::rbd::SNAPSHOT_NAMESPACE_TYPE_TRASH
:
564 *this = TrashSnapshotNamespace();
567 *this = UnknownSnapshotNamespace();
570 boost::apply_visitor(DecodeSnapshotNamespaceVisitor(p
), *this);
574 void SnapshotNamespace::dump(Formatter
*f
) const {
575 boost::apply_visitor(
576 DumpSnapshotNamespaceVisitor(f
, "snapshot_namespace_type"), *this);
579 void SnapshotNamespace::generate_test_instances(std::list
<SnapshotNamespace
*> &o
) {
580 o
.push_back(new SnapshotNamespace(UserSnapshotNamespace()));
581 o
.push_back(new SnapshotNamespace(GroupSnapshotNamespace(0, "10152ae8944a",
583 o
.push_back(new SnapshotNamespace(GroupSnapshotNamespace(5, "1018643c9869",
585 o
.push_back(new SnapshotNamespace(TrashSnapshotNamespace()));
588 std::ostream
& operator<<(std::ostream
& os
, const SnapshotNamespaceType
& type
) {
590 case SNAPSHOT_NAMESPACE_TYPE_USER
:
593 case SNAPSHOT_NAMESPACE_TYPE_GROUP
:
596 case SNAPSHOT_NAMESPACE_TYPE_TRASH
:
606 std::ostream
& operator<<(std::ostream
& os
, const UserSnapshotNamespace
& ns
) {
607 os
<< "[" << SNAPSHOT_NAMESPACE_TYPE_USER
<< "]";
611 std::ostream
& operator<<(std::ostream
& os
, const GroupSnapshotNamespace
& ns
) {
612 os
<< "[" << SNAPSHOT_NAMESPACE_TYPE_GROUP
<< " "
613 << "group_pool=" << ns
.group_pool
<< ", "
614 << "group_id=" << ns
.group_id
<< ", "
615 << "group_snapshot_id=" << ns
.group_snapshot_id
<< "]";
619 std::ostream
& operator<<(std::ostream
& os
, const TrashSnapshotNamespace
& ns
) {
620 os
<< "[" << SNAPSHOT_NAMESPACE_TYPE_TRASH
<< " "
621 << "original_name=" << ns
.original_name
<< ", "
622 << "original_snapshot_namespace=" << ns
.original_snapshot_namespace_type
627 std::ostream
& operator<<(std::ostream
& os
, const UnknownSnapshotNamespace
& ns
) {
632 void ImageSnapshotSpec::encode(bufferlist
& bl
) const {
634 ENCODE_START(1, 1, bl
);
636 encode(image_id
, bl
);
641 void ImageSnapshotSpec::decode(bufferlist::const_iterator
& it
) {
645 decode(image_id
, it
);
650 void ImageSnapshotSpec::dump(Formatter
*f
) const {
651 f
->dump_int("pool", pool
);
652 f
->dump_string("image_id", image_id
);
653 f
->dump_int("snap_id", snap_id
);
656 void ImageSnapshotSpec::generate_test_instances(std::list
<ImageSnapshotSpec
*> &o
) {
657 o
.push_back(new ImageSnapshotSpec(0, "myimage", 2));
658 o
.push_back(new ImageSnapshotSpec(1, "testimage", 7));
661 void GroupSnapshot::encode(bufferlist
& bl
) const {
663 ENCODE_START(1, 1, bl
);
671 void GroupSnapshot::decode(bufferlist::const_iterator
& it
) {
681 void GroupSnapshot::dump(Formatter
*f
) const {
682 f
->dump_string("id", id
);
683 f
->dump_string("name", name
);
684 f
->dump_int("state", state
);
687 void GroupSnapshot::generate_test_instances(std::list
<GroupSnapshot
*> &o
) {
688 o
.push_back(new GroupSnapshot("10152ae8944a", "groupsnapshot1", GROUP_SNAPSHOT_STATE_INCOMPLETE
));
689 o
.push_back(new GroupSnapshot("1018643c9869", "groupsnapshot2", GROUP_SNAPSHOT_STATE_COMPLETE
));
691 void TrashImageSpec::encode(bufferlist
& bl
) const {
692 ENCODE_START(2, 1, bl
);
695 encode(deletion_time
, bl
);
696 encode(deferment_end_time
, bl
);
701 void TrashImageSpec::decode(bufferlist::const_iterator
&it
) {
705 decode(deletion_time
, it
);
706 decode(deferment_end_time
, it
);
713 void TrashImageSpec::dump(Formatter
*f
) const {
714 f
->dump_stream("source") << source
;
715 f
->dump_string("name", name
);
716 f
->dump_unsigned("deletion_time", deletion_time
);
717 f
->dump_unsigned("deferment_end_time", deferment_end_time
);
720 void MirrorImageMap::encode(bufferlist
&bl
) const {
721 ENCODE_START(1, 1, bl
);
722 encode(instance_id
, bl
);
723 encode(mapped_time
, bl
);
728 void MirrorImageMap::decode(bufferlist::const_iterator
&it
) {
730 decode(instance_id
, it
);
731 decode(mapped_time
, it
);
736 void MirrorImageMap::dump(Formatter
*f
) const {
737 f
->dump_string("instance_id", instance_id
);
738 f
->dump_stream("mapped_time") << mapped_time
;
740 std::stringstream data_ss
;
741 data
.hexdump(data_ss
);
742 f
->dump_string("data", data_ss
.str());
745 void MirrorImageMap::generate_test_instances(
746 std::list
<MirrorImageMap
*> &o
) {
748 data
.append(std::string(128, '1'));
750 o
.push_back(new MirrorImageMap("uuid-123", utime_t(), data
));
751 o
.push_back(new MirrorImageMap("uuid-abc", utime_t(), data
));
754 bool MirrorImageMap::operator==(const MirrorImageMap
&rhs
) const {
755 return instance_id
== rhs
.instance_id
&& mapped_time
== rhs
.mapped_time
&&
756 data
.contents_equal(rhs
.data
);
759 bool MirrorImageMap::operator<(const MirrorImageMap
&rhs
) const {
760 return instance_id
< rhs
.instance_id
||
761 (instance_id
== rhs
.instance_id
&& mapped_time
< rhs
.mapped_time
);
764 std::ostream
& operator<<(std::ostream
& os
,
765 const MirrorImageMap
&image_map
) {
766 return os
<< "[" << "instance_id=" << image_map
.instance_id
<< ", mapped_time="
767 << image_map
.mapped_time
<< "]";
770 std::ostream
& operator<<(std::ostream
& os
,
771 const MigrationHeaderType
& type
) {
773 case MIGRATION_HEADER_TYPE_SRC
:
776 case MIGRATION_HEADER_TYPE_DST
:
780 os
<< "unknown (" << static_cast<uint32_t>(type
) << ")";
786 std::ostream
& operator<<(std::ostream
& os
,
787 const MigrationState
& migration_state
) {
788 switch (migration_state
) {
789 case MIGRATION_STATE_ERROR
:
792 case MIGRATION_STATE_PREPARING
:
795 case MIGRATION_STATE_PREPARED
:
798 case MIGRATION_STATE_EXECUTING
:
801 case MIGRATION_STATE_EXECUTED
:
805 os
<< "unknown (" << static_cast<uint32_t>(migration_state
) << ")";
811 void MigrationSpec::encode(bufferlist
& bl
) const {
812 ENCODE_START(1, 1, bl
);
813 encode(header_type
, bl
);
815 encode(pool_namespace
, bl
);
816 encode(image_name
, bl
);
817 encode(image_id
, bl
);
818 encode(snap_seqs
, bl
);
821 encode(mirroring
, bl
);
823 encode(state_description
, bl
);
827 void MigrationSpec::decode(bufferlist::const_iterator
& bl
) {
829 decode(header_type
, bl
);
831 decode(pool_namespace
, bl
);
832 decode(image_name
, bl
);
833 decode(image_id
, bl
);
834 decode(snap_seqs
, bl
);
837 decode(mirroring
, bl
);
839 decode(state_description
, bl
);
843 std::ostream
& operator<<(std::ostream
& os
,
844 const std::map
<uint64_t, uint64_t>& snap_seqs
) {
847 for (auto &it
: snap_seqs
) {
848 os
<< (count
++ > 0 ? ", " : "") << "(" << it
.first
<< ", " << it
.second
855 void MigrationSpec::dump(Formatter
*f
) const {
856 f
->dump_stream("header_type") << header_type
;
857 f
->dump_int("pool_id", pool_id
);
858 f
->dump_string("pool_namespace", pool_namespace
);
859 f
->dump_string("image_name", image_name
);
860 f
->dump_string("image_id", image_id
);
861 f
->dump_stream("snap_seqs") << snap_seqs
;
862 f
->dump_unsigned("overlap", overlap
);
863 f
->dump_bool("mirroring", mirroring
);
866 void MigrationSpec::generate_test_instances(std::list
<MigrationSpec
*> &o
) {
867 o
.push_back(new MigrationSpec());
868 o
.push_back(new MigrationSpec(MIGRATION_HEADER_TYPE_SRC
, 1, "ns",
869 "image_name", "image_id", {{1, 2}}, 123, true,
870 true, MIGRATION_STATE_PREPARED
, "description"));
873 std::ostream
& operator<<(std::ostream
& os
,
874 const MigrationSpec
& migration_spec
) {
876 << "header_type=" << migration_spec
.header_type
<< ", "
877 << "pool_id=" << migration_spec
.pool_id
<< ", "
878 << "pool_namespace=" << migration_spec
.pool_namespace
<< ", "
879 << "image_name=" << migration_spec
.image_name
<< ", "
880 << "image_id=" << migration_spec
.image_id
<< ", "
881 << "snap_seqs=" << migration_spec
.snap_seqs
<< ", "
882 << "overlap=" << migration_spec
.overlap
<< ", "
883 << "flatten=" << migration_spec
.flatten
<< ", "
884 << "mirroring=" << migration_spec
.mirroring
<< ", "
885 << "state=" << migration_spec
.state
<< ", "
886 << "state_description=" << migration_spec
.state_description
<< "]";
890 std::ostream
& operator<<(std::ostream
& os
, const AssertSnapcSeqState
& state
) {
892 case ASSERT_SNAPC_SEQ_GT_SNAPSET_SEQ
:
895 case ASSERT_SNAPC_SEQ_LE_SNAPSET_SEQ
:
899 os
<< "unknown (" << static_cast<uint32_t>(state
) << ")";