]> git.proxmox.com Git - ceph.git/blob - ceph/src/cls/rbd/cls_rbd_types.cc
import 15.2.2 octopus source
[ceph.git] / ceph / src / cls / rbd / cls_rbd_types.cc
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
3
4 #include <boost/variant.hpp>
5 #include "cls/rbd/cls_rbd_types.h"
6 #include "common/Formatter.h"
7
8 namespace cls {
9 namespace rbd {
10
11 std::ostream& operator<<(std::ostream& os,
12 MirrorPeerDirection mirror_peer_direction) {
13 switch (mirror_peer_direction) {
14 case MIRROR_PEER_DIRECTION_RX:
15 os << "RX";
16 break;
17 case MIRROR_PEER_DIRECTION_TX:
18 os << "TX";
19 break;
20 case MIRROR_PEER_DIRECTION_RX_TX:
21 os << "RX/TX";
22 break;
23 default:
24 os << "unknown";
25 break;
26 }
27 return os;
28 }
29
30 void MirrorPeer::encode(bufferlist &bl) const {
31 ENCODE_START(2, 1, bl);
32 encode(uuid, bl);
33 encode(site_name, bl);
34 encode(client_name, bl);
35 int64_t pool_id = -1;
36 encode(pool_id, bl);
37
38 // v2
39 encode(static_cast<uint8_t>(mirror_peer_direction), bl);
40 encode(mirror_uuid, bl);
41 encode(last_seen, bl);
42 ENCODE_FINISH(bl);
43 }
44
45 void MirrorPeer::decode(bufferlist::const_iterator &it) {
46 DECODE_START(2, it);
47 decode(uuid, it);
48 decode(site_name, it);
49 decode(client_name, it);
50 int64_t pool_id;
51 decode(pool_id, it);
52
53 if (struct_v >= 2) {
54 uint8_t mpd;
55 decode(mpd, it);
56 mirror_peer_direction = static_cast<MirrorPeerDirection>(mpd);
57 decode(mirror_uuid, it);
58 decode(last_seen, it);
59 }
60
61 DECODE_FINISH(it);
62 }
63
64 void MirrorPeer::dump(Formatter *f) const {
65 f->dump_string("uuid", uuid);
66 f->dump_stream("direction") << mirror_peer_direction;
67 f->dump_string("site_name", site_name);
68 f->dump_string("mirror_uuid", mirror_uuid);
69 f->dump_string("client_name", client_name);
70 f->dump_stream("last_seen") << last_seen;
71 }
72
73 void MirrorPeer::generate_test_instances(std::list<MirrorPeer*> &o) {
74 o.push_back(new MirrorPeer());
75 o.push_back(new MirrorPeer("uuid-123", MIRROR_PEER_DIRECTION_RX, "site A",
76 "client name", ""));
77 o.push_back(new MirrorPeer("uuid-234", MIRROR_PEER_DIRECTION_TX, "site B",
78 "", "mirror_uuid"));
79 o.push_back(new MirrorPeer("uuid-345", MIRROR_PEER_DIRECTION_RX_TX, "site C",
80 "client name", "mirror_uuid"));
81 }
82
83 bool MirrorPeer::operator==(const MirrorPeer &rhs) const {
84 return (uuid == rhs.uuid &&
85 mirror_peer_direction == rhs.mirror_peer_direction &&
86 site_name == rhs.site_name &&
87 client_name == rhs.client_name &&
88 mirror_uuid == rhs.mirror_uuid &&
89 last_seen == rhs.last_seen);
90 }
91
92 std::ostream& operator<<(std::ostream& os, const MirrorMode& mirror_mode) {
93 switch (mirror_mode) {
94 case MIRROR_MODE_DISABLED:
95 os << "disabled";
96 break;
97 case MIRROR_MODE_IMAGE:
98 os << "image";
99 break;
100 case MIRROR_MODE_POOL:
101 os << "pool";
102 break;
103 default:
104 os << "unknown (" << static_cast<uint32_t>(mirror_mode) << ")";
105 break;
106 }
107 return os;
108 }
109
110 std::ostream& operator<<(std::ostream& os, const MirrorPeer& peer) {
111 os << "["
112 << "uuid=" << peer.uuid << ", "
113 << "direction=" << peer.mirror_peer_direction << ", "
114 << "site_name=" << peer.site_name << ", "
115 << "client_name=" << peer.client_name << ", "
116 << "mirror_uuid=" << peer.mirror_uuid << ", "
117 << "last_seen=" << peer.last_seen
118 << "]";
119 return os;
120 }
121
122 void MirrorImage::encode(bufferlist &bl) const {
123 ENCODE_START(2, 1, bl);
124 encode(global_image_id, bl);
125 encode(static_cast<uint8_t>(state), bl);
126 encode(static_cast<uint8_t>(mode), bl);
127 ENCODE_FINISH(bl);
128 }
129
130 void MirrorImage::decode(bufferlist::const_iterator &it) {
131 uint8_t int_state;
132 DECODE_START(2, it);
133 decode(global_image_id, it);
134 decode(int_state, it);
135 state = static_cast<MirrorImageState>(int_state);
136 if (struct_v >= 2) {
137 uint8_t int_mode;
138 decode(int_mode, it);
139 mode = static_cast<MirrorImageMode>(int_mode);
140 }
141 DECODE_FINISH(it);
142 }
143
144 void MirrorImage::dump(Formatter *f) const {
145 f->dump_stream("mode") << mode;
146 f->dump_string("global_image_id", global_image_id);
147 f->dump_stream("state") << state;
148 }
149
150 void MirrorImage::generate_test_instances(std::list<MirrorImage*> &o) {
151 o.push_back(new MirrorImage());
152 o.push_back(new MirrorImage(MIRROR_IMAGE_MODE_JOURNAL, "uuid-123",
153 MIRROR_IMAGE_STATE_ENABLED));
154 o.push_back(new MirrorImage(MIRROR_IMAGE_MODE_SNAPSHOT, "uuid-abc",
155 MIRROR_IMAGE_STATE_DISABLING));
156 }
157
158 bool MirrorImage::operator==(const MirrorImage &rhs) const {
159 return mode == rhs.mode && global_image_id == rhs.global_image_id &&
160 state == rhs.state;
161 }
162
163 bool MirrorImage::operator<(const MirrorImage &rhs) const {
164 if (mode != rhs.mode) {
165 return mode < rhs.mode;
166 }
167 if (global_image_id != rhs.global_image_id) {
168 return global_image_id < rhs.global_image_id;
169 }
170 return state < rhs.state;
171 }
172
173 std::ostream& operator<<(std::ostream& os, const MirrorImageMode& mirror_mode) {
174 switch (mirror_mode) {
175 case MIRROR_IMAGE_MODE_JOURNAL:
176 os << "journal";
177 break;
178 case MIRROR_IMAGE_MODE_SNAPSHOT:
179 os << "snapshot";
180 break;
181 default:
182 os << "unknown (" << static_cast<uint32_t>(mirror_mode) << ")";
183 break;
184 }
185 return os;
186 }
187
188 std::ostream& operator<<(std::ostream& os, const MirrorImageState& mirror_state) {
189 switch (mirror_state) {
190 case MIRROR_IMAGE_STATE_DISABLING:
191 os << "disabling";
192 break;
193 case MIRROR_IMAGE_STATE_ENABLED:
194 os << "enabled";
195 break;
196 case MIRROR_IMAGE_STATE_DISABLED:
197 os << "disabled";
198 break;
199 default:
200 os << "unknown (" << static_cast<uint32_t>(mirror_state) << ")";
201 break;
202 }
203 return os;
204 }
205
206 std::ostream& operator<<(std::ostream& os, const MirrorImage& mirror_image) {
207 os << "["
208 << "mode=" << mirror_image.mode << ", "
209 << "global_image_id=" << mirror_image.global_image_id << ", "
210 << "state=" << mirror_image.state << "]";
211 return os;
212 }
213
214 std::ostream& operator<<(std::ostream& os,
215 const MirrorImageStatusState& state) {
216 switch (state) {
217 case MIRROR_IMAGE_STATUS_STATE_UNKNOWN:
218 os << "unknown";
219 break;
220 case MIRROR_IMAGE_STATUS_STATE_ERROR:
221 os << "error";
222 break;
223 case MIRROR_IMAGE_STATUS_STATE_SYNCING:
224 os << "syncing";
225 break;
226 case MIRROR_IMAGE_STATUS_STATE_STARTING_REPLAY:
227 os << "starting_replay";
228 break;
229 case MIRROR_IMAGE_STATUS_STATE_REPLAYING:
230 os << "replaying";
231 break;
232 case MIRROR_IMAGE_STATUS_STATE_STOPPING_REPLAY:
233 os << "stopping_replay";
234 break;
235 case MIRROR_IMAGE_STATUS_STATE_STOPPED:
236 os << "stopped";
237 break;
238 default:
239 os << "unknown (" << static_cast<uint32_t>(state) << ")";
240 break;
241 }
242 return os;
243 }
244
245 const std::string MirrorImageSiteStatus::LOCAL_MIRROR_UUID(""); // empty mirror uuid
246
247 void MirrorImageSiteStatus::encode_meta(uint8_t version, bufferlist &bl) const {
248 if (version >= 2) {
249 ceph::encode(mirror_uuid, bl);
250 }
251 cls::rbd::encode(state, bl);
252 ceph::encode(description, bl);
253 ceph::encode(last_update, bl);
254 ceph::encode(up, bl);
255 }
256
257 void MirrorImageSiteStatus::decode_meta(uint8_t version,
258 bufferlist::const_iterator &it) {
259 if (version < 2) {
260 mirror_uuid = LOCAL_MIRROR_UUID;
261 } else {
262 ceph::decode(mirror_uuid, it);
263 }
264
265 cls::rbd::decode(state, it);
266 ceph::decode(description, it);
267 ::decode(last_update, it);
268 ceph::decode(up, it);
269 }
270
271 void MirrorImageSiteStatus::encode(bufferlist &bl) const {
272 // break compatibility when site-name is provided
273 uint8_t version = (mirror_uuid == LOCAL_MIRROR_UUID ? 1 : 2);
274 ENCODE_START(version, version, bl);
275 encode_meta(version, bl);
276 ENCODE_FINISH(bl);
277 }
278
279 void MirrorImageSiteStatus::decode(bufferlist::const_iterator &it) {
280 DECODE_START(2, it);
281 decode_meta(struct_v, it);
282 DECODE_FINISH(it);
283 }
284
285 void MirrorImageSiteStatus::dump(Formatter *f) const {
286 f->dump_string("state", state_to_string());
287 f->dump_string("description", description);
288 f->dump_stream("last_update") << last_update;
289 }
290
291 std::string MirrorImageSiteStatus::state_to_string() const {
292 std::stringstream ss;
293 ss << (up ? "up+" : "down+") << state;
294 return ss.str();
295 }
296
297 void MirrorImageSiteStatus::generate_test_instances(
298 std::list<MirrorImageSiteStatus*> &o) {
299 o.push_back(new MirrorImageSiteStatus());
300 o.push_back(new MirrorImageSiteStatus("", MIRROR_IMAGE_STATUS_STATE_REPLAYING,
301 ""));
302 o.push_back(new MirrorImageSiteStatus("", MIRROR_IMAGE_STATUS_STATE_ERROR,
303 "error"));
304 o.push_back(new MirrorImageSiteStatus("2fb68ca9-1ba0-43b3-8cdf-8c5a9db71e65",
305 MIRROR_IMAGE_STATUS_STATE_STOPPED, ""));
306 }
307
308 bool MirrorImageSiteStatus::operator==(const MirrorImageSiteStatus &rhs) const {
309 return state == rhs.state && description == rhs.description && up == rhs.up;
310 }
311
312 std::ostream& operator<<(std::ostream& os,
313 const MirrorImageSiteStatus& status) {
314 os << "{"
315 << "state=" << status.state_to_string() << ", "
316 << "description=" << status.description << ", "
317 << "last_update=" << status.last_update << "]}";
318 return os;
319 }
320
321 void MirrorImageSiteStatusOnDisk::encode_meta(bufferlist &bl,
322 uint64_t features) const {
323 ENCODE_START(1, 1, bl);
324 auto sanitized_origin = origin;
325 sanitize_entity_inst(&sanitized_origin);
326 encode(sanitized_origin, bl, features);
327 ENCODE_FINISH(bl);
328 }
329
330 void MirrorImageSiteStatusOnDisk::encode(bufferlist &bl,
331 uint64_t features) const {
332 encode_meta(bl, features);
333 cls::rbd::MirrorImageSiteStatus::encode(bl);
334 }
335
336 void MirrorImageSiteStatusOnDisk::decode_meta(bufferlist::const_iterator &it) {
337 DECODE_START(1, it);
338 decode(origin, it);
339 sanitize_entity_inst(&origin);
340 DECODE_FINISH(it);
341 }
342
343 void MirrorImageSiteStatusOnDisk::decode(bufferlist::const_iterator &it) {
344 decode_meta(it);
345 cls::rbd::MirrorImageSiteStatus::decode(it);
346 }
347
348 void MirrorImageSiteStatusOnDisk::generate_test_instances(
349 std::list<MirrorImageSiteStatusOnDisk*> &o) {
350 o.push_back(new MirrorImageSiteStatusOnDisk());
351 o.push_back(new MirrorImageSiteStatusOnDisk(
352 {"", MIRROR_IMAGE_STATUS_STATE_ERROR, "error"}));
353 o.push_back(new MirrorImageSiteStatusOnDisk(
354 {"siteA", MIRROR_IMAGE_STATUS_STATE_STOPPED, ""}));
355 }
356
357 int MirrorImageStatus::get_local_mirror_image_site_status(
358 MirrorImageSiteStatus* status) const {
359 auto it = std::find_if(
360 mirror_image_site_statuses.begin(),
361 mirror_image_site_statuses.end(),
362 [](const MirrorImageSiteStatus& status) {
363 return status.mirror_uuid == MirrorImageSiteStatus::LOCAL_MIRROR_UUID;
364 });
365 if (it == mirror_image_site_statuses.end()) {
366 return -ENOENT;
367 }
368
369 *status = *it;
370 return 0;
371 }
372
373 void MirrorImageStatus::encode(bufferlist &bl) const {
374 // don't break compatibility for extra site statuses
375 ENCODE_START(2, 1, bl);
376
377 // local site status
378 MirrorImageSiteStatus local_status;
379 int r = get_local_mirror_image_site_status(&local_status);
380 local_status.encode_meta(1, bl);
381
382 bool local_status_valid = (r >= 0);
383 encode(local_status_valid, bl);
384
385 // remote site statuses
386 __u32 n = mirror_image_site_statuses.size();
387 if (local_status_valid) {
388 --n;
389 }
390 encode(n, bl);
391
392 for (auto& status : mirror_image_site_statuses) {
393 if (status.mirror_uuid == MirrorImageSiteStatus::LOCAL_MIRROR_UUID) {
394 continue;
395 }
396 status.encode_meta(2, bl);
397 }
398 ENCODE_FINISH(bl);
399 }
400
401 void MirrorImageStatus::decode(bufferlist::const_iterator &it) {
402 DECODE_START(2, it);
403
404 // local site status
405 MirrorImageSiteStatus local_status;
406 local_status.decode_meta(1, it);
407
408 if (struct_v < 2) {
409 mirror_image_site_statuses.push_back(local_status);
410 } else {
411 bool local_status_valid;
412 decode(local_status_valid, it);
413
414 __u32 n;
415 decode(n, it);
416 if (local_status_valid) {
417 ++n;
418 }
419
420 mirror_image_site_statuses.resize(n);
421 for (auto status_it = mirror_image_site_statuses.begin();
422 status_it != mirror_image_site_statuses.end(); ++status_it) {
423 if (local_status_valid &&
424 status_it == mirror_image_site_statuses.begin()) {
425 *status_it = local_status;
426 continue;
427 }
428
429 // remote site status
430 status_it->decode_meta(struct_v, it);
431 }
432 }
433 DECODE_FINISH(it);
434 }
435
436 void MirrorImageStatus::dump(Formatter *f) const {
437 MirrorImageSiteStatus local_status;
438 int r = get_local_mirror_image_site_status(&local_status);
439 if (r >= 0) {
440 local_status.dump(f);
441 }
442
443 f->open_array_section("remotes");
444 for (auto& status : mirror_image_site_statuses) {
445 if (status.mirror_uuid == MirrorImageSiteStatus::LOCAL_MIRROR_UUID) {
446 continue;
447 }
448
449 f->open_object_section("remote");
450 status.dump(f);
451 f->close_section();
452 }
453 f->close_section();
454 }
455
456 bool MirrorImageStatus::operator==(const MirrorImageStatus &rhs) const {
457 return (mirror_image_site_statuses == rhs.mirror_image_site_statuses);
458 }
459
460 void MirrorImageStatus::generate_test_instances(
461 std::list<MirrorImageStatus*> &o) {
462 o.push_back(new MirrorImageStatus());
463 o.push_back(new MirrorImageStatus({{"", MIRROR_IMAGE_STATUS_STATE_ERROR, ""}}));
464 o.push_back(new MirrorImageStatus({{"", MIRROR_IMAGE_STATUS_STATE_STOPPED, ""},
465 {"siteA", MIRROR_IMAGE_STATUS_STATE_REPLAYING, ""}}));
466 }
467
468 std::ostream& operator<<(std::ostream& os,
469 const MirrorImageStatus& status) {
470 os << "{";
471 MirrorImageSiteStatus local_status;
472 int r = status.get_local_mirror_image_site_status(&local_status);
473 if (r >= 0) {
474 os << "state=" << local_status.state_to_string() << ", "
475 << "description=" << local_status.description << ", "
476 << "last_update=" << local_status.last_update << ", ";
477 }
478
479 os << "remotes=[";
480 for (auto& remote_status : status.mirror_image_site_statuses) {
481 if (remote_status.mirror_uuid == MirrorImageSiteStatus::LOCAL_MIRROR_UUID) {
482 continue;
483 }
484
485 os << "{"
486 << "mirror_uuid=" << remote_status.mirror_uuid<< ", "
487 << "state=" << remote_status.state_to_string() << ", "
488 << "description=" << remote_status.description << ", "
489 << "last_update=" << remote_status.last_update
490 << "}";
491 }
492 os << "]}";
493 return os;
494 }
495
496 void ParentImageSpec::encode(bufferlist& bl) const {
497 ENCODE_START(1, 1, bl);
498 encode(pool_id, bl);
499 encode(pool_namespace, bl);
500 encode(image_id, bl);
501 encode(snap_id, bl);
502 ENCODE_FINISH(bl);
503 }
504
505 void ParentImageSpec::decode(bufferlist::const_iterator& bl) {
506 DECODE_START(1, bl);
507 decode(pool_id, bl);
508 decode(pool_namespace, bl);
509 decode(image_id, bl);
510 decode(snap_id, bl);
511 DECODE_FINISH(bl);
512 }
513
514 void ParentImageSpec::dump(Formatter *f) const {
515 f->dump_int("pool_id", pool_id);
516 f->dump_string("pool_namespace", pool_namespace);
517 f->dump_string("image_id", image_id);
518 f->dump_unsigned("snap_id", snap_id);
519 }
520
521 void ParentImageSpec::generate_test_instances(std::list<ParentImageSpec*>& o) {
522 o.push_back(new ParentImageSpec{});
523 o.push_back(new ParentImageSpec{1, "", "foo", 3});
524 o.push_back(new ParentImageSpec{1, "ns", "foo", 3});
525 }
526
527 std::ostream& operator<<(std::ostream& os, const ParentImageSpec& rhs) {
528 os << "["
529 << "pool_id=" << rhs.pool_id << ", "
530 << "pool_namespace=" << rhs.pool_namespace << ", "
531 << "image_id=" << rhs.image_id << ", "
532 << "snap_id=" << rhs.snap_id
533 << "]";
534 return os;
535 }
536
537 void ChildImageSpec::encode(bufferlist &bl) const {
538 ENCODE_START(2, 1, bl);
539 encode(pool_id, bl);
540 encode(image_id, bl);
541 encode(pool_namespace, bl);
542 ENCODE_FINISH(bl);
543 }
544
545 void ChildImageSpec::decode(bufferlist::const_iterator &it) {
546 DECODE_START(2, it);
547 decode(pool_id, it);
548 decode(image_id, it);
549 if (struct_v >= 2) {
550 decode(pool_namespace, it);
551 }
552 DECODE_FINISH(it);
553 }
554
555 void ChildImageSpec::dump(Formatter *f) const {
556 f->dump_int("pool_id", pool_id);
557 f->dump_string("pool_namespace", pool_namespace);
558 f->dump_string("image_id", image_id);
559 }
560
561 void ChildImageSpec::generate_test_instances(std::list<ChildImageSpec*> &o) {
562 o.push_back(new ChildImageSpec());
563 o.push_back(new ChildImageSpec(123, "", "abc"));
564 o.push_back(new ChildImageSpec(123, "ns", "abc"));
565 }
566
567 std::ostream& operator<<(std::ostream& os, const ChildImageSpec& rhs) {
568 os << "["
569 << "pool_id=" << rhs.pool_id << ", "
570 << "pool_namespace=" << rhs.pool_namespace << ", "
571 << "image_id=" << rhs.image_id
572 << "]";
573 return os;
574 }
575
576 void GroupImageSpec::encode(bufferlist &bl) const {
577 ENCODE_START(1, 1, bl);
578 encode(image_id, bl);
579 encode(pool_id, bl);
580 ENCODE_FINISH(bl);
581 }
582
583 void GroupImageSpec::decode(bufferlist::const_iterator &it) {
584 DECODE_START(1, it);
585 decode(image_id, it);
586 decode(pool_id, it);
587 DECODE_FINISH(it);
588 }
589
590 void GroupImageSpec::dump(Formatter *f) const {
591 f->dump_string("image_id", image_id);
592 f->dump_int("pool_id", pool_id);
593 }
594
595 int GroupImageSpec::from_key(const std::string &image_key,
596 GroupImageSpec *spec) {
597 if (nullptr == spec) return -EINVAL;
598 int prefix_len = cls::rbd::RBD_GROUP_IMAGE_KEY_PREFIX.size();
599 std::string data_string = image_key.substr(prefix_len,
600 image_key.size() - prefix_len);
601 size_t p = data_string.find("_");
602 if (std::string::npos == p) {
603 return -EIO;
604 }
605 data_string[p] = ' ';
606
607 istringstream iss(data_string);
608 uint64_t pool_id;
609 string image_id;
610 iss >> std::hex >> pool_id >> image_id;
611
612 spec->image_id = image_id;
613 spec->pool_id = pool_id;
614 return 0;
615 }
616
617 std::string GroupImageSpec::image_key() {
618 if (-1 == pool_id)
619 return "";
620 else {
621 ostringstream oss;
622 oss << RBD_GROUP_IMAGE_KEY_PREFIX << std::setw(16)
623 << std::setfill('0') << std::hex << pool_id << "_" << image_id;
624 return oss.str();
625 }
626 }
627
628 void GroupImageSpec::generate_test_instances(std::list<GroupImageSpec*> &o) {
629 o.push_back(new GroupImageSpec("10152ae8944a", 0));
630 o.push_back(new GroupImageSpec("1018643c9869", 3));
631 }
632
633 void GroupImageStatus::encode(bufferlist &bl) const {
634 ENCODE_START(1, 1, bl);
635 encode(spec, bl);
636 encode(state, bl);
637 ENCODE_FINISH(bl);
638 }
639
640 void GroupImageStatus::decode(bufferlist::const_iterator &it) {
641 DECODE_START(1, it);
642 decode(spec, it);
643 decode(state, it);
644 DECODE_FINISH(it);
645 }
646
647 std::string GroupImageStatus::state_to_string() const {
648 std::stringstream ss;
649 if (state == GROUP_IMAGE_LINK_STATE_INCOMPLETE) {
650 ss << "incomplete";
651 }
652 if (state == GROUP_IMAGE_LINK_STATE_ATTACHED) {
653 ss << "attached";
654 }
655 return ss.str();
656 }
657
658 void GroupImageStatus::dump(Formatter *f) const {
659 spec.dump(f);
660 f->dump_string("state", state_to_string());
661 }
662
663 void GroupImageStatus::generate_test_instances(std::list<GroupImageStatus*> &o) {
664 o.push_back(new GroupImageStatus(GroupImageSpec("10152ae8944a", 0), GROUP_IMAGE_LINK_STATE_ATTACHED));
665 o.push_back(new GroupImageStatus(GroupImageSpec("1018643c9869", 3), GROUP_IMAGE_LINK_STATE_ATTACHED));
666 o.push_back(new GroupImageStatus(GroupImageSpec("10152ae8944a", 0), GROUP_IMAGE_LINK_STATE_INCOMPLETE));
667 o.push_back(new GroupImageStatus(GroupImageSpec("1018643c9869", 3), GROUP_IMAGE_LINK_STATE_INCOMPLETE));
668 }
669
670
671 void GroupSpec::encode(bufferlist &bl) const {
672 ENCODE_START(1, 1, bl);
673 encode(pool_id, bl);
674 encode(group_id, bl);
675 ENCODE_FINISH(bl);
676 }
677
678 void GroupSpec::decode(bufferlist::const_iterator &it) {
679 DECODE_START(1, it);
680 decode(pool_id, it);
681 decode(group_id, it);
682 DECODE_FINISH(it);
683 }
684
685 void GroupSpec::dump(Formatter *f) const {
686 f->dump_string("group_id", group_id);
687 f->dump_int("pool_id", pool_id);
688 }
689
690 bool GroupSpec::is_valid() const {
691 return (!group_id.empty()) && (pool_id != -1);
692 }
693
694 void GroupSpec::generate_test_instances(std::list<GroupSpec *> &o) {
695 o.push_back(new GroupSpec("10152ae8944a", 0));
696 o.push_back(new GroupSpec("1018643c9869", 3));
697 }
698
699 void GroupSnapshotNamespace::encode(bufferlist& bl) const {
700 using ceph::encode;
701 encode(group_pool, bl);
702 encode(group_id, bl);
703 encode(group_snapshot_id, bl);
704 }
705
706 void GroupSnapshotNamespace::decode(bufferlist::const_iterator& it) {
707 using ceph::decode;
708 decode(group_pool, it);
709 decode(group_id, it);
710 decode(group_snapshot_id, it);
711 }
712
713 void GroupSnapshotNamespace::dump(Formatter *f) const {
714 f->dump_int("group_pool", group_pool);
715 f->dump_string("group_id", group_id);
716 f->dump_string("group_snapshot_id", group_snapshot_id);
717 }
718
719 void TrashSnapshotNamespace::encode(bufferlist& bl) const {
720 using ceph::encode;
721 encode(original_name, bl);
722 encode(static_cast<uint32_t>(original_snapshot_namespace_type), bl);
723 }
724
725 void TrashSnapshotNamespace::decode(bufferlist::const_iterator& it) {
726 using ceph::decode;
727 decode(original_name, it);
728 uint32_t snap_type;
729 decode(snap_type, it);
730 original_snapshot_namespace_type = static_cast<SnapshotNamespaceType>(
731 snap_type);
732 }
733
734 void TrashSnapshotNamespace::dump(Formatter *f) const {
735 f->dump_string("original_name", original_name);
736 f->dump_stream("original_snapshot_namespace")
737 << original_snapshot_namespace_type;
738 }
739
740 void MirrorSnapshotNamespace::encode(bufferlist& bl) const {
741 using ceph::encode;
742 encode(state, bl);
743 encode(complete, bl);
744 encode(mirror_peer_uuids, bl);
745 encode(primary_mirror_uuid, bl);
746 encode(primary_snap_id, bl);
747 encode(last_copied_object_number, bl);
748 encode(snap_seqs, bl);
749 }
750
751 void MirrorSnapshotNamespace::decode(bufferlist::const_iterator& it) {
752 using ceph::decode;
753 decode(state, it);
754 decode(complete, it);
755 decode(mirror_peer_uuids, it);
756 decode(primary_mirror_uuid, it);
757 decode(primary_snap_id, it);
758 decode(last_copied_object_number, it);
759 decode(snap_seqs, it);
760 }
761
762 void MirrorSnapshotNamespace::dump(Formatter *f) const {
763 f->dump_stream("state") << state;
764 f->dump_bool("complete", complete);
765 f->open_array_section("mirror_peer_uuids");
766 for (auto &peer : mirror_peer_uuids) {
767 f->dump_string("mirror_peer_uuid", peer);
768 }
769 f->close_section();
770 if (is_primary()) {
771 f->dump_unsigned("clean_since_snap_id", clean_since_snap_id);
772 } else {
773 f->dump_string("primary_mirror_uuid", primary_mirror_uuid);
774 f->dump_unsigned("primary_snap_id", primary_snap_id);
775 f->dump_unsigned("last_copied_object_number", last_copied_object_number);
776 f->dump_stream("snap_seqs") << snap_seqs;
777 }
778 }
779
780 class EncodeSnapshotNamespaceVisitor : public boost::static_visitor<void> {
781 public:
782 explicit EncodeSnapshotNamespaceVisitor(bufferlist &bl) : m_bl(bl) {
783 }
784
785 template <typename T>
786 inline void operator()(const T& t) const {
787 using ceph::encode;
788 encode(static_cast<uint32_t>(T::SNAPSHOT_NAMESPACE_TYPE), m_bl);
789 t.encode(m_bl);
790 }
791
792 private:
793 bufferlist &m_bl;
794 };
795
796 class DecodeSnapshotNamespaceVisitor : public boost::static_visitor<void> {
797 public:
798 DecodeSnapshotNamespaceVisitor(bufferlist::const_iterator &iter)
799 : m_iter(iter) {
800 }
801
802 template <typename T>
803 inline void operator()(T& t) const {
804 t.decode(m_iter);
805 }
806 private:
807 bufferlist::const_iterator &m_iter;
808 };
809
810 class DumpSnapshotNamespaceVisitor : public boost::static_visitor<void> {
811 public:
812 explicit DumpSnapshotNamespaceVisitor(Formatter *formatter, const std::string &key)
813 : m_formatter(formatter), m_key(key) {}
814
815 template <typename T>
816 inline void operator()(const T& t) const {
817 auto type = T::SNAPSHOT_NAMESPACE_TYPE;
818 m_formatter->dump_string(m_key.c_str(), stringify(type));
819 t.dump(m_formatter);
820 }
821 private:
822 ceph::Formatter *m_formatter;
823 std::string m_key;
824 };
825
826 class GetTypeVisitor : public boost::static_visitor<SnapshotNamespaceType> {
827 public:
828 template <typename T>
829 inline SnapshotNamespaceType operator()(const T&) const {
830 return static_cast<SnapshotNamespaceType>(T::SNAPSHOT_NAMESPACE_TYPE);
831 }
832 };
833
834 SnapshotNamespaceType get_snap_namespace_type(
835 const SnapshotNamespace& snapshot_namespace) {
836 return static_cast<SnapshotNamespaceType>(boost::apply_visitor(
837 GetTypeVisitor(), snapshot_namespace));
838 }
839
840 void SnapshotInfo::encode(bufferlist& bl) const {
841 ENCODE_START(1, 1, bl);
842 encode(id, bl);
843 encode(snapshot_namespace, bl);
844 encode(name, bl);
845 encode(image_size, bl);
846 encode(timestamp, bl);
847 encode(child_count, bl);
848 ENCODE_FINISH(bl);
849 }
850
851 void SnapshotInfo::decode(bufferlist::const_iterator& it) {
852 DECODE_START(1, it);
853 decode(id, it);
854 decode(snapshot_namespace, it);
855 decode(name, it);
856 decode(image_size, it);
857 decode(timestamp, it);
858 decode(child_count, it);
859 DECODE_FINISH(it);
860 }
861
862 void SnapshotInfo::dump(Formatter *f) const {
863 f->dump_unsigned("id", id);
864 f->open_object_section("namespace");
865 boost::apply_visitor(DumpSnapshotNamespaceVisitor(f, "type"),
866 snapshot_namespace);
867 f->close_section();
868 f->dump_string("name", name);
869 f->dump_unsigned("image_size", image_size);
870 f->dump_stream("timestamp") << timestamp;
871 }
872
873 void SnapshotInfo::generate_test_instances(std::list<SnapshotInfo*> &o) {
874 o.push_back(new SnapshotInfo(1ULL, UserSnapshotNamespace{}, "snap1", 123,
875 {123456, 0}, 12));
876 o.push_back(new SnapshotInfo(2ULL,
877 GroupSnapshotNamespace{567, "group1", "snap1"},
878 "snap1", 123, {123456, 0}, 987));
879 o.push_back(new SnapshotInfo(3ULL,
880 TrashSnapshotNamespace{
881 SNAPSHOT_NAMESPACE_TYPE_USER, "snap1"},
882 "12345", 123, {123456, 0}, 429));
883 o.push_back(new SnapshotInfo(1ULL,
884 MirrorSnapshotNamespace{MIRROR_SNAPSHOT_STATE_PRIMARY,
885 {"1", "2"}, "", CEPH_NOSNAP},
886 "snap1", 123, {123456, 0}, 12));
887 o.push_back(new SnapshotInfo(1ULL,
888 MirrorSnapshotNamespace{MIRROR_SNAPSHOT_STATE_NON_PRIMARY,
889 {"1", "2"}, "uuid", 123},
890 "snap1", 123, {123456, 0}, 12));
891 }
892
893 void SnapshotNamespace::encode(bufferlist& bl) const {
894 ENCODE_START(1, 1, bl);
895 boost::apply_visitor(EncodeSnapshotNamespaceVisitor(bl), *this);
896 ENCODE_FINISH(bl);
897 }
898
899 void SnapshotNamespace::decode(bufferlist::const_iterator &p)
900 {
901 DECODE_START(1, p);
902 uint32_t snap_type;
903 decode(snap_type, p);
904 switch (snap_type) {
905 case cls::rbd::SNAPSHOT_NAMESPACE_TYPE_USER:
906 *this = UserSnapshotNamespace();
907 break;
908 case cls::rbd::SNAPSHOT_NAMESPACE_TYPE_GROUP:
909 *this = GroupSnapshotNamespace();
910 break;
911 case cls::rbd::SNAPSHOT_NAMESPACE_TYPE_TRASH:
912 *this = TrashSnapshotNamespace();
913 break;
914 case cls::rbd::SNAPSHOT_NAMESPACE_TYPE_MIRROR:
915 *this = MirrorSnapshotNamespace();
916 break;
917 default:
918 *this = UnknownSnapshotNamespace();
919 break;
920 }
921 boost::apply_visitor(DecodeSnapshotNamespaceVisitor(p), *this);
922 DECODE_FINISH(p);
923 }
924
925 void SnapshotNamespace::dump(Formatter *f) const {
926 boost::apply_visitor(
927 DumpSnapshotNamespaceVisitor(f, "snapshot_namespace_type"), *this);
928 }
929
930 void SnapshotNamespace::generate_test_instances(std::list<SnapshotNamespace*> &o) {
931 o.push_back(new SnapshotNamespace(UserSnapshotNamespace()));
932 o.push_back(new SnapshotNamespace(GroupSnapshotNamespace(0, "10152ae8944a",
933 "2118643c9732")));
934 o.push_back(new SnapshotNamespace(GroupSnapshotNamespace(5, "1018643c9869",
935 "33352be8933c")));
936 o.push_back(new SnapshotNamespace(TrashSnapshotNamespace()));
937 o.push_back(new SnapshotNamespace(MirrorSnapshotNamespace(MIRROR_SNAPSHOT_STATE_PRIMARY,
938 {"peer uuid"},
939 "", CEPH_NOSNAP)));
940 o.push_back(new SnapshotNamespace(MirrorSnapshotNamespace(MIRROR_SNAPSHOT_STATE_PRIMARY_DEMOTED,
941 {"peer uuid"},
942 "", CEPH_NOSNAP)));
943 o.push_back(new SnapshotNamespace(MirrorSnapshotNamespace(MIRROR_SNAPSHOT_STATE_NON_PRIMARY,
944 {"peer uuid"},
945 "uuid", 123)));
946 o.push_back(new SnapshotNamespace(MirrorSnapshotNamespace(MIRROR_SNAPSHOT_STATE_NON_PRIMARY_DEMOTED,
947 {"peer uuid"},
948 "uuid", 123)));
949 }
950
951 std::ostream& operator<<(std::ostream& os, const SnapshotNamespaceType& type) {
952 switch (type) {
953 case SNAPSHOT_NAMESPACE_TYPE_USER:
954 os << "user";
955 break;
956 case SNAPSHOT_NAMESPACE_TYPE_GROUP:
957 os << "group";
958 break;
959 case SNAPSHOT_NAMESPACE_TYPE_TRASH:
960 os << "trash";
961 break;
962 case SNAPSHOT_NAMESPACE_TYPE_MIRROR:
963 os << "mirror";
964 break;
965 default:
966 os << "unknown";
967 break;
968 }
969 return os;
970 }
971
972 std::ostream& operator<<(std::ostream& os, const UserSnapshotNamespace& ns) {
973 os << "[" << SNAPSHOT_NAMESPACE_TYPE_USER << "]";
974 return os;
975 }
976
977 std::ostream& operator<<(std::ostream& os, const GroupSnapshotNamespace& ns) {
978 os << "[" << SNAPSHOT_NAMESPACE_TYPE_GROUP << " "
979 << "group_pool=" << ns.group_pool << ", "
980 << "group_id=" << ns.group_id << ", "
981 << "group_snapshot_id=" << ns.group_snapshot_id << "]";
982 return os;
983 }
984
985 std::ostream& operator<<(std::ostream& os, const TrashSnapshotNamespace& ns) {
986 os << "[" << SNAPSHOT_NAMESPACE_TYPE_TRASH << " "
987 << "original_name=" << ns.original_name << ", "
988 << "original_snapshot_namespace=" << ns.original_snapshot_namespace_type
989 << "]";
990 return os;
991 }
992
993 std::ostream& operator<<(std::ostream& os, const MirrorSnapshotNamespace& ns) {
994 os << "[" << SNAPSHOT_NAMESPACE_TYPE_MIRROR << " "
995 << "state=" << ns.state << ", "
996 << "complete=" << ns.complete << ", "
997 << "mirror_peer_uuids=" << ns.mirror_peer_uuids << ", "
998 << "primary_mirror_uuid=" << ns.primary_mirror_uuid << ", "
999 << "primary_snap_id=" << ns.primary_snap_id << ", "
1000 << "last_copied_object_number=" << ns.last_copied_object_number << ", "
1001 << "snap_seqs=" << ns.snap_seqs
1002 << "]";
1003 return os;
1004 }
1005
1006 std::ostream& operator<<(std::ostream& os, const UnknownSnapshotNamespace& ns) {
1007 os << "[unknown]";
1008 return os;
1009 }
1010
1011 std::ostream& operator<<(std::ostream& os, MirrorSnapshotState type) {
1012 switch (type) {
1013 case MIRROR_SNAPSHOT_STATE_PRIMARY:
1014 os << "primary";
1015 break;
1016 case MIRROR_SNAPSHOT_STATE_PRIMARY_DEMOTED:
1017 os << "primary (demoted)";
1018 break;
1019 case MIRROR_SNAPSHOT_STATE_NON_PRIMARY:
1020 os << "non-primary";
1021 break;
1022 case MIRROR_SNAPSHOT_STATE_NON_PRIMARY_DEMOTED:
1023 os << "non-primary (demoted)";
1024 break;
1025 default:
1026 os << "unknown";
1027 break;
1028 }
1029 return os;
1030 }
1031
1032 void ImageSnapshotSpec::encode(bufferlist& bl) const {
1033 using ceph::encode;
1034 ENCODE_START(1, 1, bl);
1035 encode(pool, bl);
1036 encode(image_id, bl);
1037 encode(snap_id, bl);
1038 ENCODE_FINISH(bl);
1039 }
1040
1041 void ImageSnapshotSpec::decode(bufferlist::const_iterator& it) {
1042 using ceph::decode;
1043 DECODE_START(1, it);
1044 decode(pool, it);
1045 decode(image_id, it);
1046 decode(snap_id, it);
1047 DECODE_FINISH(it);
1048 }
1049
1050 void ImageSnapshotSpec::dump(Formatter *f) const {
1051 f->dump_int("pool", pool);
1052 f->dump_string("image_id", image_id);
1053 f->dump_int("snap_id", snap_id);
1054 }
1055
1056 void ImageSnapshotSpec::generate_test_instances(std::list<ImageSnapshotSpec *> &o) {
1057 o.push_back(new ImageSnapshotSpec(0, "myimage", 2));
1058 o.push_back(new ImageSnapshotSpec(1, "testimage", 7));
1059 }
1060
1061 void GroupSnapshot::encode(bufferlist& bl) const {
1062 using ceph::encode;
1063 ENCODE_START(1, 1, bl);
1064 encode(id, bl);
1065 encode(name, bl);
1066 encode(state, bl);
1067 encode(snaps, bl);
1068 ENCODE_FINISH(bl);
1069 }
1070
1071 void GroupSnapshot::decode(bufferlist::const_iterator& it) {
1072 using ceph::decode;
1073 DECODE_START(1, it);
1074 decode(id, it);
1075 decode(name, it);
1076 decode(state, it);
1077 decode(snaps, it);
1078 DECODE_FINISH(it);
1079 }
1080
1081 void GroupSnapshot::dump(Formatter *f) const {
1082 f->dump_string("id", id);
1083 f->dump_string("name", name);
1084 f->dump_int("state", state);
1085 }
1086
1087 void GroupSnapshot::generate_test_instances(std::list<GroupSnapshot *> &o) {
1088 o.push_back(new GroupSnapshot("10152ae8944a", "groupsnapshot1", GROUP_SNAPSHOT_STATE_INCOMPLETE));
1089 o.push_back(new GroupSnapshot("1018643c9869", "groupsnapshot2", GROUP_SNAPSHOT_STATE_COMPLETE));
1090 }
1091 void TrashImageSpec::encode(bufferlist& bl) const {
1092 ENCODE_START(2, 1, bl);
1093 encode(source, bl);
1094 encode(name, bl);
1095 encode(deletion_time, bl);
1096 encode(deferment_end_time, bl);
1097 encode(state, bl);
1098 ENCODE_FINISH(bl);
1099 }
1100
1101 void TrashImageSpec::decode(bufferlist::const_iterator &it) {
1102 DECODE_START(2, it);
1103 decode(source, it);
1104 decode(name, it);
1105 decode(deletion_time, it);
1106 decode(deferment_end_time, it);
1107 if (struct_v >= 2) {
1108 decode(state, it);
1109 }
1110 DECODE_FINISH(it);
1111 }
1112
1113 void TrashImageSpec::dump(Formatter *f) const {
1114 f->dump_stream("source") << source;
1115 f->dump_string("name", name);
1116 f->dump_unsigned("deletion_time", deletion_time);
1117 f->dump_unsigned("deferment_end_time", deferment_end_time);
1118 }
1119
1120 void MirrorImageMap::encode(bufferlist &bl) const {
1121 ENCODE_START(1, 1, bl);
1122 encode(instance_id, bl);
1123 encode(mapped_time, bl);
1124 encode(data, bl);
1125 ENCODE_FINISH(bl);
1126 }
1127
1128 void MirrorImageMap::decode(bufferlist::const_iterator &it) {
1129 DECODE_START(1, it);
1130 decode(instance_id, it);
1131 decode(mapped_time, it);
1132 decode(data, it);
1133 DECODE_FINISH(it);
1134 }
1135
1136 void MirrorImageMap::dump(Formatter *f) const {
1137 f->dump_string("instance_id", instance_id);
1138 f->dump_stream("mapped_time") << mapped_time;
1139
1140 std::stringstream data_ss;
1141 data.hexdump(data_ss);
1142 f->dump_string("data", data_ss.str());
1143 }
1144
1145 void MirrorImageMap::generate_test_instances(
1146 std::list<MirrorImageMap*> &o) {
1147 bufferlist data;
1148 data.append(std::string(128, '1'));
1149
1150 o.push_back(new MirrorImageMap("uuid-123", utime_t(), data));
1151 o.push_back(new MirrorImageMap("uuid-abc", utime_t(), data));
1152 }
1153
1154 bool MirrorImageMap::operator==(const MirrorImageMap &rhs) const {
1155 return instance_id == rhs.instance_id && mapped_time == rhs.mapped_time &&
1156 data.contents_equal(rhs.data);
1157 }
1158
1159 bool MirrorImageMap::operator<(const MirrorImageMap &rhs) const {
1160 return instance_id < rhs.instance_id ||
1161 (instance_id == rhs.instance_id && mapped_time < rhs.mapped_time);
1162 }
1163
1164 std::ostream& operator<<(std::ostream& os,
1165 const MirrorImageMap &image_map) {
1166 return os << "[" << "instance_id=" << image_map.instance_id << ", mapped_time="
1167 << image_map.mapped_time << "]";
1168 }
1169
1170 std::ostream& operator<<(std::ostream& os,
1171 const MigrationHeaderType& type) {
1172 switch (type) {
1173 case MIGRATION_HEADER_TYPE_SRC:
1174 os << "source";
1175 break;
1176 case MIGRATION_HEADER_TYPE_DST:
1177 os << "destination";
1178 break;
1179 default:
1180 os << "unknown (" << static_cast<uint32_t>(type) << ")";
1181 break;
1182 }
1183 return os;
1184 }
1185
1186 std::ostream& operator<<(std::ostream& os,
1187 const MigrationState& migration_state) {
1188 switch (migration_state) {
1189 case MIGRATION_STATE_ERROR:
1190 os << "error";
1191 break;
1192 case MIGRATION_STATE_PREPARING:
1193 os << "preparing";
1194 break;
1195 case MIGRATION_STATE_PREPARED:
1196 os << "prepared";
1197 break;
1198 case MIGRATION_STATE_EXECUTING:
1199 os << "executing";
1200 break;
1201 case MIGRATION_STATE_EXECUTED:
1202 os << "executed";
1203 break;
1204 default:
1205 os << "unknown (" << static_cast<uint32_t>(migration_state) << ")";
1206 break;
1207 }
1208 return os;
1209 }
1210
1211 void MigrationSpec::encode(bufferlist& bl) const {
1212 ENCODE_START(2, 1, bl);
1213 encode(header_type, bl);
1214 encode(pool_id, bl);
1215 encode(pool_namespace, bl);
1216 encode(image_name, bl);
1217 encode(image_id, bl);
1218 encode(snap_seqs, bl);
1219 encode(overlap, bl);
1220 encode(flatten, bl);
1221 encode(mirroring, bl);
1222 encode(state, bl);
1223 encode(state_description, bl);
1224 encode(static_cast<uint8_t>(mirror_image_mode), bl);
1225 ENCODE_FINISH(bl);
1226 }
1227
1228 void MigrationSpec::decode(bufferlist::const_iterator& bl) {
1229 DECODE_START(2, bl);
1230 decode(header_type, bl);
1231 decode(pool_id, bl);
1232 decode(pool_namespace, bl);
1233 decode(image_name, bl);
1234 decode(image_id, bl);
1235 decode(snap_seqs, bl);
1236 decode(overlap, bl);
1237 decode(flatten, bl);
1238 decode(mirroring, bl);
1239 decode(state, bl);
1240 decode(state_description, bl);
1241 if (struct_v >= 2) {
1242 uint8_t int_mode;
1243 decode(int_mode, bl);
1244 mirror_image_mode = static_cast<MirrorImageMode>(int_mode);
1245 }
1246 DECODE_FINISH(bl);
1247 }
1248
1249 std::ostream& operator<<(std::ostream& os,
1250 const std::map<uint64_t, uint64_t>& snap_seqs) {
1251 os << "{";
1252 size_t count = 0;
1253 for (auto &it : snap_seqs) {
1254 os << (count++ > 0 ? ", " : "") << "(" << it.first << ", " << it.second
1255 << ")";
1256 }
1257 os << "}";
1258 return os;
1259 }
1260
1261 void MigrationSpec::dump(Formatter *f) const {
1262 f->dump_stream("header_type") << header_type;
1263 f->dump_int("pool_id", pool_id);
1264 f->dump_string("pool_namespace", pool_namespace);
1265 f->dump_string("image_name", image_name);
1266 f->dump_string("image_id", image_id);
1267 f->dump_stream("snap_seqs") << snap_seqs;
1268 f->dump_unsigned("overlap", overlap);
1269 f->dump_bool("mirroring", mirroring);
1270 f->dump_stream("mirror_image_mode") << mirror_image_mode;
1271 }
1272
1273 void MigrationSpec::generate_test_instances(std::list<MigrationSpec*> &o) {
1274 o.push_back(new MigrationSpec());
1275 o.push_back(new MigrationSpec(MIGRATION_HEADER_TYPE_SRC, 1, "ns",
1276 "image_name", "image_id", {{1, 2}}, 123, true,
1277 MIRROR_IMAGE_MODE_SNAPSHOT, true,
1278 MIGRATION_STATE_PREPARED, "description"));
1279 }
1280
1281 std::ostream& operator<<(std::ostream& os,
1282 const MigrationSpec& migration_spec) {
1283 os << "["
1284 << "header_type=" << migration_spec.header_type << ", "
1285 << "pool_id=" << migration_spec.pool_id << ", "
1286 << "pool_namespace=" << migration_spec.pool_namespace << ", "
1287 << "image_name=" << migration_spec.image_name << ", "
1288 << "image_id=" << migration_spec.image_id << ", "
1289 << "snap_seqs=" << migration_spec.snap_seqs << ", "
1290 << "overlap=" << migration_spec.overlap << ", "
1291 << "flatten=" << migration_spec.flatten << ", "
1292 << "mirroring=" << migration_spec.mirroring << ", "
1293 << "mirror_image_mode=" << migration_spec.mirror_image_mode << ", "
1294 << "state=" << migration_spec.state << ", "
1295 << "state_description=" << migration_spec.state_description << "]";
1296 return os;
1297 }
1298
1299 std::ostream& operator<<(std::ostream& os, const AssertSnapcSeqState& state) {
1300 switch (state) {
1301 case ASSERT_SNAPC_SEQ_GT_SNAPSET_SEQ:
1302 os << "gt";
1303 break;
1304 case ASSERT_SNAPC_SEQ_LE_SNAPSET_SEQ:
1305 os << "le";
1306 break;
1307 default:
1308 os << "unknown (" << static_cast<uint32_t>(state) << ")";
1309 break;
1310 }
1311 return os;
1312 }
1313
1314 void sanitize_entity_inst(entity_inst_t* entity_inst) {
1315 // make all addrs of type ANY because the type isn't what uniquely
1316 // identifies them and clients and on-disk formats can be encoded
1317 // with different backwards compatibility settings.
1318 entity_inst->addr.set_type(entity_addr_t::TYPE_ANY);
1319 }
1320
1321 } // namespace rbd
1322 } // namespace cls