1 // SPDX-License-Identifier: GPL-2.0
3 # include <linux/slab.h>
4 # include <linux/crush/crush.h>
6 # include "crush_compat.h"
10 const char *crush_bucket_alg_name(int alg
)
13 case CRUSH_BUCKET_UNIFORM
: return "uniform";
14 case CRUSH_BUCKET_LIST
: return "list";
15 case CRUSH_BUCKET_TREE
: return "tree";
16 case CRUSH_BUCKET_STRAW
: return "straw";
17 case CRUSH_BUCKET_STRAW2
: return "straw2";
18 default: return "unknown";
23 * crush_get_bucket_item_weight - Get weight of an item in given bucket
25 * @p: item index in bucket
27 int crush_get_bucket_item_weight(const struct crush_bucket
*b
, int p
)
29 if ((__u32
)p
>= b
->size
)
33 case CRUSH_BUCKET_UNIFORM
:
34 return ((struct crush_bucket_uniform
*)b
)->item_weight
;
35 case CRUSH_BUCKET_LIST
:
36 return ((struct crush_bucket_list
*)b
)->item_weights
[p
];
37 case CRUSH_BUCKET_TREE
:
38 return ((struct crush_bucket_tree
*)b
)->node_weights
[crush_calc_tree_node(p
)];
39 case CRUSH_BUCKET_STRAW
:
40 return ((struct crush_bucket_straw
*)b
)->item_weights
[p
];
41 case CRUSH_BUCKET_STRAW2
:
42 return ((struct crush_bucket_straw2
*)b
)->item_weights
[p
];
47 void crush_destroy_bucket_uniform(struct crush_bucket_uniform
*b
)
53 void crush_destroy_bucket_list(struct crush_bucket_list
*b
)
55 kfree(b
->item_weights
);
56 kfree(b
->sum_weights
);
61 void crush_destroy_bucket_tree(struct crush_bucket_tree
*b
)
64 kfree(b
->node_weights
);
68 void crush_destroy_bucket_straw(struct crush_bucket_straw
*b
)
71 kfree(b
->item_weights
);
76 void crush_destroy_bucket_straw2(struct crush_bucket_straw2
*b
)
78 kfree(b
->item_weights
);
83 void crush_destroy_bucket(struct crush_bucket
*b
)
86 case CRUSH_BUCKET_UNIFORM
:
87 crush_destroy_bucket_uniform((struct crush_bucket_uniform
*)b
);
89 case CRUSH_BUCKET_LIST
:
90 crush_destroy_bucket_list((struct crush_bucket_list
*)b
);
92 case CRUSH_BUCKET_TREE
:
93 crush_destroy_bucket_tree((struct crush_bucket_tree
*)b
);
95 case CRUSH_BUCKET_STRAW
:
96 crush_destroy_bucket_straw((struct crush_bucket_straw
*)b
);
98 case CRUSH_BUCKET_STRAW2
:
99 crush_destroy_bucket_straw2((struct crush_bucket_straw2
*)b
);
105 * crush_destroy - Destroy a crush_map
106 * @map: crush_map pointer
108 void crush_destroy(struct crush_map
*map
)
113 for (b
= 0; b
< map
->max_buckets
; b
++) {
114 if (map
->buckets
[b
] == NULL
)
116 crush_destroy_bucket(map
->buckets
[b
]);
124 for (b
= 0; b
< map
->max_rules
; b
++)
125 crush_destroy_rule(map
->rules
[b
]);
130 kfree(map
->choose_tries
);
132 clear_crush_names(&map
->type_names
);
133 clear_crush_names(&map
->names
);
134 clear_choose_args(map
);
139 void crush_destroy_rule(struct crush_rule
*rule
)