~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/net/ceph/crush/crush.c

Version: ~ [ linux-6.11.5 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.58 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.114 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.169 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.228 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.284 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.322 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.9 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 // SPDX-License-Identifier: GPL-2.0
  2 #ifdef __KERNEL__
  3 # include <linux/slab.h>
  4 # include <linux/crush/crush.h>
  5 #else
  6 # include "crush_compat.h"
  7 # include "crush.h"
  8 #endif
  9 
 10 const char *crush_bucket_alg_name(int alg)
 11 {
 12         switch (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";
 19         }
 20 }
 21 
 22 /**
 23  * crush_get_bucket_item_weight - Get weight of an item in given bucket
 24  * @b: bucket pointer
 25  * @p: item index in bucket
 26  */
 27 int crush_get_bucket_item_weight(const struct crush_bucket *b, int p)
 28 {
 29         if ((__u32)p >= b->size)
 30                 return 0;
 31 
 32         switch (b->alg) {
 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];
 43         }
 44         return 0;
 45 }
 46 
 47 void crush_destroy_bucket_uniform(struct crush_bucket_uniform *b)
 48 {
 49         kfree(b->h.items);
 50         kfree(b);
 51 }
 52 
 53 void crush_destroy_bucket_list(struct crush_bucket_list *b)
 54 {
 55         kfree(b->item_weights);
 56         kfree(b->sum_weights);
 57         kfree(b->h.items);
 58         kfree(b);
 59 }
 60 
 61 void crush_destroy_bucket_tree(struct crush_bucket_tree *b)
 62 {
 63         kfree(b->h.items);
 64         kfree(b->node_weights);
 65         kfree(b);
 66 }
 67 
 68 void crush_destroy_bucket_straw(struct crush_bucket_straw *b)
 69 {
 70         kfree(b->straws);
 71         kfree(b->item_weights);
 72         kfree(b->h.items);
 73         kfree(b);
 74 }
 75 
 76 void crush_destroy_bucket_straw2(struct crush_bucket_straw2 *b)
 77 {
 78         kfree(b->item_weights);
 79         kfree(b->h.items);
 80         kfree(b);
 81 }
 82 
 83 void crush_destroy_bucket(struct crush_bucket *b)
 84 {
 85         switch (b->alg) {
 86         case CRUSH_BUCKET_UNIFORM:
 87                 crush_destroy_bucket_uniform((struct crush_bucket_uniform *)b);
 88                 break;
 89         case CRUSH_BUCKET_LIST:
 90                 crush_destroy_bucket_list((struct crush_bucket_list *)b);
 91                 break;
 92         case CRUSH_BUCKET_TREE:
 93                 crush_destroy_bucket_tree((struct crush_bucket_tree *)b);
 94                 break;
 95         case CRUSH_BUCKET_STRAW:
 96                 crush_destroy_bucket_straw((struct crush_bucket_straw *)b);
 97                 break;
 98         case CRUSH_BUCKET_STRAW2:
 99                 crush_destroy_bucket_straw2((struct crush_bucket_straw2 *)b);
100                 break;
101         }
102 }
103 
104 /**
105  * crush_destroy - Destroy a crush_map
106  * @map: crush_map pointer
107  */
108 void crush_destroy(struct crush_map *map)
109 {
110         /* buckets */
111         if (map->buckets) {
112                 __s32 b;
113                 for (b = 0; b < map->max_buckets; b++) {
114                         if (map->buckets[b] == NULL)
115                                 continue;
116                         crush_destroy_bucket(map->buckets[b]);
117                 }
118                 kfree(map->buckets);
119         }
120 
121         /* rules */
122         if (map->rules) {
123                 __u32 b;
124                 for (b = 0; b < map->max_rules; b++)
125                         crush_destroy_rule(map->rules[b]);
126                 kfree(map->rules);
127         }
128 
129 #ifndef __KERNEL__
130         kfree(map->choose_tries);
131 #else
132         clear_crush_names(&map->type_names);
133         clear_crush_names(&map->names);
134         clear_choose_args(map);
135 #endif
136         kfree(map);
137 }
138 
139 void crush_destroy_rule(struct crush_rule *rule)
140 {
141         kfree(rule);
142 }
143 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php