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"
16 #define RBD_GROUP_REF "rbd_group_ref"
18 namespace ceph
{ class Formatter
; }
23 static const uint32_t MAX_OBJECT_MAP_OBJECT_COUNT
= 256000000;
24 static const string RBD_GROUP_IMAGE_KEY_PREFIX
= "image_";
27 MIRROR_MODE_DISABLED
= 0,
28 MIRROR_MODE_IMAGE
= 1,
32 enum GroupImageLinkState
{
33 GROUP_IMAGE_LINK_STATE_ATTACHED
,
34 GROUP_IMAGE_LINK_STATE_INCOMPLETE
37 inline void encode(const GroupImageLinkState
&state
, bufferlist
& bl
,
40 ::encode(static_cast<uint8_t>(state
), bl
);
43 inline void decode(GroupImageLinkState
&state
, bufferlist::iterator
& it
)
46 ::decode(int_state
, it
);
47 state
= static_cast<GroupImageLinkState
>(int_state
);
53 MirrorPeer(const std::string
&uuid
, const std::string
&cluster_name
,
54 const std::string
&client_name
, int64_t pool_id
)
55 : uuid(uuid
), cluster_name(cluster_name
), client_name(client_name
),
60 std::string cluster_name
;
61 std::string client_name
;
64 inline bool is_valid() const {
65 return (!uuid
.empty() && !cluster_name
.empty() && !client_name
.empty());
68 void encode(bufferlist
&bl
) const;
69 void decode(bufferlist::iterator
&it
);
70 void dump(Formatter
*f
) const;
72 static void generate_test_instances(std::list
<MirrorPeer
*> &o
);
74 bool operator==(const MirrorPeer
&rhs
) const;
77 std::ostream
& operator<<(std::ostream
& os
, const MirrorMode
& mirror_mode
);
78 std::ostream
& operator<<(std::ostream
& os
, const MirrorPeer
& peer
);
80 WRITE_CLASS_ENCODER(MirrorPeer
);
82 enum MirrorImageState
{
83 MIRROR_IMAGE_STATE_DISABLING
= 0,
84 MIRROR_IMAGE_STATE_ENABLED
= 1,
85 MIRROR_IMAGE_STATE_DISABLED
= 2,
90 MirrorImage(const std::string
&global_image_id
, MirrorImageState state
)
91 : global_image_id(global_image_id
), state(state
) {}
93 std::string global_image_id
;
94 MirrorImageState state
= MIRROR_IMAGE_STATE_DISABLING
;
96 void encode(bufferlist
&bl
) const;
97 void decode(bufferlist::iterator
&it
);
98 void dump(Formatter
*f
) const;
100 static void generate_test_instances(std::list
<MirrorImage
*> &o
);
102 bool operator==(const MirrorImage
&rhs
) const;
103 bool operator<(const MirrorImage
&rhs
) const;
106 std::ostream
& operator<<(std::ostream
& os
, const MirrorImageState
& mirror_state
);
107 std::ostream
& operator<<(std::ostream
& os
, const MirrorImage
& mirror_image
);
109 WRITE_CLASS_ENCODER(MirrorImage
);
111 enum MirrorImageStatusState
{
112 MIRROR_IMAGE_STATUS_STATE_UNKNOWN
= 0,
113 MIRROR_IMAGE_STATUS_STATE_ERROR
= 1,
114 MIRROR_IMAGE_STATUS_STATE_SYNCING
= 2,
115 MIRROR_IMAGE_STATUS_STATE_STARTING_REPLAY
= 3,
116 MIRROR_IMAGE_STATUS_STATE_REPLAYING
= 4,
117 MIRROR_IMAGE_STATUS_STATE_STOPPING_REPLAY
= 5,
118 MIRROR_IMAGE_STATUS_STATE_STOPPED
= 6,
121 inline void encode(const MirrorImageStatusState
&state
, bufferlist
& bl
,
124 ::encode(static_cast<uint8_t>(state
), bl
);
127 inline void decode(MirrorImageStatusState
&state
, bufferlist::iterator
& it
)
130 ::decode(int_state
, it
);
131 state
= static_cast<MirrorImageStatusState
>(int_state
);
134 struct MirrorImageStatus
{
135 MirrorImageStatus() {}
136 MirrorImageStatus(MirrorImageStatusState state
,
137 const std::string
&description
= "")
138 : state(state
), description(description
) {}
140 MirrorImageStatusState state
= MIRROR_IMAGE_STATUS_STATE_UNKNOWN
;
141 std::string description
;
145 void encode(bufferlist
&bl
) const;
146 void decode(bufferlist::iterator
&it
);
147 void dump(Formatter
*f
) const;
149 std::string
state_to_string() const;
151 static void generate_test_instances(std::list
<MirrorImageStatus
*> &o
);
153 bool operator==(const MirrorImageStatus
&rhs
) const;
156 std::ostream
& operator<<(std::ostream
& os
, const MirrorImageStatus
& status
);
157 std::ostream
& operator<<(std::ostream
& os
, const MirrorImageStatusState
& state
);
159 WRITE_CLASS_ENCODER(MirrorImageStatus
);
161 struct GroupImageSpec
{
164 GroupImageSpec(const std::string
&image_id
, int64_t pool_id
)
165 : image_id(image_id
), pool_id(pool_id
) {}
167 static int from_key(const std::string
&image_key
, GroupImageSpec
*spec
);
169 std::string image_id
;
170 int64_t pool_id
= -1;
172 void encode(bufferlist
&bl
) const;
173 void decode(bufferlist::iterator
&it
);
174 void dump(Formatter
*f
) const;
176 std::string
image_key();
180 WRITE_CLASS_ENCODER(GroupImageSpec
);
182 struct GroupImageStatus
{
183 GroupImageStatus() {}
184 GroupImageStatus(const std::string
&image_id
,
186 GroupImageLinkState state
)
187 : spec(image_id
, pool_id
), state(state
) {}
189 GroupImageStatus(GroupImageSpec spec
,
190 GroupImageLinkState state
)
191 : spec(spec
), state(state
) {}
194 GroupImageLinkState state
= GROUP_IMAGE_LINK_STATE_INCOMPLETE
;
196 void encode(bufferlist
&bl
) const;
197 void decode(bufferlist::iterator
&it
);
198 void dump(Formatter
*f
) const;
200 std::string
state_to_string() const;
203 WRITE_CLASS_ENCODER(GroupImageStatus
);
207 GroupSpec(const std::string
&group_id
, int64_t pool_id
)
208 : group_id(group_id
), pool_id(pool_id
) {}
210 std::string group_id
;
211 int64_t pool_id
= -1;
213 void encode(bufferlist
&bl
) const;
214 void decode(bufferlist::iterator
&it
);
215 void dump(Formatter
*f
) const;
216 bool is_valid() const;
219 WRITE_CLASS_ENCODER(GroupSpec
);
221 enum SnapshotNamespaceType
{
222 SNAPSHOT_NAMESPACE_TYPE_USER
= 0
225 struct UserSnapshotNamespace
{
226 static const uint32_t SNAPSHOT_NAMESPACE_TYPE
= SNAPSHOT_NAMESPACE_TYPE_USER
;
228 UserSnapshotNamespace() {}
230 void encode(bufferlist
& bl
) const {}
231 void decode(bufferlist::iterator
& it
) {}
233 void dump(Formatter
*f
) const {}
235 inline bool operator==(const UserSnapshotNamespace
& usn
) const {
239 inline bool operator<(const UserSnapshotNamespace
& usn
) const {
245 std::ostream
& operator<<(std::ostream
& os
, const UserSnapshotNamespace
& ns
);
247 struct UnknownSnapshotNamespace
{
248 static const uint32_t SNAPSHOT_NAMESPACE_TYPE
= static_cast<uint32_t>(-1);
250 UnknownSnapshotNamespace() {}
252 void encode(bufferlist
& bl
) const {}
253 void decode(bufferlist::iterator
& it
) {}
254 void dump(Formatter
*f
) const {}
255 inline bool operator==(const UnknownSnapshotNamespace
& gsn
) const {
259 inline bool operator<(const UnknownSnapshotNamespace
& usn
) const {
264 std::ostream
& operator<<(std::ostream
& os
, const UnknownSnapshotNamespace
& ns
);
266 typedef boost::variant
<UserSnapshotNamespace
, UnknownSnapshotNamespace
> SnapshotNamespace
;
269 struct SnapshotNamespaceOnDisk
{
271 SnapshotNamespaceOnDisk() : snapshot_namespace(UnknownSnapshotNamespace()) {}
272 SnapshotNamespaceOnDisk(const SnapshotNamespace
&sn
) : snapshot_namespace(sn
) {}
274 SnapshotNamespace snapshot_namespace
;
276 SnapshotNamespaceType
get_namespace_type() const;
278 void encode(bufferlist
& bl
) const;
279 void decode(bufferlist::iterator
& it
);
280 void dump(Formatter
*f
) const;
282 static void generate_test_instances(std::list
<SnapshotNamespaceOnDisk
*> &o
);
284 inline bool operator==(const SnapshotNamespaceOnDisk
& gsn
) const {
285 return snapshot_namespace
== gsn
.snapshot_namespace
;
288 WRITE_CLASS_ENCODER(SnapshotNamespaceOnDisk
);
290 enum TrashImageSource
{
291 TRASH_IMAGE_SOURCE_USER
= 0,
292 TRASH_IMAGE_SOURCE_MIRRORING
= 1
295 inline void encode(const TrashImageSource
&source
, bufferlist
& bl
,
298 ::encode(static_cast<uint8_t>(source
), bl
);
301 inline void decode(TrashImageSource
&source
, bufferlist::iterator
& it
)
304 ::decode(int_source
, it
);
305 source
= static_cast<TrashImageSource
>(int_source
);
308 struct TrashImageSpec
{
309 TrashImageSource source
= TRASH_IMAGE_SOURCE_USER
;
311 utime_t deletion_time
; // time of deletion
312 utime_t deferment_end_time
;
315 TrashImageSpec(TrashImageSource source
, const std::string
&name
,
316 utime_t deletion_time
, utime_t deferment_end_time
) :
317 source(source
), name(name
), deletion_time(deletion_time
),
318 deferment_end_time(deferment_end_time
) {}
320 void encode(bufferlist
&bl
) const;
321 void decode(bufferlist::iterator
& it
);
322 void dump(Formatter
*f
) const;
324 WRITE_CLASS_ENCODER(TrashImageSpec
);
329 using cls::rbd::encode
;
330 using cls::rbd::decode
;
332 #endif // CEPH_CLS_RBD_TYPES_H