]>
git.proxmox.com Git - ceph.git/blob - ceph/src/mds/mdstypes.cc
a55c85590af87e0df644c307388f16c7e33bfbf0
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
5 #include "MDSContext.h"
6 #include "common/Formatter.h"
8 const mds_gid_t MDS_GID_NONE
= mds_gid_t(0);
15 void frag_info_t::encode(bufferlist
&bl
) const
17 ENCODE_START(3, 2, bl
);
22 encode(change_attr
, bl
);
26 void frag_info_t::decode(bufferlist::const_iterator
&bl
)
28 DECODE_START_LEGACY_COMPAT_LEN(3, 2, 2, bl
);
34 decode(change_attr
, bl
);
40 void frag_info_t::dump(Formatter
*f
) const
42 f
->dump_unsigned("version", version
);
43 f
->dump_stream("mtime") << mtime
;
44 f
->dump_unsigned("num_files", nfiles
);
45 f
->dump_unsigned("num_subdirs", nsubdirs
);
48 void frag_info_t::generate_test_instances(list
<frag_info_t
*>& ls
)
50 ls
.push_back(new frag_info_t
);
51 ls
.push_back(new frag_info_t
);
52 ls
.back()->version
= 1;
53 ls
.back()->mtime
= utime_t(2, 3);
54 ls
.back()->nfiles
= 4;
55 ls
.back()->nsubdirs
= 5;
58 ostream
& operator<<(ostream
&out
, const frag_info_t
&f
)
60 if (f
== frag_info_t())
62 out
<< "f(v" << f
.version
;
63 if (f
.mtime
!= utime_t())
64 out
<< " m" << f
.mtime
;
65 if (f
.nfiles
|| f
.nsubdirs
)
66 out
<< " " << f
.size() << "=" << f
.nfiles
<< "+" << f
.nsubdirs
;
76 void nest_info_t::encode(bufferlist
&bl
) const
78 ENCODE_START(3, 2, bl
);
93 void nest_info_t::decode(bufferlist::const_iterator
&bl
)
95 DECODE_START_LEGACY_COMPAT_LEN(3, 2, 2, bl
);
102 decode(ranchors
, bl
);
109 void nest_info_t::dump(Formatter
*f
) const
111 f
->dump_unsigned("version", version
);
112 f
->dump_unsigned("rbytes", rbytes
);
113 f
->dump_unsigned("rfiles", rfiles
);
114 f
->dump_unsigned("rsubdirs", rsubdirs
);
115 f
->dump_unsigned("rsnaps", rsnaps
);
116 f
->dump_stream("rctime") << rctime
;
119 void nest_info_t::generate_test_instances(list
<nest_info_t
*>& ls
)
121 ls
.push_back(new nest_info_t
);
122 ls
.push_back(new nest_info_t
);
123 ls
.back()->version
= 1;
124 ls
.back()->rbytes
= 2;
125 ls
.back()->rfiles
= 3;
126 ls
.back()->rsubdirs
= 4;
127 ls
.back()->rsnaps
= 6;
128 ls
.back()->rctime
= utime_t(7, 8);
131 ostream
& operator<<(ostream
&out
, const nest_info_t
&n
)
133 if (n
== nest_info_t())
135 out
<< "n(v" << n
.version
;
136 if (n
.rctime
!= utime_t())
137 out
<< " rc" << n
.rctime
;
139 out
<< " b" << n
.rbytes
;
141 out
<< " rs" << n
.rsnaps
;
142 if (n
.rfiles
|| n
.rsubdirs
)
143 out
<< " " << n
.rsize() << "=" << n
.rfiles
<< "+" << n
.rsubdirs
;
151 void quota_info_t::dump(Formatter
*f
) const
153 f
->dump_int("max_bytes", max_bytes
);
154 f
->dump_int("max_files", max_files
);
157 void quota_info_t::generate_test_instances(list
<quota_info_t
*>& ls
)
159 ls
.push_back(new quota_info_t
);
160 ls
.push_back(new quota_info_t
);
161 ls
.back()->max_bytes
= 16;
162 ls
.back()->max_files
= 16;
165 ostream
& operator<<(ostream
&out
, const quota_info_t
&n
)
168 << "max_bytes = " << n
.max_bytes
169 << " max_files = " << n
.max_files
175 * client_writeable_range_t
178 void client_writeable_range_t::encode(bufferlist
&bl
) const
180 ENCODE_START(2, 2, bl
);
181 encode(range
.first
, bl
);
182 encode(range
.last
, bl
);
187 void client_writeable_range_t::decode(bufferlist::const_iterator
& bl
)
189 DECODE_START_LEGACY_COMPAT_LEN(2, 2, 2, bl
);
190 decode(range
.first
, bl
);
191 decode(range
.last
, bl
);
196 void client_writeable_range_t::dump(Formatter
*f
) const
198 f
->open_object_section("byte range");
199 f
->dump_unsigned("first", range
.first
);
200 f
->dump_unsigned("last", range
.last
);
202 f
->dump_unsigned("follows", follows
);
205 void client_writeable_range_t::generate_test_instances(list
<client_writeable_range_t
*>& ls
)
207 ls
.push_back(new client_writeable_range_t
);
208 ls
.push_back(new client_writeable_range_t
);
209 ls
.back()->range
.first
= 123;
210 ls
.back()->range
.last
= 456;
211 ls
.back()->follows
= 12;
214 ostream
& operator<<(ostream
& out
, const client_writeable_range_t
& r
)
216 return out
<< r
.range
.first
<< '-' << r
.range
.last
<< "@" << r
.follows
;
222 void inline_data_t::encode(bufferlist
&bl
) const
229 encode(bufferlist(), bl
);
231 void inline_data_t::decode(bufferlist::const_iterator
&p
)
236 decode(inline_len
, p
);
238 decode_nohead(inline_len
, get_data(), p
);
247 void fnode_t::encode(bufferlist
&bl
) const
249 ENCODE_START(4, 3, bl
);
251 encode(snap_purged_thru
, bl
);
252 encode(fragstat
, bl
);
253 encode(accounted_fragstat
, bl
);
255 encode(accounted_rstat
, bl
);
256 encode(damage_flags
, bl
);
257 encode(recursive_scrub_version
, bl
);
258 encode(recursive_scrub_stamp
, bl
);
259 encode(localized_scrub_version
, bl
);
260 encode(localized_scrub_stamp
, bl
);
264 void fnode_t::decode(bufferlist::const_iterator
&bl
)
266 DECODE_START_LEGACY_COMPAT_LEN(3, 2, 2, bl
);
268 decode(snap_purged_thru
, bl
);
269 decode(fragstat
, bl
);
270 decode(accounted_fragstat
, bl
);
272 decode(accounted_rstat
, bl
);
274 decode(damage_flags
, bl
);
277 decode(recursive_scrub_version
, bl
);
278 decode(recursive_scrub_stamp
, bl
);
279 decode(localized_scrub_version
, bl
);
280 decode(localized_scrub_stamp
, bl
);
285 void fnode_t::dump(Formatter
*f
) const
287 f
->dump_unsigned("version", version
);
288 f
->dump_unsigned("snap_purged_thru", snap_purged_thru
);
290 f
->open_object_section("fragstat");
294 f
->open_object_section("accounted_fragstat");
295 accounted_fragstat
.dump(f
);
298 f
->open_object_section("rstat");
302 f
->open_object_section("accounted_rstat");
303 accounted_rstat
.dump(f
);
307 void fnode_t::generate_test_instances(list
<fnode_t
*>& ls
)
309 ls
.push_back(new fnode_t
);
310 ls
.push_back(new fnode_t
);
311 ls
.back()->version
= 1;
312 ls
.back()->snap_purged_thru
= 2;
313 list
<frag_info_t
*> fls
;
314 frag_info_t::generate_test_instances(fls
);
315 ls
.back()->fragstat
= *fls
.back();
316 ls
.back()->accounted_fragstat
= *fls
.front();
317 list
<nest_info_t
*> nls
;
318 nest_info_t::generate_test_instances(nls
);
319 ls
.back()->rstat
= *nls
.front();
320 ls
.back()->accounted_rstat
= *nls
.back();
327 void old_rstat_t::encode(bufferlist
& bl
) const
329 ENCODE_START(2, 2, bl
);
332 encode(accounted_rstat
, bl
);
336 void old_rstat_t::decode(bufferlist::const_iterator
& bl
)
338 DECODE_START_LEGACY_COMPAT_LEN(2, 2, 2, bl
);
341 decode(accounted_rstat
, bl
);
345 void old_rstat_t::dump(Formatter
*f
) const
347 f
->dump_unsigned("snapid", first
);
348 f
->open_object_section("rstat");
351 f
->open_object_section("accounted_rstat");
352 accounted_rstat
.dump(f
);
356 void old_rstat_t::generate_test_instances(list
<old_rstat_t
*>& ls
)
358 ls
.push_back(new old_rstat_t());
359 ls
.push_back(new old_rstat_t());
360 ls
.back()->first
= 12;
361 list
<nest_info_t
*> nls
;
362 nest_info_t::generate_test_instances(nls
);
363 ls
.back()->rstat
= *nls
.back();
364 ls
.back()->accounted_rstat
= *nls
.front();
370 feature_bitset_t::feature_bitset_t(unsigned long value
)
373 for (size_t i
= 0; i
< sizeof(value
) * 8; i
+= bits_per_block
) {
374 _vec
.push_back((block_type
)(value
>> i
));
379 feature_bitset_t::feature_bitset_t(const vector
<size_t>& array
)
381 if (!array
.empty()) {
382 size_t n
= array
.back();
388 for (auto& bit
: array
) {
392 ceph_assert(bit
== last
);
393 _vec
[bit
/ bits_per_block
] |= (block_type
)1 << (bit
% bits_per_block
);
398 feature_bitset_t
& feature_bitset_t::operator-=(const feature_bitset_t
& other
)
400 for (size_t i
= 0; i
< _vec
.size(); ++i
) {
401 if (i
>= other
._vec
.size())
403 _vec
[i
] &= ~other
._vec
[i
];
408 void feature_bitset_t::encode(bufferlist
& bl
) const {
410 using ceph::encode_nohead
;
411 uint32_t len
= _vec
.size() * sizeof(block_type
);
413 encode_nohead(_vec
, bl
);
416 void feature_bitset_t::decode(bufferlist::const_iterator
&p
) {
418 using ceph::decode_nohead
;
423 if (len
>= sizeof(block_type
))
424 decode_nohead(len
/ sizeof(block_type
), _vec
, p
);
426 if (len
% sizeof(block_type
)) {
428 p
.copy(len
% sizeof(block_type
), (char*)&buf
);
429 _vec
.push_back((block_type
)buf
);
433 void feature_bitset_t::print(ostream
& out
) const
435 std::ios_base::fmtflags
f(out
.flags());
437 for (int i
= _vec
.size() - 1; i
>= 0; --i
)
438 out
<< std::setfill('0') << std::setw(sizeof(block_type
) * 2)
439 << std::hex
<< _vec
[i
];
446 void client_metadata_t::encode(bufferlist
& bl
) const
448 ENCODE_START(2, 1, bl
);
450 encode(features
, bl
);
454 void client_metadata_t::decode(bufferlist::const_iterator
& p
)
463 void client_metadata_t::dump(Formatter
*f
) const
465 f
->dump_stream("features") << features
;
466 for (const auto& [name
, val
] : kv_map
)
467 f
->dump_string(name
.c_str(), val
);
473 void session_info_t::encode(bufferlist
& bl
, uint64_t features
) const
475 ENCODE_START(7, 7, bl
);
476 encode(inst
, bl
, features
);
477 encode(completed_requests
, bl
);
478 encode(prealloc_inos
, bl
); // hacky, see below.
479 encode(used_inos
, bl
);
480 encode(completed_flushes
, bl
);
481 encode(auth_name
, bl
);
482 encode(client_metadata
, bl
);
486 void session_info_t::decode(bufferlist::const_iterator
& p
)
488 DECODE_START_LEGACY_COMPAT_LEN(7, 2, 2, p
);
494 completed_requests
[*s
.begin()] = inodeno_t();
498 decode(completed_requests
, p
);
500 decode(prealloc_inos
, p
);
501 decode(used_inos
, p
);
502 prealloc_inos
.insert(used_inos
);
504 if (struct_v
>= 4 && struct_v
< 7) {
505 decode(client_metadata
.kv_map
, p
);
508 decode(completed_flushes
, p
);
511 decode(auth_name
, p
);
514 decode(client_metadata
, p
);
519 void session_info_t::dump(Formatter
*f
) const
521 f
->dump_stream("inst") << inst
;
523 f
->open_array_section("completed_requests");
524 for (const auto& [tid
, ino
] : completed_requests
) {
525 f
->open_object_section("request");
526 f
->dump_unsigned("tid", tid
);
527 f
->dump_stream("created_ino") << ino
;
532 f
->open_array_section("prealloc_inos");
533 for (const auto& [start
, len
] : prealloc_inos
) {
534 f
->open_object_section("ino_range");
535 f
->dump_unsigned("start", start
);
536 f
->dump_unsigned("length", len
);
541 f
->open_array_section("used_inos");
542 for (const auto& [start
, len
] : used_inos
) {
543 f
->open_object_section("ino_range");
544 f
->dump_unsigned("start", start
);
545 f
->dump_unsigned("length", len
);
550 f
->dump_object("client_metadata", client_metadata
);
553 void session_info_t::generate_test_instances(list
<session_info_t
*>& ls
)
555 ls
.push_back(new session_info_t
);
556 ls
.push_back(new session_info_t
);
557 ls
.back()->inst
= entity_inst_t(entity_name_t::MDS(12), entity_addr_t());
558 ls
.back()->completed_requests
.insert(make_pair(234, inodeno_t(111222)));
559 ls
.back()->completed_requests
.insert(make_pair(237, inodeno_t(222333)));
560 ls
.back()->prealloc_inos
.insert(333, 12);
561 ls
.back()->prealloc_inos
.insert(377, 112);
562 // we can't add used inos; they're cleared on decode
569 void string_snap_t::encode(bufferlist
& bl
) const
571 ENCODE_START(2, 2, bl
);
577 void string_snap_t::decode(bufferlist::const_iterator
& bl
)
579 DECODE_START_LEGACY_COMPAT_LEN(2, 2, 2, bl
);
585 void string_snap_t::dump(Formatter
*f
) const
587 f
->dump_string("name", name
);
588 f
->dump_unsigned("snapid", snapid
);
591 void string_snap_t::generate_test_instances(list
<string_snap_t
*>& ls
)
593 ls
.push_back(new string_snap_t
);
594 ls
.push_back(new string_snap_t
);
595 ls
.back()->name
= "foo";
596 ls
.back()->snapid
= 123;
597 ls
.push_back(new string_snap_t
);
598 ls
.back()->name
= "bar";
599 ls
.back()->snapid
= 456;
606 void MDSCacheObjectInfo::encode(bufferlist
& bl
) const
608 ENCODE_START(2, 2, bl
);
616 void MDSCacheObjectInfo::decode(bufferlist::const_iterator
& p
)
618 DECODE_START_LEGACY_COMPAT_LEN(2, 2, 2, p
);
626 void MDSCacheObjectInfo::dump(Formatter
*f
) const
628 f
->dump_unsigned("ino", ino
);
629 f
->dump_stream("dirfrag") << dirfrag
;
630 f
->dump_string("name", dname
);
631 f
->dump_unsigned("snapid", snapid
);
634 void MDSCacheObjectInfo::generate_test_instances(list
<MDSCacheObjectInfo
*>& ls
)
636 ls
.push_back(new MDSCacheObjectInfo
);
637 ls
.push_back(new MDSCacheObjectInfo
);
639 ls
.back()->dirfrag
= dirfrag_t(2, 3);
640 ls
.back()->dname
= "fooname";
641 ls
.back()->snapid
= CEPH_NOSNAP
;
642 ls
.push_back(new MDSCacheObjectInfo
);
643 ls
.back()->ino
= 121;
644 ls
.back()->dirfrag
= dirfrag_t(222, 0);
645 ls
.back()->dname
= "bar foo";
646 ls
.back()->snapid
= 21322;
650 * mds_table_pending_t
652 void mds_table_pending_t::encode(bufferlist
& bl
) const
654 ENCODE_START(2, 2, bl
);
661 void mds_table_pending_t::decode(bufferlist::const_iterator
& bl
)
663 DECODE_START_LEGACY_COMPAT_LEN(2, 2, 2, bl
);
670 void mds_table_pending_t::dump(Formatter
*f
) const
672 f
->dump_unsigned("reqid", reqid
);
673 f
->dump_unsigned("mds", mds
);
674 f
->dump_unsigned("tid", tid
);
677 void mds_table_pending_t::generate_test_instances(list
<mds_table_pending_t
*>& ls
)
679 ls
.push_back(new mds_table_pending_t
);
680 ls
.push_back(new mds_table_pending_t
);
681 ls
.back()->reqid
= 234;
683 ls
.back()->tid
= 35434;
690 void inode_load_vec_t::encode(bufferlist
&bl
) const
692 ENCODE_START(2, 2, bl
);
693 for (const auto &i
: vec
) {
699 void inode_load_vec_t::decode(bufferlist::const_iterator
&p
)
701 DECODE_START_LEGACY_COMPAT_LEN(2, 2, 2, p
);
702 for (auto &i
: vec
) {
708 void inode_load_vec_t::dump(Formatter
*f
) const
710 f
->open_array_section("Decay Counters");
711 for (const auto &i
: vec
) {
712 f
->open_object_section("Decay Counter");
719 void inode_load_vec_t::generate_test_instances(list
<inode_load_vec_t
*>& ls
)
721 ls
.push_back(new inode_load_vec_t(DecayRate()));
728 void dirfrag_load_vec_t::dump(Formatter
*f
) const
730 f
->open_array_section("Decay Counters");
731 for (const auto &i
: vec
) {
732 f
->open_object_section("Decay Counter");
739 void dirfrag_load_vec_t::dump(Formatter
*f
, const DecayRate
& rate
) const
741 f
->dump_float("meta_load", meta_load());
742 f
->dump_float("IRD", get(META_POP_IRD
).get());
743 f
->dump_float("IWR", get(META_POP_IWR
).get());
744 f
->dump_float("READDIR", get(META_POP_READDIR
).get());
745 f
->dump_float("FETCH", get(META_POP_FETCH
).get());
746 f
->dump_float("STORE", get(META_POP_STORE
).get());
749 void dirfrag_load_vec_t::generate_test_instances(std::list
<dirfrag_load_vec_t
*>& ls
)
751 ls
.push_back(new dirfrag_load_vec_t(DecayRate()));
757 void mds_load_t::encode(bufferlist
&bl
) const {
758 ENCODE_START(2, 2, bl
);
761 encode(req_rate
, bl
);
762 encode(cache_hit_rate
, bl
);
763 encode(queue_len
, bl
);
764 encode(cpu_load_avg
, bl
);
768 void mds_load_t::decode(bufferlist::const_iterator
&bl
) {
769 DECODE_START_LEGACY_COMPAT_LEN(2, 2, 2, bl
);
772 decode(req_rate
, bl
);
773 decode(cache_hit_rate
, bl
);
774 decode(queue_len
, bl
);
775 decode(cpu_load_avg
, bl
);
779 void mds_load_t::dump(Formatter
*f
) const
781 f
->dump_float("request rate", req_rate
);
782 f
->dump_float("cache hit rate", cache_hit_rate
);
783 f
->dump_float("queue length", queue_len
);
784 f
->dump_float("cpu load", cpu_load_avg
);
785 f
->open_object_section("auth dirfrag");
788 f
->open_object_section("all dirfrags");
793 void mds_load_t::generate_test_instances(std::list
<mds_load_t
*>& ls
)
795 ls
.push_back(new mds_load_t(DecayRate()));
801 void cap_reconnect_t::encode(bufferlist
& bl
) const {
802 ENCODE_START(2, 1, bl
);
803 encode_old(bl
); // extract out when something changes
804 encode(snap_follows
, bl
);
808 void cap_reconnect_t::encode_old(bufferlist
& bl
) const {
811 capinfo
.flock_len
= flockbl
.length();
813 encode_nohead(flockbl
, bl
);
816 void cap_reconnect_t::decode(bufferlist::const_iterator
& bl
) {
818 decode_old(bl
); // extract out when something changes
820 decode(snap_follows
, bl
);
824 void cap_reconnect_t::decode_old(bufferlist::const_iterator
& bl
) {
828 decode_nohead(capinfo
.flock_len
, flockbl
, bl
);
831 void cap_reconnect_t::dump(Formatter
*f
) const
833 f
->dump_string("path", path
);
834 f
->dump_int("cap_id", capinfo
.cap_id
);
835 f
->dump_string("cap wanted", ccap_string(capinfo
.wanted
));
836 f
->dump_string("cap issued", ccap_string(capinfo
.issued
));
837 f
->dump_int("snaprealm", capinfo
.snaprealm
);
838 f
->dump_int("path base ino", capinfo
.pathbase
);
839 f
->dump_string("has file locks", capinfo
.flock_len
? "true" : "false");
842 void cap_reconnect_t::generate_test_instances(list
<cap_reconnect_t
*>& ls
)
844 ls
.push_back(new cap_reconnect_t
);
845 ls
.back()->path
= "/test/path";
846 ls
.back()->capinfo
.cap_id
= 1;
850 * snaprealm_reconnect_t
852 void snaprealm_reconnect_t::encode(bufferlist
& bl
) const {
853 ENCODE_START(1, 1, bl
);
854 encode_old(bl
); // extract out when something changes
858 void snaprealm_reconnect_t::encode_old(bufferlist
& bl
) const {
863 void snaprealm_reconnect_t::decode(bufferlist::const_iterator
& bl
) {
865 decode_old(bl
); // extract out when something changes
869 void snaprealm_reconnect_t::decode_old(bufferlist::const_iterator
& bl
) {
874 void snaprealm_reconnect_t::dump(Formatter
*f
) const
876 f
->dump_int("ino", realm
.ino
);
877 f
->dump_int("seq", realm
.seq
);
878 f
->dump_int("parent", realm
.parent
);
881 void snaprealm_reconnect_t::generate_test_instances(list
<snaprealm_reconnect_t
*>& ls
)
883 ls
.push_back(new snaprealm_reconnect_t
);
884 ls
.back()->realm
.ino
= 0x10000000001ULL
;
885 ls
.back()->realm
.seq
= 2;
886 ls
.back()->realm
.parent
= 1;
890 ostream
& operator<<(ostream
&out
, const mds_role_t
&role
)
892 out
<< role
.fscid
<< ":" << role
.rank
;