From 03217f4abebe76240df8aa6500e182c553a0b224 Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Thu, 18 Jun 2009 14:23:43 -0700 Subject: [PATCH] crush: fix coding style, whitespace --- src/crush/crush.c | 10 +++---- src/crush/crush.h | 5 ++-- src/crush/mapper.c | 69 +++++++++++++++++++++++++++------------------- 3 files changed, 49 insertions(+), 35 deletions(-) diff --git a/src/crush/crush.c b/src/crush/crush.c index d0f11287c3e02..13755cdc4fb3d 100644 --- a/src/crush/crush.c +++ b/src/crush/crush.c @@ -20,17 +20,17 @@ int crush_get_bucket_item_weight(struct crush_bucket *b, int p) if (p >= b->size) return 0; - switch (b->alg) { + switch (b->alg) { case CRUSH_BUCKET_UNIFORM: - return ((struct crush_bucket_uniform*)b)->item_weight; + return ((struct crush_bucket_uniform *)b)->item_weight; case CRUSH_BUCKET_LIST: - return ((struct crush_bucket_list*)b)->item_weights[p]; + return ((struct crush_bucket_list *)b)->item_weights[p]; case CRUSH_BUCKET_TREE: if (p & 1) - return ((struct crush_bucket_tree*)b)->node_weights[p]; + return ((struct crush_bucket_tree *)b)->node_weights[p]; return 0; case CRUSH_BUCKET_STRAW: - return ((struct crush_bucket_straw*)b)->item_weights[p]; + return ((struct crush_bucket_straw *)b)->item_weights[p]; } return 0; } diff --git a/src/crush/crush.h b/src/crush/crush.h index 58e79a0e8ec5c..1d89bfde4778e 100644 --- a/src/crush/crush.h +++ b/src/crush/crush.h @@ -40,7 +40,7 @@ enum { CRUSH_RULE_NOOP = 0, CRUSH_RULE_TAKE = 1, /* arg1 = value to start with */ CRUSH_RULE_CHOOSE_FIRSTN = 2, /* arg1 = num items to pick */ - /* arg2 = type */ + /* arg2 = type */ CRUSH_RULE_CHOOSE_INDEP = 3, /* same */ CRUSH_RULE_EMIT = 4, /* no args */ CRUSH_RULE_CHOOSE_LEAF_FIRSTN = 6, @@ -97,7 +97,8 @@ enum { CRUSH_BUCKET_TREE = 3, CRUSH_BUCKET_STRAW = 4 }; -static inline const char *crush_bucket_alg_name(int alg) { +static inline const char *crush_bucket_alg_name(int alg) +{ switch (alg) { case CRUSH_BUCKET_UNIFORM: return "uniform"; case CRUSH_BUCKET_LIST: return "list"; diff --git a/src/crush/mapper.c b/src/crush/mapper.c index 773428cffc04a..8dfe212e65a18 100644 --- a/src/crush/mapper.c +++ b/src/crush/mapper.c @@ -2,7 +2,7 @@ #ifdef __KERNEL__ # include # include -# include +# include # include # ifndef dprintk # define dprintk(args...) @@ -66,7 +66,7 @@ static int bucket_perm_choose(struct crush_bucket *bucket, if (bucket->perm_x != x || bucket->perm_n == 0) { dprintk("bucket %d new x=%d\n", bucket->id, x); bucket->perm_x = x; - + /* optimize common r=0 case */ if (pr == 0) { s = crush_hash32_3(x, bucket->id, 0) % @@ -75,7 +75,7 @@ static int bucket_perm_choose(struct crush_bucket *bucket, bucket->perm_n = 0xffff; goto out; } - + for (i = 0; i < bucket->size; i++) bucket->perm[i] = i; bucket->perm_n = 0; @@ -88,7 +88,7 @@ static int bucket_perm_choose(struct crush_bucket *bucket, } /* calculate permutation up to pr */ - for (i = 0; i < bucket->perm_n; i++) + for (i = 0; i < bucket->perm_n; i++) dprintk(" perm_choose have %d: %d\n", i, bucket->perm[i]); while (bucket->perm_n <= pr) { unsigned p = bucket->perm_n; @@ -105,12 +105,13 @@ static int bucket_perm_choose(struct crush_bucket *bucket, } bucket->perm_n++; } - for (i = 0; i < bucket->size; i++) + for (i = 0; i < bucket->size; i++) dprintk(" perm_choose %d: %d\n", i, bucket->perm[i]); s = bucket->perm[pr]; out: - dprintk(" perm_choose %d sz=%d x=%d r=%d (%d) s=%d\n", bucket->id, bucket->size, x, r, pr, s); + dprintk(" perm_choose %d sz=%d x=%d r=%d (%d) s=%d\n", bucket->id, + bucket->size, x, r, pr, s); return bucket->items[s]; } @@ -131,14 +132,15 @@ static int bucket_list_choose(struct crush_bucket_list *bucket, __u64 w = crush_hash32_4(x, bucket->h.items[i], r, bucket->h.id); w &= 0xffff; - /*dprintk("list_choose i=%d x=%d r=%d item %d weight %x sum_weight %x rand %llx", - i, x, r, bucket->h.items[i], bucket->item_weights[i], bucket->sum_weights[i], w);*/ + dprintk("list_choose i=%d x=%d r=%d item %d weight %x " + "sw %x rand %llx", + i, x, r, bucket->h.items[i], bucket->item_weights[i], + bucket->sum_weights[i], w); w *= bucket->sum_weights[i]; w = w >> 16; /*dprintk(" scaled %llx\n", w);*/ - if (w < bucket->item_weights[i]) { + if (w < bucket->item_weights[i]) return bucket->h.items[i]; - } } BUG_ON(1); @@ -147,7 +149,8 @@ static int bucket_list_choose(struct crush_bucket_list *bucket, /* tree */ -static int height(int n) { +static int height(int n) +{ int h = 0; while ((n & 1) == 0) { h++; @@ -156,17 +159,20 @@ static int height(int n) { return h; } -static int left(int x) { +static int left(int x) +{ int h = height(x); return x - (1 << (h-1)); } -static int right(int x) { +static int right(int x) +{ int h = height(x); return x + (1 << (h-1)); } -static int terminal(int x) { +static int terminal(int x) +{ return x & 1; } @@ -310,7 +316,8 @@ static int crush_choose(struct crush_map *map, r += ftotal; else if (in->size % numrep == 0) /* r'=r+(n+1)*f_local */ - r += (numrep+1) * (flocal+ftotal); + r += (numrep+1) * + (flocal+ftotal); else /* r' = r + n*f_local */ r += numrep * (flocal+ftotal); @@ -324,7 +331,8 @@ static int crush_choose(struct crush_map *map, } /* bucket choose */ - if (flocal >= (in->size>>1) && flocal > orig_tries) + if (flocal >= (in->size>>1) && + flocal > orig_tries) item = bucket_perm_choose(in, x, r); else item = crush_bucket_choose(in, x, r); @@ -356,7 +364,8 @@ static int crush_choose(struct crush_map *map, if (recurse_to_leaf && item < 0 && - crush_choose(map, map->buckets[-1-item], weight, + crush_choose(map, map->buckets[-1-item], + weight, x, outpos+1, 0, out2, outpos, firstn, 0, NULL) <= outpos) { @@ -364,7 +373,8 @@ static int crush_choose(struct crush_map *map, } else { /* out? */ if (itemtype == 0) - reject = is_out(map, weight, item, x); + reject = is_out(map, weight, + item, x); else reject = 0; } @@ -377,7 +387,7 @@ static int crush_choose(struct crush_map *map, /* retry locally a few times */ retry_bucket = 1; else if (flocal < in->size + orig_tries) - /* exhaustive search of bucket */ + /* exhaustive bucket search */ retry_bucket = 1; else if (ftotal < 20) /* then retry descent */ @@ -385,8 +395,10 @@ static int crush_choose(struct crush_map *map, else /* else give up */ skip_rep = 1; - dprintk(" reject %d collide %d ftotal %d flocal %d\n", reject, - collide, ftotal, flocal); + dprintk(" reject %d collide %d " + "ftotal %d flocal %d\n", + reject, collide, ftotal, + flocal); } } while (retry_bucket); } while (retry_descent); @@ -433,7 +445,7 @@ int crush_do_rule(struct crush_map *map, int *tmp; struct crush_rule *rule; int step; - int i,j; + int i, j; int numrep; int firstn; int rc = -1; @@ -473,7 +485,6 @@ int crush_do_rule(struct crush_map *map, if (!is_out(map, weight, force, x)) { while (1) { force_context[++force_pos] = force; - /*dprintk("force_context[%d] = %d\n", force_pos, force);*/ if (force >= 0) force = map->device_parents[force]; else @@ -503,9 +514,11 @@ int crush_do_rule(struct crush_map *map, case CRUSH_RULE_CHOOSE_INDEP: BUG_ON(wsize == 0); - recurse_to_leaf = - rule->steps[step].op == CRUSH_RULE_CHOOSE_LEAF_FIRSTN || - rule->steps[step].op == CRUSH_RULE_CHOOSE_LEAF_INDEP; + recurse_to_leaf = + rule->steps[step].op == + CRUSH_RULE_CHOOSE_LEAF_FIRSTN || + rule->steps[step].op == + CRUSH_RULE_CHOOSE_LEAF_INDEP; /* reset output */ osize = 0; @@ -528,7 +541,7 @@ int crush_do_rule(struct crush_map *map, while (force_pos && force_context[force_pos] < 0 && rule->steps[step].arg2 != - map->buckets[-1-force_context[force_pos]]->type) + map->buckets[-1 - force_context[force_pos]]->type) force_pos--; o[osize] = force_context[force_pos]; if (recurse_to_leaf) @@ -559,7 +572,7 @@ int crush_do_rule(struct crush_map *map, case CRUSH_RULE_EMIT: - for (i=0; i