1 // SPDX-License-Identifier: GPL-2.0
3 # include <linux/slab.h>
4 # include <linux/crush/crush.h>
5 void clear_choose_args(struct crush_map
*c
);
7 # include "crush_compat.h"
11 const char *crush_bucket_alg_name(int alg
)
14 case CRUSH_BUCKET_UNIFORM
: return "uniform";
15 case CRUSH_BUCKET_LIST
: return "list";
16 case CRUSH_BUCKET_TREE
: return "tree";
17 case CRUSH_BUCKET_STRAW
: return "straw";
18 case CRUSH_BUCKET_STRAW2
: return "straw2";
19 default: return "unknown";
24 * crush_get_bucket_item_weight - Get weight of an item in given bucket
26 * @p: item index in bucket
28 int crush_get_bucket_item_weight(const struct crush_bucket
*b
, int p
)
30 if ((__u32
)p
>= b
->size
)
34 case CRUSH_BUCKET_UNIFORM
:
35 return ((struct crush_bucket_uniform
*)b
)->item_weight
;
36 case CRUSH_BUCKET_LIST
:
37 return ((struct crush_bucket_list
*)b
)->item_weights
[p
];
38 case CRUSH_BUCKET_TREE
:
39 return ((struct crush_bucket_tree
*)b
)->node_weights
[crush_calc_tree_node(p
)];
40 case CRUSH_BUCKET_STRAW
:
41 return ((struct crush_bucket_straw
*)b
)->item_weights
[p
];
42 case CRUSH_BUCKET_STRAW2
:
43 return ((struct crush_bucket_straw2
*)b
)->item_weights
[p
];
48 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
);
62 void crush_destroy_bucket_tree(struct crush_bucket_tree
*b
)
65 kfree(b
->node_weights
);
69 void crush_destroy_bucket_straw(struct crush_bucket_straw
*b
)
72 kfree(b
->item_weights
);
77 void crush_destroy_bucket_straw2(struct crush_bucket_straw2
*b
)
79 kfree(b
->item_weights
);
84 void crush_destroy_bucket(struct crush_bucket
*b
)
87 case CRUSH_BUCKET_UNIFORM
:
88 crush_destroy_bucket_uniform((struct crush_bucket_uniform
*)b
);
90 case CRUSH_BUCKET_LIST
:
91 crush_destroy_bucket_list((struct crush_bucket_list
*)b
);
93 case CRUSH_BUCKET_TREE
:
94 crush_destroy_bucket_tree((struct crush_bucket_tree
*)b
);
96 case CRUSH_BUCKET_STRAW
:
97 crush_destroy_bucket_straw((struct crush_bucket_straw
*)b
);
99 case CRUSH_BUCKET_STRAW2
:
100 crush_destroy_bucket_straw2((struct crush_bucket_straw2
*)b
);
106 * crush_destroy - Destroy a crush_map
107 * @map: crush_map pointer
109 void crush_destroy(struct crush_map
*map
)
114 for (b
= 0; b
< map
->max_buckets
; b
++) {
115 if (map
->buckets
[b
] == NULL
)
117 crush_destroy_bucket(map
->buckets
[b
]);
125 for (b
= 0; b
< map
->max_rules
; b
++)
126 crush_destroy_rule(map
->rules
[b
]);
131 kfree(map
->choose_tries
);
133 clear_choose_args(map
);
138 void crush_destroy_rule(struct crush_rule
*rule
)