]> git.proxmox.com Git - ceph.git/blob - ceph/src/mds/mdstypes.cc
update ceph source to reef 18.2.1
[ceph.git] / ceph / src / mds / mdstypes.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 "mdstypes.h"
5 #include "include/cephfs/types.h"
6 #include "MDSContext.h"
7 #include "common/Formatter.h"
8 #include "common/StackStringStream.h"
9
10 const mds_gid_t MDS_GID_NONE = mds_gid_t(0);
11
12 using std::list;
13 using std::make_pair;
14 using std::ostream;
15 using std::set;
16 using std::vector;
17
18 using ceph::bufferlist;
19 using ceph::Formatter;
20
21 /*
22 * frag_info_t
23 */
24
25 void frag_info_t::encode(bufferlist &bl) const
26 {
27 ENCODE_START(3, 2, bl);
28 encode(version, bl);
29 encode(mtime, bl);
30 encode(nfiles, bl);
31 encode(nsubdirs, bl);
32 encode(change_attr, bl);
33 ENCODE_FINISH(bl);
34 }
35
36 void frag_info_t::decode(bufferlist::const_iterator &bl)
37 {
38 DECODE_START_LEGACY_COMPAT_LEN(3, 2, 2, bl);
39 decode(version, bl);
40 decode(mtime, bl);
41 decode(nfiles, bl);
42 decode(nsubdirs, bl);
43 if (struct_v >= 3)
44 decode(change_attr, bl);
45 else
46 change_attr = 0;
47 DECODE_FINISH(bl);
48 }
49
50 void 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);
56 f->dump_unsigned("change_attr", change_attr);
57 }
58
59 void 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
68 void frag_info_t::generate_test_instances(std::list<frag_info_t*>& ls)
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
78 ostream& 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
96 void nest_info_t::encode(bufferlist &bl) const
97 {
98 ENCODE_START(3, 2, bl);
99 encode(version, bl);
100 encode(rbytes, bl);
101 encode(rfiles, bl);
102 encode(rsubdirs, bl);
103 {
104 // removed field
105 int64_t ranchors = 0;
106 encode(ranchors, bl);
107 }
108 encode(rsnaps, bl);
109 encode(rctime, bl);
110 ENCODE_FINISH(bl);
111 }
112
113 void nest_info_t::decode(bufferlist::const_iterator &bl)
114 {
115 DECODE_START_LEGACY_COMPAT_LEN(3, 2, 2, bl);
116 decode(version, bl);
117 decode(rbytes, bl);
118 decode(rfiles, bl);
119 decode(rsubdirs, bl);
120 {
121 int64_t ranchors;
122 decode(ranchors, bl);
123 }
124 decode(rsnaps, bl);
125 decode(rctime, bl);
126 DECODE_FINISH(bl);
127 }
128
129 void 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);
135 f->dump_unsigned("rsnaps", rsnaps);
136 f->dump_stream("rctime") << rctime;
137 }
138
139 void 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
149 void nest_info_t::generate_test_instances(std::list<nest_info_t*>& ls)
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;
157 ls.back()->rsnaps = 6;
158 ls.back()->rctime = utime_t(7, 8);
159 }
160
161 ostream& 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;
170 if (n.rsnaps)
171 out << " rs" << n.rsnaps;
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 */
181 void 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
187 void 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
193 void quota_info_t::generate_test_instances(std::list<quota_info_t *>& ls)
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
201 ostream& 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
214 void client_writeable_range_t::encode(bufferlist &bl) const
215 {
216 ENCODE_START(2, 2, bl);
217 encode(range.first, bl);
218 encode(range.last, bl);
219 encode(follows, bl);
220 ENCODE_FINISH(bl);
221 }
222
223 void client_writeable_range_t::decode(bufferlist::const_iterator& bl)
224 {
225 DECODE_START_LEGACY_COMPAT_LEN(2, 2, 2, bl);
226 decode(range.first, bl);
227 decode(range.last, bl);
228 decode(follows, bl);
229 DECODE_FINISH(bl);
230 }
231
232 void 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
241 void 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
247 void client_writeable_range_t::generate_test_instances(std::list<client_writeable_range_t*>& ls)
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
256 ostream& 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 */
264 void inline_data_t::encode(bufferlist &bl) const
265 {
266 using ceph::encode;
267 encode(version, bl);
268 if (blp)
269 encode(*blp, bl);
270 else
271 encode(bufferlist(), bl);
272 }
273 void inline_data_t::decode(bufferlist::const_iterator &p)
274 {
275 using ceph::decode;
276 decode(version, p);
277 uint32_t inline_len;
278 decode(inline_len, p);
279 if (inline_len > 0) {
280 ceph::buffer::list bl;
281 decode_nohead(inline_len, bl, p);
282 set_data(bl);
283 } else
284 free_data();
285 }
286
287
288 /*
289 * fnode_t
290 */
291 void fnode_t::encode(bufferlist &bl) const
292 {
293 ENCODE_START(4, 3, bl);
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);
305 ENCODE_FINISH(bl);
306 }
307
308 void fnode_t::decode(bufferlist::const_iterator &bl)
309 {
310 DECODE_START_LEGACY_COMPAT_LEN(3, 2, 2, bl);
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);
317 if (struct_v >= 3) {
318 decode(damage_flags, bl);
319 }
320 if (struct_v >= 4) {
321 decode(recursive_scrub_version, bl);
322 decode(recursive_scrub_stamp, bl);
323 decode(localized_scrub_version, bl);
324 decode(localized_scrub_stamp, bl);
325 }
326 DECODE_FINISH(bl);
327 }
328
329 void 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 }
350 void 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 }
360 void fnode_t::generate_test_instances(std::list<fnode_t*>& ls)
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 */
380 void old_rstat_t::encode(bufferlist& bl) const
381 {
382 ENCODE_START(2, 2, bl);
383 encode(first, bl);
384 encode(rstat, bl);
385 encode(accounted_rstat, bl);
386 ENCODE_FINISH(bl);
387 }
388
389 void old_rstat_t::decode(bufferlist::const_iterator& bl)
390 {
391 DECODE_START_LEGACY_COMPAT_LEN(2, 2, 2, bl);
392 decode(first, bl);
393 decode(rstat, bl);
394 decode(accounted_rstat, bl);
395 DECODE_FINISH(bl);
396 }
397
398 void 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
409 void old_rstat_t::generate_test_instances(std::list<old_rstat_t*>& ls)
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
420 /*
421 * feature_bitset_t
422 */
423 feature_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
432 feature_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
451 feature_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
461 void 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
469 void 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
486 void feature_bitset_t::dump(Formatter *f) const {
487 CachedStackStringStream css;
488 print(*css);
489 f->dump_string("feature_bits", css->strv());
490 }
491
492 void feature_bitset_t::print(ostream& out) const
493 {
494 std::ios_base::fmtflags f(out.flags());
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 }
504 out.flags(f);
505 }
506
507 /*
508 * metric_spec_t
509 */
510 void 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
517 void 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
524 void metric_spec_t::dump(Formatter *f) const {
525 f->dump_object("metric_flags", metric_flags);
526 }
527
528 void metric_spec_t::print(ostream& out) const
529 {
530 out << "{metric_flags: '" << metric_flags << "'}";
531 }
532
533 /*
534 * client_metadata_t
535 */
536 void client_metadata_t::encode(bufferlist& bl) const
537 {
538 ENCODE_START(3, 1, bl);
539 encode(kv_map, bl);
540 encode(features, bl);
541 encode(metric_spec, bl);
542 ENCODE_FINISH(bl);
543 }
544
545 void client_metadata_t::decode(bufferlist::const_iterator& p)
546 {
547 DECODE_START(3, p);
548 decode(kv_map, p);
549 if (struct_v >= 2)
550 decode(features, p);
551 if (struct_v >= 3) {
552 decode(metric_spec, p);
553 }
554 DECODE_FINISH(p);
555 }
556
557 void client_metadata_t::dump(Formatter *f) const
558 {
559 f->dump_object("client_features", features);
560 f->dump_object("metric_spec", metric_spec);
561 for (const auto& [name, val] : kv_map)
562 f->dump_string(name.c_str(), val);
563 }
564
565 /*
566 * session_info_t
567 */
568 void session_info_t::encode(bufferlist& bl, uint64_t features) const
569 {
570 ENCODE_START(7, 7, bl);
571 encode(inst, bl, features);
572 encode(completed_requests, bl);
573 encode(prealloc_inos, bl); // hacky, see below.
574 encode((__u32)0, bl); // used_inos
575 encode(completed_flushes, bl);
576 encode(auth_name, bl);
577 encode(client_metadata, bl);
578 ENCODE_FINISH(bl);
579 }
580
581 void session_info_t::decode(bufferlist::const_iterator& p)
582 {
583 DECODE_START_LEGACY_COMPAT_LEN(7, 2, 2, p);
584 decode(inst, p);
585 if (struct_v <= 2) {
586 set<ceph_tid_t> s;
587 decode(s, p);
588 while (!s.empty()) {
589 completed_requests[*s.begin()] = inodeno_t();
590 s.erase(s.begin());
591 }
592 } else {
593 decode(completed_requests, p);
594 }
595 decode(prealloc_inos, p);
596 {
597 interval_set<inodeno_t> used_inos;
598 decode(used_inos, p);
599 prealloc_inos.insert(used_inos);
600 }
601 if (struct_v >= 4 && struct_v < 7) {
602 decode(client_metadata.kv_map, p);
603 }
604 if (struct_v >= 5) {
605 decode(completed_flushes, p);
606 }
607 if (struct_v >= 6) {
608 decode(auth_name, p);
609 }
610 if (struct_v >= 7) {
611 decode(client_metadata, p);
612 }
613 DECODE_FINISH(p);
614 }
615
616 void session_info_t::dump(Formatter *f) const
617 {
618 f->dump_stream("inst") << inst;
619
620 f->open_array_section("completed_requests");
621 for (const auto& [tid, ino] : completed_requests) {
622 f->open_object_section("request");
623 f->dump_unsigned("tid", tid);
624 f->dump_stream("created_ino") << ino;
625 f->close_section();
626 }
627 f->close_section();
628
629 f->open_array_section("prealloc_inos");
630 for (const auto& [start, len] : prealloc_inos) {
631 f->open_object_section("ino_range");
632 f->dump_stream("start") << start;
633 f->dump_unsigned("length", len);
634 f->close_section();
635 }
636 f->close_section();
637
638 f->dump_object("client_metadata", client_metadata);
639 }
640
641 void session_info_t::generate_test_instances(std::list<session_info_t*>& ls)
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 */
657 void string_snap_t::encode(bufferlist& bl) const
658 {
659 ENCODE_START(2, 2, bl);
660 encode(name, bl);
661 encode(snapid, bl);
662 ENCODE_FINISH(bl);
663 }
664
665 void string_snap_t::decode(bufferlist::const_iterator& bl)
666 {
667 DECODE_START_LEGACY_COMPAT_LEN(2, 2, 2, bl);
668 decode(name, bl);
669 decode(snapid, bl);
670 DECODE_FINISH(bl);
671 }
672
673 void string_snap_t::dump(Formatter *f) const
674 {
675 f->dump_string("name", name);
676 f->dump_unsigned("snapid", snapid);
677 }
678
679 void string_snap_t::generate_test_instances(std::list<string_snap_t*>& ls)
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 */
694 void MDSCacheObjectInfo::encode(bufferlist& bl) const
695 {
696 ENCODE_START(2, 2, bl);
697 encode(ino, bl);
698 encode(dirfrag, bl);
699 encode(dname, bl);
700 encode(snapid, bl);
701 ENCODE_FINISH(bl);
702 }
703
704 void MDSCacheObjectInfo::decode(bufferlist::const_iterator& p)
705 {
706 DECODE_START_LEGACY_COMPAT_LEN(2, 2, 2, p);
707 decode(ino, p);
708 decode(dirfrag, p);
709 decode(dname, p);
710 decode(snapid, p);
711 DECODE_FINISH(p);
712 }
713
714 void 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
722 void MDSCacheObjectInfo::generate_test_instances(std::list<MDSCacheObjectInfo*>& ls)
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 */
740 void mds_table_pending_t::encode(bufferlist& bl) const
741 {
742 ENCODE_START(2, 2, bl);
743 encode(reqid, bl);
744 encode(mds, bl);
745 encode(tid, bl);
746 ENCODE_FINISH(bl);
747 }
748
749 void mds_table_pending_t::decode(bufferlist::const_iterator& bl)
750 {
751 DECODE_START_LEGACY_COMPAT_LEN(2, 2, 2, bl);
752 decode(reqid, bl);
753 decode(mds, bl);
754 decode(tid, bl);
755 DECODE_FINISH(bl);
756 }
757
758 void 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
765 void mds_table_pending_t::generate_test_instances(std::list<mds_table_pending_t*>& ls)
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
774 void metareqid_t::dump(ceph::Formatter* f) const {
775 f->dump_object("entity", name);
776 f->dump_unsigned("tid", tid);
777 }
778
779 /*
780 * inode_load_vec_t
781 */
782 void inode_load_vec_t::encode(bufferlist &bl) const
783 {
784 ENCODE_START(2, 2, bl);
785 for (const auto &i : vec) {
786 encode(i, bl);
787 }
788 ENCODE_FINISH(bl);
789 }
790
791 void inode_load_vec_t::decode(bufferlist::const_iterator &p)
792 {
793 DECODE_START_LEGACY_COMPAT_LEN(2, 2, 2, p);
794 for (auto &i : vec) {
795 decode(i, p);
796 }
797 DECODE_FINISH(p);
798 }
799
800 void inode_load_vec_t::dump(Formatter *f) const
801 {
802 f->open_array_section("Decay Counters");
803 for (const auto &i : vec) {
804 f->open_object_section("Decay Counter");
805 i.dump(f);
806 f->close_section();
807 }
808 f->close_section();
809 }
810
811 void inode_load_vec_t::generate_test_instances(std::list<inode_load_vec_t*>& ls)
812 {
813 ls.push_back(new inode_load_vec_t(DecayRate()));
814 }
815
816
817 /*
818 * dirfrag_load_vec_t
819 */
820 void dirfrag_load_vec_t::dump(Formatter *f) const
821 {
822 f->open_array_section("Decay Counters");
823 for (const auto &i : vec) {
824 f->open_object_section("Decay Counter");
825 i.dump(f);
826 f->close_section();
827 }
828 f->close_section();
829 }
830
831 void dirfrag_load_vec_t::dump(Formatter *f, const DecayRate& rate) const
832 {
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());
839 }
840
841 void dirfrag_load_vec_t::generate_test_instances(std::list<dirfrag_load_vec_t*>& ls)
842 {
843 ls.push_back(new dirfrag_load_vec_t(DecayRate()));
844 }
845
846 /*
847 * mds_load_t
848 */
849 void mds_load_t::encode(bufferlist &bl) const {
850 ENCODE_START(2, 2, bl);
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);
857 ENCODE_FINISH(bl);
858 }
859
860 void mds_load_t::decode(bufferlist::const_iterator &bl) {
861 DECODE_START_LEGACY_COMPAT_LEN(2, 2, 2, bl);
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);
868 DECODE_FINISH(bl);
869 }
870
871 void 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
885 void mds_load_t::generate_test_instances(std::list<mds_load_t*>& ls)
886 {
887 ls.push_back(new mds_load_t(DecayRate()));
888 }
889
890 /*
891 * cap_reconnect_t
892 */
893 void cap_reconnect_t::encode(bufferlist& bl) const {
894 ENCODE_START(2, 1, bl);
895 encode_old(bl); // extract out when something changes
896 encode(snap_follows, bl);
897 ENCODE_FINISH(bl);
898 }
899
900 void cap_reconnect_t::encode_old(bufferlist& bl) const {
901 using ceph::encode;
902 encode(path, bl);
903 capinfo.flock_len = flockbl.length();
904 encode(capinfo, bl);
905 ceph::encode_nohead(flockbl, bl);
906 }
907
908 void cap_reconnect_t::decode(bufferlist::const_iterator& bl) {
909 DECODE_START(2, bl);
910 decode_old(bl); // extract out when something changes
911 if (struct_v >= 2)
912 decode(snap_follows, bl);
913 DECODE_FINISH(bl);
914 }
915
916 void cap_reconnect_t::decode_old(bufferlist::const_iterator& bl) {
917 using ceph::decode;
918 decode(path, bl);
919 decode(capinfo, bl);
920 ceph::decode_nohead(capinfo.flock_len, flockbl, bl);
921 }
922
923 void 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
934 void cap_reconnect_t::generate_test_instances(std::list<cap_reconnect_t*>& ls)
935 {
936 ls.push_back(new cap_reconnect_t);
937 ls.back()->path = "/test/path";
938 ls.back()->capinfo.cap_id = 1;
939 }
940
941 /*
942 * snaprealm_reconnect_t
943 */
944 void 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
950 void snaprealm_reconnect_t::encode_old(bufferlist& bl) const {
951 using ceph::encode;
952 encode(realm, bl);
953 }
954
955 void 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
961 void snaprealm_reconnect_t::decode_old(bufferlist::const_iterator& bl) {
962 using ceph::decode;
963 decode(realm, bl);
964 }
965
966 void 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
973 void snaprealm_reconnect_t::generate_test_instances(std::list<snaprealm_reconnect_t*>& ls)
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 }