1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
4 #ifndef CEPH_CLS_RBD_TYPES_H
5 #define CEPH_CLS_RBD_TYPES_H
7 #include <boost/variant.hpp>
8 #include "include/int_types.h"
9 #include "include/buffer.h"
10 #include "include/encoding.h"
11 #include "include/stringify.h"
12 #include "include/utime.h"
13 #include "msg/msg_types.h"
18 #define RBD_GROUP_REF "rbd_group_ref"
20 namespace ceph
{ class Formatter
; }
25 static const uint32_t MAX_OBJECT_MAP_OBJECT_COUNT
= 256000000;
26 static const string RBD_GROUP_IMAGE_KEY_PREFIX
= "image_";
29 DIRECTORY_STATE_READY
= 0,
30 DIRECTORY_STATE_ADD_DISABLED
= 1
33 inline void encode(DirectoryState state
, bufferlist
& bl
,
36 ceph::encode(static_cast<uint8_t>(state
), bl
);
39 inline void decode(DirectoryState
&state
, bufferlist::const_iterator
& it
)
42 ceph::decode(int_state
, it
);
43 state
= static_cast<DirectoryState
>(int_state
);
47 MIRROR_MODE_DISABLED
= 0,
48 MIRROR_MODE_IMAGE
= 1,
52 enum GroupImageLinkState
{
53 GROUP_IMAGE_LINK_STATE_ATTACHED
,
54 GROUP_IMAGE_LINK_STATE_INCOMPLETE
57 inline void encode(const GroupImageLinkState
&state
, bufferlist
& bl
,
61 encode(static_cast<uint8_t>(state
), bl
);
64 inline void decode(GroupImageLinkState
&state
, bufferlist::const_iterator
& it
)
68 decode(int_state
, it
);
69 state
= static_cast<GroupImageLinkState
>(int_state
);
72 enum MirrorPeerDirection
{
73 MIRROR_PEER_DIRECTION_RX
= 0,
74 MIRROR_PEER_DIRECTION_TX
= 1,
75 MIRROR_PEER_DIRECTION_RX_TX
= 2
78 std::ostream
& operator<<(std::ostream
& os
,
79 MirrorPeerDirection mirror_peer_direction
);
84 MirrorPeer(const std::string
&uuid
,
85 MirrorPeerDirection mirror_peer_direction
,
86 const std::string
& site_name
,
87 const std::string
& client_name
,
88 const std::string
& mirror_uuid
)
89 : uuid(uuid
), mirror_peer_direction(mirror_peer_direction
),
90 site_name(site_name
), client_name(client_name
),
91 mirror_uuid(mirror_uuid
) {
96 MirrorPeerDirection mirror_peer_direction
= MIRROR_PEER_DIRECTION_RX_TX
;
97 std::string site_name
;
98 std::string client_name
; // RX property
99 std::string mirror_uuid
;
102 inline bool is_valid() const {
103 switch (mirror_peer_direction
) {
104 case MIRROR_PEER_DIRECTION_TX
:
106 case MIRROR_PEER_DIRECTION_RX
:
107 case MIRROR_PEER_DIRECTION_RX_TX
:
108 if (client_name
.empty()) {
115 return (!uuid
.empty() && !site_name
.empty());
118 void encode(bufferlist
&bl
) const;
119 void decode(bufferlist::const_iterator
&it
);
120 void dump(Formatter
*f
) const;
122 static void generate_test_instances(std::list
<MirrorPeer
*> &o
);
124 bool operator==(const MirrorPeer
&rhs
) const;
125 bool operator!=(const MirrorPeer
&rhs
) const {
126 return (!(*this == rhs
));
130 std::ostream
& operator<<(std::ostream
& os
, const MirrorMode
& mirror_mode
);
131 std::ostream
& operator<<(std::ostream
& os
, const MirrorPeer
& peer
);
133 WRITE_CLASS_ENCODER(MirrorPeer
);
135 enum MirrorImageMode
{
136 MIRROR_IMAGE_MODE_JOURNAL
= 0,
137 MIRROR_IMAGE_MODE_SNAPSHOT
= 1,
140 enum MirrorImageState
{
141 MIRROR_IMAGE_STATE_DISABLING
= 0,
142 MIRROR_IMAGE_STATE_ENABLED
= 1,
143 MIRROR_IMAGE_STATE_DISABLED
= 2,
144 MIRROR_IMAGE_STATE_CREATING
= 3,
150 MirrorImage(MirrorImageMode mode
, const std::string
&global_image_id
,
151 MirrorImageState state
)
152 : mode(mode
), global_image_id(global_image_id
), state(state
) {
155 MirrorImageMode mode
= MIRROR_IMAGE_MODE_JOURNAL
;
156 std::string global_image_id
;
157 MirrorImageState state
= MIRROR_IMAGE_STATE_DISABLING
;
159 void encode(bufferlist
&bl
) const;
160 void decode(bufferlist::const_iterator
&it
);
161 void dump(Formatter
*f
) const;
163 static void generate_test_instances(std::list
<MirrorImage
*> &o
);
165 bool operator==(const MirrorImage
&rhs
) const;
166 bool operator<(const MirrorImage
&rhs
) const;
169 std::ostream
& operator<<(std::ostream
& os
, const MirrorImageMode
& mirror_mode
);
170 std::ostream
& operator<<(std::ostream
& os
, const MirrorImageState
& mirror_state
);
171 std::ostream
& operator<<(std::ostream
& os
, const MirrorImage
& mirror_image
);
173 WRITE_CLASS_ENCODER(MirrorImage
);
175 enum MirrorImageStatusState
{
176 MIRROR_IMAGE_STATUS_STATE_UNKNOWN
= 0,
177 MIRROR_IMAGE_STATUS_STATE_ERROR
= 1,
178 MIRROR_IMAGE_STATUS_STATE_SYNCING
= 2,
179 MIRROR_IMAGE_STATUS_STATE_STARTING_REPLAY
= 3,
180 MIRROR_IMAGE_STATUS_STATE_REPLAYING
= 4,
181 MIRROR_IMAGE_STATUS_STATE_STOPPING_REPLAY
= 5,
182 MIRROR_IMAGE_STATUS_STATE_STOPPED
= 6,
185 inline void encode(const MirrorImageStatusState
&state
, bufferlist
& bl
,
189 encode(static_cast<uint8_t>(state
), bl
);
192 inline void decode(MirrorImageStatusState
&state
,
193 bufferlist::const_iterator
& it
)
197 decode(int_state
, it
);
198 state
= static_cast<MirrorImageStatusState
>(int_state
);
201 std::ostream
& operator<<(std::ostream
& os
, const MirrorImageStatusState
& state
);
203 struct MirrorImageSiteStatus
{
204 static const std::string LOCAL_MIRROR_UUID
;
206 MirrorImageSiteStatus() {}
207 MirrorImageSiteStatus(const std::string
& mirror_uuid
,
208 MirrorImageStatusState state
,
209 const std::string
&description
)
210 : mirror_uuid(mirror_uuid
), state(state
), description(description
) {
213 std::string mirror_uuid
= LOCAL_MIRROR_UUID
;
214 MirrorImageStatusState state
= MIRROR_IMAGE_STATUS_STATE_UNKNOWN
;
215 std::string description
;
219 void encode_meta(uint8_t version
, bufferlist
&bl
) const;
220 void decode_meta(uint8_t version
, bufferlist::const_iterator
&it
);
222 void encode(bufferlist
&bl
) const;
223 void decode(bufferlist::const_iterator
&it
);
224 void dump(Formatter
*f
) const;
226 std::string
state_to_string() const;
228 bool operator==(const MirrorImageSiteStatus
&rhs
) const;
230 static void generate_test_instances(std::list
<MirrorImageSiteStatus
*> &o
);
232 WRITE_CLASS_ENCODER(MirrorImageSiteStatus
);
234 std::ostream
& operator<<(std::ostream
& os
, const MirrorImageSiteStatus
& status
);
236 struct MirrorImageSiteStatusOnDisk
: cls::rbd::MirrorImageSiteStatus
{
237 entity_inst_t origin
;
239 MirrorImageSiteStatusOnDisk() {
241 MirrorImageSiteStatusOnDisk(const cls::rbd::MirrorImageSiteStatus
&status
) :
242 cls::rbd::MirrorImageSiteStatus(status
) {
245 void encode_meta(bufferlist
&bl
, uint64_t features
) const;
246 void decode_meta(bufferlist::const_iterator
&it
);
248 void encode(bufferlist
&bl
, uint64_t features
) const;
249 void decode(bufferlist::const_iterator
&it
);
251 static void generate_test_instances(
252 std::list
<MirrorImageSiteStatusOnDisk
*> &o
);
254 WRITE_CLASS_ENCODER_FEATURES(MirrorImageSiteStatusOnDisk
)
256 struct MirrorImageStatus
{
257 typedef std::list
<MirrorImageSiteStatus
> MirrorImageSiteStatuses
;
259 MirrorImageStatus() {}
260 MirrorImageStatus(const MirrorImageSiteStatuses
& statuses
)
261 : mirror_image_site_statuses(statuses
) {
264 MirrorImageSiteStatuses mirror_image_site_statuses
;
266 int get_local_mirror_image_site_status(MirrorImageSiteStatus
* status
) const;
268 void encode(bufferlist
&bl
) const;
269 void decode(bufferlist::const_iterator
&it
);
270 void dump(Formatter
*f
) const;
272 bool operator==(const MirrorImageStatus
& rhs
) const;
274 static void generate_test_instances(std::list
<MirrorImageStatus
*> &o
);
276 WRITE_CLASS_ENCODER(MirrorImageStatus
);
278 std::ostream
& operator<<(std::ostream
& os
, const MirrorImageStatus
& status
);
280 struct ParentImageSpec
{
281 int64_t pool_id
= -1;
282 std::string pool_namespace
;
283 std::string image_id
;
284 snapid_t snap_id
= CEPH_NOSNAP
;
288 ParentImageSpec(int64_t pool_id
, const std::string
& pool_namespace
,
289 const std::string
& image_id
, snapid_t snap_id
)
290 : pool_id(pool_id
), pool_namespace(pool_namespace
), image_id(image_id
),
294 bool exists() const {
295 return (pool_id
>= 0 && !image_id
.empty() && snap_id
!= CEPH_NOSNAP
);
298 bool operator==(const ParentImageSpec
& rhs
) const {
299 return ((pool_id
== rhs
.pool_id
) &&
300 (pool_namespace
== rhs
.pool_namespace
) &&
301 (image_id
== rhs
.image_id
) &&
302 (snap_id
== rhs
.snap_id
));
305 bool operator!=(const ParentImageSpec
& rhs
) const {
306 return !(*this == rhs
);
309 void encode(bufferlist
&bl
) const;
310 void decode(bufferlist::const_iterator
&it
);
311 void dump(Formatter
*f
) const;
313 static void generate_test_instances(std::list
<ParentImageSpec
*> &o
);
316 WRITE_CLASS_ENCODER(ParentImageSpec
);
318 std::ostream
& operator<<(std::ostream
& os
, const ParentImageSpec
& rhs
);
320 struct ChildImageSpec
{
321 int64_t pool_id
= -1;
322 std::string pool_namespace
;
323 std::string image_id
;
326 ChildImageSpec(int64_t pool_id
, const std::string
& pool_namespace
,
327 const std::string
& image_id
)
328 : pool_id(pool_id
), pool_namespace(pool_namespace
), image_id(image_id
) {
331 void encode(bufferlist
&bl
) const;
332 void decode(bufferlist::const_iterator
&it
);
333 void dump(Formatter
*f
) const;
335 static void generate_test_instances(std::list
<ChildImageSpec
*> &o
);
337 inline bool operator==(const ChildImageSpec
& rhs
) const {
338 return (pool_id
== rhs
.pool_id
&&
339 pool_namespace
== rhs
.pool_namespace
&&
340 image_id
== rhs
.image_id
);
342 inline bool operator<(const ChildImageSpec
& rhs
) const {
343 if (pool_id
!= rhs
.pool_id
) {
344 return pool_id
< rhs
.pool_id
;
346 if (pool_namespace
!= rhs
.pool_namespace
) {
347 return pool_namespace
< rhs
.pool_namespace
;
349 return image_id
< rhs
.image_id
;
352 WRITE_CLASS_ENCODER(ChildImageSpec
);
354 std::ostream
& operator<<(std::ostream
& os
, const ChildImageSpec
& rhs
);
356 typedef std::set
<ChildImageSpec
> ChildImageSpecs
;
358 struct GroupImageSpec
{
361 GroupImageSpec(const std::string
&image_id
, int64_t pool_id
)
362 : image_id(image_id
), pool_id(pool_id
) {}
364 static int from_key(const std::string
&image_key
, GroupImageSpec
*spec
);
366 std::string image_id
;
367 int64_t pool_id
= -1;
369 void encode(bufferlist
&bl
) const;
370 void decode(bufferlist::const_iterator
&it
);
371 void dump(Formatter
*f
) const;
373 static void generate_test_instances(std::list
<GroupImageSpec
*> &o
);
375 std::string
image_key();
378 WRITE_CLASS_ENCODER(GroupImageSpec
);
380 struct GroupImageStatus
{
381 GroupImageStatus() {}
382 GroupImageStatus(const std::string
&image_id
,
384 GroupImageLinkState state
)
385 : spec(image_id
, pool_id
), state(state
) {}
387 GroupImageStatus(GroupImageSpec spec
,
388 GroupImageLinkState state
)
389 : spec(spec
), state(state
) {}
392 GroupImageLinkState state
= GROUP_IMAGE_LINK_STATE_INCOMPLETE
;
394 void encode(bufferlist
&bl
) const;
395 void decode(bufferlist::const_iterator
&it
);
396 void dump(Formatter
*f
) const;
398 static void generate_test_instances(std::list
<GroupImageStatus
*> &o
);
400 std::string
state_to_string() const;
403 WRITE_CLASS_ENCODER(GroupImageStatus
);
407 GroupSpec(const std::string
&group_id
, int64_t pool_id
)
408 : group_id(group_id
), pool_id(pool_id
) {}
410 std::string group_id
;
411 int64_t pool_id
= -1;
413 void encode(bufferlist
&bl
) const;
414 void decode(bufferlist::const_iterator
&it
);
415 void dump(Formatter
*f
) const;
416 bool is_valid() const;
418 static void generate_test_instances(std::list
<GroupSpec
*> &o
);
421 WRITE_CLASS_ENCODER(GroupSpec
);
423 enum SnapshotNamespaceType
{
424 SNAPSHOT_NAMESPACE_TYPE_USER
= 0,
425 SNAPSHOT_NAMESPACE_TYPE_GROUP
= 1,
426 SNAPSHOT_NAMESPACE_TYPE_TRASH
= 2,
427 SNAPSHOT_NAMESPACE_TYPE_MIRROR
= 3,
430 struct UserSnapshotNamespace
{
431 static const SnapshotNamespaceType SNAPSHOT_NAMESPACE_TYPE
=
432 SNAPSHOT_NAMESPACE_TYPE_USER
;
434 UserSnapshotNamespace() {}
436 void encode(bufferlist
& bl
) const {}
437 void decode(bufferlist::const_iterator
& it
) {}
439 void dump(Formatter
*f
) const {}
441 inline bool operator==(const UserSnapshotNamespace
& usn
) const {
445 inline bool operator<(const UserSnapshotNamespace
& usn
) const {
450 struct GroupSnapshotNamespace
{
451 static const SnapshotNamespaceType SNAPSHOT_NAMESPACE_TYPE
=
452 SNAPSHOT_NAMESPACE_TYPE_GROUP
;
454 GroupSnapshotNamespace() {}
456 GroupSnapshotNamespace(int64_t _group_pool
,
457 const string
&_group_id
,
458 const string
&_group_snapshot_id
)
459 : group_id(_group_id
), group_pool(_group_pool
),
460 group_snapshot_id(_group_snapshot_id
) {}
463 int64_t group_pool
= 0;
464 string group_snapshot_id
;
466 void encode(bufferlist
& bl
) const;
467 void decode(bufferlist::const_iterator
& it
);
469 void dump(Formatter
*f
) const;
471 inline bool operator==(const GroupSnapshotNamespace
& gsn
) const {
472 return group_pool
== gsn
.group_pool
&&
473 group_id
== gsn
.group_id
&&
474 group_snapshot_id
== gsn
.group_snapshot_id
;
477 inline bool operator<(const GroupSnapshotNamespace
& gsn
) const {
478 if (group_pool
< gsn
.group_pool
) {
480 } else if (group_id
< gsn
.group_id
) {
483 return (group_snapshot_id
< gsn
.group_snapshot_id
);
489 struct TrashSnapshotNamespace
{
490 static const SnapshotNamespaceType SNAPSHOT_NAMESPACE_TYPE
=
491 SNAPSHOT_NAMESPACE_TYPE_TRASH
;
493 std::string original_name
;
494 SnapshotNamespaceType original_snapshot_namespace_type
=
495 SNAPSHOT_NAMESPACE_TYPE_USER
;
497 TrashSnapshotNamespace() {}
498 TrashSnapshotNamespace(SnapshotNamespaceType original_snapshot_namespace_type
,
499 const std::string
& original_name
)
500 : original_name(original_name
),
501 original_snapshot_namespace_type(original_snapshot_namespace_type
) {}
503 void encode(bufferlist
& bl
) const;
504 void decode(bufferlist::const_iterator
& it
);
505 void dump(Formatter
*f
) const;
507 inline bool operator==(const TrashSnapshotNamespace
& usn
) const {
510 inline bool operator<(const TrashSnapshotNamespace
& usn
) const {
515 enum MirrorSnapshotState
{
516 MIRROR_SNAPSHOT_STATE_PRIMARY
= 0,
517 MIRROR_SNAPSHOT_STATE_PRIMARY_DEMOTED
= 1,
518 MIRROR_SNAPSHOT_STATE_NON_PRIMARY
= 2,
519 MIRROR_SNAPSHOT_STATE_NON_PRIMARY_DEMOTED
= 3,
522 inline void encode(const MirrorSnapshotState
&state
, bufferlist
& bl
,
523 uint64_t features
=0) {
525 encode(static_cast<uint8_t>(state
), bl
);
528 inline void decode(MirrorSnapshotState
&state
, bufferlist::const_iterator
& it
) {
531 decode(int_state
, it
);
532 state
= static_cast<MirrorSnapshotState
>(int_state
);
535 std::ostream
& operator<<(std::ostream
& os
, MirrorSnapshotState type
);
537 typedef std::map
<uint64_t, uint64_t> SnapSeqs
;
539 struct MirrorSnapshotNamespace
{
540 static const SnapshotNamespaceType SNAPSHOT_NAMESPACE_TYPE
=
541 SNAPSHOT_NAMESPACE_TYPE_MIRROR
;
543 MirrorSnapshotState state
= MIRROR_SNAPSHOT_STATE_NON_PRIMARY
;
544 bool complete
= false;
545 std::set
<std::string
> mirror_peer_uuids
;
547 std::string primary_mirror_uuid
;
548 snapid_t primary_snap_id
= CEPH_NOSNAP
;
549 uint64_t last_copied_object_number
= 0;
552 MirrorSnapshotNamespace() {
554 MirrorSnapshotNamespace(MirrorSnapshotState state
,
555 const std::set
<std::string
> &mirror_peer_uuids
,
556 const std::string
& primary_mirror_uuid
,
557 snapid_t primary_snap_id
)
558 : state(state
), mirror_peer_uuids(mirror_peer_uuids
),
559 primary_mirror_uuid(primary_mirror_uuid
),
560 primary_snap_id(primary_snap_id
) {
562 MirrorSnapshotNamespace(MirrorSnapshotState state
,
563 const std::set
<std::string
> &mirror_peer_uuids
,
564 const std::string
& primary_mirror_uuid
,
565 snapid_t primary_snap_id
,
567 uint64_t last_copied_object_number
,
568 const SnapSeqs
& snap_seqs
)
569 : state(state
), complete(complete
), mirror_peer_uuids(mirror_peer_uuids
),
570 primary_mirror_uuid(primary_mirror_uuid
),
571 primary_snap_id(primary_snap_id
),
572 last_copied_object_number(last_copied_object_number
),
573 snap_seqs(snap_seqs
) {
576 inline bool is_primary() const {
577 return (state
== MIRROR_SNAPSHOT_STATE_PRIMARY
||
578 state
== MIRROR_SNAPSHOT_STATE_PRIMARY_DEMOTED
);
581 inline bool is_non_primary() const {
582 return (state
== MIRROR_SNAPSHOT_STATE_NON_PRIMARY
||
583 state
== MIRROR_SNAPSHOT_STATE_NON_PRIMARY_DEMOTED
);
586 inline bool is_demoted() const {
587 return (state
== MIRROR_SNAPSHOT_STATE_PRIMARY_DEMOTED
||
588 state
== MIRROR_SNAPSHOT_STATE_NON_PRIMARY_DEMOTED
);
591 inline bool is_orphan() const {
592 return (is_non_primary() &&
593 primary_mirror_uuid
.empty() &&
594 primary_snap_id
== CEPH_NOSNAP
);
597 void encode(bufferlist
& bl
) const;
598 void decode(bufferlist::const_iterator
& it
);
600 void dump(Formatter
*f
) const;
602 inline bool operator==(const MirrorSnapshotNamespace
& rhs
) const {
603 return state
== rhs
.state
&&
604 complete
== rhs
.complete
&&
605 mirror_peer_uuids
== rhs
.mirror_peer_uuids
&&
606 primary_mirror_uuid
== rhs
.primary_mirror_uuid
&&
607 primary_snap_id
== rhs
.primary_snap_id
&&
608 last_copied_object_number
== rhs
.last_copied_object_number
&&
609 snap_seqs
== rhs
.snap_seqs
;
612 inline bool operator<(const MirrorSnapshotNamespace
& rhs
) const {
613 if (state
!= rhs
.state
) {
614 return state
< rhs
.state
;
615 } else if (complete
!= rhs
.complete
) {
616 return complete
< rhs
.complete
;
617 } else if (mirror_peer_uuids
!= rhs
.mirror_peer_uuids
) {
618 return mirror_peer_uuids
< rhs
.mirror_peer_uuids
;
619 } else if (primary_mirror_uuid
!= rhs
.primary_mirror_uuid
) {
620 return primary_mirror_uuid
< rhs
.primary_mirror_uuid
;
621 } else if (primary_snap_id
!= rhs
.primary_snap_id
) {
622 return primary_snap_id
< rhs
.primary_snap_id
;
623 } else if (last_copied_object_number
!= rhs
.last_copied_object_number
) {
624 return last_copied_object_number
< rhs
.last_copied_object_number
;
626 return snap_seqs
< rhs
.snap_seqs
;
631 struct UnknownSnapshotNamespace
{
632 static const SnapshotNamespaceType SNAPSHOT_NAMESPACE_TYPE
=
633 static_cast<SnapshotNamespaceType
>(-1);
635 UnknownSnapshotNamespace() {}
637 void encode(bufferlist
& bl
) const {}
638 void decode(bufferlist::const_iterator
& it
) {}
639 void dump(Formatter
*f
) const {}
641 inline bool operator==(const UnknownSnapshotNamespace
& gsn
) const {
645 inline bool operator<(const UnknownSnapshotNamespace
& gsn
) const {
650 std::ostream
& operator<<(std::ostream
& os
, const SnapshotNamespaceType
& type
);
651 std::ostream
& operator<<(std::ostream
& os
, const UserSnapshotNamespace
& ns
);
652 std::ostream
& operator<<(std::ostream
& os
, const GroupSnapshotNamespace
& ns
);
653 std::ostream
& operator<<(std::ostream
& os
, const TrashSnapshotNamespace
& ns
);
654 std::ostream
& operator<<(std::ostream
& os
, const MirrorSnapshotNamespace
& ns
);
655 std::ostream
& operator<<(std::ostream
& os
, const UnknownSnapshotNamespace
& ns
);
657 typedef boost::variant
<UserSnapshotNamespace
,
658 GroupSnapshotNamespace
,
659 TrashSnapshotNamespace
,
660 MirrorSnapshotNamespace
,
661 UnknownSnapshotNamespace
> SnapshotNamespaceVariant
;
663 struct SnapshotNamespace
: public SnapshotNamespaceVariant
{
664 SnapshotNamespace() {
667 template <typename T
>
668 SnapshotNamespace(T
&& t
) : SnapshotNamespaceVariant(std::forward
<T
>(t
)) {
671 void encode(bufferlist
& bl
) const;
672 void decode(bufferlist::const_iterator
& it
);
673 void dump(Formatter
*f
) const;
675 static void generate_test_instances(std::list
<SnapshotNamespace
*> &o
);
677 inline bool operator==(const SnapshotNamespaceVariant
& sn
) const {
678 return static_cast<const SnapshotNamespaceVariant
&>(*this) == sn
;
680 inline bool operator<(const SnapshotNamespaceVariant
& sn
) const {
681 return static_cast<const SnapshotNamespaceVariant
&>(*this) < sn
;
683 inline bool operator!=(const SnapshotNamespaceVariant
& sn
) const {
684 return !(*this == sn
);
687 WRITE_CLASS_ENCODER(SnapshotNamespace
);
689 SnapshotNamespaceType
get_snap_namespace_type(
690 const SnapshotNamespace
& snapshot_namespace
);
692 struct SnapshotInfo
{
693 snapid_t id
= CEPH_NOSNAP
;
694 cls::rbd::SnapshotNamespace snapshot_namespace
= {UserSnapshotNamespace
{}};
696 uint64_t image_size
= 0;
698 uint32_t child_count
= 0;
702 SnapshotInfo(snapid_t id
,
703 const cls::rbd::SnapshotNamespace
& snapshot_namespace
,
704 const std::string
& name
, uint64_t image_size
,
705 const utime_t
& timestamp
, uint32_t child_count
)
706 : id(id
), snapshot_namespace(snapshot_namespace
),
707 name(name
), image_size(image_size
), timestamp(timestamp
),
708 child_count(child_count
) {
711 void encode(bufferlist
& bl
) const;
712 void decode(bufferlist::const_iterator
& it
);
713 void dump(Formatter
*f
) const;
715 static void generate_test_instances(std::list
<SnapshotInfo
*> &o
);
717 WRITE_CLASS_ENCODER(SnapshotInfo
);
719 enum GroupSnapshotState
{
720 GROUP_SNAPSHOT_STATE_INCOMPLETE
= 0,
721 GROUP_SNAPSHOT_STATE_COMPLETE
= 1,
724 inline void encode(const GroupSnapshotState
&state
, bufferlist
& bl
, uint64_t features
=0)
727 encode(static_cast<uint8_t>(state
), bl
);
730 inline void decode(GroupSnapshotState
&state
, bufferlist::const_iterator
& it
)
734 decode(int_state
, it
);
735 state
= static_cast<GroupSnapshotState
>(int_state
);
738 struct ImageSnapshotSpec
{
743 ImageSnapshotSpec() {}
744 ImageSnapshotSpec(int64_t _pool
,
746 snapid_t _snap_id
) : pool(_pool
),
750 void encode(bufferlist
& bl
) const;
751 void decode(bufferlist::const_iterator
& it
);
753 void dump(Formatter
*f
) const;
755 static void generate_test_instances(std::list
<ImageSnapshotSpec
*> &o
);
757 WRITE_CLASS_ENCODER(ImageSnapshotSpec
);
759 struct GroupSnapshot
{
762 GroupSnapshotState state
= GROUP_SNAPSHOT_STATE_INCOMPLETE
;
765 GroupSnapshot(std::string _id
,
767 GroupSnapshotState _state
) : id(_id
),
771 vector
<ImageSnapshotSpec
> snaps
;
773 void encode(bufferlist
& bl
) const;
774 void decode(bufferlist::const_iterator
& it
);
775 void dump(Formatter
*f
) const;
777 static void generate_test_instances(std::list
<GroupSnapshot
*> &o
);
779 WRITE_CLASS_ENCODER(GroupSnapshot
);
780 enum TrashImageSource
{
781 TRASH_IMAGE_SOURCE_USER
= 0,
782 TRASH_IMAGE_SOURCE_MIRRORING
= 1,
783 TRASH_IMAGE_SOURCE_MIGRATION
= 2,
784 TRASH_IMAGE_SOURCE_REMOVING
= 3,
785 TRASH_IMAGE_SOURCE_USER_PARENT
= 4,
788 inline std::ostream
& operator<<(std::ostream
& os
,
789 const TrashImageSource
& source
) {
791 case TRASH_IMAGE_SOURCE_USER
:
794 case TRASH_IMAGE_SOURCE_MIRRORING
:
797 case TRASH_IMAGE_SOURCE_MIGRATION
:
800 case TRASH_IMAGE_SOURCE_REMOVING
:
804 os
<< "unknown (" << static_cast<uint32_t>(source
) << ")";
810 inline void encode(const TrashImageSource
&source
, bufferlist
& bl
,
814 encode(static_cast<uint8_t>(source
), bl
);
817 inline void decode(TrashImageSource
&source
, bufferlist::const_iterator
& it
)
821 decode(int_source
, it
);
822 source
= static_cast<TrashImageSource
>(int_source
);
825 enum TrashImageState
{
826 TRASH_IMAGE_STATE_NORMAL
= 0,
827 TRASH_IMAGE_STATE_MOVING
= 1,
828 TRASH_IMAGE_STATE_REMOVING
= 2,
829 TRASH_IMAGE_STATE_RESTORING
= 3
832 inline void encode(const TrashImageState
&state
, bufferlist
&bl
)
835 encode(static_cast<uint8_t>(state
), bl
);
838 inline void decode(TrashImageState
&state
, bufferlist::const_iterator
&it
)
842 decode(int_state
, it
);
843 state
= static_cast<TrashImageState
>(int_state
);
846 struct TrashImageSpec
{
847 TrashImageSource source
= TRASH_IMAGE_SOURCE_USER
;
849 utime_t deletion_time
; // time of deletion
850 utime_t deferment_end_time
;
851 TrashImageState state
= TRASH_IMAGE_STATE_NORMAL
;
854 TrashImageSpec(TrashImageSource source
, const std::string
&name
,
855 const utime_t
& deletion_time
,
856 const utime_t
& deferment_end_time
)
857 : source(source
), name(name
), deletion_time(deletion_time
),
858 deferment_end_time(deferment_end_time
) {
861 void encode(bufferlist
&bl
) const;
862 void decode(bufferlist::const_iterator
& it
);
863 void dump(Formatter
*f
) const;
865 inline bool operator==(const TrashImageSpec
& rhs
) const {
866 return (source
== rhs
.source
&&
868 deletion_time
== rhs
.deletion_time
&&
869 deferment_end_time
== rhs
.deferment_end_time
);
872 WRITE_CLASS_ENCODER(TrashImageSpec
);
874 struct MirrorImageMap
{
878 MirrorImageMap(const std::string
&instance_id
, utime_t mapped_time
,
879 const bufferlist
&data
)
880 : instance_id(instance_id
),
881 mapped_time(mapped_time
),
885 std::string instance_id
;
889 void encode(bufferlist
&bl
) const;
890 void decode(bufferlist::const_iterator
&it
);
891 void dump(Formatter
*f
) const;
893 static void generate_test_instances(std::list
<MirrorImageMap
*> &o
);
895 bool operator==(const MirrorImageMap
&rhs
) const;
896 bool operator<(const MirrorImageMap
&rhs
) const;
899 std::ostream
& operator<<(std::ostream
& os
, const MirrorImageMap
&image_map
);
901 WRITE_CLASS_ENCODER(MirrorImageMap
);
903 enum MigrationHeaderType
{
904 MIGRATION_HEADER_TYPE_SRC
= 1,
905 MIGRATION_HEADER_TYPE_DST
= 2,
908 inline void encode(const MigrationHeaderType
&type
, bufferlist
& bl
) {
910 encode(static_cast<uint8_t>(type
), bl
);
913 inline void decode(MigrationHeaderType
&type
, bufferlist::const_iterator
& it
) {
916 decode(int_type
, it
);
917 type
= static_cast<MigrationHeaderType
>(int_type
);
920 enum MigrationState
{
921 MIGRATION_STATE_ERROR
= 0,
922 MIGRATION_STATE_PREPARING
= 1,
923 MIGRATION_STATE_PREPARED
= 2,
924 MIGRATION_STATE_EXECUTING
= 3,
925 MIGRATION_STATE_EXECUTED
= 4,
928 inline void encode(const MigrationState
&state
, bufferlist
& bl
) {
930 encode(static_cast<uint8_t>(state
), bl
);
933 inline void decode(MigrationState
&state
, bufferlist::const_iterator
& it
) {
936 decode(int_state
, it
);
937 state
= static_cast<MigrationState
>(int_state
);
940 std::ostream
& operator<<(std::ostream
& os
,
941 const MigrationState
& migration_state
);
943 struct MigrationSpec
{
944 MigrationHeaderType header_type
= MIGRATION_HEADER_TYPE_SRC
;
945 int64_t pool_id
= -1;
946 std::string pool_namespace
;
947 std::string image_name
;
948 std::string image_id
;
949 std::map
<uint64_t, uint64_t> snap_seqs
;
950 uint64_t overlap
= 0;
951 bool flatten
= false;
952 bool mirroring
= false;
953 MirrorImageMode mirror_image_mode
= MIRROR_IMAGE_MODE_JOURNAL
;
954 MigrationState state
= MIGRATION_STATE_ERROR
;
955 std::string state_description
;
959 MigrationSpec(MigrationHeaderType header_type
, int64_t pool_id
,
960 const std::string
& pool_namespace
,
961 const std::string
&image_name
, const std::string
&image_id
,
962 const std::map
<uint64_t, uint64_t> &snap_seqs
, uint64_t overlap
,
963 bool mirroring
, MirrorImageMode mirror_image_mode
, bool flatten
,
964 MigrationState state
, const std::string
&state_description
)
965 : header_type(header_type
), pool_id(pool_id
),
966 pool_namespace(pool_namespace
), image_name(image_name
),
967 image_id(image_id
), snap_seqs(snap_seqs
), overlap(overlap
),
968 flatten(flatten
), mirroring(mirroring
),
969 mirror_image_mode(mirror_image_mode
), state(state
),
970 state_description(state_description
) {
973 void encode(bufferlist
&bl
) const;
974 void decode(bufferlist::const_iterator
& it
);
975 void dump(Formatter
*f
) const;
977 static void generate_test_instances(std::list
<MigrationSpec
*> &o
);
979 inline bool operator==(const MigrationSpec
& ms
) const {
980 return header_type
== ms
.header_type
&& pool_id
== ms
.pool_id
&&
981 pool_namespace
== ms
.pool_namespace
&& image_name
== ms
.image_name
&&
982 image_id
== ms
.image_id
&& snap_seqs
== ms
.snap_seqs
&&
983 overlap
== ms
.overlap
&& flatten
== ms
.flatten
&&
984 mirroring
== ms
.mirroring
&& mirror_image_mode
== ms
.mirror_image_mode
&&
985 state
== ms
.state
&& state_description
== ms
.state_description
;
989 std::ostream
& operator<<(std::ostream
& os
, const MigrationSpec
& migration_spec
);
991 WRITE_CLASS_ENCODER(MigrationSpec
);
993 enum AssertSnapcSeqState
{
994 ASSERT_SNAPC_SEQ_GT_SNAPSET_SEQ
= 0,
995 ASSERT_SNAPC_SEQ_LE_SNAPSET_SEQ
= 1,
998 inline void encode(const AssertSnapcSeqState
&state
, bufferlist
& bl
) {
1000 encode(static_cast<uint8_t>(state
), bl
);
1003 inline void decode(AssertSnapcSeqState
&state
, bufferlist::const_iterator
& it
) {
1006 decode(int_state
, it
);
1007 state
= static_cast<AssertSnapcSeqState
>(int_state
);
1010 std::ostream
& operator<<(std::ostream
& os
, const AssertSnapcSeqState
& state
);
1012 void sanitize_entity_inst(entity_inst_t
* entity_inst
);
1017 #endif // CEPH_CLS_RBD_TYPES_H