It's a common practice to avoid use sizeof(struct btrfs_super_block)
(3531), but to use BTRFS_SUPER_INFO_SIZE (4096).
The problem is that, sizeof(struct btrfs_super_block) doesn't match
BTRFS_SUPER_INFO_SIZE from the very beginning.
Furthermore, for all call sites except selftest, we always allocate
BTRFS_SUPER_INFO_SIZE space for btrfs super block, there isn't any real
reason to use the smaller value, and it doesn't really save any space.
So let's get rid of such confusing behavior, and unify those two values.
This patch will also add a BUILD_BUG_ON() to verify the value at build
time.
Signed-off-by: Qu Wenruo <redacted>
---
fs/btrfs/ctree.h | 3 +++
fs/btrfs/super.c | 2 ++
2 files changed, 5 insertions(+)
diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h
index 140126898577..e05098ac0337 100644
--- a/fs/btrfs/ctree.h
+++ b/fs/btrfs/ctree.h
@@ -270,6 +270,9 @@ struct btrfs_super_block {
__le64 reserved[28];
u8 sys_chunk_array[BTRFS_SYSTEM_CHUNK_ARRAY_SIZE];
struct btrfs_root_backup super_roots[BTRFS_NUM_BACKUP_ROOTS];
+
+ /* Padded to 4096 bytes */
+ u8 padding[565];
} __attribute__ ((__packed__));
/*diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c
index a1c54a2c787c..6fb5cdfceaf5 100644
--- a/fs/btrfs/super.c
+++ b/fs/btrfs/super.c
@@ -2552,6 +2552,8 @@ static int __init init_btrfs_fs(void)
{
int err;
+ BUILD_BUG_ON(sizeof(struct btrfs_super_block) != BTRFS_SUPER_INFO_SIZE);
+
btrfs_props_init();
err = btrfs_init_sysfs();--
2.33.0