]> git.proxmox.com Git - ceph.git/blame - ceph/src/mds/mdstypes.cc
update ceph source to reef 18.2.1
[ceph.git] / ceph / src / mds / mdstypes.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#include "mdstypes.h"
1e59de90 5#include "include/cephfs/types.h"
7c673cae
FG
6#include "MDSContext.h"
7#include "common/Formatter.h"
9f95a23c 8#include "common/StackStringStream.h"
7c673cae
FG
9
10const mds_gid_t MDS_GID_NONE = mds_gid_t(0);
7c673cae 11
f67539c2
TL
12using std::list;
13using std::make_pair;
14using std::ostream;
15using std::set;
16using std::vector;
17
18using ceph::bufferlist;
19using ceph::Formatter;
7c673cae
FG
20
21/*
22 * frag_info_t
23 */
24
25void frag_info_t::encode(bufferlist &bl) const
26{
27 ENCODE_START(3, 2, bl);
11fdf7f2
TL
28 encode(version, bl);
29 encode(mtime, bl);
30 encode(nfiles, bl);
31 encode(nsubdirs, bl);
32 encode(change_attr, bl);
7c673cae
FG
33 ENCODE_FINISH(bl);
34}
35
11fdf7f2 36void frag_info_t::decode(bufferlist::const_iterator &bl)
7c673cae
FG
37{
38 DECODE_START_LEGACY_COMPAT_LEN(3, 2, 2, bl);
11fdf7f2
TL
39 decode(version, bl);
40 decode(mtime, bl);
41 decode(nfiles, bl);
42 decode(nsubdirs, bl);
7c673cae 43 if (struct_v >= 3)
11fdf7f2 44 decode(change_attr, bl);
7c673cae
FG
45 else
46 change_attr = 0;
47 DECODE_FINISH(bl);
48}
49
50void frag_info_t::dump(Formatter *f) const
51{
52 f->dump_unsigned("version", version);
53 f->dump_stream("mtime") << mtime;
54 f->dump_unsigned("num_files", nfiles);
55 f->dump_unsigned("num_subdirs", nsubdirs);
9f95a23c 56 f->dump_unsigned("change_attr", change_attr);
7c673cae
FG
57}
58
f67539c2
TL
59void frag_info_t::decode_json(JSONObj *obj){
60
61 JSONDecoder::decode_json("version", version, obj, true);
62 JSONDecoder::decode_json("mtime", mtime, obj, true);
63 JSONDecoder::decode_json("num_files", nfiles, obj, true);
64 JSONDecoder::decode_json("num_subdirs", nsubdirs, obj, true);
65 JSONDecoder::decode_json("change_attr", change_attr, obj, true);
66}
67
9f95a23c 68void frag_info_t::generate_test_instances(std::list<frag_info_t*>& ls)
7c673cae
FG
69{
70 ls.push_back(new frag_info_t);
71 ls.push_back(new frag_info_t);
72 ls.back()->version = 1;
73 ls.back()->mtime = utime_t(2, 3);
74 ls.back()->nfiles = 4;
75 ls.back()->nsubdirs = 5;
76}
77
78ostream& operator<<(ostream &out, const frag_info_t &f)
79{
80 if (f == frag_info_t())
81 return out << "f()";
82 out << "f(v" << f.version;
83 if (f.mtime != utime_t())
84 out << " m" << f.mtime;
85 if (f.nfiles || f.nsubdirs)
86 out << " " << f.size() << "=" << f.nfiles << "+" << f.nsubdirs;
87 out << ")";
88 return out;
89}
90
91
92/*
93 * nest_info_t
94 */
95
96void nest_info_t::encode(bufferlist &bl) const
97{
98 ENCODE_START(3, 2, bl);
11fdf7f2
TL
99 encode(version, bl);
100 encode(rbytes, bl);
101 encode(rfiles, bl);
102 encode(rsubdirs, bl);
7c673cae
FG
103 {
104 // removed field
105 int64_t ranchors = 0;
11fdf7f2 106 encode(ranchors, bl);
7c673cae 107 }
11fdf7f2
TL
108 encode(rsnaps, bl);
109 encode(rctime, bl);
7c673cae
FG
110 ENCODE_FINISH(bl);
111}
112
11fdf7f2 113void nest_info_t::decode(bufferlist::const_iterator &bl)
7c673cae
FG
114{
115 DECODE_START_LEGACY_COMPAT_LEN(3, 2, 2, bl);
11fdf7f2
TL
116 decode(version, bl);
117 decode(rbytes, bl);
118 decode(rfiles, bl);
119 decode(rsubdirs, bl);
7c673cae
FG
120 {
121 int64_t ranchors;
11fdf7f2 122 decode(ranchors, bl);
7c673cae 123 }
11fdf7f2
TL
124 decode(rsnaps, bl);
125 decode(rctime, bl);
7c673cae
FG
126 DECODE_FINISH(bl);
127}
128
129void nest_info_t::dump(Formatter *f) const
130{
131 f->dump_unsigned("version", version);
132 f->dump_unsigned("rbytes", rbytes);
133 f->dump_unsigned("rfiles", rfiles);
134 f->dump_unsigned("rsubdirs", rsubdirs);
11fdf7f2 135 f->dump_unsigned("rsnaps", rsnaps);
7c673cae
FG
136 f->dump_stream("rctime") << rctime;
137}
138
f67539c2
TL
139void nest_info_t::decode_json(JSONObj *obj){
140
141 JSONDecoder::decode_json("version", version, obj, true);
142 JSONDecoder::decode_json("rbytes", rbytes, obj, true);
143 JSONDecoder::decode_json("rfiles", rfiles, obj, true);
144 JSONDecoder::decode_json("rsubdirs", rsubdirs, obj, true);
145 JSONDecoder::decode_json("rsnaps", rsnaps, obj, true);
146 JSONDecoder::decode_json("rctime", rctime, obj, true);
147}
148
9f95a23c 149void nest_info_t::generate_test_instances(std::list<nest_info_t*>& ls)
7c673cae
FG
150{
151 ls.push_back(new nest_info_t);
152 ls.push_back(new nest_info_t);
153 ls.back()->version = 1;
154 ls.back()->rbytes = 2;
155 ls.back()->rfiles = 3;
156 ls.back()->rsubdirs = 4;
11fdf7f2 157 ls.back()->rsnaps = 6;
7c673cae
FG
158 ls.back()->rctime = utime_t(7, 8);
159}
160
161ostream& operator<<(ostream &out, const nest_info_t &n)
162{
163 if (n == nest_info_t())
164 return out << "n()";
165 out << "n(v" << n.version;
166 if (n.rctime != utime_t())
167 out << " rc" << n.rctime;
168 if (n.rbytes)
169 out << " b" << n.rbytes;
11fdf7f2
TL
170 if (n.rsnaps)
171 out << " rs" << n.rsnaps;
7c673cae
FG
172 if (n.rfiles || n.rsubdirs)
173 out << " " << n.rsize() << "=" << n.rfiles << "+" << n.rsubdirs;
174 out << ")";
175 return out;
176}
177
178/*
179 * quota_info_t
180 */
181void quota_info_t::dump(Formatter *f) const
182{
183 f->dump_int("max_bytes", max_bytes);
184 f->dump_int("max_files", max_files);
185}
186
f67539c2
TL
187void quota_info_t::decode_json(JSONObj *obj){
188
189 JSONDecoder::decode_json("max_bytes", max_bytes, obj, true);
190 JSONDecoder::decode_json("max_files", max_files, obj, true);
191}
192
9f95a23c 193void quota_info_t::generate_test_instances(std::list<quota_info_t *>& ls)
7c673cae
FG
194{
195 ls.push_back(new quota_info_t);
196 ls.push_back(new quota_info_t);
197 ls.back()->max_bytes = 16;
198 ls.back()->max_files = 16;
199}
200
201ostream& operator<<(ostream &out, const quota_info_t &n)
202{
203 out << "quota("
204 << "max_bytes = " << n.max_bytes
205 << " max_files = " << n.max_files
206 << ")";
207 return out;
208}
209
210/*
211 * client_writeable_range_t
212 */
213
214void client_writeable_range_t::encode(bufferlist &bl) const
215{
216 ENCODE_START(2, 2, bl);
11fdf7f2
TL
217 encode(range.first, bl);
218 encode(range.last, bl);
219 encode(follows, bl);
7c673cae
FG
220 ENCODE_FINISH(bl);
221}
222
11fdf7f2 223void client_writeable_range_t::decode(bufferlist::const_iterator& bl)
7c673cae
FG
224{
225 DECODE_START_LEGACY_COMPAT_LEN(2, 2, 2, bl);
11fdf7f2
TL
226 decode(range.first, bl);
227 decode(range.last, bl);
228 decode(follows, bl);
7c673cae
FG
229 DECODE_FINISH(bl);
230}
231
232void client_writeable_range_t::dump(Formatter *f) const
233{
234 f->open_object_section("byte range");
235 f->dump_unsigned("first", range.first);
236 f->dump_unsigned("last", range.last);
237 f->close_section();
238 f->dump_unsigned("follows", follows);
239}
240
f67539c2
TL
241void client_writeable_range_t::byte_range_t::decode_json(JSONObj *obj){
242
243 JSONDecoder::decode_json("first", first, obj, true);
244 JSONDecoder::decode_json("last", last, obj, true);
245}
246
9f95a23c 247void client_writeable_range_t::generate_test_instances(std::list<client_writeable_range_t*>& ls)
7c673cae
FG
248{
249 ls.push_back(new client_writeable_range_t);
250 ls.push_back(new client_writeable_range_t);
251 ls.back()->range.first = 123;
252 ls.back()->range.last = 456;
253 ls.back()->follows = 12;
254}
255
256ostream& operator<<(ostream& out, const client_writeable_range_t& r)
257{
258 return out << r.range.first << '-' << r.range.last << "@" << r.follows;
259}
260
261/*
262 * inline_data_t
263 */
264void inline_data_t::encode(bufferlist &bl) const
265{
11fdf7f2
TL
266 using ceph::encode;
267 encode(version, bl);
7c673cae 268 if (blp)
11fdf7f2 269 encode(*blp, bl);
7c673cae 270 else
11fdf7f2 271 encode(bufferlist(), bl);
7c673cae 272}
11fdf7f2 273void inline_data_t::decode(bufferlist::const_iterator &p)
7c673cae 274{
11fdf7f2
TL
275 using ceph::decode;
276 decode(version, p);
7c673cae 277 uint32_t inline_len;
11fdf7f2 278 decode(inline_len, p);
f67539c2
TL
279 if (inline_len > 0) {
280 ceph::buffer::list bl;
281 decode_nohead(inline_len, bl, p);
282 set_data(bl);
283 } else
7c673cae
FG
284 free_data();
285}
286
7c673cae
FG
287
288/*
289 * fnode_t
290 */
291void fnode_t::encode(bufferlist &bl) const
292{
293 ENCODE_START(4, 3, bl);
11fdf7f2
TL
294 encode(version, bl);
295 encode(snap_purged_thru, bl);
296 encode(fragstat, bl);
297 encode(accounted_fragstat, bl);
298 encode(rstat, bl);
299 encode(accounted_rstat, bl);
300 encode(damage_flags, bl);
301 encode(recursive_scrub_version, bl);
302 encode(recursive_scrub_stamp, bl);
303 encode(localized_scrub_version, bl);
304 encode(localized_scrub_stamp, bl);
7c673cae
FG
305 ENCODE_FINISH(bl);
306}
307
11fdf7f2 308void fnode_t::decode(bufferlist::const_iterator &bl)
7c673cae
FG
309{
310 DECODE_START_LEGACY_COMPAT_LEN(3, 2, 2, bl);
11fdf7f2
TL
311 decode(version, bl);
312 decode(snap_purged_thru, bl);
313 decode(fragstat, bl);
314 decode(accounted_fragstat, bl);
315 decode(rstat, bl);
316 decode(accounted_rstat, bl);
7c673cae 317 if (struct_v >= 3) {
11fdf7f2 318 decode(damage_flags, bl);
7c673cae
FG
319 }
320 if (struct_v >= 4) {
11fdf7f2
TL
321 decode(recursive_scrub_version, bl);
322 decode(recursive_scrub_stamp, bl);
323 decode(localized_scrub_version, bl);
324 decode(localized_scrub_stamp, bl);
7c673cae
FG
325 }
326 DECODE_FINISH(bl);
327}
328
329void fnode_t::dump(Formatter *f) const
330{
331 f->dump_unsigned("version", version);
332 f->dump_unsigned("snap_purged_thru", snap_purged_thru);
333
334 f->open_object_section("fragstat");
335 fragstat.dump(f);
336 f->close_section();
337
338 f->open_object_section("accounted_fragstat");
339 accounted_fragstat.dump(f);
340 f->close_section();
341
342 f->open_object_section("rstat");
343 rstat.dump(f);
344 f->close_section();
345
346 f->open_object_section("accounted_rstat");
347 accounted_rstat.dump(f);
348 f->close_section();
349}
f67539c2
TL
350void fnode_t::decode_json(JSONObj *obj){
351 JSONDecoder::decode_json("version", version, obj, true);
352 uint64_t tmp;
353 JSONDecoder::decode_json("snap_purged_thru", tmp, obj, true);
354 snap_purged_thru.val = tmp;
355 JSONDecoder::decode_json("fragstat", fragstat, obj, true);
356 JSONDecoder::decode_json("accounted_fragstat", accounted_fragstat, obj, true);
357 JSONDecoder::decode_json("rstat", rstat, obj, true);
358 JSONDecoder::decode_json("accounted_rstat", accounted_rstat, obj, true);
359}
9f95a23c 360void fnode_t::generate_test_instances(std::list<fnode_t*>& ls)
7c673cae
FG
361{
362 ls.push_back(new fnode_t);
363 ls.push_back(new fnode_t);
364 ls.back()->version = 1;
365 ls.back()->snap_purged_thru = 2;
366 list<frag_info_t*> fls;
367 frag_info_t::generate_test_instances(fls);
368 ls.back()->fragstat = *fls.back();
369 ls.back()->accounted_fragstat = *fls.front();
370 list<nest_info_t*> nls;
371 nest_info_t::generate_test_instances(nls);
372 ls.back()->rstat = *nls.front();
373 ls.back()->accounted_rstat = *nls.back();
374}
375
376
377/*
378 * old_rstat_t
379 */
380void old_rstat_t::encode(bufferlist& bl) const
381{
382 ENCODE_START(2, 2, bl);
11fdf7f2
TL
383 encode(first, bl);
384 encode(rstat, bl);
385 encode(accounted_rstat, bl);
7c673cae
FG
386 ENCODE_FINISH(bl);
387}
388
11fdf7f2 389void old_rstat_t::decode(bufferlist::const_iterator& bl)
7c673cae
FG
390{
391 DECODE_START_LEGACY_COMPAT_LEN(2, 2, 2, bl);
11fdf7f2
TL
392 decode(first, bl);
393 decode(rstat, bl);
394 decode(accounted_rstat, bl);
7c673cae
FG
395 DECODE_FINISH(bl);
396}
397
398void old_rstat_t::dump(Formatter *f) const
399{
400 f->dump_unsigned("snapid", first);
401 f->open_object_section("rstat");
402 rstat.dump(f);
403 f->close_section();
404 f->open_object_section("accounted_rstat");
405 accounted_rstat.dump(f);
406 f->close_section();
407}
408
9f95a23c 409void old_rstat_t::generate_test_instances(std::list<old_rstat_t*>& ls)
7c673cae
FG
410{
411 ls.push_back(new old_rstat_t());
412 ls.push_back(new old_rstat_t());
413 ls.back()->first = 12;
414 list<nest_info_t*> nls;
415 nest_info_t::generate_test_instances(nls);
416 ls.back()->rstat = *nls.back();
417 ls.back()->accounted_rstat = *nls.front();
418}
419
11fdf7f2
TL
420/*
421 * feature_bitset_t
422 */
423feature_bitset_t::feature_bitset_t(unsigned long value)
424{
425 if (value) {
426 for (size_t i = 0; i < sizeof(value) * 8; i += bits_per_block) {
427 _vec.push_back((block_type)(value >> i));
428 }
429 }
430}
431
432feature_bitset_t::feature_bitset_t(const vector<size_t>& array)
433{
434 if (!array.empty()) {
435 size_t n = array.back();
436 n += bits_per_block;
437 n /= bits_per_block;
438 _vec.resize(n, 0);
439
440 size_t last = 0;
441 for (auto& bit : array) {
442 if (bit > last)
443 last = bit;
444 else
445 ceph_assert(bit == last);
446 _vec[bit / bits_per_block] |= (block_type)1 << (bit % bits_per_block);
447 }
448 }
449}
450
451feature_bitset_t& feature_bitset_t::operator-=(const feature_bitset_t& other)
452{
453 for (size_t i = 0; i < _vec.size(); ++i) {
454 if (i >= other._vec.size())
455 break;
456 _vec[i] &= ~other._vec[i];
457 }
458 return *this;
459}
460
461void feature_bitset_t::encode(bufferlist& bl) const {
462 using ceph::encode;
463 using ceph::encode_nohead;
464 uint32_t len = _vec.size() * sizeof(block_type);
465 encode(len, bl);
466 encode_nohead(_vec, bl);
467}
468
469void feature_bitset_t::decode(bufferlist::const_iterator &p) {
470 using ceph::decode;
471 using ceph::decode_nohead;
472 uint32_t len;
473 decode(len, p);
474
475 _vec.clear();
476 if (len >= sizeof(block_type))
477 decode_nohead(len / sizeof(block_type), _vec, p);
478
479 if (len % sizeof(block_type)) {
480 ceph_le64 buf{};
481 p.copy(len % sizeof(block_type), (char*)&buf);
482 _vec.push_back((block_type)buf);
483 }
484}
485
9f95a23c
TL
486void feature_bitset_t::dump(Formatter *f) const {
487 CachedStackStringStream css;
488 print(*css);
489 f->dump_string("feature_bits", css->strv());
490}
491
11fdf7f2
TL
492void feature_bitset_t::print(ostream& out) const
493{
494 std::ios_base::fmtflags f(out.flags());
05a536ef
TL
495 int size = _vec.size();
496 if (!size) {
497 out << "0x0";
498 } else {
499 out << "0x";
500 for (int i = size - 1; i >= 0; --i)
501 out << std::setfill('0') << std::setw(sizeof(block_type) * 2)
502 << std::hex << _vec[i];
503 }
11fdf7f2
TL
504 out.flags(f);
505}
506
9f95a23c
TL
507/*
508 * metric_spec_t
509 */
510void metric_spec_t::encode(bufferlist& bl) const {
511 using ceph::encode;
512 ENCODE_START(1, 1, bl);
513 encode(metric_flags, bl);
514 ENCODE_FINISH(bl);
515}
516
517void metric_spec_t::decode(bufferlist::const_iterator &p) {
518 using ceph::decode;
519 DECODE_START(1, p);
520 decode(metric_flags, p);
521 DECODE_FINISH(p);
522}
523
524void metric_spec_t::dump(Formatter *f) const {
525 f->dump_object("metric_flags", metric_flags);
526}
527
528void metric_spec_t::print(ostream& out) const
529{
530 out << "{metric_flags: '" << metric_flags << "'}";
531}
532
11fdf7f2
TL
533/*
534 * client_metadata_t
535 */
536void client_metadata_t::encode(bufferlist& bl) const
537{
9f95a23c 538 ENCODE_START(3, 1, bl);
11fdf7f2
TL
539 encode(kv_map, bl);
540 encode(features, bl);
9f95a23c 541 encode(metric_spec, bl);
11fdf7f2
TL
542 ENCODE_FINISH(bl);
543}
544
545void client_metadata_t::decode(bufferlist::const_iterator& p)
546{
9f95a23c 547 DECODE_START(3, p);
11fdf7f2
TL
548 decode(kv_map, p);
549 if (struct_v >= 2)
550 decode(features, p);
9f95a23c
TL
551 if (struct_v >= 3) {
552 decode(metric_spec, p);
553 }
11fdf7f2
TL
554 DECODE_FINISH(p);
555}
556
557void client_metadata_t::dump(Formatter *f) const
558{
9f95a23c
TL
559 f->dump_object("client_features", features);
560 f->dump_object("metric_spec", metric_spec);
92f5a8d4
TL
561 for (const auto& [name, val] : kv_map)
562 f->dump_string(name.c_str(), val);
11fdf7f2
TL
563}
564
7c673cae
FG
565/*
566 * session_info_t
567 */
568void session_info_t::encode(bufferlist& bl, uint64_t features) const
569{
11fdf7f2
TL
570 ENCODE_START(7, 7, bl);
571 encode(inst, bl, features);
572 encode(completed_requests, bl);
573 encode(prealloc_inos, bl); // hacky, see below.
f67539c2 574 encode((__u32)0, bl); // used_inos
11fdf7f2
TL
575 encode(completed_flushes, bl);
576 encode(auth_name, bl);
577 encode(client_metadata, bl);
7c673cae
FG
578 ENCODE_FINISH(bl);
579}
580
11fdf7f2 581void session_info_t::decode(bufferlist::const_iterator& p)
7c673cae 582{
11fdf7f2
TL
583 DECODE_START_LEGACY_COMPAT_LEN(7, 2, 2, p);
584 decode(inst, p);
7c673cae
FG
585 if (struct_v <= 2) {
586 set<ceph_tid_t> s;
11fdf7f2 587 decode(s, p);
7c673cae
FG
588 while (!s.empty()) {
589 completed_requests[*s.begin()] = inodeno_t();
590 s.erase(s.begin());
591 }
592 } else {
11fdf7f2 593 decode(completed_requests, p);
7c673cae 594 }
11fdf7f2 595 decode(prealloc_inos, p);
f67539c2
TL
596 {
597 interval_set<inodeno_t> used_inos;
598 decode(used_inos, p);
599 prealloc_inos.insert(used_inos);
600 }
11fdf7f2
TL
601 if (struct_v >= 4 && struct_v < 7) {
602 decode(client_metadata.kv_map, p);
7c673cae
FG
603 }
604 if (struct_v >= 5) {
11fdf7f2 605 decode(completed_flushes, p);
7c673cae
FG
606 }
607 if (struct_v >= 6) {
11fdf7f2
TL
608 decode(auth_name, p);
609 }
610 if (struct_v >= 7) {
611 decode(client_metadata, p);
7c673cae
FG
612 }
613 DECODE_FINISH(p);
614}
615
616void session_info_t::dump(Formatter *f) const
617{
618 f->dump_stream("inst") << inst;
619
620 f->open_array_section("completed_requests");
92f5a8d4 621 for (const auto& [tid, ino] : completed_requests) {
7c673cae 622 f->open_object_section("request");
92f5a8d4
TL
623 f->dump_unsigned("tid", tid);
624 f->dump_stream("created_ino") << ino;
7c673cae
FG
625 f->close_section();
626 }
627 f->close_section();
628
629 f->open_array_section("prealloc_inos");
92f5a8d4 630 for (const auto& [start, len] : prealloc_inos) {
7c673cae 631 f->open_object_section("ino_range");
9f95a23c 632 f->dump_stream("start") << start;
92f5a8d4 633 f->dump_unsigned("length", len);
7c673cae
FG
634 f->close_section();
635 }
636 f->close_section();
637
92f5a8d4 638 f->dump_object("client_metadata", client_metadata);
7c673cae
FG
639}
640
9f95a23c 641void session_info_t::generate_test_instances(std::list<session_info_t*>& ls)
7c673cae
FG
642{
643 ls.push_back(new session_info_t);
644 ls.push_back(new session_info_t);
645 ls.back()->inst = entity_inst_t(entity_name_t::MDS(12), entity_addr_t());
646 ls.back()->completed_requests.insert(make_pair(234, inodeno_t(111222)));
647 ls.back()->completed_requests.insert(make_pair(237, inodeno_t(222333)));
648 ls.back()->prealloc_inos.insert(333, 12);
649 ls.back()->prealloc_inos.insert(377, 112);
650 // we can't add used inos; they're cleared on decode
651}
652
653
654/*
655 * string_snap_t
656 */
657void string_snap_t::encode(bufferlist& bl) const
658{
659 ENCODE_START(2, 2, bl);
11fdf7f2
TL
660 encode(name, bl);
661 encode(snapid, bl);
7c673cae
FG
662 ENCODE_FINISH(bl);
663}
664
11fdf7f2 665void string_snap_t::decode(bufferlist::const_iterator& bl)
7c673cae
FG
666{
667 DECODE_START_LEGACY_COMPAT_LEN(2, 2, 2, bl);
11fdf7f2
TL
668 decode(name, bl);
669 decode(snapid, bl);
7c673cae
FG
670 DECODE_FINISH(bl);
671}
672
673void string_snap_t::dump(Formatter *f) const
674{
675 f->dump_string("name", name);
676 f->dump_unsigned("snapid", snapid);
677}
678
9f95a23c 679void string_snap_t::generate_test_instances(std::list<string_snap_t*>& ls)
7c673cae
FG
680{
681 ls.push_back(new string_snap_t);
682 ls.push_back(new string_snap_t);
683 ls.back()->name = "foo";
684 ls.back()->snapid = 123;
685 ls.push_back(new string_snap_t);
686 ls.back()->name = "bar";
687 ls.back()->snapid = 456;
688}
689
690
691/*
692 * MDSCacheObjectInfo
693 */
694void MDSCacheObjectInfo::encode(bufferlist& bl) const
695{
696 ENCODE_START(2, 2, bl);
11fdf7f2
TL
697 encode(ino, bl);
698 encode(dirfrag, bl);
699 encode(dname, bl);
700 encode(snapid, bl);
7c673cae
FG
701 ENCODE_FINISH(bl);
702}
703
11fdf7f2 704void MDSCacheObjectInfo::decode(bufferlist::const_iterator& p)
7c673cae
FG
705{
706 DECODE_START_LEGACY_COMPAT_LEN(2, 2, 2, p);
11fdf7f2
TL
707 decode(ino, p);
708 decode(dirfrag, p);
709 decode(dname, p);
710 decode(snapid, p);
7c673cae
FG
711 DECODE_FINISH(p);
712}
713
714void MDSCacheObjectInfo::dump(Formatter *f) const
715{
716 f->dump_unsigned("ino", ino);
717 f->dump_stream("dirfrag") << dirfrag;
718 f->dump_string("name", dname);
719 f->dump_unsigned("snapid", snapid);
720}
721
9f95a23c 722void MDSCacheObjectInfo::generate_test_instances(std::list<MDSCacheObjectInfo*>& ls)
7c673cae
FG
723{
724 ls.push_back(new MDSCacheObjectInfo);
725 ls.push_back(new MDSCacheObjectInfo);
726 ls.back()->ino = 1;
727 ls.back()->dirfrag = dirfrag_t(2, 3);
728 ls.back()->dname = "fooname";
729 ls.back()->snapid = CEPH_NOSNAP;
730 ls.push_back(new MDSCacheObjectInfo);
731 ls.back()->ino = 121;
732 ls.back()->dirfrag = dirfrag_t(222, 0);
733 ls.back()->dname = "bar foo";
734 ls.back()->snapid = 21322;
735}
736
737/*
738 * mds_table_pending_t
739 */
740void mds_table_pending_t::encode(bufferlist& bl) const
741{
742 ENCODE_START(2, 2, bl);
11fdf7f2
TL
743 encode(reqid, bl);
744 encode(mds, bl);
745 encode(tid, bl);
7c673cae
FG
746 ENCODE_FINISH(bl);
747}
748
11fdf7f2 749void mds_table_pending_t::decode(bufferlist::const_iterator& bl)
7c673cae
FG
750{
751 DECODE_START_LEGACY_COMPAT_LEN(2, 2, 2, bl);
11fdf7f2
TL
752 decode(reqid, bl);
753 decode(mds, bl);
754 decode(tid, bl);
7c673cae
FG
755 DECODE_FINISH(bl);
756}
757
758void mds_table_pending_t::dump(Formatter *f) const
759{
760 f->dump_unsigned("reqid", reqid);
761 f->dump_unsigned("mds", mds);
762 f->dump_unsigned("tid", tid);
763}
764
9f95a23c 765void mds_table_pending_t::generate_test_instances(std::list<mds_table_pending_t*>& ls)
7c673cae
FG
766{
767 ls.push_back(new mds_table_pending_t);
768 ls.push_back(new mds_table_pending_t);
769 ls.back()->reqid = 234;
770 ls.back()->mds = 2;
771 ls.back()->tid = 35434;
772}
773
aee94f69
TL
774void metareqid_t::dump(ceph::Formatter* f) const {
775 f->dump_object("entity", name);
776 f->dump_unsigned("tid", tid);
777}
7c673cae
FG
778
779/*
780 * inode_load_vec_t
781 */
782void inode_load_vec_t::encode(bufferlist &bl) const
783{
784 ENCODE_START(2, 2, bl);
94b18763 785 for (const auto &i : vec) {
11fdf7f2 786 encode(i, bl);
94b18763 787 }
7c673cae
FG
788 ENCODE_FINISH(bl);
789}
790
11fdf7f2 791void inode_load_vec_t::decode(bufferlist::const_iterator &p)
7c673cae
FG
792{
793 DECODE_START_LEGACY_COMPAT_LEN(2, 2, 2, p);
94b18763 794 for (auto &i : vec) {
11fdf7f2 795 decode(i, p);
94b18763 796 }
7c673cae
FG
797 DECODE_FINISH(p);
798}
799
11fdf7f2 800void inode_load_vec_t::dump(Formatter *f) const
7c673cae
FG
801{
802 f->open_array_section("Decay Counters");
94b18763 803 for (const auto &i : vec) {
7c673cae 804 f->open_object_section("Decay Counter");
94b18763 805 i.dump(f);
7c673cae
FG
806 f->close_section();
807 }
808 f->close_section();
809}
810
9f95a23c 811void inode_load_vec_t::generate_test_instances(std::list<inode_load_vec_t*>& ls)
7c673cae 812{
11fdf7f2 813 ls.push_back(new inode_load_vec_t(DecayRate()));
7c673cae
FG
814}
815
816
817/*
818 * dirfrag_load_vec_t
819 */
820void dirfrag_load_vec_t::dump(Formatter *f) const
821{
822 f->open_array_section("Decay Counters");
94b18763 823 for (const auto &i : vec) {
7c673cae 824 f->open_object_section("Decay Counter");
94b18763 825 i.dump(f);
7c673cae
FG
826 f->close_section();
827 }
828 f->close_section();
829}
830
11fdf7f2 831void dirfrag_load_vec_t::dump(Formatter *f, const DecayRate& rate) const
28e407b8 832{
11fdf7f2
TL
833 f->dump_float("meta_load", meta_load());
834 f->dump_float("IRD", get(META_POP_IRD).get());
835 f->dump_float("IWR", get(META_POP_IWR).get());
836 f->dump_float("READDIR", get(META_POP_READDIR).get());
837 f->dump_float("FETCH", get(META_POP_FETCH).get());
838 f->dump_float("STORE", get(META_POP_STORE).get());
28e407b8
AA
839}
840
11fdf7f2 841void dirfrag_load_vec_t::generate_test_instances(std::list<dirfrag_load_vec_t*>& ls)
7c673cae 842{
11fdf7f2 843 ls.push_back(new dirfrag_load_vec_t(DecayRate()));
7c673cae
FG
844}
845
846/*
847 * mds_load_t
848 */
849void mds_load_t::encode(bufferlist &bl) const {
850 ENCODE_START(2, 2, bl);
11fdf7f2
TL
851 encode(auth, bl);
852 encode(all, bl);
853 encode(req_rate, bl);
854 encode(cache_hit_rate, bl);
855 encode(queue_len, bl);
856 encode(cpu_load_avg, bl);
7c673cae
FG
857 ENCODE_FINISH(bl);
858}
859
11fdf7f2 860void mds_load_t::decode(bufferlist::const_iterator &bl) {
7c673cae 861 DECODE_START_LEGACY_COMPAT_LEN(2, 2, 2, bl);
11fdf7f2
TL
862 decode(auth, bl);
863 decode(all, bl);
864 decode(req_rate, bl);
865 decode(cache_hit_rate, bl);
866 decode(queue_len, bl);
867 decode(cpu_load_avg, bl);
7c673cae
FG
868 DECODE_FINISH(bl);
869}
870
871void mds_load_t::dump(Formatter *f) const
872{
873 f->dump_float("request rate", req_rate);
874 f->dump_float("cache hit rate", cache_hit_rate);
875 f->dump_float("queue length", queue_len);
876 f->dump_float("cpu load", cpu_load_avg);
877 f->open_object_section("auth dirfrag");
878 auth.dump(f);
879 f->close_section();
880 f->open_object_section("all dirfrags");
881 all.dump(f);
882 f->close_section();
883}
884
11fdf7f2 885void mds_load_t::generate_test_instances(std::list<mds_load_t*>& ls)
7c673cae 886{
11fdf7f2 887 ls.push_back(new mds_load_t(DecayRate()));
7c673cae
FG
888}
889
890/*
891 * cap_reconnect_t
892 */
893void cap_reconnect_t::encode(bufferlist& bl) const {
894 ENCODE_START(2, 1, bl);
895 encode_old(bl); // extract out when something changes
11fdf7f2 896 encode(snap_follows, bl);
7c673cae
FG
897 ENCODE_FINISH(bl);
898}
899
900void cap_reconnect_t::encode_old(bufferlist& bl) const {
11fdf7f2
TL
901 using ceph::encode;
902 encode(path, bl);
7c673cae 903 capinfo.flock_len = flockbl.length();
11fdf7f2 904 encode(capinfo, bl);
f67539c2 905 ceph::encode_nohead(flockbl, bl);
7c673cae
FG
906}
907
11fdf7f2
TL
908void cap_reconnect_t::decode(bufferlist::const_iterator& bl) {
909 DECODE_START(2, bl);
7c673cae
FG
910 decode_old(bl); // extract out when something changes
911 if (struct_v >= 2)
11fdf7f2 912 decode(snap_follows, bl);
7c673cae
FG
913 DECODE_FINISH(bl);
914}
915
11fdf7f2
TL
916void cap_reconnect_t::decode_old(bufferlist::const_iterator& bl) {
917 using ceph::decode;
918 decode(path, bl);
919 decode(capinfo, bl);
f67539c2 920 ceph::decode_nohead(capinfo.flock_len, flockbl, bl);
7c673cae
FG
921}
922
923void cap_reconnect_t::dump(Formatter *f) const
924{
925 f->dump_string("path", path);
926 f->dump_int("cap_id", capinfo.cap_id);
927 f->dump_string("cap wanted", ccap_string(capinfo.wanted));
928 f->dump_string("cap issued", ccap_string(capinfo.issued));
929 f->dump_int("snaprealm", capinfo.snaprealm);
930 f->dump_int("path base ino", capinfo.pathbase);
931 f->dump_string("has file locks", capinfo.flock_len ? "true" : "false");
932}
933
9f95a23c 934void cap_reconnect_t::generate_test_instances(std::list<cap_reconnect_t*>& ls)
7c673cae
FG
935{
936 ls.push_back(new cap_reconnect_t);
937 ls.back()->path = "/test/path";
938 ls.back()->capinfo.cap_id = 1;
939}
940
11fdf7f2
TL
941/*
942 * snaprealm_reconnect_t
943 */
944void snaprealm_reconnect_t::encode(bufferlist& bl) const {
945 ENCODE_START(1, 1, bl);
946 encode_old(bl); // extract out when something changes
947 ENCODE_FINISH(bl);
948}
949
950void snaprealm_reconnect_t::encode_old(bufferlist& bl) const {
951 using ceph::encode;
952 encode(realm, bl);
953}
954
955void snaprealm_reconnect_t::decode(bufferlist::const_iterator& bl) {
956 DECODE_START(1, bl);
957 decode_old(bl); // extract out when something changes
958 DECODE_FINISH(bl);
959}
960
961void snaprealm_reconnect_t::decode_old(bufferlist::const_iterator& bl) {
962 using ceph::decode;
963 decode(realm, bl);
964}
965
966void snaprealm_reconnect_t::dump(Formatter *f) const
967{
968 f->dump_int("ino", realm.ino);
969 f->dump_int("seq", realm.seq);
970 f->dump_int("parent", realm.parent);
971}
972
9f95a23c 973void snaprealm_reconnect_t::generate_test_instances(std::list<snaprealm_reconnect_t*>& ls)
11fdf7f2
TL
974{
975 ls.push_back(new snaprealm_reconnect_t);
976 ls.back()->realm.ino = 0x10000000001ULL;
977 ls.back()->realm.seq = 2;
978 ls.back()->realm.parent = 1;
979}