2 # include <linux/slab.h>
3 # include <linux/crush/crush.h>
5 # include "crush_compat.h"
9 const char *crush_bucket_alg_name(int alg
)
12 case CRUSH_BUCKET_UNIFORM
: return "uniform";
13 case CRUSH_BUCKET_LIST
: return "list";
14 case CRUSH_BUCKET_TREE
: return "tree";
15 case CRUSH_BUCKET_STRAW
: return "straw";
16 case CRUSH_BUCKET_STRAW2
: return "straw2";
17 default: return "unknown";
22 * crush_get_bucket_item_weight - Get weight of an item in given bucket
24 * @p: item index in bucket
26 int crush_get_bucket_item_weight(const struct crush_bucket
*b
, int p
)
28 if ((__u32
)p
>= b
->size
)
32 case CRUSH_BUCKET_UNIFORM
:
33 return ((struct crush_bucket_uniform
*)b
)->item_weight
;
34 case CRUSH_BUCKET_LIST
:
35 return ((struct crush_bucket_list
*)b
)->item_weights
[p
];
36 case CRUSH_BUCKET_TREE
:
37 return ((struct crush_bucket_tree
*)b
)->node_weights
[crush_calc_tree_node(p
)];
38 case CRUSH_BUCKET_STRAW
:
39 return ((struct crush_bucket_straw
*)b
)->item_weights
[p
];
40 case CRUSH_BUCKET_STRAW2
:
41 return ((struct crush_bucket_straw2
*)b
)->item_weights
[p
];
46 void crush_destroy_bucket_uniform(struct crush_bucket_uniform
*b
)
52 void crush_destroy_bucket_list(struct crush_bucket_list
*b
)
54 kfree(b
->item_weights
);
55 kfree(b
->sum_weights
);
60 void crush_destroy_bucket_tree(struct crush_bucket_tree
*b
)
63 kfree(b
->node_weights
);
67 void crush_destroy_bucket_straw(struct crush_bucket_straw
*b
)
70 kfree(b
->item_weights
);
75 void crush_destroy_bucket_straw2(struct crush_bucket_straw2
*b
)
77 kfree(b
->item_weights
);
82 void crush_destroy_bucket(struct crush_bucket
*b
)
85 case CRUSH_BUCKET_UNIFORM
:
86 crush_destroy_bucket_uniform((struct crush_bucket_uniform
*)b
);
88 case CRUSH_BUCKET_LIST
:
89 crush_destroy_bucket_list((struct crush_bucket_list
*)b
);
91 case CRUSH_BUCKET_TREE
:
92 crush_destroy_bucket_tree((struct crush_bucket_tree
*)b
);
94 case CRUSH_BUCKET_STRAW
:
95 crush_destroy_bucket_straw((struct crush_bucket_straw
*)b
);
97 case CRUSH_BUCKET_STRAW2
:
98 crush_destroy_bucket_straw2((struct crush_bucket_straw2
*)b
);
104 * crush_destroy - Destroy a crush_map
105 * @map: crush_map pointer
107 void crush_destroy(struct crush_map
*map
)
112 for (b
= 0; b
< map
->max_buckets
; b
++) {
113 if (map
->buckets
[b
] == NULL
)
115 crush_destroy_bucket(map
->buckets
[b
]);
123 for (b
= 0; b
< map
->max_rules
; b
++)
124 crush_destroy_rule(map
->rules
[b
]);
129 kfree(map
->choose_tries
);
134 void crush_destroy_rule(struct crush_rule
*rule
)