btrfs: Remove impossible condition from mergable_maps
PATCH 1/1 btrfs: Remove impossible condition from mergable_maps
We can never have extents marked as EXTENT_MAP_DELALLOC since this value is only ever used by btrfs_get_extent_fiemap. In this case the extent map is created by btrfs_get_extent_fiemap and is never really published, this flag is used to return the corresponding userspace one. Considering this, it's pointless having a check for EXTENT_MAP_DELALLOC in mergable_maps. Just remove it.
--- fs/btrfs/extent_map.c | 2 -- 1 file changed, 2 deletions(-)
fs/btrfs/extent_map.c +0 -2
@@ -217,8 +217,6 @@ static int mergable_maps(struct extent_map *prev, struct extent_map *next) prev->block_start == EXTENT_MAP_HOLE) || (next->block_start == EXTENT_MAP_INLINE && prev->block_start == EXTENT_MAP_INLINE) || - (next->block_start ==EXTENT_MAP_DELALLOC && - prev->block_start ==EXTENT_MAP_DELALLOC ) || (next->block_start < EXTENT_MAP_LAST_BYTE - 1 && next->block_start == extent_map_block_end(prev)))) {return 1 ;
Signature · 1 line
2.17.1
Quoted 6 lines · Nikolay Borisov
We can never have extents marked as
EXTENT_MAP_DELALLOCsince this value is only ever used bybtrfs_get_extent_fiemap. In this case the extent map is created bybtrfs_get_extent_fiemapand is never really published, this flag is used to return the corresponding userspace one. Considering this, it's pointless having a check forEXTENT_MAP_DELALLOCinmergable_maps. Just remove it.
An assert would be good and a comment at EXTENT_MAP_DELALLOC definition repeating what's in the changelog. Otherwise ok.
Quoted 10 lines · David Sterba
Quoted 6 lines · Nikolay Borisov
We can never have extents marked as
EXTENT_MAP_DELALLOCsince this value is only ever used bybtrfs_get_extent_fiemap. In this case the extent map is created bybtrfs_get_extent_fiemapand is never really published, this flag is used to return the corresponding userspace one. Considering this, it's pointless having a check forEXTENT_MAP_DELALLOCinmergable_maps. Just remove it.An assert would be good and a comment at
EXTENT_MAP_DELALLOCdefinition repeating what's in the changelog. Otherwise ok.
Do we really need the assert though, it's plainly obvious EXTENT_MAP_DELALLOC is only set in a single function?
Quoted 1 line
Quoted 11 lines · Nikolay Borisov
Quoted 8 lines · David Sterba
Quoted 6 lines · Nikolay Borisov
We can never have extents marked as
EXTENT_MAP_DELALLOCsince this value is only ever used bybtrfs_get_extent_fiemap. In this case the extent map is created bybtrfs_get_extent_fiemapand is never really published, this flag is used to return the corresponding userspace one. Considering this, it's pointless having a check forEXTENT_MAP_DELALLOCinmergable_maps. Just remove it.
Quoted 5 lines
Quoted 2 lines
An assert would be good and a comment at
EXTENT_MAP_DELALLOCdefinition repeating what's in the changelog. Otherwise ok.Do we really need the assert though, it's plainly obvious
EXTENT_MAP_DELALLOCis only set in a single function?
IMHO ASSERT() is not for now, but for the future.
Later on maybe some modification would change when and who sets DELALLOC bit.
(And that's why there are a lot of seemingly stupid ASSERT(), it won't hurt anyway).
Thanks,
Qu
Quoted 2 lines
Quoted 2 lines
Quoted 13 lines · Qu Wenruo
Quoted 12 lines · Nikolay Borisov
Quoted 10 lines · David Sterba
Quoted 6 lines · Nikolay Borisov
We can never have extents marked as
EXTENT_MAP_DELALLOCsince this value is only ever used bybtrfs_get_extent_fiemap. In this case the extent map is created bybtrfs_get_extent_fiemapand is never really published, this flag is used to return the corresponding userspace one. Considering this, it's pointless having a check forEXTENT_MAP_DELALLOCinmergable_maps. Just remove it.An assert would be good and a comment at
EXTENT_MAP_DELALLOCdefinition repeating what's in the changelog. Otherwise ok.
Quoted 6 lines
Quoted 2 lines
Do we really need the assert though, it's plainly obvious
EXTENT_MAP_DELALLOCis only set in a single function?IMHO
ASSERT()is not for now, but for the future.
Later on maybe some modification would change when and who sets DELALLOC bit.
Agreed, that's exactly the point. We want to catch when DELALLOC is accidentally found during normal extent merging.
PATCH v2 1/1 btrfs: Remove impossible condition from mergable_maps
In reply to David SterbaWe can never have extents marked as EXTENT_MAP_DELALLOC since this value is only ever used by btrfs_get_extent_fiemap. In this case the extent map is created by btrfs_get_extent_fiemap and is never really published, this flag is used to return the corresponding userspace one. Considering this, it's pointless having a check for EXTENT_MAP_DELALLOC in mergable_maps. Just remove it.
---
V2:
* Add assert in mergable_maps to ensure EXTENT_MAP_DELALLOC is not set
* Clarifty that EXTENT_MAP_DELALLOC is only used during fiemap in a comment
fs/btrfs/extent_map.c | 4 ++-- fs/btrfs/extent_map.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-)
fs/btrfs/extent_map.c +2 -2
@@ -210,6 +210,8 @@ static int mergable_maps(struct extent_map *prev, struct extent_map *next)if (!list_empty (&prev->list) || !list_empty (&next->list))return 0 ; +ASSERT (next->block_start !=EXTENT_MAP_DELALLOC && + prev->block_start !=EXTENT_MAP_DELALLOC ); if (extent_map_end(prev) == next->start && prev->flags == next->flags && prev->bdev == next->bdev &&
@@ -217,8 +219,6 @@ static int mergable_maps(struct extent_map *prev, struct extent_map *next) prev->block_start == EXTENT_MAP_HOLE) || (next->block_start == EXTENT_MAP_INLINE && prev->block_start == EXTENT_MAP_INLINE) || - (next->block_start ==EXTENT_MAP_DELALLOC && - prev->block_start ==EXTENT_MAP_DELALLOC ) || (next->block_start < EXTENT_MAP_LAST_BYTE - 1 && next->block_start == extent_map_block_end(prev)))) {return 1 ;
fs/btrfs/extent_map.h +1 -1
@@ -9,7 +9,7 @@#define EXTENT_MAP_LAST_BYTE ((u64)-4)#define EXTENT_MAP_HOLE ((u64)-3)#define EXTENT_MAP_INLINE ((u64)-2) -#define EXTENT_MAP_DELALLOC ((u64)-1) +#define EXTENT_MAP_DELALLOC ((u64)-1)/* used only during fiemap calls */ /* bits for the extent_map::flags field */ enum {
Signature · 1 line
2.17.1
Quoted 8 lines · Nikolay Borisov
We can never have extents marked as
EXTENT_MAP_DELALLOCsince this value is only ever used bybtrfs_get_extent_fiemap. In this case the extent map is created bybtrfs_get_extent_fiemapand is never really published, this flag is used to return the corresponding userspace one. Considering this, it's pointless having a check forEXTENT_MAP_DELALLOCinmergable_maps. Just remove it.Signed-off-by Nikolay Borisov <[email protected]>