3 # include <linux/slab.h>
7 # define kfree(x) do { if (x) free(x); } while (0)
8 # define BUG_ON(x) assert(!(x))
11 #include <linux/crush/crush.h>
13 const char *crush_bucket_alg_name(int alg
)
16 case CRUSH_BUCKET_UNIFORM
: return "uniform";
17 case CRUSH_BUCKET_LIST
: return "list";
18 case CRUSH_BUCKET_TREE
: return "tree";
19 case CRUSH_BUCKET_STRAW
: return "straw";
20 default: return "unknown";
25 * crush_get_bucket_item_weight - Get weight of an item in given bucket
27 * @p: item index in bucket
29 int crush_get_bucket_item_weight(const struct crush_bucket
*b
, int p
)
31 if ((__u32
)p
>= b
->size
)
35 case CRUSH_BUCKET_UNIFORM
:
36 return ((struct crush_bucket_uniform
*)b
)->item_weight
;
37 case CRUSH_BUCKET_LIST
:
38 return ((struct crush_bucket_list
*)b
)->item_weights
[p
];
39 case CRUSH_BUCKET_TREE
:
40 return ((struct crush_bucket_tree
*)b
)->node_weights
[crush_calc_tree_node(p
)];
41 case CRUSH_BUCKET_STRAW
:
42 return ((struct crush_bucket_straw
*)b
)->item_weights
[p
];
47 void crush_destroy_bucket_uniform(struct crush_bucket_uniform
*b
)
54 void crush_destroy_bucket_list(struct crush_bucket_list
*b
)
56 kfree(b
->item_weights
);
57 kfree(b
->sum_weights
);
63 void crush_destroy_bucket_tree(struct crush_bucket_tree
*b
)
67 kfree(b
->node_weights
);
71 void crush_destroy_bucket_straw(struct crush_bucket_straw
*b
)
74 kfree(b
->item_weights
);
80 void crush_destroy_bucket(struct crush_bucket
*b
)
83 case CRUSH_BUCKET_UNIFORM
:
84 crush_destroy_bucket_uniform((struct crush_bucket_uniform
*)b
);
86 case CRUSH_BUCKET_LIST
:
87 crush_destroy_bucket_list((struct crush_bucket_list
*)b
);
89 case CRUSH_BUCKET_TREE
:
90 crush_destroy_bucket_tree((struct crush_bucket_tree
*)b
);
92 case CRUSH_BUCKET_STRAW
:
93 crush_destroy_bucket_straw((struct crush_bucket_straw
*)b
);
99 * crush_destroy - Destroy a crush_map
100 * @map: crush_map pointer
102 void crush_destroy(struct crush_map
*map
)
107 for (b
= 0; b
< map
->max_buckets
; b
++) {
108 if (map
->buckets
[b
] == NULL
)
110 crush_destroy_bucket(map
->buckets
[b
]);
118 for (b
= 0; b
< map
->max_rules
; b
++)
119 crush_destroy_rule(map
->rules
[b
]);
126 void crush_destroy_rule(struct crush_rule
*rule
)