Linux Kernel  3.7.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
crush.c
Go to the documentation of this file.
1 
2 #ifdef __KERNEL__
3 # include <linux/slab.h>
4 #else
5 # include <stdlib.h>
6 # include <assert.h>
7 # define kfree(x) do { if (x) free(x); } while (0)
8 # define BUG_ON(x) assert(!(x))
9 #endif
10 
11 #include <linux/crush/crush.h>
12 
13 const char *crush_bucket_alg_name(int alg)
14 {
15  switch (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";
21  }
22 }
23 
30 {
31  if ((__u32)p >= b->size)
32  return 0;
33 
34  switch (b->alg) {
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];
43  }
44  return 0;
45 }
46 
48 {
49  kfree(b->h.perm);
50  kfree(b->h.items);
51  kfree(b);
52 }
53 
55 {
56  kfree(b->item_weights);
57  kfree(b->sum_weights);
58  kfree(b->h.perm);
59  kfree(b->h.items);
60  kfree(b);
61 }
62 
64 {
65  kfree(b->h.perm);
66  kfree(b->h.items);
67  kfree(b->node_weights);
68  kfree(b);
69 }
70 
72 {
73  kfree(b->straws);
74  kfree(b->item_weights);
75  kfree(b->h.perm);
76  kfree(b->h.items);
77  kfree(b);
78 }
79 
81 {
82  switch (b->alg) {
85  break;
86  case CRUSH_BUCKET_LIST:
88  break;
89  case CRUSH_BUCKET_TREE:
91  break;
92  case CRUSH_BUCKET_STRAW:
94  break;
95  }
96 }
97 
103 {
104  /* buckets */
105  if (map->buckets) {
106  __s32 b;
107  for (b = 0; b < map->max_buckets; b++) {
108  if (map->buckets[b] == NULL)
109  continue;
110  crush_destroy_bucket(map->buckets[b]);
111  }
112  kfree(map->buckets);
113  }
114 
115  /* rules */
116  if (map->rules) {
117  __u32 b;
118  for (b = 0; b < map->max_rules; b++)
119  kfree(map->rules[b]);
120  kfree(map->rules);
121  }
122 
123  kfree(map);
124 }
125 
126