Commit 3bdad1e4 authored by Nicholas Swenson's avatar Nicholas Swenson Committed by Kent Overstreet

bcache: Add bch_bkey_equal_header()

Checks if two keys have equivalent header fields.
(good enough for replacement or merging)

Used in bch_bkey_try_merge, and replacing a key
in the btree.
Signed-off-by: default avatarNicholas Swenson <nks@daterainc.com>
Signed-off-by: default avatarKent Overstreet <kmo@daterainc.com>
parent 0f49cf3d
...@@ -788,12 +788,8 @@ bool bch_bkey_try_merge(struct btree_keys *b, struct bkey *l, struct bkey *r) ...@@ -788,12 +788,8 @@ bool bch_bkey_try_merge(struct btree_keys *b, struct bkey *l, struct bkey *r)
* Assumes left and right are in order * Assumes left and right are in order
* Left and right must be exactly aligned * Left and right must be exactly aligned
*/ */
if (KEY_U64s(l) != KEY_U64s(r) || if (!bch_bkey_equal_header(l, r) ||
KEY_DELETED(l) != KEY_DELETED(r) || bkey_cmp(l, &START_KEY(r)))
KEY_CACHED(l) != KEY_CACHED(r) ||
KEY_VERSION(l) != KEY_VERSION(r) ||
KEY_CSUM(l) != KEY_CSUM(r) ||
bkey_cmp(l, &START_KEY(r)))
return false; return false;
return b->ops->key_merge(b, l, r); return b->ops->key_merge(b, l, r);
......
...@@ -448,6 +448,14 @@ static inline void bch_bkey_to_text(struct btree_keys *b, char *buf, ...@@ -448,6 +448,14 @@ static inline void bch_bkey_to_text(struct btree_keys *b, char *buf,
return b->ops->key_to_text(buf, size, k); return b->ops->key_to_text(buf, size, k);
} }
static inline bool bch_bkey_equal_header(const struct bkey *l,
const struct bkey *r)
{
return (KEY_DIRTY(l) == KEY_DIRTY(r) &&
KEY_PTRS(l) == KEY_PTRS(r) &&
KEY_CSUM(l) == KEY_CSUM(l));
}
/* Keylists */ /* Keylists */
struct keylist { struct keylist {
......
...@@ -372,8 +372,7 @@ static bool bch_extent_insert_fixup(struct btree_keys *b, ...@@ -372,8 +372,7 @@ static bool bch_extent_insert_fixup(struct btree_keys *b,
if (KEY_START(k) > KEY_START(insert) + sectors_found) if (KEY_START(k) > KEY_START(insert) + sectors_found)
goto check_failed; goto check_failed;
if (KEY_PTRS(k) != KEY_PTRS(replace_key) || if (!bch_bkey_equal_header(k, replace_key))
KEY_DIRTY(k) != KEY_DIRTY(replace_key))
goto check_failed; goto check_failed;
/* skip past gen */ /* skip past gen */
......
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