btrfs: fiemap: make the assert more explicit after handling the error cases
PATCH 1/1 btrfs: fiemap: make the assert more explicit after handling the error cases
Let's not assert the errors and clearly state the expected result only after eventual error handling. It makes a bit more sense this way.
--- fs/btrfs/fiemap.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
fs/btrfs/fiemap.c +2 -2
@@ -568,10 +568,10 @@ static int fiemap_find_last_extent_offset(struct btrfs_inode *inode,* there might be preallocation past i_size. */ ret =btrfs_lookup_file_extent (NULL , root, path, ino, (u64)-1 ,0 ); -/* There can't be a file extent item at offset (u64)-1 */ -ASSERT (ret !=0 );if (ret <0 )return ret; +/* There can't be a file extent item at offset (u64)-1 */ +ASSERT (ret ==1 );/* * For a non-existing key, btrfs_search_slot() always leaves us at a
Signature · 1 line
2.47.2
Quoted 3 lines · Daniel Vacek
Let's not assert the errors and clearly state the expected result only after eventual error handling. It makes a bit more sense this way.
It doesn't make more sense to me...
I prefer to assert expected results right after the function call.
Thanks.
Quoted 27 lines
Signed-off-by Daniel Vacek <[email protected]>--- fs/btrfs/fiemap.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)fs/btrfs/fiemap.c +2
-3@@ -568,10 +568,10 @@ static int fiemap_find_last_extent_offset(struct btrfs_inode *inode,* there might be preallocation past i_size. */ ret =btrfs_lookup_file_extent (NULL , root, path, ino, (u64)-1 ,0 ); -/* There can't be a file extent item at offset (u64)-1 */ -ASSERT (ret !=0 );if (ret <0 )return ret; +/* There can't be a file extent item at offset (u64)-1 */ +ASSERT (ret ==1 );/* * For a non-existing key, btrfs_search_slot() always leaves us at a -- 2.47.2
Quoted 8 lines · Filipe Manana
Quoted 3 lines · Daniel Vacek
Let's not assert the errors and clearly state the expected result only after eventual error handling. It makes a bit more sense this way.
It doesn't make more sense to me...
I prefer to assert expected results right after the function call.
Oh well, if an error is expected then I get it. Is an error likely here? I understood the comment says there can't be a file extent item at offset (u64)-1 which implies a strict return value of 1 and not an error or something >1. So that's why. And it's still quite after the function call.
But I'm happy to scratch it if you don't like it.
Quoted 29 lines
Thanks.
Quoted 27 lines
Signed-off-by Daniel Vacek <[email protected]>--- fs/btrfs/fiemap.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)fs/btrfs/fiemap.c +2
-3@@ -568,10 +568,10 @@ static int fiemap_find_last_extent_offset(struct btrfs_inode *inode,* there might be preallocation past i_size. */ ret =btrfs_lookup_file_extent (NULL , root, path, ino, (u64)-1 ,0 ); -/* There can't be a file extent item at offset (u64)-1 */ -ASSERT (ret !=0 );if (ret <0 )return ret; +/* There can't be a file extent item at offset (u64)-1 */ +ASSERT (ret ==1 );/* * For a non-existing key, btrfs_search_slot() always leaves us at a -- 2.47.2
Quoted 5 lines · Daniel Vacek
Quoted 3 lines · Filipe Manana
Quoted 1 line · Daniel Vacek
Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
Let's not assert the errors and clearly state the expected result only after eventual error handling. It makes a bit more sense this way.
It doesn't make more sense to me...
I prefer to assert expected results right after the function call.Oh well, if an error is expected then I get it. Is an error likely here?
The assertion serves to state what is never expected, and not what is likely or unlikely.
It's about stating that an exact match shouldn't happen, i.e. ret == 0.
We do this sort of asserts in many places, and I find it more clear this way.
Quoted 36 lines
I understood the comment says there can't be a file extent item at offset (u64)-1 which implies a strict return value of 1 and not an error or something >1. So that's why. And it's still quite after the function call.
But I'm happy to scratch it if you don't like it.
Quoted 29 lines
Thanks.
Quoted 27 lines
Signed-off-by Daniel Vacek <[email protected]>--- fs/btrfs/fiemap.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)fs/btrfs/fiemap.c +2
-3@@ -568,10 +568,10 @@ static int fiemap_find_last_extent_offset(struct btrfs_inode *inode,* there might be preallocation past i_size. */ ret =btrfs_lookup_file_extent (NULL , root, path, ino, (u64)-1 ,0 ); -/* There can't be a file extent item at offset (u64)-1 */ -ASSERT (ret !=0 );if (ret <0 )return ret; +/* There can't be a file extent item at offset (u64)-1 */ +ASSERT (ret ==1 );/* * For a non-existing key, btrfs_search_slot() always leaves us at a -- 2.47.2
Quoted 13 lines · Filipe Manana
Quoted 11 lines · Daniel Vacek
Quoted 8 lines · Filipe Manana
Quoted 3 lines · Daniel Vacek
Let's not assert the errors and clearly state the expected result only after eventual error handling. It makes a bit more sense this way.
It doesn't make more sense to me...
I prefer to assert expected results right after the function call.
Quoted 8 lines
Quoted 2 lines
Oh well, if an error is expected then I get it. Is an error likely here?
The assertion serves to state what is never expected, and not what is likely or unlikely.
It's about stating that an exact match shouldn't happen, i.e. ret == 0.We do this sort of asserts in many places, and I find it more clear this way.
I see. Forget it then.
Thanks.
Quoted 36 lines
Quoted 36 lines
I understood the comment says there can't be a file extent item at offset (u64)-1 which implies a strict return value of 1 and not an error or something >1. So that's why. And it's still quite after the function call.
But I'm happy to scratch it if you don't like it.
Quoted 29 lines
Thanks.
Quoted 27 lines
Signed-off-by Daniel Vacek <[email protected]>--- fs/btrfs/fiemap.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)fs/btrfs/fiemap.c +2
-3@@ -568,10 +568,10 @@ static int fiemap_find_last_extent_offset(struct btrfs_inode *inode,* there might be preallocation past i_size. */ ret =btrfs_lookup_file_extent (NULL , root, path, ino, (u64)-1 ,0 ); -/* There can't be a file extent item at offset (u64)-1 */ -ASSERT (ret !=0 );if (ret <0 )return ret; +/* There can't be a file extent item at offset (u64)-1 */ +ASSERT (ret ==1 );/* * For a non-existing key, btrfs_search_slot() always leaves us at a -- 2.47.2