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