Fix some bugs when testing opensds ansible
[stor4nfv.git] / src / ceph / src / crush / mapper.h
1 #ifndef CEPH_CRUSH_MAPPER_H
2 #define CEPH_CRUSH_MAPPER_H
3
4 /*
5  * CRUSH functions for find rules and then mapping an input to an
6  * output set.
7  *
8  * LGPL2
9  */
10
11 #include "crush.h"
12
13 extern int crush_find_rule(const struct crush_map *map, int ruleset, int type, int size);
14 /** @ingroup API
15  *
16  * Map __x__ to __result_max__ items and store them in the __result__
17  * array. The mapping is done by following each step of the rule
18  * __ruleno__. See crush_make_rule(), crush_rule_set_step() and
19  * crush_add_rule() for more information on how the rules are created,
20  * populated and added to the crush __map__.
21  *
22  * The return value is the the number of items in the __result__
23  * array. If the caller asked for __result_max__ items and the return
24  * value is X where X < __result_max__, the content of __result[0,X[__
25  * is defined but the content of __result[X,result_max[__ is
26  * undefined. For example:
27  *
28  *     crush_do_rule(map, ruleno=1, x=1, result, result_max=3,...) == 1
29  *     result[0] is set
30  *     result[1] is undefined
31  *     result[2] is undefined
32  *
33  * An entry in the __result__ array is either an item in the crush
34  * __map__ or ::CRUSH_ITEM_NONE if no item was found. For example:
35  *
36  *     crush_do_rule(map, ruleno=1, x=1, result, result_max=4,...) == 2
37  *     result[0] is CRUSH_ITEM_NONE
38  *     result[1] is item number 5
39  *     result[2] is undefined
40  *     result[3] is undefined
41  *
42  * The __weight__ array contains the probabilities that a leaf is
43  * ignored even if it is selected. It is a 16.16 fixed point
44  * number in the range [0x00000,0x10000]. The lower the value, the
45  * more often the leaf is ignored. For instance:
46  *
47  * - weight[leaf] == 0x00000 == 0.0 always ignore
48  * - weight[leaf] == 0x10000 == 1.0 never ignore
49  * - weight[leaf] == 0x08000 == 0.5 ignore 50% of the time
50  * - weight[leaf] == 0x04000 == 0.25 ignore 75% of the time
51  * - etc.
52  *
53  * During mapping, each leaf is checked against the __weight__ array,
54  * using the leaf as an index. If there is no entry in __weight__ for
55  * the leaf, it is ignored. If there is an entry, the leaf will be
56  * ignored some of the time, depending on the probability.
57  *
58  * The __cwin__ argument must be set as follows:
59  *
60  *         char __cwin__[crush_work_size(__map__, __result_max__)];
61  *         crush_init_workspace(__map__, __cwin__);
62  *
63  * @param map the crush_map
64  * @param ruleno a positive integer < __CRUSH_MAX_RULES__
65  * @param x the value to map to __result_max__ items
66  * @param result an array of items of size __result_max__
67  * @param result_max the size of the __result__ array
68  * @param weights an array of weights of size __weight_max__
69  * @param weight_max the size of the __weights__ array
70  * @param cwin must be an char array initialized by crush_init_workspace
71  * @param choose_args weights and ids for each known bucket
72  *
73  * @return 0 on error or the size of __result__ on success
74  */
75 extern int crush_do_rule(const struct crush_map *map,
76                          int ruleno,
77                          int x, int *result, int result_max,
78                          const __u32 *weights, int weight_max,
79                          void *cwin, const struct crush_choose_arg *choose_args);
80
81 /* Returns the exact amount of workspace that will need to be used
82    for a given combination of crush_map and result_max. The caller can
83    then allocate this much on its own, either on the stack, in a
84    per-thread long-lived buffer, or however it likes. */
85
86 static inline size_t crush_work_size(const struct crush_map *map,
87                                      int result_max) {
88         return map->working_size + result_max * 3 * sizeof(__u32);
89 }
90
91 extern void crush_init_workspace(const struct crush_map *m, void *v);
92
93 #endif