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