aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/md/persistent-data/dm-btree.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/md/persistent-data/dm-btree.c')
-rw-r--r--drivers/md/persistent-data/dm-btree.c31
1 files changed, 18 insertions, 13 deletions
diff --git a/drivers/md/persistent-data/dm-btree.c b/drivers/md/persistent-data/dm-btree.c
index d12b2cc51f1a..4caf66918cdb 100644
--- a/drivers/md/persistent-data/dm-btree.c
+++ b/drivers/md/persistent-data/dm-btree.c
@@ -38,7 +38,7 @@ static void array_insert(void *base, size_t elt_size, unsigned nr_elts,
38/*----------------------------------------------------------------*/ 38/*----------------------------------------------------------------*/
39 39
40/* makes the assumption that no two keys are the same. */ 40/* makes the assumption that no two keys are the same. */
41static int bsearch(struct node *n, uint64_t key, int want_hi) 41static int bsearch(struct btree_node *n, uint64_t key, int want_hi)
42{ 42{
43 int lo = -1, hi = le32_to_cpu(n->header.nr_entries); 43 int lo = -1, hi = le32_to_cpu(n->header.nr_entries);
44 44
@@ -58,12 +58,12 @@ static int bsearch(struct node *n, uint64_t key, int want_hi)
58 return want_hi ? hi : lo; 58 return want_hi ? hi : lo;
59} 59}
60 60
61int lower_bound(struct node *n, uint64_t key) 61int lower_bound(struct btree_node *n, uint64_t key)
62{ 62{
63 return bsearch(n, key, 0); 63 return bsearch(n, key, 0);
64} 64}
65 65
66void inc_children(struct dm_transaction_manager *tm, struct node *n, 66void inc_children(struct dm_transaction_manager *tm, struct btree_node *n,
67 struct dm_btree_value_type *vt) 67 struct dm_btree_value_type *vt)
68{ 68{
69 unsigned i; 69 unsigned i;
@@ -77,7 +77,7 @@ void inc_children(struct dm_transaction_manager *tm, struct node *n,
77 vt->inc(vt->context, value_ptr(n, i)); 77 vt->inc(vt->context, value_ptr(n, i));
78} 78}
79 79
80static int insert_at(size_t value_size, struct node *node, unsigned index, 80static int insert_at(size_t value_size, struct btree_node *node, unsigned index,
81 uint64_t key, void *value) 81 uint64_t key, void *value)
82 __dm_written_to_disk(value) 82 __dm_written_to_disk(value)
83{ 83{
@@ -122,7 +122,7 @@ int dm_btree_empty(struct dm_btree_info *info, dm_block_t *root)
122{ 122{
123 int r; 123 int r;
124 struct dm_block *b; 124 struct dm_block *b;
125 struct node *n; 125 struct btree_node *n;
126 size_t block_size; 126 size_t block_size;
127 uint32_t max_entries; 127 uint32_t max_entries;
128 128
@@ -154,7 +154,7 @@ EXPORT_SYMBOL_GPL(dm_btree_empty);
154#define MAX_SPINE_DEPTH 64 154#define MAX_SPINE_DEPTH 64
155struct frame { 155struct frame {
156 struct dm_block *b; 156 struct dm_block *b;
157 struct node *n; 157 struct btree_node *n;
158 unsigned level; 158 unsigned level;
159 unsigned nr_children; 159 unsigned nr_children;
160 unsigned current_child; 160 unsigned current_child;
@@ -230,6 +230,11 @@ static void pop_frame(struct del_stack *s)
230 dm_tm_unlock(s->tm, f->b); 230 dm_tm_unlock(s->tm, f->b);
231} 231}
232 232
233static bool is_internal_level(struct dm_btree_info *info, struct frame *f)
234{
235 return f->level < (info->levels - 1);
236}
237
233int dm_btree_del(struct dm_btree_info *info, dm_block_t root) 238int dm_btree_del(struct dm_btree_info *info, dm_block_t root)
234{ 239{
235 int r; 240 int r;
@@ -241,7 +246,7 @@ int dm_btree_del(struct dm_btree_info *info, dm_block_t root)
241 s->tm = info->tm; 246 s->tm = info->tm;
242 s->top = -1; 247 s->top = -1;
243 248
244 r = push_frame(s, root, 1); 249 r = push_frame(s, root, 0);
245 if (r) 250 if (r)
246 goto out; 251 goto out;
247 252
@@ -267,7 +272,7 @@ int dm_btree_del(struct dm_btree_info *info, dm_block_t root)
267 if (r) 272 if (r)
268 goto out; 273 goto out;
269 274
270 } else if (f->level != (info->levels - 1)) { 275 } else if (is_internal_level(info, f)) {
271 b = value64(f->n, f->current_child); 276 b = value64(f->n, f->current_child);
272 f->current_child++; 277 f->current_child++;
273 r = push_frame(s, b, f->level + 1); 278 r = push_frame(s, b, f->level + 1);
@@ -295,7 +300,7 @@ EXPORT_SYMBOL_GPL(dm_btree_del);
295/*----------------------------------------------------------------*/ 300/*----------------------------------------------------------------*/
296 301
297static int btree_lookup_raw(struct ro_spine *s, dm_block_t block, uint64_t key, 302static int btree_lookup_raw(struct ro_spine *s, dm_block_t block, uint64_t key,
298 int (*search_fn)(struct node *, uint64_t), 303 int (*search_fn)(struct btree_node *, uint64_t),
299 uint64_t *result_key, void *v, size_t value_size) 304 uint64_t *result_key, void *v, size_t value_size)
300{ 305{
301 int i, r; 306 int i, r;
@@ -406,7 +411,7 @@ static int btree_split_sibling(struct shadow_spine *s, dm_block_t root,
406 size_t size; 411 size_t size;
407 unsigned nr_left, nr_right; 412 unsigned nr_left, nr_right;
408 struct dm_block *left, *right, *parent; 413 struct dm_block *left, *right, *parent;
409 struct node *ln, *rn, *pn; 414 struct btree_node *ln, *rn, *pn;
410 __le64 location; 415 __le64 location;
411 416
412 left = shadow_current(s); 417 left = shadow_current(s);
@@ -491,7 +496,7 @@ static int btree_split_beneath(struct shadow_spine *s, uint64_t key)
491 size_t size; 496 size_t size;
492 unsigned nr_left, nr_right; 497 unsigned nr_left, nr_right;
493 struct dm_block *left, *right, *new_parent; 498 struct dm_block *left, *right, *new_parent;
494 struct node *pn, *ln, *rn; 499 struct btree_node *pn, *ln, *rn;
495 __le64 val; 500 __le64 val;
496 501
497 new_parent = shadow_current(s); 502 new_parent = shadow_current(s);
@@ -576,7 +581,7 @@ static int btree_insert_raw(struct shadow_spine *s, dm_block_t root,
576 uint64_t key, unsigned *index) 581 uint64_t key, unsigned *index)
577{ 582{
578 int r, i = *index, top = 1; 583 int r, i = *index, top = 1;
579 struct node *node; 584 struct btree_node *node;
580 585
581 for (;;) { 586 for (;;) {
582 r = shadow_step(s, root, vt); 587 r = shadow_step(s, root, vt);
@@ -643,7 +648,7 @@ static int insert(struct dm_btree_info *info, dm_block_t root,
643 unsigned level, index = -1, last_level = info->levels - 1; 648 unsigned level, index = -1, last_level = info->levels - 1;
644 dm_block_t block = root; 649 dm_block_t block = root;
645 struct shadow_spine spine; 650 struct shadow_spine spine;
646 struct node *n; 651 struct btree_node *n;
647 struct dm_btree_value_type le64_type; 652 struct dm_btree_value_type le64_type;
648 653
649 le64_type.context = NULL; 654 le64_type.context = NULL;