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
) {
479 return group_pool
< gsn
.group_pool
;
481 if (group_id
!= gsn
.group_id
) {
482 return group_id
< gsn
.group_id
;
484 return group_snapshot_id
< gsn
.group_snapshot_id
;
488 struct TrashSnapshotNamespace
{
489 static const SnapshotNamespaceType SNAPSHOT_NAMESPACE_TYPE
=
490 SNAPSHOT_NAMESPACE_TYPE_TRASH
;
492 std::string original_name
;
493 SnapshotNamespaceType original_snapshot_namespace_type
=
494 SNAPSHOT_NAMESPACE_TYPE_USER
;
496 TrashSnapshotNamespace() {}
497 TrashSnapshotNamespace(SnapshotNamespaceType original_snapshot_namespace_type
,
498 const std::string
& original_name
)
499 : original_name(original_name
),
500 original_snapshot_namespace_type(original_snapshot_namespace_type
) {}
502 void encode(bufferlist
& bl
) const;
503 void decode(bufferlist::const_iterator
& it
);
504 void dump(Formatter
*f
) const;
506 inline bool operator==(const TrashSnapshotNamespace
& usn
) const {
509 inline bool operator<(const TrashSnapshotNamespace
& usn
) const {
514 enum MirrorSnapshotState
{
515 MIRROR_SNAPSHOT_STATE_PRIMARY
= 0,
516 MIRROR_SNAPSHOT_STATE_PRIMARY_DEMOTED
= 1,
517 MIRROR_SNAPSHOT_STATE_NON_PRIMARY
= 2,
518 MIRROR_SNAPSHOT_STATE_NON_PRIMARY_DEMOTED
= 3,
521 inline void encode(const MirrorSnapshotState
&state
, bufferlist
& bl
,
522 uint64_t features
=0) {
524 encode(static_cast<uint8_t>(state
), bl
);
527 inline void decode(MirrorSnapshotState
&state
, bufferlist::const_iterator
& it
) {
530 decode(int_state
, it
);
531 state
= static_cast<MirrorSnapshotState
>(int_state
);
534 std::ostream
& operator<<(std::ostream
& os
, MirrorSnapshotState type
);
536 typedef std::map
<uint64_t, uint64_t> SnapSeqs
;
538 struct MirrorSnapshotNamespace
{
539 static const SnapshotNamespaceType SNAPSHOT_NAMESPACE_TYPE
=
540 SNAPSHOT_NAMESPACE_TYPE_MIRROR
;
542 MirrorSnapshotState state
= MIRROR_SNAPSHOT_STATE_NON_PRIMARY
;
543 bool complete
= false;
544 std::set
<std::string
> mirror_peer_uuids
;
546 std::string primary_mirror_uuid
;
548 snapid_t primary_snap_id
= CEPH_NOSNAP
;
549 snapid_t clean_since_snap_id
;
551 uint64_t last_copied_object_number
= 0;
554 MirrorSnapshotNamespace() {
556 MirrorSnapshotNamespace(MirrorSnapshotState state
,
557 const std::set
<std::string
> &mirror_peer_uuids
,
558 const std::string
& primary_mirror_uuid
,
559 snapid_t primary_snap_id
)
560 : state(state
), mirror_peer_uuids(mirror_peer_uuids
),
561 primary_mirror_uuid(primary_mirror_uuid
),
562 primary_snap_id(primary_snap_id
) {
564 MirrorSnapshotNamespace(MirrorSnapshotState state
,
565 const std::set
<std::string
> &mirror_peer_uuids
,
566 const std::string
& primary_mirror_uuid
,
567 snapid_t primary_snap_id
,
569 uint64_t last_copied_object_number
,
570 const SnapSeqs
& snap_seqs
)
571 : state(state
), complete(complete
), mirror_peer_uuids(mirror_peer_uuids
),
572 primary_mirror_uuid(primary_mirror_uuid
),
573 primary_snap_id(primary_snap_id
),
574 last_copied_object_number(last_copied_object_number
),
575 snap_seqs(snap_seqs
) {
578 inline bool is_primary() const {
579 return (state
== MIRROR_SNAPSHOT_STATE_PRIMARY
||
580 state
== MIRROR_SNAPSHOT_STATE_PRIMARY_DEMOTED
);
583 inline bool is_non_primary() const {
584 return (state
== MIRROR_SNAPSHOT_STATE_NON_PRIMARY
||
585 state
== MIRROR_SNAPSHOT_STATE_NON_PRIMARY_DEMOTED
);
588 inline bool is_demoted() const {
589 return (state
== MIRROR_SNAPSHOT_STATE_PRIMARY_DEMOTED
||
590 state
== MIRROR_SNAPSHOT_STATE_NON_PRIMARY_DEMOTED
);
593 inline bool is_orphan() const {
594 return (is_non_primary() &&
595 primary_mirror_uuid
.empty() &&
596 primary_snap_id
== CEPH_NOSNAP
);
599 void encode(bufferlist
& bl
) const;
600 void decode(bufferlist::const_iterator
& it
);
602 void dump(Formatter
*f
) const;
604 inline bool operator==(const MirrorSnapshotNamespace
& rhs
) const {
605 return state
== rhs
.state
&&
606 complete
== rhs
.complete
&&
607 mirror_peer_uuids
== rhs
.mirror_peer_uuids
&&
608 primary_mirror_uuid
== rhs
.primary_mirror_uuid
&&
609 primary_snap_id
== rhs
.primary_snap_id
&&
610 last_copied_object_number
== rhs
.last_copied_object_number
&&
611 snap_seqs
== rhs
.snap_seqs
;
614 inline bool operator<(const MirrorSnapshotNamespace
& rhs
) const {
615 if (state
!= rhs
.state
) {
616 return state
< rhs
.state
;
617 } else if (complete
!= rhs
.complete
) {
618 return complete
< rhs
.complete
;
619 } else if (mirror_peer_uuids
!= rhs
.mirror_peer_uuids
) {
620 return mirror_peer_uuids
< rhs
.mirror_peer_uuids
;
621 } else if (primary_mirror_uuid
!= rhs
.primary_mirror_uuid
) {
622 return primary_mirror_uuid
< rhs
.primary_mirror_uuid
;
623 } else if (primary_snap_id
!= rhs
.primary_snap_id
) {
624 return primary_snap_id
< rhs
.primary_snap_id
;
625 } else if (last_copied_object_number
!= rhs
.last_copied_object_number
) {
626 return last_copied_object_number
< rhs
.last_copied_object_number
;
628 return snap_seqs
< rhs
.snap_seqs
;
633 struct UnknownSnapshotNamespace
{
634 static const SnapshotNamespaceType SNAPSHOT_NAMESPACE_TYPE
=
635 static_cast<SnapshotNamespaceType
>(-1);
637 UnknownSnapshotNamespace() {}
639 void encode(bufferlist
& bl
) const {}
640 void decode(bufferlist::const_iterator
& it
) {}
641 void dump(Formatter
*f
) const {}
643 inline bool operator==(const UnknownSnapshotNamespace
& gsn
) const {
647 inline bool operator<(const UnknownSnapshotNamespace
& gsn
) const {
652 std::ostream
& operator<<(std::ostream
& os
, const SnapshotNamespaceType
& type
);
653 std::ostream
& operator<<(std::ostream
& os
, const UserSnapshotNamespace
& ns
);
654 std::ostream
& operator<<(std::ostream
& os
, const GroupSnapshotNamespace
& ns
);
655 std::ostream
& operator<<(std::ostream
& os
, const TrashSnapshotNamespace
& ns
);
656 std::ostream
& operator<<(std::ostream
& os
, const MirrorSnapshotNamespace
& ns
);
657 std::ostream
& operator<<(std::ostream
& os
, const UnknownSnapshotNamespace
& ns
);
659 typedef boost::variant
<UserSnapshotNamespace
,
660 GroupSnapshotNamespace
,
661 TrashSnapshotNamespace
,
662 MirrorSnapshotNamespace
,
663 UnknownSnapshotNamespace
> SnapshotNamespaceVariant
;
665 struct SnapshotNamespace
: public SnapshotNamespaceVariant
{
666 SnapshotNamespace() {
669 template <typename T
>
670 SnapshotNamespace(T
&& t
) : SnapshotNamespaceVariant(std::forward
<T
>(t
)) {
673 void encode(bufferlist
& bl
) const;
674 void decode(bufferlist::const_iterator
& it
);
675 void dump(Formatter
*f
) const;
677 static void generate_test_instances(std::list
<SnapshotNamespace
*> &o
);
679 inline bool operator==(const SnapshotNamespaceVariant
& sn
) const {
680 return static_cast<const SnapshotNamespaceVariant
&>(*this) == sn
;
682 inline bool operator<(const SnapshotNamespaceVariant
& sn
) const {
683 return static_cast<const SnapshotNamespaceVariant
&>(*this) < sn
;
685 inline bool operator!=(const SnapshotNamespaceVariant
& sn
) const {
686 return !(*this == sn
);
689 WRITE_CLASS_ENCODER(SnapshotNamespace
);
691 SnapshotNamespaceType
get_snap_namespace_type(
692 const SnapshotNamespace
& snapshot_namespace
);
694 struct SnapshotInfo
{
695 snapid_t id
= CEPH_NOSNAP
;
696 cls::rbd::SnapshotNamespace snapshot_namespace
= {UserSnapshotNamespace
{}};
698 uint64_t image_size
= 0;
700 uint32_t child_count
= 0;
704 SnapshotInfo(snapid_t id
,
705 const cls::rbd::SnapshotNamespace
& snapshot_namespace
,
706 const std::string
& name
, uint64_t image_size
,
707 const utime_t
& timestamp
, uint32_t child_count
)
708 : id(id
), snapshot_namespace(snapshot_namespace
),
709 name(name
), image_size(image_size
), timestamp(timestamp
),
710 child_count(child_count
) {
713 void encode(bufferlist
& bl
) const;
714 void decode(bufferlist::const_iterator
& it
);
715 void dump(Formatter
*f
) const;
717 static void generate_test_instances(std::list
<SnapshotInfo
*> &o
);
719 WRITE_CLASS_ENCODER(SnapshotInfo
);
721 enum GroupSnapshotState
{
722 GROUP_SNAPSHOT_STATE_INCOMPLETE
= 0,
723 GROUP_SNAPSHOT_STATE_COMPLETE
= 1,
726 inline void encode(const GroupSnapshotState
&state
, bufferlist
& bl
, uint64_t features
=0)
729 encode(static_cast<uint8_t>(state
), bl
);
732 inline void decode(GroupSnapshotState
&state
, bufferlist::const_iterator
& it
)
736 decode(int_state
, it
);
737 state
= static_cast<GroupSnapshotState
>(int_state
);
740 struct ImageSnapshotSpec
{
745 ImageSnapshotSpec() {}
746 ImageSnapshotSpec(int64_t _pool
,
748 snapid_t _snap_id
) : pool(_pool
),
752 void encode(bufferlist
& bl
) const;
753 void decode(bufferlist::const_iterator
& it
);
755 void dump(Formatter
*f
) const;
757 static void generate_test_instances(std::list
<ImageSnapshotSpec
*> &o
);
759 WRITE_CLASS_ENCODER(ImageSnapshotSpec
);
761 struct GroupSnapshot
{
764 GroupSnapshotState state
= GROUP_SNAPSHOT_STATE_INCOMPLETE
;
767 GroupSnapshot(std::string _id
,
769 GroupSnapshotState _state
) : id(_id
),
773 vector
<ImageSnapshotSpec
> snaps
;
775 void encode(bufferlist
& bl
) const;
776 void decode(bufferlist::const_iterator
& it
);
777 void dump(Formatter
*f
) const;
779 static void generate_test_instances(std::list
<GroupSnapshot
*> &o
);
781 WRITE_CLASS_ENCODER(GroupSnapshot
);
782 enum TrashImageSource
{
783 TRASH_IMAGE_SOURCE_USER
= 0,
784 TRASH_IMAGE_SOURCE_MIRRORING
= 1,
785 TRASH_IMAGE_SOURCE_MIGRATION
= 2,
786 TRASH_IMAGE_SOURCE_REMOVING
= 3,
787 TRASH_IMAGE_SOURCE_USER_PARENT
= 4,
790 inline std::ostream
& operator<<(std::ostream
& os
,
791 const TrashImageSource
& source
) {
793 case TRASH_IMAGE_SOURCE_USER
:
796 case TRASH_IMAGE_SOURCE_MIRRORING
:
799 case TRASH_IMAGE_SOURCE_MIGRATION
:
802 case TRASH_IMAGE_SOURCE_REMOVING
:
806 os
<< "unknown (" << static_cast<uint32_t>(source
) << ")";
812 inline void encode(const TrashImageSource
&source
, bufferlist
& bl
,
816 encode(static_cast<uint8_t>(source
), bl
);
819 inline void decode(TrashImageSource
&source
, bufferlist::const_iterator
& it
)
823 decode(int_source
, it
);
824 source
= static_cast<TrashImageSource
>(int_source
);
827 enum TrashImageState
{
828 TRASH_IMAGE_STATE_NORMAL
= 0,
829 TRASH_IMAGE_STATE_MOVING
= 1,
830 TRASH_IMAGE_STATE_REMOVING
= 2,
831 TRASH_IMAGE_STATE_RESTORING
= 3
834 inline void encode(const TrashImageState
&state
, bufferlist
&bl
)
837 encode(static_cast<uint8_t>(state
), bl
);
840 inline void decode(TrashImageState
&state
, bufferlist::const_iterator
&it
)
844 decode(int_state
, it
);
845 state
= static_cast<TrashImageState
>(int_state
);
848 struct TrashImageSpec
{
849 TrashImageSource source
= TRASH_IMAGE_SOURCE_USER
;
851 utime_t deletion_time
; // time of deletion
852 utime_t deferment_end_time
;
853 TrashImageState state
= TRASH_IMAGE_STATE_NORMAL
;
856 TrashImageSpec(TrashImageSource source
, const std::string
&name
,
857 const utime_t
& deletion_time
,
858 const utime_t
& deferment_end_time
)
859 : source(source
), name(name
), deletion_time(deletion_time
),
860 deferment_end_time(deferment_end_time
) {
863 void encode(bufferlist
&bl
) const;
864 void decode(bufferlist::const_iterator
& it
);
865 void dump(Formatter
*f
) const;
867 inline bool operator==(const TrashImageSpec
& rhs
) const {
868 return (source
== rhs
.source
&&
870 deletion_time
== rhs
.deletion_time
&&
871 deferment_end_time
== rhs
.deferment_end_time
);
874 WRITE_CLASS_ENCODER(TrashImageSpec
);
876 struct MirrorImageMap
{
880 MirrorImageMap(const std::string
&instance_id
, utime_t mapped_time
,
881 const bufferlist
&data
)
882 : instance_id(instance_id
),
883 mapped_time(mapped_time
),
887 std::string instance_id
;
891 void encode(bufferlist
&bl
) const;
892 void decode(bufferlist::const_iterator
&it
);
893 void dump(Formatter
*f
) const;
895 static void generate_test_instances(std::list
<MirrorImageMap
*> &o
);
897 bool operator==(const MirrorImageMap
&rhs
) const;
898 bool operator<(const MirrorImageMap
&rhs
) const;
901 std::ostream
& operator<<(std::ostream
& os
, const MirrorImageMap
&image_map
);
903 WRITE_CLASS_ENCODER(MirrorImageMap
);
905 enum MigrationHeaderType
{
906 MIGRATION_HEADER_TYPE_SRC
= 1,
907 MIGRATION_HEADER_TYPE_DST
= 2,
910 inline void encode(const MigrationHeaderType
&type
, bufferlist
& bl
) {
912 encode(static_cast<uint8_t>(type
), bl
);
915 inline void decode(MigrationHeaderType
&type
, bufferlist::const_iterator
& it
) {
918 decode(int_type
, it
);
919 type
= static_cast<MigrationHeaderType
>(int_type
);
922 enum MigrationState
{
923 MIGRATION_STATE_ERROR
= 0,
924 MIGRATION_STATE_PREPARING
= 1,
925 MIGRATION_STATE_PREPARED
= 2,
926 MIGRATION_STATE_EXECUTING
= 3,
927 MIGRATION_STATE_EXECUTED
= 4,
928 MIGRATION_STATE_ABORTING
= 5,
931 inline void encode(const MigrationState
&state
, bufferlist
& bl
) {
933 encode(static_cast<uint8_t>(state
), bl
);
936 inline void decode(MigrationState
&state
, bufferlist::const_iterator
& it
) {
939 decode(int_state
, it
);
940 state
= static_cast<MigrationState
>(int_state
);
943 std::ostream
& operator<<(std::ostream
& os
,
944 const MigrationState
& migration_state
);
946 struct MigrationSpec
{
947 MigrationHeaderType header_type
= MIGRATION_HEADER_TYPE_SRC
;
948 int64_t pool_id
= -1;
949 std::string pool_namespace
;
950 std::string image_name
;
951 std::string image_id
;
952 std::map
<uint64_t, uint64_t> snap_seqs
;
953 uint64_t overlap
= 0;
954 bool flatten
= false;
955 bool mirroring
= false;
956 MirrorImageMode mirror_image_mode
= MIRROR_IMAGE_MODE_JOURNAL
;
957 MigrationState state
= MIGRATION_STATE_ERROR
;
958 std::string state_description
;
962 MigrationSpec(MigrationHeaderType header_type
, int64_t pool_id
,
963 const std::string
& pool_namespace
,
964 const std::string
&image_name
, const std::string
&image_id
,
965 const std::map
<uint64_t, uint64_t> &snap_seqs
, uint64_t overlap
,
966 bool mirroring
, MirrorImageMode mirror_image_mode
, bool flatten
,
967 MigrationState state
, const std::string
&state_description
)
968 : header_type(header_type
), pool_id(pool_id
),
969 pool_namespace(pool_namespace
), image_name(image_name
),
970 image_id(image_id
), snap_seqs(snap_seqs
), overlap(overlap
),
971 flatten(flatten
), mirroring(mirroring
),
972 mirror_image_mode(mirror_image_mode
), state(state
),
973 state_description(state_description
) {
976 void encode(bufferlist
&bl
) const;
977 void decode(bufferlist::const_iterator
& it
);
978 void dump(Formatter
*f
) const;
980 static void generate_test_instances(std::list
<MigrationSpec
*> &o
);
982 inline bool operator==(const MigrationSpec
& ms
) const {
983 return header_type
== ms
.header_type
&& pool_id
== ms
.pool_id
&&
984 pool_namespace
== ms
.pool_namespace
&& image_name
== ms
.image_name
&&
985 image_id
== ms
.image_id
&& snap_seqs
== ms
.snap_seqs
&&
986 overlap
== ms
.overlap
&& flatten
== ms
.flatten
&&
987 mirroring
== ms
.mirroring
&& mirror_image_mode
== ms
.mirror_image_mode
&&
988 state
== ms
.state
&& state_description
== ms
.state_description
;
992 std::ostream
& operator<<(std::ostream
& os
, const MigrationSpec
& migration_spec
);
994 WRITE_CLASS_ENCODER(MigrationSpec
);
996 enum AssertSnapcSeqState
{
997 ASSERT_SNAPC_SEQ_GT_SNAPSET_SEQ
= 0,
998 ASSERT_SNAPC_SEQ_LE_SNAPSET_SEQ
= 1,
1001 inline void encode(const AssertSnapcSeqState
&state
, bufferlist
& bl
) {
1003 encode(static_cast<uint8_t>(state
), bl
);
1006 inline void decode(AssertSnapcSeqState
&state
, bufferlist::const_iterator
& it
) {
1009 decode(int_state
, it
);
1010 state
= static_cast<AssertSnapcSeqState
>(int_state
);
1013 std::ostream
& operator<<(std::ostream
& os
, const AssertSnapcSeqState
& state
);
1015 void sanitize_entity_inst(entity_inst_t
* entity_inst
);
1020 #endif // CEPH_CLS_RBD_TYPES_H