path: root/cmds-check.c
diff options
authorQu Wenruo <>2016-10-24 15:22:33 +0800
committerDavid Sterba <>2016-10-25 14:31:06 +0200
commitffb1b847bd554e45c00212280847b9f2059a87f3 (patch)
treeac814579158f3a29451ed842850989ca7c000d8e /cmds-check.c
parentb2fbfc8cdd4ce4bf7d22e55695a4cc7e707c9ef3 (diff)
btrfs-progs: Fix wrong tree block alignment for unalianged block group
Commit 854437ca(btrfs-progs: extent-tree: avoid allocating tree block that crosses stripe boundary) introduces check for logical bytenr not crossing stripe boundary. However that check is not completely correct. It only checks if the logical bytenr and length agaist absolute logical offset. That's to say, it only check if a tree block lies in 64K logical stripe. But in fact, it's possible a block group starts at bytenr unaligned with 64K, just like the following case. Then btrfsck will give false alert. 0 32K 64K 96K 128K 160K ... |--------------- Block group A --------------------- |<-----TB 32K------>| |/Scrub stripe unit/| | WRONG UNIT | In that case, TB(tree block) at bytenr 32K in fact fits into the kernel scrub stripe unit. But doesn't fit into the pure logical 64K stripe. Fix check_crossing_stripes() to compare bytenr to block group start, not to absolute logical bytenr. Reported-by: Jussi Kansanen <> Signed-off-by: Qu Wenruo <> Signed-off-by: David Sterba <>
Diffstat (limited to 'cmds-check.c')
1 files changed, 6 insertions, 4 deletions
diff --git a/cmds-check.c b/cmds-check.c
index 670ccd1f..907d60c5 100644
--- a/cmds-check.c
+++ b/cmds-check.c
@@ -4662,8 +4662,8 @@ static int add_extent_rec_nolookup(struct cache_tree *extent_cache,
bytes_used += rec->nr;
if (tmpl->metadata)
- rec->crossing_stripes = check_crossing_stripes(rec->start,
- global_info->tree_root->nodesize);
+ rec->crossing_stripes = check_crossing_stripes(global_info,
+ rec->start, global_info->tree_root->nodesize);
return ret;
@@ -4764,7 +4764,8 @@ static int add_extent_rec(struct cache_tree *extent_cache,
if (tmpl->metadata)
rec->crossing_stripes = check_crossing_stripes(
- rec->start, global_info->tree_root->nodesize);
+ global_info, rec->start,
+ global_info->tree_root->nodesize);
maybe_free_extent_rec(extent_cache, rec);
return ret;
@@ -9359,7 +9360,8 @@ static int check_extent_item(struct btrfs_fs_info *fs_info,
metadata = 1;
- if (metadata && check_crossing_stripes(key.objectid, eb->len)) {
+ if (metadata && check_crossing_stripes(global_info, key.objectid,
+ eb->len)) {
error("bad metadata [%llu, %llu) crossing stripe boundary",
key.objectid, key.objectid + nodesize);