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