summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKent Overstreet <kent.overstreet@gmail.com>2016-07-13 00:50:46 -0800
committerKent Overstreet <kent.overstreet@gmail.com>2016-07-26 00:25:00 -0800
commite5b6127f3d8c6810495b1399d5ef5e1e52991a16 (patch)
tree2cdf90a1cb282c1a44a7a665430e933cf03e54fd
parentede8d0d3ce6bb0dbd06b62d0bc3c87d119a3f6ea (diff)
bcache: bch_bkey_to_bset
-rw-r--r--drivers/md/bcache/bset.c78
-rw-r--r--drivers/md/bcache/bset.h1
-rw-r--r--drivers/md/bcache/extents.c3
3 files changed, 45 insertions, 37 deletions
diff --git a/drivers/md/bcache/bset.c b/drivers/md/bcache/bset.c
index d09155a4ccd2..44a8f23ac448 100644
--- a/drivers/md/bcache/bset.c
+++ b/drivers/md/bcache/bset.c
@@ -20,6 +20,18 @@
#include "alloc_types.h"
#include <trace/events/bcache.h>
+struct bset_tree *bch_bkey_to_bset(struct btree_keys *b, struct bkey_packed *k)
+{
+ struct bset_tree *t;
+
+ for (t = b->set; t <= b->set + b->nsets; t++)
+ if (k >= t->data->start &&
+ k < bset_bkey_last(t->data))
+ return t;
+
+ BUG();
+}
+
/*
* There are never duplicate live keys in the btree - but including keys that
* have been flagged as deleted (and will be cleaned up later) we _will_ see
@@ -151,6 +163,34 @@ static void bch_btree_node_iter_next_check(struct btree_node_iter *iter,
}
}
+static inline bool btree_node_iter_cmp(struct btree_node_iter *,
+ struct btree_keys *,
+ struct btree_node_iter_set,
+ struct btree_node_iter_set);
+
+void bch_btree_node_iter_verify(struct btree_node_iter *iter,
+ struct btree_keys *b)
+{
+ struct btree_node_iter_set *set;
+ struct bset_tree *t;
+ struct bkey_packed *k;
+
+ BUG_ON(iter->used > MAX_BSETS);
+
+ for (set = iter->data;
+ set < iter->data + iter->used;
+ set++) {
+ BUG_ON(set + 1 < iter->data + iter->used &&
+ btree_node_iter_cmp(iter, b, set[0], set[1]));
+
+ k = __btree_node_offset_to_key(b, set->k);
+ t = bch_bkey_to_bset(b, k);
+
+ BUG_ON(__btree_node_offset_to_key(b, set->end) !=
+ bset_bkey_last(t->data));
+ }
+}
+
#else
static void bch_btree_node_iter_next_check(struct btree_node_iter *iter,
@@ -721,6 +761,8 @@ struct bkey_packed *bkey_prev(struct bset_tree *t, struct bkey_packed *k)
struct bkey_packed *p;
int j;
+ EBUG_ON(k < t->data->start || k > bset_bkey_last(t->data));
+
if (k == t->data->start)
return NULL;
@@ -772,15 +814,9 @@ static void verify_insert_pos(struct btree_keys *b,
*/
void bch_bset_fix_invalidated_key(struct btree_keys *b, struct bkey_packed *k)
{
- struct bset_tree *t;
+ struct bset_tree *t = bch_bkey_to_bset(b, k);
unsigned inorder, j = 1;
- for (t = b->set; t <= bset_tree_last(b); t++)
- if (k < bset_bkey_last(t->data))
- goto found_set;
-
- BUG();
-found_set:
if (!bset_written(t))
return;
@@ -1431,34 +1467,6 @@ void bch_btree_node_iter_advance(struct btree_node_iter *iter,
bch_btree_node_iter_next_check(iter, b, k);
}
-#ifdef CONFIG_BCACHE_DEBUG
-void bch_btree_node_iter_verify(struct btree_node_iter *iter,
- struct btree_keys *b)
-{
- struct btree_node_iter_set *set;
- struct bset_tree *t;
-
- BUG_ON(iter->used > MAX_BSETS);
-
- for (set = iter->data;
- set < iter->data + iter->used;
- set++) {
- BUG_ON(set + 1 < iter->data + iter->used &&
- btree_node_iter_cmp(iter, b, set[0], set[1]));
-
- for (t = b->set;
- t <= b->set + b->nsets;
- t++)
- if (__btree_node_offset_to_key(b, set->end) ==
- bset_bkey_last(t->data))
- goto next;
- BUG();
-next:
- ;
- }
-}
-#endif
-
/*
* Expensive:
*/
diff --git a/drivers/md/bcache/bset.h b/drivers/md/bcache/bset.h
index 5785270f4674..f34eb5d63ab7 100644
--- a/drivers/md/bcache/bset.h
+++ b/drivers/md/bcache/bset.h
@@ -365,6 +365,7 @@ static inline struct bkey_packed *bset_bkey_idx(struct bset *i, unsigned idx)
return bkey_idx(i, idx);
}
+struct bset_tree *bch_bkey_to_bset(struct btree_keys *, struct bkey_packed *);
struct bkey_packed *bkey_prev(struct bset_tree *, struct bkey_packed *);
/*
diff --git a/drivers/md/bcache/extents.c b/drivers/md/bcache/extents.c
index cb23a8e865b7..41b1eb508f09 100644
--- a/drivers/md/bcache/extents.c
+++ b/drivers/md/bcache/extents.c
@@ -2020,8 +2020,7 @@ static bool bch_extent_merge_inline(struct btree_keys *b,
mi = back_merge ? &li.k : &ri.k;
/* l & r should be in last bset: */
- BUG_ON(m < bset_tree_last(b)->data->start ||
- m >= bset_bkey_last(bset_tree_last(b)->data));
+ EBUG_ON(bch_bkey_to_bset(b, m) != bset_tree_last(b));
switch (bch_extent_merge(b, &li.k, &ri.k)) {
case BCH_MERGE_NOMERGE: