diff options
author | Kent Overstreet <kmo@daterainc.com> | 2013-07-01 22:29:05 -0400 |
---|---|---|
committer | Kent Overstreet <kmo@daterainc.com> | 2013-11-11 00:56:36 -0500 |
commit | 0eacac22034ca21c73fe49e800d0b938b2047250 (patch) | |
tree | 5ff18b8b3296de48a5fa7e60aeedf2e2d2789a0a | |
parent | d5cc66e95744065f96024add4bf7d7e019be54ac (diff) |
bcache: PRECEDING_KEY()
btree_insert_key() was open coding this, this is just refactoring.
Signed-off-by: Kent Overstreet <kmo@daterainc.com>
-rw-r--r-- | drivers/md/bcache/bset.h | 18 | ||||
-rw-r--r-- | drivers/md/bcache/btree.c | 9 |
2 files changed, 20 insertions, 7 deletions
diff --git a/drivers/md/bcache/bset.h b/drivers/md/bcache/bset.h index e67386001814..bc9975526aa1 100644 --- a/drivers/md/bcache/bset.h +++ b/drivers/md/bcache/bset.h | |||
@@ -353,12 +353,30 @@ void bch_bset_fix_lookup_table(struct btree *, struct bkey *); | |||
353 | struct bkey *__bch_bset_search(struct btree *, struct bset_tree *, | 353 | struct bkey *__bch_bset_search(struct btree *, struct bset_tree *, |
354 | const struct bkey *); | 354 | const struct bkey *); |
355 | 355 | ||
356 | /* | ||
357 | * Returns the first key that is strictly greater than search | ||
358 | */ | ||
356 | static inline struct bkey *bch_bset_search(struct btree *b, struct bset_tree *t, | 359 | static inline struct bkey *bch_bset_search(struct btree *b, struct bset_tree *t, |
357 | const struct bkey *search) | 360 | const struct bkey *search) |
358 | { | 361 | { |
359 | return search ? __bch_bset_search(b, t, search) : t->data->start; | 362 | return search ? __bch_bset_search(b, t, search) : t->data->start; |
360 | } | 363 | } |
361 | 364 | ||
365 | #define PRECEDING_KEY(_k) \ | ||
366 | ({ \ | ||
367 | struct bkey *_ret = NULL; \ | ||
368 | \ | ||
369 | if (KEY_INODE(_k) || KEY_OFFSET(_k)) { \ | ||
370 | _ret = &KEY(KEY_INODE(_k), KEY_OFFSET(_k), 0); \ | ||
371 | \ | ||
372 | if (!_ret->low) \ | ||
373 | _ret->high--; \ | ||
374 | _ret->low--; \ | ||
375 | } \ | ||
376 | \ | ||
377 | _ret; \ | ||
378 | }) | ||
379 | |||
362 | bool bch_bkey_try_merge(struct btree *, struct bkey *, struct bkey *); | 380 | bool bch_bkey_try_merge(struct btree *, struct bkey *, struct bkey *); |
363 | void bch_btree_sort_lazy(struct btree *); | 381 | void bch_btree_sort_lazy(struct btree *); |
364 | void bch_btree_sort_into(struct btree *, struct btree *); | 382 | void bch_btree_sort_into(struct btree *, struct btree *); |
diff --git a/drivers/md/bcache/btree.c b/drivers/md/bcache/btree.c index 7dff73ba1b71..773b0e929ff4 100644 --- a/drivers/md/bcache/btree.c +++ b/drivers/md/bcache/btree.c | |||
@@ -1844,19 +1844,14 @@ static bool btree_insert_key(struct btree *b, struct btree_op *op, | |||
1844 | 1844 | ||
1845 | if (!b->level) { | 1845 | if (!b->level) { |
1846 | struct btree_iter iter; | 1846 | struct btree_iter iter; |
1847 | struct bkey search = KEY(KEY_INODE(k), KEY_START(k), 0); | ||
1848 | 1847 | ||
1849 | /* | 1848 | /* |
1850 | * bset_search() returns the first key that is strictly greater | 1849 | * bset_search() returns the first key that is strictly greater |
1851 | * than the search key - but for back merging, we want to find | 1850 | * than the search key - but for back merging, we want to find |
1852 | * the first key that is greater than or equal to KEY_START(k) - | 1851 | * the previous key. |
1853 | * unless KEY_START(k) is 0. | ||
1854 | */ | 1852 | */ |
1855 | if (KEY_OFFSET(&search)) | ||
1856 | SET_KEY_OFFSET(&search, KEY_OFFSET(&search) - 1); | ||
1857 | |||
1858 | prev = NULL; | 1853 | prev = NULL; |
1859 | m = bch_btree_iter_init(b, &iter, &search); | 1854 | m = bch_btree_iter_init(b, &iter, PRECEDING_KEY(&START_KEY(k))); |
1860 | 1855 | ||
1861 | if (fix_overlapping_extents(b, k, &iter, replace_key)) { | 1856 | if (fix_overlapping_extents(b, k, &iter, replace_key)) { |
1862 | op->insert_collision = true; | 1857 | op->insert_collision = true; |