crush: strip firstn conditionals out of crush_choose, rename

Now that indep is handled by crush_choose_indep, rename crush_choose to
crush_choose_firstn and remove all the conditionals.  This ends up
stripping out *lots* of code.

Note that it *also* makes it obvious that the shenanigans we were playing
with r' for uniform buckets were broken for firstn mode.  This appears to
have happened waaaay back in commit dae8bec9 (or earlier)... 2007.

Reflects ceph.git commit 94350996cb2035850bcbece6a77a9b0394177ec9.

Signed-off-by: Ilya Dryomov <ilya.dryomov@inktank.com>
Reviewed-by: Sage Weil <sage@inktank.com>
This commit is contained in:
Ilya Dryomov 2013-12-24 21:19:25 +02:00
parent 3102b0a5b4
commit 9fe0718282

View file

@ -282,7 +282,7 @@ static int is_out(const struct crush_map *map,
} }
/** /**
* crush_choose - choose numrep distinct items of given type * crush_choose_firstn - choose numrep distinct items of given type
* @map: the crush_map * @map: the crush_map
* @bucket: the bucket we are choose an item from * @bucket: the bucket we are choose an item from
* @x: crush input value * @x: crush input value
@ -290,18 +290,17 @@ static int is_out(const struct crush_map *map,
* @type: the type of item to choose * @type: the type of item to choose
* @out: pointer to output vector * @out: pointer to output vector
* @outpos: our position in that vector * @outpos: our position in that vector
* @firstn: true if choosing "first n" items, false if choosing "indep"
* @recurse_to_leaf: true if we want one device under each item of given type * @recurse_to_leaf: true if we want one device under each item of given type
* @descend_once: true if we should only try one descent before giving up * @descend_once: true if we should only try one descent before giving up
* @out2: second output vector for leaf items (if @recurse_to_leaf) * @out2: second output vector for leaf items (if @recurse_to_leaf)
*/ */
static int crush_choose(const struct crush_map *map, static int crush_choose_firstn(const struct crush_map *map,
struct crush_bucket *bucket, struct crush_bucket *bucket,
const __u32 *weight, int weight_max, const __u32 *weight, int weight_max,
int x, int numrep, int type, int x, int numrep, int type,
int *out, int outpos, int *out, int outpos,
int firstn, int recurse_to_leaf, int recurse_to_leaf,
int descend_once, int *out2) int descend_once, int *out2)
{ {
int rep; int rep;
unsigned int ftotal, flocal; unsigned int ftotal, flocal;
@ -330,26 +329,8 @@ static int crush_choose(const struct crush_map *map,
collide = 0; collide = 0;
retry_bucket = 0; retry_bucket = 0;
r = rep; r = rep;
if (in->alg == CRUSH_BUCKET_UNIFORM) { /* r' = r + f_total */
/* be careful */ r += ftotal;
if (firstn || (__u32)numrep >= in->size)
/* r' = r + f_total */
r += ftotal;
else if (in->size % numrep == 0)
/* r'=r+(n+1)*f_local */
r += (numrep+1) *
(flocal+ftotal);
else
/* r' = r + n*f_local */
r += numrep * (flocal+ftotal);
} else {
if (firstn)
/* r' = r + f_total */
r += ftotal;
else
/* r' = r + n*f_local */
r += numrep * (flocal+ftotal);
}
/* bucket choose */ /* bucket choose */
if (in->size == 0) { if (in->size == 0) {
@ -399,12 +380,12 @@ static int crush_choose(const struct crush_map *map,
reject = 0; reject = 0;
if (!collide && recurse_to_leaf) { if (!collide && recurse_to_leaf) {
if (item < 0) { if (item < 0) {
if (crush_choose(map, if (crush_choose_firstn(map,
map->buckets[-1-item], map->buckets[-1-item],
weight, weight_max, weight, weight_max,
x, outpos+1, 0, x, outpos+1, 0,
out2, outpos, out2, outpos,
firstn, 0, 0,
map->chooseleaf_descend_once, map->chooseleaf_descend_once,
NULL) <= outpos) NULL) <= outpos)
/* didn't get leaf */ /* didn't get leaf */
@ -455,12 +436,8 @@ static int crush_choose(const struct crush_map *map,
} while (retry_descent); } while (retry_descent);
if (skip_rep) { if (skip_rep) {
if (firstn) { dprintk("skip rep\n");
dprintk("skip rep\n"); continue;
continue;
}
dprintk("undef rep, continuing\n");
item = CRUSH_ITEM_UNDEF;
} }
dprintk("CHOOSE got %d\n", item); dprintk("CHOOSE got %d\n", item);
@ -474,7 +451,7 @@ static int crush_choose(const struct crush_map *map,
/** /**
* choose indep: alternative breadth-first positionally stable mapping * crush_choose_indep: alternative breadth-first positionally stable mapping
* *
*/ */
static void crush_choose_indep(const struct crush_map *map, static void crush_choose_indep(const struct crush_map *map,
@ -707,24 +684,25 @@ int crush_do_rule(const struct crush_map *map,
} }
j = 0; j = 0;
if (firstn) { if (firstn) {
osize += crush_choose(map, osize += crush_choose_firstn(
map->buckets[-1-w[i]], map,
weight, weight_max, map->buckets[-1-w[i]],
x, numrep, weight, weight_max,
curstep->arg2, x, numrep,
o+osize, j, curstep->arg2,
firstn, o+osize, j,
recurse_to_leaf, recurse_to_leaf,
descend_once, c+osize); descend_once, c+osize);
} else { } else {
crush_choose_indep(map, crush_choose_indep(
map->buckets[-1-w[i]], map,
weight, weight_max, map->buckets[-1-w[i]],
x, numrep, weight, weight_max,
curstep->arg2, x, numrep,
o+osize, j, curstep->arg2,
recurse_to_leaf, o+osize, j,
c+osize); recurse_to_leaf,
c+osize);
osize += numrep; osize += numrep;
} }
} }