dedupe: clamp the source range to the file size to avoid EINVAL (#398) - #409
Open
martinus wants to merge 1 commit into
Open
dedupe: clamp the source range to the file size to avoid EINVAL (#398)#409martinus wants to merge 1 commit into
martinus wants to merge 1 commit into
Conversation
…fasheh#398) The kernel rejects the entire FIDEDUPERANGE ioctl with EINVAL when the source range extends past the end of the source (ioctl) file - the "off + len > i_size_read(src)" check in vfs_dedupe_file_range(). Extent lengths come from fiemap's fe_length, which is rounded up to the filesystem block size, so a file's final extent typically reports a length that overshoots the real end of file (a file that shrank since it was scanned does the same). Using that as the dedupe source range fails the whole batch with "Dedupe ioctl returns 22: Invalid argument" even though the data is genuinely deduplicable. Clamp the request to the source file's current size before the ioctl. If the source offset is now entirely past EOF, move the queued requests to the completed list and skip the doomed ioctl. A too-short destination is unaffected - the kernel reports that per-file via info->status. Fixes: markfasheh#398 Co-Authored-By: Claude Opus 4.8 <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What this fixes
The kernel rejects the entire
FIDEDUPERANGEioctl withEINVALwhen the source range extends past the end of the source file — theoff + len > i_size_read(src)check invfs_dedupe_file_range().Extent lengths come from fiemap's
fe_length, which is rounded up to the filesystem block size, so a file's final extent typically reports a length that overshoots the real end of file. (A file that shrank since it was scanned does the same.)What happens without the fix
Deduping genuinely-duplicate data fails with
Dedupe ioctl returns 22: Invalid argument, and the whole batch of destinations sharing that source is dropped — so real, deduplicable data is silently left un-deduped. This is the common #398 report.The fix
Clamp the request to the source file's current size (
fstat) before issuing the ioctl, so we dedupe what actually exists. If the source offset is now entirely past EOF, move the queued requests to the completed list and skip the doomed ioctl. A too-short destination is unaffected — the kernel reports that per-file viainfo->status.Fixes: #398