]> git.proxmox.com Git - ceph.git/blob - ceph/src/osd/OSDMap.h
update sources to 12.2.7
[ceph.git] / ceph / src / osd / OSDMap.h
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
19 #ifndef CEPH_OSDMAP_H
20 #define CEPH_OSDMAP_H
21
22 /*
23 * describe properties of the OSD cluster.
24 * disks, disk groups, total # osds,
25 *
26 */
27 #include "include/types.h"
28 #include "osd_types.h"
29
30 //#include "include/ceph_features.h"
31 #include "crush/CrushWrapper.h"
32 #include <vector>
33 #include <list>
34 #include <set>
35 #include <map>
36 #include "include/memory.h"
37 #include "include/btree_map.h"
38 using namespace std;
39
40 // forward declaration
41 class CephContext;
42 class CrushWrapper;
43 class health_check_map_t;
44
45 // FIXME C++11 does not have std::equal for two differently-typed containers.
46 // use this until we move to c++14
47 template<typename A, typename B>
48 bool vectors_equal(A a, B b)
49 {
50 return
51 a.size() == b.size() &&
52 (a.empty() ||
53 memcmp((char*)&a[0], (char*)&b[0], sizeof(a[0]) * a.size()) == 0);
54 }
55
56
57 /*
58 * we track up to two intervals during which the osd was alive and
59 * healthy. the most recent is [up_from,up_thru), where up_thru is
60 * the last epoch the osd is known to have _started_. i.e., a lower
61 * bound on the actual osd death. down_at (if it is > up_from) is an
62 * upper bound on the actual osd death.
63 *
64 * the second is the last_clean interval [first,last]. in that case,
65 * the last interval is the last epoch known to have been either
66 * _finished_, or during which the osd cleanly shut down. when
67 * possible, we push this forward to the epoch the osd was eventually
68 * marked down.
69 *
70 * the lost_at is used to allow build_prior to proceed without waiting
71 * for an osd to recover. In certain cases, progress may be blocked
72 * because an osd is down that may contain updates (i.e., a pg may have
73 * gone rw during an interval). If the osd can't be brought online, we
74 * can force things to proceed knowing that we _might_ be losing some
75 * acked writes. If the osd comes back to life later, that's fine to,
76 * but those writes will still be lost (the divergent objects will be
77 * thrown out).
78 */
79 struct osd_info_t {
80 epoch_t last_clean_begin; // last interval that ended with a clean osd shutdown
81 epoch_t last_clean_end;
82 epoch_t up_from; // epoch osd marked up
83 epoch_t up_thru; // lower bound on actual osd death (if > up_from)
84 epoch_t down_at; // upper bound on actual osd death (if > up_from)
85 epoch_t lost_at; // last epoch we decided data was "lost"
86
87 osd_info_t() : last_clean_begin(0), last_clean_end(0),
88 up_from(0), up_thru(0), down_at(0), lost_at(0) {}
89
90 void dump(Formatter *f) const;
91 void encode(bufferlist& bl) const;
92 void decode(bufferlist::iterator& bl);
93 static void generate_test_instances(list<osd_info_t*>& o);
94 };
95 WRITE_CLASS_ENCODER(osd_info_t)
96
97 ostream& operator<<(ostream& out, const osd_info_t& info);
98
99 struct osd_xinfo_t {
100 utime_t down_stamp; ///< timestamp when we were last marked down
101 float laggy_probability; ///< encoded as __u32: 0 = definitely not laggy, 0xffffffff definitely laggy
102 __u32 laggy_interval; ///< average interval between being marked laggy and recovering
103 uint64_t features; ///< features supported by this osd we should know about
104 __u32 old_weight; ///< weight prior to being auto marked out
105
106 osd_xinfo_t() : laggy_probability(0), laggy_interval(0),
107 features(0), old_weight(0) {}
108
109 void dump(Formatter *f) const;
110 void encode(bufferlist& bl) const;
111 void decode(bufferlist::iterator& bl);
112 static void generate_test_instances(list<osd_xinfo_t*>& o);
113 };
114 WRITE_CLASS_ENCODER(osd_xinfo_t)
115
116 ostream& operator<<(ostream& out, const osd_xinfo_t& xi);
117
118
119 struct PGTempMap {
120 #if 1
121 bufferlist data;
122 typedef btree::btree_map<pg_t,int32_t*> map_t;
123 map_t map;
124
125 void encode(bufferlist& bl) const {
126 uint32_t n = map.size();
127 ::encode(n, bl);
128 for (auto &p : map) {
129 ::encode(p.first, bl);
130 bl.append((char*)p.second, (*p.second + 1) * sizeof(int32_t));
131 }
132 }
133 void decode(bufferlist::iterator& p) {
134 data.clear();
135 map.clear();
136 uint32_t n;
137 ::decode(n, p);
138 if (!n)
139 return;
140 bufferlist::iterator pstart = p;
141 size_t start_off = pstart.get_off();
142 vector<pair<pg_t,size_t>> offsets;
143 offsets.resize(n);
144 for (unsigned i=0; i<n; ++i) {
145 pg_t pgid;
146 ::decode(pgid, p);
147 offsets[i].first = pgid;
148 offsets[i].second = p.get_off() - start_off;
149 uint32_t vn;
150 ::decode(vn, p);
151 p.advance(vn * sizeof(int32_t));
152 }
153 size_t len = p.get_off() - start_off;
154 pstart.copy(len, data);
155 if (data.get_num_buffers() > 1) {
156 data.rebuild();
157 }
158 //map.reserve(n);
159 char *start = data.c_str();
160 for (auto i : offsets) {
161 map.insert(map.end(), make_pair(i.first, (int32_t*)(start + i.second)));
162 }
163 }
164 void rebuild() {
165 bufferlist bl;
166 encode(bl);
167 auto p = bl.begin();
168 decode(p);
169 }
170 friend bool operator==(const PGTempMap& l, const PGTempMap& r) {
171 return
172 l.map.size() == r.map.size() &&
173 l.data.contents_equal(r.data);
174 }
175
176 class iterator {
177 map_t::const_iterator it;
178 map_t::const_iterator end;
179 pair<pg_t,vector<int32_t>> current;
180 void init_current() {
181 if (it != end) {
182 current.first = it->first;
183 assert(it->second);
184 current.second.resize(*it->second);
185 int32_t *p = it->second + 1;
186 for (int n = 0; n < *it->second; ++n, ++p) {
187 current.second[n] = *p;
188 }
189 }
190 }
191 public:
192 iterator(map_t::const_iterator p,
193 map_t::const_iterator e)
194 : it(p), end(e) {
195 init_current();
196 }
197
198 const pair<pg_t,vector<int32_t>>& operator*() const {
199 return current;
200 }
201 const pair<pg_t,vector<int32_t>>* operator->() const {
202 return &current;
203 }
204 friend bool operator==(const iterator& l, const iterator& r) {
205 return l.it == r.it;
206 }
207 friend bool operator!=(const iterator& l, const iterator& r) {
208 return l.it != r.it;
209 }
210 iterator& operator++() {
211 ++it;
212 if (it != end)
213 init_current();
214 return *this;
215 }
216 iterator operator++(int) {
217 iterator r = *this;
218 ++it;
219 if (it != end)
220 init_current();
221 return r;
222 }
223 };
224 iterator begin() const {
225 return iterator(map.begin(), map.end());
226 }
227 iterator end() const {
228 return iterator(map.end(), map.end());
229 }
230 iterator find(pg_t pgid) const {
231 return iterator(map.find(pgid), map.end());
232 }
233 size_t size() const {
234 return map.size();
235 }
236 size_t count(pg_t pgid) const {
237 return map.count(pgid);
238 }
239 void erase(pg_t pgid) {
240 map.erase(pgid);
241 }
242 void clear() {
243 map.clear();
244 data.clear();
245 }
246 void set(pg_t pgid, const mempool::osdmap::vector<int32_t>& v) {
247 size_t need = sizeof(int32_t) * (1 + v.size());
248 if (need < data.get_append_buffer_unused_tail_length()) {
249 bufferptr z(data.get_append_buffer_unused_tail_length());
250 z.zero();
251 data.append(z.c_str(), z.length());
252 }
253 ::encode(v, data);
254 map[pgid] = (int32_t*)(data.back().end_c_str()) - (1 + v.size());
255 }
256 mempool::osdmap::vector<int32_t> get(pg_t pgid) {
257 mempool::osdmap::vector<int32_t> v;
258 int32_t *p = map[pgid];
259 size_t n = *p++;
260 v.resize(n);
261 for (size_t i = 0; i < n; ++i, ++p) {
262 v[i] = *p;
263 }
264 return v;
265 }
266 #else
267 // trivial implementation
268 mempool::osdmap::map<pg_t,mempool::osdmap::vector<int32_t> > pg_temp;
269
270 void encode(bufferlist& bl) const {
271 ::encode(pg_temp, bl);
272 }
273 void decode(bufferlist::iterator& p) {
274 ::decode(pg_temp, p);
275 }
276 friend bool operator==(const PGTempMap& l, const PGTempMap& r) {
277 return
278 l.pg_temp.size() == r.pg_temp.size() &&
279 l.pg_temp == r.pg_temp;
280 }
281
282 class iterator {
283 mempool::osdmap::map<pg_t,mempool::osdmap::vector<int32_t> >::const_iterator it;
284 public:
285 iterator(mempool::osdmap::map<pg_t,
286 mempool::osdmap::vector<int32_t> >::const_iterator p)
287 : it(p) {}
288
289 pair<pg_t,const mempool::osdmap::vector<int32_t>&> operator*() const {
290 return *it;
291 }
292 const pair<const pg_t,mempool::osdmap::vector<int32_t>>* operator->() const {
293 return &*it;
294 }
295 friend bool operator==(const iterator& l, const iterator& r) {
296 return l.it == r.it;
297 }
298 friend bool operator!=(const iterator& l, const iterator& r) {
299 return l.it != r.it;
300 }
301 iterator& operator++() {
302 ++it;
303 return *this;
304 }
305 iterator operator++(int) {
306 iterator r = *this;
307 ++it;
308 return r;
309 }
310 };
311 iterator begin() const {
312 return iterator(pg_temp.cbegin());
313 }
314 iterator end() const {
315 return iterator(pg_temp.cend());
316 }
317 iterator find(pg_t pgid) const {
318 return iterator(pg_temp.find(pgid));
319 }
320 size_t size() const {
321 return pg_temp.size();
322 }
323 size_t count(pg_t pgid) const {
324 return pg_temp.count(pgid);
325 }
326 void erase(pg_t pgid) {
327 pg_temp.erase(pgid);
328 }
329 void clear() {
330 pg_temp.clear();
331 }
332 void set(pg_t pgid, const mempool::osdmap::vector<int32_t>& v) {
333 pg_temp[pgid] = v;
334 }
335 const mempool::osdmap::vector<int32_t>& get(pg_t pgid) {
336 return pg_temp.at(pgid);
337 }
338 #endif
339 void dump(Formatter *f) const {
340 for (const auto &pg : *this) {
341 f->open_object_section("osds");
342 f->dump_stream("pgid") << pg.first;
343 f->open_array_section("osds");
344 for (const auto osd : pg.second)
345 f->dump_int("osd", osd);
346 f->close_section();
347 f->close_section();
348 }
349 }
350 };
351 WRITE_CLASS_ENCODER(PGTempMap)
352
353 /** OSDMap
354 */
355 class OSDMap {
356 public:
357 MEMPOOL_CLASS_HELPERS();
358
359 class Incremental {
360 public:
361 MEMPOOL_CLASS_HELPERS();
362
363 /// feature bits we were encoded with. the subsequent OSDMap
364 /// encoding should match.
365 uint64_t encode_features;
366 uuid_d fsid;
367 epoch_t epoch; // new epoch; we are a diff from epoch-1 to epoch
368 utime_t modified;
369 int64_t new_pool_max; //incremented by the OSDMonitor on each pool create
370 int32_t new_flags;
371 int8_t new_require_osd_release = -1;
372
373 // full (rare)
374 bufferlist fullmap; // in lieu of below.
375 bufferlist crush;
376
377 // incremental
378 int32_t new_max_osd;
379 mempool::osdmap::map<int64_t,pg_pool_t> new_pools;
380 mempool::osdmap::map<int64_t,string> new_pool_names;
381 mempool::osdmap::set<int64_t> old_pools;
382 mempool::osdmap::map<string,map<string,string> > new_erasure_code_profiles;
383 mempool::osdmap::vector<string> old_erasure_code_profiles;
384 mempool::osdmap::map<int32_t,entity_addr_t> new_up_client;
385 mempool::osdmap::map<int32_t,entity_addr_t> new_up_cluster;
386 mempool::osdmap::map<int32_t,uint32_t> new_state; // XORed onto previous state.
387 mempool::osdmap::map<int32_t,uint32_t> new_weight;
388 mempool::osdmap::map<pg_t,mempool::osdmap::vector<int32_t> > new_pg_temp; // [] to remove
389 mempool::osdmap::map<pg_t, int32_t> new_primary_temp; // [-1] to remove
390 mempool::osdmap::map<int32_t,uint32_t> new_primary_affinity;
391 mempool::osdmap::map<int32_t,epoch_t> new_up_thru;
392 mempool::osdmap::map<int32_t,pair<epoch_t,epoch_t> > new_last_clean_interval;
393 mempool::osdmap::map<int32_t,epoch_t> new_lost;
394 mempool::osdmap::map<int32_t,uuid_d> new_uuid;
395 mempool::osdmap::map<int32_t,osd_xinfo_t> new_xinfo;
396
397 mempool::osdmap::map<entity_addr_t,utime_t> new_blacklist;
398 mempool::osdmap::vector<entity_addr_t> old_blacklist;
399 mempool::osdmap::map<int32_t, entity_addr_t> new_hb_back_up;
400 mempool::osdmap::map<int32_t, entity_addr_t> new_hb_front_up;
401
402 mempool::osdmap::map<pg_t,mempool::osdmap::vector<int32_t>> new_pg_upmap;
403 mempool::osdmap::map<pg_t,mempool::osdmap::vector<pair<int32_t,int32_t>>> new_pg_upmap_items;
404 mempool::osdmap::set<pg_t> old_pg_upmap, old_pg_upmap_items;
405
406 string cluster_snapshot;
407
408 float new_nearfull_ratio = -1;
409 float new_backfillfull_ratio = -1;
410 float new_full_ratio = -1;
411
412 int8_t new_require_min_compat_client = -1;
413
414 mutable bool have_crc; ///< crc values are defined
415 uint32_t full_crc; ///< crc of the resulting OSDMap
416 mutable uint32_t inc_crc; ///< crc of this incremental
417
418 int get_net_marked_out(const OSDMap *previous) const;
419 int get_net_marked_down(const OSDMap *previous) const;
420 int identify_osd(uuid_d u) const;
421
422 void encode_client_old(bufferlist& bl) const;
423 void encode_classic(bufferlist& bl, uint64_t features) const;
424 void encode(bufferlist& bl, uint64_t features=CEPH_FEATURES_ALL) const;
425 void decode_classic(bufferlist::iterator &p);
426 void decode(bufferlist::iterator &bl);
427 void dump(Formatter *f) const;
428 static void generate_test_instances(list<Incremental*>& o);
429
430 explicit Incremental(epoch_t e=0) :
431 encode_features(0),
432 epoch(e), new_pool_max(-1), new_flags(-1), new_max_osd(-1),
433 have_crc(false), full_crc(0), inc_crc(0) {
434 memset(&fsid, 0, sizeof(fsid));
435 }
436 explicit Incremental(bufferlist &bl) {
437 bufferlist::iterator p = bl.begin();
438 decode(p);
439 }
440 explicit Incremental(bufferlist::iterator &p) {
441 decode(p);
442 }
443
444 pg_pool_t *get_new_pool(int64_t pool, const pg_pool_t *orig) {
445 if (new_pools.count(pool) == 0)
446 new_pools[pool] = *orig;
447 return &new_pools[pool];
448 }
449 bool has_erasure_code_profile(const string &name) const {
450 auto i = new_erasure_code_profiles.find(name);
451 return i != new_erasure_code_profiles.end();
452 }
453 void set_erasure_code_profile(const string &name,
454 const map<string,string>& profile) {
455 new_erasure_code_profiles[name] = profile;
456 }
457
458 /// propage update pools' snap metadata to any of their tiers
459 int propagate_snaps_to_tiers(CephContext *cct, const OSDMap &base);
460
461 /// filter out osds with any pending state changing
462 size_t get_pending_state_osds(vector<int> *osds) {
463 assert(osds);
464 osds->clear();
465
466 for (auto &p : new_state) {
467 osds->push_back(p.first);
468 }
469
470 return osds->size();
471 }
472
473 bool pending_osd_has_state(int osd, unsigned state) {
474 return new_state.count(osd) && (new_state[osd] & state) != 0;
475 }
476
477 void pending_osd_state_set(int osd, unsigned state) {
478 new_state[osd] |= state;
479 }
480
481 // cancel the specified pending osd state if there is any
482 // return ture on success, false otherwise.
483 bool pending_osd_state_clear(int osd, unsigned state) {
484 if (!pending_osd_has_state(osd, state)) {
485 // never has been set or already has been cancelled.
486 return false;
487 }
488
489 new_state[osd] &= ~state;
490 return true;
491 }
492
493 };
494
495 private:
496 uuid_d fsid;
497 epoch_t epoch; // what epoch of the osd cluster descriptor is this
498 utime_t created, modified; // epoch start time
499 int32_t pool_max; // the largest pool num, ever
500
501 uint32_t flags;
502
503 int num_osd; // not saved; see calc_num_osds
504 int num_up_osd; // not saved; see calc_num_osds
505 int num_in_osd; // not saved; see calc_num_osds
506
507 int32_t max_osd;
508 vector<uint32_t> osd_state;
509
510 // These features affect OSDMap[::Incremental] encoding, or the
511 // encoding of some type embedded therein (CrushWrapper, something
512 // from osd_types, etc.).
513 static constexpr uint64_t SIGNIFICANT_FEATURES =
514 CEPH_FEATUREMASK_PGID64 |
515 CEPH_FEATUREMASK_PGPOOL3 |
516 CEPH_FEATUREMASK_OSDENC |
517 CEPH_FEATUREMASK_OSDMAP_ENC |
518 CEPH_FEATUREMASK_OSD_POOLRESEND |
519 CEPH_FEATUREMASK_NEW_OSDOP_ENCODING |
520 CEPH_FEATUREMASK_MSG_ADDR2 |
521 CEPH_FEATUREMASK_CRUSH_TUNABLES5 |
522 CEPH_FEATUREMASK_CRUSH_CHOOSE_ARGS |
523 CEPH_FEATUREMASK_SERVER_LUMINOUS ;
524 struct addrs_s {
525 mempool::osdmap::vector<ceph::shared_ptr<entity_addr_t> > client_addr;
526 mempool::osdmap::vector<ceph::shared_ptr<entity_addr_t> > cluster_addr;
527 mempool::osdmap::vector<ceph::shared_ptr<entity_addr_t> > hb_back_addr;
528 mempool::osdmap::vector<ceph::shared_ptr<entity_addr_t> > hb_front_addr;
529 entity_addr_t blank;
530 };
531 ceph::shared_ptr<addrs_s> osd_addrs;
532
533 mempool::osdmap::vector<__u32> osd_weight; // 16.16 fixed point, 0x10000 = "in", 0 = "out"
534 mempool::osdmap::vector<osd_info_t> osd_info;
535 ceph::shared_ptr<PGTempMap> pg_temp; // temp pg mapping (e.g. while we rebuild)
536 ceph::shared_ptr< mempool::osdmap::map<pg_t,int32_t > > primary_temp; // temp primary mapping (e.g. while we rebuild)
537 ceph::shared_ptr< mempool::osdmap::vector<__u32> > osd_primary_affinity; ///< 16.16 fixed point, 0x10000 = baseline
538
539 // remap (post-CRUSH, pre-up)
540 mempool::osdmap::map<pg_t,mempool::osdmap::vector<int32_t>> pg_upmap; ///< remap pg
541 mempool::osdmap::map<pg_t,mempool::osdmap::vector<pair<int32_t,int32_t>>> pg_upmap_items; ///< remap osds in up set
542
543 mempool::osdmap::map<int64_t,pg_pool_t> pools;
544 mempool::osdmap::map<int64_t,string> pool_name;
545 mempool::osdmap::map<string,map<string,string> > erasure_code_profiles;
546 mempool::osdmap::map<string,int64_t> name_pool;
547
548 ceph::shared_ptr< mempool::osdmap::vector<uuid_d> > osd_uuid;
549 mempool::osdmap::vector<osd_xinfo_t> osd_xinfo;
550
551 mempool::osdmap::unordered_map<entity_addr_t,utime_t> blacklist;
552
553 epoch_t cluster_snapshot_epoch;
554 string cluster_snapshot;
555 bool new_blacklist_entries;
556
557 float full_ratio = 0, backfillfull_ratio = 0, nearfull_ratio = 0;
558
559 /// min compat client we want to support
560 uint8_t require_min_compat_client = 0; // CEPH_RELEASE_*
561
562 public:
563 /// require osds to run at least this release
564 uint8_t require_osd_release = 0; // CEPH_RELEASE_*
565
566 private:
567 mutable uint64_t cached_up_osd_features;
568
569 mutable bool crc_defined;
570 mutable uint32_t crc;
571
572 void _calc_up_osd_features();
573
574 public:
575 bool have_crc() const { return crc_defined; }
576 uint32_t get_crc() const { return crc; }
577
578 ceph::shared_ptr<CrushWrapper> crush; // hierarchical map
579 private:
580 uint32_t crush_version = 1;
581
582 friend class OSDMonitor;
583
584 public:
585 OSDMap() : epoch(0),
586 pool_max(0),
587 flags(0),
588 num_osd(0), num_up_osd(0), num_in_osd(0),
589 max_osd(0),
590 osd_addrs(std::make_shared<addrs_s>()),
591 pg_temp(std::make_shared<PGTempMap>()),
592 primary_temp(std::make_shared<mempool::osdmap::map<pg_t,int32_t>>()),
593 osd_uuid(std::make_shared<mempool::osdmap::vector<uuid_d>>()),
594 cluster_snapshot_epoch(0),
595 new_blacklist_entries(false),
596 cached_up_osd_features(0),
597 crc_defined(false), crc(0),
598 crush(std::make_shared<CrushWrapper>()) {
599 memset(&fsid, 0, sizeof(fsid));
600 }
601
602 // no copying
603 private:
604 OSDMap(const OSDMap& other) = default;
605 OSDMap& operator=(const OSDMap& other) = default;
606 public:
607
608 /// return feature mask subset that is relevant to OSDMap encoding
609 static uint64_t get_significant_features(uint64_t features) {
610 return SIGNIFICANT_FEATURES & features;
611 }
612
613 uint64_t get_encoding_features() const;
614
615 void deepish_copy_from(const OSDMap& o) {
616 *this = o;
617 primary_temp.reset(new mempool::osdmap::map<pg_t,int32_t>(*o.primary_temp));
618 pg_temp.reset(new PGTempMap(*o.pg_temp));
619 osd_uuid.reset(new mempool::osdmap::vector<uuid_d>(*o.osd_uuid));
620
621 if (o.osd_primary_affinity)
622 osd_primary_affinity.reset(new mempool::osdmap::vector<__u32>(*o.osd_primary_affinity));
623
624 // NOTE: this still references shared entity_addr_t's.
625 osd_addrs.reset(new addrs_s(*o.osd_addrs));
626
627 // NOTE: we do not copy crush. note that apply_incremental will
628 // allocate a new CrushWrapper, though.
629 }
630
631 // map info
632 const uuid_d& get_fsid() const { return fsid; }
633 void set_fsid(uuid_d& f) { fsid = f; }
634
635 epoch_t get_epoch() const { return epoch; }
636 void inc_epoch() { epoch++; }
637
638 void set_epoch(epoch_t e);
639
640 uint32_t get_crush_version() const {
641 return crush_version;
642 }
643
644 /* stamps etc */
645 const utime_t& get_created() const { return created; }
646 const utime_t& get_modified() const { return modified; }
647
648 bool is_blacklisted(const entity_addr_t& a) const;
649 void get_blacklist(list<pair<entity_addr_t,utime_t > > *bl) const;
650 void get_blacklist(std::set<entity_addr_t> *bl) const;
651
652 string get_cluster_snapshot() const {
653 if (cluster_snapshot_epoch == epoch)
654 return cluster_snapshot;
655 return string();
656 }
657
658 float get_full_ratio() const {
659 return full_ratio;
660 }
661 float get_backfillfull_ratio() const {
662 return backfillfull_ratio;
663 }
664 float get_nearfull_ratio() const {
665 return nearfull_ratio;
666 }
667 void get_full_osd_util(
668 const mempool::pgmap::unordered_map<int32_t,osd_stat_t> &osd_stat,
669 map<int, float> *full,
670 map<int, float> *backfill,
671 map<int, float> *nearfull) const;
672 void get_full_pools(CephContext *cct,
673 set<int64_t> *full,
674 set<int64_t> *backfillfull,
675 set<int64_t> *nearfull) const;
676 void get_full_osd_counts(set<int> *full, set<int> *backfill,
677 set<int> *nearfull) const;
678
679
680 /***** cluster state *****/
681 /* osds */
682 int get_max_osd() const { return max_osd; }
683 void set_max_osd(int m);
684
685 unsigned get_num_osds() const {
686 return num_osd;
687 }
688 unsigned get_num_up_osds() const {
689 return num_up_osd;
690 }
691 unsigned get_num_in_osds() const {
692 return num_in_osd;
693 }
694 /// recalculate cached values for get_num{,_up,_in}_osds
695 int calc_num_osds();
696
697 void get_all_osds(set<int32_t>& ls) const;
698 void get_up_osds(set<int32_t>& ls) const;
699 void get_out_osds(set<int32_t>& ls) const;
700 unsigned get_num_pg_temp() const {
701 return pg_temp->size();
702 }
703
704 int get_flags() const { return flags; }
705 bool test_flag(int f) const { return flags & f; }
706 void set_flag(int f) { flags |= f; }
707 void clear_flag(int f) { flags &= ~f; }
708
709 static void calc_state_set(int state, set<string>& st);
710
711 int get_state(int o) const {
712 assert(o < max_osd);
713 return osd_state[o];
714 }
715 int get_state(int o, set<string>& st) const {
716 assert(o < max_osd);
717 unsigned t = osd_state[o];
718 calc_state_set(t, st);
719 return osd_state[o];
720 }
721 void set_state(int o, unsigned s) {
722 assert(o < max_osd);
723 osd_state[o] = s;
724 }
725 void set_weight(int o, unsigned w) {
726 assert(o < max_osd);
727 osd_weight[o] = w;
728 if (w)
729 osd_state[o] |= CEPH_OSD_EXISTS;
730 }
731 unsigned get_weight(int o) const {
732 assert(o < max_osd);
733 return osd_weight[o];
734 }
735 float get_weightf(int o) const {
736 return (float)get_weight(o) / (float)CEPH_OSD_IN;
737 }
738 void adjust_osd_weights(const map<int,double>& weights, Incremental& inc) const;
739
740 void set_primary_affinity(int o, int w) {
741 assert(o < max_osd);
742 if (!osd_primary_affinity)
743 osd_primary_affinity.reset(
744 new mempool::osdmap::vector<__u32>(
745 max_osd, CEPH_OSD_DEFAULT_PRIMARY_AFFINITY));
746 (*osd_primary_affinity)[o] = w;
747 }
748 unsigned get_primary_affinity(int o) const {
749 assert(o < max_osd);
750 if (!osd_primary_affinity)
751 return CEPH_OSD_DEFAULT_PRIMARY_AFFINITY;
752 return (*osd_primary_affinity)[o];
753 }
754 float get_primary_affinityf(int o) const {
755 return (float)get_primary_affinity(o) / (float)CEPH_OSD_MAX_PRIMARY_AFFINITY;
756 }
757
758 bool has_erasure_code_profile(const string &name) const {
759 auto i = erasure_code_profiles.find(name);
760 return i != erasure_code_profiles.end();
761 }
762 int get_erasure_code_profile_default(CephContext *cct,
763 map<string,string> &profile_map,
764 ostream *ss);
765 void set_erasure_code_profile(const string &name,
766 const map<string,string>& profile) {
767 erasure_code_profiles[name] = profile;
768 }
769 const map<string,string> &get_erasure_code_profile(
770 const string &name) const {
771 static map<string,string> empty;
772 auto i = erasure_code_profiles.find(name);
773 if (i == erasure_code_profiles.end())
774 return empty;
775 else
776 return i->second;
777 }
778 const mempool::osdmap::map<string,map<string,string> > &get_erasure_code_profiles() const {
779 return erasure_code_profiles;
780 }
781
782 bool exists(int osd) const {
783 //assert(osd >= 0);
784 return osd >= 0 && osd < max_osd && (osd_state[osd] & CEPH_OSD_EXISTS);
785 }
786
787 bool is_destroyed(int osd) const {
788 return exists(osd) && (osd_state[osd] & CEPH_OSD_DESTROYED);
789 }
790
791 bool is_up(int osd) const {
792 return exists(osd) && (osd_state[osd] & CEPH_OSD_UP);
793 }
794
795 bool has_been_up_since(int osd, epoch_t epoch) const {
796 return is_up(osd) && get_up_from(osd) <= epoch;
797 }
798
799 bool is_down(int osd) const {
800 return !is_up(osd);
801 }
802
803 bool is_out(int osd) const {
804 return !exists(osd) || get_weight(osd) == CEPH_OSD_OUT;
805 }
806
807 bool is_in(int osd) const {
808 return !is_out(osd);
809 }
810
811 bool is_noup(int osd) const {
812 return exists(osd) && (osd_state[osd] & CEPH_OSD_NOUP);
813 }
814
815 bool is_nodown(int osd) const {
816 return exists(osd) && (osd_state[osd] & CEPH_OSD_NODOWN);
817 }
818
819 bool is_noin(int osd) const {
820 return exists(osd) && (osd_state[osd] & CEPH_OSD_NOIN);
821 }
822
823 bool is_noout(int osd) const {
824 return exists(osd) && (osd_state[osd] & CEPH_OSD_NOOUT);
825 }
826
827 void get_noup_osds(vector<int> *osds) const {
828 assert(osds);
829 osds->clear();
830
831 for (int i = 0; i < max_osd; i++) {
832 if (is_noup(i)) {
833 osds->push_back(i);
834 }
835 }
836 }
837
838 void get_nodown_osds(vector<int> *osds) const {
839 assert(osds);
840 osds->clear();
841
842 for (int i = 0; i < max_osd; i++) {
843 if (is_nodown(i)) {
844 osds->push_back(i);
845 }
846 }
847 }
848
849 void get_noin_osds(vector<int> *osds) const {
850 assert(osds);
851 osds->clear();
852
853 for (int i = 0; i < max_osd; i++) {
854 if (is_noin(i)) {
855 osds->push_back(i);
856 }
857 }
858 }
859
860 void get_noout_osds(vector<int> *osds) const {
861 assert(osds);
862 osds->clear();
863
864 for (int i = 0; i < max_osd; i++) {
865 if (is_noout(i)) {
866 osds->push_back(i);
867 }
868 }
869 }
870
871 /**
872 * check if an entire crush subtree is down
873 */
874 bool subtree_is_down(int id, set<int> *down_cache) const;
875 bool containing_subtree_is_down(CephContext *cct, int osd, int subtree_type, set<int> *down_cache) const;
876
877 bool subtree_type_is_down(CephContext *cct, int id, int subtree_type, set<int> *down_in_osds, set<int> *up_in_osds,
878 set<int> *subtree_up, unordered_map<int, set<int> > *subtree_type_down) const;
879
880 int identify_osd(const entity_addr_t& addr) const;
881 int identify_osd(const uuid_d& u) const;
882 int identify_osd_on_all_channels(const entity_addr_t& addr) const;
883
884 bool have_addr(const entity_addr_t& addr) const {
885 return identify_osd(addr) >= 0;
886 }
887 int find_osd_on_ip(const entity_addr_t& ip) const;
888 const entity_addr_t &get_addr(int osd) const {
889 assert(exists(osd));
890 return osd_addrs->client_addr[osd] ? *osd_addrs->client_addr[osd] : osd_addrs->blank;
891 }
892 const entity_addr_t &get_cluster_addr(int osd) const {
893 assert(exists(osd));
894 if (!osd_addrs->cluster_addr[osd] || *osd_addrs->cluster_addr[osd] == entity_addr_t())
895 return get_addr(osd);
896 return *osd_addrs->cluster_addr[osd];
897 }
898 const entity_addr_t &get_hb_back_addr(int osd) const {
899 assert(exists(osd));
900 return osd_addrs->hb_back_addr[osd] ? *osd_addrs->hb_back_addr[osd] : osd_addrs->blank;
901 }
902 const entity_addr_t &get_hb_front_addr(int osd) const {
903 assert(exists(osd));
904 return osd_addrs->hb_front_addr[osd] ? *osd_addrs->hb_front_addr[osd] : osd_addrs->blank;
905 }
906 entity_inst_t get_most_recent_inst(int osd) const {
907 assert(exists(osd));
908 return entity_inst_t(entity_name_t::OSD(osd), get_addr(osd));
909 }
910 entity_inst_t get_inst(int osd) const {
911 assert(is_up(osd));
912 return get_most_recent_inst(osd);
913 }
914 entity_inst_t get_cluster_inst(int osd) const {
915 assert(is_up(osd));
916 return entity_inst_t(entity_name_t::OSD(osd), get_cluster_addr(osd));
917 }
918 entity_inst_t get_hb_back_inst(int osd) const {
919 assert(is_up(osd));
920 return entity_inst_t(entity_name_t::OSD(osd), get_hb_back_addr(osd));
921 }
922 entity_inst_t get_hb_front_inst(int osd) const {
923 assert(is_up(osd));
924 return entity_inst_t(entity_name_t::OSD(osd), get_hb_front_addr(osd));
925 }
926
927 const uuid_d& get_uuid(int osd) const {
928 assert(exists(osd));
929 return (*osd_uuid)[osd];
930 }
931
932 const epoch_t& get_up_from(int osd) const {
933 assert(exists(osd));
934 return osd_info[osd].up_from;
935 }
936 const epoch_t& get_up_thru(int osd) const {
937 assert(exists(osd));
938 return osd_info[osd].up_thru;
939 }
940 const epoch_t& get_down_at(int osd) const {
941 assert(exists(osd));
942 return osd_info[osd].down_at;
943 }
944 const osd_info_t& get_info(int osd) const {
945 assert(osd < max_osd);
946 return osd_info[osd];
947 }
948
949 const osd_xinfo_t& get_xinfo(int osd) const {
950 assert(osd < max_osd);
951 return osd_xinfo[osd];
952 }
953
954 int get_next_up_osd_after(int n) const {
955 if (get_max_osd() == 0)
956 return -1;
957 for (int i = n + 1; i != n; ++i) {
958 if (i >= get_max_osd())
959 i = 0;
960 if (i == n)
961 break;
962 if (is_up(i))
963 return i;
964 }
965 return -1;
966 }
967
968 int get_previous_up_osd_before(int n) const {
969 if (get_max_osd() == 0)
970 return -1;
971 for (int i = n - 1; i != n; --i) {
972 if (i < 0)
973 i = get_max_osd() - 1;
974 if (i == n)
975 break;
976 if (is_up(i))
977 return i;
978 }
979 return -1;
980 }
981
982 /**
983 * get feature bits required by the current structure
984 *
985 * @param entity_type [in] what entity type we are asking about
986 * @param mask [out] set of all possible map-related features we could set
987 * @return feature bits used by this map
988 */
989 uint64_t get_features(int entity_type, uint64_t *mask) const;
990
991 /**
992 * get oldest *client* version (firefly, hammer, etc.) that can connect given
993 * the feature bits required (according to get_features()).
994 */
995 uint8_t get_min_compat_client() const;
996
997 /**
998 * get intersection of features supported by up osds
999 */
1000 uint64_t get_up_osd_features() const;
1001
1002 void maybe_remove_pg_upmaps(CephContext *cct,
1003 const OSDMap& osdmap,
1004 Incremental *pending_inc);
1005
1006 int apply_incremental(const Incremental &inc);
1007
1008 /// try to re-use/reference addrs in oldmap from newmap
1009 static void dedup(const OSDMap *oldmap, OSDMap *newmap);
1010
1011 static void clean_temps(CephContext *cct, const OSDMap& osdmap,
1012 Incremental *pending_inc);
1013
1014 // serialize, unserialize
1015 private:
1016 void encode_client_old(bufferlist& bl) const;
1017 void encode_classic(bufferlist& bl, uint64_t features) const;
1018 void decode_classic(bufferlist::iterator& p);
1019 void post_decode();
1020 public:
1021 void encode(bufferlist& bl, uint64_t features=CEPH_FEATURES_ALL) const;
1022 void decode(bufferlist& bl);
1023 void decode(bufferlist::iterator& bl);
1024
1025
1026 /**** mapping facilities ****/
1027 int map_to_pg(
1028 int64_t pool,
1029 const string& name,
1030 const string& key,
1031 const string& nspace,
1032 pg_t *pg) const;
1033 int object_locator_to_pg(const object_t& oid, const object_locator_t& loc,
1034 pg_t &pg) const;
1035 pg_t object_locator_to_pg(const object_t& oid,
1036 const object_locator_t& loc) const {
1037 pg_t pg;
1038 int ret = object_locator_to_pg(oid, loc, pg);
1039 assert(ret == 0);
1040 return pg;
1041 }
1042
1043
1044 static object_locator_t file_to_object_locator(const file_layout_t& layout) {
1045 return object_locator_t(layout.pool_id, layout.pool_ns);
1046 }
1047
1048 ceph_object_layout file_to_object_layout(object_t oid,
1049 file_layout_t& layout) const {
1050 return make_object_layout(oid, layout.pool_id, layout.pool_ns);
1051 }
1052
1053 ceph_object_layout make_object_layout(object_t oid, int pg_pool,
1054 string nspace) const;
1055
1056 int get_pg_num(int pg_pool) const
1057 {
1058 const pg_pool_t *pool = get_pg_pool(pg_pool);
1059 assert(NULL != pool);
1060 return pool->get_pg_num();
1061 }
1062
1063 bool pg_exists(pg_t pgid) const {
1064 const pg_pool_t *p = get_pg_pool(pgid.pool());
1065 return p && pgid.ps() < p->get_pg_num();
1066 }
1067
1068 int get_pg_pool_min_size(pg_t pgid) const {
1069 if (!pg_exists(pgid)) {
1070 return -ENOENT;
1071 }
1072 const pg_pool_t *p = get_pg_pool(pgid.pool());
1073 assert(p);
1074 return p->get_min_size();
1075 }
1076
1077 int get_pg_pool_size(pg_t pgid) const {
1078 if (!pg_exists(pgid)) {
1079 return -ENOENT;
1080 }
1081 const pg_pool_t *p = get_pg_pool(pgid.pool());
1082 assert(p);
1083 return p->get_size();
1084 }
1085
1086 int get_pg_pool_crush_rule(pg_t pgid) const {
1087 if (!pg_exists(pgid)) {
1088 return -ENOENT;
1089 }
1090 const pg_pool_t *p = get_pg_pool(pgid.pool());
1091 assert(p);
1092 return p->get_crush_rule();
1093 }
1094
1095 private:
1096 /// pg -> (raw osd list)
1097 void _pg_to_raw_osds(
1098 const pg_pool_t& pool, pg_t pg,
1099 vector<int> *osds,
1100 ps_t *ppps) const;
1101 int _pick_primary(const vector<int>& osds) const;
1102 void _remove_nonexistent_osds(const pg_pool_t& pool, vector<int>& osds) const;
1103
1104 void _apply_primary_affinity(ps_t seed, const pg_pool_t& pool,
1105 vector<int> *osds, int *primary) const;
1106
1107 /// apply pg_upmap[_items] mappings
1108 void _apply_upmap(const pg_pool_t& pi, pg_t pg, vector<int> *raw) const;
1109
1110 /// pg -> (up osd list)
1111 void _raw_to_up_osds(const pg_pool_t& pool, const vector<int>& raw,
1112 vector<int> *up) const;
1113
1114
1115 /**
1116 * Get the pg and primary temp, if they are specified.
1117 * @param temp_pg [out] Will be empty or contain the temp PG mapping on return
1118 * @param temp_primary [out] Will be the value in primary_temp, or a value derived
1119 * from the pg_temp (if specified), or -1 if you should use the calculated (up_)primary.
1120 */
1121 void _get_temp_osds(const pg_pool_t& pool, pg_t pg,
1122 vector<int> *temp_pg, int *temp_primary) const;
1123
1124 /**
1125 * map to up and acting. Fills in whatever fields are non-NULL.
1126 */
1127 void _pg_to_up_acting_osds(const pg_t& pg, vector<int> *up, int *up_primary,
1128 vector<int> *acting, int *acting_primary,
1129 bool raw_pg_to_pg = true) const;
1130
1131 public:
1132 /***
1133 * This is suitable only for looking at raw CRUSH outputs. It skips
1134 * applying the temp and up checks and should not be used
1135 * by anybody for data mapping purposes.
1136 * raw and primary must be non-NULL
1137 */
1138 void pg_to_raw_osds(pg_t pg, vector<int> *raw, int *primary) const;
1139 /// map a pg to its acting set. @return acting set size
1140 void pg_to_acting_osds(const pg_t& pg, vector<int> *acting,
1141 int *acting_primary) const {
1142 _pg_to_up_acting_osds(pg, NULL, NULL, acting, acting_primary);
1143 }
1144 void pg_to_acting_osds(pg_t pg, vector<int>& acting) const {
1145 return pg_to_acting_osds(pg, &acting, NULL);
1146 }
1147 /**
1148 * This does not apply temp overrides and should not be used
1149 * by anybody for data mapping purposes. Specify both pointers.
1150 */
1151 void pg_to_raw_up(pg_t pg, vector<int> *up, int *primary) const;
1152 /**
1153 * map a pg to its acting set as well as its up set. You must use
1154 * the acting set for data mapping purposes, but some users will
1155 * also find the up set useful for things like deciding what to
1156 * set as pg_temp.
1157 * Each of these pointers must be non-NULL.
1158 */
1159 void pg_to_up_acting_osds(pg_t pg, vector<int> *up, int *up_primary,
1160 vector<int> *acting, int *acting_primary) const {
1161 _pg_to_up_acting_osds(pg, up, up_primary, acting, acting_primary);
1162 }
1163 void pg_to_up_acting_osds(pg_t pg, vector<int>& up, vector<int>& acting) const {
1164 int up_primary, acting_primary;
1165 pg_to_up_acting_osds(pg, &up, &up_primary, &acting, &acting_primary);
1166 }
1167 bool pg_is_ec(pg_t pg) const {
1168 auto i = pools.find(pg.pool());
1169 assert(i != pools.end());
1170 return i->second.ec_pool();
1171 }
1172 bool get_primary_shard(const pg_t& pgid, spg_t *out) const {
1173 auto i = get_pools().find(pgid.pool());
1174 if (i == get_pools().end()) {
1175 return false;
1176 }
1177 if (!i->second.ec_pool()) {
1178 *out = spg_t(pgid);
1179 return true;
1180 }
1181 int primary;
1182 vector<int> acting;
1183 pg_to_acting_osds(pgid, &acting, &primary);
1184 for (uint8_t i = 0; i < acting.size(); ++i) {
1185 if (acting[i] == primary) {
1186 *out = spg_t(pgid, shard_id_t(i));
1187 return true;
1188 }
1189 }
1190 return false;
1191 }
1192
1193 int64_t lookup_pg_pool_name(const string& name) const {
1194 auto p = name_pool.find(name);
1195 if (p == name_pool.end())
1196 return -ENOENT;
1197 return p->second;
1198 }
1199
1200 int64_t get_pool_max() const {
1201 return pool_max;
1202 }
1203 const mempool::osdmap::map<int64_t,pg_pool_t>& get_pools() const {
1204 return pools;
1205 }
1206 mempool::osdmap::map<int64_t,pg_pool_t>& get_pools() {
1207 return pools;
1208 }
1209 void get_pool_ids_by_rule(int rule_id, set<int64_t> *pool_ids) const {
1210 assert(pool_ids);
1211 for (auto &p: pools) {
1212 if ((int)p.second.get_crush_rule() == rule_id) {
1213 pool_ids->insert(p.first);
1214 }
1215 }
1216 }
1217 void get_pool_ids_by_osd(CephContext *cct,
1218 int osd,
1219 set<int64_t> *pool_ids) const;
1220 const string& get_pool_name(int64_t p) const {
1221 auto i = pool_name.find(p);
1222 assert(i != pool_name.end());
1223 return i->second;
1224 }
1225 const mempool::osdmap::map<int64_t,string>& get_pool_names() const {
1226 return pool_name;
1227 }
1228 bool have_pg_pool(int64_t p) const {
1229 return pools.count(p);
1230 }
1231 const pg_pool_t* get_pg_pool(int64_t p) const {
1232 auto i = pools.find(p);
1233 if (i != pools.end())
1234 return &i->second;
1235 return NULL;
1236 }
1237 unsigned get_pg_size(pg_t pg) const {
1238 auto p = pools.find(pg.pool());
1239 assert(p != pools.end());
1240 return p->second.get_size();
1241 }
1242 int get_pg_type(pg_t pg) const {
1243 auto p = pools.find(pg.pool());
1244 assert(p != pools.end());
1245 return p->second.get_type();
1246 }
1247
1248
1249 pg_t raw_pg_to_pg(pg_t pg) const {
1250 auto p = pools.find(pg.pool());
1251 assert(p != pools.end());
1252 return p->second.raw_pg_to_pg(pg);
1253 }
1254
1255 // pg -> acting primary osd
1256 int get_pg_acting_primary(pg_t pg) const {
1257 int primary = -1;
1258 _pg_to_up_acting_osds(pg, nullptr, nullptr, nullptr, &primary);
1259 return primary;
1260 }
1261
1262 /*
1263 * check whether an spg_t maps to a particular osd
1264 */
1265 bool is_up_acting_osd_shard(spg_t pg, int osd) const {
1266 vector<int> up, acting;
1267 _pg_to_up_acting_osds(pg.pgid, &up, NULL, &acting, NULL, false);
1268 if (pg.shard == shard_id_t::NO_SHARD) {
1269 if (calc_pg_role(osd, acting, acting.size()) >= 0 ||
1270 calc_pg_role(osd, up, up.size()) >= 0)
1271 return true;
1272 } else {
1273 if (pg.shard < (int)acting.size() && acting[pg.shard] == osd)
1274 return true;
1275 if (pg.shard < (int)up.size() && up[pg.shard] == osd)
1276 return true;
1277 }
1278 return false;
1279 }
1280
1281
1282 /* what replica # is a given osd? 0 primary, -1 for none. */
1283 static int calc_pg_rank(int osd, const vector<int>& acting, int nrep=0);
1284 static int calc_pg_role(int osd, const vector<int>& acting, int nrep=0);
1285 static bool primary_changed(
1286 int oldprimary,
1287 const vector<int> &oldacting,
1288 int newprimary,
1289 const vector<int> &newacting);
1290
1291 /* rank is -1 (stray), 0 (primary), 1,2,3,... (replica) */
1292 int get_pg_acting_rank(pg_t pg, int osd) const {
1293 vector<int> group;
1294 pg_to_acting_osds(pg, group);
1295 return calc_pg_rank(osd, group, group.size());
1296 }
1297 /* role is -1 (stray), 0 (primary), 1 (replica) */
1298 int get_pg_acting_role(const pg_t& pg, int osd) const {
1299 vector<int> group;
1300 pg_to_acting_osds(pg, group);
1301 return calc_pg_role(osd, group, group.size());
1302 }
1303
1304 bool osd_is_valid_op_target(pg_t pg, int osd) const {
1305 int primary;
1306 vector<int> group;
1307 pg_to_acting_osds(pg, &group, &primary);
1308 if (osd == primary)
1309 return true;
1310 if (pg_is_ec(pg))
1311 return false;
1312
1313 return calc_pg_role(osd, group, group.size()) >= 0;
1314 }
1315
1316 int clean_pg_upmaps(
1317 CephContext *cct,
1318 Incremental *pending_inc);
1319
1320 bool try_pg_upmap(
1321 CephContext *cct,
1322 pg_t pg, ///< pg to potentially remap
1323 const set<int>& overfull, ///< osds we'd want to evacuate
1324 const vector<int>& underfull, ///< osds to move to, in order of preference
1325 vector<int> *orig,
1326 vector<int> *out); ///< resulting alternative mapping
1327
1328 int calc_pg_upmaps(
1329 CephContext *cct,
1330 float max_deviation, ///< max deviation from target (value < 1.0)
1331 int max_iterations, ///< max iterations to run
1332 const set<int64_t>& pools, ///< [optional] restrict to pool
1333 Incremental *pending_inc
1334 );
1335
1336 int get_osds_by_bucket_name(const string &name, set<int> *osds) const;
1337
1338 /*
1339 * handy helpers to build simple maps...
1340 */
1341 /**
1342 * Build an OSD map suitable for basic usage. If **num_osd** is >= 0
1343 * it will be initialized with the specified number of OSDs in a
1344 * single host. If **num_osd** is < 0 the layout of the OSD map will
1345 * be built by reading the content of the configuration file.
1346 *
1347 * @param cct [in] in core ceph context
1348 * @param e [in] initial epoch
1349 * @param fsid [in] id of the cluster
1350 * @param num_osd [in] number of OSDs if >= 0 or read from conf if < 0
1351 * @return **0** on success, negative errno on error.
1352 */
1353 private:
1354 int build_simple_optioned(CephContext *cct, epoch_t e, uuid_d &fsid,
1355 int num_osd, int pg_bits, int pgp_bits,
1356 bool default_pool);
1357 public:
1358 int build_simple(CephContext *cct, epoch_t e, uuid_d &fsid,
1359 int num_osd) {
1360 return build_simple_optioned(cct, e, fsid, num_osd, 0, 0, false);
1361 }
1362 int build_simple_with_pool(CephContext *cct, epoch_t e, uuid_d &fsid,
1363 int num_osd, int pg_bits, int pgp_bits) {
1364 return build_simple_optioned(cct, e, fsid, num_osd,
1365 pg_bits, pgp_bits, true);
1366 }
1367 static int _build_crush_types(CrushWrapper& crush);
1368 static int build_simple_crush_map(CephContext *cct, CrushWrapper& crush,
1369 int num_osd, ostream *ss);
1370 static int build_simple_crush_map_from_conf(CephContext *cct,
1371 CrushWrapper& crush,
1372 ostream *ss);
1373 static int build_simple_crush_rules(
1374 CephContext *cct, CrushWrapper& crush,
1375 const string& root,
1376 ostream *ss);
1377
1378 bool crush_rule_in_use(int rule_id) const;
1379
1380 int validate_crush_rules(CrushWrapper *crush, ostream *ss) const;
1381
1382 void clear_temp() {
1383 pg_temp->clear();
1384 primary_temp->clear();
1385 }
1386
1387 private:
1388 void print_osd_line(int cur, ostream *out, Formatter *f) const;
1389 public:
1390 void print(ostream& out) const;
1391 void print_pools(ostream& out) const;
1392 void print_summary(Formatter *f, ostream& out, const string& prefix) const;
1393 void print_oneline_summary(ostream& out) const;
1394
1395 enum {
1396 DUMP_IN = 1, // only 'in' osds
1397 DUMP_OUT = 2, // only 'out' osds
1398 DUMP_UP = 4, // only 'up' osds
1399 DUMP_DOWN = 8, // only 'down' osds
1400 DUMP_DESTROYED = 16, // only 'destroyed' osds
1401 };
1402 void print_tree(Formatter *f, ostream *out, unsigned dump_flags=0) const;
1403
1404 int summarize_mapping_stats(
1405 OSDMap *newmap,
1406 const set<int64_t> *pools,
1407 std::string *out,
1408 Formatter *f) const;
1409
1410 string get_flag_string() const;
1411 static string get_flag_string(unsigned flags);
1412 static void dump_erasure_code_profiles(
1413 const mempool::osdmap::map<string,map<string,string> > &profiles,
1414 Formatter *f);
1415 void dump(Formatter *f) const;
1416 static void generate_test_instances(list<OSDMap*>& o);
1417 bool check_new_blacklist_entries() const { return new_blacklist_entries; }
1418
1419 void check_health(health_check_map_t *checks) const;
1420
1421 int parse_osd_id_list(const vector<string>& ls,
1422 set<int> *out,
1423 ostream *ss) const;
1424 };
1425 WRITE_CLASS_ENCODER_FEATURES(OSDMap)
1426 WRITE_CLASS_ENCODER_FEATURES(OSDMap::Incremental)
1427
1428 typedef ceph::shared_ptr<const OSDMap> OSDMapRef;
1429
1430 inline ostream& operator<<(ostream& out, const OSDMap& m) {
1431 m.print_oneline_summary(out);
1432 return out;
1433 }
1434
1435 class PGStatService;
1436
1437 void print_osd_utilization(const OSDMap& osdmap,
1438 const PGStatService *pgstat,
1439 ostream& out,
1440 Formatter *f,
1441 bool tree);
1442
1443 #endif