Commit 0eacac22 authored by Kent Overstreet's avatar Kent Overstreet

bcache: PRECEDING_KEY()

btree_insert_key() was open coding this, this is just refactoring.
Signed-off-by: default avatarKent Overstreet <kmo@daterainc.com>
parent d5cc66e9
...@@ -353,12 +353,30 @@ void bch_bset_fix_lookup_table(struct btree *, struct bkey *); ...@@ -353,12 +353,30 @@ void bch_bset_fix_lookup_table(struct btree *, struct bkey *);
struct bkey *__bch_bset_search(struct btree *, struct bset_tree *, struct bkey *__bch_bset_search(struct btree *, struct bset_tree *,
const struct bkey *); 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 *b, struct bset_tree *t,
const struct bkey *search) const struct bkey *search)
{ {
return search ? __bch_bset_search(b, t, search) : t->data->start; return search ? __bch_bset_search(b, t, search) : t->data->start;
} }
#define PRECEDING_KEY(_k) \
({ \
struct bkey *_ret = NULL; \
\
if (KEY_INODE(_k) || KEY_OFFSET(_k)) { \
_ret = &KEY(KEY_INODE(_k), KEY_OFFSET(_k), 0); \
\
if (!_ret->low) \
_ret->high--; \
_ret->low--; \
} \
\
_ret; \
})
bool bch_bkey_try_merge(struct btree *, struct bkey *, struct bkey *); bool bch_bkey_try_merge(struct btree *, struct bkey *, struct bkey *);
void bch_btree_sort_lazy(struct btree *); void bch_btree_sort_lazy(struct btree *);
void bch_btree_sort_into(struct btree *, struct btree *); void bch_btree_sort_into(struct btree *, struct btree *);
......
...@@ -1844,19 +1844,14 @@ static bool btree_insert_key(struct btree *b, struct btree_op *op, ...@@ -1844,19 +1844,14 @@ static bool btree_insert_key(struct btree *b, struct btree_op *op,
if (!b->level) { if (!b->level) {
struct btree_iter iter; struct btree_iter iter;
struct bkey search = KEY(KEY_INODE(k), KEY_START(k), 0);
/* /*
* bset_search() returns the first key that is strictly greater * bset_search() returns the first key that is strictly greater
* than the search key - but for back merging, we want to find * than the search key - but for back merging, we want to find
* the first key that is greater than or equal to KEY_START(k) - * the previous key.
* unless KEY_START(k) is 0.
*/ */
if (KEY_OFFSET(&search))
SET_KEY_OFFSET(&search, KEY_OFFSET(&search) - 1);
prev = NULL; prev = NULL;
m = bch_btree_iter_init(b, &iter, &search); m = bch_btree_iter_init(b, &iter, PRECEDING_KEY(&START_KEY(k)));
if (fix_overlapping_extents(b, k, &iter, replace_key)) { if (fix_overlapping_extents(b, k, &iter, replace_key)) {
op->insert_collision = true; op->insert_collision = true;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment