From 9e975dffe104a48dce50f0b5344d0316fa1fd310 Mon Sep 17 00:00:00 2001 From: Zach Brown Date: Tue, 18 Aug 2020 10:14:12 -0700 Subject: [PATCH] scoutfs: refactor btree split condition Btree traversal doesn't split a block if it has room for the caller's item. Extract this test into a function so that an upcoming btree call can test that each of multiple insertions into a leaf will fit. Signed-off-by: Zach Brown --- kmod/src/btree.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/kmod/src/btree.c b/kmod/src/btree.c index 59cde151..9d79335c 100644 --- a/kmod/src/btree.c +++ b/kmod/src/btree.c @@ -153,6 +153,13 @@ static inline unsigned int mid_free_off(struct scoutfs_btree_block *bt) return le16_to_cpu(ptr_off(bt, &bt->items[le16_to_cpu(bt->nr_items)])); } +/* true if the mid free region has room for an item struct and its value */ +static inline bool mid_free_item_room(struct scoutfs_btree_block *bt, + int val_len) +{ + return le16_to_cpu(bt->mid_free_len) >= item_len_bytes(val_len); +} + static inline struct scoutfs_key *item_key(struct scoutfs_btree_item *item) { return &item->key; @@ -873,7 +880,7 @@ static int try_split(struct super_block *sb, val_len = sizeof(struct scoutfs_btree_ref); /* don't need to split if there's enough space for the item */ - if (le16_to_cpu(right->mid_free_len) >= item_len_bytes(val_len)) + if (mid_free_item_room(right, val_len)) return 0; if (item_full_pct(right) < 80) {