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