From fc38ae7f4826f0cb0c668c1e044cab1fe624fe0b Mon Sep 17 00:00:00 2001 From: Qu Wenruo Date: Mon, 9 Nov 2020 13:39:51 +0800 Subject: [PATCH] btrfs-progs: check: detect and warn about tree blocks crossing 64K page boundary For the incoming subpage support, there is a new requirement for tree blocks. Tree blocks should not cross 64K page boundary. For current btrfs-progs and kernel, there shouldn't be any causes to create such tree blocks. But still, we want to detect such tree blocks in the wild before subpage support fully lands in upstream. This patch will add such check for both lowmem and original mode. Currently it's just a warning, since there aren't many users using 64K page size yet. Signed-off-by: Qu Wenruo Signed-off-by: David Sterba --- check/main.c | 2 ++ check/mode-common.h | 18 ++++++++++++++++++ check/mode-lowmem.c | 2 ++ 3 files changed, 22 insertions(+) diff --git a/check/main.c b/check/main.c index c7c5408b..0c4eb3ca 100644 --- a/check/main.c +++ b/check/main.c @@ -5400,6 +5400,8 @@ static int process_extent_item(struct btrfs_root *root, num_bytes, gfs_info->sectorsize); return -EIO; } + if (metadata) + btrfs_check_subpage_eb_alignment(key.objectid, num_bytes); memset(&tmpl, 0, sizeof(tmpl)); tmpl.start = key.objectid; diff --git a/check/mode-common.h b/check/mode-common.h index 604dc3e8..8fdeb7f6 100644 --- a/check/mode-common.h +++ b/check/mode-common.h @@ -174,4 +174,22 @@ static inline u32 btrfs_type_to_imode(u8 type) int get_extent_item_generation(u64 bytenr, u64 *gen_ret); +/* + * Check tree block alignement for future subpage support on 64K page system. + * + * Subpage support on 64K page size require one eb to be completely contained + * by a page. Not allowing a tree block to cross 64K page boudanry. + * + * Since subpage support is still under development, this check only provides + * warning. + */ +static inline void btrfs_check_subpage_eb_alignment(u64 start, u32 len) +{ + if (start / BTRFS_MAX_METADATA_BLOCKSIZE != + (start + len) / BTRFS_MAX_METADATA_BLOCKSIZE) + warning( +"tree block [%llu, %llu) crosses 64K page boudnary, may cause problem for 64K page system", + start, start + len); +} + #endif diff --git a/check/mode-lowmem.c b/check/mode-lowmem.c index 8c80e5f0..2531fde8 100644 --- a/check/mode-lowmem.c +++ b/check/mode-lowmem.c @@ -4264,6 +4264,8 @@ static int check_extent_item(struct btrfs_path *path) key.objectid, key.objectid + nodesize); err |= CROSSING_STRIPE_BOUNDARY; } + if (metadata) + btrfs_check_subpage_eb_alignment(key.objectid, nodesize); ptr = (unsigned long)(ei + 1);