1#ifndef CEPH_CRUSH_CRUSH_H
2#define CEPH_CRUSH_CRUSH_H
3
4#include <linux/types.h>
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20#define CRUSH_MAGIC 0x00010000ul
21
22#define CRUSH_MAX_DEPTH 10
23
24
25#define CRUSH_ITEM_UNDEF 0x7ffffffe
26#define CRUSH_ITEM_NONE 0x7fffffff
27
28
29
30
31
32
33struct crush_rule_step {
34 __u32 op;
35 __s32 arg1;
36 __s32 arg2;
37};
38
39
40enum {
41 CRUSH_RULE_NOOP = 0,
42 CRUSH_RULE_TAKE = 1,
43 CRUSH_RULE_CHOOSE_FIRSTN = 2,
44
45 CRUSH_RULE_CHOOSE_INDEP = 3,
46 CRUSH_RULE_EMIT = 4,
47 CRUSH_RULE_CHOOSELEAF_FIRSTN = 6,
48 CRUSH_RULE_CHOOSELEAF_INDEP = 7,
49
50 CRUSH_RULE_SET_CHOOSE_TRIES = 8,
51 CRUSH_RULE_SET_CHOOSELEAF_TRIES = 9,
52 CRUSH_RULE_SET_CHOOSE_LOCAL_TRIES = 10,
53 CRUSH_RULE_SET_CHOOSE_LOCAL_FALLBACK_TRIES = 11,
54 CRUSH_RULE_SET_CHOOSELEAF_VARY_R = 12
55};
56
57
58
59
60
61#define CRUSH_CHOOSE_N 0
62#define CRUSH_CHOOSE_N_MINUS(x) (-(x))
63
64
65
66
67
68
69struct crush_rule_mask {
70 __u8 ruleset;
71 __u8 type;
72 __u8 min_size;
73 __u8 max_size;
74};
75
76struct crush_rule {
77 __u32 len;
78 struct crush_rule_mask mask;
79 struct crush_rule_step steps[0];
80};
81
82#define crush_rule_size(len) (sizeof(struct crush_rule) + \
83 (len)*sizeof(struct crush_rule_step))
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101enum {
102 CRUSH_BUCKET_UNIFORM = 1,
103 CRUSH_BUCKET_LIST = 2,
104 CRUSH_BUCKET_TREE = 3,
105 CRUSH_BUCKET_STRAW = 4
106};
107extern const char *crush_bucket_alg_name(int alg);
108
109struct crush_bucket {
110 __s32 id;
111 __u16 type;
112 __u8 alg;
113 __u8 hash;
114 __u32 weight;
115 __u32 size;
116 __s32 *items;
117
118
119
120
121
122 __u32 perm_x;
123 __u32 perm_n;
124 __u32 *perm;
125};
126
127struct crush_bucket_uniform {
128 struct crush_bucket h;
129 __u32 item_weight;
130};
131
132struct crush_bucket_list {
133 struct crush_bucket h;
134 __u32 *item_weights;
135 __u32 *sum_weights;
136
137};
138
139struct crush_bucket_tree {
140 struct crush_bucket h;
141
142 __u8 num_nodes;
143 __u32 *node_weights;
144};
145
146struct crush_bucket_straw {
147 struct crush_bucket h;
148 __u32 *item_weights;
149 __u32 *straws;
150};
151
152
153
154
155
156
157struct crush_map {
158 struct crush_bucket **buckets;
159 struct crush_rule **rules;
160
161 __s32 max_buckets;
162 __u32 max_rules;
163 __s32 max_devices;
164
165
166 __u32 choose_local_tries;
167
168
169 __u32 choose_local_fallback_tries;
170
171 __u32 choose_total_tries;
172
173
174
175
176 __u32 chooseleaf_descend_once;
177
178
179
180
181
182 __u8 chooseleaf_vary_r;
183};
184
185
186
187extern int crush_get_bucket_item_weight(const struct crush_bucket *b, int pos);
188extern void crush_destroy_bucket_uniform(struct crush_bucket_uniform *b);
189extern void crush_destroy_bucket_list(struct crush_bucket_list *b);
190extern void crush_destroy_bucket_tree(struct crush_bucket_tree *b);
191extern void crush_destroy_bucket_straw(struct crush_bucket_straw *b);
192extern void crush_destroy_bucket(struct crush_bucket *b);
193extern void crush_destroy_rule(struct crush_rule *r);
194extern void crush_destroy(struct crush_map *map);
195
196static inline int crush_calc_tree_node(int i)
197{
198 return ((i+1) << 1)-1;
199}
200
201#endif
202