Bug 203933

Summary: btrfs incremental send fails after deduplication
Product: File System Reporter: adebeus
Component: btrfsAssignee: BTRFS virtual assignee (fs_btrfs)
Status: RESOLVED CODE_FIX    
Severity: normal CC: dsterba, fdmanana, massimo.burcheri
Priority: P1    
Hardware: All   
OS: Linux   
Kernel Version: 5.1.8 Subsystem:
Regression: No Bisected commit-id:

Description adebeus 2019-06-19 17:26:20 UTC
After deduplicating a filesystem containing a parent snapshot using bees, doing an incremental btrfs send fails with the following in dmesg:

[57807.246706] BTRFS error (device dm-2): Send: inconsistent snapshot, found updated extent for inode 8924138 without updated inode item, send root is 4457, parent root is 4425

Note: This isn't related to the fix that's in kernel 5.2 since the send and deduplication didn't occur simultaneously.

See https://github.com/Zygo/bees/issues/115
Comment 1 Filipe David Manana 2019-07-02 11:13:54 UTC
So I tried the following:

$ mkfs.btrfs -f /dev/sdb
$ mount /dev/sdb /mnt

$ xfs_io -f -c "pwrite -S 0xab 0 1M" /mnt/foo

$ btrfs subvolume snapshot -r /mnt /mnt/snap1

$ xfs_io -f -c "pwrite -S 0xab 0 1M" /mnt/bar

$ btrfs subvolume snapshot -r /mnt /mnt/snap2

# deduplicate foo into bar, so that both point to the same extent(s)
$ xfs_io -c "dedupe /mnt/snap2/foo 0 0 1M" /mnt/snap2/bar

# do the incremental send, see if it fails
$ btrfs send -p /mnt/snap1 -f /dev/null /mnt/snap2
$ echo $?
0

dmesg/syslog is also clean. Applying send streams to a filesystem also shows both files are there and with correct content.

Can you provide more details on how the deduplication is being done exactly? Full, just same extents, order, etc.
Also, any special mount options?

Thanks.
Comment 2 Filipe David Manana 2019-07-16 15:30:00 UTC
So I managed to find out how it happens exactly, it's not that trivial to reproduce and happens sort of randomly, no wonder why I have not ever hit it or had other user reports before. I'll send a fix soon (this week) to the btrfs mailing list.
Comment 4 David Sterba 2019-07-26 14:53:19 UTC
Thanks for the report and fix. Patch queued for 5.3, closing.