Skip to contentSkip to conversation

btrfs: Remove impossible condition from mergable_maps

PATCH Superseded Nikolay Borisov 3 participants 7 messages Dec 18, 2018 – Jan 9, 2019 Btrfs file system

lore
Share & tools
lore
#0 lore raw

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
index 7eea8b6e2cd3..7cc893876f83 100644
@@ -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
#1 lore raw
Quoted 6 lines · Nikolay Borisov

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.

An assert would be good and a comment at EXTENT_MAP_DELALLOC definition repeating what's in the changelog. Otherwise ok.

#2 lore raw
Quoted 10 lines · David Sterba
Quoted 6 lines · Nikolay Borisov

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.

An assert would be good and a comment at EXTENT_MAP_DELALLOC definition 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
#3 lore raw
Quoted 11 lines · Nikolay Borisov
Quoted 8 lines · David Sterba
Quoted 6 lines · Nikolay Borisov

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.

Quoted 5 lines
Quoted 2 lines

An assert would be good and a comment at EXTENT_MAP_DELALLOC definition 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?

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
#4 lore raw
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_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.

An assert would be good and a comment at EXTENT_MAP_DELALLOC definition 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_DELALLOC is 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.

#5 lore raw

PATCH v2 1/1 btrfs: Remove impossible condition from mergable_maps

In reply to David Sterba

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.

---

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
index a042a193c120..c65f208acfb3 100644
@@ -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
index ef05a0121652..9ef8766f478a 100644
@@ -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
Reviewed-by on v2 1/1
#6 lore raw
Quoted 8 lines · Nikolay Borisov

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.