]> git.proxmox.com Git - ceph.git/blob - ceph/src/osd/ECMsgTypes.cc
bump version to 18.2.4-pve3
[ceph.git] / ceph / src / osd / ECMsgTypes.cc
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
3 /*
4 * Ceph - scalable distributed file system
5 *
6 * Copyright (C) 2013 Inktank Storage, Inc.
7 *
8 * This is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License version 2.1, as published by the Free Software
11 * Foundation. See file COPYING.
12 *
13 */
14
15 #include "ECMsgTypes.h"
16
17 using std::list;
18 using std::make_pair;
19 using std::map;
20 using std::pair;
21 using std::set;
22 using ceph::bufferlist;
23 using ceph::Formatter;
24
25 void ECSubWrite::encode(bufferlist &bl) const
26 {
27 ENCODE_START(4, 1, bl);
28 encode(from, bl);
29 encode(tid, bl);
30 encode(reqid, bl);
31 encode(soid, bl);
32 encode(stats, bl);
33 encode(t, bl);
34 encode(at_version, bl);
35 encode(trim_to, bl);
36 encode(log_entries, bl);
37 encode(temp_added, bl);
38 encode(temp_removed, bl);
39 encode(updated_hit_set_history, bl);
40 encode(roll_forward_to, bl);
41 encode(backfill_or_async_recovery, bl);
42 ENCODE_FINISH(bl);
43 }
44
45 void ECSubWrite::decode(bufferlist::const_iterator &bl)
46 {
47 DECODE_START(4, bl);
48 decode(from, bl);
49 decode(tid, bl);
50 decode(reqid, bl);
51 decode(soid, bl);
52 decode(stats, bl);
53 decode(t, bl);
54 decode(at_version, bl);
55 decode(trim_to, bl);
56 decode(log_entries, bl);
57 decode(temp_added, bl);
58 decode(temp_removed, bl);
59 if (struct_v >= 2) {
60 decode(updated_hit_set_history, bl);
61 }
62 if (struct_v >= 3) {
63 decode(roll_forward_to, bl);
64 } else {
65 roll_forward_to = trim_to;
66 }
67 if (struct_v >= 4) {
68 decode(backfill_or_async_recovery, bl);
69 } else {
70 // The old protocol used an empty transaction to indicate backfill or async_recovery
71 backfill_or_async_recovery = t.empty();
72 }
73 DECODE_FINISH(bl);
74 }
75
76 std::ostream &operator<<(
77 std::ostream &lhs, const ECSubWrite &rhs)
78 {
79 lhs << "ECSubWrite(tid=" << rhs.tid
80 << ", reqid=" << rhs.reqid
81 << ", at_version=" << rhs.at_version
82 << ", trim_to=" << rhs.trim_to
83 << ", roll_forward_to=" << rhs.roll_forward_to;
84 if (rhs.updated_hit_set_history)
85 lhs << ", has_updated_hit_set_history";
86 if (rhs.backfill_or_async_recovery)
87 lhs << ", backfill_or_async_recovery";
88 return lhs << ")";
89 }
90
91 void ECSubWrite::dump(Formatter *f) const
92 {
93 f->dump_unsigned("tid", tid);
94 f->dump_stream("reqid") << reqid;
95 f->dump_stream("at_version") << at_version;
96 f->dump_stream("trim_to") << trim_to;
97 f->dump_stream("roll_forward_to") << roll_forward_to;
98 f->dump_bool("has_updated_hit_set_history",
99 static_cast<bool>(updated_hit_set_history));
100 f->dump_bool("backfill_or_async_recovery", backfill_or_async_recovery);
101 }
102
103 void ECSubWrite::generate_test_instances(list<ECSubWrite*> &o)
104 {
105 o.push_back(new ECSubWrite());
106 o.back()->tid = 1;
107 o.back()->at_version = eversion_t(2, 100);
108 o.back()->trim_to = eversion_t(1, 40);
109 o.push_back(new ECSubWrite());
110 o.back()->tid = 4;
111 o.back()->reqid = osd_reqid_t(entity_name_t::CLIENT(123), 1, 45678);
112 o.back()->at_version = eversion_t(10, 300);
113 o.back()->trim_to = eversion_t(5, 42);
114 o.push_back(new ECSubWrite());
115 o.back()->tid = 9;
116 o.back()->reqid = osd_reqid_t(entity_name_t::CLIENT(123), 1, 45678);
117 o.back()->at_version = eversion_t(10, 300);
118 o.back()->trim_to = eversion_t(5, 42);
119 o.back()->roll_forward_to = eversion_t(8, 250);
120 }
121
122 void ECSubWriteReply::encode(bufferlist &bl) const
123 {
124 ENCODE_START(1, 1, bl);
125 encode(from, bl);
126 encode(tid, bl);
127 encode(last_complete, bl);
128 encode(committed, bl);
129 encode(applied, bl);
130 ENCODE_FINISH(bl);
131 }
132
133 void ECSubWriteReply::decode(bufferlist::const_iterator &bl)
134 {
135 DECODE_START(1, bl);
136 decode(from, bl);
137 decode(tid, bl);
138 decode(last_complete, bl);
139 decode(committed, bl);
140 decode(applied, bl);
141 DECODE_FINISH(bl);
142 }
143
144 std::ostream &operator<<(
145 std::ostream &lhs, const ECSubWriteReply &rhs)
146 {
147 return lhs
148 << "ECSubWriteReply(tid=" << rhs.tid
149 << ", last_complete=" << rhs.last_complete
150 << ", committed=" << rhs.committed
151 << ", applied=" << rhs.applied << ")";
152 }
153
154 void ECSubWriteReply::dump(Formatter *f) const
155 {
156 f->dump_unsigned("tid", tid);
157 f->dump_stream("last_complete") << last_complete;
158 f->dump_bool("committed", committed);
159 f->dump_bool("applied", applied);
160 }
161
162 void ECSubWriteReply::generate_test_instances(list<ECSubWriteReply*>& o)
163 {
164 o.push_back(new ECSubWriteReply());
165 o.back()->tid = 20;
166 o.back()->last_complete = eversion_t(100, 2000);
167 o.back()->committed = true;
168 o.push_back(new ECSubWriteReply());
169 o.back()->tid = 80;
170 o.back()->last_complete = eversion_t(50, 200);
171 o.back()->applied = true;
172 }
173
174 void ECSubRead::encode(bufferlist &bl, uint64_t features) const
175 {
176 if ((features & CEPH_FEATURE_OSD_FADVISE_FLAGS) == 0) {
177 ENCODE_START(2, 1, bl);
178 encode(from, bl);
179 encode(tid, bl);
180 map<hobject_t, list<pair<uint64_t, uint64_t> >> tmp;
181 for (auto m = to_read.cbegin(); m != to_read.cend(); ++m) {
182 list<pair<uint64_t, uint64_t> > tlist;
183 for (auto l = m->second.cbegin(); l != m->second.cend(); ++l) {
184 tlist.push_back(std::make_pair(l->get<0>(), l->get<1>()));
185 }
186 tmp[m->first] = tlist;
187 }
188 encode(tmp, bl);
189 encode(attrs_to_read, bl);
190 encode(subchunks, bl);
191 ENCODE_FINISH(bl);
192 return;
193 }
194
195 ENCODE_START(3, 2, bl);
196 encode(from, bl);
197 encode(tid, bl);
198 encode(to_read, bl);
199 encode(attrs_to_read, bl);
200 encode(subchunks, bl);
201 ENCODE_FINISH(bl);
202 }
203
204 void ECSubRead::decode(bufferlist::const_iterator &bl)
205 {
206 DECODE_START(3, bl);
207 decode(from, bl);
208 decode(tid, bl);
209 if (struct_v == 1) {
210 map<hobject_t, list<pair<uint64_t, uint64_t> >>tmp;
211 decode(tmp, bl);
212 for (auto m = tmp.cbegin(); m != tmp.cend(); ++m) {
213 list<boost::tuple<uint64_t, uint64_t, uint32_t> > tlist;
214 for (auto l = m->second.cbegin(); l != m->second.cend(); ++l) {
215 tlist.push_back(boost::make_tuple(l->first, l->second, 0));
216 }
217 to_read[m->first] = tlist;
218 }
219 } else {
220 decode(to_read, bl);
221 }
222 decode(attrs_to_read, bl);
223 if (struct_v > 2 && struct_v > struct_compat) {
224 decode(subchunks, bl);
225 } else {
226 for (auto &i : to_read) {
227 subchunks[i.first].push_back(make_pair(0, 1));
228 }
229 }
230 DECODE_FINISH(bl);
231 }
232
233 std::ostream &operator<<(
234 std::ostream &lhs, const ECSubRead &rhs)
235 {
236 return lhs
237 << "ECSubRead(tid=" << rhs.tid
238 << ", to_read=" << rhs.to_read
239 << ", subchunks=" << rhs.subchunks
240 << ", attrs_to_read=" << rhs.attrs_to_read << ")";
241 }
242
243 void ECSubRead::dump(Formatter *f) const
244 {
245 f->dump_stream("from") << from;
246 f->dump_unsigned("tid", tid);
247 f->open_array_section("objects");
248 for (auto i = to_read.cbegin(); i != to_read.cend(); ++i) {
249 f->open_object_section("object");
250 f->dump_stream("oid") << i->first;
251 f->open_array_section("extents");
252 for (auto j = i->second.cbegin(); j != i->second.cend(); ++j) {
253 f->open_object_section("extent");
254 f->dump_unsigned("off", j->get<0>());
255 f->dump_unsigned("len", j->get<1>());
256 f->dump_unsigned("flags", j->get<2>());
257 f->close_section();
258 }
259 f->close_section();
260 f->close_section();
261 }
262 f->close_section();
263
264 f->open_array_section("object_attrs_requested");
265 for (auto i = attrs_to_read.cbegin(); i != attrs_to_read.cend(); ++i) {
266 f->open_object_section("object");
267 f->dump_stream("oid") << *i;
268 f->close_section();
269 }
270 f->close_section();
271 }
272
273 void ECSubRead::generate_test_instances(list<ECSubRead*>& o)
274 {
275 hobject_t hoid1(sobject_t("asdf", 1));
276 hobject_t hoid2(sobject_t("asdf2", CEPH_NOSNAP));
277 o.push_back(new ECSubRead());
278 o.back()->from = pg_shard_t(2, shard_id_t(-1));
279 o.back()->tid = 1;
280 o.back()->to_read[hoid1].push_back(boost::make_tuple(100, 200, 0));
281 o.back()->to_read[hoid1].push_back(boost::make_tuple(400, 600, 0));
282 o.back()->to_read[hoid2].push_back(boost::make_tuple(400, 600, 0));
283 o.back()->attrs_to_read.insert(hoid1);
284 o.push_back(new ECSubRead());
285 o.back()->from = pg_shard_t(2, shard_id_t(-1));
286 o.back()->tid = 300;
287 o.back()->to_read[hoid1].push_back(boost::make_tuple(300, 200, 0));
288 o.back()->to_read[hoid2].push_back(boost::make_tuple(400, 600, 0));
289 o.back()->to_read[hoid2].push_back(boost::make_tuple(2000, 600, 0));
290 o.back()->attrs_to_read.insert(hoid2);
291 }
292
293 void ECSubReadReply::encode(bufferlist &bl) const
294 {
295 ENCODE_START(1, 1, bl);
296 encode(from, bl);
297 encode(tid, bl);
298 encode(buffers_read, bl);
299 encode(attrs_read, bl);
300 encode(errors, bl);
301 ENCODE_FINISH(bl);
302 }
303
304 void ECSubReadReply::decode(bufferlist::const_iterator &bl)
305 {
306 DECODE_START(1, bl);
307 decode(from, bl);
308 decode(tid, bl);
309 decode(buffers_read, bl);
310 decode(attrs_read, bl);
311 decode(errors, bl);
312 DECODE_FINISH(bl);
313 }
314
315 std::ostream &operator<<(
316 std::ostream &lhs, const ECSubReadReply &rhs)
317 {
318 return lhs
319 << "ECSubReadReply(tid=" << rhs.tid
320 << ", attrs_read=" << rhs.attrs_read.size()
321 << ")";
322 }
323
324 void ECSubReadReply::dump(Formatter *f) const
325 {
326 f->dump_stream("from") << from;
327 f->dump_unsigned("tid", tid);
328 f->open_array_section("buffers_read");
329 for (auto i = buffers_read.cbegin(); i != buffers_read.cend(); ++i) {
330 f->open_object_section("object");
331 f->dump_stream("oid") << i->first;
332 f->open_array_section("data");
333 for (auto j = i->second.cbegin(); j != i->second.cend(); ++j) {
334 f->open_object_section("extent");
335 f->dump_unsigned("off", j->first);
336 f->dump_unsigned("buf_len", j->second.length());
337 f->close_section();
338 }
339 f->close_section();
340 f->close_section();
341 }
342 f->close_section();
343
344 f->open_array_section("attrs_returned");
345 for (auto i = attrs_read.cbegin(); i != attrs_read.cend(); ++i) {
346 f->open_object_section("object_attrs");
347 f->dump_stream("oid") << i->first;
348 f->open_array_section("attrs");
349 for (auto j = i->second.cbegin(); j != i->second.cend(); ++j) {
350 f->open_object_section("attr");
351 f->dump_string("attr", j->first);
352 f->dump_unsigned("val_len", j->second.length());
353 f->close_section();
354 }
355 f->close_section();
356 f->close_section();
357 }
358 f->close_section();
359
360 f->open_array_section("errors");
361 for (auto i = errors.cbegin(); i != errors.cend(); ++i) {
362 f->open_object_section("error_pair");
363 f->dump_stream("oid") << i->first;
364 f->dump_int("error", i->second);
365 f->close_section();
366 }
367 f->close_section();
368 }
369
370 void ECSubReadReply::generate_test_instances(list<ECSubReadReply*>& o)
371 {
372 hobject_t hoid1(sobject_t("asdf", 1));
373 hobject_t hoid2(sobject_t("asdf2", CEPH_NOSNAP));
374 bufferlist bl;
375 bl.append_zero(100);
376 bufferlist bl2;
377 bl2.append_zero(200);
378 o.push_back(new ECSubReadReply());
379 o.back()->from = pg_shard_t(2, shard_id_t(-1));
380 o.back()->tid = 1;
381 o.back()->buffers_read[hoid1].push_back(make_pair(20, bl));
382 o.back()->buffers_read[hoid1].push_back(make_pair(2000, bl2));
383 o.back()->buffers_read[hoid2].push_back(make_pair(0, bl));
384 o.back()->attrs_read[hoid1]["foo"] = bl;
385 o.back()->attrs_read[hoid1]["_"] = bl2;
386 o.push_back(new ECSubReadReply());
387 o.back()->from = pg_shard_t(2, shard_id_t(-1));
388 o.back()->tid = 300;
389 o.back()->buffers_read[hoid2].push_back(make_pair(0, bl2));
390 o.back()->attrs_read[hoid2]["foo"] = bl;
391 o.back()->attrs_read[hoid2]["_"] = bl2;
392 o.back()->errors[hoid1] = -2;
393 }