btrfs: tree-checker: missing returns after data_ref alignment checks
RFC PATCH 1/1 btrfs: tree-checker: missing returns after data_ref alignment checks
Hi Qu,
I've found more missing return satetments in tree-checker but I'm not sure if leaving them out was intentional. Both are for extent data_ref item alignment checks. It could be that alignment is not a hard problem, tough it could point to one, there's a check of the hash vs key->offset that would catch inconsistent data.
As there's only one statement after if, this looks like it was forgotten, but otherwise needs a comment why the returns are not there given that the rest of the file follows the same pattern "if / extent_err/ return -EUCLEAN".
--- fs/btrfs/tree-checker.c | 2 ++ 1 file changed, 2 insertions(+)
fs/btrfs/tree-checker.c +2 -0
@@ -1424,6 +1424,7 @@ static int check_extent_data_ref(struct extent_buffer *leaf,"invalid item size, have %u expect aligned to %zu for key type %u" ,btrfs_item_size_nr (leaf, slot), sizeof(*dref), key->type); +return -EUCLEAN ; }if (!IS_ALIGNED (key->objectid, leaf->fs_info->sectorsize)) { generic_err(leaf, slot,
@@ -1452,6 +1453,7 @@ static int check_extent_data_ref(struct extent_buffer *leaf,extent_err (leaf, slot,"invalid extent data backref offset, have %llu expect aligned to %u" , offset, leaf->fs_info->sectorsize); +return -EUCLEAN ; } }return 0 ;
Signature · 1 line
2.25.0
Quoted 7 lines · David Sterba
Hi Qu,
I've found more missing return satetments in tree-checker but I'm not sure if leaving them out was intentional. Both are for extent
data_refitem alignment checks. It could be that alignment is not a hard problem, tough it could point to one, there's a check of the hash vskey->offsetthat would catch inconsistent data.
All my bad.
The case is, alignment is the first sign of corruption. So if alignment is incorrect, there is no need to continue.
So yeah, I forgot more return lines.
Quoted 15 lines
As there's only one statement after if, this looks like it was forgotten, but otherwise needs a comment why the returns are not there given that the rest of the file follows the same pattern "if / extent_err/ return
-EUCLEAN".--- fs/btrfs/tree-checker.c | 2 ++ 1 file changed, 2 insertions(+)fs/btrfs/tree-checker.c +0
-0
fs/btrfs/tree-checker.c static int check_extent_data_ref(struct extent_buffer *leaf, · line 1427
Quoted 4 lines
fs/btrfs/tree-checker.c +1
-0@@ -1424,6 +1424,7 @@ static int check_extent_data_ref(struct extent_buffer *leaf,"invalid item size, have %u expect aligned to %zu for key type %u" ,btrfs_item_size_nr (leaf, slot), sizeof(*dref), key->type); +return -EUCLEAN ;
For EXTENT_DATA_REF_KEY, it should only contains one or more btrfs_extent_data_ref, thus the alignment is a hard requirement.
Thus the return is needed.
fs/btrfs/tree-checker.c static int check_extent_data_ref(struct extent_buffer *leaf, · line 1456
Quoted 8 lines
fs/btrfs/tree-checker.c +1
-0}if (!IS_ALIGNED (key->objectid, leaf->fs_info->sectorsize)) { generic_err(leaf, slot,@@ -1452,6 +1453,7 @@ static int check_extent_data_ref(struct extent_buffer *leaf,extent_err (leaf, slot,"invalid extent data backref offset, have %llu expect aligned to %u" , offset, leaf->fs_info->sectorsize); +return -EUCLEAN ;
Basic sector size alignment requirement.
So yet another missing return.
Thanks,
Qu
Quoted 4 lines
fs/btrfs/tree-checker.c +0
-0} }return 0 ;
Quoted 41 lines · Qu Wenruo
Quoted 7 lines · David Sterba
Hi Qu,
I've found more missing return satetments in tree-checker but I'm not sure if leaving them out was intentional. Both are for extent
data_refitem alignment checks. It could be that alignment is not a hard problem, tough it could point to one, there's a check of the hash vskey->offsetthat would catch inconsistent data.All my bad.
The case is, alignment is the first sign of corruption. So if alignment is incorrect, there is no need to continue.
So yeah, I forgot more return lines.
Quoted 15 lines
As there's only one statement after if, this looks like it was forgotten, but otherwise needs a comment why the returns are not there given that the rest of the file follows the same pattern "if / extent_err/ return
-EUCLEAN".--- fs/btrfs/tree-checker.c | 2 ++ 1 file changed, 2 insertions(+)fs/btrfs/tree-checker.c +0
-0fs/btrfs/tree-checker.c static int check_extent_data_ref(struct extent_buffer *leaf, · line 1427
Quoted 4 lines
fs/btrfs/tree-checker.c +1
-0@@ -1424,6 +1424,7 @@ static int check_extent_data_ref(struct extent_buffer *leaf,"invalid item size, have %u expect aligned to %zu for key type %u" ,btrfs_item_size_nr (leaf, slot), sizeof(*dref), key->type); +return -EUCLEAN ;For
EXTENT_DATA_REF_KEY, it should only contains one or morebtrfs_extent_data_ref, thus the alignment is a hard requirement.Thus the return is needed.
Quoted 11 lines
fs/btrfs/tree-checker.c static int check_extent_data_ref(struct extent_buffer *leaf, · line 1456
Quoted 8 lines
fs/btrfs/tree-checker.c +1
-0}if (!IS_ALIGNED (key->objectid, leaf->fs_info->sectorsize)) { generic_err(leaf, slot,@@ -1452,6 +1453,7 @@ static int check_extent_data_ref(struct extent_buffer *leaf,extent_err (leaf, slot,"invalid extent data backref offset, have %llu expect aligned to %u" , offset, leaf->fs_info->sectorsize); +return -EUCLEAN ;Basic sector size alignment requirement.
So yet another missing return.
Thanks, I'll resend it as a proper patch.