]> git.proxmox.com Git - ceph.git/blob - ceph/src/cls/rbd/cls_rbd_types.h
e940b660e68077d6c4603b89ad90ed617fe145ea
[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 group_pool < gsn.group_pool;
480 }
481 if (group_id != gsn.group_id) {
482 return group_id < gsn.group_id;
483 }
484 return group_snapshot_id < gsn.group_snapshot_id;
485 }
486 };
487
488 struct TrashSnapshotNamespace {
489 static const SnapshotNamespaceType SNAPSHOT_NAMESPACE_TYPE =
490 SNAPSHOT_NAMESPACE_TYPE_TRASH;
491
492 std::string original_name;
493 SnapshotNamespaceType original_snapshot_namespace_type =
494 SNAPSHOT_NAMESPACE_TYPE_USER;
495
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) {}
501
502 void encode(bufferlist& bl) const;
503 void decode(bufferlist::const_iterator& it);
504 void dump(Formatter *f) const;
505
506 inline bool operator==(const TrashSnapshotNamespace& usn) const {
507 return true;
508 }
509 inline bool operator<(const TrashSnapshotNamespace& usn) const {
510 return false;
511 }
512 };
513
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,
519 };
520
521 inline void encode(const MirrorSnapshotState &state, bufferlist& bl,
522 uint64_t features=0) {
523 using ceph::encode;
524 encode(static_cast<uint8_t>(state), bl);
525 }
526
527 inline void decode(MirrorSnapshotState &state, bufferlist::const_iterator& it) {
528 using ceph::decode;
529 uint8_t int_state;
530 decode(int_state, it);
531 state = static_cast<MirrorSnapshotState>(int_state);
532 }
533
534 std::ostream& operator<<(std::ostream& os, MirrorSnapshotState type);
535
536 typedef std::map<uint64_t, uint64_t> SnapSeqs;
537
538 struct MirrorSnapshotNamespace {
539 static const SnapshotNamespaceType SNAPSHOT_NAMESPACE_TYPE =
540 SNAPSHOT_NAMESPACE_TYPE_MIRROR;
541
542 MirrorSnapshotState state = MIRROR_SNAPSHOT_STATE_NON_PRIMARY;
543 bool complete = false;
544 std::set<std::string> mirror_peer_uuids;
545
546 std::string primary_mirror_uuid;
547 union {
548 snapid_t primary_snap_id = CEPH_NOSNAP;
549 snapid_t clean_since_snap_id;
550 };
551 uint64_t last_copied_object_number = 0;
552 SnapSeqs snap_seqs;
553
554 MirrorSnapshotNamespace() {
555 }
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) {
563 }
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,
568 bool complete,
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) {
576 }
577
578 inline bool is_primary() const {
579 return (state == MIRROR_SNAPSHOT_STATE_PRIMARY ||
580 state == MIRROR_SNAPSHOT_STATE_PRIMARY_DEMOTED);
581 }
582
583 inline bool is_non_primary() const {
584 return (state == MIRROR_SNAPSHOT_STATE_NON_PRIMARY ||
585 state == MIRROR_SNAPSHOT_STATE_NON_PRIMARY_DEMOTED);
586 }
587
588 inline bool is_demoted() const {
589 return (state == MIRROR_SNAPSHOT_STATE_PRIMARY_DEMOTED ||
590 state == MIRROR_SNAPSHOT_STATE_NON_PRIMARY_DEMOTED);
591 }
592
593 inline bool is_orphan() const {
594 return (is_non_primary() &&
595 primary_mirror_uuid.empty() &&
596 primary_snap_id == CEPH_NOSNAP);
597 }
598
599 void encode(bufferlist& bl) const;
600 void decode(bufferlist::const_iterator& it);
601
602 void dump(Formatter *f) const;
603
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;
612 }
613
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;
627 } else {
628 return snap_seqs < rhs.snap_seqs;
629 }
630 }
631 };
632
633 struct UnknownSnapshotNamespace {
634 static const SnapshotNamespaceType SNAPSHOT_NAMESPACE_TYPE =
635 static_cast<SnapshotNamespaceType>(-1);
636
637 UnknownSnapshotNamespace() {}
638
639 void encode(bufferlist& bl) const {}
640 void decode(bufferlist::const_iterator& it) {}
641 void dump(Formatter *f) const {}
642
643 inline bool operator==(const UnknownSnapshotNamespace& gsn) const {
644 return true;
645 }
646
647 inline bool operator<(const UnknownSnapshotNamespace& gsn) const {
648 return false;
649 }
650 };
651
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);
658
659 typedef boost::variant<UserSnapshotNamespace,
660 GroupSnapshotNamespace,
661 TrashSnapshotNamespace,
662 MirrorSnapshotNamespace,
663 UnknownSnapshotNamespace> SnapshotNamespaceVariant;
664
665 struct SnapshotNamespace : public SnapshotNamespaceVariant {
666 SnapshotNamespace() {
667 }
668
669 template <typename T>
670 SnapshotNamespace(T&& t) : SnapshotNamespaceVariant(std::forward<T>(t)) {
671 }
672
673 void encode(bufferlist& bl) const;
674 void decode(bufferlist::const_iterator& it);
675 void dump(Formatter *f) const;
676
677 static void generate_test_instances(std::list<SnapshotNamespace*> &o);
678
679 inline bool operator==(const SnapshotNamespaceVariant& sn) const {
680 return static_cast<const SnapshotNamespaceVariant&>(*this) == sn;
681 }
682 inline bool operator<(const SnapshotNamespaceVariant& sn) const {
683 return static_cast<const SnapshotNamespaceVariant&>(*this) < sn;
684 }
685 inline bool operator!=(const SnapshotNamespaceVariant& sn) const {
686 return !(*this == sn);
687 }
688 };
689 WRITE_CLASS_ENCODER(SnapshotNamespace);
690
691 SnapshotNamespaceType get_snap_namespace_type(
692 const SnapshotNamespace& snapshot_namespace);
693
694 struct SnapshotInfo {
695 snapid_t id = CEPH_NOSNAP;
696 cls::rbd::SnapshotNamespace snapshot_namespace = {UserSnapshotNamespace{}};
697 std::string name;
698 uint64_t image_size = 0;
699 utime_t timestamp;
700 uint32_t child_count = 0;
701
702 SnapshotInfo() {
703 }
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) {
711 }
712
713 void encode(bufferlist& bl) const;
714 void decode(bufferlist::const_iterator& it);
715 void dump(Formatter *f) const;
716
717 static void generate_test_instances(std::list<SnapshotInfo*> &o);
718 };
719 WRITE_CLASS_ENCODER(SnapshotInfo);
720
721 enum GroupSnapshotState {
722 GROUP_SNAPSHOT_STATE_INCOMPLETE = 0,
723 GROUP_SNAPSHOT_STATE_COMPLETE = 1,
724 };
725
726 inline void encode(const GroupSnapshotState &state, bufferlist& bl, uint64_t features=0)
727 {
728 using ceph::encode;
729 encode(static_cast<uint8_t>(state), bl);
730 }
731
732 inline void decode(GroupSnapshotState &state, bufferlist::const_iterator& it)
733 {
734 using ceph::decode;
735 uint8_t int_state;
736 decode(int_state, it);
737 state = static_cast<GroupSnapshotState>(int_state);
738 }
739
740 struct ImageSnapshotSpec {
741 int64_t pool;
742 string image_id;
743 snapid_t snap_id;
744
745 ImageSnapshotSpec() {}
746 ImageSnapshotSpec(int64_t _pool,
747 string _image_id,
748 snapid_t _snap_id) : pool(_pool),
749 image_id(_image_id),
750 snap_id(_snap_id) {}
751
752 void encode(bufferlist& bl) const;
753 void decode(bufferlist::const_iterator& it);
754
755 void dump(Formatter *f) const;
756
757 static void generate_test_instances(std::list<ImageSnapshotSpec *> &o);
758 };
759 WRITE_CLASS_ENCODER(ImageSnapshotSpec);
760
761 struct GroupSnapshot {
762 std::string id;
763 std::string name;
764 GroupSnapshotState state = GROUP_SNAPSHOT_STATE_INCOMPLETE;
765
766 GroupSnapshot() {}
767 GroupSnapshot(std::string _id,
768 std::string _name,
769 GroupSnapshotState _state) : id(_id),
770 name(_name),
771 state(_state) {}
772
773 vector<ImageSnapshotSpec> snaps;
774
775 void encode(bufferlist& bl) const;
776 void decode(bufferlist::const_iterator& it);
777 void dump(Formatter *f) const;
778
779 static void generate_test_instances(std::list<GroupSnapshot *> &o);
780 };
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,
788 };
789
790 inline std::ostream& operator<<(std::ostream& os,
791 const TrashImageSource& source) {
792 switch (source) {
793 case TRASH_IMAGE_SOURCE_USER:
794 os << "user";
795 break;
796 case TRASH_IMAGE_SOURCE_MIRRORING:
797 os << "mirroring";
798 break;
799 case TRASH_IMAGE_SOURCE_MIGRATION:
800 os << "migration";
801 break;
802 case TRASH_IMAGE_SOURCE_REMOVING:
803 os << "removing";
804 break;
805 default:
806 os << "unknown (" << static_cast<uint32_t>(source) << ")";
807 break;
808 }
809 return os;
810 }
811
812 inline void encode(const TrashImageSource &source, bufferlist& bl,
813 uint64_t features=0)
814 {
815 using ceph::encode;
816 encode(static_cast<uint8_t>(source), bl);
817 }
818
819 inline void decode(TrashImageSource &source, bufferlist::const_iterator& it)
820 {
821 uint8_t int_source;
822 using ceph::decode;
823 decode(int_source, it);
824 source = static_cast<TrashImageSource>(int_source);
825 }
826
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
832 };
833
834 inline void encode(const TrashImageState &state, bufferlist &bl)
835 {
836 using ceph::encode;
837 encode(static_cast<uint8_t>(state), bl);
838 }
839
840 inline void decode(TrashImageState &state, bufferlist::const_iterator &it)
841 {
842 uint8_t int_state;
843 using ceph::decode;
844 decode(int_state, it);
845 state = static_cast<TrashImageState>(int_state);
846 }
847
848 struct TrashImageSpec {
849 TrashImageSource source = TRASH_IMAGE_SOURCE_USER;
850 std::string name;
851 utime_t deletion_time; // time of deletion
852 utime_t deferment_end_time;
853 TrashImageState state = TRASH_IMAGE_STATE_NORMAL;
854
855 TrashImageSpec() {}
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) {
861 }
862
863 void encode(bufferlist &bl) const;
864 void decode(bufferlist::const_iterator& it);
865 void dump(Formatter *f) const;
866
867 inline bool operator==(const TrashImageSpec& rhs) const {
868 return (source == rhs.source &&
869 name == rhs.name &&
870 deletion_time == rhs.deletion_time &&
871 deferment_end_time == rhs.deferment_end_time);
872 }
873 };
874 WRITE_CLASS_ENCODER(TrashImageSpec);
875
876 struct MirrorImageMap {
877 MirrorImageMap() {
878 }
879
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),
884 data(data) {
885 }
886
887 std::string instance_id;
888 utime_t mapped_time;
889 bufferlist data;
890
891 void encode(bufferlist &bl) const;
892 void decode(bufferlist::const_iterator &it);
893 void dump(Formatter *f) const;
894
895 static void generate_test_instances(std::list<MirrorImageMap*> &o);
896
897 bool operator==(const MirrorImageMap &rhs) const;
898 bool operator<(const MirrorImageMap &rhs) const;
899 };
900
901 std::ostream& operator<<(std::ostream& os, const MirrorImageMap &image_map);
902
903 WRITE_CLASS_ENCODER(MirrorImageMap);
904
905 enum MigrationHeaderType {
906 MIGRATION_HEADER_TYPE_SRC = 1,
907 MIGRATION_HEADER_TYPE_DST = 2,
908 };
909
910 inline void encode(const MigrationHeaderType &type, bufferlist& bl) {
911 using ceph::encode;
912 encode(static_cast<uint8_t>(type), bl);
913 }
914
915 inline void decode(MigrationHeaderType &type, bufferlist::const_iterator& it) {
916 uint8_t int_type;
917 using ceph::decode;
918 decode(int_type, it);
919 type = static_cast<MigrationHeaderType>(int_type);
920 }
921
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,
929 };
930
931 inline void encode(const MigrationState &state, bufferlist& bl) {
932 using ceph::encode;
933 encode(static_cast<uint8_t>(state), bl);
934 }
935
936 inline void decode(MigrationState &state, bufferlist::const_iterator& it) {
937 uint8_t int_state;
938 using ceph::decode;
939 decode(int_state, it);
940 state = static_cast<MigrationState>(int_state);
941 }
942
943 std::ostream& operator<<(std::ostream& os,
944 const MigrationState& migration_state);
945
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;
959
960 MigrationSpec() {
961 }
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) {
974 }
975
976 void encode(bufferlist &bl) const;
977 void decode(bufferlist::const_iterator& it);
978 void dump(Formatter *f) const;
979
980 static void generate_test_instances(std::list<MigrationSpec*> &o);
981
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;
989 }
990 };
991
992 std::ostream& operator<<(std::ostream& os, const MigrationSpec& migration_spec);
993
994 WRITE_CLASS_ENCODER(MigrationSpec);
995
996 enum AssertSnapcSeqState {
997 ASSERT_SNAPC_SEQ_GT_SNAPSET_SEQ = 0,
998 ASSERT_SNAPC_SEQ_LE_SNAPSET_SEQ = 1,
999 };
1000
1001 inline void encode(const AssertSnapcSeqState &state, bufferlist& bl) {
1002 using ceph::encode;
1003 encode(static_cast<uint8_t>(state), bl);
1004 }
1005
1006 inline void decode(AssertSnapcSeqState &state, bufferlist::const_iterator& it) {
1007 uint8_t int_state;
1008 using ceph::decode;
1009 decode(int_state, it);
1010 state = static_cast<AssertSnapcSeqState>(int_state);
1011 }
1012
1013 std::ostream& operator<<(std::ostream& os, const AssertSnapcSeqState& state);
1014
1015 void sanitize_entity_inst(entity_inst_t* entity_inst);
1016
1017 } // namespace rbd
1018 } // namespace cls
1019
1020 #endif // CEPH_CLS_RBD_TYPES_H