1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
4 #ifndef CEPH_CRUSH_WRAPPER_H
5 #define CEPH_CRUSH_WRAPPER_H
14 #include "include/types.h"
23 #include "include/assert.h"
24 #include "include/err.h"
25 #include "include/encoding.h"
26 #include "include/mempool.h"
28 #include "common/Mutex.h"
30 #define BUG_ON(x) assert(!(x))
36 namespace CrushTreeDumper
{
37 typedef mempool::osdmap::map
<int64_t,string
> name_map_t
;
40 WRITE_RAW_ENCODER(crush_rule_mask
) // it's all u8's
42 inline static void encode(const crush_rule_step
&s
, bufferlist
&bl
)
48 inline static void decode(crush_rule_step
&s
, bufferlist::iterator
&p
)
58 // magic value used by OSDMap for a "default" fallback choose_args, used if
59 // the choose_arg_map passed to do_rule does not exist. if this also
60 // doesn't exist, fall back to canonical weights.
62 DEFAULT_CHOOSE_ARGS
= -1
65 std::map
<int32_t, string
> type_map
; /* bucket/device type names */
66 std::map
<int32_t, string
> name_map
; /* bucket/device names */
67 std::map
<int32_t, string
> rule_name_map
;
69 std::map
<int32_t, int32_t> class_map
; /* item id -> class id */
70 std::map
<int32_t, string
> class_name
; /* class id -> class name */
71 std::map
<string
, int32_t> class_rname
; /* class name -> class id */
72 std::map
<int32_t, map
<int32_t, int32_t> > class_bucket
; /* bucket[id][class] == id */
73 std::map
<int64_t, crush_choose_arg_map
> choose_args
;
76 struct crush_map
*crush
= nullptr;
78 bool have_uniform_rules
= false;
81 mutable bool have_rmaps
= false;
82 mutable std::map
<string
, int> type_rmap
, name_rmap
, rule_name_rmap
;
83 void build_rmaps() const {
84 if (have_rmaps
) return;
85 build_rmap(type_map
, type_rmap
);
86 build_rmap(name_map
, name_rmap
);
87 build_rmap(rule_name_map
, rule_name_rmap
);
90 void build_rmap(const map
<int, string
> &f
, std::map
<string
, int> &r
) const {
92 for (std::map
<int, string
>::const_iterator p
= f
.begin(); p
!= f
.end(); ++p
)
93 r
[p
->second
] = p
->first
;
97 CrushWrapper(const CrushWrapper
& other
);
98 const CrushWrapper
& operator=(const CrushWrapper
& other
);
105 crush_destroy(crush
);
109 crush_map
*get_crush_map() { return crush
; }
114 crush_destroy(crush
);
115 crush
= crush_create();
120 set_tunables_default();
124 * true if any rule has a rule id != its position in the array
126 * These indicate "ruleset" IDs that were created by older versions
127 * of Ceph. They are cleaned up in renumber_rules so that eventually
128 * we can remove the code for handling them.
130 bool has_legacy_rule_ids() const;
133 * fix rules whose ruleid != ruleset
135 * These rules were created in older versions of Ceph. The concept
136 * of a ruleset no longer exists.
138 * Return a map of old ID -> new ID. Caller must update OSDMap
141 std::map
<int, int> renumber_rules();
143 /// true if any buckets that aren't straw2
144 bool has_non_straw2_buckets() const;
147 void set_tunables_argonaut() {
148 crush
->choose_local_tries
= 2;
149 crush
->choose_local_fallback_tries
= 5;
150 crush
->choose_total_tries
= 19;
151 crush
->chooseleaf_descend_once
= 0;
152 crush
->chooseleaf_vary_r
= 0;
153 crush
->chooseleaf_stable
= 0;
154 crush
->allowed_bucket_algs
= CRUSH_LEGACY_ALLOWED_BUCKET_ALGS
;
156 void set_tunables_bobtail() {
157 crush
->choose_local_tries
= 0;
158 crush
->choose_local_fallback_tries
= 0;
159 crush
->choose_total_tries
= 50;
160 crush
->chooseleaf_descend_once
= 1;
161 crush
->chooseleaf_vary_r
= 0;
162 crush
->chooseleaf_stable
= 0;
163 crush
->allowed_bucket_algs
= CRUSH_LEGACY_ALLOWED_BUCKET_ALGS
;
165 void set_tunables_firefly() {
166 crush
->choose_local_tries
= 0;
167 crush
->choose_local_fallback_tries
= 0;
168 crush
->choose_total_tries
= 50;
169 crush
->chooseleaf_descend_once
= 1;
170 crush
->chooseleaf_vary_r
= 1;
171 crush
->chooseleaf_stable
= 0;
172 crush
->allowed_bucket_algs
= CRUSH_LEGACY_ALLOWED_BUCKET_ALGS
;
174 void set_tunables_hammer() {
175 crush
->choose_local_tries
= 0;
176 crush
->choose_local_fallback_tries
= 0;
177 crush
->choose_total_tries
= 50;
178 crush
->chooseleaf_descend_once
= 1;
179 crush
->chooseleaf_vary_r
= 1;
180 crush
->chooseleaf_stable
= 0;
181 crush
->allowed_bucket_algs
=
182 (1 << CRUSH_BUCKET_UNIFORM
) |
183 (1 << CRUSH_BUCKET_LIST
) |
184 (1 << CRUSH_BUCKET_STRAW
) |
185 (1 << CRUSH_BUCKET_STRAW2
);
187 void set_tunables_jewel() {
188 crush
->choose_local_tries
= 0;
189 crush
->choose_local_fallback_tries
= 0;
190 crush
->choose_total_tries
= 50;
191 crush
->chooseleaf_descend_once
= 1;
192 crush
->chooseleaf_vary_r
= 1;
193 crush
->chooseleaf_stable
= 1;
194 crush
->allowed_bucket_algs
=
195 (1 << CRUSH_BUCKET_UNIFORM
) |
196 (1 << CRUSH_BUCKET_LIST
) |
197 (1 << CRUSH_BUCKET_STRAW
) |
198 (1 << CRUSH_BUCKET_STRAW2
);
201 void set_tunables_legacy() {
202 set_tunables_argonaut();
203 crush
->straw_calc_version
= 0;
205 void set_tunables_optimal() {
206 set_tunables_jewel();
207 crush
->straw_calc_version
= 1;
209 void set_tunables_default() {
210 set_tunables_jewel();
211 crush
->straw_calc_version
= 1;
214 int get_choose_local_tries() const {
215 return crush
->choose_local_tries
;
217 void set_choose_local_tries(int n
) {
218 crush
->choose_local_tries
= n
;
221 int get_choose_local_fallback_tries() const {
222 return crush
->choose_local_fallback_tries
;
224 void set_choose_local_fallback_tries(int n
) {
225 crush
->choose_local_fallback_tries
= n
;
228 int get_choose_total_tries() const {
229 return crush
->choose_total_tries
;
231 void set_choose_total_tries(int n
) {
232 crush
->choose_total_tries
= n
;
235 int get_chooseleaf_descend_once() const {
236 return crush
->chooseleaf_descend_once
;
238 void set_chooseleaf_descend_once(int n
) {
239 crush
->chooseleaf_descend_once
= !!n
;
242 int get_chooseleaf_vary_r() const {
243 return crush
->chooseleaf_vary_r
;
245 void set_chooseleaf_vary_r(int n
) {
246 crush
->chooseleaf_vary_r
= n
;
249 int get_chooseleaf_stable() const {
250 return crush
->chooseleaf_stable
;
252 void set_chooseleaf_stable(int n
) {
253 crush
->chooseleaf_stable
= n
;
256 int get_straw_calc_version() const {
257 return crush
->straw_calc_version
;
259 void set_straw_calc_version(int n
) {
260 crush
->straw_calc_version
= n
;
263 unsigned get_allowed_bucket_algs() const {
264 return crush
->allowed_bucket_algs
;
266 void set_allowed_bucket_algs(unsigned n
) {
267 crush
->allowed_bucket_algs
= n
;
270 bool has_argonaut_tunables() const {
272 crush
->choose_local_tries
== 2 &&
273 crush
->choose_local_fallback_tries
== 5 &&
274 crush
->choose_total_tries
== 19 &&
275 crush
->chooseleaf_descend_once
== 0 &&
276 crush
->chooseleaf_vary_r
== 0 &&
277 crush
->chooseleaf_stable
== 0 &&
278 crush
->allowed_bucket_algs
== CRUSH_LEGACY_ALLOWED_BUCKET_ALGS
;
280 bool has_bobtail_tunables() const {
282 crush
->choose_local_tries
== 0 &&
283 crush
->choose_local_fallback_tries
== 0 &&
284 crush
->choose_total_tries
== 50 &&
285 crush
->chooseleaf_descend_once
== 1 &&
286 crush
->chooseleaf_vary_r
== 0 &&
287 crush
->chooseleaf_stable
== 0 &&
288 crush
->allowed_bucket_algs
== CRUSH_LEGACY_ALLOWED_BUCKET_ALGS
;
290 bool has_firefly_tunables() const {
292 crush
->choose_local_tries
== 0 &&
293 crush
->choose_local_fallback_tries
== 0 &&
294 crush
->choose_total_tries
== 50 &&
295 crush
->chooseleaf_descend_once
== 1 &&
296 crush
->chooseleaf_vary_r
== 1 &&
297 crush
->chooseleaf_stable
== 0 &&
298 crush
->allowed_bucket_algs
== CRUSH_LEGACY_ALLOWED_BUCKET_ALGS
;
300 bool has_hammer_tunables() const {
302 crush
->choose_local_tries
== 0 &&
303 crush
->choose_local_fallback_tries
== 0 &&
304 crush
->choose_total_tries
== 50 &&
305 crush
->chooseleaf_descend_once
== 1 &&
306 crush
->chooseleaf_vary_r
== 1 &&
307 crush
->chooseleaf_stable
== 0 &&
308 crush
->allowed_bucket_algs
== ((1 << CRUSH_BUCKET_UNIFORM
) |
309 (1 << CRUSH_BUCKET_LIST
) |
310 (1 << CRUSH_BUCKET_STRAW
) |
311 (1 << CRUSH_BUCKET_STRAW2
));
313 bool has_jewel_tunables() const {
315 crush
->choose_local_tries
== 0 &&
316 crush
->choose_local_fallback_tries
== 0 &&
317 crush
->choose_total_tries
== 50 &&
318 crush
->chooseleaf_descend_once
== 1 &&
319 crush
->chooseleaf_vary_r
== 1 &&
320 crush
->chooseleaf_stable
== 1 &&
321 crush
->allowed_bucket_algs
== ((1 << CRUSH_BUCKET_UNIFORM
) |
322 (1 << CRUSH_BUCKET_LIST
) |
323 (1 << CRUSH_BUCKET_STRAW
) |
324 (1 << CRUSH_BUCKET_STRAW2
));
327 bool has_optimal_tunables() const {
328 return has_jewel_tunables();
330 bool has_legacy_tunables() const {
331 return has_argonaut_tunables();
334 bool has_nondefault_tunables() const {
336 (crush
->choose_local_tries
!= 2 ||
337 crush
->choose_local_fallback_tries
!= 5 ||
338 crush
->choose_total_tries
!= 19);
340 bool has_nondefault_tunables2() const {
342 crush
->chooseleaf_descend_once
!= 0;
344 bool has_nondefault_tunables3() const {
346 crush
->chooseleaf_vary_r
!= 0;
348 bool has_nondefault_tunables5() const {
350 crush
->chooseleaf_stable
!= 0;
353 bool has_v2_rules() const;
354 bool has_v3_rules() const;
355 bool has_v4_buckets() const;
356 bool has_v5_rules() const;
357 bool has_choose_args() const; // any choose_args
358 bool has_incompat_choose_args() const; // choose_args that can't be made compat
360 bool is_v2_rule(unsigned ruleid
) const;
361 bool is_v3_rule(unsigned ruleid
) const;
362 bool is_v5_rule(unsigned ruleid
) const;
364 string
get_min_required_version() const {
365 if (has_v5_rules() || has_nondefault_tunables5())
367 else if (has_v4_buckets())
369 else if (has_nondefault_tunables3())
371 else if (has_nondefault_tunables2() || has_nondefault_tunables())
377 // default bucket types
378 unsigned get_default_bucket_alg() const {
379 // in order of preference
380 if (crush
->allowed_bucket_algs
& (1 << CRUSH_BUCKET_STRAW2
))
381 return CRUSH_BUCKET_STRAW2
;
382 if (crush
->allowed_bucket_algs
& (1 << CRUSH_BUCKET_STRAW
))
383 return CRUSH_BUCKET_STRAW
;
384 if (crush
->allowed_bucket_algs
& (1 << CRUSH_BUCKET_TREE
))
385 return CRUSH_BUCKET_TREE
;
386 if (crush
->allowed_bucket_algs
& (1 << CRUSH_BUCKET_LIST
))
387 return CRUSH_BUCKET_LIST
;
388 if (crush
->allowed_bucket_algs
& (1 << CRUSH_BUCKET_UNIFORM
))
389 return CRUSH_BUCKET_UNIFORM
;
394 int get_num_type_names() const {
395 return type_map
.size();
397 int get_max_type_id() const {
398 if (type_map
.empty())
400 return type_map
.rbegin()->first
;
402 int get_type_id(const string
& name
) const {
404 if (type_rmap
.count(name
))
405 return type_rmap
[name
];
408 const char *get_type_name(int t
) const {
409 std::map
<int,string
>::const_iterator p
= type_map
.find(t
);
410 if (p
!= type_map
.end())
411 return p
->second
.c_str();
414 void set_type_name(int i
, const string
& name
) {
421 bool name_exists(const string
& name
) const {
423 return name_rmap
.count(name
);
425 bool item_exists(int i
) const {
426 return name_map
.count(i
);
428 int get_item_id(const string
& name
) const {
430 if (name_rmap
.count(name
))
431 return name_rmap
[name
];
434 const char *get_item_name(int t
) const {
435 std::map
<int,string
>::const_iterator p
= name_map
.find(t
);
436 if (p
!= name_map
.end())
437 return p
->second
.c_str();
440 int set_item_name(int i
, const string
& name
) {
441 if (!is_valid_crush_name(name
))
448 void swap_names(int a
, int b
) {
449 string an
= name_map
[a
];
450 string bn
= name_map
[b
];
458 int split_id_class(int i
, int *idout
, int *classout
) const;
460 bool class_exists(const string
& name
) const {
461 return class_rname
.count(name
);
463 const char *get_class_name(int i
) const {
464 auto p
= class_name
.find(i
);
465 if (p
!= class_name
.end())
466 return p
->second
.c_str();
469 int get_class_id(const string
& name
) const {
470 auto p
= class_rname
.find(name
);
471 if (p
!= class_rname
.end())
476 int remove_class_name(const string
& name
) {
477 auto p
= class_rname
.find(name
);
478 if (p
== class_rname
.end())
480 int class_id
= p
->second
;
481 auto q
= class_name
.find(class_id
);
482 if (q
== class_name
.end())
484 class_rname
.erase(name
);
485 class_name
.erase(class_id
);
489 int32_t _alloc_class_id() const;
491 int get_or_create_class_id(const string
& name
) {
492 int c
= get_class_id(name
);
494 int i
= _alloc_class_id();
495 class_name
[i
] = name
;
496 class_rname
[name
] = i
;
503 const char *get_item_class(int t
) const {
504 std::map
<int,int>::const_iterator p
= class_map
.find(t
);
505 if (p
== class_map
.end())
507 return get_class_name(p
->second
);
509 int set_item_class(int i
, const string
& name
) {
510 if (!is_valid_crush_name(name
))
512 class_map
[i
] = get_or_create_class_id(name
);
515 int set_item_class(int i
, int c
) {
519 void get_devices_by_class(const string
&name
, set
<int> *devices
) const {
522 if (!class_exists(name
)) {
525 auto cid
= get_class_id(name
);
526 for (auto& p
: class_map
) {
527 if (p
.first
>= 0 && p
.second
== cid
) {
528 devices
->insert(p
.first
);
532 void class_remove_item(int i
) {
533 auto it
= class_map
.find(i
);
534 if (it
== class_map
.end()) {
539 int can_rename_item(const string
& srcname
,
540 const string
& dstname
,
542 int rename_item(const string
& srcname
,
543 const string
& dstname
,
545 int can_rename_bucket(const string
& srcname
,
546 const string
& dstname
,
548 int rename_bucket(const string
& srcname
,
549 const string
& dstname
,
553 int rename_rule(const string
& srcname
,
554 const string
& dstname
,
556 bool rule_exists(string name
) const {
558 return rule_name_rmap
.count(name
);
560 int get_rule_id(string name
) const {
562 if (rule_name_rmap
.count(name
))
563 return rule_name_rmap
[name
];
566 const char *get_rule_name(int t
) const {
567 std::map
<int,string
>::const_iterator p
= rule_name_map
.find(t
);
568 if (p
!= rule_name_map
.end())
569 return p
->second
.c_str();
572 void set_rule_name(int i
, const string
& name
) {
573 rule_name_map
[i
] = name
;
575 rule_name_rmap
[name
] = i
;
577 bool is_shadow_item(int id
) const {
578 const char *name
= get_item_name(id
);
579 return name
&& !is_valid_crush_name(name
);
584 * find tree nodes referenced by rules by a 'take' command
586 * Note that these may not be parentless roots.
588 void find_takes(set
<int> *roots
) const;
589 void find_takes_by_rule(int rule
, set
<int> *roots
) const;
594 * These are parentless nodes in the map.
596 void find_roots(set
<int> *roots
) const;
600 * find tree roots that contain shadow (device class) items only
602 void find_shadow_roots(set
<int> *roots
) const {
606 if (is_shadow_item(p
)) {
613 * find tree roots that are not shadow (device class) items
615 * These are parentless nodes in the map that are not shadow
616 * items for device classes.
618 void find_nonshadow_roots(set
<int> *roots
) const {
622 if (!is_shadow_item(p
)) {
629 * see if an item is contained within a subtree
631 * @param root haystack
633 * @return true if the item is located beneath the given node
635 bool subtree_contains(int root
, int item
) const;
639 * search for an item in any bucket
642 * @return true if present
644 bool _search_item_exists(int i
) const;
648 * see if item is located where we think it is
650 * This verifies that the given item is located at a particular
651 * location in the hierarchy. However, that check is imprecise; we
652 * are actually verifying that the most specific location key/value
653 * is correct. For example, if loc specifies that rack=foo and
654 * host=bar, it will verify that host=bar is correct; any placement
655 * above that level in the hierarchy is ignored. This matches the
656 * semantics for insert_item().
659 * @param item item id
660 * @param loc location to check (map of type to bucket names)
661 * @param weight optional pointer to weight of item at that location
662 * @return true if item is at specified location
664 bool check_item_loc(CephContext
*cct
, int item
, const map
<string
,string
>& loc
, int *iweight
);
665 bool check_item_loc(CephContext
*cct
, int item
, const map
<string
,string
>& loc
, float *weight
) {
667 bool ret
= check_item_loc(cct
, item
, loc
, &iweight
);
669 *weight
= (float)iweight
/ (float)0x10000;
675 * returns the (type, name) of the parent bucket of id
677 * FIXME: ambiguous for items that occur multiple times in the map
679 pair
<string
,string
> get_immediate_parent(int id
, int *ret
= NULL
);
681 int get_immediate_parent_id(int id
, int *parent
) const;
684 * return ancestor of the given type, or 0 if none
685 * can pass in a specific crush **rule** to return ancestor from that rule only
686 * (parent is always a bucket and thus <0)
688 int get_parent_of_type(int id
, int type
, int rule
= -1) const;
691 * get the fully qualified location of a device by successively finding
692 * parents beginning at ID and ending at highest type number specified in
693 * the CRUSH map which assumes that if device foo is under device bar, the
694 * type_id of foo < bar where type_id is the integer specified in the CRUSH map
696 * returns the location in the form of (type=foo) where type is a type of bucket
697 * specified in the CRUSH map and foo is a name specified in the CRUSH map
699 map
<string
, string
> get_full_location(int id
);
702 * identical to get_full_location(int id) although it returns the type/name
703 * pairs in the order they occur in the hierarchy.
705 * returns -ENOENT if id is not found.
707 int get_full_location_ordered(int id
, vector
<pair
<string
, string
> >& path
);
710 * identical to get_full_location_ordered(int id, vector<pair<string, string> >& path),
711 * although it returns a concatenated string with the type/name pairs in descending
712 * hierarchical order with format key1=val1,key2=val2.
714 * returns the location in descending hierarchy as a string.
716 string
get_full_location_ordered_string(int id
);
719 * returns (type_id, type) of all parent buckets between id and
720 * default, can be used to check for anomolous CRUSH maps
722 map
<int, string
> get_parent_hierarchy(int id
);
725 * enumerate immediate children of given node
727 * @param id parent bucket or device id
728 * @return number of items, or error
730 int get_children(int id
, list
<int> *children
);
731 void get_children_of_type(int id
,
734 bool exclude_shadow
= true) const;
737 * get failure-domain type of a specific crush rule
738 * @param rule_id crush rule id
739 * @return type of failure-domain or a negative errno on error.
741 int get_rule_failure_domain(int rule_id
);
744 * enumerate leaves(devices) of given node
746 * @param name parent bucket name
747 * @return 0 on success or a negative errno on error.
749 int get_leaves(const string
&name
, set
<int> *leaves
);
750 int _get_leaves(int id
, list
<int> *leaves
); // worker
753 * insert an item into the map at a specific position
755 * Add an item as a specific location of the hierarchy.
756 * Specifically, we look for the most specific location constraint
757 * for which a bucket already exists, and then create intervening
758 * buckets beneath that in order to place the item.
760 * Note that any location specifiers *above* the most specific match
761 * are ignored. For example, if we specify that osd.12 goes in
762 * host=foo, rack=bar, and row=baz, and rack=bar is the most
763 * specific match, we will create host=foo beneath that point and
764 * put osd.12 inside it. However, we will not verify that rack=bar
765 * is beneath row=baz or move it.
767 * In short, we will build out a hierarchy, and move leaves around,
768 * but not adjust the hierarchy's internal structure. Yet.
770 * If the item is already present in the map, we will return EEXIST.
771 * If the location key/value pairs are nonsensical
772 * (rack=nameofdevice), or location specifies that do not attach us
773 * to any existing part of the hierarchy, we will return EINVAL.
777 * @param weight item weight
778 * @param name item name
779 * @param loc location (map of type to bucket names)
780 * @return 0 for success, negative on error
782 int insert_item(CephContext
*cct
, int id
, float weight
, string name
, const map
<string
,string
>& loc
);
785 * move a bucket in the hierarchy to the given location
787 * This has the same location and ancestor creation behavior as
788 * insert_item(), but will relocate the specified existing bucket.
791 * @param id bucket id
792 * @param loc location (map of type to bucket names)
793 * @return 0 for success, negative on error
795 int move_bucket(CephContext
*cct
, int id
, const map
<string
,string
>& loc
);
798 * swap bucket contents of two buckets without touching bucket ids
801 * @param src bucket a
802 * @param dst bucket b
803 * @return 0 for success, negative on error
805 int swap_bucket(CephContext
*cct
, int src
, int dst
);
808 * add a link to an existing bucket in the hierarchy to the new location
810 * This has the same location and ancestor creation behavior as
811 * insert_item(), but will add a new link to the specified existing
815 * @param id bucket id
816 * @param loc location (map of type to bucket names)
817 * @return 0 for success, negative on error
819 int link_bucket(CephContext
*cct
, int id
, const map
<string
,string
>& loc
);
822 * add or update an item's position in the map
824 * This is analogous to insert_item, except we will move an item if
825 * it is already present.
829 * @param weight item weight
830 * @param name item name
831 * @param loc location (map of type to bucket names)
832 * @return 0 for no change, 1 for successful change, negative on error
834 int update_item(CephContext
*cct
, int id
, float weight
, string name
, const map
<string
,string
>& loc
);
837 * create or move an item, but do not adjust its weight if it already exists
840 * @param item item id
841 * @param weight initial item weight (if we need to create it)
842 * @param name item name
843 * @param loc location (map of type to bucket names)
844 * @return 0 for no change, 1 for successful change, negative on error
846 int create_or_move_item(CephContext
*cct
, int item
, float weight
, string name
,
847 const map
<string
,string
>& loc
);
850 * remove all instances of an item from the map
853 * @param id item id to remove
854 * @param unlink_only unlink but do not remove bucket (useful if multiple links or not empty)
855 * @return 0 on success, negative on error
857 int remove_item(CephContext
*cct
, int id
, bool unlink_only
);
860 * recursively remove buckets starting at item and stop removing
861 * when a bucket is in use.
863 * @param item id to remove
864 * @return 0 on success, negative on error
866 int remove_root(int item
);
869 * remove all instances of an item nested beneath a certain point from the map
872 * @param id item id to remove
873 * @param ancestor ancestor item id under which to search for id
874 * @param unlink_only unlink but do not remove bucket (useful if bucket has multiple links or is not empty)
875 * @return 0 on success, negative on error
878 bool _maybe_remove_last_instance(CephContext
*cct
, int id
, bool unlink_only
);
879 int _remove_item_under(CephContext
*cct
, int id
, int ancestor
, bool unlink_only
);
880 bool _bucket_is_in_use(int id
);
882 int remove_item_under(CephContext
*cct
, int id
, int ancestor
, bool unlink_only
);
885 * calculate the locality/distance from a given id to a crush location map
887 * Specifically, we look for the lowest-valued type for which the
888 * location of id matches that described in loc.
891 * @param id the existing id in the map
892 * @param loc a set of key=value pairs describing a location in the hierarchy
894 int get_common_ancestor_distance(CephContext
*cct
, int id
,
895 const std::multimap
<string
,string
>& loc
);
898 * parse a set of key/value pairs out of a string vector
900 * These are used to describe a location in the CRUSH hierarchy.
902 * @param args list of strings (each key= or key=value)
903 * @param ploc pointer to a resulting location map or multimap
905 static int parse_loc_map(const std::vector
<string
>& args
,
906 std::map
<string
,string
> *ploc
);
907 static int parse_loc_multimap(const std::vector
<string
>& args
,
908 std::multimap
<string
,string
> *ploc
);
911 * get an item's weight
913 * Will return the weight for the first instance it finds.
915 * @param id item id to check
916 * @return weight of item
918 int get_item_weight(int id
) const;
919 float get_item_weightf(int id
) const {
920 return (float)get_item_weight(id
) / (float)0x10000;
922 int get_item_weight_in_loc(int id
, const map
<string
,string
> &loc
);
923 float get_item_weightf_in_loc(int id
, const map
<string
,string
> &loc
) {
924 return (float)get_item_weight_in_loc(id
, loc
) / (float)0x10000;
927 int validate_weightf(float weight
) {
928 uint64_t iweight
= weight
* 0x10000;
929 if (iweight
> std::numeric_limits
<int>::max()) {
934 int adjust_item_weight(CephContext
*cct
, int id
, int weight
);
935 int adjust_item_weightf(CephContext
*cct
, int id
, float weight
) {
936 int r
= validate_weightf(weight
);
940 return adjust_item_weight(cct
, id
, (int)(weight
* (float)0x10000));
942 int adjust_item_weight_in_loc(CephContext
*cct
, int id
, int weight
, const map
<string
,string
>& loc
);
943 int adjust_item_weightf_in_loc(CephContext
*cct
, int id
, float weight
, const map
<string
,string
>& loc
) {
944 int r
= validate_weightf(weight
);
948 return adjust_item_weight_in_loc(cct
, id
, (int)(weight
* (float)0x10000), loc
);
950 void reweight(CephContext
*cct
);
952 int adjust_subtree_weight(CephContext
*cct
, int id
, int weight
);
953 int adjust_subtree_weightf(CephContext
*cct
, int id
, float weight
) {
954 int r
= validate_weightf(weight
);
958 return adjust_subtree_weight(cct
, id
, (int)(weight
* (float)0x10000));
961 /// check if item id is present in the map hierarchy
962 bool check_item_present(int id
) const;
966 int get_max_devices() const {
967 if (!crush
) return 0;
968 return crush
->max_devices
;
974 crush_rule
*get_rule(unsigned ruleno
) const {
975 if (!crush
) return (crush_rule
*)(-ENOENT
);
976 if (ruleno
>= crush
->max_rules
)
978 return crush
->rules
[ruleno
];
980 crush_rule_step
*get_rule_step(unsigned ruleno
, unsigned step
) const {
981 crush_rule
*n
= get_rule(ruleno
);
982 if (IS_ERR(n
)) return (crush_rule_step
*)(-EINVAL
);
983 if (step
>= n
->len
) return (crush_rule_step
*)(-EINVAL
);
984 return &n
->steps
[step
];
989 int get_max_rules() const {
990 if (!crush
) return 0;
991 return crush
->max_rules
;
993 bool rule_exists(unsigned ruleno
) const {
994 if (!crush
) return false;
995 if (ruleno
< crush
->max_rules
&&
996 crush
->rules
[ruleno
] != NULL
)
1000 bool rule_has_take(unsigned ruleno
, int take
) const {
1001 if (!crush
) return false;
1002 crush_rule
*rule
= get_rule(ruleno
);
1003 for (unsigned i
= 0; i
< rule
->len
; ++i
) {
1004 if (rule
->steps
[i
].op
== CRUSH_RULE_TAKE
&&
1005 rule
->steps
[i
].arg1
== take
) {
1011 int get_rule_len(unsigned ruleno
) const {
1012 crush_rule
*r
= get_rule(ruleno
);
1013 if (IS_ERR(r
)) return PTR_ERR(r
);
1016 int get_rule_mask_ruleset(unsigned ruleno
) const {
1017 crush_rule
*r
= get_rule(ruleno
);
1018 if (IS_ERR(r
)) return -1;
1019 return r
->mask
.ruleset
;
1021 int get_rule_mask_type(unsigned ruleno
) const {
1022 crush_rule
*r
= get_rule(ruleno
);
1023 if (IS_ERR(r
)) return -1;
1024 return r
->mask
.type
;
1026 int get_rule_mask_min_size(unsigned ruleno
) const {
1027 crush_rule
*r
= get_rule(ruleno
);
1028 if (IS_ERR(r
)) return -1;
1029 return r
->mask
.min_size
;
1031 int get_rule_mask_max_size(unsigned ruleno
) const {
1032 crush_rule
*r
= get_rule(ruleno
);
1033 if (IS_ERR(r
)) return -1;
1034 return r
->mask
.max_size
;
1036 int get_rule_op(unsigned ruleno
, unsigned step
) const {
1037 crush_rule_step
*s
= get_rule_step(ruleno
, step
);
1038 if (IS_ERR(s
)) return PTR_ERR(s
);
1041 int get_rule_arg1(unsigned ruleno
, unsigned step
) const {
1042 crush_rule_step
*s
= get_rule_step(ruleno
, step
);
1043 if (IS_ERR(s
)) return PTR_ERR(s
);
1046 int get_rule_arg2(unsigned ruleno
, unsigned step
) const {
1047 crush_rule_step
*s
= get_rule_step(ruleno
, step
);
1048 if (IS_ERR(s
)) return PTR_ERR(s
);
1053 float _get_take_weight_osd_map(int root
, map
<int,float> *pmap
) const;
1054 void _normalize_weight_map(float sum
, const map
<int,float>& m
,
1055 map
<int,float> *pmap
) const;
1059 * calculate a map of osds to weights for a given rule
1061 * Generate a map of which OSDs get how much relative weight for a
1064 * @param ruleno [in] rule id
1065 * @param pmap [out] map of osd to weight
1066 * @return 0 for success, or negative error code
1068 int get_rule_weight_osd_map(unsigned ruleno
, map
<int,float> *pmap
) const;
1071 * calculate a map of osds to weights for a given starting root
1073 * Generate a map of which OSDs get how much relative weight for a
1074 * given starting root
1077 * @param pmap [out] map of osd to weight
1078 * @return 0 for success, or negative error code
1080 int get_take_weight_osd_map(int root
, map
<int,float> *pmap
) const;
1084 int add_rule(int ruleno
, int len
, int type
, int minsize
, int maxsize
) {
1085 if (!crush
) return -ENOENT
;
1086 crush_rule
*n
= crush_make_rule(len
, ruleno
, type
, minsize
, maxsize
);
1088 ruleno
= crush_add_rule(crush
, n
, ruleno
);
1091 int set_rule_mask_max_size(unsigned ruleno
, int max_size
) {
1092 crush_rule
*r
= get_rule(ruleno
);
1093 if (IS_ERR(r
)) return -1;
1094 return r
->mask
.max_size
= max_size
;
1096 int set_rule_step(unsigned ruleno
, unsigned step
, int op
, int arg1
, int arg2
) {
1097 if (!crush
) return -ENOENT
;
1098 crush_rule
*n
= get_rule(ruleno
);
1100 crush_rule_set_step(n
, step
, op
, arg1
, arg2
);
1103 int set_rule_step_take(unsigned ruleno
, unsigned step
, int val
) {
1104 return set_rule_step(ruleno
, step
, CRUSH_RULE_TAKE
, val
, 0);
1106 int set_rule_step_set_choose_tries(unsigned ruleno
, unsigned step
, int val
) {
1107 return set_rule_step(ruleno
, step
, CRUSH_RULE_SET_CHOOSE_TRIES
, val
, 0);
1109 int set_rule_step_set_choose_local_tries(unsigned ruleno
, unsigned step
, int val
) {
1110 return set_rule_step(ruleno
, step
, CRUSH_RULE_SET_CHOOSE_LOCAL_TRIES
, val
, 0);
1112 int set_rule_step_set_choose_local_fallback_tries(unsigned ruleno
, unsigned step
, int val
) {
1113 return set_rule_step(ruleno
, step
, CRUSH_RULE_SET_CHOOSE_LOCAL_FALLBACK_TRIES
, val
, 0);
1115 int set_rule_step_set_chooseleaf_tries(unsigned ruleno
, unsigned step
, int val
) {
1116 return set_rule_step(ruleno
, step
, CRUSH_RULE_SET_CHOOSELEAF_TRIES
, val
, 0);
1118 int set_rule_step_set_chooseleaf_vary_r(unsigned ruleno
, unsigned step
, int val
) {
1119 return set_rule_step(ruleno
, step
, CRUSH_RULE_SET_CHOOSELEAF_VARY_R
, val
, 0);
1121 int set_rule_step_set_chooseleaf_stable(unsigned ruleno
, unsigned step
, int val
) {
1122 return set_rule_step(ruleno
, step
, CRUSH_RULE_SET_CHOOSELEAF_STABLE
, val
, 0);
1124 int set_rule_step_choose_firstn(unsigned ruleno
, unsigned step
, int val
, int type
) {
1125 return set_rule_step(ruleno
, step
, CRUSH_RULE_CHOOSE_FIRSTN
, val
, type
);
1127 int set_rule_step_choose_indep(unsigned ruleno
, unsigned step
, int val
, int type
) {
1128 return set_rule_step(ruleno
, step
, CRUSH_RULE_CHOOSE_INDEP
, val
, type
);
1130 int set_rule_step_choose_leaf_firstn(unsigned ruleno
, unsigned step
, int val
, int type
) {
1131 return set_rule_step(ruleno
, step
, CRUSH_RULE_CHOOSELEAF_FIRSTN
, val
, type
);
1133 int set_rule_step_choose_leaf_indep(unsigned ruleno
, unsigned step
, int val
, int type
) {
1134 return set_rule_step(ruleno
, step
, CRUSH_RULE_CHOOSELEAF_INDEP
, val
, type
);
1136 int set_rule_step_emit(unsigned ruleno
, unsigned step
) {
1137 return set_rule_step(ruleno
, step
, CRUSH_RULE_EMIT
, 0, 0);
1140 int add_simple_rule(
1141 string name
, string root_name
, string failure_domain_type
,
1142 string device_class
,
1143 string mode
, int rule_type
, ostream
*err
= 0);
1146 * @param rno rule[set] id to use, -1 to pick the lowest available
1148 int add_simple_rule_at(
1149 string name
, string root_name
,
1150 string failure_domain_type
, string device_class
, string mode
,
1151 int rule_type
, int rno
, ostream
*err
= 0);
1153 int remove_rule(int ruleno
);
1157 const crush_bucket
*get_bucket(int id
) const {
1159 return (crush_bucket
*)(-EINVAL
);
1160 unsigned int pos
= (unsigned int)(-1 - id
);
1161 unsigned int max_buckets
= crush
->max_buckets
;
1162 if (pos
>= max_buckets
)
1163 return (crush_bucket
*)(-ENOENT
);
1164 crush_bucket
*ret
= crush
->buckets
[pos
];
1166 return (crush_bucket
*)(-ENOENT
);
1170 crush_bucket
*get_bucket(int id
) {
1172 return (crush_bucket
*)(-EINVAL
);
1173 unsigned int pos
= (unsigned int)(-1 - id
);
1174 unsigned int max_buckets
= crush
->max_buckets
;
1175 if (pos
>= max_buckets
)
1176 return (crush_bucket
*)(-ENOENT
);
1177 crush_bucket
*ret
= crush
->buckets
[pos
];
1179 return (crush_bucket
*)(-ENOENT
);
1183 * detach a bucket from its parent and adjust the parent weight
1185 * returns the weight of the detached bucket
1187 int detach_bucket(CephContext
*cct
, int item
);
1190 int get_max_buckets() const {
1191 if (!crush
) return -EINVAL
;
1192 return crush
->max_buckets
;
1194 int get_next_bucket_id() const {
1195 if (!crush
) return -EINVAL
;
1196 return crush_get_next_bucket_id(crush
);
1198 bool bucket_exists(int id
) const {
1199 const crush_bucket
*b
= get_bucket(id
);
1204 int get_bucket_weight(int id
) const {
1205 const crush_bucket
*b
= get_bucket(id
);
1206 if (IS_ERR(b
)) return PTR_ERR(b
);
1209 float get_bucket_weightf(int id
) const {
1210 const crush_bucket
*b
= get_bucket(id
);
1211 if (IS_ERR(b
)) return 0;
1212 return b
->weight
/ (float)0x10000;
1214 int get_bucket_type(int id
) const {
1215 const crush_bucket
*b
= get_bucket(id
);
1216 if (IS_ERR(b
)) return PTR_ERR(b
);
1219 int get_bucket_alg(int id
) const {
1220 const crush_bucket
*b
= get_bucket(id
);
1221 if (IS_ERR(b
)) return PTR_ERR(b
);
1224 int get_bucket_hash(int id
) const {
1225 const crush_bucket
*b
= get_bucket(id
);
1226 if (IS_ERR(b
)) return PTR_ERR(b
);
1229 int get_bucket_size(int id
) const {
1230 const crush_bucket
*b
= get_bucket(id
);
1231 if (IS_ERR(b
)) return PTR_ERR(b
);
1234 int get_bucket_item(int id
, int pos
) const {
1235 const crush_bucket
*b
= get_bucket(id
);
1236 if (IS_ERR(b
)) return PTR_ERR(b
);
1237 if ((__u32
)pos
>= b
->size
)
1239 return b
->items
[pos
];
1241 int get_bucket_item_weight(int id
, int pos
) const {
1242 const crush_bucket
*b
= get_bucket(id
);
1243 if (IS_ERR(b
)) return PTR_ERR(b
);
1244 return crush_get_bucket_item_weight(b
, pos
);
1246 float get_bucket_item_weightf(int id
, int pos
) const {
1247 const crush_bucket
*b
= get_bucket(id
);
1248 if (IS_ERR(b
)) return 0;
1249 return (float)crush_get_bucket_item_weight(b
, pos
) / (float)0x10000;
1253 int add_bucket(int bucketno
, int alg
, int hash
, int type
, int size
,
1254 int *items
, int *weights
, int *idout
);
1255 int bucket_add_item(crush_bucket
*bucket
, int item
, int weight
);
1256 int bucket_remove_item(struct crush_bucket
*bucket
, int item
);
1257 int bucket_adjust_item_weight(CephContext
*cct
, struct crush_bucket
*bucket
, int item
, int weight
);
1261 crush_finalize(crush
);
1262 if (!name_map
.empty() &&
1263 name_map
.rbegin()->first
>= crush
->max_devices
) {
1264 crush
->max_devices
= name_map
.rbegin()->first
+ 1;
1266 have_uniform_rules
= !has_legacy_rule_ids();
1268 int bucket_set_alg(int id
, int alg
);
1270 int update_device_class(int id
, const string
& class_name
, const string
& name
, ostream
*ss
);
1271 int remove_device_class(CephContext
*cct
, int id
, ostream
*ss
);
1272 int device_class_clone(
1273 int original
, int device_class
,
1274 const std::map
<int32_t, map
<int32_t, int32_t>>& old_class_bucket
,
1275 const std::set
<int32_t>& used_ids
,
1277 map
<int,map
<int,vector
<int>>> *cmap_item_weight
);
1278 int rename_class(const string
& srcname
, const string
& dstname
);
1279 int populate_classes(
1280 const std::map
<int32_t, map
<int32_t, int32_t>>& old_class_bucket
);
1281 int get_rules_by_class(const string
&class_name
, set
<int> *rules
);
1282 int get_rules_by_osd(int osd
, set
<int> *rules
);
1283 bool _class_is_dead(int class_id
);
1284 void cleanup_dead_classes();
1285 int rebuild_roots_with_classes();
1286 /* remove unused roots generated for class devices */
1287 int trim_roots_with_class();
1289 void start_choose_profile() {
1290 free(crush
->choose_tries
);
1292 * the original choose_total_tries value was off by one (it
1293 * counted "retries" and not "tries"). add one to alloc.
1295 crush
->choose_tries
= (__u32
*)calloc(sizeof(*crush
->choose_tries
),
1296 (crush
->choose_total_tries
+ 1));
1297 memset(crush
->choose_tries
, 0,
1298 sizeof(*crush
->choose_tries
) * (crush
->choose_total_tries
+ 1));
1300 void stop_choose_profile() {
1301 free(crush
->choose_tries
);
1302 crush
->choose_tries
= 0;
1305 int get_choose_profile(__u32
**vec
) {
1306 if (crush
->choose_tries
) {
1307 *vec
= crush
->choose_tries
;
1308 return crush
->choose_total_tries
;
1314 void set_max_devices(int m
) {
1315 crush
->max_devices
= m
;
1318 int find_rule(int ruleset
, int type
, int size
) const {
1319 if (!crush
) return -1;
1320 if (have_uniform_rules
&&
1321 ruleset
< (int)crush
->max_rules
&&
1322 crush
->rules
[ruleset
] &&
1323 crush
->rules
[ruleset
]->mask
.type
== type
&&
1324 crush
->rules
[ruleset
]->mask
.min_size
<= size
&&
1325 crush
->rules
[ruleset
]->mask
.max_size
>= size
) {
1328 return crush_find_rule(crush
, ruleset
, type
, size
);
1331 bool ruleset_exists(const int ruleset
) const {
1332 for (size_t i
= 0; i
< crush
->max_rules
; ++i
) {
1333 if (rule_exists(i
) && crush
->rules
[i
]->mask
.ruleset
== ruleset
) {
1342 * Return the lowest numbered ruleset of type `type`
1344 * @returns a ruleset ID, or -1 if no matching rules found.
1346 int find_first_ruleset(int type
) const {
1349 for (size_t i
= 0; i
< crush
->max_rules
; ++i
) {
1351 && crush
->rules
[i
]->mask
.type
== type
1352 && (crush
->rules
[i
]->mask
.ruleset
< result
|| result
== -1)) {
1353 result
= crush
->rules
[i
]->mask
.ruleset
;
1360 bool have_choose_args(int64_t choose_args_index
) const {
1361 return choose_args
.count(choose_args_index
);
1364 crush_choose_arg_map
choose_args_get_with_fallback(
1365 int64_t choose_args_index
) const {
1366 auto i
= choose_args
.find(choose_args_index
);
1367 if (i
== choose_args
.end()) {
1368 i
= choose_args
.find(DEFAULT_CHOOSE_ARGS
);
1370 if (i
== choose_args
.end()) {
1371 crush_choose_arg_map arg_map
;
1372 arg_map
.args
= NULL
;
1379 crush_choose_arg_map
choose_args_get(int64_t choose_args_index
) const {
1380 auto i
= choose_args
.find(choose_args_index
);
1381 if (i
== choose_args
.end()) {
1382 crush_choose_arg_map arg_map
;
1383 arg_map
.args
= NULL
;
1391 void destroy_choose_args(crush_choose_arg_map arg_map
) {
1392 for (__u32 i
= 0; i
< arg_map
.size
; i
++) {
1393 crush_choose_arg
*arg
= &arg_map
.args
[i
];
1394 for (__u32 j
= 0; j
< arg
->weight_set_positions
; j
++) {
1395 crush_weight_set
*weight_set
= &arg
->weight_set
[j
];
1396 free(weight_set
->weights
);
1398 if (arg
->weight_set
)
1399 free(arg
->weight_set
);
1406 void create_choose_args(int64_t id
, int positions
) {
1407 if (choose_args
.count(id
))
1410 auto &cmap
= choose_args
[id
];
1411 cmap
.args
= (crush_choose_arg
*)calloc(sizeof(crush_choose_arg
),
1412 crush
->max_buckets
);
1413 cmap
.size
= crush
->max_buckets
;
1414 for (int bidx
=0; bidx
< crush
->max_buckets
; ++bidx
) {
1415 crush_bucket
*b
= crush
->buckets
[bidx
];
1416 auto &carg
= cmap
.args
[bidx
];
1419 if (b
&& b
->alg
== CRUSH_BUCKET_STRAW2
) {
1420 crush_bucket_straw2
*sb
= (crush_bucket_straw2
*)b
;
1421 carg
.weight_set_positions
= positions
;
1422 carg
.weight_set
= (crush_weight_set
*)calloc(sizeof(crush_weight_set
),
1423 carg
.weight_set_positions
);
1424 // initialize with canonical weights
1425 for (int pos
= 0; pos
< positions
; ++pos
) {
1426 carg
.weight_set
[pos
].size
= b
->size
;
1427 carg
.weight_set
[pos
].weights
= (__u32
*)calloc(4, b
->size
);
1428 for (unsigned i
= 0; i
< b
->size
; ++i
) {
1429 carg
.weight_set
[pos
].weights
[i
] = sb
->item_weights
[i
];
1433 carg
.weight_set
= NULL
;
1434 carg
.weight_set_positions
= 0;
1439 void rm_choose_args(int64_t id
) {
1440 auto p
= choose_args
.find(id
);
1441 if (p
!= choose_args
.end()) {
1442 destroy_choose_args(p
->second
);
1443 choose_args
.erase(p
);
1447 void choose_args_clear() {
1448 for (auto w
: choose_args
)
1449 destroy_choose_args(w
.second
);
1450 choose_args
.clear();
1453 // remove choose_args for buckets that no longer exist, create them for new buckets
1454 void update_choose_args(CephContext
*cct
);
1456 // adjust choose_args_map weight, preserving the hierarchical summation
1457 // property. used by callers optimizing layouts by tweaking weights.
1458 int _choose_args_adjust_item_weight_in_bucket(
1460 crush_choose_arg_map cmap
,
1463 const vector
<int>& weight
,
1465 int choose_args_adjust_item_weight(
1467 crush_choose_arg_map cmap
,
1468 int id
, const vector
<int>& weight
,
1470 int choose_args_adjust_item_weightf(
1472 crush_choose_arg_map cmap
,
1473 int id
, const vector
<double>& weightf
,
1475 vector
<int> weight(weightf
.size());
1476 for (unsigned i
= 0; i
< weightf
.size(); ++i
) {
1477 weight
[i
] = (int)(weightf
[i
] * (float)0x10000);
1479 return choose_args_adjust_item_weight(cct
, cmap
, id
, weight
, ss
);
1482 int get_choose_args_positions(crush_choose_arg_map cmap
) {
1483 // infer positions from other buckets
1484 for (unsigned j
= 0; j
< cmap
.size
; ++j
) {
1485 if (cmap
.args
[j
].weight_set_positions
) {
1486 return cmap
.args
[j
].weight_set_positions
;
1492 template<typename WeightVector
>
1493 void do_rule(int rule
, int x
, vector
<int>& out
, int maxout
,
1494 const WeightVector
& weight
,
1495 uint64_t choose_args_index
) const {
1497 char work
[crush_work_size(crush
, maxout
)];
1498 crush_init_workspace(crush
, work
);
1499 crush_choose_arg_map arg_map
= choose_args_get_with_fallback(
1501 int numrep
= crush_do_rule(crush
, rule
, x
, rawout
, maxout
, &weight
[0],
1502 weight
.size(), work
, arg_map
.args
);
1506 for (int i
=0; i
<numrep
; i
++)
1510 int _choose_type_stack(
1512 const vector
<pair
<int,int>>& stack
,
1513 const set
<int>& overfull
,
1514 const vector
<int>& underfull
,
1515 const vector
<int>& orig
,
1516 vector
<int>::const_iterator
& i
,
1518 vector
<int> *pw
) const;
1524 const set
<int>& overfull
,
1525 const vector
<int>& underfull
,
1526 const vector
<int>& orig
,
1527 vector
<int> *out
) const;
1529 bool check_crush_rule(int ruleset
, int type
, int size
, ostream
& ss
) {
1533 for (i
= 0; i
< crush
->max_rules
; i
++) {
1534 if (crush
->rules
[i
] &&
1535 crush
->rules
[i
]->mask
.ruleset
== ruleset
&&
1536 crush
->rules
[i
]->mask
.type
== type
) {
1538 if (crush
->rules
[i
]->mask
.min_size
<= size
&&
1539 crush
->rules
[i
]->mask
.max_size
>= size
) {
1541 } else if (size
< crush
->rules
[i
]->mask
.min_size
) {
1542 ss
<< "pool size is smaller than the crush rule min size";
1545 ss
<< "pool size is bigger than the crush rule max size";
1554 void encode(bufferlist
&bl
, uint64_t features
) const;
1555 void decode(bufferlist::iterator
&blp
);
1556 void decode_crush_bucket(crush_bucket
** bptr
, bufferlist::iterator
&blp
);
1557 void dump(Formatter
*f
) const;
1558 void dump_rules(Formatter
*f
) const;
1559 void dump_rule(int ruleset
, Formatter
*f
) const;
1560 void dump_tunables(Formatter
*f
) const;
1561 void dump_choose_args(Formatter
*f
) const;
1562 void list_rules(Formatter
*f
) const;
1563 void list_rules(ostream
*ss
) const;
1564 void dump_tree(ostream
*out
,
1566 const CrushTreeDumper::name_map_t
& ws
,
1567 bool show_shadow
= false) const;
1568 void dump_tree(ostream
*out
, Formatter
*f
) {
1569 dump_tree(out
, f
, CrushTreeDumper::name_map_t());
1571 void dump_tree(Formatter
*f
,
1572 const CrushTreeDumper::name_map_t
& ws
) const;
1573 static void generate_test_instances(list
<CrushWrapper
*>& o
);
1575 int get_osd_pool_default_crush_replicated_ruleset(CephContext
*cct
);
1577 static bool is_valid_crush_name(const string
& s
);
1578 static bool is_valid_crush_loc(CephContext
*cct
,
1579 const map
<string
,string
>& loc
);
1581 WRITE_CLASS_ENCODER_FEATURES(CrushWrapper
)