Skip to content

Commit 8dff9c8

Browse files
committed
Btrfs: deal with duplciates during extent_map insertion in btrfs_get_extent
When dealing with inline extents, btrfs_get_extent will incorrectly try to insert a duplicate extent_map. The dup hits -EEXIST from add_extent_map, but then we try to merge with the existing one and end up trying to insert a zero length extent_map. This actually works most of the time, except when there are extent maps past the end of the inline extent. rocksdb will trigger this sometimes because it preallocates an extent and then truncates down. Josef made a script to trigger with xfs_io: #!/bin/bash xfs_io -f -c "pwrite 0 1000" inline xfs_io -c "falloc -k 4k 1M" inline xfs_io -c "pread 0 1000" -c "fadvise -d 0 1000" -c "pread 0 1000" inline xfs_io -c "fadvise -d 0 1000" inline cat inline You'll get EIOs trying to read inline after this because add_extent_map is returning EEXIST Signed-off-by: Chris Mason <[email protected]>
1 parent f881dd2 commit 8dff9c8

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

fs/btrfs/inode.c

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6979,7 +6979,18 @@ struct extent_map *btrfs_get_extent(struct inode *inode, struct page *page,
69796979
* existing will always be non-NULL, since there must be
69806980
* extent causing the -EEXIST.
69816981
*/
6982-
if (start >= extent_map_end(existing) ||
6982+
if (existing->start == em->start &&
6983+
extent_map_end(existing) == extent_map_end(em) &&
6984+
em->block_start == existing->block_start) {
6985+
/*
6986+
* these two extents are the same, it happens
6987+
* with inlines especially
6988+
*/
6989+
free_extent_map(em);
6990+
em = existing;
6991+
err = 0;
6992+
6993+
} else if (start >= extent_map_end(existing) ||
69836994
start <= existing->start) {
69846995
/*
69856996
* The existing extent map is the one nearest to

0 commit comments

Comments
 (0)