summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKent Overstreet <kmo@daterainc.com>2015-02-04 13:57:03 -0800
committerKent Overstreet <kmo@daterainc.com>2015-02-12 23:43:53 -0800
commit85a4cfae5a09bead6d9c0d0ea183ad7964db63a5 (patch)
treeb4bd9dbb555daed208332ddf8f557443860a9b37
parentf7fe2154c28faa60cbcd0486bddf7f5026fae065 (diff)
bcache: Minor refactoring
Change-Id: I63a9609938432da27c51468736322f62047fb315
-rw-r--r--drivers/md/bcache/bset.c35
-rw-r--r--drivers/md/bcache/bset.h2
-rw-r--r--drivers/md/bcache/extents.c18
3 files changed, 24 insertions, 31 deletions
diff --git a/drivers/md/bcache/bset.c b/drivers/md/bcache/bset.c
index 1b206f9ab721..f55f034fe240 100644
--- a/drivers/md/bcache/bset.c
+++ b/drivers/md/bcache/bset.c
@@ -588,22 +588,6 @@ static void verify_insert_pos(struct btree_keys *b,
#endif
}
-static struct bkey *bch_btree_node_insert_pos(struct btree_keys *b,
- struct btree_node_iter *iter)
-{
- struct btree_node_iter_set *set;
-
- BUG_ON(iter->used > MAX_BSETS);
-
- for (set = iter->data;
- set < iter->data + iter->used;
- set++)
- if (set->k >= b->set[b->nsets].data->start)
- return set->k;
-
- return bset_bkey_last(bset_tree_last(b)->data);
-}
-
/**
* Used by extent fixup functions which insert entries into the bset.
* We have to update the iterator's cached ->end pointer.
@@ -745,7 +729,8 @@ void bch_bset_insert(struct btree_keys *b,
struct bset_tree *t = bset_tree_last(b);
struct bset *i = t->data;
struct bkey *prev = NULL;
- struct bkey *where = bch_btree_node_insert_pos(b, iter);
+ struct bkey *where = bch_btree_node_iter_bset_pos(iter, i) ?:
+ bset_bkey_last(i);
BKEY_PADDED(k) tmp;
BUG_ON(insert->u64s > bch_btree_keys_u64s_remaining(b));
@@ -1051,6 +1036,22 @@ void bch_btree_node_iter_init_from_start(struct btree_keys *b,
}
EXPORT_SYMBOL(bch_btree_node_iter_init_from_start);
+struct bkey *bch_btree_node_iter_bset_pos(struct btree_node_iter *iter,
+ struct bset *i)
+{
+ struct btree_node_iter_set *set;
+
+ BUG_ON(iter->used > MAX_BSETS);
+
+ for (set = iter->data;
+ set < iter->data + iter->used;
+ set++)
+ if (bset_bkey_last(i) == set->end)
+ return set->k;
+
+ return NULL;
+}
+
static inline void btree_node_iter_sift(struct btree_node_iter *iter, unsigned start)
{
unsigned i;
diff --git a/drivers/md/bcache/bset.h b/drivers/md/bcache/bset.h
index c14bc6aa5762..74112cb57959 100644
--- a/drivers/md/bcache/bset.h
+++ b/drivers/md/bcache/bset.h
@@ -380,6 +380,8 @@ void bch_btree_node_iter_init(struct btree_keys *, struct btree_node_iter *,
struct bpos);
void bch_btree_node_iter_init_from_start(struct btree_keys *,
struct btree_node_iter *);
+struct bkey *bch_btree_node_iter_bset_pos(struct btree_node_iter *,
+ struct bset *);
void bch_btree_node_iter_sort(struct btree_node_iter *);
void bch_btree_node_iter_advance(struct btree_node_iter *);
diff --git a/drivers/md/bcache/extents.c b/drivers/md/bcache/extents.c
index 56a922a64a57..ad8ea29a61ee 100644
--- a/drivers/md/bcache/extents.c
+++ b/drivers/md/bcache/extents.c
@@ -1579,7 +1579,6 @@ static bool bch_extent_merge_inline(struct btree_keys *b,
struct btree_node_iter *iter,
struct bkey *l, struct bkey *r)
{
- struct btree_node_iter_set *set;
struct bset_tree *t;
struct bkey *k, *m;
@@ -1610,22 +1609,13 @@ static bool bch_extent_merge_inline(struct btree_keys *b,
m < bset_bkey_last(t->data)))
continue;
- for (set = iter->data;
- set < iter->data + iter->used;
- set++)
- if (bset_bkey_last(t->data) == set->end) {
- k = set->k;
- goto found_pos;
- }
-
/*
- * if we didn't find this bset in the iterator, we already got
- * to the end of that bset, so start searching from the end of
- * the bset.
+ * if we don't find this bset in the iterator we already got to
+ * the end of that bset, so start searching from the end.
*/
+ k = bch_btree_node_iter_bset_pos(iter, t->data) ?:
+ bkey_prev(b, t, bset_bkey_last(t->data));
- k = bkey_prev(b, t, bset_bkey_last(t->data));
-found_pos:
if (m == l) {
/*
* Back merge: 0 size extents will be before the key