]> git.proxmox.com Git - ceph.git/blob - ceph/src/librbd/mirror/snapshot/Types.cc
import 15.2.0 Octopus source
[ceph.git] / ceph / src / librbd / mirror / snapshot / 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 "common/Formatter.h"
5 #include "include/encoding.h"
6 #include "include/stringify.h"
7 #include "librbd/mirror/snapshot/Types.h"
8
9 namespace librbd {
10 namespace mirror {
11 namespace snapshot {
12
13 void ImageStateHeader::encode(bufferlist& bl) const {
14 ENCODE_START(1, 1, bl);
15 encode(object_count, bl);
16 ENCODE_FINISH(bl);
17 }
18
19 void ImageStateHeader::decode(bufferlist::const_iterator& bl) {
20 DECODE_START(1, bl);
21 decode(object_count, bl);
22 DECODE_FINISH(bl);
23 }
24
25 void SnapState::encode(bufferlist& bl) const {
26 ENCODE_START(1, 1, bl);
27 encode(snap_namespace, bl);
28 encode(name, bl);
29 encode(protection_status, bl);
30 ENCODE_FINISH(bl);
31 }
32
33 void SnapState::decode(bufferlist::const_iterator& bl) {
34 DECODE_START(1, bl);
35 decode(snap_namespace, bl);
36 decode(name, bl);
37 decode(protection_status, bl);
38 DECODE_FINISH(bl);
39 }
40
41 void SnapState::dump(Formatter *f) const {
42 f->open_object_section("namespace");
43 snap_namespace.dump(f);
44 f->close_section();
45 f->dump_string("name", name);
46 f->dump_unsigned("protection_status", protection_status);
47 }
48
49 std::ostream& operator<<(std::ostream& os, const SnapState& snap_state) {
50 os << "["
51 << "namespace=" << snap_state.snap_namespace << ", "
52 << "name=" << snap_state.name << ", "
53 << "protection=" << static_cast<int>(snap_state.protection_status)
54 << "]";
55 return os;
56 }
57
58 void ImageState::encode(bufferlist& bl) const {
59 ENCODE_START(1, 1, bl);
60 encode(name, bl);
61 encode(features, bl);
62 encode(snap_limit, bl);
63 encode(snapshots, bl);
64 encode(metadata, bl);
65 ENCODE_FINISH(bl);
66 }
67
68 void ImageState::decode(bufferlist::const_iterator& bl) {
69 DECODE_START(1, bl);
70 decode(name, bl);
71 decode(features, bl);
72 decode(snap_limit, bl);
73 decode(snapshots, bl);
74 decode(metadata, bl);
75 DECODE_FINISH(bl);
76 }
77
78 void ImageState::dump(Formatter *f) const {
79 f->dump_string("name", name);
80 f->dump_unsigned("features", features);
81 f->dump_unsigned("snap_limit", snap_limit);
82 f->open_array_section("snapshots");
83 for (auto &[id, snap_state] : snapshots) {
84 f->open_object_section(stringify(id).c_str());
85 snap_state.dump(f);
86 f->close_section(); // snap_state
87 }
88 f->close_section(); // snapshots
89 f->open_object_section("metadata");
90 for (auto &it : metadata) {
91 f->dump_stream(it.first.c_str()) << it.second;
92 }
93 f->close_section(); // metadata
94 }
95
96 std::ostream& operator<<(std::ostream& os, const ImageState& image_state) {
97 os << "["
98 << "name=" << image_state.name << ", "
99 << "features=" << image_state.features << ", "
100 << "snap_limit=" << image_state.snap_limit << ", "
101 << "snaps=" << image_state.snapshots << ", "
102 << "metadata_count=" << image_state.metadata.size()
103 << "]";
104 return os;
105 }
106
107 } // namespace snapshot
108 } // namespace mirror
109 } // namespace librbd