summaryrefslogtreecommitdiff
path: root/libbcachefs/bset.h
diff options
context:
space:
mode:
Diffstat (limited to 'libbcachefs/bset.h')
-rw-r--r--libbcachefs/bset.h51
1 files changed, 30 insertions, 21 deletions
diff --git a/libbcachefs/bset.h b/libbcachefs/bset.h
index c195cd91..f5a84481 100644
--- a/libbcachefs/bset.h
+++ b/libbcachefs/bset.h
@@ -188,16 +188,15 @@ static inline enum bset_aux_tree_type bset_aux_tree_type(const struct bset_tree
typedef void (*compiled_unpack_fn)(struct bkey *, const struct bkey_packed *);
-static inline struct bkey
-bkey_unpack_key_format_checked(const struct btree *b,
+static inline void
+__bkey_unpack_key_format_checked(const struct btree *b,
+ struct bkey *dst,
const struct bkey_packed *src)
{
- struct bkey dst;
-
#ifdef HAVE_BCACHEFS_COMPILED_UNPACK
{
compiled_unpack_fn unpack_fn = b->aux_data;
- unpack_fn(&dst, src);
+ unpack_fn(dst, src);
if (btree_keys_expensive_checks(b)) {
struct bkey dst2 = __bch2_bkey_unpack_key(&b->format, src);
@@ -206,17 +205,36 @@ bkey_unpack_key_format_checked(const struct btree *b,
* hack around a harmless race when compacting whiteouts
* for a write:
*/
- dst2.needs_whiteout = dst.needs_whiteout;
+ dst2.needs_whiteout = dst->needs_whiteout;
- BUG_ON(memcmp(&dst, &dst2, sizeof(dst)));
+ BUG_ON(memcmp(dst, &dst2, sizeof(*dst)));
}
}
#else
- dst = __bch2_bkey_unpack_key(&b->format, src);
+ *dst = __bch2_bkey_unpack_key(&b->format, src);
#endif
+}
+
+static inline struct bkey
+bkey_unpack_key_format_checked(const struct btree *b,
+ const struct bkey_packed *src)
+{
+ struct bkey dst;
+
+ __bkey_unpack_key_format_checked(b, &dst, src);
return dst;
}
+static inline void __bkey_unpack_key(const struct btree *b,
+ struct bkey *dst,
+ const struct bkey_packed *src)
+{
+ if (likely(bkey_packed(src)))
+ __bkey_unpack_key_format_checked(b, dst, src);
+ else
+ *dst = *packed_to_bkey_c(src);
+}
+
/**
* bkey_unpack_key -- unpack just the key, not the value
*/
@@ -253,7 +271,7 @@ static inline struct bkey_s_c bkey_disassemble(struct btree *b,
const struct bkey_packed *k,
struct bkey *u)
{
- *u = bkey_unpack_key(b, k);
+ __bkey_unpack_key(b, u, k);
return (struct bkey_s_c) { u, bkeyp_val(&b->format, k), };
}
@@ -263,7 +281,7 @@ static inline struct bkey_s __bkey_disassemble(struct btree *b,
struct bkey_packed *k,
struct bkey *u)
{
- *u = bkey_unpack_key(b, k);
+ __bkey_unpack_key(b, u, k);
return (struct bkey_s) { .k = u, .v = bkeyp_val(&b->format, k), };
}
@@ -353,15 +371,6 @@ static inline int bkey_cmp_p_or_unp(const struct btree *b,
}
/* Returns true if @k is after iterator position @pos */
-static inline bool btree_iter_pos_cmp(struct bpos pos, const struct bkey *k,
- bool strictly_greater)
-{
- int cmp = bkey_cmp(k->p, pos);
-
- return cmp > 0 ||
- (cmp == 0 && !strictly_greater && !bkey_deleted(k));
-}
-
static inline bool btree_iter_pos_cmp_packed(const struct btree *b,
struct bpos *pos,
const struct bkey_packed *k,
@@ -493,14 +502,14 @@ static inline void __bch2_btree_node_iter_push(struct btree_node_iter *iter,
static inline struct bkey_packed *
__bch2_btree_node_iter_peek_all(struct btree_node_iter *iter,
- struct btree *b)
+ struct btree *b)
{
return __btree_node_offset_to_key(b, iter->data->k);
}
static inline struct bkey_packed *
bch2_btree_node_iter_peek_all(struct btree_node_iter *iter,
- struct btree *b)
+ struct btree *b)
{
return bch2_btree_node_iter_end(iter)
? NULL