From 5e1c8586ccb947ffbe87592413f75006fd854518 Mon Sep 17 00:00:00 2001 From: Andy Grover Date: Wed, 14 Oct 2020 09:23:50 -0700 Subject: [PATCH] scoutfs: ensure btree values end on 8-byte-alignment boundary Round val_len up to BTREE_VALUE_ALIGN (8), to keep mid_free_len aligned. Signed-off-by: Andy Grover --- kmod/src/btree.c | 4 +++- kmod/src/format.h | 7 ++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/kmod/src/btree.c b/kmod/src/btree.c index 28644c98..92a4d4da 100644 --- a/kmod/src/btree.c +++ b/kmod/src/btree.c @@ -88,7 +88,7 @@ enum { /* total length of the value payload */ static inline unsigned int val_bytes(unsigned val_len) { - return val_len; + return round_up(val_len, SCOUTFS_BTREE_VALUE_ALIGN); } /* number of bytes in a block used by an item with the given value length */ @@ -1024,6 +1024,8 @@ static void verify_btree_block(struct super_block *sb, goto out; } + BUILD_BUG_ON(SCOUTFS_BTREE_LEAF_ITEM_HASH_BYTES % SCOUTFS_BTREE_VALUE_ALIGN != 0); + end_off = SCOUTFS_BLOCK_LG_SIZE - (level ? 0 : SCOUTFS_BTREE_LEAF_ITEM_HASH_BYTES); diff --git a/kmod/src/format.h b/kmod/src/format.h index 0ccf78ca..1dcadbe2 100644 --- a/kmod/src/format.h +++ b/kmod/src/format.h @@ -234,14 +234,19 @@ struct scoutfs_btree_block { /* leaf blocks have a fixed size item offset hash table at the end */ } __packed; +#define SCOUTFS_BTREE_VALUE_ALIGN 8 + /* * Try to aim for a 75% load in a leaf full of items with no value. * We'll almost never see this because most items have values and most * blocks aren't full. */ -#define SCOUTFS_BTREE_LEAF_ITEM_HASH_NR \ +#define SCOUTFS_BTREE_LEAF_ITEM_HASH_NR_UNALIGNED \ ((SCOUTFS_BLOCK_LG_SIZE - sizeof(struct scoutfs_btree_block)) / \ (sizeof(struct scoutfs_btree_item) + (sizeof(__le16))) * 100 / 75) +#define SCOUTFS_BTREE_LEAF_ITEM_HASH_NR \ + (round_up(SCOUTFS_BTREE_LEAF_ITEM_HASH_NR_UNALIGNED, \ + SCOUTFS_BTREE_VALUE_ALIGN)) #define SCOUTFS_BTREE_LEAF_ITEM_HASH_BYTES \ (SCOUTFS_BTREE_LEAF_ITEM_HASH_NR * sizeof(__le16))