]> git.proxmox.com Git - ceph.git/blob - ceph/src/cls/journal/cls_journal_types.cc
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / cls / journal / cls_journal_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 "cls/journal/cls_journal_types.h"
5 #include "include/stringify.h"
6 #include "common/Formatter.h"
7
8 namespace cls {
9 namespace journal {
10
11 void ObjectPosition::encode(bufferlist& bl) const {
12 ENCODE_START(1, 1, bl);
13 ::encode(object_number, bl);
14 ::encode(tag_tid, bl);
15 ::encode(entry_tid, bl);
16 ENCODE_FINISH(bl);
17 }
18
19 void ObjectPosition::decode(bufferlist::iterator& iter) {
20 DECODE_START(1, iter);
21 ::decode(object_number, iter);
22 ::decode(tag_tid, iter);
23 ::decode(entry_tid, iter);
24 DECODE_FINISH(iter);
25 }
26
27 void ObjectPosition::dump(Formatter *f) const {
28 f->dump_unsigned("object_number", object_number);
29 f->dump_unsigned("tag_tid", tag_tid);
30 f->dump_unsigned("entry_tid", entry_tid);
31 }
32
33 void ObjectPosition::generate_test_instances(std::list<ObjectPosition *> &o) {
34 o.push_back(new ObjectPosition());
35 o.push_back(new ObjectPosition(1, 2, 3));
36 }
37
38 void ObjectSetPosition::encode(bufferlist& bl) const {
39 ENCODE_START(1, 1, bl);
40 ::encode(object_positions, bl);
41 ENCODE_FINISH(bl);
42 }
43
44 void ObjectSetPosition::decode(bufferlist::iterator& iter) {
45 DECODE_START(1, iter);
46 ::decode(object_positions, iter);
47 DECODE_FINISH(iter);
48 }
49
50 void ObjectSetPosition::dump(Formatter *f) const {
51 f->open_array_section("object_positions");
52 for (auto &pos : object_positions) {
53 f->open_object_section("object_position");
54 pos.dump(f);
55 f->close_section();
56 }
57 f->close_section();
58 }
59
60 void ObjectSetPosition::generate_test_instances(
61 std::list<ObjectSetPosition *> &o) {
62 o.push_back(new ObjectSetPosition());
63 o.push_back(new ObjectSetPosition({{0, 1, 120}, {121, 2, 121}}));
64 }
65
66 void Client::encode(bufferlist& bl) const {
67 ENCODE_START(1, 1, bl);
68 ::encode(id, bl);
69 ::encode(data, bl);
70 ::encode(commit_position, bl);
71 ::encode(static_cast<uint8_t>(state), bl);
72 ENCODE_FINISH(bl);
73 }
74
75 void Client::decode(bufferlist::iterator& iter) {
76 DECODE_START(1, iter);
77 ::decode(id, iter);
78 ::decode(data, iter);
79 ::decode(commit_position, iter);
80
81 uint8_t state_raw;
82 ::decode(state_raw, iter);
83 state = static_cast<ClientState>(state_raw);
84 DECODE_FINISH(iter);
85 }
86
87 void Client::dump(Formatter *f) const {
88 f->dump_string("id", id);
89
90 std::stringstream data_ss;
91 data.hexdump(data_ss);
92 f->dump_string("data", data_ss.str());
93
94 f->open_object_section("commit_position");
95 commit_position.dump(f);
96 f->close_section();
97
98 f->dump_string("state", stringify(state));
99 }
100
101 void Client::generate_test_instances(std::list<Client *> &o) {
102 bufferlist data;
103 data.append(std::string(128, '1'));
104
105 o.push_back(new Client());
106 o.push_back(new Client("id", data));
107 o.push_back(new Client("id", data, {{{1, 2, 120}, {2, 3, 121}}}));
108 }
109
110 void Tag::encode(bufferlist& bl) const {
111 ENCODE_START(1, 1, bl);
112 ::encode(tid, bl);
113 ::encode(tag_class, bl);
114 ::encode(data, bl);
115 ENCODE_FINISH(bl);
116 }
117
118 void Tag::decode(bufferlist::iterator& iter) {
119 DECODE_START(1, iter);
120 ::decode(tid, iter);
121 ::decode(tag_class, iter);
122 ::decode(data, iter);
123 DECODE_FINISH(iter);
124 }
125
126 void Tag::dump(Formatter *f) const {
127 f->dump_unsigned("tid", tid);
128 f->dump_unsigned("tag_class", tag_class);
129
130 std::stringstream data_ss;
131 data.hexdump(data_ss);
132 f->dump_string("data", data_ss.str());
133 }
134
135 void Tag::generate_test_instances(std::list<Tag *> &o) {
136 o.push_back(new Tag());
137
138 bufferlist data;
139 data.append(std::string(128, '1'));
140 o.push_back(new Tag(123, 234, data));
141 }
142
143 std::ostream &operator<<(std::ostream &os, const ClientState &state) {
144 switch (state) {
145 case CLIENT_STATE_CONNECTED:
146 os << "connected";
147 break;
148 case CLIENT_STATE_DISCONNECTED:
149 os << "disconnected";
150 break;
151 default:
152 os << "unknown (" << static_cast<uint32_t>(state) << ")";
153 break;
154 }
155 return os;
156 }
157
158 std::ostream &operator<<(std::ostream &os,
159 const ObjectPosition &object_position) {
160 os << "["
161 << "object_number=" << object_position.object_number << ", "
162 << "tag_tid=" << object_position.tag_tid << ", "
163 << "entry_tid=" << object_position.entry_tid << "]";
164 return os;
165 }
166
167 std::ostream &operator<<(std::ostream &os,
168 const ObjectSetPosition &object_set_position) {
169 os << "[positions=[";
170 std::string delim;
171 for (auto &object_position : object_set_position.object_positions) {
172 os << delim << object_position;
173 delim = ", ";
174 }
175 os << "]]";
176 return os;
177 }
178
179 std::ostream &operator<<(std::ostream &os, const Client &client) {
180 os << "[id=" << client.id << ", "
181 << "commit_position=" << client.commit_position << ", "
182 << "state=" << client.state << "]";
183 return os;
184 }
185
186 std::ostream &operator<<(std::ostream &os, const Tag &tag) {
187 os << "[tid=" << tag.tid << ", "
188 << "tag_class=" << tag.tag_class << ", "
189 << "data=";
190 tag.data.hexdump(os);
191 os << "]";
192 return os;
193 }
194
195 } // namespace journal
196 } // namespace cls