Bug 2187312 - SEEK_HOLE on BTRFS is treating some just written data as holes
Summary: SEEK_HOLE on BTRFS is treating some just written data as holes
Keywords:
Status: CLOSED CURRENTRELEASE
Alias: None
Product: Fedora
Classification: Fedora
Component: kernel
Version: 37
Hardware: x86_64
OS: Linux
unspecified
urgent
Target Milestone: ---
Assignee: Josef Bacik
QA Contact: Fedora Extras Quality Assurance
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2023-04-17 12:49 UTC by Pádraig Brady
Modified: 2023-04-17 21:27 UTC (History)
19 users (show)

Fixed In Version:
Clone Of:
Environment:
Last Closed: 2023-04-17 21:27:16 UTC
Type: ---
Embargoed:


Attachments (Terms of Use)
repro (1.49 KB, text/plain)
2023-04-17 12:52 UTC, Pádraig Brady
no flags Details

Description Pádraig Brady 2023-04-17 12:49:38 UTC
User-Agent:       Mozilla/5.0 (X11; Linux x86_64; rv:109.0) Gecko/20100101 Firefox/112.0
Build Identifier: 

using cp to copy a sparse file treats some none sparse parts as sparse, resulting in data corruption in the copy. The size of the copy is correct, just that some of the extents are zeros when they should not be. Repro script is attached and usually triggers within a minute. Note if the sparse file is sync'd with the sync command before the copy, then there is no corruption.

Reproducible: Sometimes

Steps to Reproduce:
1.Just run the attached script on BTRFS
Actual Results:  
script exits with error message

Expected Results:  
script runs forever

Comment 1 Pádraig Brady 2023-04-17 12:51:03 UTC
Note the versions / settings on this machine are:

$ uname -a
Linux fedora 6.1.6-200.fc37.x86_64 #1 SMP PREEMPT_DYNAMIC Sat Jan 14 16:55:06 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux

$ df -Th .
Filesystem                                            Type   Size  Used Avail Use% Mounted on
/dev/mapper/luks-453ccafd-e054-4cab-8e60-d88256429112 btrfs  238G   11G  226G   5% /home

$ grep home /proc/mounts
/dev/mapper/luks-453ccafd-e054-4cab-8e60-d88256429112 /home btrfs rw,seclabel,relatime,compress=zstd:1,ssd,space_cache=v2,subvolid=256,subvol=/home 0 0

Comment 2 Pádraig Brady 2023-04-17 12:52:22 UTC
Created attachment 1957851 [details]
repro

Comment 3 Filipe Manana 2023-04-17 18:23:10 UTC
Can you try with a 6.2 kernel?

I'm unable to reproduce on a 6.3-rcX kernel, with coreutils 9.2 (so cp uses SEEK_HOLE and not fiemap).

Some changes happened in 6.2 that may have accidentally fixed the problem you are running into.
These are the 6.2 changes:  https://lore.kernel.org/linux-btrfs/cover.1668166764.git.fdmanana@suse.com/

Thanks.

Comment 4 Pádraig Brady 2023-04-17 21:26:48 UTC
I can NOT repro on a 6.2 kernel.
So Fedora is fine I suppose since all Fedora now have a 6.2 kernel as their stable kernel.

For completeness the problematic combo is: coreutils >= 9.0, kernel <= 6.1, BTRFS, sparse input file


Note You need to log in before you can comment on or make changes to this bug.