From d287ade5bcbdca82a3aef145b92924cf1e856733 Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Fri, 20 May 2011 16:40:36 -0700 Subject: [PATCH] crush: fix tree weight accessor, decompile Signed-off-by: Sage Weil --- src/crush/builder.c | 17 ++++++++--------- src/crush/crush.c | 4 +--- src/crush/crush.h | 5 +++++ src/crushtool.cc | 2 +- 4 files changed, 15 insertions(+), 13 deletions(-) diff --git a/src/crush/builder.c b/src/crush/builder.c index 8049291afbe9..9a6588a1bf7d 100644 --- a/src/crush/builder.c +++ b/src/crush/builder.c @@ -246,11 +246,6 @@ static int calc_depth(int size) return depth; } -static int calc_node(int i) -{ - return ((i+1) << 1)-1; -} - struct crush_bucket_tree* crush_make_tree_bucket(int hash, int type, int size, int *items, /* in leaf order */ @@ -274,6 +269,7 @@ crush_make_tree_bucket(int hash, int type, int size, /* calc tree depth */ depth = calc_depth(size); bucket->num_nodes = 1 << depth; + printf("size %d depth %d nodes %d\n", size, depth, bucket->num_nodes); bucket->node_weights = malloc(sizeof(__u32)*bucket->num_nodes); memset(bucket->h.items, 0, sizeof(__u32)*bucket->h.size); @@ -281,7 +277,7 @@ crush_make_tree_bucket(int hash, int type, int size, for (i=0; ih.items[i] = items[i]; - node = calc_node(i); + node = crush_calc_tree_node(i); printf("item %d node %d weight %d\n", i, node, weights[i]); bucket->node_weights[node] = weights[i]; bucket->h.weight += weights[i]; @@ -487,7 +483,7 @@ int crush_add_tree_bucket_item(struct crush_bucket_tree *bucket, int item, int w bucket->h.perm = realloc(bucket->h.perm, sizeof(__u32)*newsize); bucket->node_weights = realloc(bucket->node_weights, sizeof(__u32)*bucket->num_nodes); - node = calc_node(newsize-1); + node = crush_calc_tree_node(newsize-1); bucket->node_weights[node] = weight; for (j=1; jperm_n = 0; + switch (b->alg) { case CRUSH_BUCKET_UNIFORM: return crush_add_uniform_bucket_item((struct crush_bucket_uniform *)b, item, weight); @@ -584,7 +583,7 @@ int crush_adjust_tree_bucket_item_weight(struct crush_bucket_tree *bucket, int i if (i == bucket->h.size) return 0; - node = calc_node(i); + node = crush_calc_tree_node(i); diff = weight = bucket->node_weights[node]; bucket->node_weights[node] = weight; bucket->h.weight += diff; @@ -687,7 +686,7 @@ int crush_reweight_tree_bucket(struct crush_map *crush, struct crush_bucket_tree bucket->h.weight = 0; for (i = 0; i < bucket->h.size; i++) { - int node = calc_node(i); + int node = crush_calc_tree_node(i); int id = bucket->h.items[i]; if (id < 0) { struct crush_bucket *c = crush->buckets[-1-id]; diff --git a/src/crush/crush.c b/src/crush/crush.c index 040cbbd63606..0790b80facca 100644 --- a/src/crush/crush.c +++ b/src/crush/crush.c @@ -37,9 +37,7 @@ int crush_get_bucket_item_weight(const struct crush_bucket *b, int p) case CRUSH_BUCKET_LIST: 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 0; + return ((struct crush_bucket_tree *)b)->node_weights[crush_calc_tree_node(p)]; case CRUSH_BUCKET_STRAW: return ((struct crush_bucket_straw *)b)->item_weights[p]; } diff --git a/src/crush/crush.h b/src/crush/crush.h index eabd059dc850..14e5f4e369a1 100644 --- a/src/crush/crush.h +++ b/src/crush/crush.h @@ -176,4 +176,9 @@ extern void crush_destroy_bucket_straw(struct crush_bucket_straw *b); extern void crush_destroy_bucket(struct crush_bucket *b); extern void crush_destroy(struct crush_map *map); +static inline int crush_calc_tree_node(int i) +{ + return ((i+1) << 1)-1; +} + #endif diff --git a/src/crushtool.cc b/src/crushtool.cc index d23067f94a58..bae229e7e89b 100644 --- a/src/crushtool.cc +++ b/src/crushtool.cc @@ -572,7 +572,7 @@ static int decompile_crush_bucket_impl(int i, print_fixedpoint(out, w); if (dopos) { if (alg == CRUSH_BUCKET_TREE) - out << " pos " << (j-1)/2; + out << " pos " << j; else out << " pos " << j; } -- 2.47.3