public inbox for linux-fsdevel@vger.kernel.org
 help / color / mirror / Atom feed
* FIDEDUPERANGE claims to succeed for non-identical files
@ 2022-12-20  0:10 Zbigniew Halas
  2022-12-22  8:25 ` Amir Goldstein
  0 siblings, 1 reply; 7+ messages in thread
From: Zbigniew Halas @ 2022-12-20  0:10 UTC (permalink / raw)
  To: viro; +Cc: linux-fsdevel

Hi,

I noticed a strange and misleading edge case in FIDEDUPERANGE ioctl.
For the files with the following content:
f1: abcd
f2: efghi
FIDEDUPERANGE claims to succeed and reports 4 bytes deduplicated,
despite the files being clearly different. Strace output:
openat(AT_FDCWD, "f1", O_RDONLY|O_CLOEXEC) = 3
openat(AT_FDCWD, "f2", O_WRONLY|O_CLOEXEC) = 4
ioctl(3, BTRFS_IOC_FILE_EXTENT_SAME or FIDEDUPERANGE, {src_offset=0,
src_length=4, dest_count=1, info=[{dest_fd=4, dest_offset=0}]} =>
{info=[{bytes_deduped=4, status=0}]}) = 0

The reason is that generic_remap_checks function is doing block
alignment of the deduplication length when the end of the destination
file is not at the end of the deduplication range (as described in the
comment):
/*
* If the user wanted us to link to the infile's EOF, round up to the
* next block boundary for this check.
*
* Otherwise, make sure the count is also block-aligned, having
* already confirmed the starting offsets' block alignment.
*/

So it effectively becomes a zero-length deduplication, which succeeds.
Despite that it's reported as a successful 4 bytes deduplication.

For a very similar test case, but with the files of the same length:
f3: abcd
f4: efgh
FIDEDUPERANGE fails with FILE_DEDUPE_RANGE_DIFFERS. Strace output:
openat(AT_FDCWD, "f3", O_RDONLY|O_CLOEXEC) = 3
openat(AT_FDCWD, "f4", O_WRONLY|O_CLOEXEC) = 4
ioctl(3, BTRFS_IOC_FILE_EXTENT_SAME or FIDEDUPERANGE, {src_offset=0,
src_length=4, dest_count=1, info=[{dest_fd=4, dest_offset=0}]} =>
{info=[{bytes_deduped=0, status=1}]}) = 0

For this case generic_remap_checks does not alter deduplication
length, and deduplication fails when comparing the content of the
files.

Cheers,
Zbigniew Halas

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2023-02-04  7:00 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-12-20  0:10 FIDEDUPERANGE claims to succeed for non-identical files Zbigniew Halas
2022-12-22  8:25 ` Amir Goldstein
2022-12-22 14:41   ` Zbigniew Halas
2023-01-04 17:25     ` Darrick J. Wong
2023-01-04 19:36       ` Zbigniew Halas
2023-02-04  2:23         ` Darrick J. Wong
2023-02-04  7:00           ` Amir Goldstein

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox