]> git.proxmox.com Git - ceph.git/blob - ceph/src/cls/rbd/cls_rbd_types.h
b2c155eb864a2378101b2e27addd94c742efce73
[ceph.git] / ceph / src / cls / rbd / cls_rbd_types.h
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
3
4 #ifndef CEPH_CLS_RBD_TYPES_H
5 #define CEPH_CLS_RBD_TYPES_H
6
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"
14 #include <iosfwd>
15 #include <string>
16 #include <set>
17
18 #define RBD_GROUP_REF "rbd_group_ref"
19
20 namespace ceph { class Formatter; }
21
22 namespace cls {
23 namespace rbd {
24
25 static const uint32_t MAX_OBJECT_MAP_OBJECT_COUNT = 256000000;
26 static const string RBD_GROUP_IMAGE_KEY_PREFIX = "image_";
27
28 enum DirectoryState {
29 DIRECTORY_STATE_READY = 0,
30 DIRECTORY_STATE_ADD_DISABLED = 1
31 };
32
33 inline void encode(DirectoryState state, bufferlist& bl,
34 uint64_t features=0)
35 {
36 ceph::encode(static_cast<uint8_t>(state), bl);
37 }
38
39 inline void decode(DirectoryState &state, bufferlist::const_iterator& it)
40 {
41 uint8_t int_state;
42 ceph::decode(int_state, it);
43 state = static_cast<DirectoryState>(int_state);
44 }
45
46 enum MirrorMode {
47 MIRROR_MODE_DISABLED = 0,
48 MIRROR_MODE_IMAGE = 1,
49 MIRROR_MODE_POOL = 2
50 };
51
52 enum GroupImageLinkState {
53 GROUP_IMAGE_LINK_STATE_ATTACHED,
54 GROUP_IMAGE_LINK_STATE_INCOMPLETE
55 };
56
57 inline void encode(const GroupImageLinkState &state, bufferlist& bl,
58 uint64_t features=0)
59 {
60 using ceph::encode;
61 encode(static_cast<uint8_t>(state), bl);
62 }
63
64 inline void decode(GroupImageLinkState &state, bufferlist::const_iterator& it)
65 {
66 uint8_t int_state;
67 using ceph::decode;
68 decode(int_state, it);
69 state = static_cast<GroupImageLinkState>(int_state);
70 }
71
72 enum MirrorPeerDirection {
73 MIRROR_PEER_DIRECTION_RX = 0,
74 MIRROR_PEER_DIRECTION_TX = 1,
75 MIRROR_PEER_DIRECTION_RX_TX = 2
76 };
77
78 std::ostream& operator<<(std::ostream& os,
79 MirrorPeerDirection mirror_peer_direction);
80
81 struct MirrorPeer {
82 MirrorPeer() {
83 }
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) {
92 }
93
94 std::string uuid;
95
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;
100 utime_t last_seen;
101
102 inline bool is_valid() const {
103 switch (mirror_peer_direction) {
104 case MIRROR_PEER_DIRECTION_TX:
105 break;
106 case MIRROR_PEER_DIRECTION_RX:
107 case MIRROR_PEER_DIRECTION_RX_TX:
108 if (client_name.empty()) {
109 return false;
110 }
111 break;
112 default:
113 return false;
114 }
115 return (!uuid.empty() && !site_name.empty());
116 }
117
118 void encode(bufferlist &bl) const;
119 void decode(bufferlist::const_iterator &it);
120 void dump(Formatter *f) const;
121
122 static void generate_test_instances(std::list<MirrorPeer*> &o);
123
124 bool operator==(const MirrorPeer &rhs) const;
125 bool operator!=(const MirrorPeer &rhs) const {
126 return (!(*this == rhs));
127 }
128 };
129
130 std::ostream& operator<<(std::ostream& os, const MirrorMode& mirror_mode);
131 std::ostream& operator<<(std::ostream& os, const MirrorPeer& peer);
132
133 WRITE_CLASS_ENCODER(MirrorPeer);
134
135 enum MirrorImageMode {
136 MIRROR_IMAGE_MODE_JOURNAL = 0,
137 MIRROR_IMAGE_MODE_SNAPSHOT = 1,
138 };
139
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,
145 };
146
147 struct MirrorImage {
148 MirrorImage() {
149 }
150 MirrorImage(MirrorImageMode mode, const std::string &global_image_id,
151 MirrorImageState state)
152 : mode(mode), global_image_id(global_image_id), state(state) {
153 }
154
155 MirrorImageMode mode = MIRROR_IMAGE_MODE_JOURNAL;
156 std::string global_image_id;
157 MirrorImageState state = MIRROR_IMAGE_STATE_DISABLING;
158
159 void encode(bufferlist &bl) const;
160 void decode(bufferlist::const_iterator &it);
161 void dump(Formatter *f) const;
162
163 static void generate_test_instances(std::list<MirrorImage*> &o);
164
165 bool operator==(const MirrorImage &rhs) const;
166 bool operator<(const MirrorImage &rhs) const;
167 };
168
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);
172
173 WRITE_CLASS_ENCODER(MirrorImage);
174
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,
183 };
184
185 inline void encode(const MirrorImageStatusState &state, bufferlist& bl,
186 uint64_t features=0)
187 {
188 using ceph::encode;
189 encode(static_cast<uint8_t>(state), bl);
190 }
191
192 inline void decode(MirrorImageStatusState &state,
193 bufferlist::const_iterator& it)
194 {
195 uint8_t int_state;
196 using ceph::decode;
197 decode(int_state, it);
198 state = static_cast<MirrorImageStatusState>(int_state);
199 }
200
201 std::ostream& operator<<(std::ostream& os, const MirrorImageStatusState& state);
202
203 struct MirrorImageSiteStatus {
204 static const std::string LOCAL_MIRROR_UUID;
205
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) {
211 }
212
213 std::string mirror_uuid = LOCAL_MIRROR_UUID;
214 MirrorImageStatusState state = MIRROR_IMAGE_STATUS_STATE_UNKNOWN;
215 std::string description;
216 utime_t last_update;
217 bool up = false;
218
219 void encode_meta(uint8_t version, bufferlist &bl) const;
220 void decode_meta(uint8_t version, bufferlist::const_iterator &it);
221
222 void encode(bufferlist &bl) const;
223 void decode(bufferlist::const_iterator &it);
224 void dump(Formatter *f) const;
225
226 std::string state_to_string() const;
227
228 bool operator==(const MirrorImageSiteStatus &rhs) const;
229
230 static void generate_test_instances(std::list<MirrorImageSiteStatus*> &o);
231 };
232 WRITE_CLASS_ENCODER(MirrorImageSiteStatus);
233
234 std::ostream& operator<<(std::ostream& os, const MirrorImageSiteStatus& status);
235
236 struct MirrorImageSiteStatusOnDisk : cls::rbd::MirrorImageSiteStatus {
237 entity_inst_t origin;
238
239 MirrorImageSiteStatusOnDisk() {
240 }
241 MirrorImageSiteStatusOnDisk(const cls::rbd::MirrorImageSiteStatus &status) :
242 cls::rbd::MirrorImageSiteStatus(status) {
243 }
244
245 void encode_meta(bufferlist &bl, uint64_t features) const;
246 void decode_meta(bufferlist::const_iterator &it);
247
248 void encode(bufferlist &bl, uint64_t features) const;
249 void decode(bufferlist::const_iterator &it);
250
251 static void generate_test_instances(
252 std::list<MirrorImageSiteStatusOnDisk*> &o);
253 };
254 WRITE_CLASS_ENCODER_FEATURES(MirrorImageSiteStatusOnDisk)
255
256 struct MirrorImageStatus {
257 typedef std::list<MirrorImageSiteStatus> MirrorImageSiteStatuses;
258
259 MirrorImageStatus() {}
260 MirrorImageStatus(const MirrorImageSiteStatuses& statuses)
261 : mirror_image_site_statuses(statuses) {
262 }
263
264 MirrorImageSiteStatuses mirror_image_site_statuses;
265
266 int get_local_mirror_image_site_status(MirrorImageSiteStatus* status) const;
267
268 void encode(bufferlist &bl) const;
269 void decode(bufferlist::const_iterator &it);
270 void dump(Formatter *f) const;
271
272 bool operator==(const MirrorImageStatus& rhs) const;
273
274 static void generate_test_instances(std::list<MirrorImageStatus*> &o);
275 };
276 WRITE_CLASS_ENCODER(MirrorImageStatus);
277
278 std::ostream& operator<<(std::ostream& os, const MirrorImageStatus& status);
279
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;
285
286 ParentImageSpec() {
287 }
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),
291 snap_id(snap_id) {
292 }
293
294 bool exists() const {
295 return (pool_id >= 0 && !image_id.empty() && snap_id != CEPH_NOSNAP);
296 }
297
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));
303 }
304
305 bool operator!=(const ParentImageSpec& rhs) const {
306 return !(*this == rhs);
307 }
308
309 void encode(bufferlist &bl) const;
310 void decode(bufferlist::const_iterator &it);
311 void dump(Formatter *f) const;
312
313 static void generate_test_instances(std::list<ParentImageSpec*> &o);
314 };
315
316 WRITE_CLASS_ENCODER(ParentImageSpec);
317
318 std::ostream& operator<<(std::ostream& os, const ParentImageSpec& rhs);
319
320 struct ChildImageSpec {
321 int64_t pool_id = -1;
322 std::string pool_namespace;
323 std::string image_id;
324
325 ChildImageSpec() {}
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) {
329 }
330
331 void encode(bufferlist &bl) const;
332 void decode(bufferlist::const_iterator &it);
333 void dump(Formatter *f) const;
334
335 static void generate_test_instances(std::list<ChildImageSpec*> &o);
336
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);
341 }
342 inline bool operator<(const ChildImageSpec& rhs) const {
343 if (pool_id != rhs.pool_id) {
344 return pool_id < rhs.pool_id;
345 }
346 if (pool_namespace != rhs.pool_namespace) {
347 return pool_namespace < rhs.pool_namespace;
348 }
349 return image_id < rhs.image_id;
350 }
351 };
352 WRITE_CLASS_ENCODER(ChildImageSpec);
353
354 std::ostream& operator<<(std::ostream& os, const ChildImageSpec& rhs);
355
356 typedef std::set<ChildImageSpec> ChildImageSpecs;
357
358 struct GroupImageSpec {
359 GroupImageSpec() {}
360
361 GroupImageSpec(const std::string &image_id, int64_t pool_id)
362 : image_id(image_id), pool_id(pool_id) {}
363
364 static int from_key(const std::string &image_key, GroupImageSpec *spec);
365
366 std::string image_id;
367 int64_t pool_id = -1;
368
369 void encode(bufferlist &bl) const;
370 void decode(bufferlist::const_iterator &it);
371 void dump(Formatter *f) const;
372
373 static void generate_test_instances(std::list<GroupImageSpec*> &o);
374
375 std::string image_key();
376
377 };
378 WRITE_CLASS_ENCODER(GroupImageSpec);
379
380 struct GroupImageStatus {
381 GroupImageStatus() {}
382 GroupImageStatus(const std::string &image_id,
383 int64_t pool_id,
384 GroupImageLinkState state)
385 : spec(image_id, pool_id), state(state) {}
386
387 GroupImageStatus(GroupImageSpec spec,
388 GroupImageLinkState state)
389 : spec(spec), state(state) {}
390
391 GroupImageSpec spec;
392 GroupImageLinkState state = GROUP_IMAGE_LINK_STATE_INCOMPLETE;
393
394 void encode(bufferlist &bl) const;
395 void decode(bufferlist::const_iterator &it);
396 void dump(Formatter *f) const;
397
398 static void generate_test_instances(std::list<GroupImageStatus*> &o);
399
400 std::string state_to_string() const;
401 };
402
403 WRITE_CLASS_ENCODER(GroupImageStatus);
404
405 struct GroupSpec {
406 GroupSpec() {}
407 GroupSpec(const std::string &group_id, int64_t pool_id)
408 : group_id(group_id), pool_id(pool_id) {}
409
410 std::string group_id;
411 int64_t pool_id = -1;
412
413 void encode(bufferlist &bl) const;
414 void decode(bufferlist::const_iterator &it);
415 void dump(Formatter *f) const;
416 bool is_valid() const;
417
418 static void generate_test_instances(std::list<GroupSpec *> &o);
419 };
420
421 WRITE_CLASS_ENCODER(GroupSpec);
422
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,
428 };
429
430 struct UserSnapshotNamespace {
431 static const SnapshotNamespaceType SNAPSHOT_NAMESPACE_TYPE =
432 SNAPSHOT_NAMESPACE_TYPE_USER;
433
434 UserSnapshotNamespace() {}
435
436 void encode(bufferlist& bl) const {}
437 void decode(bufferlist::const_iterator& it) {}
438
439 void dump(Formatter *f) const {}
440
441 inline bool operator==(const UserSnapshotNamespace& usn) const {
442 return true;
443 }
444
445 inline bool operator<(const UserSnapshotNamespace& usn) const {
446 return false;
447 }
448 };
449
450 struct GroupSnapshotNamespace {
451 static const SnapshotNamespaceType SNAPSHOT_NAMESPACE_TYPE =
452 SNAPSHOT_NAMESPACE_TYPE_GROUP;
453
454 GroupSnapshotNamespace() {}
455
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) {}
461
462 string group_id;
463 int64_t group_pool = 0;
464 string group_snapshot_id;
465
466 void encode(bufferlist& bl) const;
467 void decode(bufferlist::const_iterator& it);
468
469 void dump(Formatter *f) const;
470
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;
475 }
476
477 inline bool operator<(const GroupSnapshotNamespace& gsn) const {
478 if (group_pool < gsn.group_pool) {
479 return true;
480 } else if (group_id < gsn.group_id) {
481 return true;
482 } else {
483 return (group_snapshot_id < gsn.group_snapshot_id);
484 }
485 return false;
486 }
487 };
488
489 struct TrashSnapshotNamespace {
490 static const SnapshotNamespaceType SNAPSHOT_NAMESPACE_TYPE =
491 SNAPSHOT_NAMESPACE_TYPE_TRASH;
492
493 std::string original_name;
494 SnapshotNamespaceType original_snapshot_namespace_type =
495 SNAPSHOT_NAMESPACE_TYPE_USER;
496
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) {}
502
503 void encode(bufferlist& bl) const;
504 void decode(bufferlist::const_iterator& it);
505 void dump(Formatter *f) const;
506
507 inline bool operator==(const TrashSnapshotNamespace& usn) const {
508 return true;
509 }
510 inline bool operator<(const TrashSnapshotNamespace& usn) const {
511 return false;
512 }
513 };
514
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,
520 };
521
522 inline void encode(const MirrorSnapshotState &state, bufferlist& bl,
523 uint64_t features=0) {
524 using ceph::encode;
525 encode(static_cast<uint8_t>(state), bl);
526 }
527
528 inline void decode(MirrorSnapshotState &state, bufferlist::const_iterator& it) {
529 using ceph::decode;
530 uint8_t int_state;
531 decode(int_state, it);
532 state = static_cast<MirrorSnapshotState>(int_state);
533 }
534
535 std::ostream& operator<<(std::ostream& os, MirrorSnapshotState type);
536
537 typedef std::map<uint64_t, uint64_t> SnapSeqs;
538
539 struct MirrorSnapshotNamespace {
540 static const SnapshotNamespaceType SNAPSHOT_NAMESPACE_TYPE =
541 SNAPSHOT_NAMESPACE_TYPE_MIRROR;
542
543 MirrorSnapshotState state = MIRROR_SNAPSHOT_STATE_NON_PRIMARY;
544 bool complete = false;
545 std::set<std::string> mirror_peer_uuids;
546
547 std::string primary_mirror_uuid;
548 snapid_t primary_snap_id = CEPH_NOSNAP;
549 uint64_t last_copied_object_number = 0;
550 SnapSeqs snap_seqs;
551
552 MirrorSnapshotNamespace() {
553 }
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) {
561 }
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,
566 bool complete,
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) {
574 }
575
576 inline bool is_primary() const {
577 return (state == MIRROR_SNAPSHOT_STATE_PRIMARY ||
578 state == MIRROR_SNAPSHOT_STATE_PRIMARY_DEMOTED);
579 }
580
581 inline bool is_non_primary() const {
582 return (state == MIRROR_SNAPSHOT_STATE_NON_PRIMARY ||
583 state == MIRROR_SNAPSHOT_STATE_NON_PRIMARY_DEMOTED);
584 }
585
586 inline bool is_demoted() const {
587 return (state == MIRROR_SNAPSHOT_STATE_PRIMARY_DEMOTED ||
588 state == MIRROR_SNAPSHOT_STATE_NON_PRIMARY_DEMOTED);
589 }
590
591 inline bool is_orphan() const {
592 return (is_non_primary() &&
593 primary_mirror_uuid.empty() &&
594 primary_snap_id == CEPH_NOSNAP);
595 }
596
597 void encode(bufferlist& bl) const;
598 void decode(bufferlist::const_iterator& it);
599
600 void dump(Formatter *f) const;
601
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;
610 }
611
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;
625 } else {
626 return snap_seqs < rhs.snap_seqs;
627 }
628 }
629 };
630
631 struct UnknownSnapshotNamespace {
632 static const SnapshotNamespaceType SNAPSHOT_NAMESPACE_TYPE =
633 static_cast<SnapshotNamespaceType>(-1);
634
635 UnknownSnapshotNamespace() {}
636
637 void encode(bufferlist& bl) const {}
638 void decode(bufferlist::const_iterator& it) {}
639 void dump(Formatter *f) const {}
640
641 inline bool operator==(const UnknownSnapshotNamespace& gsn) const {
642 return true;
643 }
644
645 inline bool operator<(const UnknownSnapshotNamespace& gsn) const {
646 return false;
647 }
648 };
649
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);
656
657 typedef boost::variant<UserSnapshotNamespace,
658 GroupSnapshotNamespace,
659 TrashSnapshotNamespace,
660 MirrorSnapshotNamespace,
661 UnknownSnapshotNamespace> SnapshotNamespaceVariant;
662
663 struct SnapshotNamespace : public SnapshotNamespaceVariant {
664 SnapshotNamespace() {
665 }
666
667 template <typename T>
668 SnapshotNamespace(T&& t) : SnapshotNamespaceVariant(std::forward<T>(t)) {
669 }
670
671 void encode(bufferlist& bl) const;
672 void decode(bufferlist::const_iterator& it);
673 void dump(Formatter *f) const;
674
675 static void generate_test_instances(std::list<SnapshotNamespace*> &o);
676
677 inline bool operator==(const SnapshotNamespaceVariant& sn) const {
678 return static_cast<const SnapshotNamespaceVariant&>(*this) == sn;
679 }
680 inline bool operator<(const SnapshotNamespaceVariant& sn) const {
681 return static_cast<const SnapshotNamespaceVariant&>(*this) < sn;
682 }
683 inline bool operator!=(const SnapshotNamespaceVariant& sn) const {
684 return !(*this == sn);
685 }
686 };
687 WRITE_CLASS_ENCODER(SnapshotNamespace);
688
689 SnapshotNamespaceType get_snap_namespace_type(
690 const SnapshotNamespace& snapshot_namespace);
691
692 struct SnapshotInfo {
693 snapid_t id = CEPH_NOSNAP;
694 cls::rbd::SnapshotNamespace snapshot_namespace = {UserSnapshotNamespace{}};
695 std::string name;
696 uint64_t image_size = 0;
697 utime_t timestamp;
698 uint32_t child_count = 0;
699
700 SnapshotInfo() {
701 }
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) {
709 }
710
711 void encode(bufferlist& bl) const;
712 void decode(bufferlist::const_iterator& it);
713 void dump(Formatter *f) const;
714
715 static void generate_test_instances(std::list<SnapshotInfo*> &o);
716 };
717 WRITE_CLASS_ENCODER(SnapshotInfo);
718
719 enum GroupSnapshotState {
720 GROUP_SNAPSHOT_STATE_INCOMPLETE = 0,
721 GROUP_SNAPSHOT_STATE_COMPLETE = 1,
722 };
723
724 inline void encode(const GroupSnapshotState &state, bufferlist& bl, uint64_t features=0)
725 {
726 using ceph::encode;
727 encode(static_cast<uint8_t>(state), bl);
728 }
729
730 inline void decode(GroupSnapshotState &state, bufferlist::const_iterator& it)
731 {
732 using ceph::decode;
733 uint8_t int_state;
734 decode(int_state, it);
735 state = static_cast<GroupSnapshotState>(int_state);
736 }
737
738 struct ImageSnapshotSpec {
739 int64_t pool;
740 string image_id;
741 snapid_t snap_id;
742
743 ImageSnapshotSpec() {}
744 ImageSnapshotSpec(int64_t _pool,
745 string _image_id,
746 snapid_t _snap_id) : pool(_pool),
747 image_id(_image_id),
748 snap_id(_snap_id) {}
749
750 void encode(bufferlist& bl) const;
751 void decode(bufferlist::const_iterator& it);
752
753 void dump(Formatter *f) const;
754
755 static void generate_test_instances(std::list<ImageSnapshotSpec *> &o);
756 };
757 WRITE_CLASS_ENCODER(ImageSnapshotSpec);
758
759 struct GroupSnapshot {
760 std::string id;
761 std::string name;
762 GroupSnapshotState state = GROUP_SNAPSHOT_STATE_INCOMPLETE;
763
764 GroupSnapshot() {}
765 GroupSnapshot(std::string _id,
766 std::string _name,
767 GroupSnapshotState _state) : id(_id),
768 name(_name),
769 state(_state) {}
770
771 vector<ImageSnapshotSpec> snaps;
772
773 void encode(bufferlist& bl) const;
774 void decode(bufferlist::const_iterator& it);
775 void dump(Formatter *f) const;
776
777 static void generate_test_instances(std::list<GroupSnapshot *> &o);
778 };
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,
786 };
787
788 inline std::ostream& operator<<(std::ostream& os,
789 const TrashImageSource& source) {
790 switch (source) {
791 case TRASH_IMAGE_SOURCE_USER:
792 os << "user";
793 break;
794 case TRASH_IMAGE_SOURCE_MIRRORING:
795 os << "mirroring";
796 break;
797 case TRASH_IMAGE_SOURCE_MIGRATION:
798 os << "migration";
799 break;
800 case TRASH_IMAGE_SOURCE_REMOVING:
801 os << "removing";
802 break;
803 default:
804 os << "unknown (" << static_cast<uint32_t>(source) << ")";
805 break;
806 }
807 return os;
808 }
809
810 inline void encode(const TrashImageSource &source, bufferlist& bl,
811 uint64_t features=0)
812 {
813 using ceph::encode;
814 encode(static_cast<uint8_t>(source), bl);
815 }
816
817 inline void decode(TrashImageSource &source, bufferlist::const_iterator& it)
818 {
819 uint8_t int_source;
820 using ceph::decode;
821 decode(int_source, it);
822 source = static_cast<TrashImageSource>(int_source);
823 }
824
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
830 };
831
832 inline void encode(const TrashImageState &state, bufferlist &bl)
833 {
834 using ceph::encode;
835 encode(static_cast<uint8_t>(state), bl);
836 }
837
838 inline void decode(TrashImageState &state, bufferlist::const_iterator &it)
839 {
840 uint8_t int_state;
841 using ceph::decode;
842 decode(int_state, it);
843 state = static_cast<TrashImageState>(int_state);
844 }
845
846 struct TrashImageSpec {
847 TrashImageSource source = TRASH_IMAGE_SOURCE_USER;
848 std::string name;
849 utime_t deletion_time; // time of deletion
850 utime_t deferment_end_time;
851 TrashImageState state = TRASH_IMAGE_STATE_NORMAL;
852
853 TrashImageSpec() {}
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) {
859 }
860
861 void encode(bufferlist &bl) const;
862 void decode(bufferlist::const_iterator& it);
863 void dump(Formatter *f) const;
864
865 inline bool operator==(const TrashImageSpec& rhs) const {
866 return (source == rhs.source &&
867 name == rhs.name &&
868 deletion_time == rhs.deletion_time &&
869 deferment_end_time == rhs.deferment_end_time);
870 }
871 };
872 WRITE_CLASS_ENCODER(TrashImageSpec);
873
874 struct MirrorImageMap {
875 MirrorImageMap() {
876 }
877
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),
882 data(data) {
883 }
884
885 std::string instance_id;
886 utime_t mapped_time;
887 bufferlist data;
888
889 void encode(bufferlist &bl) const;
890 void decode(bufferlist::const_iterator &it);
891 void dump(Formatter *f) const;
892
893 static void generate_test_instances(std::list<MirrorImageMap*> &o);
894
895 bool operator==(const MirrorImageMap &rhs) const;
896 bool operator<(const MirrorImageMap &rhs) const;
897 };
898
899 std::ostream& operator<<(std::ostream& os, const MirrorImageMap &image_map);
900
901 WRITE_CLASS_ENCODER(MirrorImageMap);
902
903 enum MigrationHeaderType {
904 MIGRATION_HEADER_TYPE_SRC = 1,
905 MIGRATION_HEADER_TYPE_DST = 2,
906 };
907
908 inline void encode(const MigrationHeaderType &type, bufferlist& bl) {
909 using ceph::encode;
910 encode(static_cast<uint8_t>(type), bl);
911 }
912
913 inline void decode(MigrationHeaderType &type, bufferlist::const_iterator& it) {
914 uint8_t int_type;
915 using ceph::decode;
916 decode(int_type, it);
917 type = static_cast<MigrationHeaderType>(int_type);
918 }
919
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,
926 };
927
928 inline void encode(const MigrationState &state, bufferlist& bl) {
929 using ceph::encode;
930 encode(static_cast<uint8_t>(state), bl);
931 }
932
933 inline void decode(MigrationState &state, bufferlist::const_iterator& it) {
934 uint8_t int_state;
935 using ceph::decode;
936 decode(int_state, it);
937 state = static_cast<MigrationState>(int_state);
938 }
939
940 std::ostream& operator<<(std::ostream& os,
941 const MigrationState& migration_state);
942
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;
956
957 MigrationSpec() {
958 }
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) {
971 }
972
973 void encode(bufferlist &bl) const;
974 void decode(bufferlist::const_iterator& it);
975 void dump(Formatter *f) const;
976
977 static void generate_test_instances(std::list<MigrationSpec*> &o);
978
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;
986 }
987 };
988
989 std::ostream& operator<<(std::ostream& os, const MigrationSpec& migration_spec);
990
991 WRITE_CLASS_ENCODER(MigrationSpec);
992
993 enum AssertSnapcSeqState {
994 ASSERT_SNAPC_SEQ_GT_SNAPSET_SEQ = 0,
995 ASSERT_SNAPC_SEQ_LE_SNAPSET_SEQ = 1,
996 };
997
998 inline void encode(const AssertSnapcSeqState &state, bufferlist& bl) {
999 using ceph::encode;
1000 encode(static_cast<uint8_t>(state), bl);
1001 }
1002
1003 inline void decode(AssertSnapcSeqState &state, bufferlist::const_iterator& it) {
1004 uint8_t int_state;
1005 using ceph::decode;
1006 decode(int_state, it);
1007 state = static_cast<AssertSnapcSeqState>(int_state);
1008 }
1009
1010 std::ostream& operator<<(std::ostream& os, const AssertSnapcSeqState& state);
1011
1012 void sanitize_entity_inst(entity_inst_t* entity_inst);
1013
1014 } // namespace rbd
1015 } // namespace cls
1016
1017 #endif // CEPH_CLS_RBD_TYPES_H