blob: 5fcfb98f309efb5018f84628902cd1711fc36705 [file] [log] [blame]
Ilya Dryomovb459be72015-06-12 13:21:07 +03001/*
2 * Ceph - scalable distributed file system
3 *
4 * Copyright (C) 2015 Intel Corporation All Rights Reserved
5 *
6 * This is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License version 2.1, as published by the Free Software
9 * Foundation. See file COPYING.
10 *
11 */
Sage Weil5ecc0a02009-10-06 11:31:11 -070012
13#ifdef __KERNEL__
14# include <linux/string.h>
15# include <linux/slab.h>
16# include <linux/bug.h>
17# include <linux/kernel.h>
Ilya Dryomovb459be72015-06-12 13:21:07 +030018# include <linux/crush/crush.h>
19# include <linux/crush/hash.h>
Sage Weil5ecc0a02009-10-06 11:31:11 -070020#else
Ilya Dryomovb459be72015-06-12 13:21:07 +030021# include "crush_compat.h"
22# include "crush.h"
23# include "hash.h"
Sage Weil5ecc0a02009-10-06 11:31:11 -070024#endif
Ilya Dryomov958a2762015-04-14 16:54:52 +030025#include "crush_ln_table.h"
Sage Weil5ecc0a02009-10-06 11:31:11 -070026
Ilya Dryomovb459be72015-06-12 13:21:07 +030027#define dprintk(args...) /* printf(args) */
28
Sage Weil5ecc0a02009-10-06 11:31:11 -070029/*
30 * Implement the core CRUSH mapping algorithm.
31 */
32
33/**
34 * crush_find_rule - find a crush_rule id for a given ruleset, type, and size.
35 * @map: the crush_map
36 * @ruleset: the storage ruleset id (user defined)
37 * @type: storage ruleset type (user defined)
38 * @size: output set size
39 */
Sage Weil8b12d472012-05-07 15:38:35 -070040int crush_find_rule(const struct crush_map *map, int ruleset, int type, int size)
Sage Weil5ecc0a02009-10-06 11:31:11 -070041{
Sage Weil8b12d472012-05-07 15:38:35 -070042 __u32 i;
Sage Weil5ecc0a02009-10-06 11:31:11 -070043
44 for (i = 0; i < map->max_rules; i++) {
45 if (map->rules[i] &&
46 map->rules[i]->mask.ruleset == ruleset &&
47 map->rules[i]->mask.type == type &&
48 map->rules[i]->mask.min_size <= size &&
49 map->rules[i]->mask.max_size >= size)
50 return i;
51 }
52 return -1;
53}
54
55
56/*
57 * bucket choose methods
58 *
59 * For each bucket algorithm, we have a "choose" method that, given a
60 * crush input @x and replica position (usually, position in output set) @r,
61 * will produce an item in the bucket.
62 */
63
64/*
65 * Choose based on a random permutation of the bucket.
66 *
67 * We used to use some prime number arithmetic to do this, but it
68 * wasn't very random, and had some other bad behaviors. Instead, we
69 * calculate an actual random permutation of the bucket members.
70 * Since this is expensive, we optimize for the r=0 case, which
71 * captures the vast majority of calls.
72 */
73static int bucket_perm_choose(struct crush_bucket *bucket,
74 int x, int r)
75{
Eric Dumazet95c96172012-04-15 05:58:06 +000076 unsigned int pr = r % bucket->size;
77 unsigned int i, s;
Sage Weil5ecc0a02009-10-06 11:31:11 -070078
79 /* start a new permutation if @x has changed */
Sage Weil8b12d472012-05-07 15:38:35 -070080 if (bucket->perm_x != (__u32)x || bucket->perm_n == 0) {
Sage Weil5ecc0a02009-10-06 11:31:11 -070081 dprintk("bucket %d new x=%d\n", bucket->id, x);
82 bucket->perm_x = x;
83
84 /* optimize common r=0 case */
85 if (pr == 0) {
Sage Weilfb690392009-11-07 20:18:22 -080086 s = crush_hash32_3(bucket->hash, x, bucket->id, 0) %
Sage Weil5ecc0a02009-10-06 11:31:11 -070087 bucket->size;
88 bucket->perm[0] = s;
89 bucket->perm_n = 0xffff; /* magic value, see below */
90 goto out;
91 }
92
93 for (i = 0; i < bucket->size; i++)
94 bucket->perm[i] = i;
95 bucket->perm_n = 0;
96 } else if (bucket->perm_n == 0xffff) {
97 /* clean up after the r=0 case above */
98 for (i = 1; i < bucket->size; i++)
99 bucket->perm[i] = i;
100 bucket->perm[bucket->perm[0]] = 0;
101 bucket->perm_n = 1;
102 }
103
104 /* calculate permutation up to pr */
105 for (i = 0; i < bucket->perm_n; i++)
106 dprintk(" perm_choose have %d: %d\n", i, bucket->perm[i]);
107 while (bucket->perm_n <= pr) {
Eric Dumazet95c96172012-04-15 05:58:06 +0000108 unsigned int p = bucket->perm_n;
Sage Weil5ecc0a02009-10-06 11:31:11 -0700109 /* no point in swapping the final entry */
110 if (p < bucket->size - 1) {
Sage Weilfb690392009-11-07 20:18:22 -0800111 i = crush_hash32_3(bucket->hash, x, bucket->id, p) %
Sage Weil5ecc0a02009-10-06 11:31:11 -0700112 (bucket->size - p);
113 if (i) {
Eric Dumazet95c96172012-04-15 05:58:06 +0000114 unsigned int t = bucket->perm[p + i];
Sage Weil5ecc0a02009-10-06 11:31:11 -0700115 bucket->perm[p + i] = bucket->perm[p];
116 bucket->perm[p] = t;
117 }
118 dprintk(" perm_choose swap %d with %d\n", p, p+i);
119 }
120 bucket->perm_n++;
121 }
122 for (i = 0; i < bucket->size; i++)
123 dprintk(" perm_choose %d: %d\n", i, bucket->perm[i]);
124
125 s = bucket->perm[pr];
126out:
127 dprintk(" perm_choose %d sz=%d x=%d r=%d (%d) s=%d\n", bucket->id,
128 bucket->size, x, r, pr, s);
129 return bucket->items[s];
130}
131
132/* uniform */
133static int bucket_uniform_choose(struct crush_bucket_uniform *bucket,
134 int x, int r)
135{
136 return bucket_perm_choose(&bucket->h, x, r);
137}
138
139/* list */
140static int bucket_list_choose(struct crush_bucket_list *bucket,
141 int x, int r)
142{
143 int i;
144
145 for (i = bucket->h.size-1; i >= 0; i--) {
Ilya Dryomovb459be72015-06-12 13:21:07 +0300146 __u64 w = crush_hash32_4(bucket->h.hash, x, bucket->h.items[i],
Sage Weilfb690392009-11-07 20:18:22 -0800147 r, bucket->h.id);
Sage Weil5ecc0a02009-10-06 11:31:11 -0700148 w &= 0xffff;
149 dprintk("list_choose i=%d x=%d r=%d item %d weight %x "
150 "sw %x rand %llx",
151 i, x, r, bucket->h.items[i], bucket->item_weights[i],
152 bucket->sum_weights[i], w);
153 w *= bucket->sum_weights[i];
154 w = w >> 16;
155 /*dprintk(" scaled %llx\n", w);*/
156 if (w < bucket->item_weights[i])
157 return bucket->h.items[i];
158 }
159
Sage Weila1f48952012-05-07 15:35:24 -0700160 dprintk("bad list sums for bucket %d\n", bucket->h.id);
161 return bucket->h.items[0];
Sage Weil5ecc0a02009-10-06 11:31:11 -0700162}
163
164
165/* (binary) tree */
166static int height(int n)
167{
168 int h = 0;
169 while ((n & 1) == 0) {
170 h++;
171 n = n >> 1;
172 }
173 return h;
174}
175
176static int left(int x)
177{
178 int h = height(x);
179 return x - (1 << (h-1));
180}
181
182static int right(int x)
183{
184 int h = height(x);
185 return x + (1 << (h-1));
186}
187
188static int terminal(int x)
189{
190 return x & 1;
191}
192
193static int bucket_tree_choose(struct crush_bucket_tree *bucket,
194 int x, int r)
195{
Ilya Dryomov8f99c852013-12-24 21:19:24 +0200196 int n;
Sage Weil5ecc0a02009-10-06 11:31:11 -0700197 __u32 w;
198 __u64 t;
199
200 /* start at root */
201 n = bucket->num_nodes >> 1;
202
203 while (!terminal(n)) {
Ilya Dryomov8f99c852013-12-24 21:19:24 +0200204 int l;
Sage Weil5ecc0a02009-10-06 11:31:11 -0700205 /* pick point in [0, w) */
206 w = bucket->node_weights[n];
Sage Weilfb690392009-11-07 20:18:22 -0800207 t = (__u64)crush_hash32_4(bucket->h.hash, x, n, r,
208 bucket->h.id) * (__u64)w;
Sage Weil5ecc0a02009-10-06 11:31:11 -0700209 t = t >> 32;
210
211 /* descend to the left or right? */
212 l = left(n);
213 if (t < bucket->node_weights[l])
214 n = l;
215 else
216 n = right(n);
217 }
218
219 return bucket->h.items[n >> 1];
220}
221
222
223/* straw */
224
225static int bucket_straw_choose(struct crush_bucket_straw *bucket,
226 int x, int r)
227{
Sage Weil8b12d472012-05-07 15:38:35 -0700228 __u32 i;
Sage Weil5ecc0a02009-10-06 11:31:11 -0700229 int high = 0;
230 __u64 high_draw = 0;
231 __u64 draw;
232
233 for (i = 0; i < bucket->h.size; i++) {
Sage Weilfb690392009-11-07 20:18:22 -0800234 draw = crush_hash32_3(bucket->h.hash, x, bucket->h.items[i], r);
Sage Weil5ecc0a02009-10-06 11:31:11 -0700235 draw &= 0xffff;
236 draw *= bucket->straws[i];
237 if (i == 0 || draw > high_draw) {
238 high = i;
239 high_draw = draw;
240 }
241 }
242 return bucket->h.items[high];
243}
244
Ilya Dryomovb459be72015-06-12 13:21:07 +0300245/* compute 2^44*log2(input+1) */
246static __u64 crush_ln(unsigned int xin)
Ilya Dryomov958a2762015-04-14 16:54:52 +0300247{
Ilya Dryomovb459be72015-06-12 13:21:07 +0300248 unsigned int x = xin, x1;
249 int iexpon, index1, index2;
250 __u64 RH, LH, LL, xl64, result;
Ilya Dryomov958a2762015-04-14 16:54:52 +0300251
Ilya Dryomovb459be72015-06-12 13:21:07 +0300252 x++;
Ilya Dryomov958a2762015-04-14 16:54:52 +0300253
Ilya Dryomovb459be72015-06-12 13:21:07 +0300254 /* normalize input */
255 iexpon = 15;
256 while (!(x & 0x18000)) {
257 x <<= 1;
258 iexpon--;
259 }
Ilya Dryomov958a2762015-04-14 16:54:52 +0300260
Ilya Dryomovb459be72015-06-12 13:21:07 +0300261 index1 = (x >> 8) << 1;
262 /* RH ~ 2^56/index1 */
263 RH = __RH_LH_tbl[index1 - 256];
264 /* LH ~ 2^48 * log2(index1/256) */
265 LH = __RH_LH_tbl[index1 + 1 - 256];
Ilya Dryomov958a2762015-04-14 16:54:52 +0300266
Ilya Dryomovb459be72015-06-12 13:21:07 +0300267 /* RH*x ~ 2^48 * (2^15 + xf), xf<2^8 */
268 xl64 = (__s64)x * RH;
269 xl64 >>= 48;
270 x1 = xl64;
Ilya Dryomov958a2762015-04-14 16:54:52 +0300271
Ilya Dryomovb459be72015-06-12 13:21:07 +0300272 result = iexpon;
273 result <<= (12 + 32);
Ilya Dryomov958a2762015-04-14 16:54:52 +0300274
Ilya Dryomovb459be72015-06-12 13:21:07 +0300275 index2 = x1 & 0xff;
276 /* LL ~ 2^48*log2(1.0+index2/2^15) */
277 LL = __LL_tbl[index2];
Ilya Dryomov958a2762015-04-14 16:54:52 +0300278
Ilya Dryomovb459be72015-06-12 13:21:07 +0300279 LH = LH + LL;
Ilya Dryomov958a2762015-04-14 16:54:52 +0300280
Ilya Dryomovb459be72015-06-12 13:21:07 +0300281 LH >>= (48 - 12 - 32);
282 result += LH;
Ilya Dryomov958a2762015-04-14 16:54:52 +0300283
Ilya Dryomovb459be72015-06-12 13:21:07 +0300284 return result;
Ilya Dryomov958a2762015-04-14 16:54:52 +0300285}
286
287
288/*
289 * straw2
290 *
291 * for reference, see:
292 *
293 * http://en.wikipedia.org/wiki/Exponential_distribution#Distribution_of_the_minimum_of_exponential_random_variables
294 *
295 */
296
297static int bucket_straw2_choose(struct crush_bucket_straw2 *bucket,
298 int x, int r)
299{
Ilya Dryomovb459be72015-06-12 13:21:07 +0300300 unsigned int i, high = 0;
301 unsigned int u;
302 unsigned int w;
Ilya Dryomov958a2762015-04-14 16:54:52 +0300303 __s64 ln, draw, high_draw = 0;
304
305 for (i = 0; i < bucket->h.size; i++) {
306 w = bucket->item_weights[i];
307 if (w) {
308 u = crush_hash32_3(bucket->h.hash, x,
309 bucket->h.items[i], r);
310 u &= 0xffff;
311
312 /*
313 * for some reason slightly less than 0x10000 produces
314 * a slightly more accurate distribution... probably a
315 * rounding effect.
316 *
317 * the natural log lookup table maps [0,0xffff]
318 * (corresponding to real numbers [1/0x10000, 1] to
319 * [0, 0xffffffffffff] (corresponding to real numbers
320 * [-11.090355,0]).
321 */
322 ln = crush_ln(u) - 0x1000000000000ll;
323
324 /*
325 * divide by 16.16 fixed-point weight. note
326 * that the ln value is negative, so a larger
327 * weight means a larger (less negative) value
328 * for draw.
329 */
330 draw = div64_s64(ln, w);
331 } else {
332 draw = S64_MIN;
333 }
334
335 if (i == 0 || draw > high_draw) {
336 high = i;
337 high_draw = draw;
338 }
339 }
340 return bucket->h.items[high];
341}
342
343
Sage Weil5ecc0a02009-10-06 11:31:11 -0700344static int crush_bucket_choose(struct crush_bucket *in, int x, int r)
345{
Sage Weila1a31e72010-06-24 12:58:14 -0700346 dprintk(" crush_bucket_choose %d x=%d r=%d\n", in->id, x, r);
Sage Weila1f48952012-05-07 15:35:24 -0700347 BUG_ON(in->size == 0);
Sage Weil5ecc0a02009-10-06 11:31:11 -0700348 switch (in->alg) {
349 case CRUSH_BUCKET_UNIFORM:
350 return bucket_uniform_choose((struct crush_bucket_uniform *)in,
351 x, r);
352 case CRUSH_BUCKET_LIST:
353 return bucket_list_choose((struct crush_bucket_list *)in,
354 x, r);
355 case CRUSH_BUCKET_TREE:
356 return bucket_tree_choose((struct crush_bucket_tree *)in,
357 x, r);
358 case CRUSH_BUCKET_STRAW:
359 return bucket_straw_choose((struct crush_bucket_straw *)in,
360 x, r);
Ilya Dryomov958a2762015-04-14 16:54:52 +0300361 case CRUSH_BUCKET_STRAW2:
362 return bucket_straw2_choose((struct crush_bucket_straw2 *)in,
363 x, r);
Sage Weil5ecc0a02009-10-06 11:31:11 -0700364 default:
Sage Weila1f48952012-05-07 15:35:24 -0700365 dprintk("unknown bucket %d alg %d\n", in->id, in->alg);
Sage Weil50b885b2009-12-01 14:12:07 -0800366 return in->items[0];
Sage Weil5ecc0a02009-10-06 11:31:11 -0700367 }
368}
369
Ilya Dryomov958a2762015-04-14 16:54:52 +0300370
Sage Weil5ecc0a02009-10-06 11:31:11 -0700371/*
372 * true if device is marked "out" (failed, fully offloaded)
373 * of the cluster
374 */
Ilya Dryomovb3b33b02013-12-24 21:19:24 +0200375static int is_out(const struct crush_map *map,
376 const __u32 *weight, int weight_max,
377 int item, int x)
Sage Weil5ecc0a02009-10-06 11:31:11 -0700378{
Ilya Dryomovb3b33b02013-12-24 21:19:24 +0200379 if (item >= weight_max)
380 return 1;
Sage Weil153a1092010-07-05 09:44:17 -0700381 if (weight[item] >= 0x10000)
Sage Weil5ecc0a02009-10-06 11:31:11 -0700382 return 0;
383 if (weight[item] == 0)
384 return 1;
Sage Weilfb690392009-11-07 20:18:22 -0800385 if ((crush_hash32_2(CRUSH_HASH_RJENKINS1, x, item) & 0xffff)
386 < weight[item])
Sage Weil5ecc0a02009-10-06 11:31:11 -0700387 return 0;
388 return 1;
389}
390
391/**
Ilya Dryomov9fe07182013-12-24 21:19:25 +0200392 * crush_choose_firstn - choose numrep distinct items of given type
Sage Weil5ecc0a02009-10-06 11:31:11 -0700393 * @map: the crush_map
394 * @bucket: the bucket we are choose an item from
395 * @x: crush input value
396 * @numrep: the number of items to choose
397 * @type: the type of item to choose
398 * @out: pointer to output vector
399 * @outpos: our position in that vector
Ilya Dryomov45002262015-04-14 16:04:23 +0300400 * @out_size: size of the out vector
Ilya Dryomov0e32d712013-12-24 21:19:27 +0200401 * @tries: number of attempts to make
402 * @recurse_tries: number of attempts to have recursive chooseleaf make
Ilya Dryomov48a163d2014-03-19 16:58:36 +0200403 * @local_retries: localized retries
404 * @local_fallback_retries: localized fallback retries
Ilya Dryomov0e32d712013-12-24 21:19:27 +0200405 * @recurse_to_leaf: true if we want one device under each item of given type (chooseleaf instead of choose)
Ilya Dryomovdc6ae6d2016-01-31 14:36:07 +0100406 * @stable: stable mode starts rep=0 in the recursive call for all replicas
Ilya Dryomove2b149c2014-03-19 16:58:37 +0200407 * @vary_r: pass r to recursive calls
Sage Weil5ecc0a02009-10-06 11:31:11 -0700408 * @out2: second output vector for leaf items (if @recurse_to_leaf)
Ilya Dryomove2b149c2014-03-19 16:58:37 +0200409 * @parent_r: r value passed from the parent
Sage Weil5ecc0a02009-10-06 11:31:11 -0700410 */
Ilya Dryomov9fe07182013-12-24 21:19:25 +0200411static int crush_choose_firstn(const struct crush_map *map,
412 struct crush_bucket *bucket,
413 const __u32 *weight, int weight_max,
414 int x, int numrep, int type,
415 int *out, int outpos,
Ilya Dryomov45002262015-04-14 16:04:23 +0300416 int out_size,
Ilya Dryomov2d8be0b2013-12-24 21:19:27 +0200417 unsigned int tries,
418 unsigned int recurse_tries,
Ilya Dryomov48a163d2014-03-19 16:58:36 +0200419 unsigned int local_retries,
420 unsigned int local_fallback_retries,
Ilya Dryomov9fe07182013-12-24 21:19:25 +0200421 int recurse_to_leaf,
Ilya Dryomove2b149c2014-03-19 16:58:37 +0200422 unsigned int vary_r,
Ilya Dryomovdc6ae6d2016-01-31 14:36:07 +0100423 unsigned int stable,
Ilya Dryomove2b149c2014-03-19 16:58:37 +0200424 int *out2,
425 int parent_r)
Sage Weil5ecc0a02009-10-06 11:31:11 -0700426{
427 int rep;
Sage Weil8b12d472012-05-07 15:38:35 -0700428 unsigned int ftotal, flocal;
Sage Weil5ecc0a02009-10-06 11:31:11 -0700429 int retry_descent, retry_bucket, skip_rep;
430 struct crush_bucket *in = bucket;
431 int r;
432 int i;
Sage Weilb28813a2009-10-07 10:59:34 -0700433 int item = 0;
Sage Weil5ecc0a02009-10-06 11:31:11 -0700434 int itemtype;
435 int collide, reject;
Ilya Dryomov45002262015-04-14 16:04:23 +0300436 int count = out_size;
Sage Weila1a31e72010-06-24 12:58:14 -0700437
Ilya Dryomovdc6ae6d2016-01-31 14:36:07 +0100438 dprintk("CHOOSE%s bucket %d x %d outpos %d numrep %d tries %d recurse_tries %d local_retries %d local_fallback_retries %d parent_r %d stable %d\n",
Ilya Dryomove2b149c2014-03-19 16:58:37 +0200439 recurse_to_leaf ? "_LEAF" : "",
440 bucket->id, x, outpos, numrep,
441 tries, recurse_tries, local_retries, local_fallback_retries,
Ilya Dryomovdc6ae6d2016-01-31 14:36:07 +0100442 parent_r, stable);
Sage Weil5ecc0a02009-10-06 11:31:11 -0700443
Ilya Dryomovdc6ae6d2016-01-31 14:36:07 +0100444 for (rep = stable ? 0 : outpos; rep < numrep && count > 0 ; rep++) {
Sage Weil5ecc0a02009-10-06 11:31:11 -0700445 /* keep trying until we get a non-out, non-colliding item */
446 ftotal = 0;
447 skip_rep = 0;
448 do {
449 retry_descent = 0;
450 in = bucket; /* initial bucket */
451
452 /* choose through intervening buckets */
453 flocal = 0;
454 do {
Sage Weilb28813a2009-10-07 10:59:34 -0700455 collide = 0;
Sage Weil5ecc0a02009-10-06 11:31:11 -0700456 retry_bucket = 0;
Ilya Dryomove2b149c2014-03-19 16:58:37 +0200457 r = rep + parent_r;
Ilya Dryomov9fe07182013-12-24 21:19:25 +0200458 /* r' = r + f_total */
459 r += ftotal;
Sage Weil5ecc0a02009-10-06 11:31:11 -0700460
461 /* bucket choose */
Sage Weilb28813a2009-10-07 10:59:34 -0700462 if (in->size == 0) {
463 reject = 1;
464 goto reject;
465 }
Ilya Dryomov48a163d2014-03-19 16:58:36 +0200466 if (local_fallback_retries > 0 &&
Sage Weil546f04e2012-07-30 18:15:23 -0700467 flocal >= (in->size>>1) &&
Ilya Dryomov48a163d2014-03-19 16:58:36 +0200468 flocal > local_fallback_retries)
Sage Weil5ecc0a02009-10-06 11:31:11 -0700469 item = bucket_perm_choose(in, x, r);
470 else
471 item = crush_bucket_choose(in, x, r);
Sage Weila1f48952012-05-07 15:35:24 -0700472 if (item >= map->max_devices) {
473 dprintk(" bad item %d\n", item);
474 skip_rep = 1;
475 break;
476 }
Sage Weil5ecc0a02009-10-06 11:31:11 -0700477
478 /* desired type? */
479 if (item < 0)
480 itemtype = map->buckets[-1-item]->type;
481 else
482 itemtype = 0;
483 dprintk(" item %d type %d\n", item, itemtype);
484
485 /* keep going? */
486 if (itemtype != type) {
Sage Weila1f48952012-05-07 15:35:24 -0700487 if (item >= 0 ||
488 (-1-item) >= map->max_buckets) {
489 dprintk(" bad item type %d\n", type);
490 skip_rep = 1;
491 break;
492 }
Sage Weil5ecc0a02009-10-06 11:31:11 -0700493 in = map->buckets[-1-item];
Sage Weil55bda7a2010-06-24 12:55:48 -0700494 retry_bucket = 1;
Sage Weil5ecc0a02009-10-06 11:31:11 -0700495 continue;
496 }
497
498 /* collision? */
Sage Weil5ecc0a02009-10-06 11:31:11 -0700499 for (i = 0; i < outpos; i++) {
500 if (out[i] == item) {
501 collide = 1;
502 break;
503 }
504 }
505
Sage Weila1a31e72010-06-24 12:58:14 -0700506 reject = 0;
Sage Weil7d7c1f62013-01-15 18:49:09 -0800507 if (!collide && recurse_to_leaf) {
Sage Weila1a31e72010-06-24 12:58:14 -0700508 if (item < 0) {
Ilya Dryomove2b149c2014-03-19 16:58:37 +0200509 int sub_r;
510 if (vary_r)
511 sub_r = r >> (vary_r-1);
512 else
513 sub_r = 0;
Ilya Dryomov9fe07182013-12-24 21:19:25 +0200514 if (crush_choose_firstn(map,
Sage Weila1a31e72010-06-24 12:58:14 -0700515 map->buckets[-1-item],
Ilya Dryomovb3b33b02013-12-24 21:19:24 +0200516 weight, weight_max,
Ilya Dryomovdc6ae6d2016-01-31 14:36:07 +0100517 x, stable ? 1 : outpos+1, 0,
Ilya Dryomov45002262015-04-14 16:04:23 +0300518 out2, outpos, count,
Ilya Dryomov2d8be0b2013-12-24 21:19:27 +0200519 recurse_tries, 0,
Ilya Dryomov48a163d2014-03-19 16:58:36 +0200520 local_retries,
521 local_fallback_retries,
Ilya Dryomov9fe07182013-12-24 21:19:25 +0200522 0,
Ilya Dryomove2b149c2014-03-19 16:58:37 +0200523 vary_r,
Ilya Dryomovdc6ae6d2016-01-31 14:36:07 +0100524 stable,
Ilya Dryomove2b149c2014-03-19 16:58:37 +0200525 NULL,
526 sub_r) <= outpos)
Sage Weila1a31e72010-06-24 12:58:14 -0700527 /* didn't get leaf */
528 reject = 1;
529 } else {
530 /* we already have a leaf! */
531 out2[outpos] = item;
532 }
533 }
534
535 if (!reject) {
Sage Weil5ecc0a02009-10-06 11:31:11 -0700536 /* out? */
537 if (itemtype == 0)
538 reject = is_out(map, weight,
Ilya Dryomovb3b33b02013-12-24 21:19:24 +0200539 weight_max,
Sage Weil5ecc0a02009-10-06 11:31:11 -0700540 item, x);
541 else
542 reject = 0;
543 }
544
Sage Weilb28813a2009-10-07 10:59:34 -0700545reject:
Sage Weil5ecc0a02009-10-06 11:31:11 -0700546 if (reject || collide) {
547 ftotal++;
548 flocal++;
549
Ilya Dryomov48a163d2014-03-19 16:58:36 +0200550 if (collide && flocal <= local_retries)
Sage Weil5ecc0a02009-10-06 11:31:11 -0700551 /* retry locally a few times */
552 retry_bucket = 1;
Ilya Dryomov48a163d2014-03-19 16:58:36 +0200553 else if (local_fallback_retries > 0 &&
554 flocal <= in->size + local_fallback_retries)
Sage Weil5ecc0a02009-10-06 11:31:11 -0700555 /* exhaustive bucket search */
556 retry_bucket = 1;
Ilya Dryomov48a163d2014-03-19 16:58:36 +0200557 else if (ftotal < tries)
Sage Weil5ecc0a02009-10-06 11:31:11 -0700558 /* then retry descent */
559 retry_descent = 1;
560 else
561 /* else give up */
562 skip_rep = 1;
563 dprintk(" reject %d collide %d "
Sage Weil8b12d472012-05-07 15:38:35 -0700564 "ftotal %u flocal %u\n",
Sage Weil5ecc0a02009-10-06 11:31:11 -0700565 reject, collide, ftotal,
566 flocal);
567 }
568 } while (retry_bucket);
569 } while (retry_descent);
570
571 if (skip_rep) {
Ilya Dryomov9fe07182013-12-24 21:19:25 +0200572 dprintk("skip rep\n");
573 continue;
Sage Weil5ecc0a02009-10-06 11:31:11 -0700574 }
575
Sage Weila1a31e72010-06-24 12:58:14 -0700576 dprintk("CHOOSE got %d\n", item);
Sage Weil5ecc0a02009-10-06 11:31:11 -0700577 out[outpos] = item;
578 outpos++;
Ilya Dryomov45002262015-04-14 16:04:23 +0300579 count--;
Ilya Dryomovb459be72015-06-12 13:21:07 +0300580#ifndef __KERNEL__
581 if (map->choose_tries && ftotal <= map->choose_total_tries)
582 map->choose_tries[ftotal]++;
583#endif
Sage Weil5ecc0a02009-10-06 11:31:11 -0700584 }
585
Sage Weila1a31e72010-06-24 12:58:14 -0700586 dprintk("CHOOSE returns %d\n", outpos);
Sage Weil5ecc0a02009-10-06 11:31:11 -0700587 return outpos;
588}
589
590
591/**
Ilya Dryomov9fe07182013-12-24 21:19:25 +0200592 * crush_choose_indep: alternative breadth-first positionally stable mapping
Ilya Dryomov9a3b4902013-12-24 21:19:25 +0200593 *
594 */
595static void crush_choose_indep(const struct crush_map *map,
Ilya Dryomovbe3226a2013-12-24 21:19:26 +0200596 struct crush_bucket *bucket,
597 const __u32 *weight, int weight_max,
Ilya Dryomovab4ce2b52013-12-24 21:19:25 +0200598 int x, int left, int numrep, int type,
Ilya Dryomovbe3226a2013-12-24 21:19:26 +0200599 int *out, int outpos,
Ilya Dryomov2d8be0b2013-12-24 21:19:27 +0200600 unsigned int tries,
601 unsigned int recurse_tries,
Ilya Dryomovbe3226a2013-12-24 21:19:26 +0200602 int recurse_to_leaf,
Ilya Dryomov41586082013-12-24 21:19:25 +0200603 int *out2,
604 int parent_r)
Ilya Dryomov9a3b4902013-12-24 21:19:25 +0200605{
606 struct crush_bucket *in = bucket;
Ilya Dryomovab4ce2b52013-12-24 21:19:25 +0200607 int endpos = outpos + left;
Ilya Dryomov9a3b4902013-12-24 21:19:25 +0200608 int rep;
609 unsigned int ftotal;
610 int r;
611 int i;
612 int item = 0;
613 int itemtype;
614 int collide;
615
616 dprintk("CHOOSE%s INDEP bucket %d x %d outpos %d numrep %d\n", recurse_to_leaf ? "_LEAF" : "",
617 bucket->id, x, outpos, numrep);
618
619 /* initially my result is undefined */
Ilya Dryomovab4ce2b52013-12-24 21:19:25 +0200620 for (rep = outpos; rep < endpos; rep++) {
Ilya Dryomov9a3b4902013-12-24 21:19:25 +0200621 out[rep] = CRUSH_ITEM_UNDEF;
622 if (out2)
623 out2[rep] = CRUSH_ITEM_UNDEF;
624 }
625
Ilya Dryomov2d8be0b2013-12-24 21:19:27 +0200626 for (ftotal = 0; left > 0 && ftotal < tries; ftotal++) {
Ilya Dryomovb459be72015-06-12 13:21:07 +0300627#ifdef DEBUG_INDEP
628 if (out2 && ftotal) {
629 dprintk("%u %d a: ", ftotal, left);
630 for (rep = outpos; rep < endpos; rep++) {
631 dprintk(" %d", out[rep]);
632 }
633 dprintk("\n");
634 dprintk("%u %d b: ", ftotal, left);
635 for (rep = outpos; rep < endpos; rep++) {
636 dprintk(" %d", out2[rep]);
637 }
638 dprintk("\n");
639 }
640#endif
Ilya Dryomovab4ce2b52013-12-24 21:19:25 +0200641 for (rep = outpos; rep < endpos; rep++) {
Ilya Dryomov9a3b4902013-12-24 21:19:25 +0200642 if (out[rep] != CRUSH_ITEM_UNDEF)
643 continue;
644
645 in = bucket; /* initial bucket */
646
647 /* choose through intervening buckets */
648 for (;;) {
Ilya Dryomov3102b0a2013-12-24 21:19:25 +0200649 /* note: we base the choice on the position
650 * even in the nested call. that means that
651 * if the first layer chooses the same bucket
652 * in a different position, we will tend to
653 * choose a different item in that bucket.
654 * this will involve more devices in data
655 * movement and tend to distribute the load.
656 */
Ilya Dryomov41586082013-12-24 21:19:25 +0200657 r = rep + parent_r;
Ilya Dryomov9a3b4902013-12-24 21:19:25 +0200658
659 /* be careful */
660 if (in->alg == CRUSH_BUCKET_UNIFORM &&
661 in->size % numrep == 0)
662 /* r'=r+(n+1)*f_total */
663 r += (numrep+1) * ftotal;
664 else
665 /* r' = r + n*f_total */
666 r += numrep * ftotal;
667
668 /* bucket choose */
669 if (in->size == 0) {
670 dprintk(" empty bucket\n");
671 break;
672 }
673
674 item = crush_bucket_choose(in, x, r);
675 if (item >= map->max_devices) {
676 dprintk(" bad item %d\n", item);
677 out[rep] = CRUSH_ITEM_NONE;
678 if (out2)
679 out2[rep] = CRUSH_ITEM_NONE;
680 left--;
681 break;
682 }
683
684 /* desired type? */
685 if (item < 0)
686 itemtype = map->buckets[-1-item]->type;
687 else
688 itemtype = 0;
689 dprintk(" item %d type %d\n", item, itemtype);
690
691 /* keep going? */
692 if (itemtype != type) {
693 if (item >= 0 ||
694 (-1-item) >= map->max_buckets) {
695 dprintk(" bad item type %d\n", type);
696 out[rep] = CRUSH_ITEM_NONE;
697 if (out2)
698 out2[rep] =
699 CRUSH_ITEM_NONE;
700 left--;
701 break;
702 }
703 in = map->buckets[-1-item];
704 continue;
705 }
706
707 /* collision? */
708 collide = 0;
Ilya Dryomovab4ce2b52013-12-24 21:19:25 +0200709 for (i = outpos; i < endpos; i++) {
Ilya Dryomov9a3b4902013-12-24 21:19:25 +0200710 if (out[i] == item) {
711 collide = 1;
712 break;
713 }
714 }
715 if (collide)
716 break;
717
718 if (recurse_to_leaf) {
719 if (item < 0) {
720 crush_choose_indep(map,
Ilya Dryomovbe3226a2013-12-24 21:19:26 +0200721 map->buckets[-1-item],
722 weight, weight_max,
723 x, 1, numrep, 0,
724 out2, rep,
Ilya Dryomov2d8be0b2013-12-24 21:19:27 +0200725 recurse_tries, 0,
Ilya Dryomovbe3226a2013-12-24 21:19:26 +0200726 0, NULL, r);
Ilya Dryomov9a3b4902013-12-24 21:19:25 +0200727 if (out2[rep] == CRUSH_ITEM_NONE) {
728 /* placed nothing; no leaf */
729 break;
730 }
731 } else {
732 /* we already have a leaf! */
733 out2[rep] = item;
734 }
735 }
736
737 /* out? */
738 if (itemtype == 0 &&
739 is_out(map, weight, weight_max, item, x))
740 break;
741
742 /* yay! */
743 out[rep] = item;
744 left--;
745 break;
746 }
747 }
748 }
Ilya Dryomovab4ce2b52013-12-24 21:19:25 +0200749 for (rep = outpos; rep < endpos; rep++) {
Ilya Dryomov9a3b4902013-12-24 21:19:25 +0200750 if (out[rep] == CRUSH_ITEM_UNDEF) {
751 out[rep] = CRUSH_ITEM_NONE;
752 }
753 if (out2 && out2[rep] == CRUSH_ITEM_UNDEF) {
754 out2[rep] = CRUSH_ITEM_NONE;
755 }
756 }
Ilya Dryomovb459be72015-06-12 13:21:07 +0300757#ifndef __KERNEL__
758 if (map->choose_tries && ftotal <= map->choose_total_tries)
759 map->choose_tries[ftotal]++;
760#endif
761#ifdef DEBUG_INDEP
762 if (out2) {
763 dprintk("%u %d a: ", ftotal, left);
764 for (rep = outpos; rep < endpos; rep++) {
765 dprintk(" %d", out[rep]);
766 }
767 dprintk("\n");
768 dprintk("%u %d b: ", ftotal, left);
769 for (rep = outpos; rep < endpos; rep++) {
770 dprintk(" %d", out2[rep]);
771 }
772 dprintk("\n");
773 }
774#endif
Ilya Dryomov9a3b4902013-12-24 21:19:25 +0200775}
776
777/**
Sage Weil5ecc0a02009-10-06 11:31:11 -0700778 * crush_do_rule - calculate a mapping with the given input and rule
779 * @map: the crush_map
780 * @ruleno: the rule id
781 * @x: hash input
782 * @result: pointer to result vector
783 * @result_max: maximum result size
Ilya Dryomovb3b33b02013-12-24 21:19:24 +0200784 * @weight: weight vector (for map leaves)
785 * @weight_max: size of weight vector
Ilya Dryomove8ef19c2013-12-24 21:19:24 +0200786 * @scratch: scratch vector for private use; must be >= 3 * result_max
Sage Weil5ecc0a02009-10-06 11:31:11 -0700787 */
Sage Weil8b12d472012-05-07 15:38:35 -0700788int crush_do_rule(const struct crush_map *map,
Sage Weil5ecc0a02009-10-06 11:31:11 -0700789 int ruleno, int x, int *result, int result_max,
Ilya Dryomove8ef19c2013-12-24 21:19:24 +0200790 const __u32 *weight, int weight_max,
791 int *scratch)
Sage Weil5ecc0a02009-10-06 11:31:11 -0700792{
793 int result_len;
Ilya Dryomove8ef19c2013-12-24 21:19:24 +0200794 int *a = scratch;
795 int *b = scratch + result_max;
796 int *c = scratch + result_max*2;
Sage Weil5ecc0a02009-10-06 11:31:11 -0700797 int recurse_to_leaf;
798 int *w;
799 int wsize = 0;
800 int *o;
801 int osize;
802 int *tmp;
803 struct crush_rule *rule;
Sage Weil8b12d472012-05-07 15:38:35 -0700804 __u32 step;
Sage Weil5ecc0a02009-10-06 11:31:11 -0700805 int i, j;
806 int numrep;
Ilya Dryomov45002262015-04-14 16:04:23 +0300807 int out_size;
Ilya Dryomov48a163d2014-03-19 16:58:36 +0200808 /*
809 * the original choose_total_tries value was off by one (it
810 * counted "retries" and not "tries"). add one.
811 */
812 int choose_tries = map->choose_total_tries + 1;
Ilya Dryomovf18650a2013-12-24 21:19:26 +0200813 int choose_leaf_tries = 0;
Ilya Dryomov48a163d2014-03-19 16:58:36 +0200814 /*
815 * the local tries values were counted as "retries", though,
816 * and need no adjustment
817 */
818 int choose_local_retries = map->choose_local_tries;
819 int choose_local_fallback_retries = map->choose_local_fallback_tries;
Sage Weil5ecc0a02009-10-06 11:31:11 -0700820
Ilya Dryomove2b149c2014-03-19 16:58:37 +0200821 int vary_r = map->chooseleaf_vary_r;
Ilya Dryomovdc6ae6d2016-01-31 14:36:07 +0100822 int stable = map->chooseleaf_stable;
Ilya Dryomove2b149c2014-03-19 16:58:37 +0200823
Sage Weila1f48952012-05-07 15:35:24 -0700824 if ((__u32)ruleno >= map->max_rules) {
825 dprintk(" bad ruleno %d\n", ruleno);
826 return 0;
827 }
Sage Weil5ecc0a02009-10-06 11:31:11 -0700828
829 rule = map->rules[ruleno];
830 result_len = 0;
831 w = a;
832 o = b;
833
Sage Weil5ecc0a02009-10-06 11:31:11 -0700834 for (step = 0; step < rule->len; step++) {
Ilya Dryomov8f99c852013-12-24 21:19:24 +0200835 int firstn = 0;
Sage Weil06682162012-05-07 15:35:48 -0700836 struct crush_rule_step *curstep = &rule->steps[step];
837
Sage Weil06682162012-05-07 15:35:48 -0700838 switch (curstep->op) {
Sage Weil5ecc0a02009-10-06 11:31:11 -0700839 case CRUSH_RULE_TAKE:
Ilya Dryomov8f529792015-06-12 11:20:03 +0300840 if ((curstep->arg1 >= 0 &&
841 curstep->arg1 < map->max_devices) ||
Ilya Dryomov56a4f302016-01-31 14:36:05 +0100842 (-1-curstep->arg1 >= 0 &&
843 -1-curstep->arg1 < map->max_buckets &&
Ilya Dryomov8f529792015-06-12 11:20:03 +0300844 map->buckets[-1-curstep->arg1])) {
845 w[0] = curstep->arg1;
846 wsize = 1;
847 } else {
848 dprintk(" bad take value %d\n", curstep->arg1);
849 }
Sage Weil5ecc0a02009-10-06 11:31:11 -0700850 break;
851
Ilya Dryomovcc10df42013-12-24 21:19:26 +0200852 case CRUSH_RULE_SET_CHOOSE_TRIES:
853 if (curstep->arg1 > 0)
854 choose_tries = curstep->arg1;
855 break;
856
Ilya Dryomov917edad2013-12-24 21:19:26 +0200857 case CRUSH_RULE_SET_CHOOSELEAF_TRIES:
Ilya Dryomovbe3226a2013-12-24 21:19:26 +0200858 if (curstep->arg1 > 0)
859 choose_leaf_tries = curstep->arg1;
860 break;
861
Ilya Dryomovf046bf92013-12-24 21:19:27 +0200862 case CRUSH_RULE_SET_CHOOSE_LOCAL_TRIES:
Ilya Dryomov6ed10022014-03-19 16:58:37 +0200863 if (curstep->arg1 >= 0)
Ilya Dryomov48a163d2014-03-19 16:58:36 +0200864 choose_local_retries = curstep->arg1;
Ilya Dryomovf046bf92013-12-24 21:19:27 +0200865 break;
866
867 case CRUSH_RULE_SET_CHOOSE_LOCAL_FALLBACK_TRIES:
Ilya Dryomov6ed10022014-03-19 16:58:37 +0200868 if (curstep->arg1 >= 0)
Ilya Dryomov48a163d2014-03-19 16:58:36 +0200869 choose_local_fallback_retries = curstep->arg1;
Ilya Dryomovf046bf92013-12-24 21:19:27 +0200870 break;
871
Ilya Dryomovd83ed852014-03-19 16:58:37 +0200872 case CRUSH_RULE_SET_CHOOSELEAF_VARY_R:
873 if (curstep->arg1 >= 0)
874 vary_r = curstep->arg1;
875 break;
876
Ilya Dryomovdc6ae6d2016-01-31 14:36:07 +0100877 case CRUSH_RULE_SET_CHOOSELEAF_STABLE:
878 if (curstep->arg1 >= 0)
879 stable = curstep->arg1;
880 break;
881
Ilya Dryomov917edad2013-12-24 21:19:26 +0200882 case CRUSH_RULE_CHOOSELEAF_FIRSTN:
Sage Weil5ecc0a02009-10-06 11:31:11 -0700883 case CRUSH_RULE_CHOOSE_FIRSTN:
884 firstn = 1;
Sage Weil06682162012-05-07 15:35:48 -0700885 /* fall through */
Ilya Dryomov917edad2013-12-24 21:19:26 +0200886 case CRUSH_RULE_CHOOSELEAF_INDEP:
Sage Weil5ecc0a02009-10-06 11:31:11 -0700887 case CRUSH_RULE_CHOOSE_INDEP:
Sage Weila1f48952012-05-07 15:35:24 -0700888 if (wsize == 0)
889 break;
Sage Weil5ecc0a02009-10-06 11:31:11 -0700890
891 recurse_to_leaf =
Sage Weil06682162012-05-07 15:35:48 -0700892 curstep->op ==
Ilya Dryomov917edad2013-12-24 21:19:26 +0200893 CRUSH_RULE_CHOOSELEAF_FIRSTN ||
Sage Weil06682162012-05-07 15:35:48 -0700894 curstep->op ==
Ilya Dryomov917edad2013-12-24 21:19:26 +0200895 CRUSH_RULE_CHOOSELEAF_INDEP;
Sage Weil5ecc0a02009-10-06 11:31:11 -0700896
897 /* reset output */
898 osize = 0;
899
900 for (i = 0; i < wsize; i++) {
Ilya Dryomovf224a692016-01-31 14:35:59 +0100901 int bno;
Sage Weil5ecc0a02009-10-06 11:31:11 -0700902 /*
903 * see CRUSH_N, CRUSH_N_MINUS macros.
904 * basically, numrep <= 0 means relative to
905 * the provided result_max
906 */
Sage Weil06682162012-05-07 15:35:48 -0700907 numrep = curstep->arg1;
Sage Weil5ecc0a02009-10-06 11:31:11 -0700908 if (numrep <= 0) {
909 numrep += result_max;
910 if (numrep <= 0)
911 continue;
912 }
913 j = 0;
Ilya Dryomovf224a692016-01-31 14:35:59 +0100914 /* make sure bucket id is valid */
915 bno = -1 - w[i];
916 if (bno < 0 || bno >= map->max_buckets) {
917 /* w[i] is probably CRUSH_ITEM_NONE */
918 dprintk(" bad w[i] %d\n", w[i]);
919 continue;
920 }
Ilya Dryomov9a3b4902013-12-24 21:19:25 +0200921 if (firstn) {
Ilya Dryomovd390bb22013-12-24 21:19:26 +0200922 int recurse_tries;
923 if (choose_leaf_tries)
924 recurse_tries =
925 choose_leaf_tries;
926 else if (map->chooseleaf_descend_once)
927 recurse_tries = 1;
928 else
929 recurse_tries = choose_tries;
Ilya Dryomov9fe07182013-12-24 21:19:25 +0200930 osize += crush_choose_firstn(
931 map,
Ilya Dryomovf224a692016-01-31 14:35:59 +0100932 map->buckets[bno],
Ilya Dryomov9fe07182013-12-24 21:19:25 +0200933 weight, weight_max,
934 x, numrep,
935 curstep->arg2,
936 o+osize, j,
Ilya Dryomov45002262015-04-14 16:04:23 +0300937 result_max-osize,
Ilya Dryomovf18650a2013-12-24 21:19:26 +0200938 choose_tries,
Ilya Dryomovd390bb22013-12-24 21:19:26 +0200939 recurse_tries,
Ilya Dryomov48a163d2014-03-19 16:58:36 +0200940 choose_local_retries,
941 choose_local_fallback_retries,
Ilya Dryomov9fe07182013-12-24 21:19:25 +0200942 recurse_to_leaf,
Ilya Dryomove2b149c2014-03-19 16:58:37 +0200943 vary_r,
Ilya Dryomovdc6ae6d2016-01-31 14:36:07 +0100944 stable,
Ilya Dryomove2b149c2014-03-19 16:58:37 +0200945 c+osize,
946 0);
Ilya Dryomov9a3b4902013-12-24 21:19:25 +0200947 } else {
Ilya Dryomov45002262015-04-14 16:04:23 +0300948 out_size = ((numrep < (result_max-osize)) ?
Ilya Dryomovb459be72015-06-12 13:21:07 +0300949 numrep : (result_max-osize));
Ilya Dryomov9fe07182013-12-24 21:19:25 +0200950 crush_choose_indep(
951 map,
Ilya Dryomovf224a692016-01-31 14:35:59 +0100952 map->buckets[bno],
Ilya Dryomov9fe07182013-12-24 21:19:25 +0200953 weight, weight_max,
Ilya Dryomov45002262015-04-14 16:04:23 +0300954 x, out_size, numrep,
Ilya Dryomov9fe07182013-12-24 21:19:25 +0200955 curstep->arg2,
956 o+osize, j,
Ilya Dryomovf18650a2013-12-24 21:19:26 +0200957 choose_tries,
Ilya Dryomovd390bb22013-12-24 21:19:26 +0200958 choose_leaf_tries ?
959 choose_leaf_tries : 1,
Ilya Dryomov9fe07182013-12-24 21:19:25 +0200960 recurse_to_leaf,
Ilya Dryomov41586082013-12-24 21:19:25 +0200961 c+osize,
962 0);
Ilya Dryomov45002262015-04-14 16:04:23 +0300963 osize += out_size;
Ilya Dryomov9a3b4902013-12-24 21:19:25 +0200964 }
Sage Weil5ecc0a02009-10-06 11:31:11 -0700965 }
966
967 if (recurse_to_leaf)
968 /* copy final _leaf_ values to output set */
969 memcpy(o, c, osize*sizeof(*o));
970
Ilya Dryomov2a4ba742013-12-24 21:19:24 +0200971 /* swap o and w arrays */
Sage Weil5ecc0a02009-10-06 11:31:11 -0700972 tmp = o;
973 o = w;
974 w = tmp;
975 wsize = osize;
976 break;
977
978
979 case CRUSH_RULE_EMIT:
980 for (i = 0; i < wsize && result_len < result_max; i++) {
981 result[result_len] = w[i];
982 result_len++;
983 }
984 wsize = 0;
985 break;
986
987 default:
Sage Weila1f48952012-05-07 15:35:24 -0700988 dprintk(" unknown op %d at step %d\n",
989 curstep->op, step);
990 break;
Sage Weil5ecc0a02009-10-06 11:31:11 -0700991 }
992 }
Sage Weilf1932fc2011-12-07 09:10:26 -0800993 return result_len;
Sage Weil5ecc0a02009-10-06 11:31:11 -0700994}