]> git.proxmox.com Git - ceph.git/blob - ceph/src/osd/OSDMap.cc
57035c4c8ea8e704597a7afeb75a905b562e5e6c
[ceph.git] / ceph / src / osd / OSDMap.cc
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
3 /*
4 * Ceph - scalable distributed file system
5 *
6 * Copyright (C) 2004-2006 Sage Weil <sage@newdream.net>
7 * Copyright (C) 2013,2014 Cloudwatt <libre.licensing@cloudwatt.com>
8 *
9 * Author: Loic Dachary <loic@dachary.org>
10 *
11 * This is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU Lesser General Public
13 * License version 2.1, as published by the Free Software
14 * Foundation. See file COPYING.
15 *
16 */
17
18 #include <boost/algorithm/string.hpp>
19
20 #include "OSDMap.h"
21 #include <algorithm>
22 #include "common/config.h"
23 #include "common/Formatter.h"
24 #include "common/TextTable.h"
25 #include "include/ceph_features.h"
26 #include "include/str_map.h"
27
28 #include "common/code_environment.h"
29 #include "mon/health_check.h"
30
31 #include "crush/CrushTreeDumper.h"
32 #include "common/Clock.h"
33 #include "mon/PGStatService.h"
34
35 #define dout_subsys ceph_subsys_osd
36
37 MEMPOOL_DEFINE_OBJECT_FACTORY(OSDMap, osdmap, osdmap);
38 MEMPOOL_DEFINE_OBJECT_FACTORY(OSDMap::Incremental, osdmap_inc, osdmap);
39
40
41 // ----------------------------------
42 // osd_info_t
43
44 void osd_info_t::dump(Formatter *f) const
45 {
46 f->dump_int("last_clean_begin", last_clean_begin);
47 f->dump_int("last_clean_end", last_clean_end);
48 f->dump_int("up_from", up_from);
49 f->dump_int("up_thru", up_thru);
50 f->dump_int("down_at", down_at);
51 f->dump_int("lost_at", lost_at);
52 }
53
54 void osd_info_t::encode(bufferlist& bl) const
55 {
56 __u8 struct_v = 1;
57 ::encode(struct_v, bl);
58 ::encode(last_clean_begin, bl);
59 ::encode(last_clean_end, bl);
60 ::encode(up_from, bl);
61 ::encode(up_thru, bl);
62 ::encode(down_at, bl);
63 ::encode(lost_at, bl);
64 }
65
66 void osd_info_t::decode(bufferlist::iterator& bl)
67 {
68 __u8 struct_v;
69 ::decode(struct_v, bl);
70 ::decode(last_clean_begin, bl);
71 ::decode(last_clean_end, bl);
72 ::decode(up_from, bl);
73 ::decode(up_thru, bl);
74 ::decode(down_at, bl);
75 ::decode(lost_at, bl);
76 }
77
78 void osd_info_t::generate_test_instances(list<osd_info_t*>& o)
79 {
80 o.push_back(new osd_info_t);
81 o.push_back(new osd_info_t);
82 o.back()->last_clean_begin = 1;
83 o.back()->last_clean_end = 2;
84 o.back()->up_from = 30;
85 o.back()->up_thru = 40;
86 o.back()->down_at = 5;
87 o.back()->lost_at = 6;
88 }
89
90 ostream& operator<<(ostream& out, const osd_info_t& info)
91 {
92 out << "up_from " << info.up_from
93 << " up_thru " << info.up_thru
94 << " down_at " << info.down_at
95 << " last_clean_interval [" << info.last_clean_begin << "," << info.last_clean_end << ")";
96 if (info.lost_at)
97 out << " lost_at " << info.lost_at;
98 return out;
99 }
100
101 // ----------------------------------
102 // osd_xinfo_t
103
104 void osd_xinfo_t::dump(Formatter *f) const
105 {
106 f->dump_stream("down_stamp") << down_stamp;
107 f->dump_float("laggy_probability", laggy_probability);
108 f->dump_int("laggy_interval", laggy_interval);
109 f->dump_int("features", features);
110 f->dump_unsigned("old_weight", old_weight);
111 }
112
113 void osd_xinfo_t::encode(bufferlist& bl) const
114 {
115 ENCODE_START(3, 1, bl);
116 ::encode(down_stamp, bl);
117 __u32 lp = laggy_probability * 0xfffffffful;
118 ::encode(lp, bl);
119 ::encode(laggy_interval, bl);
120 ::encode(features, bl);
121 ::encode(old_weight, bl);
122 ENCODE_FINISH(bl);
123 }
124
125 void osd_xinfo_t::decode(bufferlist::iterator& bl)
126 {
127 DECODE_START(3, bl);
128 ::decode(down_stamp, bl);
129 __u32 lp;
130 ::decode(lp, bl);
131 laggy_probability = (float)lp / (float)0xffffffff;
132 ::decode(laggy_interval, bl);
133 if (struct_v >= 2)
134 ::decode(features, bl);
135 else
136 features = 0;
137 if (struct_v >= 3)
138 ::decode(old_weight, bl);
139 else
140 old_weight = 0;
141 DECODE_FINISH(bl);
142 }
143
144 void osd_xinfo_t::generate_test_instances(list<osd_xinfo_t*>& o)
145 {
146 o.push_back(new osd_xinfo_t);
147 o.push_back(new osd_xinfo_t);
148 o.back()->down_stamp = utime_t(2, 3);
149 o.back()->laggy_probability = .123;
150 o.back()->laggy_interval = 123456;
151 o.back()->old_weight = 0x7fff;
152 }
153
154 ostream& operator<<(ostream& out, const osd_xinfo_t& xi)
155 {
156 return out << "down_stamp " << xi.down_stamp
157 << " laggy_probability " << xi.laggy_probability
158 << " laggy_interval " << xi.laggy_interval
159 << " old_weight " << xi.old_weight;
160 }
161
162 // ----------------------------------
163 // OSDMap::Incremental
164
165 int OSDMap::Incremental::get_net_marked_out(const OSDMap *previous) const
166 {
167 int n = 0;
168 for (auto &weight : new_weight) {
169 if (weight.second == CEPH_OSD_OUT && !previous->is_out(weight.first))
170 n++; // marked out
171 else if (weight.second != CEPH_OSD_OUT && previous->is_out(weight.first))
172 n--; // marked in
173 }
174 return n;
175 }
176
177 int OSDMap::Incremental::get_net_marked_down(const OSDMap *previous) const
178 {
179 int n = 0;
180 for (auto &state : new_state) { //
181 if (state.second & CEPH_OSD_UP) {
182 if (previous->is_up(state.first))
183 n++; // marked down
184 else
185 n--; // marked up
186 }
187 }
188 return n;
189 }
190
191 int OSDMap::Incremental::identify_osd(uuid_d u) const
192 {
193 for (auto &uuid : new_uuid)
194 if (uuid.second == u)
195 return uuid.first;
196 return -1;
197 }
198
199 int OSDMap::Incremental::propagate_snaps_to_tiers(CephContext *cct,
200 const OSDMap& osdmap)
201 {
202 assert(epoch == osdmap.get_epoch() + 1);
203
204 for (auto &new_pool : new_pools) {
205 if (!new_pool.second.tiers.empty()) {
206 pg_pool_t& base = new_pool.second;
207
208 for (const auto &tier_pool : base.tiers) {
209 const auto &r = new_pools.find(tier_pool);
210 pg_pool_t *tier = 0;
211 if (r == new_pools.end()) {
212 const pg_pool_t *orig = osdmap.get_pg_pool(tier_pool);
213 if (!orig) {
214 lderr(cct) << __func__ << " no pool " << tier_pool << dendl;
215 return -EIO;
216 }
217 tier = get_new_pool(tier_pool, orig);
218 } else {
219 tier = &r->second;
220 }
221 if (tier->tier_of != new_pool.first) {
222 lderr(cct) << __func__ << " " << r->first << " tier_of != " << new_pool.first << dendl;
223 return -EIO;
224 }
225
226 ldout(cct, 10) << __func__ << " from " << new_pool.first << " to "
227 << tier_pool << dendl;
228 tier->snap_seq = base.snap_seq;
229 tier->snap_epoch = base.snap_epoch;
230 tier->snaps = base.snaps;
231 tier->removed_snaps = base.removed_snaps;
232 }
233 }
234 }
235 return 0;
236 }
237
238
239 bool OSDMap::subtree_is_down(int id, set<int> *down_cache) const
240 {
241 if (id >= 0)
242 return is_down(id);
243
244 if (down_cache &&
245 down_cache->count(id)) {
246 return true;
247 }
248
249 list<int> children;
250 crush->get_children(id, &children);
251 for (const auto &child : children) {
252 if (!subtree_is_down(child, down_cache)) {
253 return false;
254 }
255 }
256 if (down_cache) {
257 down_cache->insert(id);
258 }
259 return true;
260 }
261
262 bool OSDMap::containing_subtree_is_down(CephContext *cct, int id, int subtree_type, set<int> *down_cache) const
263 {
264 // use a stack-local down_cache if we didn't get one from the
265 // caller. then at least this particular call will avoid duplicated
266 // work.
267 set<int> local_down_cache;
268 if (!down_cache) {
269 down_cache = &local_down_cache;
270 }
271
272 int current = id;
273 while (true) {
274 int type;
275 if (current >= 0) {
276 type = 0;
277 } else {
278 type = crush->get_bucket_type(current);
279 }
280 assert(type >= 0);
281
282 if (!subtree_is_down(current, down_cache)) {
283 ldout(cct, 30) << "containing_subtree_is_down(" << id << ") = false" << dendl;
284 return false;
285 }
286
287 // is this a big enough subtree to be marked as down?
288 if (type >= subtree_type) {
289 ldout(cct, 30) << "containing_subtree_is_down(" << id << ") = true ... " << type << " >= " << subtree_type << dendl;
290 return true;
291 }
292
293 int r = crush->get_immediate_parent_id(current, &current);
294 if (r < 0) {
295 return false;
296 }
297 }
298 }
299
300 bool OSDMap::subtree_type_is_down(
301 CephContext *cct,
302 int id,
303 int subtree_type,
304 set<int> *down_in_osds,
305 set<int> *up_in_osds,
306 set<int> *subtree_up,
307 unordered_map<int, set<int> > *subtree_type_down) const
308 {
309 if (id >= 0) {
310 bool is_down_ret = is_down(id);
311 if (!is_out(id)) {
312 if (is_down_ret) {
313 down_in_osds->insert(id);
314 } else {
315 up_in_osds->insert(id);
316 }
317 }
318 return is_down_ret;
319 }
320
321 if (subtree_type_down &&
322 (*subtree_type_down)[subtree_type].count(id)) {
323 return true;
324 }
325
326 list<int> children;
327 crush->get_children(id, &children);
328 for (const auto &child : children) {
329 if (!subtree_type_is_down(
330 cct, child, crush->get_bucket_type(child),
331 down_in_osds, up_in_osds, subtree_up, subtree_type_down)) {
332 subtree_up->insert(id);
333 return false;
334 }
335 }
336 if (subtree_type_down) {
337 (*subtree_type_down)[subtree_type].insert(id);
338 }
339 return true;
340 }
341
342 void OSDMap::Incremental::encode_client_old(bufferlist& bl) const
343 {
344 __u16 v = 5;
345 ::encode(v, bl);
346 ::encode(fsid, bl);
347 ::encode(epoch, bl);
348 ::encode(modified, bl);
349 int32_t new_t = new_pool_max;
350 ::encode(new_t, bl);
351 ::encode(new_flags, bl);
352 ::encode(fullmap, bl);
353 ::encode(crush, bl);
354
355 ::encode(new_max_osd, bl);
356 // for ::encode(new_pools, bl);
357 __u32 n = new_pools.size();
358 ::encode(n, bl);
359 for (const auto &new_pool : new_pools) {
360 n = new_pool.first;
361 ::encode(n, bl);
362 ::encode(new_pool.second, bl, 0);
363 }
364 // for ::encode(new_pool_names, bl);
365 n = new_pool_names.size();
366 ::encode(n, bl);
367
368 for (const auto &new_pool_name : new_pool_names) {
369 n = new_pool_name.first;
370 ::encode(n, bl);
371 ::encode(new_pool_name.second, bl);
372 }
373 // for ::encode(old_pools, bl);
374 n = old_pools.size();
375 ::encode(n, bl);
376 for (auto &old_pool : old_pools) {
377 n = old_pool;
378 ::encode(n, bl);
379 }
380 ::encode(new_up_client, bl, 0);
381 {
382 // legacy is map<int32_t,uint8_t>
383 uint32_t n = new_state.size();
384 ::encode(n, bl);
385 for (auto p : new_state) {
386 ::encode(p.first, bl);
387 ::encode((uint8_t)p.second, bl);
388 }
389 }
390 ::encode(new_weight, bl);
391 // for ::encode(new_pg_temp, bl);
392 n = new_pg_temp.size();
393 ::encode(n, bl);
394
395 for (const auto &pg_temp : new_pg_temp) {
396 old_pg_t opg = pg_temp.first.get_old_pg();
397 ::encode(opg, bl);
398 ::encode(pg_temp.second, bl);
399 }
400 }
401
402 void OSDMap::Incremental::encode_classic(bufferlist& bl, uint64_t features) const
403 {
404 if ((features & CEPH_FEATURE_PGID64) == 0) {
405 encode_client_old(bl);
406 return;
407 }
408
409 // base
410 __u16 v = 6;
411 ::encode(v, bl);
412 ::encode(fsid, bl);
413 ::encode(epoch, bl);
414 ::encode(modified, bl);
415 ::encode(new_pool_max, bl);
416 ::encode(new_flags, bl);
417 ::encode(fullmap, bl);
418 ::encode(crush, bl);
419
420 ::encode(new_max_osd, bl);
421 ::encode(new_pools, bl, features);
422 ::encode(new_pool_names, bl);
423 ::encode(old_pools, bl);
424 ::encode(new_up_client, bl, features);
425 {
426 uint32_t n = new_state.size();
427 ::encode(n, bl);
428 for (auto p : new_state) {
429 ::encode(p.first, bl);
430 ::encode((uint8_t)p.second, bl);
431 }
432 }
433 ::encode(new_weight, bl);
434 ::encode(new_pg_temp, bl);
435
436 // extended
437 __u16 ev = 10;
438 ::encode(ev, bl);
439 ::encode(new_hb_back_up, bl, features);
440 ::encode(new_up_thru, bl);
441 ::encode(new_last_clean_interval, bl);
442 ::encode(new_lost, bl);
443 ::encode(new_blacklist, bl, features);
444 ::encode(old_blacklist, bl, features);
445 ::encode(new_up_cluster, bl, features);
446 ::encode(cluster_snapshot, bl);
447 ::encode(new_uuid, bl);
448 ::encode(new_xinfo, bl);
449 ::encode(new_hb_front_up, bl, features);
450 }
451
452 void OSDMap::Incremental::encode(bufferlist& bl, uint64_t features) const
453 {
454 if ((features & CEPH_FEATURE_OSDMAP_ENC) == 0) {
455 encode_classic(bl, features);
456 return;
457 }
458
459 // only a select set of callers should *ever* be encoding new
460 // OSDMaps. others should be passing around the canonical encoded
461 // buffers from on high. select out those callers by passing in an
462 // "impossible" feature bit.
463 assert(features & CEPH_FEATURE_RESERVED);
464 features &= ~CEPH_FEATURE_RESERVED;
465
466 size_t start_offset = bl.length();
467 size_t tail_offset;
468 buffer::list::iterator crc_it;
469
470 // meta-encoding: how we include client-used and osd-specific data
471 ENCODE_START(8, 7, bl);
472
473 {
474 uint8_t v = 5;
475 if (!HAVE_FEATURE(features, SERVER_LUMINOUS)) {
476 v = 3;
477 }
478 ENCODE_START(v, 1, bl); // client-usable data
479 ::encode(fsid, bl);
480 ::encode(epoch, bl);
481 ::encode(modified, bl);
482 ::encode(new_pool_max, bl);
483 ::encode(new_flags, bl);
484 ::encode(fullmap, bl);
485 ::encode(crush, bl);
486
487 ::encode(new_max_osd, bl);
488 ::encode(new_pools, bl, features);
489 ::encode(new_pool_names, bl);
490 ::encode(old_pools, bl);
491 ::encode(new_up_client, bl, features);
492 if (v >= 5) {
493 ::encode(new_state, bl);
494 } else {
495 uint32_t n = new_state.size();
496 ::encode(n, bl);
497 for (auto p : new_state) {
498 ::encode(p.first, bl);
499 ::encode((uint8_t)p.second, bl);
500 }
501 }
502 ::encode(new_weight, bl);
503 ::encode(new_pg_temp, bl);
504 ::encode(new_primary_temp, bl);
505 ::encode(new_primary_affinity, bl);
506 ::encode(new_erasure_code_profiles, bl);
507 ::encode(old_erasure_code_profiles, bl);
508 if (v >= 4) {
509 ::encode(new_pg_upmap, bl);
510 ::encode(old_pg_upmap, bl);
511 ::encode(new_pg_upmap_items, bl);
512 ::encode(old_pg_upmap_items, bl);
513 }
514 ENCODE_FINISH(bl); // client-usable data
515 }
516
517 {
518 uint8_t target_v = 6;
519 if (!HAVE_FEATURE(features, SERVER_LUMINOUS)) {
520 target_v = 2;
521 }
522 ENCODE_START(target_v, 1, bl); // extended, osd-only data
523 ::encode(new_hb_back_up, bl, features);
524 ::encode(new_up_thru, bl);
525 ::encode(new_last_clean_interval, bl);
526 ::encode(new_lost, bl);
527 ::encode(new_blacklist, bl, features);
528 ::encode(old_blacklist, bl, features);
529 ::encode(new_up_cluster, bl, features);
530 ::encode(cluster_snapshot, bl);
531 ::encode(new_uuid, bl);
532 ::encode(new_xinfo, bl);
533 ::encode(new_hb_front_up, bl, features);
534 ::encode(features, bl); // NOTE: features arg, not the member
535 if (target_v >= 3) {
536 ::encode(new_nearfull_ratio, bl);
537 ::encode(new_full_ratio, bl);
538 ::encode(new_backfillfull_ratio, bl);
539 }
540 // 5 was string-based new_require_min_compat_client
541 if (target_v >= 6) {
542 ::encode(new_require_min_compat_client, bl);
543 ::encode(new_require_osd_release, bl);
544 }
545 ENCODE_FINISH(bl); // osd-only data
546 }
547
548 ::encode((uint32_t)0, bl); // dummy inc_crc
549 crc_it = bl.end();
550 crc_it.advance(-4);
551 tail_offset = bl.length();
552
553 ::encode(full_crc, bl);
554
555 ENCODE_FINISH(bl); // meta-encoding wrapper
556
557 // fill in crc
558 bufferlist front;
559 front.substr_of(bl, start_offset, crc_it.get_off() - start_offset);
560 inc_crc = front.crc32c(-1);
561 bufferlist tail;
562 tail.substr_of(bl, tail_offset, bl.length() - tail_offset);
563 inc_crc = tail.crc32c(inc_crc);
564 ceph_le32 crc_le;
565 crc_le = inc_crc;
566 crc_it.copy_in(4, (char*)&crc_le);
567 have_crc = true;
568 }
569
570 void OSDMap::Incremental::decode_classic(bufferlist::iterator &p)
571 {
572 __u32 n, t;
573 // base
574 __u16 v;
575 ::decode(v, p);
576 ::decode(fsid, p);
577 ::decode(epoch, p);
578 ::decode(modified, p);
579 if (v == 4 || v == 5) {
580 ::decode(n, p);
581 new_pool_max = n;
582 } else if (v >= 6)
583 ::decode(new_pool_max, p);
584 ::decode(new_flags, p);
585 ::decode(fullmap, p);
586 ::decode(crush, p);
587
588 ::decode(new_max_osd, p);
589 if (v < 6) {
590 new_pools.clear();
591 ::decode(n, p);
592 while (n--) {
593 ::decode(t, p);
594 ::decode(new_pools[t], p);
595 }
596 } else {
597 ::decode(new_pools, p);
598 }
599 if (v == 5) {
600 new_pool_names.clear();
601 ::decode(n, p);
602 while (n--) {
603 ::decode(t, p);
604 ::decode(new_pool_names[t], p);
605 }
606 } else if (v >= 6) {
607 ::decode(new_pool_names, p);
608 }
609 if (v < 6) {
610 old_pools.clear();
611 ::decode(n, p);
612 while (n--) {
613 ::decode(t, p);
614 old_pools.insert(t);
615 }
616 } else {
617 ::decode(old_pools, p);
618 }
619 ::decode(new_up_client, p);
620 {
621 map<int32_t,uint8_t> ns;
622 ::decode(ns, p);
623 for (auto q : ns) {
624 new_state[q.first] = q.second;
625 }
626 }
627 ::decode(new_weight, p);
628
629 if (v < 6) {
630 new_pg_temp.clear();
631 ::decode(n, p);
632 while (n--) {
633 old_pg_t opg;
634 ::decode_raw(opg, p);
635 ::decode(new_pg_temp[pg_t(opg)], p);
636 }
637 } else {
638 ::decode(new_pg_temp, p);
639 }
640
641 // decode short map, too.
642 if (v == 5 && p.end())
643 return;
644
645 // extended
646 __u16 ev = 0;
647 if (v >= 5)
648 ::decode(ev, p);
649 ::decode(new_hb_back_up, p);
650 if (v < 5)
651 ::decode(new_pool_names, p);
652 ::decode(new_up_thru, p);
653 ::decode(new_last_clean_interval, p);
654 ::decode(new_lost, p);
655 ::decode(new_blacklist, p);
656 ::decode(old_blacklist, p);
657 if (ev >= 6)
658 ::decode(new_up_cluster, p);
659 if (ev >= 7)
660 ::decode(cluster_snapshot, p);
661 if (ev >= 8)
662 ::decode(new_uuid, p);
663 if (ev >= 9)
664 ::decode(new_xinfo, p);
665 if (ev >= 10)
666 ::decode(new_hb_front_up, p);
667 }
668
669 void OSDMap::Incremental::decode(bufferlist::iterator& bl)
670 {
671 /**
672 * Older encodings of the Incremental had a single struct_v which
673 * covered the whole encoding, and was prior to our modern
674 * stuff which includes a compatv and a size. So if we see
675 * a struct_v < 7, we must rewind to the beginning and use our
676 * classic decoder.
677 */
678 size_t start_offset = bl.get_off();
679 size_t tail_offset = 0;
680 bufferlist crc_front, crc_tail;
681
682 DECODE_START_LEGACY_COMPAT_LEN(8, 7, 7, bl); // wrapper
683 if (struct_v < 7) {
684 int struct_v_size = sizeof(struct_v);
685 bl.advance(-struct_v_size);
686 decode_classic(bl);
687 encode_features = 0;
688 if (struct_v >= 6)
689 encode_features = CEPH_FEATURE_PGID64;
690 else
691 encode_features = 0;
692 return;
693 }
694 {
695 DECODE_START(5, bl); // client-usable data
696 ::decode(fsid, bl);
697 ::decode(epoch, bl);
698 ::decode(modified, bl);
699 ::decode(new_pool_max, bl);
700 ::decode(new_flags, bl);
701 ::decode(fullmap, bl);
702 ::decode(crush, bl);
703
704 ::decode(new_max_osd, bl);
705 ::decode(new_pools, bl);
706 ::decode(new_pool_names, bl);
707 ::decode(old_pools, bl);
708 ::decode(new_up_client, bl);
709 if (struct_v >= 5) {
710 ::decode(new_state, bl);
711 } else {
712 map<int32_t,uint8_t> ns;
713 ::decode(ns, bl);
714 for (auto q : ns) {
715 new_state[q.first] = q.second;
716 }
717 }
718 ::decode(new_weight, bl);
719 ::decode(new_pg_temp, bl);
720 ::decode(new_primary_temp, bl);
721 if (struct_v >= 2)
722 ::decode(new_primary_affinity, bl);
723 else
724 new_primary_affinity.clear();
725 if (struct_v >= 3) {
726 ::decode(new_erasure_code_profiles, bl);
727 ::decode(old_erasure_code_profiles, bl);
728 } else {
729 new_erasure_code_profiles.clear();
730 old_erasure_code_profiles.clear();
731 }
732 if (struct_v >= 4) {
733 ::decode(new_pg_upmap, bl);
734 ::decode(old_pg_upmap, bl);
735 ::decode(new_pg_upmap_items, bl);
736 ::decode(old_pg_upmap_items, bl);
737 }
738 DECODE_FINISH(bl); // client-usable data
739 }
740
741 {
742 DECODE_START(6, bl); // extended, osd-only data
743 ::decode(new_hb_back_up, bl);
744 ::decode(new_up_thru, bl);
745 ::decode(new_last_clean_interval, bl);
746 ::decode(new_lost, bl);
747 ::decode(new_blacklist, bl);
748 ::decode(old_blacklist, bl);
749 ::decode(new_up_cluster, bl);
750 ::decode(cluster_snapshot, bl);
751 ::decode(new_uuid, bl);
752 ::decode(new_xinfo, bl);
753 ::decode(new_hb_front_up, bl);
754 if (struct_v >= 2)
755 ::decode(encode_features, bl);
756 else
757 encode_features = CEPH_FEATURE_PGID64 | CEPH_FEATURE_OSDMAP_ENC;
758 if (struct_v >= 3) {
759 ::decode(new_nearfull_ratio, bl);
760 ::decode(new_full_ratio, bl);
761 } else {
762 new_nearfull_ratio = -1;
763 new_full_ratio = -1;
764 }
765 if (struct_v >= 4) {
766 ::decode(new_backfillfull_ratio, bl);
767 } else {
768 new_backfillfull_ratio = -1;
769 }
770 if (struct_v == 5) {
771 string r;
772 ::decode(r, bl);
773 if (r.length()) {
774 new_require_min_compat_client = ceph_release_from_name(r.c_str());
775 }
776 }
777 if (struct_v >= 6) {
778 ::decode(new_require_min_compat_client, bl);
779 ::decode(new_require_osd_release, bl);
780 } else {
781 if (new_flags >= 0 && (new_flags & CEPH_OSDMAP_REQUIRE_LUMINOUS)) {
782 // only for compat with post-kraken pre-luminous test clusters
783 new_require_osd_release = CEPH_RELEASE_LUMINOUS;
784 new_flags &= ~(CEPH_OSDMAP_LEGACY_REQUIRE_FLAGS);
785 } else if (new_flags >= 0 && (new_flags & CEPH_OSDMAP_REQUIRE_KRAKEN)) {
786 new_require_osd_release = CEPH_RELEASE_KRAKEN;
787 } else if (new_flags >= 0 && (new_flags & CEPH_OSDMAP_REQUIRE_JEWEL)) {
788 new_require_osd_release = CEPH_RELEASE_JEWEL;
789 } else {
790 new_require_osd_release = -1;
791 }
792 }
793 DECODE_FINISH(bl); // osd-only data
794 }
795
796 if (struct_v >= 8) {
797 have_crc = true;
798 crc_front.substr_of(bl.get_bl(), start_offset, bl.get_off() - start_offset);
799 ::decode(inc_crc, bl);
800 tail_offset = bl.get_off();
801 ::decode(full_crc, bl);
802 } else {
803 have_crc = false;
804 full_crc = 0;
805 inc_crc = 0;
806 }
807
808 DECODE_FINISH(bl); // wrapper
809
810 if (have_crc) {
811 // verify crc
812 uint32_t actual = crc_front.crc32c(-1);
813 if (tail_offset < bl.get_off()) {
814 bufferlist tail;
815 tail.substr_of(bl.get_bl(), tail_offset, bl.get_off() - tail_offset);
816 actual = tail.crc32c(actual);
817 }
818 if (inc_crc != actual) {
819 ostringstream ss;
820 ss << "bad crc, actual " << actual << " != expected " << inc_crc;
821 string s = ss.str();
822 throw buffer::malformed_input(s.c_str());
823 }
824 }
825 }
826
827 void OSDMap::Incremental::dump(Formatter *f) const
828 {
829 f->dump_int("epoch", epoch);
830 f->dump_stream("fsid") << fsid;
831 f->dump_stream("modified") << modified;
832 f->dump_int("new_pool_max", new_pool_max);
833 f->dump_int("new_flags", new_flags);
834 f->dump_float("new_full_ratio", new_full_ratio);
835 f->dump_float("new_nearfull_ratio", new_nearfull_ratio);
836 f->dump_float("new_backfillfull_ratio", new_backfillfull_ratio);
837 f->dump_int("new_require_min_compat_client", new_require_min_compat_client);
838 f->dump_int("new_require_osd_release", new_require_osd_release);
839
840 if (fullmap.length()) {
841 f->open_object_section("full_map");
842 OSDMap full;
843 bufferlist fbl = fullmap; // kludge around constness.
844 auto p = fbl.begin();
845 full.decode(p);
846 full.dump(f);
847 f->close_section();
848 }
849 if (crush.length()) {
850 f->open_object_section("crush");
851 CrushWrapper c;
852 bufferlist tbl = crush; // kludge around constness.
853 auto p = tbl.begin();
854 c.decode(p);
855 c.dump(f);
856 f->close_section();
857 }
858
859 f->dump_int("new_max_osd", new_max_osd);
860
861 f->open_array_section("new_pools");
862
863 for (const auto &new_pool : new_pools) {
864 f->open_object_section("pool");
865 f->dump_int("pool", new_pool.first);
866 new_pool.second.dump(f);
867 f->close_section();
868 }
869 f->close_section();
870 f->open_array_section("new_pool_names");
871
872 for (const auto &new_pool_name : new_pool_names) {
873 f->open_object_section("pool_name");
874 f->dump_int("pool", new_pool_name.first);
875 f->dump_string("name", new_pool_name.second);
876 f->close_section();
877 }
878 f->close_section();
879 f->open_array_section("old_pools");
880
881 for (const auto &old_pool : old_pools)
882 f->dump_int("pool", old_pool);
883 f->close_section();
884
885 f->open_array_section("new_up_osds");
886
887 for (const auto &upclient : new_up_client) {
888 f->open_object_section("osd");
889 f->dump_int("osd", upclient.first);
890 f->dump_stream("public_addr") << upclient.second;
891 f->dump_stream("cluster_addr") << new_up_cluster.find(upclient.first)->second;
892 f->dump_stream("heartbeat_back_addr") << new_hb_back_up.find(upclient.first)->second;
893 map<int32_t, entity_addr_t>::const_iterator q;
894 if ((q = new_hb_front_up.find(upclient.first)) != new_hb_front_up.end())
895 f->dump_stream("heartbeat_front_addr") << q->second;
896 f->close_section();
897 }
898 f->close_section();
899
900 f->open_array_section("new_weight");
901
902 for (const auto &weight : new_weight) {
903 f->open_object_section("osd");
904 f->dump_int("osd", weight.first);
905 f->dump_int("weight", weight.second);
906 f->close_section();
907 }
908 f->close_section();
909
910 f->open_array_section("osd_state_xor");
911 for (const auto &ns : new_state) {
912 f->open_object_section("osd");
913 f->dump_int("osd", ns.first);
914 set<string> st;
915 calc_state_set(new_state.find(ns.first)->second, st);
916 f->open_array_section("state_xor");
917 for (auto &state : st)
918 f->dump_string("state", state);
919 f->close_section();
920 f->close_section();
921 }
922 f->close_section();
923
924 f->open_array_section("new_pg_temp");
925
926 for (const auto &pg_temp : new_pg_temp) {
927 f->open_object_section("pg");
928 f->dump_stream("pgid") << pg_temp.first;
929 f->open_array_section("osds");
930
931 for (const auto &osd : pg_temp.second)
932 f->dump_int("osd", osd);
933 f->close_section();
934 f->close_section();
935 }
936 f->close_section();
937
938 f->open_array_section("primary_temp");
939
940 for (const auto &primary_temp : new_primary_temp) {
941 f->dump_stream("pgid") << primary_temp.first;
942 f->dump_int("osd", primary_temp.second);
943 }
944 f->close_section(); // primary_temp
945
946 f->open_array_section("new_pg_upmap");
947 for (auto& i : new_pg_upmap) {
948 f->open_object_section("mapping");
949 f->dump_stream("pgid") << i.first;
950 f->open_array_section("osds");
951 for (auto osd : i.second) {
952 f->dump_int("osd", osd);
953 }
954 f->close_section();
955 f->close_section();
956 }
957 f->close_section();
958 f->open_array_section("old_pg_upmap");
959 for (auto& i : old_pg_upmap) {
960 f->dump_stream("pgid") << i;
961 }
962 f->close_section();
963
964 f->open_array_section("new_pg_upmap_items");
965 for (auto& i : new_pg_upmap_items) {
966 f->open_object_section("mapping");
967 f->dump_stream("pgid") << i.first;
968 f->open_array_section("mappings");
969 for (auto& p : i.second) {
970 f->open_object_section("mapping");
971 f->dump_int("from", p.first);
972 f->dump_int("to", p.second);
973 f->close_section();
974 }
975 f->close_section();
976 f->close_section();
977 }
978 f->close_section();
979 f->open_array_section("old_pg_upmap_items");
980 for (auto& i : old_pg_upmap_items) {
981 f->dump_stream("pgid") << i;
982 }
983 f->close_section();
984
985 f->open_array_section("new_up_thru");
986
987 for (const auto &up_thru : new_up_thru) {
988 f->open_object_section("osd");
989 f->dump_int("osd", up_thru.first);
990 f->dump_int("up_thru", up_thru.second);
991 f->close_section();
992 }
993 f->close_section();
994
995 f->open_array_section("new_lost");
996
997 for (const auto &lost : new_lost) {
998 f->open_object_section("osd");
999 f->dump_int("osd", lost.first);
1000 f->dump_int("epoch_lost", lost.second);
1001 f->close_section();
1002 }
1003 f->close_section();
1004
1005 f->open_array_section("new_last_clean_interval");
1006
1007 for (const auto &last_clean_interval : new_last_clean_interval) {
1008 f->open_object_section("osd");
1009 f->dump_int("osd", last_clean_interval.first);
1010 f->dump_int("first", last_clean_interval.second.first);
1011 f->dump_int("last", last_clean_interval.second.second);
1012 f->close_section();
1013 }
1014 f->close_section();
1015
1016 f->open_array_section("new_blacklist");
1017 for (const auto &blist : new_blacklist) {
1018 stringstream ss;
1019 ss << blist.first;
1020 f->dump_stream(ss.str().c_str()) << blist.second;
1021 }
1022 f->close_section();
1023 f->open_array_section("old_blacklist");
1024 for (const auto &blist : old_blacklist)
1025 f->dump_stream("addr") << blist;
1026 f->close_section();
1027
1028 f->open_array_section("new_xinfo");
1029 for (const auto &xinfo : new_xinfo) {
1030 f->open_object_section("xinfo");
1031 f->dump_int("osd", xinfo.first);
1032 xinfo.second.dump(f);
1033 f->close_section();
1034 }
1035 f->close_section();
1036
1037 if (cluster_snapshot.size())
1038 f->dump_string("cluster_snapshot", cluster_snapshot);
1039
1040 f->open_array_section("new_uuid");
1041 for (const auto &uuid : new_uuid) {
1042 f->open_object_section("osd");
1043 f->dump_int("osd", uuid.first);
1044 f->dump_stream("uuid") << uuid.second;
1045 f->close_section();
1046 }
1047 f->close_section();
1048
1049 OSDMap::dump_erasure_code_profiles(new_erasure_code_profiles, f);
1050 f->open_array_section("old_erasure_code_profiles");
1051 for (const auto &erasure_code_profile : old_erasure_code_profiles) {
1052 f->dump_string("old", erasure_code_profile.c_str());
1053 }
1054 f->close_section();
1055 }
1056
1057 void OSDMap::Incremental::generate_test_instances(list<Incremental*>& o)
1058 {
1059 o.push_back(new Incremental);
1060 }
1061
1062 // ----------------------------------
1063 // OSDMap
1064
1065 void OSDMap::set_epoch(epoch_t e)
1066 {
1067 epoch = e;
1068 for (auto &pool : pools)
1069 pool.second.last_change = e;
1070 }
1071
1072 bool OSDMap::is_blacklisted(const entity_addr_t& a) const
1073 {
1074 if (blacklist.empty())
1075 return false;
1076
1077 // this specific instance?
1078 if (blacklist.count(a))
1079 return true;
1080
1081 // is entire ip blacklisted?
1082 if (a.is_ip()) {
1083 entity_addr_t b = a;
1084 b.set_port(0);
1085 b.set_nonce(0);
1086 if (blacklist.count(b)) {
1087 return true;
1088 }
1089 }
1090
1091 return false;
1092 }
1093
1094 void OSDMap::get_blacklist(list<pair<entity_addr_t,utime_t> > *bl) const
1095 {
1096 std::copy(blacklist.begin(), blacklist.end(), std::back_inserter(*bl));
1097 }
1098
1099 void OSDMap::get_blacklist(std::set<entity_addr_t> *bl) const
1100 {
1101 for (const auto &i : blacklist) {
1102 bl->insert(i.first);
1103 }
1104 }
1105
1106 void OSDMap::set_max_osd(int m)
1107 {
1108 int o = max_osd;
1109 max_osd = m;
1110 osd_state.resize(m);
1111 osd_weight.resize(m);
1112 for (; o<max_osd; o++) {
1113 osd_state[o] = 0;
1114 osd_weight[o] = CEPH_OSD_OUT;
1115 }
1116 osd_info.resize(m);
1117 osd_xinfo.resize(m);
1118 osd_addrs->client_addr.resize(m);
1119 osd_addrs->cluster_addr.resize(m);
1120 osd_addrs->hb_back_addr.resize(m);
1121 osd_addrs->hb_front_addr.resize(m);
1122 osd_uuid->resize(m);
1123 if (osd_primary_affinity)
1124 osd_primary_affinity->resize(m, CEPH_OSD_DEFAULT_PRIMARY_AFFINITY);
1125
1126 calc_num_osds();
1127 }
1128
1129 int OSDMap::calc_num_osds()
1130 {
1131 num_osd = 0;
1132 num_up_osd = 0;
1133 num_in_osd = 0;
1134 for (int i=0; i<max_osd; i++) {
1135 if (osd_state[i] & CEPH_OSD_EXISTS) {
1136 ++num_osd;
1137 if (osd_state[i] & CEPH_OSD_UP) {
1138 ++num_up_osd;
1139 }
1140 if (get_weight(i) != CEPH_OSD_OUT) {
1141 ++num_in_osd;
1142 }
1143 }
1144 }
1145 return num_osd;
1146 }
1147
1148 void OSDMap::count_full_nearfull_osds(int *full, int *backfill, int *nearfull) const
1149 {
1150 *full = 0;
1151 *backfill = 0;
1152 *nearfull = 0;
1153 for (int i = 0; i < max_osd; ++i) {
1154 if (exists(i) && is_up(i) && is_in(i)) {
1155 if (osd_state[i] & CEPH_OSD_FULL)
1156 ++(*full);
1157 else if (osd_state[i] & CEPH_OSD_BACKFILLFULL)
1158 ++(*backfill);
1159 else if (osd_state[i] & CEPH_OSD_NEARFULL)
1160 ++(*nearfull);
1161 }
1162 }
1163 }
1164
1165 static bool get_osd_utilization(
1166 const mempool::pgmap::unordered_map<int32_t,osd_stat_t> &osd_stat,
1167 int id, int64_t* kb, int64_t* kb_used, int64_t* kb_avail)
1168 {
1169 auto p = osd_stat.find(id);
1170 if (p == osd_stat.end())
1171 return false;
1172 *kb = p->second.kb;
1173 *kb_used = p->second.kb_used;
1174 *kb_avail = p->second.kb_avail;
1175 return *kb > 0;
1176 }
1177
1178 void OSDMap::get_full_osd_util(
1179 const mempool::pgmap::unordered_map<int32_t,osd_stat_t> &osd_stat,
1180 map<int, float> *full, map<int, float> *backfill, map<int, float> *nearfull) const
1181 {
1182 full->clear();
1183 backfill->clear();
1184 nearfull->clear();
1185 for (int i = 0; i < max_osd; ++i) {
1186 if (exists(i) && is_up(i) && is_in(i)) {
1187 int64_t kb, kb_used, kb_avail;
1188 if (osd_state[i] & CEPH_OSD_FULL) {
1189 if (get_osd_utilization(osd_stat, i, &kb, &kb_used, &kb_avail))
1190 full->emplace(i, (float)kb_used / (float)kb);
1191 } else if (osd_state[i] & CEPH_OSD_BACKFILLFULL) {
1192 if (get_osd_utilization(osd_stat, i, &kb, &kb_used, &kb_avail))
1193 backfill->emplace(i, (float)kb_used / (float)kb);
1194 } else if (osd_state[i] & CEPH_OSD_NEARFULL) {
1195 if (get_osd_utilization(osd_stat, i, &kb, &kb_used, &kb_avail))
1196 nearfull->emplace(i, (float)kb_used / (float)kb);
1197 }
1198 }
1199 }
1200 }
1201
1202 void OSDMap::get_full_osd_counts(set<int> *full, set<int> *backfill,
1203 set<int> *nearfull) const
1204 {
1205 full->clear();
1206 backfill->clear();
1207 nearfull->clear();
1208 for (int i = 0; i < max_osd; ++i) {
1209 if (exists(i) && is_up(i) && is_in(i)) {
1210 if (osd_state[i] & CEPH_OSD_FULL)
1211 full->emplace(i);
1212 else if (osd_state[i] & CEPH_OSD_BACKFILLFULL)
1213 backfill->emplace(i);
1214 else if (osd_state[i] & CEPH_OSD_NEARFULL)
1215 nearfull->emplace(i);
1216 }
1217 }
1218 }
1219
1220 void OSDMap::get_all_osds(set<int32_t>& ls) const
1221 {
1222 for (int i=0; i<max_osd; i++)
1223 if (exists(i))
1224 ls.insert(i);
1225 }
1226
1227 void OSDMap::get_up_osds(set<int32_t>& ls) const
1228 {
1229 for (int i = 0; i < max_osd; i++) {
1230 if (is_up(i))
1231 ls.insert(i);
1232 }
1233 }
1234
1235 void OSDMap::get_out_osds(set<int32_t>& ls) const
1236 {
1237 for (int i = 0; i < max_osd; i++) {
1238 if (is_out(i))
1239 ls.insert(i);
1240 }
1241 }
1242
1243 void OSDMap::calc_state_set(int state, set<string>& st)
1244 {
1245 unsigned t = state;
1246 for (unsigned s = 1; t; s <<= 1) {
1247 if (t & s) {
1248 t &= ~s;
1249 st.insert(ceph_osd_state_name(s));
1250 }
1251 }
1252 }
1253
1254 void OSDMap::adjust_osd_weights(const map<int,double>& weights, Incremental& inc) const
1255 {
1256 float max = 0;
1257 for (const auto &weight : weights) {
1258 if (weight.second > max)
1259 max = weight.second;
1260 }
1261
1262 for (const auto &weight : weights) {
1263 inc.new_weight[weight.first] = (unsigned)((weight.second / max) * CEPH_OSD_IN);
1264 }
1265 }
1266
1267 int OSDMap::identify_osd(const entity_addr_t& addr) const
1268 {
1269 for (int i=0; i<max_osd; i++)
1270 if (exists(i) && (get_addr(i) == addr || get_cluster_addr(i) == addr))
1271 return i;
1272 return -1;
1273 }
1274
1275 int OSDMap::identify_osd(const uuid_d& u) const
1276 {
1277 for (int i=0; i<max_osd; i++)
1278 if (exists(i) && get_uuid(i) == u)
1279 return i;
1280 return -1;
1281 }
1282
1283 int OSDMap::identify_osd_on_all_channels(const entity_addr_t& addr) const
1284 {
1285 for (int i=0; i<max_osd; i++)
1286 if (exists(i) && (get_addr(i) == addr || get_cluster_addr(i) == addr ||
1287 get_hb_back_addr(i) == addr || get_hb_front_addr(i) == addr))
1288 return i;
1289 return -1;
1290 }
1291
1292 int OSDMap::find_osd_on_ip(const entity_addr_t& ip) const
1293 {
1294 for (int i=0; i<max_osd; i++)
1295 if (exists(i) && (get_addr(i).is_same_host(ip) || get_cluster_addr(i).is_same_host(ip)))
1296 return i;
1297 return -1;
1298 }
1299
1300
1301 uint64_t OSDMap::get_features(int entity_type, uint64_t *pmask) const
1302 {
1303 uint64_t features = 0; // things we actually have
1304 uint64_t mask = 0; // things we could have
1305
1306 if (crush->has_nondefault_tunables())
1307 features |= CEPH_FEATURE_CRUSH_TUNABLES;
1308 if (crush->has_nondefault_tunables2())
1309 features |= CEPH_FEATURE_CRUSH_TUNABLES2;
1310 if (crush->has_nondefault_tunables3())
1311 features |= CEPH_FEATURE_CRUSH_TUNABLES3;
1312 if (crush->has_v4_buckets())
1313 features |= CEPH_FEATURE_CRUSH_V4;
1314 if (crush->has_nondefault_tunables5())
1315 features |= CEPH_FEATURE_CRUSH_TUNABLES5;
1316 if (crush->has_incompat_choose_args()) {
1317 features |= CEPH_FEATUREMASK_CRUSH_CHOOSE_ARGS;
1318 }
1319 mask |= CEPH_FEATURES_CRUSH;
1320
1321 if (!pg_upmap.empty() || !pg_upmap_items.empty())
1322 features |= CEPH_FEATUREMASK_OSDMAP_PG_UPMAP;
1323 mask |= CEPH_FEATUREMASK_OSDMAP_PG_UPMAP;
1324
1325 for (auto &pool: pools) {
1326 if (pool.second.has_flag(pg_pool_t::FLAG_HASHPSPOOL)) {
1327 features |= CEPH_FEATURE_OSDHASHPSPOOL;
1328 }
1329 if (pool.second.is_erasure() &&
1330 entity_type != CEPH_ENTITY_TYPE_CLIENT) { // not for clients
1331 features |= CEPH_FEATURE_OSD_ERASURE_CODES;
1332 }
1333 if (!pool.second.tiers.empty() ||
1334 pool.second.is_tier()) {
1335 features |= CEPH_FEATURE_OSD_CACHEPOOL;
1336 }
1337 int ruleid = crush->find_rule(pool.second.get_crush_rule(),
1338 pool.second.get_type(),
1339 pool.second.get_size());
1340 if (ruleid >= 0) {
1341 if (crush->is_v2_rule(ruleid))
1342 features |= CEPH_FEATURE_CRUSH_V2;
1343 if (crush->is_v3_rule(ruleid))
1344 features |= CEPH_FEATURE_CRUSH_TUNABLES3;
1345 if (crush->is_v5_rule(ruleid))
1346 features |= CEPH_FEATURE_CRUSH_TUNABLES5;
1347 }
1348 }
1349 if (entity_type == CEPH_ENTITY_TYPE_OSD) {
1350 for (auto &erasure_code_profile : erasure_code_profiles) {
1351 auto& profile = erasure_code_profile.second;
1352 const auto& plugin = profile.find("plugin");
1353 if (plugin != profile.end()) {
1354 if (plugin->second == "isa" || plugin->second == "lrc")
1355 features |= CEPH_FEATURE_ERASURE_CODE_PLUGINS_V2;
1356 if (plugin->second == "shec")
1357 features |= CEPH_FEATURE_ERASURE_CODE_PLUGINS_V3;
1358 }
1359 }
1360 }
1361 mask |= CEPH_FEATURE_OSDHASHPSPOOL | CEPH_FEATURE_OSD_CACHEPOOL;
1362 if (entity_type != CEPH_ENTITY_TYPE_CLIENT)
1363 mask |= CEPH_FEATURE_OSD_ERASURE_CODES;
1364
1365 if (osd_primary_affinity) {
1366 for (int i = 0; i < max_osd; ++i) {
1367 if ((*osd_primary_affinity)[i] != CEPH_OSD_DEFAULT_PRIMARY_AFFINITY) {
1368 features |= CEPH_FEATURE_OSD_PRIMARY_AFFINITY;
1369 break;
1370 }
1371 }
1372 }
1373 mask |= CEPH_FEATURE_OSD_PRIMARY_AFFINITY;
1374
1375 if (entity_type == CEPH_ENTITY_TYPE_OSD) {
1376 const uint64_t jewel_features = CEPH_FEATURE_SERVER_JEWEL;
1377 if (require_osd_release >= CEPH_RELEASE_JEWEL) {
1378 features |= jewel_features;
1379 }
1380 mask |= jewel_features;
1381
1382 const uint64_t kraken_features = CEPH_FEATUREMASK_SERVER_KRAKEN
1383 | CEPH_FEATURE_MSG_ADDR2;
1384 if (require_osd_release >= CEPH_RELEASE_KRAKEN) {
1385 features |= kraken_features;
1386 }
1387 mask |= kraken_features;
1388 }
1389
1390 if (pmask)
1391 *pmask = mask;
1392 return features;
1393 }
1394
1395 uint8_t OSDMap::get_min_compat_client() const
1396 {
1397 uint64_t f = get_features(CEPH_ENTITY_TYPE_CLIENT, nullptr);
1398
1399 if (HAVE_FEATURE(f, OSDMAP_PG_UPMAP) || // v12.0.0-1733-g27d6f43
1400 HAVE_FEATURE(f, CRUSH_CHOOSE_ARGS)) { // v12.0.1-2172-gef1ef28
1401 return CEPH_RELEASE_LUMINOUS; // v12.2.0
1402 }
1403 if (HAVE_FEATURE(f, CRUSH_TUNABLES5)) { // v10.0.0-612-g043a737
1404 return CEPH_RELEASE_JEWEL; // v10.2.0
1405 }
1406 if (HAVE_FEATURE(f, CRUSH_V4)) { // v0.91-678-g325fc56
1407 return CEPH_RELEASE_HAMMER; // v0.94.0
1408 }
1409 if (HAVE_FEATURE(f, OSD_PRIMARY_AFFINITY) || // v0.76-553-gf825624
1410 HAVE_FEATURE(f, CRUSH_TUNABLES3) || // v0.76-395-ge20a55d
1411 HAVE_FEATURE(f, OSD_ERASURE_CODES) || // v0.73-498-gbfc86a8
1412 HAVE_FEATURE(f, OSD_CACHEPOOL)) { // v0.67-401-gb91c1c5
1413 return CEPH_RELEASE_FIREFLY; // v0.80.0
1414 }
1415 if (HAVE_FEATURE(f, CRUSH_TUNABLES2) || // v0.54-684-g0cc47ff
1416 HAVE_FEATURE(f, OSDHASHPSPOOL)) { // v0.57-398-g8cc2b0f
1417 return CEPH_RELEASE_DUMPLING; // v0.67.0
1418 }
1419 if (HAVE_FEATURE(f, CRUSH_TUNABLES)) { // v0.48argonaut-206-g6f381af
1420 return CEPH_RELEASE_ARGONAUT; // v0.48argonaut-206-g6f381af
1421 }
1422 return CEPH_RELEASE_ARGONAUT; // v0.48argonaut-206-g6f381af
1423 }
1424
1425 void OSDMap::_calc_up_osd_features()
1426 {
1427 bool first = true;
1428 cached_up_osd_features = 0;
1429 for (int osd = 0; osd < max_osd; ++osd) {
1430 if (!is_up(osd))
1431 continue;
1432 const osd_xinfo_t &xi = get_xinfo(osd);
1433 if (first) {
1434 cached_up_osd_features = xi.features;
1435 first = false;
1436 } else {
1437 cached_up_osd_features &= xi.features;
1438 }
1439 }
1440 }
1441
1442 uint64_t OSDMap::get_up_osd_features() const
1443 {
1444 return cached_up_osd_features;
1445 }
1446
1447 void OSDMap::dedup(const OSDMap *o, OSDMap *n)
1448 {
1449 if (o->epoch == n->epoch)
1450 return;
1451
1452 int diff = 0;
1453
1454 // do addrs match?
1455 if (o->max_osd != n->max_osd)
1456 diff++;
1457 for (int i = 0; i < o->max_osd && i < n->max_osd; i++) {
1458 if ( n->osd_addrs->client_addr[i] && o->osd_addrs->client_addr[i] &&
1459 *n->osd_addrs->client_addr[i] == *o->osd_addrs->client_addr[i])
1460 n->osd_addrs->client_addr[i] = o->osd_addrs->client_addr[i];
1461 else
1462 diff++;
1463 if ( n->osd_addrs->cluster_addr[i] && o->osd_addrs->cluster_addr[i] &&
1464 *n->osd_addrs->cluster_addr[i] == *o->osd_addrs->cluster_addr[i])
1465 n->osd_addrs->cluster_addr[i] = o->osd_addrs->cluster_addr[i];
1466 else
1467 diff++;
1468 if ( n->osd_addrs->hb_back_addr[i] && o->osd_addrs->hb_back_addr[i] &&
1469 *n->osd_addrs->hb_back_addr[i] == *o->osd_addrs->hb_back_addr[i])
1470 n->osd_addrs->hb_back_addr[i] = o->osd_addrs->hb_back_addr[i];
1471 else
1472 diff++;
1473 if ( n->osd_addrs->hb_front_addr[i] && o->osd_addrs->hb_front_addr[i] &&
1474 *n->osd_addrs->hb_front_addr[i] == *o->osd_addrs->hb_front_addr[i])
1475 n->osd_addrs->hb_front_addr[i] = o->osd_addrs->hb_front_addr[i];
1476 else
1477 diff++;
1478 }
1479 if (diff == 0) {
1480 // zoinks, no differences at all!
1481 n->osd_addrs = o->osd_addrs;
1482 }
1483
1484 // does crush match?
1485 bufferlist oc, nc;
1486 ::encode(*o->crush, oc, CEPH_FEATURES_SUPPORTED_DEFAULT);
1487 ::encode(*n->crush, nc, CEPH_FEATURES_SUPPORTED_DEFAULT);
1488 if (oc.contents_equal(nc)) {
1489 n->crush = o->crush;
1490 }
1491
1492 // does pg_temp match?
1493 if (*o->pg_temp == *n->pg_temp)
1494 n->pg_temp = o->pg_temp;
1495
1496 // does primary_temp match?
1497 if (o->primary_temp->size() == n->primary_temp->size()) {
1498 if (*o->primary_temp == *n->primary_temp)
1499 n->primary_temp = o->primary_temp;
1500 }
1501
1502 // do uuids match?
1503 if (o->osd_uuid->size() == n->osd_uuid->size() &&
1504 *o->osd_uuid == *n->osd_uuid)
1505 n->osd_uuid = o->osd_uuid;
1506 }
1507
1508 void OSDMap::clean_temps(CephContext *cct,
1509 const OSDMap& osdmap, Incremental *pending_inc)
1510 {
1511 ldout(cct, 10) << __func__ << dendl;
1512 OSDMap tmpmap;
1513 tmpmap.deepish_copy_from(osdmap);
1514 tmpmap.apply_incremental(*pending_inc);
1515
1516 for (auto pg : *tmpmap.pg_temp) {
1517 // if pool does not exist, remove any existing pg_temps associated with
1518 // it. we don't care about pg_temps on the pending_inc either; if there
1519 // are new_pg_temp entries on the pending, clear them out just as well.
1520 if (!osdmap.have_pg_pool(pg.first.pool())) {
1521 ldout(cct, 10) << __func__ << " removing pg_temp " << pg.first
1522 << " for nonexistent pool " << pg.first.pool() << dendl;
1523 pending_inc->new_pg_temp[pg.first].clear();
1524 continue;
1525 }
1526 // all osds down?
1527 unsigned num_up = 0;
1528 for (auto o : pg.second) {
1529 if (!tmpmap.is_down(o)) {
1530 ++num_up;
1531 break;
1532 }
1533 }
1534 if (num_up == 0) {
1535 ldout(cct, 10) << __func__ << " removing pg_temp " << pg.first
1536 << " with all down osds" << pg.second << dendl;
1537 pending_inc->new_pg_temp[pg.first].clear();
1538 continue;
1539 }
1540 // redundant pg_temp?
1541 vector<int> raw_up;
1542 int primary;
1543 tmpmap.pg_to_raw_up(pg.first, &raw_up, &primary);
1544 if (vectors_equal(raw_up, pg.second)) {
1545 ldout(cct, 10) << __func__ << " removing pg_temp " << pg.first << " "
1546 << pg.second << " that matches raw_up mapping" << dendl;
1547 if (osdmap.pg_temp->count(pg.first))
1548 pending_inc->new_pg_temp[pg.first].clear();
1549 else
1550 pending_inc->new_pg_temp.erase(pg.first);
1551 }
1552 }
1553
1554 for (auto &pg : *tmpmap.primary_temp) {
1555 // primary down?
1556 if (tmpmap.is_down(pg.second)) {
1557 ldout(cct, 10) << __func__ << " removing primary_temp " << pg.first
1558 << " to down " << pg.second << dendl;
1559 pending_inc->new_primary_temp[pg.first] = -1;
1560 continue;
1561 }
1562 // redundant primary_temp?
1563 vector<int> real_up, templess_up;
1564 int real_primary, templess_primary;
1565 pg_t pgid = pg.first;
1566 tmpmap.pg_to_acting_osds(pgid, &real_up, &real_primary);
1567 tmpmap.pg_to_raw_up(pgid, &templess_up, &templess_primary);
1568 if (real_primary == templess_primary){
1569 ldout(cct, 10) << __func__ << " removing primary_temp "
1570 << pgid << " -> " << real_primary
1571 << " (unnecessary/redundant)" << dendl;
1572 if (osdmap.primary_temp->count(pgid))
1573 pending_inc->new_primary_temp[pgid] = -1;
1574 else
1575 pending_inc->new_primary_temp.erase(pgid);
1576 }
1577 }
1578 }
1579
1580 int OSDMap::apply_incremental(const Incremental &inc)
1581 {
1582 new_blacklist_entries = false;
1583 if (inc.epoch == 1)
1584 fsid = inc.fsid;
1585 else if (inc.fsid != fsid)
1586 return -EINVAL;
1587
1588 assert(inc.epoch == epoch+1);
1589
1590 epoch++;
1591 modified = inc.modified;
1592
1593 // full map?
1594 if (inc.fullmap.length()) {
1595 bufferlist bl(inc.fullmap);
1596 decode(bl);
1597 return 0;
1598 }
1599
1600 // nope, incremental.
1601 if (inc.new_flags >= 0) {
1602 flags = inc.new_flags;
1603 // the below is just to cover a newly-upgraded luminous mon
1604 // cluster that has to set require_jewel_osds or
1605 // require_kraken_osds before the osds can be upgraded to
1606 // luminous.
1607 if (flags & CEPH_OSDMAP_REQUIRE_KRAKEN) {
1608 if (require_osd_release < CEPH_RELEASE_KRAKEN) {
1609 require_osd_release = CEPH_RELEASE_KRAKEN;
1610 }
1611 } else if (flags & CEPH_OSDMAP_REQUIRE_JEWEL) {
1612 if (require_osd_release < CEPH_RELEASE_JEWEL) {
1613 require_osd_release = CEPH_RELEASE_JEWEL;
1614 }
1615 }
1616 }
1617
1618 if (inc.new_max_osd >= 0)
1619 set_max_osd(inc.new_max_osd);
1620
1621 if (inc.new_pool_max != -1)
1622 pool_max = inc.new_pool_max;
1623
1624 for (const auto &pool : inc.new_pools) {
1625 pools[pool.first] = pool.second;
1626 pools[pool.first].last_change = epoch;
1627 }
1628
1629 for (const auto &pname : inc.new_pool_names) {
1630 auto pool_name_entry = pool_name.find(pname.first);
1631 if (pool_name_entry != pool_name.end()) {
1632 name_pool.erase(pool_name_entry->second);
1633 pool_name_entry->second = pname.second;
1634 } else {
1635 pool_name[pname.first] = pname.second;
1636 }
1637 name_pool[pname.second] = pname.first;
1638 }
1639
1640 for (const auto &pool : inc.old_pools) {
1641 pools.erase(pool);
1642 name_pool.erase(pool_name[pool]);
1643 pool_name.erase(pool);
1644 }
1645
1646 for (const auto &weight : inc.new_weight) {
1647 set_weight(weight.first, weight.second);
1648
1649 // if we are marking in, clear the AUTOOUT and NEW bits, and clear
1650 // xinfo old_weight.
1651 if (weight.second) {
1652 osd_state[weight.first] &= ~(CEPH_OSD_AUTOOUT | CEPH_OSD_NEW);
1653 osd_xinfo[weight.first].old_weight = 0;
1654 }
1655 }
1656
1657 for (const auto &primary_affinity : inc.new_primary_affinity) {
1658 set_primary_affinity(primary_affinity.first, primary_affinity.second);
1659 }
1660
1661 // erasure_code_profiles
1662 for (const auto &profile : inc.old_erasure_code_profiles)
1663 erasure_code_profiles.erase(profile);
1664
1665 for (const auto &profile : inc.new_erasure_code_profiles) {
1666 set_erasure_code_profile(profile.first, profile.second);
1667 }
1668
1669 // up/down
1670 for (const auto &state : inc.new_state) {
1671 const auto osd = state.first;
1672 int s = state.second ? state.second : CEPH_OSD_UP;
1673 if ((osd_state[osd] & CEPH_OSD_UP) &&
1674 (s & CEPH_OSD_UP)) {
1675 osd_info[osd].down_at = epoch;
1676 osd_xinfo[osd].down_stamp = modified;
1677 }
1678 if ((osd_state[osd] & CEPH_OSD_EXISTS) &&
1679 (s & CEPH_OSD_EXISTS)) {
1680 // osd is destroyed; clear out anything interesting.
1681 (*osd_uuid)[osd] = uuid_d();
1682 osd_info[osd] = osd_info_t();
1683 osd_xinfo[osd] = osd_xinfo_t();
1684 set_primary_affinity(osd, CEPH_OSD_DEFAULT_PRIMARY_AFFINITY);
1685 osd_addrs->client_addr[osd].reset(new entity_addr_t());
1686 osd_addrs->cluster_addr[osd].reset(new entity_addr_t());
1687 osd_addrs->hb_front_addr[osd].reset(new entity_addr_t());
1688 osd_addrs->hb_back_addr[osd].reset(new entity_addr_t());
1689 osd_state[osd] = 0;
1690 } else {
1691 osd_state[osd] ^= s;
1692 }
1693 }
1694
1695 for (const auto &client : inc.new_up_client) {
1696 osd_state[client.first] |= CEPH_OSD_EXISTS | CEPH_OSD_UP;
1697 osd_addrs->client_addr[client.first].reset(new entity_addr_t(client.second));
1698 if (inc.new_hb_back_up.empty())
1699 osd_addrs->hb_back_addr[client.first].reset(new entity_addr_t(client.second)); //this is a backward-compatibility hack
1700 else
1701 osd_addrs->hb_back_addr[client.first].reset(
1702 new entity_addr_t(inc.new_hb_back_up.find(client.first)->second));
1703 const auto j = inc.new_hb_front_up.find(client.first);
1704 if (j != inc.new_hb_front_up.end())
1705 osd_addrs->hb_front_addr[client.first].reset(new entity_addr_t(j->second));
1706 else
1707 osd_addrs->hb_front_addr[client.first].reset();
1708
1709 osd_info[client.first].up_from = epoch;
1710 }
1711
1712 for (const auto &cluster : inc.new_up_cluster)
1713 osd_addrs->cluster_addr[cluster.first].reset(new entity_addr_t(cluster.second));
1714
1715 // info
1716 for (const auto &thru : inc.new_up_thru)
1717 osd_info[thru.first].up_thru = thru.second;
1718
1719 for (const auto &interval : inc.new_last_clean_interval) {
1720 osd_info[interval.first].last_clean_begin = interval.second.first;
1721 osd_info[interval.first].last_clean_end = interval.second.second;
1722 }
1723
1724 for (const auto &lost : inc.new_lost)
1725 osd_info[lost.first].lost_at = lost.second;
1726
1727 // xinfo
1728 for (const auto &xinfo : inc.new_xinfo)
1729 osd_xinfo[xinfo.first] = xinfo.second;
1730
1731 // uuid
1732 for (const auto &uuid : inc.new_uuid)
1733 (*osd_uuid)[uuid.first] = uuid.second;
1734
1735 // pg rebuild
1736 for (const auto &pg : inc.new_pg_temp) {
1737 if (pg.second.empty())
1738 pg_temp->erase(pg.first);
1739 else
1740 pg_temp->set(pg.first, pg.second);
1741 }
1742 if (!inc.new_pg_temp.empty()) {
1743 // make sure pg_temp is efficiently stored
1744 pg_temp->rebuild();
1745 }
1746
1747 for (const auto &pg : inc.new_primary_temp) {
1748 if (pg.second == -1)
1749 primary_temp->erase(pg.first);
1750 else
1751 (*primary_temp)[pg.first] = pg.second;
1752 }
1753
1754 for (auto& p : inc.new_pg_upmap) {
1755 pg_upmap[p.first] = p.second;
1756 }
1757 for (auto& pg : inc.old_pg_upmap) {
1758 pg_upmap.erase(pg);
1759 }
1760 for (auto& p : inc.new_pg_upmap_items) {
1761 pg_upmap_items[p.first] = p.second;
1762 }
1763 for (auto& pg : inc.old_pg_upmap_items) {
1764 pg_upmap_items.erase(pg);
1765 }
1766
1767 // blacklist
1768 if (!inc.new_blacklist.empty()) {
1769 blacklist.insert(inc.new_blacklist.begin(),inc.new_blacklist.end());
1770 new_blacklist_entries = true;
1771 }
1772 for (const auto &addr : inc.old_blacklist)
1773 blacklist.erase(addr);
1774
1775 // cluster snapshot?
1776 if (inc.cluster_snapshot.length()) {
1777 cluster_snapshot = inc.cluster_snapshot;
1778 cluster_snapshot_epoch = inc.epoch;
1779 } else {
1780 cluster_snapshot.clear();
1781 cluster_snapshot_epoch = 0;
1782 }
1783
1784 if (inc.new_nearfull_ratio >= 0) {
1785 nearfull_ratio = inc.new_nearfull_ratio;
1786 }
1787 if (inc.new_backfillfull_ratio >= 0) {
1788 backfillfull_ratio = inc.new_backfillfull_ratio;
1789 }
1790 if (inc.new_full_ratio >= 0) {
1791 full_ratio = inc.new_full_ratio;
1792 }
1793 if (inc.new_require_min_compat_client > 0) {
1794 require_min_compat_client = inc.new_require_min_compat_client;
1795 }
1796 if (inc.new_require_osd_release >= 0) {
1797 require_osd_release = inc.new_require_osd_release;
1798 if (require_osd_release >= CEPH_RELEASE_LUMINOUS) {
1799 flags &= ~(CEPH_OSDMAP_LEGACY_REQUIRE_FLAGS);
1800 flags |= CEPH_OSDMAP_RECOVERY_DELETES;
1801 }
1802 }
1803
1804 // do new crush map last (after up/down stuff)
1805 if (inc.crush.length()) {
1806 bufferlist bl(inc.crush);
1807 auto blp = bl.begin();
1808 crush.reset(new CrushWrapper);
1809 crush->decode(blp);
1810 if (require_osd_release >= CEPH_RELEASE_LUMINOUS) {
1811 // only increment if this is a luminous-encoded osdmap, lest
1812 // the mon's crush_version diverge from what the osds or others
1813 // are decoding and applying on their end. if we won't encode
1814 // it in the canonical version, don't change it.
1815 ++crush_version;
1816 }
1817 }
1818
1819 calc_num_osds();
1820 _calc_up_osd_features();
1821 return 0;
1822 }
1823
1824 // mapping
1825 int OSDMap::map_to_pg(
1826 int64_t poolid,
1827 const string& name,
1828 const string& key,
1829 const string& nspace,
1830 pg_t *pg) const
1831 {
1832 // calculate ps (placement seed)
1833 const pg_pool_t *pool = get_pg_pool(poolid);
1834 if (!pool)
1835 return -ENOENT;
1836 ps_t ps;
1837 if (!key.empty())
1838 ps = pool->hash_key(key, nspace);
1839 else
1840 ps = pool->hash_key(name, nspace);
1841 *pg = pg_t(ps, poolid);
1842 return 0;
1843 }
1844
1845 int OSDMap::object_locator_to_pg(
1846 const object_t& oid, const object_locator_t& loc, pg_t &pg) const
1847 {
1848 if (loc.hash >= 0) {
1849 if (!get_pg_pool(loc.get_pool())) {
1850 return -ENOENT;
1851 }
1852 pg = pg_t(loc.hash, loc.get_pool());
1853 return 0;
1854 }
1855 return map_to_pg(loc.get_pool(), oid.name, loc.key, loc.nspace, &pg);
1856 }
1857
1858 ceph_object_layout OSDMap::make_object_layout(
1859 object_t oid, int pg_pool, string nspace) const
1860 {
1861 object_locator_t loc(pg_pool, nspace);
1862
1863 ceph_object_layout ol;
1864 pg_t pgid = object_locator_to_pg(oid, loc);
1865 ol.ol_pgid = pgid.get_old_pg().v;
1866 ol.ol_stripe_unit = 0;
1867 return ol;
1868 }
1869
1870 void OSDMap::_remove_nonexistent_osds(const pg_pool_t& pool,
1871 vector<int>& osds) const
1872 {
1873 if (pool.can_shift_osds()) {
1874 unsigned removed = 0;
1875 for (unsigned i = 0; i < osds.size(); i++) {
1876 if (!exists(osds[i])) {
1877 removed++;
1878 continue;
1879 }
1880 if (removed) {
1881 osds[i - removed] = osds[i];
1882 }
1883 }
1884 if (removed)
1885 osds.resize(osds.size() - removed);
1886 } else {
1887 for (auto& osd : osds) {
1888 if (!exists(osd))
1889 osd = CRUSH_ITEM_NONE;
1890 }
1891 }
1892 }
1893
1894 void OSDMap::_pg_to_raw_osds(
1895 const pg_pool_t& pool, pg_t pg,
1896 vector<int> *osds,
1897 ps_t *ppps) const
1898 {
1899 // map to osds[]
1900 ps_t pps = pool.raw_pg_to_pps(pg); // placement ps
1901 unsigned size = pool.get_size();
1902
1903 // what crush rule?
1904 int ruleno = crush->find_rule(pool.get_crush_rule(), pool.get_type(), size);
1905 if (ruleno >= 0)
1906 crush->do_rule(ruleno, pps, *osds, size, osd_weight, pg.pool());
1907
1908 _remove_nonexistent_osds(pool, *osds);
1909
1910 if (ppps)
1911 *ppps = pps;
1912 }
1913
1914 int OSDMap::_pick_primary(const vector<int>& osds) const
1915 {
1916 for (auto osd : osds) {
1917 if (osd != CRUSH_ITEM_NONE) {
1918 return osd;
1919 }
1920 }
1921 return -1;
1922 }
1923
1924 void OSDMap::_apply_upmap(const pg_pool_t& pi, pg_t raw_pg, vector<int> *raw) const
1925 {
1926 pg_t pg = pi.raw_pg_to_pg(raw_pg);
1927 auto p = pg_upmap.find(pg);
1928 if (p != pg_upmap.end()) {
1929 // make sure targets aren't marked out
1930 for (auto osd : p->second) {
1931 if (osd != CRUSH_ITEM_NONE && osd < max_osd && osd_weight[osd] == 0) {
1932 // reject/ignore the explicit mapping
1933 return;
1934 }
1935 }
1936 *raw = vector<int>(p->second.begin(), p->second.end());
1937 // continue to check and apply pg_upmap_items if any
1938 }
1939
1940 auto q = pg_upmap_items.find(pg);
1941 if (q != pg_upmap_items.end()) {
1942 for (auto& i : *raw) {
1943 for (auto& r : q->second) {
1944 if (r.first != i) {
1945 continue;
1946 }
1947 if (!(r.second != CRUSH_ITEM_NONE &&
1948 r.second < max_osd &&
1949 osd_weight[r.second] == 0)) {
1950 i = r.second;
1951 }
1952 break;
1953 }
1954 }
1955 }
1956 }
1957
1958 // pg -> (up osd list)
1959 void OSDMap::_raw_to_up_osds(const pg_pool_t& pool, const vector<int>& raw,
1960 vector<int> *up) const
1961 {
1962 if (pool.can_shift_osds()) {
1963 // shift left
1964 up->clear();
1965 up->reserve(raw.size());
1966 for (unsigned i=0; i<raw.size(); i++) {
1967 if (!exists(raw[i]) || is_down(raw[i]))
1968 continue;
1969 up->push_back(raw[i]);
1970 }
1971 } else {
1972 // set down/dne devices to NONE
1973 up->resize(raw.size());
1974 for (int i = raw.size() - 1; i >= 0; --i) {
1975 if (!exists(raw[i]) || is_down(raw[i])) {
1976 (*up)[i] = CRUSH_ITEM_NONE;
1977 } else {
1978 (*up)[i] = raw[i];
1979 }
1980 }
1981 }
1982 }
1983
1984 void OSDMap::_apply_primary_affinity(ps_t seed,
1985 const pg_pool_t& pool,
1986 vector<int> *osds,
1987 int *primary) const
1988 {
1989 // do we have any non-default primary_affinity values for these osds?
1990 if (!osd_primary_affinity)
1991 return;
1992
1993 bool any = false;
1994 for (const auto osd : *osds) {
1995 if (osd != CRUSH_ITEM_NONE &&
1996 (*osd_primary_affinity)[osd] != CEPH_OSD_DEFAULT_PRIMARY_AFFINITY) {
1997 any = true;
1998 break;
1999 }
2000 }
2001 if (!any)
2002 return;
2003
2004 // pick the primary. feed both the seed (for the pg) and the osd
2005 // into the hash/rng so that a proportional fraction of an osd's pgs
2006 // get rejected as primary.
2007 int pos = -1;
2008 for (unsigned i = 0; i < osds->size(); ++i) {
2009 int o = (*osds)[i];
2010 if (o == CRUSH_ITEM_NONE)
2011 continue;
2012 unsigned a = (*osd_primary_affinity)[o];
2013 if (a < CEPH_OSD_MAX_PRIMARY_AFFINITY &&
2014 (crush_hash32_2(CRUSH_HASH_RJENKINS1,
2015 seed, o) >> 16) >= a) {
2016 // we chose not to use this primary. note it anyway as a
2017 // fallback in case we don't pick anyone else, but keep looking.
2018 if (pos < 0)
2019 pos = i;
2020 } else {
2021 pos = i;
2022 break;
2023 }
2024 }
2025 if (pos < 0)
2026 return;
2027
2028 *primary = (*osds)[pos];
2029
2030 if (pool.can_shift_osds() && pos > 0) {
2031 // move the new primary to the front.
2032 for (int i = pos; i > 0; --i) {
2033 (*osds)[i] = (*osds)[i-1];
2034 }
2035 (*osds)[0] = *primary;
2036 }
2037 }
2038
2039 void OSDMap::_get_temp_osds(const pg_pool_t& pool, pg_t pg,
2040 vector<int> *temp_pg, int *temp_primary) const
2041 {
2042 pg = pool.raw_pg_to_pg(pg);
2043 const auto p = pg_temp->find(pg);
2044 temp_pg->clear();
2045 if (p != pg_temp->end()) {
2046 for (unsigned i=0; i<p->second.size(); i++) {
2047 if (!exists(p->second[i]) || is_down(p->second[i])) {
2048 if (pool.can_shift_osds()) {
2049 continue;
2050 } else {
2051 temp_pg->push_back(CRUSH_ITEM_NONE);
2052 }
2053 } else {
2054 temp_pg->push_back(p->second[i]);
2055 }
2056 }
2057 }
2058 const auto &pp = primary_temp->find(pg);
2059 *temp_primary = -1;
2060 if (pp != primary_temp->end()) {
2061 *temp_primary = pp->second;
2062 } else if (!temp_pg->empty()) { // apply pg_temp's primary
2063 for (unsigned i = 0; i < temp_pg->size(); ++i) {
2064 if ((*temp_pg)[i] != CRUSH_ITEM_NONE) {
2065 *temp_primary = (*temp_pg)[i];
2066 break;
2067 }
2068 }
2069 }
2070 }
2071
2072 void OSDMap::pg_to_raw_osds(pg_t pg, vector<int> *raw, int *primary) const
2073 {
2074 *primary = -1;
2075 raw->clear();
2076 const pg_pool_t *pool = get_pg_pool(pg.pool());
2077 if (!pool)
2078 return;
2079 _pg_to_raw_osds(*pool, pg, raw, NULL);
2080 if (primary)
2081 *primary = _pick_primary(*raw);
2082 }
2083
2084 void OSDMap::pg_to_raw_up(pg_t pg, vector<int> *up, int *primary) const
2085 {
2086 const pg_pool_t *pool = get_pg_pool(pg.pool());
2087 if (!pool) {
2088 if (primary)
2089 *primary = -1;
2090 if (up)
2091 up->clear();
2092 return;
2093 }
2094 vector<int> raw;
2095 ps_t pps;
2096 _pg_to_raw_osds(*pool, pg, &raw, &pps);
2097 _apply_upmap(*pool, pg, &raw);
2098 _raw_to_up_osds(*pool, raw, up);
2099 *primary = _pick_primary(raw);
2100 _apply_primary_affinity(pps, *pool, up, primary);
2101 }
2102
2103 void OSDMap::_pg_to_up_acting_osds(
2104 const pg_t& pg, vector<int> *up, int *up_primary,
2105 vector<int> *acting, int *acting_primary,
2106 bool raw_pg_to_pg) const
2107 {
2108 const pg_pool_t *pool = get_pg_pool(pg.pool());
2109 if (!pool ||
2110 (!raw_pg_to_pg && pg.ps() >= pool->get_pg_num())) {
2111 if (up)
2112 up->clear();
2113 if (up_primary)
2114 *up_primary = -1;
2115 if (acting)
2116 acting->clear();
2117 if (acting_primary)
2118 *acting_primary = -1;
2119 return;
2120 }
2121 vector<int> raw;
2122 vector<int> _up;
2123 vector<int> _acting;
2124 int _up_primary;
2125 int _acting_primary;
2126 ps_t pps;
2127 _get_temp_osds(*pool, pg, &_acting, &_acting_primary);
2128 if (_acting.empty() || up || up_primary) {
2129 _pg_to_raw_osds(*pool, pg, &raw, &pps);
2130 _apply_upmap(*pool, pg, &raw);
2131 _raw_to_up_osds(*pool, raw, &_up);
2132 _up_primary = _pick_primary(_up);
2133 _apply_primary_affinity(pps, *pool, &_up, &_up_primary);
2134 if (_acting.empty()) {
2135 _acting = _up;
2136 if (_acting_primary == -1) {
2137 _acting_primary = _up_primary;
2138 }
2139 }
2140
2141 if (up)
2142 up->swap(_up);
2143 if (up_primary)
2144 *up_primary = _up_primary;
2145 }
2146
2147 if (acting)
2148 acting->swap(_acting);
2149 if (acting_primary)
2150 *acting_primary = _acting_primary;
2151 }
2152
2153 int OSDMap::calc_pg_rank(int osd, const vector<int>& acting, int nrep)
2154 {
2155 if (!nrep)
2156 nrep = acting.size();
2157 for (int i=0; i<nrep; i++)
2158 if (acting[i] == osd)
2159 return i;
2160 return -1;
2161 }
2162
2163 int OSDMap::calc_pg_role(int osd, const vector<int>& acting, int nrep)
2164 {
2165 return calc_pg_rank(osd, acting, nrep);
2166 }
2167
2168 bool OSDMap::primary_changed(
2169 int oldprimary,
2170 const vector<int> &oldacting,
2171 int newprimary,
2172 const vector<int> &newacting)
2173 {
2174 if (oldacting.empty() && newacting.empty())
2175 return false; // both still empty
2176 if (oldacting.empty() ^ newacting.empty())
2177 return true; // was empty, now not, or vice versa
2178 if (oldprimary != newprimary)
2179 return true; // primary changed
2180 if (calc_pg_rank(oldprimary, oldacting) !=
2181 calc_pg_rank(newprimary, newacting))
2182 return true;
2183 return false; // same primary (tho replicas may have changed)
2184 }
2185
2186
2187 // serialize, unserialize
2188 void OSDMap::encode_client_old(bufferlist& bl) const
2189 {
2190 __u16 v = 5;
2191 ::encode(v, bl);
2192
2193 // base
2194 ::encode(fsid, bl);
2195 ::encode(epoch, bl);
2196 ::encode(created, bl);
2197 ::encode(modified, bl);
2198
2199 // for ::encode(pools, bl);
2200 __u32 n = pools.size();
2201 ::encode(n, bl);
2202
2203 for (const auto &pool : pools) {
2204 n = pool.first;
2205 ::encode(n, bl);
2206 ::encode(pool.second, bl, 0);
2207 }
2208 // for ::encode(pool_name, bl);
2209 n = pool_name.size();
2210 ::encode(n, bl);
2211 for (const auto &pname : pool_name) {
2212 n = pname.first;
2213 ::encode(n, bl);
2214 ::encode(pname.second, bl);
2215 }
2216 // for ::encode(pool_max, bl);
2217 n = pool_max;
2218 ::encode(n, bl);
2219
2220 ::encode(flags, bl);
2221
2222 ::encode(max_osd, bl);
2223 {
2224 uint32_t n = osd_state.size();
2225 ::encode(n, bl);
2226 for (auto s : osd_state) {
2227 ::encode((uint8_t)s, bl);
2228 }
2229 }
2230 ::encode(osd_weight, bl);
2231 ::encode(osd_addrs->client_addr, bl, 0);
2232
2233 // for ::encode(pg_temp, bl);
2234 n = pg_temp->size();
2235 ::encode(n, bl);
2236 for (const auto pg : *pg_temp) {
2237 old_pg_t opg = pg.first.get_old_pg();
2238 ::encode(opg, bl);
2239 ::encode(pg.second, bl);
2240 }
2241
2242 // crush
2243 bufferlist cbl;
2244 crush->encode(cbl, 0 /* legacy (no) features */);
2245 ::encode(cbl, bl);
2246 }
2247
2248 void OSDMap::encode_classic(bufferlist& bl, uint64_t features) const
2249 {
2250 if ((features & CEPH_FEATURE_PGID64) == 0) {
2251 encode_client_old(bl);
2252 return;
2253 }
2254
2255 __u16 v = 6;
2256 ::encode(v, bl);
2257
2258 // base
2259 ::encode(fsid, bl);
2260 ::encode(epoch, bl);
2261 ::encode(created, bl);
2262 ::encode(modified, bl);
2263
2264 ::encode(pools, bl, features);
2265 ::encode(pool_name, bl);
2266 ::encode(pool_max, bl);
2267
2268 ::encode(flags, bl);
2269
2270 ::encode(max_osd, bl);
2271 {
2272 uint32_t n = osd_state.size();
2273 ::encode(n, bl);
2274 for (auto s : osd_state) {
2275 ::encode((uint8_t)s, bl);
2276 }
2277 }
2278 ::encode(osd_weight, bl);
2279 ::encode(osd_addrs->client_addr, bl, features);
2280
2281 ::encode(*pg_temp, bl);
2282
2283 // crush
2284 bufferlist cbl;
2285 crush->encode(cbl, 0 /* legacy (no) features */);
2286 ::encode(cbl, bl);
2287
2288 // extended
2289 __u16 ev = 10;
2290 ::encode(ev, bl);
2291 ::encode(osd_addrs->hb_back_addr, bl, features);
2292 ::encode(osd_info, bl);
2293 ::encode(blacklist, bl, features);
2294 ::encode(osd_addrs->cluster_addr, bl, features);
2295 ::encode(cluster_snapshot_epoch, bl);
2296 ::encode(cluster_snapshot, bl);
2297 ::encode(*osd_uuid, bl);
2298 ::encode(osd_xinfo, bl);
2299 ::encode(osd_addrs->hb_front_addr, bl, features);
2300 }
2301
2302 void OSDMap::encode(bufferlist& bl, uint64_t features) const
2303 {
2304 if ((features & CEPH_FEATURE_OSDMAP_ENC) == 0) {
2305 encode_classic(bl, features);
2306 return;
2307 }
2308
2309 // only a select set of callers should *ever* be encoding new
2310 // OSDMaps. others should be passing around the canonical encoded
2311 // buffers from on high. select out those callers by passing in an
2312 // "impossible" feature bit.
2313 assert(features & CEPH_FEATURE_RESERVED);
2314 features &= ~CEPH_FEATURE_RESERVED;
2315
2316 size_t start_offset = bl.length();
2317 size_t tail_offset;
2318 buffer::list::iterator crc_it;
2319
2320 // meta-encoding: how we include client-used and osd-specific data
2321 ENCODE_START(8, 7, bl);
2322
2323 {
2324 uint8_t v = 6;
2325 if (!HAVE_FEATURE(features, SERVER_LUMINOUS)) {
2326 v = 3;
2327 }
2328 ENCODE_START(v, 1, bl); // client-usable data
2329 // base
2330 ::encode(fsid, bl);
2331 ::encode(epoch, bl);
2332 ::encode(created, bl);
2333 ::encode(modified, bl);
2334
2335 ::encode(pools, bl, features);
2336 ::encode(pool_name, bl);
2337 ::encode(pool_max, bl);
2338
2339 if (v < 4) {
2340 decltype(flags) f = flags;
2341 if (require_osd_release >= CEPH_RELEASE_LUMINOUS)
2342 f |= CEPH_OSDMAP_REQUIRE_LUMINOUS | CEPH_OSDMAP_RECOVERY_DELETES;
2343 else if (require_osd_release == CEPH_RELEASE_KRAKEN)
2344 f |= CEPH_OSDMAP_REQUIRE_KRAKEN;
2345 else if (require_osd_release == CEPH_RELEASE_JEWEL)
2346 f |= CEPH_OSDMAP_REQUIRE_JEWEL;
2347 ::encode(f, bl);
2348 } else {
2349 ::encode(flags, bl);
2350 }
2351
2352 ::encode(max_osd, bl);
2353 if (v >= 5) {
2354 ::encode(osd_state, bl);
2355 } else {
2356 uint32_t n = osd_state.size();
2357 ::encode(n, bl);
2358 for (auto s : osd_state) {
2359 ::encode((uint8_t)s, bl);
2360 }
2361 }
2362 ::encode(osd_weight, bl);
2363 ::encode(osd_addrs->client_addr, bl, features);
2364
2365 ::encode(*pg_temp, bl);
2366 ::encode(*primary_temp, bl);
2367 if (osd_primary_affinity) {
2368 ::encode(*osd_primary_affinity, bl);
2369 } else {
2370 vector<__u32> v;
2371 ::encode(v, bl);
2372 }
2373
2374 // crush
2375 bufferlist cbl;
2376 crush->encode(cbl, features);
2377 ::encode(cbl, bl);
2378 ::encode(erasure_code_profiles, bl);
2379
2380 if (v >= 4) {
2381 ::encode(pg_upmap, bl);
2382 ::encode(pg_upmap_items, bl);
2383 } else {
2384 assert(pg_upmap.empty());
2385 assert(pg_upmap_items.empty());
2386 }
2387 if (v >= 6) {
2388 ::encode(crush_version, bl);
2389 }
2390 ENCODE_FINISH(bl); // client-usable data
2391 }
2392
2393 {
2394 uint8_t target_v = 5;
2395 if (!HAVE_FEATURE(features, SERVER_LUMINOUS)) {
2396 target_v = 1;
2397 }
2398 ENCODE_START(target_v, 1, bl); // extended, osd-only data
2399 ::encode(osd_addrs->hb_back_addr, bl, features);
2400 ::encode(osd_info, bl);
2401 {
2402 // put this in a sorted, ordered map<> so that we encode in a
2403 // deterministic order.
2404 map<entity_addr_t,utime_t> blacklist_map;
2405 for (const auto &addr : blacklist)
2406 blacklist_map.insert(make_pair(addr.first, addr.second));
2407 ::encode(blacklist_map, bl, features);
2408 }
2409 ::encode(osd_addrs->cluster_addr, bl, features);
2410 ::encode(cluster_snapshot_epoch, bl);
2411 ::encode(cluster_snapshot, bl);
2412 ::encode(*osd_uuid, bl);
2413 ::encode(osd_xinfo, bl);
2414 ::encode(osd_addrs->hb_front_addr, bl, features);
2415 if (target_v >= 2) {
2416 ::encode(nearfull_ratio, bl);
2417 ::encode(full_ratio, bl);
2418 ::encode(backfillfull_ratio, bl);
2419 }
2420 // 4 was string-based new_require_min_compat_client
2421 if (target_v >= 5) {
2422 ::encode(require_min_compat_client, bl);
2423 ::encode(require_osd_release, bl);
2424 }
2425 ENCODE_FINISH(bl); // osd-only data
2426 }
2427
2428 ::encode((uint32_t)0, bl); // dummy crc
2429 crc_it = bl.end();
2430 crc_it.advance(-4);
2431 tail_offset = bl.length();
2432
2433 ENCODE_FINISH(bl); // meta-encoding wrapper
2434
2435 // fill in crc
2436 bufferlist front;
2437 front.substr_of(bl, start_offset, crc_it.get_off() - start_offset);
2438 crc = front.crc32c(-1);
2439 if (tail_offset < bl.length()) {
2440 bufferlist tail;
2441 tail.substr_of(bl, tail_offset, bl.length() - tail_offset);
2442 crc = tail.crc32c(crc);
2443 }
2444 ceph_le32 crc_le;
2445 crc_le = crc;
2446 crc_it.copy_in(4, (char*)&crc_le);
2447 crc_defined = true;
2448 }
2449
2450 void OSDMap::decode(bufferlist& bl)
2451 {
2452 auto p = bl.begin();
2453 decode(p);
2454 }
2455
2456 void OSDMap::decode_classic(bufferlist::iterator& p)
2457 {
2458 __u32 n, t;
2459 __u16 v;
2460 ::decode(v, p);
2461
2462 // base
2463 ::decode(fsid, p);
2464 ::decode(epoch, p);
2465 ::decode(created, p);
2466 ::decode(modified, p);
2467
2468 if (v < 6) {
2469 if (v < 4) {
2470 int32_t max_pools = 0;
2471 ::decode(max_pools, p);
2472 pool_max = max_pools;
2473 }
2474 pools.clear();
2475 ::decode(n, p);
2476 while (n--) {
2477 ::decode(t, p);
2478 ::decode(pools[t], p);
2479 }
2480 if (v == 4) {
2481 ::decode(n, p);
2482 pool_max = n;
2483 } else if (v == 5) {
2484 pool_name.clear();
2485 ::decode(n, p);
2486 while (n--) {
2487 ::decode(t, p);
2488 ::decode(pool_name[t], p);
2489 }
2490 ::decode(n, p);
2491 pool_max = n;
2492 }
2493 } else {
2494 ::decode(pools, p);
2495 ::decode(pool_name, p);
2496 ::decode(pool_max, p);
2497 }
2498 // kludge around some old bug that zeroed out pool_max (#2307)
2499 if (pools.size() && pool_max < pools.rbegin()->first) {
2500 pool_max = pools.rbegin()->first;
2501 }
2502
2503 ::decode(flags, p);
2504
2505 ::decode(max_osd, p);
2506 {
2507 vector<uint8_t> os;
2508 ::decode(os, p);
2509 osd_state.resize(os.size());
2510 for (unsigned i = 0; i < os.size(); ++i) {
2511 osd_state[i] = os[i];
2512 }
2513 }
2514 ::decode(osd_weight, p);
2515 ::decode(osd_addrs->client_addr, p);
2516 if (v <= 5) {
2517 pg_temp->clear();
2518 ::decode(n, p);
2519 while (n--) {
2520 old_pg_t opg;
2521 ::decode_raw(opg, p);
2522 mempool::osdmap::vector<int32_t> v;
2523 ::decode(v, p);
2524 pg_temp->set(pg_t(opg), v);
2525 }
2526 } else {
2527 ::decode(*pg_temp, p);
2528 }
2529
2530 // crush
2531 bufferlist cbl;
2532 ::decode(cbl, p);
2533 auto cblp = cbl.begin();
2534 crush->decode(cblp);
2535
2536 // extended
2537 __u16 ev = 0;
2538 if (v >= 5)
2539 ::decode(ev, p);
2540 ::decode(osd_addrs->hb_back_addr, p);
2541 ::decode(osd_info, p);
2542 if (v < 5)
2543 ::decode(pool_name, p);
2544
2545 ::decode(blacklist, p);
2546 if (ev >= 6)
2547 ::decode(osd_addrs->cluster_addr, p);
2548 else
2549 osd_addrs->cluster_addr.resize(osd_addrs->client_addr.size());
2550
2551 if (ev >= 7) {
2552 ::decode(cluster_snapshot_epoch, p);
2553 ::decode(cluster_snapshot, p);
2554 }
2555
2556 if (ev >= 8) {
2557 ::decode(*osd_uuid, p);
2558 } else {
2559 osd_uuid->resize(max_osd);
2560 }
2561 if (ev >= 9)
2562 ::decode(osd_xinfo, p);
2563 else
2564 osd_xinfo.resize(max_osd);
2565
2566 if (ev >= 10)
2567 ::decode(osd_addrs->hb_front_addr, p);
2568 else
2569 osd_addrs->hb_front_addr.resize(osd_addrs->hb_back_addr.size());
2570
2571 osd_primary_affinity.reset();
2572
2573 post_decode();
2574 }
2575
2576 void OSDMap::decode(bufferlist::iterator& bl)
2577 {
2578 /**
2579 * Older encodings of the OSDMap had a single struct_v which
2580 * covered the whole encoding, and was prior to our modern
2581 * stuff which includes a compatv and a size. So if we see
2582 * a struct_v < 7, we must rewind to the beginning and use our
2583 * classic decoder.
2584 */
2585 size_t start_offset = bl.get_off();
2586 size_t tail_offset = 0;
2587 bufferlist crc_front, crc_tail;
2588
2589 DECODE_START_LEGACY_COMPAT_LEN(8, 7, 7, bl); // wrapper
2590 if (struct_v < 7) {
2591 int struct_v_size = sizeof(struct_v);
2592 bl.advance(-struct_v_size);
2593 decode_classic(bl);
2594 return;
2595 }
2596 /**
2597 * Since we made it past that hurdle, we can use our normal paths.
2598 */
2599 {
2600 DECODE_START(6, bl); // client-usable data
2601 // base
2602 ::decode(fsid, bl);
2603 ::decode(epoch, bl);
2604 ::decode(created, bl);
2605 ::decode(modified, bl);
2606
2607 ::decode(pools, bl);
2608 ::decode(pool_name, bl);
2609 ::decode(pool_max, bl);
2610
2611 ::decode(flags, bl);
2612
2613 ::decode(max_osd, bl);
2614 if (struct_v >= 5) {
2615 ::decode(osd_state, bl);
2616 } else {
2617 vector<uint8_t> os;
2618 ::decode(os, bl);
2619 osd_state.resize(os.size());
2620 for (unsigned i = 0; i < os.size(); ++i) {
2621 osd_state[i] = os[i];
2622 }
2623 }
2624 ::decode(osd_weight, bl);
2625 ::decode(osd_addrs->client_addr, bl);
2626
2627 ::decode(*pg_temp, bl);
2628 ::decode(*primary_temp, bl);
2629 if (struct_v >= 2) {
2630 osd_primary_affinity.reset(new mempool::osdmap::vector<__u32>);
2631 ::decode(*osd_primary_affinity, bl);
2632 if (osd_primary_affinity->empty())
2633 osd_primary_affinity.reset();
2634 } else {
2635 osd_primary_affinity.reset();
2636 }
2637
2638 // crush
2639 bufferlist cbl;
2640 ::decode(cbl, bl);
2641 auto cblp = cbl.begin();
2642 crush->decode(cblp);
2643 if (struct_v >= 3) {
2644 ::decode(erasure_code_profiles, bl);
2645 } else {
2646 erasure_code_profiles.clear();
2647 }
2648 if (struct_v >= 4) {
2649 ::decode(pg_upmap, bl);
2650 ::decode(pg_upmap_items, bl);
2651 } else {
2652 pg_upmap.clear();
2653 pg_upmap_items.clear();
2654 }
2655 if (struct_v >= 6) {
2656 ::decode(crush_version, bl);
2657 }
2658 DECODE_FINISH(bl); // client-usable data
2659 }
2660
2661 {
2662 DECODE_START(5, bl); // extended, osd-only data
2663 ::decode(osd_addrs->hb_back_addr, bl);
2664 ::decode(osd_info, bl);
2665 ::decode(blacklist, bl);
2666 ::decode(osd_addrs->cluster_addr, bl);
2667 ::decode(cluster_snapshot_epoch, bl);
2668 ::decode(cluster_snapshot, bl);
2669 ::decode(*osd_uuid, bl);
2670 ::decode(osd_xinfo, bl);
2671 ::decode(osd_addrs->hb_front_addr, bl);
2672 if (struct_v >= 2) {
2673 ::decode(nearfull_ratio, bl);
2674 ::decode(full_ratio, bl);
2675 } else {
2676 nearfull_ratio = 0;
2677 full_ratio = 0;
2678 }
2679 if (struct_v >= 3) {
2680 ::decode(backfillfull_ratio, bl);
2681 } else {
2682 backfillfull_ratio = 0;
2683 }
2684 if (struct_v == 4) {
2685 string r;
2686 ::decode(r, bl);
2687 if (r.length())
2688 require_min_compat_client = ceph_release_from_name(r.c_str());
2689 }
2690 if (struct_v >= 5) {
2691 ::decode(require_min_compat_client, bl);
2692 ::decode(require_osd_release, bl);
2693 if (require_osd_release >= CEPH_RELEASE_LUMINOUS) {
2694 flags &= ~(CEPH_OSDMAP_LEGACY_REQUIRE_FLAGS);
2695 flags |= CEPH_OSDMAP_RECOVERY_DELETES;
2696 }
2697 } else {
2698 if (flags & CEPH_OSDMAP_REQUIRE_LUMINOUS) {
2699 // only for compat with post-kraken pre-luminous test clusters
2700 require_osd_release = CEPH_RELEASE_LUMINOUS;
2701 flags &= ~(CEPH_OSDMAP_LEGACY_REQUIRE_FLAGS);
2702 flags |= CEPH_OSDMAP_RECOVERY_DELETES;
2703 } else if (flags & CEPH_OSDMAP_REQUIRE_KRAKEN) {
2704 require_osd_release = CEPH_RELEASE_KRAKEN;
2705 } else if (flags & CEPH_OSDMAP_REQUIRE_JEWEL) {
2706 require_osd_release = CEPH_RELEASE_JEWEL;
2707 } else {
2708 require_osd_release = 0;
2709 }
2710 }
2711 DECODE_FINISH(bl); // osd-only data
2712 }
2713
2714 if (struct_v >= 8) {
2715 crc_front.substr_of(bl.get_bl(), start_offset, bl.get_off() - start_offset);
2716 ::decode(crc, bl);
2717 tail_offset = bl.get_off();
2718 crc_defined = true;
2719 } else {
2720 crc_defined = false;
2721 crc = 0;
2722 }
2723
2724 DECODE_FINISH(bl); // wrapper
2725
2726 if (tail_offset) {
2727 // verify crc
2728 uint32_t actual = crc_front.crc32c(-1);
2729 if (tail_offset < bl.get_off()) {
2730 bufferlist tail;
2731 tail.substr_of(bl.get_bl(), tail_offset, bl.get_off() - tail_offset);
2732 actual = tail.crc32c(actual);
2733 }
2734 if (crc != actual) {
2735 ostringstream ss;
2736 ss << "bad crc, actual " << actual << " != expected " << crc;
2737 string s = ss.str();
2738 throw buffer::malformed_input(s.c_str());
2739 }
2740 }
2741
2742 post_decode();
2743 }
2744
2745 void OSDMap::post_decode()
2746 {
2747 // index pool names
2748 name_pool.clear();
2749 for (const auto &pname : pool_name) {
2750 name_pool[pname.second] = pname.first;
2751 }
2752
2753 calc_num_osds();
2754 _calc_up_osd_features();
2755 }
2756
2757 void OSDMap::dump_erasure_code_profiles(
2758 const mempool::osdmap::map<string,map<string,string>>& profiles,
2759 Formatter *f)
2760 {
2761 f->open_object_section("erasure_code_profiles");
2762 for (const auto &profile : profiles) {
2763 f->open_object_section(profile.first.c_str());
2764 for (const auto &profm : profile.second) {
2765 f->dump_string(profm.first.c_str(), profm.second.c_str());
2766 }
2767 f->close_section();
2768 }
2769 f->close_section();
2770 }
2771
2772 void OSDMap::dump(Formatter *f) const
2773 {
2774 f->dump_int("epoch", get_epoch());
2775 f->dump_stream("fsid") << get_fsid();
2776 f->dump_stream("created") << get_created();
2777 f->dump_stream("modified") << get_modified();
2778 f->dump_string("flags", get_flag_string());
2779 f->dump_unsigned("crush_version", get_crush_version());
2780 f->dump_float("full_ratio", full_ratio);
2781 f->dump_float("backfillfull_ratio", backfillfull_ratio);
2782 f->dump_float("nearfull_ratio", nearfull_ratio);
2783 f->dump_string("cluster_snapshot", get_cluster_snapshot());
2784 f->dump_int("pool_max", get_pool_max());
2785 f->dump_int("max_osd", get_max_osd());
2786 f->dump_string("require_min_compat_client",
2787 ceph_release_name(require_min_compat_client));
2788 f->dump_string("min_compat_client",
2789 ceph_release_name(get_min_compat_client()));
2790 f->dump_string("require_osd_release",
2791 ceph_release_name(require_osd_release));
2792
2793 f->open_array_section("pools");
2794 for (const auto &pool : pools) {
2795 std::string name("<unknown>");
2796 const auto &pni = pool_name.find(pool.first);
2797 if (pni != pool_name.end())
2798 name = pni->second;
2799 f->open_object_section("pool");
2800 f->dump_int("pool", pool.first);
2801 f->dump_string("pool_name", name);
2802 pool.second.dump(f);
2803 f->close_section();
2804 }
2805 f->close_section();
2806
2807 f->open_array_section("osds");
2808 for (int i=0; i<get_max_osd(); i++)
2809 if (exists(i)) {
2810 f->open_object_section("osd_info");
2811 f->dump_int("osd", i);
2812 f->dump_stream("uuid") << get_uuid(i);
2813 f->dump_int("up", is_up(i));
2814 f->dump_int("in", is_in(i));
2815 f->dump_float("weight", get_weightf(i));
2816 f->dump_float("primary_affinity", get_primary_affinityf(i));
2817 get_info(i).dump(f);
2818 f->dump_stream("public_addr") << get_addr(i);
2819 f->dump_stream("cluster_addr") << get_cluster_addr(i);
2820 f->dump_stream("heartbeat_back_addr") << get_hb_back_addr(i);
2821 f->dump_stream("heartbeat_front_addr") << get_hb_front_addr(i);
2822
2823 set<string> st;
2824 get_state(i, st);
2825 f->open_array_section("state");
2826 for (const auto &state : st)
2827 f->dump_string("state", state);
2828 f->close_section();
2829
2830 f->close_section();
2831 }
2832 f->close_section();
2833
2834 f->open_array_section("osd_xinfo");
2835 for (int i=0; i<get_max_osd(); i++) {
2836 if (exists(i)) {
2837 f->open_object_section("xinfo");
2838 f->dump_int("osd", i);
2839 osd_xinfo[i].dump(f);
2840 f->close_section();
2841 }
2842 }
2843 f->close_section();
2844
2845 f->open_array_section("pg_upmap");
2846 for (auto& p : pg_upmap) {
2847 f->open_object_section("mapping");
2848 f->dump_stream("pgid") << p.first;
2849 f->open_array_section("osds");
2850 for (auto q : p.second) {
2851 f->dump_int("osd", q);
2852 }
2853 f->close_section();
2854 f->close_section();
2855 }
2856 f->close_section();
2857 f->open_array_section("pg_upmap_items");
2858 for (auto& p : pg_upmap_items) {
2859 f->open_object_section("mapping");
2860 f->dump_stream("pgid") << p.first;
2861 f->open_array_section("mappings");
2862 for (auto& q : p.second) {
2863 f->open_object_section("mapping");
2864 f->dump_int("from", q.first);
2865 f->dump_int("to", q.second);
2866 f->close_section();
2867 }
2868 f->close_section();
2869 f->close_section();
2870 }
2871 f->close_section();
2872 f->open_array_section("pg_temp");
2873 pg_temp->dump(f);
2874 f->close_section();
2875
2876 f->open_array_section("primary_temp");
2877 for (const auto &pg : *primary_temp) {
2878 f->dump_stream("pgid") << pg.first;
2879 f->dump_int("osd", pg.second);
2880 }
2881 f->close_section(); // primary_temp
2882
2883 f->open_object_section("blacklist");
2884 for (const auto &addr : blacklist) {
2885 stringstream ss;
2886 ss << addr.first;
2887 f->dump_stream(ss.str().c_str()) << addr.second;
2888 }
2889 f->close_section();
2890
2891 dump_erasure_code_profiles(erasure_code_profiles, f);
2892 }
2893
2894 void OSDMap::generate_test_instances(list<OSDMap*>& o)
2895 {
2896 o.push_back(new OSDMap);
2897
2898 CephContext *cct = new CephContext(CODE_ENVIRONMENT_UTILITY);
2899 o.push_back(new OSDMap);
2900 uuid_d fsid;
2901 o.back()->build_simple(cct, 1, fsid, 16);
2902 o.back()->created = o.back()->modified = utime_t(1, 2); // fix timestamp
2903 o.back()->blacklist[entity_addr_t()] = utime_t(5, 6);
2904 cct->put();
2905 }
2906
2907 string OSDMap::get_flag_string(unsigned f)
2908 {
2909 string s;
2910 if ( f& CEPH_OSDMAP_NEARFULL)
2911 s += ",nearfull";
2912 if (f & CEPH_OSDMAP_FULL)
2913 s += ",full";
2914 if (f & CEPH_OSDMAP_PAUSERD)
2915 s += ",pauserd";
2916 if (f & CEPH_OSDMAP_PAUSEWR)
2917 s += ",pausewr";
2918 if (f & CEPH_OSDMAP_PAUSEREC)
2919 s += ",pauserec";
2920 if (f & CEPH_OSDMAP_NOUP)
2921 s += ",noup";
2922 if (f & CEPH_OSDMAP_NODOWN)
2923 s += ",nodown";
2924 if (f & CEPH_OSDMAP_NOOUT)
2925 s += ",noout";
2926 if (f & CEPH_OSDMAP_NOIN)
2927 s += ",noin";
2928 if (f & CEPH_OSDMAP_NOBACKFILL)
2929 s += ",nobackfill";
2930 if (f & CEPH_OSDMAP_NOREBALANCE)
2931 s += ",norebalance";
2932 if (f & CEPH_OSDMAP_NORECOVER)
2933 s += ",norecover";
2934 if (f & CEPH_OSDMAP_NOSCRUB)
2935 s += ",noscrub";
2936 if (f & CEPH_OSDMAP_NODEEP_SCRUB)
2937 s += ",nodeep-scrub";
2938 if (f & CEPH_OSDMAP_NOTIERAGENT)
2939 s += ",notieragent";
2940 if (f & CEPH_OSDMAP_SORTBITWISE)
2941 s += ",sortbitwise";
2942 if (f & CEPH_OSDMAP_REQUIRE_JEWEL)
2943 s += ",require_jewel_osds";
2944 if (f & CEPH_OSDMAP_REQUIRE_KRAKEN)
2945 s += ",require_kraken_osds";
2946 if (f & CEPH_OSDMAP_REQUIRE_LUMINOUS)
2947 s += ",require_luminous_osds";
2948 if (f & CEPH_OSDMAP_RECOVERY_DELETES)
2949 s += ",recovery_deletes";
2950 if (s.length())
2951 s.erase(0, 1);
2952 return s;
2953 }
2954
2955 string OSDMap::get_flag_string() const
2956 {
2957 return get_flag_string(flags);
2958 }
2959
2960 void OSDMap::print_pools(ostream& out) const
2961 {
2962 for (const auto &pool : pools) {
2963 std::string name("<unknown>");
2964 const auto &pni = pool_name.find(pool.first);
2965 if (pni != pool_name.end())
2966 name = pni->second;
2967 out << "pool " << pool.first
2968 << " '" << name
2969 << "' " << pool.second << "\n";
2970
2971 for (const auto &snap : pool.second.snaps)
2972 out << "\tsnap " << snap.second.snapid << " '" << snap.second.name << "' " << snap.second.stamp << "\n";
2973
2974 if (!pool.second.removed_snaps.empty())
2975 out << "\tremoved_snaps " << pool.second.removed_snaps << "\n";
2976 }
2977 out << std::endl;
2978 }
2979
2980 void OSDMap::print(ostream& out) const
2981 {
2982 out << "epoch " << get_epoch() << "\n"
2983 << "fsid " << get_fsid() << "\n"
2984 << "created " << get_created() << "\n"
2985 << "modified " << get_modified() << "\n";
2986
2987 out << "flags " << get_flag_string() << "\n";
2988 out << "crush_version " << get_crush_version() << "\n";
2989 out << "full_ratio " << full_ratio << "\n";
2990 out << "backfillfull_ratio " << backfillfull_ratio << "\n";
2991 out << "nearfull_ratio " << nearfull_ratio << "\n";
2992 if (require_min_compat_client > 0) {
2993 out << "require_min_compat_client "
2994 << ceph_release_name(require_min_compat_client) << "\n";
2995 }
2996 out << "min_compat_client " << ceph_release_name(get_min_compat_client())
2997 << "\n";
2998 if (require_osd_release > 0) {
2999 out << "require_osd_release " << ceph_release_name(require_osd_release)
3000 << "\n";
3001 }
3002 if (get_cluster_snapshot().length())
3003 out << "cluster_snapshot " << get_cluster_snapshot() << "\n";
3004 out << "\n";
3005
3006 print_pools(out);
3007
3008 out << "max_osd " << get_max_osd() << "\n";
3009 for (int i=0; i<get_max_osd(); i++) {
3010 if (exists(i)) {
3011 out << "osd." << i;
3012 out << (is_up(i) ? " up ":" down");
3013 out << (is_in(i) ? " in ":" out");
3014 out << " weight " << get_weightf(i);
3015 if (get_primary_affinity(i) != CEPH_OSD_DEFAULT_PRIMARY_AFFINITY)
3016 out << " primary_affinity " << get_primary_affinityf(i);
3017 const osd_info_t& info(get_info(i));
3018 out << " " << info;
3019 out << " " << get_addr(i) << " " << get_cluster_addr(i) << " " << get_hb_back_addr(i)
3020 << " " << get_hb_front_addr(i);
3021 set<string> st;
3022 get_state(i, st);
3023 out << " " << st;
3024 if (!get_uuid(i).is_zero())
3025 out << " " << get_uuid(i);
3026 out << "\n";
3027 }
3028 }
3029 out << std::endl;
3030
3031 for (auto& p : pg_upmap) {
3032 out << "pg_upmap " << p.first << " " << p.second << "\n";
3033 }
3034 for (auto& p : pg_upmap_items) {
3035 out << "pg_upmap_items " << p.first << " " << p.second << "\n";
3036 }
3037
3038 for (const auto pg : *pg_temp)
3039 out << "pg_temp " << pg.first << " " << pg.second << "\n";
3040
3041 for (const auto pg : *primary_temp)
3042 out << "primary_temp " << pg.first << " " << pg.second << "\n";
3043
3044 for (const auto &addr : blacklist)
3045 out << "blacklist " << addr.first << " expires " << addr.second << "\n";
3046
3047 // ignore pg_swap_primary
3048 }
3049
3050 class OSDTreePlainDumper : public CrushTreeDumper::Dumper<TextTable> {
3051 public:
3052 typedef CrushTreeDumper::Dumper<TextTable> Parent;
3053
3054 OSDTreePlainDumper(const CrushWrapper *crush, const OSDMap *osdmap_,
3055 unsigned f)
3056 : Parent(crush, osdmap_->get_pool_names()), osdmap(osdmap_), filter(f) { }
3057
3058 bool should_dump_leaf(int i) const override {
3059 if (!filter) {
3060 return true; // normal case
3061 }
3062 if (((filter & OSDMap::DUMP_UP) && osdmap->is_up(i)) ||
3063 ((filter & OSDMap::DUMP_DOWN) && osdmap->is_down(i)) ||
3064 ((filter & OSDMap::DUMP_IN) && osdmap->is_in(i)) ||
3065 ((filter & OSDMap::DUMP_OUT) && osdmap->is_out(i)) ||
3066 ((filter & OSDMap::DUMP_DESTROYED) && osdmap->is_destroyed(i))) {
3067 return true;
3068 }
3069 return false;
3070 }
3071
3072 bool should_dump_empty_bucket() const override {
3073 return !filter;
3074 }
3075
3076 void dump(TextTable *tbl) {
3077 tbl->define_column("ID", TextTable::LEFT, TextTable::RIGHT);
3078 tbl->define_column("CLASS", TextTable::LEFT, TextTable::RIGHT);
3079 tbl->define_column("WEIGHT", TextTable::LEFT, TextTable::RIGHT);
3080 tbl->define_column("TYPE NAME", TextTable::LEFT, TextTable::LEFT);
3081 tbl->define_column("STATUS", TextTable::LEFT, TextTable::RIGHT);
3082 tbl->define_column("REWEIGHT", TextTable::LEFT, TextTable::RIGHT);
3083 tbl->define_column("PRI-AFF", TextTable::LEFT, TextTable::RIGHT);
3084
3085 Parent::dump(tbl);
3086
3087 for (int i = 0; i < osdmap->get_max_osd(); i++) {
3088 if (osdmap->exists(i) && !is_touched(i) && should_dump_leaf(i)) {
3089 dump_item(CrushTreeDumper::Item(i, 0, 0, 0), tbl);
3090 }
3091 }
3092 }
3093
3094 protected:
3095 void dump_item(const CrushTreeDumper::Item &qi, TextTable *tbl) override {
3096 const char *c = crush->get_item_class(qi.id);
3097 if (!c)
3098 c = "";
3099 *tbl << qi.id
3100 << c
3101 << weightf_t(qi.weight);
3102
3103 ostringstream name;
3104 for (int k = 0; k < qi.depth; k++)
3105 name << " ";
3106 if (qi.is_bucket()) {
3107 name << crush->get_type_name(crush->get_bucket_type(qi.id)) << " "
3108 << crush->get_item_name(qi.id);
3109 } else {
3110 name << "osd." << qi.id;
3111 }
3112 *tbl << name.str();
3113
3114 if (!qi.is_bucket()) {
3115 if (!osdmap->exists(qi.id)) {
3116 *tbl << "DNE"
3117 << 0;
3118 } else {
3119 string s;
3120 if (osdmap->is_up(qi.id)) {
3121 s = "up";
3122 } else if (osdmap->is_destroyed(qi.id)) {
3123 s = "destroyed";
3124 } else {
3125 s = "down";
3126 }
3127 *tbl << s
3128 << weightf_t(osdmap->get_weightf(qi.id))
3129 << weightf_t(osdmap->get_primary_affinityf(qi.id));
3130 }
3131 }
3132 *tbl << TextTable::endrow;
3133 }
3134
3135 private:
3136 const OSDMap *osdmap;
3137 const unsigned filter;
3138 };
3139
3140 class OSDTreeFormattingDumper : public CrushTreeDumper::FormattingDumper {
3141 public:
3142 typedef CrushTreeDumper::FormattingDumper Parent;
3143
3144 OSDTreeFormattingDumper(const CrushWrapper *crush, const OSDMap *osdmap_,
3145 unsigned f)
3146 : Parent(crush, osdmap_->get_pool_names()), osdmap(osdmap_), filter(f) { }
3147
3148 bool should_dump_leaf(int i) const override {
3149 if (!filter) {
3150 return true; // normal case
3151 }
3152 if (((filter & OSDMap::DUMP_UP) && osdmap->is_up(i)) ||
3153 ((filter & OSDMap::DUMP_DOWN) && osdmap->is_down(i)) ||
3154 ((filter & OSDMap::DUMP_IN) && osdmap->is_in(i)) ||
3155 ((filter & OSDMap::DUMP_OUT) && osdmap->is_out(i)) ||
3156 ((filter & OSDMap::DUMP_DESTROYED) && osdmap->is_destroyed(i))) {
3157 return true;
3158 }
3159 return false;
3160 }
3161
3162 bool should_dump_empty_bucket() const override {
3163 return !filter;
3164 }
3165
3166 void dump(Formatter *f) {
3167 f->open_array_section("nodes");
3168 Parent::dump(f);
3169 f->close_section();
3170 f->open_array_section("stray");
3171 for (int i = 0; i < osdmap->get_max_osd(); i++) {
3172 if (osdmap->exists(i) && !is_touched(i) && should_dump_leaf(i))
3173 dump_item(CrushTreeDumper::Item(i, 0, 0, 0), f);
3174 }
3175 f->close_section();
3176 }
3177
3178 protected:
3179 void dump_item_fields(const CrushTreeDumper::Item &qi, Formatter *f) override {
3180 Parent::dump_item_fields(qi, f);
3181 if (!qi.is_bucket())
3182 {
3183 string s;
3184 if (osdmap->is_up(qi.id)) {
3185 s = "up";
3186 } else if (osdmap->is_destroyed(qi.id)) {
3187 s = "destroyed";
3188 } else {
3189 s = "down";
3190 }
3191 f->dump_unsigned("exists", (int)osdmap->exists(qi.id));
3192 f->dump_string("status", s);
3193 f->dump_float("reweight", osdmap->get_weightf(qi.id));
3194 f->dump_float("primary_affinity", osdmap->get_primary_affinityf(qi.id));
3195 }
3196 }
3197
3198 private:
3199 const OSDMap *osdmap;
3200 const unsigned filter;
3201 };
3202
3203 void OSDMap::print_tree(Formatter *f, ostream *out, unsigned filter) const
3204 {
3205 if (f) {
3206 OSDTreeFormattingDumper(crush.get(), this, filter).dump(f);
3207 } else {
3208 assert(out);
3209 TextTable tbl;
3210 OSDTreePlainDumper(crush.get(), this, filter).dump(&tbl);
3211 *out << tbl;
3212 }
3213 }
3214
3215 void OSDMap::print_summary(Formatter *f, ostream& out,
3216 const string& prefix) const
3217 {
3218 if (f) {
3219 f->open_object_section("osdmap");
3220 f->dump_int("epoch", get_epoch());
3221 f->dump_int("num_osds", get_num_osds());
3222 f->dump_int("num_up_osds", get_num_up_osds());
3223 f->dump_int("num_in_osds", get_num_in_osds());
3224 f->dump_bool("full", test_flag(CEPH_OSDMAP_FULL) ? true : false);
3225 f->dump_bool("nearfull", test_flag(CEPH_OSDMAP_NEARFULL) ? true : false);
3226 f->dump_unsigned("num_remapped_pgs", get_num_pg_temp());
3227 f->close_section();
3228 } else {
3229 out << get_num_osds() << " osds: "
3230 << get_num_up_osds() << " up, "
3231 << get_num_in_osds() << " in";
3232 if (get_num_pg_temp())
3233 out << "; " << get_num_pg_temp() << " remapped pgs";
3234 out << "\n";
3235 uint64_t important_flags = flags & ~CEPH_OSDMAP_SEMIHIDDEN_FLAGS;
3236 if (important_flags)
3237 out << prefix << "flags " << get_flag_string(important_flags) << "\n";
3238 }
3239 }
3240
3241 void OSDMap::print_oneline_summary(ostream& out) const
3242 {
3243 out << "e" << get_epoch() << ": "
3244 << get_num_osds() << " total, "
3245 << get_num_up_osds() << " up, "
3246 << get_num_in_osds() << " in";
3247 if (test_flag(CEPH_OSDMAP_FULL))
3248 out << " full";
3249 else if (test_flag(CEPH_OSDMAP_NEARFULL))
3250 out << " nearfull";
3251 }
3252
3253 bool OSDMap::crush_ruleset_in_use(int ruleset) const
3254 {
3255 for (const auto &pool : pools) {
3256 if (pool.second.crush_rule == ruleset)
3257 return true;
3258 }
3259 return false;
3260 }
3261
3262 int OSDMap::build_simple_optioned(CephContext *cct, epoch_t e, uuid_d &fsid,
3263 int nosd, int pg_bits, int pgp_bits,
3264 bool default_pool)
3265 {
3266 ldout(cct, 10) << "build_simple on " << nosd
3267 << " osds" << dendl;
3268 epoch = e;
3269 set_fsid(fsid);
3270 created = modified = ceph_clock_now();
3271
3272 if (nosd >= 0) {
3273 set_max_osd(nosd);
3274 } else {
3275 // count osds
3276 int maxosd = 0;
3277 const md_config_t *conf = cct->_conf;
3278 vector<string> sections;
3279 conf->get_all_sections(sections);
3280
3281 for (auto &section : sections) {
3282 if (section.find("osd.") != 0)
3283 continue;
3284
3285 const char *begin = section.c_str() + 4;
3286 char *end = (char*)begin;
3287 int o = strtol(begin, &end, 10);
3288 if (*end != '\0')
3289 continue;
3290
3291 if (o > cct->_conf->mon_max_osd) {
3292 lderr(cct) << "[osd." << o << "] in config has id > mon_max_osd " << cct->_conf->mon_max_osd << dendl;
3293 return -ERANGE;
3294 }
3295
3296 if (o > maxosd)
3297 maxosd = o;
3298 }
3299
3300 set_max_osd(maxosd + 1);
3301 }
3302
3303
3304 stringstream ss;
3305 int r;
3306 if (nosd >= 0)
3307 r = build_simple_crush_map(cct, *crush, nosd, &ss);
3308 else
3309 r = build_simple_crush_map_from_conf(cct, *crush, &ss);
3310 assert(r == 0);
3311
3312 int poolbase = get_max_osd() ? get_max_osd() : 1;
3313
3314 int const default_replicated_rule = crush->get_osd_pool_default_crush_replicated_ruleset(cct);
3315 assert(default_replicated_rule >= 0);
3316
3317 if (default_pool) {
3318 // pgp_num <= pg_num
3319 if (pgp_bits > pg_bits)
3320 pgp_bits = pg_bits;
3321
3322 vector<string> pool_names;
3323 pool_names.push_back("rbd");
3324 for (auto &plname : pool_names) {
3325 int64_t pool = ++pool_max;
3326 pools[pool].type = pg_pool_t::TYPE_REPLICATED;
3327 pools[pool].flags = cct->_conf->osd_pool_default_flags;
3328 if (cct->_conf->osd_pool_default_flag_hashpspool)
3329 pools[pool].set_flag(pg_pool_t::FLAG_HASHPSPOOL);
3330 if (cct->_conf->osd_pool_default_flag_nodelete)
3331 pools[pool].set_flag(pg_pool_t::FLAG_NODELETE);
3332 if (cct->_conf->osd_pool_default_flag_nopgchange)
3333 pools[pool].set_flag(pg_pool_t::FLAG_NOPGCHANGE);
3334 if (cct->_conf->osd_pool_default_flag_nosizechange)
3335 pools[pool].set_flag(pg_pool_t::FLAG_NOSIZECHANGE);
3336 pools[pool].size = cct->_conf->osd_pool_default_size;
3337 pools[pool].min_size = cct->_conf->get_osd_pool_default_min_size();
3338 pools[pool].crush_rule = default_replicated_rule;
3339 pools[pool].object_hash = CEPH_STR_HASH_RJENKINS;
3340 pools[pool].set_pg_num(poolbase << pg_bits);
3341 pools[pool].set_pgp_num(poolbase << pgp_bits);
3342 pools[pool].last_change = epoch;
3343 pools[pool].application_metadata.insert(
3344 {pg_pool_t::APPLICATION_NAME_RBD, {}});
3345 pool_name[pool] = plname;
3346 name_pool[plname] = pool;
3347 }
3348 }
3349
3350 for (int i=0; i<get_max_osd(); i++) {
3351 set_state(i, 0);
3352 set_weight(i, CEPH_OSD_OUT);
3353 }
3354
3355 map<string,string> profile_map;
3356 r = get_erasure_code_profile_default(cct, profile_map, &ss);
3357 if (r < 0) {
3358 lderr(cct) << ss.str() << dendl;
3359 return r;
3360 }
3361 set_erasure_code_profile("default", profile_map);
3362 return 0;
3363 }
3364
3365 int OSDMap::get_erasure_code_profile_default(CephContext *cct,
3366 map<string,string> &profile_map,
3367 ostream *ss)
3368 {
3369 int r = get_json_str_map(cct->_conf->osd_pool_default_erasure_code_profile,
3370 *ss,
3371 &profile_map);
3372 return r;
3373 }
3374
3375 int OSDMap::_build_crush_types(CrushWrapper& crush)
3376 {
3377 crush.set_type_name(0, "osd");
3378 crush.set_type_name(1, "host");
3379 crush.set_type_name(2, "chassis");
3380 crush.set_type_name(3, "rack");
3381 crush.set_type_name(4, "row");
3382 crush.set_type_name(5, "pdu");
3383 crush.set_type_name(6, "pod");
3384 crush.set_type_name(7, "room");
3385 crush.set_type_name(8, "datacenter");
3386 crush.set_type_name(9, "region");
3387 crush.set_type_name(10, "root");
3388 return 10;
3389 }
3390
3391 int OSDMap::build_simple_crush_map(CephContext *cct, CrushWrapper& crush,
3392 int nosd, ostream *ss)
3393 {
3394 crush.create();
3395
3396 // root
3397 int root_type = _build_crush_types(crush);
3398 int rootid;
3399 int r = crush.add_bucket(0, 0, CRUSH_HASH_DEFAULT,
3400 root_type, 0, NULL, NULL, &rootid);
3401 assert(r == 0);
3402 crush.set_item_name(rootid, "default");
3403
3404 for (int o=0; o<nosd; o++) {
3405 map<string,string> loc;
3406 loc["host"] = "localhost";
3407 loc["rack"] = "localrack";
3408 loc["root"] = "default";
3409 ldout(cct, 10) << " adding osd." << o << " at " << loc << dendl;
3410 char name[32];
3411 snprintf(name, sizeof(name), "osd.%d", o);
3412 crush.insert_item(cct, o, 1.0, name, loc);
3413 }
3414
3415 build_simple_crush_rules(cct, crush, "default", ss);
3416
3417 crush.finalize();
3418
3419 return 0;
3420 }
3421
3422 int OSDMap::build_simple_crush_map_from_conf(CephContext *cct,
3423 CrushWrapper& crush,
3424 ostream *ss)
3425 {
3426 const md_config_t *conf = cct->_conf;
3427
3428 crush.create();
3429
3430 // root
3431 int root_type = _build_crush_types(crush);
3432 int rootid;
3433 int r = crush.add_bucket(0, 0,
3434 CRUSH_HASH_DEFAULT,
3435 root_type, 0, NULL, NULL, &rootid);
3436 assert(r == 0);
3437 crush.set_item_name(rootid, "default");
3438
3439 // add osds
3440 vector<string> sections;
3441 conf->get_all_sections(sections);
3442
3443 for (auto &section : sections) {
3444 if (section.find("osd.") != 0)
3445 continue;
3446
3447 const char *begin = section.c_str() + 4;
3448 char *end = (char*)begin;
3449 int o = strtol(begin, &end, 10);
3450 if (*end != '\0')
3451 continue;
3452
3453 string host, rack, row, room, dc, pool;
3454 vector<string> sectiontmp;
3455 sectiontmp.push_back("osd");
3456 sectiontmp.push_back(section);
3457 conf->get_val_from_conf_file(sectiontmp, "host", host, false);
3458 conf->get_val_from_conf_file(sectiontmp, "rack", rack, false);
3459 conf->get_val_from_conf_file(sectiontmp, "row", row, false);
3460 conf->get_val_from_conf_file(sectiontmp, "room", room, false);
3461 conf->get_val_from_conf_file(sectiontmp, "datacenter", dc, false);
3462 conf->get_val_from_conf_file(sectiontmp, "root", pool, false);
3463
3464 if (host.length() == 0)
3465 host = "unknownhost";
3466 if (rack.length() == 0)
3467 rack = "unknownrack";
3468
3469 map<string,string> loc;
3470 loc["host"] = host;
3471 loc["rack"] = rack;
3472 if (row.size())
3473 loc["row"] = row;
3474 if (room.size())
3475 loc["room"] = room;
3476 if (dc.size())
3477 loc["datacenter"] = dc;
3478 loc["root"] = "default";
3479
3480 ldout(cct, 5) << " adding osd." << o << " at " << loc << dendl;
3481 crush.insert_item(cct, o, 1.0, section, loc);
3482 }
3483
3484 build_simple_crush_rules(cct, crush, "default", ss);
3485
3486 crush.finalize();
3487
3488 return 0;
3489 }
3490
3491
3492 int OSDMap::build_simple_crush_rules(
3493 CephContext *cct,
3494 CrushWrapper& crush,
3495 const string& root,
3496 ostream *ss)
3497 {
3498 int crush_rule = crush.get_osd_pool_default_crush_replicated_ruleset(cct);
3499 string failure_domain =
3500 crush.get_type_name(cct->_conf->osd_crush_chooseleaf_type);
3501
3502 int r;
3503 r = crush.add_simple_rule_at(
3504 "replicated_rule", root, failure_domain, "",
3505 "firstn", pg_pool_t::TYPE_REPLICATED,
3506 crush_rule, ss);
3507 if (r < 0)
3508 return r;
3509 // do not add an erasure rule by default or else we will implicitly
3510 // require the crush_v2 feature of clients
3511 return 0;
3512 }
3513
3514 int OSDMap::summarize_mapping_stats(
3515 OSDMap *newmap,
3516 const set<int64_t> *pools,
3517 std::string *out,
3518 Formatter *f) const
3519 {
3520 set<int64_t> ls;
3521 if (pools) {
3522 ls = *pools;
3523 } else {
3524 for (auto &p : get_pools())
3525 ls.insert(p.first);
3526 }
3527
3528 unsigned total_pg = 0;
3529 unsigned moved_pg = 0;
3530 vector<unsigned> base_by_osd(get_max_osd(), 0);
3531 vector<unsigned> new_by_osd(get_max_osd(), 0);
3532 for (int64_t pool_id : ls) {
3533 const pg_pool_t *pi = get_pg_pool(pool_id);
3534 vector<int> up, up2;
3535 int up_primary;
3536 for (unsigned ps = 0; ps < pi->get_pg_num(); ++ps) {
3537 pg_t pgid(ps, pool_id, -1);
3538 total_pg += pi->get_size();
3539 pg_to_up_acting_osds(pgid, &up, &up_primary, nullptr, nullptr);
3540 for (int osd : up) {
3541 if (osd >= 0 && osd < get_max_osd())
3542 ++base_by_osd[osd];
3543 }
3544 if (newmap) {
3545 newmap->pg_to_up_acting_osds(pgid, &up2, &up_primary, nullptr, nullptr);
3546 for (int osd : up2) {
3547 if (osd >= 0 && osd < get_max_osd())
3548 ++new_by_osd[osd];
3549 }
3550 if (pi->type == pg_pool_t::TYPE_ERASURE) {
3551 for (unsigned i=0; i<up.size(); ++i) {
3552 if (up[i] != up2[i]) {
3553 ++moved_pg;
3554 }
3555 }
3556 } else if (pi->type == pg_pool_t::TYPE_REPLICATED) {
3557 for (int osd : up) {
3558 if (std::find(up2.begin(), up2.end(), osd) == up2.end()) {
3559 ++moved_pg;
3560 }
3561 }
3562 } else {
3563 assert(0 == "unhandled pool type");
3564 }
3565 }
3566 }
3567 }
3568
3569 unsigned num_up_in = 0;
3570 for (int osd = 0; osd < get_max_osd(); ++osd) {
3571 if (is_up(osd) && is_in(osd))
3572 ++num_up_in;
3573 }
3574 if (!num_up_in) {
3575 return -EINVAL;
3576 }
3577
3578 float avg_pg = (float)total_pg / (float)num_up_in;
3579 float base_stddev = 0, new_stddev = 0;
3580 int min = -1, max = -1;
3581 unsigned min_base_pg = 0, max_base_pg = 0;
3582 unsigned min_new_pg = 0, max_new_pg = 0;
3583 for (int osd = 0; osd < get_max_osd(); ++osd) {
3584 if (is_up(osd) && is_in(osd)) {
3585 float base_diff = (float)base_by_osd[osd] - avg_pg;
3586 base_stddev += base_diff * base_diff;
3587 float new_diff = (float)new_by_osd[osd] - avg_pg;
3588 new_stddev += new_diff * new_diff;
3589 if (min < 0 || base_by_osd[osd] < min_base_pg) {
3590 min = osd;
3591 min_base_pg = base_by_osd[osd];
3592 min_new_pg = new_by_osd[osd];
3593 }
3594 if (max < 0 || base_by_osd[osd] > max_base_pg) {
3595 max = osd;
3596 max_base_pg = base_by_osd[osd];
3597 max_new_pg = new_by_osd[osd];
3598 }
3599 }
3600 }
3601 base_stddev = sqrt(base_stddev / num_up_in);
3602 new_stddev = sqrt(new_stddev / num_up_in);
3603
3604 float edev = sqrt(avg_pg * (1.0 - (1.0 / (double)num_up_in)));
3605
3606 ostringstream ss;
3607 if (f)
3608 f->open_object_section("utilization");
3609 if (newmap) {
3610 if (f) {
3611 f->dump_unsigned("moved_pgs", moved_pg);
3612 f->dump_unsigned("total_pgs", total_pg);
3613 } else {
3614 float percent = 0;
3615 if (total_pg)
3616 percent = (float)moved_pg * 100.0 / (float)total_pg;
3617 ss << "moved " << moved_pg << " / " << total_pg
3618 << " (" << percent << "%)\n";
3619 }
3620 }
3621 if (f) {
3622 f->dump_float("avg_pgs", avg_pg);
3623 f->dump_float("std_dev", base_stddev);
3624 f->dump_float("expected_baseline_std_dev", edev);
3625 if (newmap)
3626 f->dump_float("new_std_dev", new_stddev);
3627 } else {
3628 ss << "avg " << avg_pg << "\n";
3629 ss << "stddev " << base_stddev;
3630 if (newmap)
3631 ss << " -> " << new_stddev;
3632 ss << " (expected baseline " << edev << ")\n";
3633 }
3634 if (min >= 0) {
3635 if (f) {
3636 f->dump_unsigned("min_osd", min);
3637 f->dump_unsigned("min_osd_pgs", min_base_pg);
3638 if (newmap)
3639 f->dump_unsigned("new_min_osd_pgs", min_new_pg);
3640 } else {
3641 ss << "min osd." << min << " with " << min_base_pg;
3642 if (newmap)
3643 ss << " -> " << min_new_pg;
3644 ss << " pgs (" << (float)min_base_pg / avg_pg;
3645 if (newmap)
3646 ss << " -> " << (float)min_new_pg / avg_pg;
3647 ss << " * mean)\n";
3648 }
3649 }
3650 if (max >= 0) {
3651 if (f) {
3652 f->dump_unsigned("max_osd", max);
3653 f->dump_unsigned("max_osd_pgs", max_base_pg);
3654 if (newmap)
3655 f->dump_unsigned("new_max_osd_pgs", max_new_pg);
3656 } else {
3657 ss << "max osd." << max << " with " << max_base_pg;
3658 if (newmap)
3659 ss << " -> " << max_new_pg;
3660 ss << " pgs (" << (float)max_base_pg / avg_pg;
3661 if (newmap)
3662 ss << " -> " << (float)max_new_pg / avg_pg;
3663 ss << " * mean)\n";
3664 }
3665 }
3666 if (f)
3667 f->close_section();
3668 if (out)
3669 *out = ss.str();
3670 return 0;
3671 }
3672
3673
3674 int OSDMap::clean_pg_upmaps(
3675 CephContext *cct,
3676 Incremental *pending_inc)
3677 {
3678 ldout(cct, 10) << __func__ << dendl;
3679 int changed = 0;
3680 for (auto& p : pg_upmap) {
3681 vector<int> raw;
3682 int primary;
3683 pg_to_raw_osds(p.first, &raw, &primary);
3684 if (vectors_equal(raw, p.second)) {
3685 ldout(cct, 10) << " removing redundant pg_upmap " << p.first << " "
3686 << p.second << dendl;
3687 pending_inc->old_pg_upmap.insert(p.first);
3688 ++changed;
3689 }
3690 }
3691 for (auto& p : pg_upmap_items) {
3692 vector<int> raw;
3693 int primary;
3694 pg_to_raw_osds(p.first, &raw, &primary);
3695 mempool::osdmap::vector<pair<int,int>> newmap;
3696 for (auto& q : p.second) {
3697 if (std::find(raw.begin(), raw.end(), q.first) != raw.end()) {
3698 newmap.push_back(q);
3699 }
3700 }
3701 if (newmap.empty()) {
3702 ldout(cct, 10) << " removing no-op pg_upmap_items " << p.first << " "
3703 << p.second << dendl;
3704 pending_inc->old_pg_upmap_items.insert(p.first);
3705 ++changed;
3706 } else if (newmap != p.second) {
3707 ldout(cct, 10) << " simplifying partially no-op pg_upmap_items "
3708 << p.first << " " << p.second << " -> " << newmap << dendl;
3709 pending_inc->new_pg_upmap_items[p.first] = newmap;
3710 ++changed;
3711 }
3712 }
3713 return changed;
3714 }
3715
3716 bool OSDMap::try_pg_upmap(
3717 CephContext *cct,
3718 pg_t pg, ///< pg to potentially remap
3719 const set<int>& overfull, ///< osds we'd want to evacuate
3720 const vector<int>& underfull, ///< osds to move to, in order of preference
3721 vector<int> *orig,
3722 vector<int> *out) ///< resulting alternative mapping
3723 {
3724 const pg_pool_t *pool = get_pg_pool(pg.pool());
3725 if (!pool)
3726 return false;
3727 int rule = crush->find_rule(pool->get_crush_rule(), pool->get_type(),
3728 pool->get_size());
3729 if (rule < 0)
3730 return false;
3731
3732 // get original mapping
3733 _pg_to_raw_osds(*pool, pg, orig, NULL);
3734
3735 // make sure there is something there to remap
3736 bool any = false;
3737 for (auto osd : *orig) {
3738 if (overfull.count(osd)) {
3739 any = true;
3740 break;
3741 }
3742 }
3743 if (!any) {
3744 return false;
3745 }
3746
3747 int r = crush->try_remap_rule(
3748 cct,
3749 rule,
3750 pool->get_size(),
3751 overfull, underfull,
3752 *orig,
3753 out);
3754 if (r < 0)
3755 return false;
3756 if (*out == *orig)
3757 return false;
3758 return true;
3759 }
3760
3761 int OSDMap::calc_pg_upmaps(
3762 CephContext *cct,
3763 float max_deviation_ratio,
3764 int max,
3765 const set<int64_t>& only_pools_orig,
3766 OSDMap::Incremental *pending_inc)
3767 {
3768 set<int64_t> only_pools;
3769 if (only_pools_orig.empty()) {
3770 for (auto& i : pools) {
3771 only_pools.insert(i.first);
3772 }
3773 } else {
3774 only_pools = only_pools_orig;
3775 }
3776 OSDMap tmp;
3777 tmp.deepish_copy_from(*this);
3778 float start_deviation = 0;
3779 float end_deviation = 0;
3780 int num_changed = 0;
3781 while (true) {
3782 map<int,set<pg_t>> pgs_by_osd;
3783 int total_pgs = 0;
3784 float osd_weight_total = 0;
3785 map<int,float> osd_weight;
3786 for (auto& i : pools) {
3787 if (!only_pools.empty() && !only_pools.count(i.first))
3788 continue;
3789 for (unsigned ps = 0; ps < i.second.get_pg_num(); ++ps) {
3790 pg_t pg(ps, i.first);
3791 vector<int> up;
3792 tmp.pg_to_up_acting_osds(pg, &up, nullptr, nullptr, nullptr);
3793 for (auto osd : up) {
3794 if (osd != CRUSH_ITEM_NONE)
3795 pgs_by_osd[osd].insert(pg);
3796 }
3797 }
3798 total_pgs += i.second.get_size() * i.second.get_pg_num();
3799
3800 map<int,float> pmap;
3801 int ruleno = tmp.crush->find_rule(i.second.get_crush_rule(),
3802 i.second.get_type(),
3803 i.second.get_size());
3804 tmp.crush->get_rule_weight_osd_map(ruleno, &pmap);
3805 ldout(cct,30) << __func__ << " pool " << i.first << " ruleno " << ruleno << dendl;
3806 for (auto p : pmap) {
3807 osd_weight[p.first] += p.second;
3808 osd_weight_total += p.second;
3809 }
3810 }
3811 for (auto& i : osd_weight) {
3812 int pgs = 0;
3813 auto p = pgs_by_osd.find(i.first);
3814 if (p != pgs_by_osd.end())
3815 pgs = p->second.size();
3816 else
3817 pgs_by_osd.emplace(i.first, set<pg_t>());
3818 ldout(cct, 20) << " osd." << i.first << " weight " << i.second
3819 << " pgs " << pgs << dendl;
3820 }
3821
3822 if (osd_weight_total == 0) {
3823 lderr(cct) << __func__ << " abort due to osd_weight_total == 0" << dendl;
3824 break;
3825 }
3826 float pgs_per_weight = total_pgs / osd_weight_total;
3827 ldout(cct, 10) << " osd_weight_total " << osd_weight_total << dendl;
3828 ldout(cct, 10) << " pgs_per_weight " << pgs_per_weight << dendl;
3829
3830 // osd deviation
3831 float total_deviation = 0;
3832 map<int,float> osd_deviation; // osd, deviation(pgs)
3833 multimap<float,int> deviation_osd; // deviation(pgs), osd
3834 set<int> overfull;
3835 for (auto& i : pgs_by_osd) {
3836 float target = osd_weight[i.first] * pgs_per_weight;
3837 float deviation = (float)i.second.size() - target;
3838 ldout(cct, 20) << " osd." << i.first
3839 << "\tpgs " << i.second.size()
3840 << "\ttarget " << target
3841 << "\tdeviation " << deviation
3842 << dendl;
3843 osd_deviation[i.first] = deviation;
3844 deviation_osd.insert(make_pair(deviation, i.first));
3845 if (deviation >= 1.0)
3846 overfull.insert(i.first);
3847 total_deviation += abs(deviation);
3848 }
3849 if (num_changed == 0) {
3850 start_deviation = total_deviation;
3851 }
3852 end_deviation = total_deviation;
3853
3854 // build underfull, sorted from least-full to most-average
3855 vector<int> underfull;
3856 for (auto i = deviation_osd.begin();
3857 i != deviation_osd.end();
3858 ++i) {
3859 if (i->first >= -.999)
3860 break;
3861 underfull.push_back(i->second);
3862 }
3863 ldout(cct, 10) << " total_deviation " << total_deviation
3864 << " overfull " << overfull
3865 << " underfull " << underfull << dendl;
3866 if (overfull.empty() || underfull.empty())
3867 break;
3868
3869 // pick fullest
3870 bool restart = false;
3871 for (auto p = deviation_osd.rbegin(); p != deviation_osd.rend(); ++p) {
3872 int osd = p->second;
3873 float deviation = p->first;
3874 float target = osd_weight[osd] * pgs_per_weight;
3875 assert(target > 0);
3876 if (deviation/target < max_deviation_ratio) {
3877 ldout(cct, 10) << " osd." << osd
3878 << " target " << target
3879 << " deviation " << deviation
3880 << " -> ratio " << deviation/target
3881 << " < max ratio " << max_deviation_ratio << dendl;
3882 break;
3883 }
3884 int num_to_move = deviation;
3885 ldout(cct, 10) << " osd." << osd << " move " << num_to_move << dendl;
3886 if (num_to_move < 1)
3887 break;
3888
3889 set<pg_t>& pgs = pgs_by_osd[osd];
3890
3891 // look for remaps we can un-remap
3892 for (auto pg : pgs) {
3893 auto p = tmp.pg_upmap_items.find(pg);
3894 if (p != tmp.pg_upmap_items.end()) {
3895 for (auto q : p->second) {
3896 if (q.second == osd) {
3897 ldout(cct, 10) << " dropping pg_upmap_items " << pg
3898 << " " << p->second << dendl;
3899 tmp.pg_upmap_items.erase(p);
3900 pending_inc->old_pg_upmap_items.insert(pg);
3901 ++num_changed;
3902 restart = true;
3903 }
3904 }
3905 }
3906 if (restart)
3907 break;
3908 } // pg loop
3909 if (restart)
3910 break;
3911
3912 for (auto pg : pgs) {
3913 if (tmp.pg_upmap.count(pg) ||
3914 tmp.pg_upmap_items.count(pg)) {
3915 ldout(cct, 20) << " already remapped " << pg << dendl;
3916 continue;
3917 }
3918 ldout(cct, 10) << " trying " << pg << dendl;
3919 vector<int> orig, out;
3920 if (!try_pg_upmap(cct, pg, overfull, underfull, &orig, &out)) {
3921 continue;
3922 }
3923 ldout(cct, 10) << " " << pg << " " << orig << " -> " << out << dendl;
3924 if (orig.size() != out.size()) {
3925 continue;
3926 }
3927 assert(orig != out);
3928 auto& rmi = tmp.pg_upmap_items[pg];
3929 for (unsigned i = 0; i < out.size(); ++i) {
3930 if (orig[i] != out[i]) {
3931 rmi.push_back(make_pair(orig[i], out[i]));
3932 }
3933 }
3934 pending_inc->new_pg_upmap_items[pg] = rmi;
3935 ldout(cct, 10) << " " << pg << " pg_upmap_items " << rmi << dendl;
3936 restart = true;
3937 ++num_changed;
3938 break;
3939 } // pg loop
3940 if (restart)
3941 break;
3942 } // osd loop
3943
3944 if (!restart) {
3945 ldout(cct, 10) << " failed to find any changes to make" << dendl;
3946 break;
3947 }
3948 if (--max == 0) {
3949 ldout(cct, 10) << " hit max iterations, stopping" << dendl;
3950 break;
3951 }
3952 }
3953 ldout(cct, 10) << " start deviation " << start_deviation << dendl;
3954 ldout(cct, 10) << " end deviation " << end_deviation << dendl;
3955 return num_changed;
3956 }
3957
3958 int OSDMap::get_osds_by_bucket_name(const string &name, set<int> *osds) const
3959 {
3960 return crush->get_leaves(name, osds);
3961 }
3962
3963 template <typename F>
3964 class OSDUtilizationDumper : public CrushTreeDumper::Dumper<F> {
3965 public:
3966 typedef CrushTreeDumper::Dumper<F> Parent;
3967
3968 OSDUtilizationDumper(const CrushWrapper *crush, const OSDMap *osdmap_,
3969 const PGStatService *pgs_, bool tree_) :
3970 Parent(crush, osdmap_->get_pool_names()),
3971 osdmap(osdmap_),
3972 pgs(pgs_),
3973 tree(tree_),
3974 average_util(average_utilization()),
3975 min_var(-1),
3976 max_var(-1),
3977 stddev(0),
3978 sum(0) {
3979 }
3980
3981 protected:
3982 void dump_stray(F *f) {
3983 for (int i = 0; i < osdmap->get_max_osd(); i++) {
3984 if (osdmap->exists(i) && !this->is_touched(i))
3985 dump_item(CrushTreeDumper::Item(i, 0, 0, 0), f);
3986 }
3987 }
3988
3989 void dump_item(const CrushTreeDumper::Item &qi, F *f) override {
3990 if (!tree && qi.is_bucket())
3991 return;
3992
3993 float reweight = qi.is_bucket() ? -1 : osdmap->get_weightf(qi.id);
3994 int64_t kb = 0, kb_used = 0, kb_avail = 0;
3995 double util = 0;
3996 if (get_bucket_utilization(qi.id, &kb, &kb_used, &kb_avail))
3997 if (kb_used && kb)
3998 util = 100.0 * (double)kb_used / (double)kb;
3999
4000 double var = 1.0;
4001 if (average_util)
4002 var = util / average_util;
4003
4004 size_t num_pgs = qi.is_bucket() ? 0 : pgs->get_num_pg_by_osd(qi.id);
4005
4006 dump_item(qi, reweight, kb, kb_used, kb_avail, util, var, num_pgs, f);
4007
4008 if (!qi.is_bucket() && reweight > 0) {
4009 if (min_var < 0 || var < min_var)
4010 min_var = var;
4011 if (max_var < 0 || var > max_var)
4012 max_var = var;
4013
4014 double dev = util - average_util;
4015 dev *= dev;
4016 stddev += reweight * dev;
4017 sum += reweight;
4018 }
4019 }
4020
4021 virtual void dump_item(const CrushTreeDumper::Item &qi,
4022 float &reweight,
4023 int64_t kb,
4024 int64_t kb_used,
4025 int64_t kb_avail,
4026 double& util,
4027 double& var,
4028 const size_t num_pgs,
4029 F *f) = 0;
4030
4031 double dev() {
4032 return sum > 0 ? sqrt(stddev / sum) : 0;
4033 }
4034
4035 double average_utilization() {
4036 int64_t kb = 0, kb_used = 0;
4037 for (int i = 0; i < osdmap->get_max_osd(); i++) {
4038 if (!osdmap->exists(i) || osdmap->get_weight(i) == 0)
4039 continue;
4040 int64_t kb_i, kb_used_i, kb_avail_i;
4041 if (get_osd_utilization(i, &kb_i, &kb_used_i, &kb_avail_i)) {
4042 kb += kb_i;
4043 kb_used += kb_used_i;
4044 }
4045 }
4046 return kb > 0 ? 100.0 * (double)kb_used / (double)kb : 0;
4047 }
4048
4049 bool get_osd_utilization(int id, int64_t* kb, int64_t* kb_used,
4050 int64_t* kb_avail) const {
4051 const osd_stat_t *p = pgs->get_osd_stat(id);
4052 if (!p) return false;
4053 *kb = p->kb;
4054 *kb_used = p->kb_used;
4055 *kb_avail = p->kb_avail;
4056 return *kb > 0;
4057 }
4058
4059 bool get_bucket_utilization(int id, int64_t* kb, int64_t* kb_used,
4060 int64_t* kb_avail) const {
4061 if (id >= 0) {
4062 if (osdmap->is_out(id)) {
4063 *kb = 0;
4064 *kb_used = 0;
4065 *kb_avail = 0;
4066 return true;
4067 }
4068 return get_osd_utilization(id, kb, kb_used, kb_avail);
4069 }
4070
4071 *kb = 0;
4072 *kb_used = 0;
4073 *kb_avail = 0;
4074
4075 for (int k = osdmap->crush->get_bucket_size(id) - 1; k >= 0; k--) {
4076 int item = osdmap->crush->get_bucket_item(id, k);
4077 int64_t kb_i = 0, kb_used_i = 0, kb_avail_i = 0;
4078 if (!get_bucket_utilization(item, &kb_i, &kb_used_i, &kb_avail_i))
4079 return false;
4080 *kb += kb_i;
4081 *kb_used += kb_used_i;
4082 *kb_avail += kb_avail_i;
4083 }
4084 return *kb > 0;
4085 }
4086
4087 protected:
4088 const OSDMap *osdmap;
4089 const PGStatService *pgs;
4090 bool tree;
4091 double average_util;
4092 double min_var;
4093 double max_var;
4094 double stddev;
4095 double sum;
4096 };
4097
4098
4099 class OSDUtilizationPlainDumper : public OSDUtilizationDumper<TextTable> {
4100 public:
4101 typedef OSDUtilizationDumper<TextTable> Parent;
4102
4103 OSDUtilizationPlainDumper(const CrushWrapper *crush, const OSDMap *osdmap,
4104 const PGStatService *pgs, bool tree) :
4105 Parent(crush, osdmap, pgs, tree) {}
4106
4107 void dump(TextTable *tbl) {
4108 tbl->define_column("ID", TextTable::LEFT, TextTable::RIGHT);
4109 tbl->define_column("CLASS", TextTable::LEFT, TextTable::RIGHT);
4110 tbl->define_column("WEIGHT", TextTable::LEFT, TextTable::RIGHT);
4111 tbl->define_column("REWEIGHT", TextTable::LEFT, TextTable::RIGHT);
4112 tbl->define_column("SIZE", TextTable::LEFT, TextTable::RIGHT);
4113 tbl->define_column("USE", TextTable::LEFT, TextTable::RIGHT);
4114 tbl->define_column("AVAIL", TextTable::LEFT, TextTable::RIGHT);
4115 tbl->define_column("%USE", TextTable::LEFT, TextTable::RIGHT);
4116 tbl->define_column("VAR", TextTable::LEFT, TextTable::RIGHT);
4117 tbl->define_column("PGS", TextTable::LEFT, TextTable::RIGHT);
4118 if (tree)
4119 tbl->define_column("TYPE NAME", TextTable::LEFT, TextTable::LEFT);
4120
4121 Parent::dump(tbl);
4122
4123 dump_stray(tbl);
4124
4125 *tbl << ""
4126 << ""
4127 << "" << "TOTAL"
4128 << si_t(pgs->get_osd_sum().kb << 10)
4129 << si_t(pgs->get_osd_sum().kb_used << 10)
4130 << si_t(pgs->get_osd_sum().kb_avail << 10)
4131 << lowprecision_t(average_util)
4132 << ""
4133 << TextTable::endrow;
4134 }
4135
4136 protected:
4137 struct lowprecision_t {
4138 float v;
4139 explicit lowprecision_t(float _v) : v(_v) {}
4140 };
4141 friend std::ostream &operator<<(ostream& out, const lowprecision_t& v);
4142
4143 using OSDUtilizationDumper<TextTable>::dump_item;
4144 void dump_item(const CrushTreeDumper::Item &qi,
4145 float &reweight,
4146 int64_t kb,
4147 int64_t kb_used,
4148 int64_t kb_avail,
4149 double& util,
4150 double& var,
4151 const size_t num_pgs,
4152 TextTable *tbl) override {
4153 const char *c = crush->get_item_class(qi.id);
4154 if (!c)
4155 c = "";
4156 *tbl << qi.id
4157 << c
4158 << weightf_t(qi.weight)
4159 << weightf_t(reweight)
4160 << si_t(kb << 10)
4161 << si_t(kb_used << 10)
4162 << si_t(kb_avail << 10)
4163 << lowprecision_t(util)
4164 << lowprecision_t(var);
4165
4166 if (qi.is_bucket()) {
4167 *tbl << "-";
4168 } else {
4169 *tbl << num_pgs;
4170 }
4171
4172 if (tree) {
4173 ostringstream name;
4174 for (int k = 0; k < qi.depth; k++)
4175 name << " ";
4176 if (qi.is_bucket()) {
4177 int type = crush->get_bucket_type(qi.id);
4178 name << crush->get_type_name(type) << " "
4179 << crush->get_item_name(qi.id);
4180 } else {
4181 name << "osd." << qi.id;
4182 }
4183 *tbl << name.str();
4184 }
4185
4186 *tbl << TextTable::endrow;
4187 }
4188
4189 public:
4190 string summary() {
4191 ostringstream out;
4192 out << "MIN/MAX VAR: " << lowprecision_t(min_var)
4193 << "/" << lowprecision_t(max_var) << " "
4194 << "STDDEV: " << lowprecision_t(dev());
4195 return out.str();
4196 }
4197 };
4198
4199 ostream& operator<<(ostream& out,
4200 const OSDUtilizationPlainDumper::lowprecision_t& v)
4201 {
4202 if (v.v < -0.01) {
4203 return out << "-";
4204 } else if (v.v < 0.001) {
4205 return out << "0";
4206 } else {
4207 std::streamsize p = out.precision();
4208 return out << std::fixed << std::setprecision(2) << v.v << std::setprecision(p);
4209 }
4210 }
4211
4212 class OSDUtilizationFormatDumper : public OSDUtilizationDumper<Formatter> {
4213 public:
4214 typedef OSDUtilizationDumper<Formatter> Parent;
4215
4216 OSDUtilizationFormatDumper(const CrushWrapper *crush, const OSDMap *osdmap,
4217 const PGStatService *pgs, bool tree) :
4218 Parent(crush, osdmap, pgs, tree) {}
4219
4220 void dump(Formatter *f) {
4221 f->open_array_section("nodes");
4222 Parent::dump(f);
4223 f->close_section();
4224
4225 f->open_array_section("stray");
4226 dump_stray(f);
4227 f->close_section();
4228 }
4229
4230 protected:
4231 using OSDUtilizationDumper<Formatter>::dump_item;
4232 void dump_item(const CrushTreeDumper::Item &qi,
4233 float &reweight,
4234 int64_t kb,
4235 int64_t kb_used,
4236 int64_t kb_avail,
4237 double& util,
4238 double& var,
4239 const size_t num_pgs,
4240 Formatter *f) override {
4241 f->open_object_section("item");
4242 CrushTreeDumper::dump_item_fields(crush, weight_set_names, qi, f);
4243 f->dump_float("reweight", reweight);
4244 f->dump_int("kb", kb);
4245 f->dump_int("kb_used", kb_used);
4246 f->dump_int("kb_avail", kb_avail);
4247 f->dump_float("utilization", util);
4248 f->dump_float("var", var);
4249 f->dump_unsigned("pgs", num_pgs);
4250 CrushTreeDumper::dump_bucket_children(crush, qi, f);
4251 f->close_section();
4252 }
4253
4254 public:
4255 void summary(Formatter *f) {
4256 f->open_object_section("summary");
4257 f->dump_int("total_kb", pgs->get_osd_sum().kb);
4258 f->dump_int("total_kb_used", pgs->get_osd_sum().kb_used);
4259 f->dump_int("total_kb_avail", pgs->get_osd_sum().kb_avail);
4260 f->dump_float("average_utilization", average_util);
4261 f->dump_float("min_var", min_var);
4262 f->dump_float("max_var", max_var);
4263 f->dump_float("dev", dev());
4264 f->close_section();
4265 }
4266 };
4267
4268 void print_osd_utilization(const OSDMap& osdmap,
4269 const PGStatService *pgstat,
4270 ostream& out,
4271 Formatter *f,
4272 bool tree)
4273 {
4274 const CrushWrapper *crush = osdmap.crush.get();
4275 if (f) {
4276 f->open_object_section("df");
4277 OSDUtilizationFormatDumper d(crush, &osdmap, pgstat, tree);
4278 d.dump(f);
4279 d.summary(f);
4280 f->close_section();
4281 f->flush(out);
4282 } else {
4283 OSDUtilizationPlainDumper d(crush, &osdmap, pgstat, tree);
4284 TextTable tbl;
4285 d.dump(&tbl);
4286 out << tbl << d.summary() << "\n";
4287 }
4288 }
4289
4290 void OSDMap::check_health(health_check_map_t *checks) const
4291 {
4292 int num_osds = get_num_osds();
4293
4294 // OSD_DOWN
4295 // OSD_$subtree_DOWN
4296 // OSD_ORPHAN
4297 if (num_osds >= 0) {
4298 int num_in_osds = 0;
4299 int num_down_in_osds = 0;
4300 set<int> osds;
4301 set<int> down_in_osds;
4302 set<int> up_in_osds;
4303 set<int> subtree_up;
4304 unordered_map<int, set<int> > subtree_type_down;
4305 unordered_map<int, int> num_osds_subtree;
4306 int max_type = crush->get_max_type_id();
4307
4308 for (int i = 0; i < get_max_osd(); i++) {
4309 if (!exists(i)) {
4310 if (crush->item_exists(i)) {
4311 osds.insert(i);
4312 }
4313 continue;
4314 }
4315 if (is_out(i))
4316 continue;
4317 ++num_in_osds;
4318 if (down_in_osds.count(i) || up_in_osds.count(i))
4319 continue;
4320 if (!is_up(i)) {
4321 down_in_osds.insert(i);
4322 int parent_id = 0;
4323 int current = i;
4324 for (int type = 0; type <= max_type; type++) {
4325 if (!crush->get_type_name(type))
4326 continue;
4327 int r = crush->get_immediate_parent_id(current, &parent_id);
4328 if (r == -ENOENT)
4329 break;
4330 // break early if this parent is already marked as up
4331 if (subtree_up.count(parent_id))
4332 break;
4333 type = crush->get_bucket_type(parent_id);
4334 if (!subtree_type_is_down(
4335 g_ceph_context, parent_id, type,
4336 &down_in_osds, &up_in_osds, &subtree_up, &subtree_type_down))
4337 break;
4338 current = parent_id;
4339 }
4340 }
4341 }
4342
4343 // calculate the number of down osds in each down subtree and
4344 // store it in num_osds_subtree
4345 for (int type = 1; type <= max_type; type++) {
4346 if (!crush->get_type_name(type))
4347 continue;
4348 for (auto j = subtree_type_down[type].begin();
4349 j != subtree_type_down[type].end();
4350 ++j) {
4351 list<int> children;
4352 int num = 0;
4353 int num_children = crush->get_children(*j, &children);
4354 if (num_children == 0)
4355 continue;
4356 for (auto l = children.begin(); l != children.end(); ++l) {
4357 if (*l >= 0) {
4358 ++num;
4359 } else if (num_osds_subtree[*l] > 0) {
4360 num = num + num_osds_subtree[*l];
4361 }
4362 }
4363 num_osds_subtree[*j] = num;
4364 }
4365 }
4366 num_down_in_osds = down_in_osds.size();
4367 assert(num_down_in_osds <= num_in_osds);
4368 if (num_down_in_osds > 0) {
4369 // summary of down subtree types and osds
4370 for (int type = max_type; type > 0; type--) {
4371 if (!crush->get_type_name(type))
4372 continue;
4373 if (subtree_type_down[type].size() > 0) {
4374 ostringstream ss;
4375 ss << subtree_type_down[type].size() << " "
4376 << crush->get_type_name(type);
4377 if (subtree_type_down[type].size() > 1) {
4378 ss << "s";
4379 }
4380 int sum_down_osds = 0;
4381 for (auto j = subtree_type_down[type].begin();
4382 j != subtree_type_down[type].end();
4383 ++j) {
4384 sum_down_osds = sum_down_osds + num_osds_subtree[*j];
4385 }
4386 ss << " (" << sum_down_osds << " osds) down";
4387 string err = string("OSD_") +
4388 string(crush->get_type_name(type)) + "_DOWN";
4389 boost::to_upper(err);
4390 auto& d = checks->add(err, HEALTH_WARN, ss.str());
4391 for (auto j = subtree_type_down[type].rbegin();
4392 j != subtree_type_down[type].rend();
4393 ++j) {
4394 ostringstream ss;
4395 ss << crush->get_type_name(type);
4396 ss << " ";
4397 ss << crush->get_item_name(*j);
4398 // at the top level, do not print location
4399 if (type != max_type) {
4400 ss << " (";
4401 ss << crush->get_full_location_ordered_string(*j);
4402 ss << ")";
4403 }
4404 int num = num_osds_subtree[*j];
4405 ss << " (" << num << " osds)";
4406 ss << " is down";
4407 d.detail.push_back(ss.str());
4408 }
4409 }
4410 }
4411 ostringstream ss;
4412 ss << down_in_osds.size() << " osds down";
4413 auto& d = checks->add("OSD_DOWN", HEALTH_WARN, ss.str());
4414 for (auto it = down_in_osds.begin(); it != down_in_osds.end(); ++it) {
4415 ostringstream ss;
4416 ss << "osd." << *it << " (";
4417 ss << crush->get_full_location_ordered_string(*it);
4418 ss << ") is down";
4419 d.detail.push_back(ss.str());
4420 }
4421 }
4422
4423 if (!osds.empty()) {
4424 ostringstream ss;
4425 ss << osds.size() << " osds exist in the crush map but not in the osdmap";
4426 auto& d = checks->add("OSD_ORPHAN", HEALTH_WARN, ss.str());
4427 for (auto osd : osds) {
4428 ostringstream ss;
4429 ss << "osd." << osd << " exists in crush map but not in osdmap";
4430 d.detail.push_back(ss.str());
4431 }
4432 }
4433 }
4434
4435 // OSD_OUT_OF_ORDER_FULL
4436 {
4437 // An osd could configure failsafe ratio, to something different
4438 // but for now assume it is the same here.
4439 float fsr = g_conf->osd_failsafe_full_ratio;
4440 if (fsr > 1.0) fsr /= 100;
4441 float fr = get_full_ratio();
4442 float br = get_backfillfull_ratio();
4443 float nr = get_nearfull_ratio();
4444
4445 list<string> detail;
4446 // These checks correspond to how OSDService::check_full_status() in an OSD
4447 // handles the improper setting of these values.
4448 if (br < nr) {
4449 ostringstream ss;
4450 ss << "backfillfull_ratio (" << br
4451 << ") < nearfull_ratio (" << nr << "), increased";
4452 detail.push_back(ss.str());
4453 br = nr;
4454 }
4455 if (fr < br) {
4456 ostringstream ss;
4457 ss << "full_ratio (" << fr << ") < backfillfull_ratio (" << br
4458 << "), increased";
4459 detail.push_back(ss.str());
4460 fr = br;
4461 }
4462 if (fsr < fr) {
4463 ostringstream ss;
4464 ss << "osd_failsafe_full_ratio (" << fsr << ") < full_ratio (" << fr
4465 << "), increased";
4466 detail.push_back(ss.str());
4467 }
4468 if (!detail.empty()) {
4469 auto& d = checks->add("OSD_OUT_OF_ORDER_FULL", HEALTH_ERR,
4470 "full ratio(s) out of order");
4471 d.detail.swap(detail);
4472 }
4473 }
4474
4475 // OSD_FULL
4476 // OSD_NEARFULL
4477 // OSD_BACKFILLFULL
4478 // OSD_FAILSAFE_FULL
4479 {
4480 set<int> full, backfillfull, nearfull;
4481 get_full_osd_counts(&full, &backfillfull, &nearfull);
4482 if (full.size()) {
4483 ostringstream ss;
4484 ss << full.size() << " full osd(s)";
4485 auto& d = checks->add("OSD_FULL", HEALTH_ERR, ss.str());
4486 for (auto& i: full) {
4487 ostringstream ss;
4488 ss << "osd." << i << " is full";
4489 d.detail.push_back(ss.str());
4490 }
4491 }
4492 if (backfillfull.size()) {
4493 ostringstream ss;
4494 ss << backfillfull.size() << " backfillfull osd(s)";
4495 auto& d = checks->add("OSD_BACKFILLFULL", HEALTH_WARN, ss.str());
4496 for (auto& i: backfillfull) {
4497 ostringstream ss;
4498 ss << "osd." << i << " is backfill full";
4499 d.detail.push_back(ss.str());
4500 }
4501 }
4502 if (nearfull.size()) {
4503 ostringstream ss;
4504 ss << nearfull.size() << " nearfull osd(s)";
4505 auto& d = checks->add("OSD_NEARFULL", HEALTH_WARN, ss.str());
4506 for (auto& i: nearfull) {
4507 ostringstream ss;
4508 ss << "osd." << i << " is near full";
4509 d.detail.push_back(ss.str());
4510 }
4511 }
4512 }
4513
4514 // OSDMAP_FLAGS
4515 {
4516 // warn about flags
4517 uint64_t warn_flags =
4518 CEPH_OSDMAP_FULL |
4519 CEPH_OSDMAP_PAUSERD |
4520 CEPH_OSDMAP_PAUSEWR |
4521 CEPH_OSDMAP_PAUSEREC |
4522 CEPH_OSDMAP_NOUP |
4523 CEPH_OSDMAP_NODOWN |
4524 CEPH_OSDMAP_NOIN |
4525 CEPH_OSDMAP_NOOUT |
4526 CEPH_OSDMAP_NOBACKFILL |
4527 CEPH_OSDMAP_NORECOVER |
4528 CEPH_OSDMAP_NOSCRUB |
4529 CEPH_OSDMAP_NODEEP_SCRUB |
4530 CEPH_OSDMAP_NOTIERAGENT |
4531 CEPH_OSDMAP_NOREBALANCE;
4532 if (test_flag(warn_flags)) {
4533 ostringstream ss;
4534 ss << get_flag_string(get_flags() & warn_flags)
4535 << " flag(s) set";
4536 checks->add("OSDMAP_FLAGS", HEALTH_WARN, ss.str());
4537 }
4538 }
4539
4540 // OSD_FLAGS
4541 {
4542 list<string> detail;
4543 const unsigned flags =
4544 CEPH_OSD_NOUP |
4545 CEPH_OSD_NOIN |
4546 CEPH_OSD_NODOWN |
4547 CEPH_OSD_NOOUT;
4548 for (int i = 0; i < max_osd; ++i) {
4549 if (osd_state[i] & flags) {
4550 ostringstream ss;
4551 set<string> states;
4552 OSDMap::calc_state_set(osd_state[i] & flags, states);
4553 ss << "osd." << i << " has flags " << states;
4554 detail.push_back(ss.str());
4555 }
4556 }
4557 if (!detail.empty()) {
4558 ostringstream ss;
4559 ss << detail.size() << " osd(s) have {NOUP,NODOWN,NOIN,NOOUT} flags set";
4560 auto& d = checks->add("OSD_FLAGS", HEALTH_WARN, ss.str());
4561 d.detail.swap(detail);
4562 }
4563 }
4564
4565 // OLD_CRUSH_TUNABLES
4566 if (g_conf->mon_warn_on_legacy_crush_tunables) {
4567 string min = crush->get_min_required_version();
4568 if (min < g_conf->mon_crush_min_required_version) {
4569 ostringstream ss;
4570 ss << "crush map has legacy tunables (require " << min
4571 << ", min is " << g_conf->mon_crush_min_required_version << ")";
4572 auto& d = checks->add("OLD_CRUSH_TUNABLES", HEALTH_WARN, ss.str());
4573 d.detail.push_back("see http://docs.ceph.com/docs/master/rados/operations/crush-map/#tunables");
4574 }
4575 }
4576
4577 // OLD_CRUSH_STRAW_CALC_VERSION
4578 if (g_conf->mon_warn_on_crush_straw_calc_version_zero) {
4579 if (crush->get_straw_calc_version() == 0) {
4580 ostringstream ss;
4581 ss << "crush map has straw_calc_version=0";
4582 auto& d = checks->add("OLD_CRUSH_STRAW_CALC_VERSION", HEALTH_WARN, ss.str());
4583 d.detail.push_back(
4584 "see http://docs.ceph.com/docs/master/rados/operations/crush-map/#tunables");
4585 }
4586 }
4587
4588 // CACHE_POOL_NO_HIT_SET
4589 if (g_conf->mon_warn_on_cache_pools_without_hit_sets) {
4590 list<string> detail;
4591 for (map<int64_t, pg_pool_t>::const_iterator p = pools.begin();
4592 p != pools.end();
4593 ++p) {
4594 const pg_pool_t& info = p->second;
4595 if (info.cache_mode_requires_hit_set() &&
4596 info.hit_set_params.get_type() == HitSet::TYPE_NONE) {
4597 ostringstream ss;
4598 ss << "pool '" << get_pool_name(p->first)
4599 << "' with cache_mode " << info.get_cache_mode_name()
4600 << " needs hit_set_type to be set but it is not";
4601 detail.push_back(ss.str());
4602 }
4603 }
4604 if (!detail.empty()) {
4605 ostringstream ss;
4606 ss << detail.size() << " cache pools are missing hit_sets";
4607 auto& d = checks->add("CACHE_POOL_NO_HIT_SET", HEALTH_WARN, ss.str());
4608 d.detail.swap(detail);
4609 }
4610 }
4611
4612 // OSD_NO_SORTBITWISE
4613 if (!test_flag(CEPH_OSDMAP_SORTBITWISE) &&
4614 (get_up_osd_features() &
4615 CEPH_FEATURE_OSD_BITWISE_HOBJ_SORT)) {
4616 ostringstream ss;
4617 ss << "no legacy OSD present but 'sortbitwise' flag is not set";
4618 checks->add("OSD_NO_SORTBITWISE", HEALTH_WARN, ss.str());
4619 }
4620
4621 // OSD_UPGRADE_FINISHED
4622 // none of these (yet) since we don't run until luminous upgrade is done.
4623
4624 // POOL_FULL
4625 {
4626 list<string> detail;
4627 for (auto it : get_pools()) {
4628 const pg_pool_t &pool = it.second;
4629 if (pool.has_flag(pg_pool_t::FLAG_FULL)) {
4630 const string& pool_name = get_pool_name(it.first);
4631 stringstream ss;
4632 ss << "pool '" << pool_name << "' is full";
4633 detail.push_back(ss.str());
4634 }
4635 }
4636 if (!detail.empty()) {
4637 ostringstream ss;
4638 ss << detail.size() << " pool(s) full";
4639 auto& d = checks->add("POOL_FULL", HEALTH_WARN, ss.str());
4640 d.detail.swap(detail);
4641 }
4642 }
4643 }