summaryrefslogtreecommitdiff
path: root/drivers/md/bcache/bset.h
diff options
context:
space:
mode:
authorKent Overstreet <kmo@daterainc.com>2013-11-11 19:03:54 -0800
committerKent Overstreet <kmo@daterainc.com>2014-01-08 13:05:13 -0800
commit59158fde429fb5d18064e2734b3dd5e6048affbd (patch)
tree1cc4d34e0ba1523155dad7b8726b5249d050cc34 /drivers/md/bcache/bset.h
parenta85e968e66a175c86d0410719ea84a5bd0f1d070 (diff)
bcache: Add bch_btree_keys_u64s_remaining()
Helper function to explicitly check how much space is free in a btree node Signed-off-by: Kent Overstreet <kmo@daterainc.com>
Diffstat (limited to 'drivers/md/bcache/bset.h')
-rw-r--r--drivers/md/bcache/bset.h15
1 files changed, 15 insertions, 0 deletions
diff --git a/drivers/md/bcache/bset.h b/drivers/md/bcache/bset.h
index 87da828477f3..4fc40fd719de 100644
--- a/drivers/md/bcache/bset.h
+++ b/drivers/md/bcache/bset.h
@@ -260,6 +260,21 @@ static inline bool btree_keys_expensive_checks(struct btree_keys *b)
#define set_blocks(i, block_bytes) \
__set_blocks(i, (i)->keys, block_bytes)
+static inline size_t bch_btree_keys_u64s_remaining(struct btree_keys *b)
+{
+ struct bset_tree *t = bset_tree_last(b);
+
+ BUG_ON((PAGE_SIZE << b->page_order) <
+ (bset_byte_offset(b, t->data) + set_bytes(t->data)));
+
+ if (!b->last_set_unwritten)
+ return 0;
+
+ return ((PAGE_SIZE << b->page_order) -
+ (bset_byte_offset(b, t->data) + set_bytes(t->data))) /
+ sizeof(u64);
+}
+
static inline struct bset *bset_next_set(struct btree_keys *b,
unsigned block_bytes)
{