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,
223 SNAPSHOT_NAMESPACE_TYPE_GROUP = 1
226 struct UserSnapshotNamespace {
227 static const uint32_t SNAPSHOT_NAMESPACE_TYPE = SNAPSHOT_NAMESPACE_TYPE_USER;
229 UserSnapshotNamespace() {}
231 void encode(bufferlist& bl) const {}
232 void decode(bufferlist::iterator& it) {}
234 void dump(Formatter *f) const {}
236 inline bool operator==(const UserSnapshotNamespace& usn) const {
240 inline bool operator<(const UserSnapshotNamespace& usn) const {
246 std::ostream& operator<<(std::ostream& os, const UserSnapshotNamespace& ns);
248 struct GroupSnapshotNamespace {
249 static const uint32_t SNAPSHOT_NAMESPACE_TYPE = SNAPSHOT_NAMESPACE_TYPE_GROUP;
251 GroupSnapshotNamespace() {}
253 GroupSnapshotNamespace(int64_t _group_pool,
254 const string &_group_id,
255 const snapid_t &_snapshot_id) :group_pool(_group_pool),
257 snapshot_id(_snapshot_id) {}
261 snapid_t snapshot_id;
263 void encode(bufferlist& bl) const;
264 void decode(bufferlist::iterator& it);
266 void dump(Formatter *f) const;
268 inline bool operator==(const GroupSnapshotNamespace& gsn) const {
269 return group_pool == gsn.group_pool &&
270 group_id == gsn.group_id &&
271 snapshot_id == gsn.snapshot_id;
274 inline bool operator<(const GroupSnapshotNamespace& gsn) const {
275 if (group_pool < gsn.group_pool) {
277 } else if (group_id < gsn.group_id) {
280 return snapshot_id < gsn.snapshot_id;
286 std::ostream& operator<<(std::ostream& os, const GroupSnapshotNamespace& ns);
288 struct UnknownSnapshotNamespace {
289 static const uint32_t SNAPSHOT_NAMESPACE_TYPE = static_cast<uint32_t>(-1);
291 UnknownSnapshotNamespace() {}
293 void encode(bufferlist& bl) const {}
294 void decode(bufferlist::iterator& it) {}
295 void dump(Formatter *f) const {}
296 inline bool operator==(const UnknownSnapshotNamespace& gsn) const {
300 inline bool operator<(const UnknownSnapshotNamespace& usn) const {
305 std::ostream& operator<<(std::ostream& os, const UnknownSnapshotNamespace& ns);
307 typedef boost::variant<UserSnapshotNamespace, GroupSnapshotNamespace, UnknownSnapshotNamespace> SnapshotNamespace;
310 struct SnapshotNamespaceOnDisk {
312 SnapshotNamespaceOnDisk() : snapshot_namespace(UnknownSnapshotNamespace()) {}
313 SnapshotNamespaceOnDisk(const SnapshotNamespace &sn) : snapshot_namespace(sn) {}
315 SnapshotNamespace snapshot_namespace;
317 SnapshotNamespaceType get_namespace_type() const;
319 void encode(bufferlist& bl) const;
320 void decode(bufferlist::iterator& it);
321 void dump(Formatter *f) const;
323 static void generate_test_instances(std::list<SnapshotNamespaceOnDisk *> &o);
325 inline bool operator==(const SnapshotNamespaceOnDisk& gsn) const {
326 return snapshot_namespace == gsn.snapshot_namespace;
329 WRITE_CLASS_ENCODER(SnapshotNamespaceOnDisk);
331 enum TrashImageSource {
332 TRASH_IMAGE_SOURCE_USER = 0,
333 TRASH_IMAGE_SOURCE_MIRRORING = 1
336 inline void encode(const TrashImageSource &source, bufferlist& bl,
339 ::encode(static_cast<uint8_t>(source), bl);
342 inline void decode(TrashImageSource &source, bufferlist::iterator& it)
345 ::decode(int_source, it);
346 source = static_cast<TrashImageSource>(int_source);
349 struct TrashImageSpec {
350 TrashImageSource source = TRASH_IMAGE_SOURCE_USER;
352 utime_t deletion_time; // time of deletion
353 utime_t deferment_end_time;
356 TrashImageSpec(TrashImageSource source, const std::string &name,
357 utime_t deletion_time, utime_t deferment_end_time) :
358 source(source), name(name), deletion_time(deletion_time),
359 deferment_end_time(deferment_end_time) {}
361 void encode(bufferlist &bl) const;
362 void decode(bufferlist::iterator& it);
363 void dump(Formatter *f) const;
365 WRITE_CLASS_ENCODER(TrashImageSpec);
370 using cls::rbd::encode;
371 using cls::rbd::decode;
373 #endif // CEPH_CLS_RBD_TYPES_H