return (struct bset_search_iter) {l, r};
}
-struct bkey *__bch_bset_search(struct btree *b, struct bset_tree *t,
+struct bkey *__bch_bset_search(struct btree_keys *b, struct bset_tree *t,
const struct bkey *search)
{
struct bset_search_iter i;
if (unlikely(!t->size)) {
i.l = t->data->start;
i.r = bset_bkey_last(t->data);
- } else if (bset_written(&b->keys, t)) {
+ } else if (bset_written(b, t)) {
/*
* Each node in the auxiliary search tree covers a certain range
* of bits, and keys above and below the set it covers might
i = bset_search_tree(t, search);
} else {
- BUG_ON(!b->keys.nsets &&
+ BUG_ON(!b->nsets &&
t->size < bkey_to_cacheline(t, bset_bkey_last(t->data)));
i = bset_search_write_set(t, search);
}
- if (expensive_debug_checks(b->c)) {
- BUG_ON(bset_written(&b->keys, t) &&
+ if (btree_keys_expensive_checks(b)) {
+ BUG_ON(bset_written(b, t) &&
i.l != t->data->start &&
bkey_cmp(tree_to_prev_bkey(t,
inorder_to_tree(bkey_to_cacheline(t, i.l), t)),
btree_iter_cmp));
}
-static struct bkey *__bch_btree_iter_init(struct btree *b,
+static struct bkey *__bch_btree_iter_init(struct btree_keys *b,
struct btree_iter *iter,
struct bkey *search,
struct bset_tree *start)
iter->b = b;
#endif
- for (; start <= bset_tree_last(&b->keys); start++) {
+ for (; start <= bset_tree_last(b); start++) {
ret = bch_bset_search(b, start, search);
bch_btree_iter_push(iter, ret, bset_bkey_last(start->data));
}
return ret;
}
-struct bkey *bch_btree_iter_init(struct btree *b,
+struct bkey *bch_btree_iter_init(struct btree_keys *b,
struct btree_iter *iter,
struct bkey *search)
{
- return __bch_btree_iter_init(b, iter, search, b->keys.set);
+ return __bch_btree_iter_init(b, iter, search, b->set);
}
EXPORT_SYMBOL(bch_btree_iter_init);
struct btree_iter iter;
int oldsize = bch_count_data(b);
- __bch_btree_iter_init(b, &iter, NULL, &b->keys.set[start]);
+ __bch_btree_iter_init(&b->keys, &iter, NULL, &b->keys.set[start]);
if (start) {
unsigned i;
uint64_t start_time = local_clock();
struct btree_iter iter;
- bch_btree_iter_init(b, &iter, NULL);
+ bch_btree_iter_init(&b->keys, &iter, NULL);
btree_mergesort(&b->keys, new->keys.set->data, &iter, false, true);
struct btree_iter {
size_t size, used;
#ifdef CONFIG_BCACHE_DEBUG
- struct btree *b;
+ struct btree_keys *b;
#endif
struct btree_iter_set {
struct bkey *k, *end;
struct btree_keys *, ptr_filter_fn);
void bch_btree_iter_push(struct btree_iter *, struct bkey *, struct bkey *);
-struct bkey *bch_btree_iter_init(struct btree *, struct btree_iter *,
+struct bkey *bch_btree_iter_init(struct btree_keys *, struct btree_iter *,
struct bkey *);
-struct bkey *__bch_bset_search(struct btree *, struct bset_tree *,
- const struct bkey *);
+struct bkey *__bch_bset_search(struct btree_keys *, struct bset_tree *,
+ const struct bkey *);
/*
* Returns the first key that is strictly greater than search
*/
-static inline struct bkey *bch_bset_search(struct btree *b, struct bset_tree *t,
+static inline struct bkey *bch_bset_search(struct btree_keys *b,
+ struct bset_tree *t,
const struct bkey *search)
{
return search ? __bch_bset_search(b, t, search) : t->data->start;
}
+#define for_each_key_filter(b, k, iter, filter) \
+ for (bch_btree_iter_init((b), (iter), NULL); \
+ ((k) = bch_btree_iter_next_filter((iter), (b), filter));)
+
+#define for_each_key(b, k, iter) \
+ for (bch_btree_iter_init((b), (iter), NULL); \
+ ((k) = bch_btree_iter_next(iter));)
+
/* Sorting */
struct bset_sort_state {
iter->used = 0;
#ifdef CONFIG_BCACHE_DEBUG
- iter->b = b;
+ iter->b = &b->keys;
#endif
if (!i->seq)
gc->nodes++;
- for_each_key_filter(b, k, &iter, bch_ptr_invalid) {
+ for_each_key_filter(&b->keys, k, &iter, bch_ptr_invalid) {
stale = max(stale, btree_mark_key(b, k));
keys++;
struct btree_iter iter;
unsigned ret = 0;
- for_each_key_filter(b, k, &iter, bch_ptr_bad)
+ for_each_key_filter(&b->keys, k, &iter, bch_ptr_bad)
ret += bkey_u64s(k);
return ret;
struct gc_merge_info *last = r + GC_MERGE_NODES - 1;
bch_keylist_init(&keys);
- bch_btree_iter_init(b, &iter, &b->c->gc_done);
+ bch_btree_iter_init(&b->keys, &iter, &b->c->gc_done);
for (i = 0; i < GC_MERGE_NODES; i++)
r[i].b = ERR_PTR(-EINTR);
struct bucket *g;
struct btree_iter iter;
- for_each_key_filter(b, k, &iter, bch_ptr_invalid) {
+ for_each_key_filter(&b->keys, k, &iter, bch_ptr_invalid) {
for (i = 0; i < KEY_PTRS(k); i++) {
if (!ptr_available(b->c, k, i))
continue;
}
if (b->level) {
- bch_btree_iter_init(b, &iter, NULL);
+ bch_btree_iter_init(&b->keys, &iter, NULL);
do {
k = bch_btree_iter_next_filter(&iter, &b->keys,
* depends on us inserting a new key for the top
* here.
*/
- top = bch_bset_search(b,
+ top = bch_bset_search(&b->keys,
bset_tree_last(&b->keys),
insert);
bch_bset_insert(&b->keys, top, k);
* the previous key.
*/
prev = NULL;
- m = bch_btree_iter_init(b, &iter,
+ m = bch_btree_iter_init(&b->keys, &iter,
PRECEDING_KEY(&START_KEY(k)));
if (fix_overlapping_extents(b, k, &iter, replace_key)) {
goto copy;
} else {
BUG_ON(replace_key);
- m = bch_bset_search(b, bset_tree_last(&b->keys), k);
+ m = bch_bset_search(&b->keys, bset_tree_last(&b->keys), k);
}
insert: bch_bset_insert(&b->keys, m, k);
struct bkey *k;
struct btree_iter iter;
- bch_btree_iter_init(b, &iter, from);
+ bch_btree_iter_init(&b->keys, &iter, from);
while ((k = bch_btree_iter_next_filter(&iter, &b->keys,
bch_ptr_bad))) {
struct bkey *k;
struct btree_iter iter;
- bch_btree_iter_init(b, &iter, from);
+ bch_btree_iter_init(&b->keys, &iter, from);
while ((k = bch_btree_iter_next_filter(&iter, &b->keys, bch_ptr_bad))) {
ret = !b->level
iter++) \
hlist_for_each_entry_rcu((b), (c)->bucket_hash + iter, hash)
-#define for_each_key_filter(b, k, iter, filter) \
- for (bch_btree_iter_init((b), (iter), NULL); \
- ((k) = bch_btree_iter_next_filter((iter), &(b)->keys, filter));)
-
-#define for_each_key(b, k, iter) \
- for (bch_btree_iter_init((b), (iter), NULL); \
- ((k) = bch_btree_iter_next(iter));)
-
/* Recursing down the btree */
struct btree_op {
struct bkey *k;
if (!b->level)
- for_each_key(b, k, &iter)
+ for_each_key(&b->keys, k, &iter)
ret += KEY_SIZE(k);
return ret;
}
struct btree_iter iter;
const char *err;
- for_each_key(b, k, &iter) {
+ for_each_key(&b->keys, k, &iter) {
if (!b->level) {
err = "Keys out of order";
if (p && bkey_cmp(&START_KEY(p), &START_KEY(k)) > 0)
void bch_btree_iter_next_check(struct btree_iter *iter)
{
+#if 0
struct bkey *k = iter->data->k, *next = bkey_next(k);
if (next < iter->data->end &&
bch_dump_bucket(iter->b);
panic("Key skipped backwards\n");
}
+#endif
}
#endif
rw_lock(false, b, b->level);
} while (b != c->root);
- for_each_key_filter(b, k, &iter, bch_ptr_bad)
+ for_each_key_filter(&b->keys, k, &iter, bch_ptr_bad)
bytes += bkey_bytes(k);
rw_unlock(false, b);