Repository navigation
fix(copy): fall back to a byte copy when reflink is rejected with EPERM - #4434
Conversation
reflink-copy's reflink_or_copy returns PermissionDenied from the clone attempt without trying fs::copy. Some filesystems answer FICLONE with EPERM rather than EOPNOTSUPP, so wt step copy-ignored failed where cp --reflink=auto succeeds. Retry with fs::copy on PermissionDenied; a genuine permission problem fails the retry with the same error. Closes #4433
|
@worktrunk-bot The EPERM fallback retries with
|
reflink_or_copy removes the destination it created before returning PermissionDenied, so retrying with fs::copy could overwrite a file another process created in that gap, even with force=false. The fallback now creates the destination with create_new, so a racer surfaces as AlreadyExists (which copy_leaf skips), copies the source's permissions onto the handle, and removes its own partial file if the copy fails. Co-Authored-By: Claude <[email protected]>
|
Fixed in 9d69e07. The EPERM fallback no longer calls New tests:
|
worktrunk-bot
left a comment
There was a problem hiding this comment.
codecov/patch is red: the partial-copy cleanup in copy_to_new_file (the drop(writer); let _ = fs::remove_file(dest); branch) is never exercised, so the claim that a failed copy leaves nothing for a re-run to skip is untested. On Unix, opening a directory as the source reaches that branch: File::open succeeds, create_new creates the destination, and io::copy fails with EISDIR. I'll push a test asserting the error and that no destination is left behind.
|
@worktrunk-bot The new exclusive create fixes the overwrite on a successful fallback. The failed-copy cleanup still drops
|
…ouches dest The fallback created `dest` with `create_new` and, on a failed copy, removed it by pathname — deleting another process's file if the path was replaced in between, and ignoring a failed removal. Copy into a sibling temp file and persist it with a no-clobber rename instead: `dest` only appears complete, a failed copy removes only the temp file, and a failed removal is reported.
|
Fixed in b6df455. The fallback no longer creates
New tests:
One case is still possible: a crash between creating the temp file and the rename leaves a |
Route the staged leaf copy through main's EPERM reflink fallback (#4434) and keep both Windows-only dependencies (windows-sys, dirs).
reflink-copy 0.1.30's
reflink_or_copypassesPermissionDeniedfrom the clone attempt straight through instead of falling back tofs::copy(it does the same forNotFoundandAlreadyExists). On the reporter's kernelFICLONEreturnsEPERMrather thanEOPNOTSUPP, sowt step copy-ignoredfailed with "Operation not permitted" on a file thatcp --reflink=autocopies without trouble.copy_leafnow goes through a small wrapper that retries with a byte copy when the reflink attempt returnsPermissionDenied. The file is then reported as written in full rather than reflinked. A real permission problem on the source or destination fails the retry with the same error, so it is still reported. The crate'sAutoRemovedFiledeletes the destination it created before returning the error, so the retry doesn't callfs::copy, which could overwrite a file another process puts there in that gap. It copies into a temp file beside the destination, gives it the source's mode, and moves it into place with a no-clobber rename (persist_noclobber, asutils::write_new_atomicallydoes). The destination only ever appears complete. If something already occupies it, the retry fails withAlreadyExists, whichcopy_leafalready skips. A failed copy removes only its own temp file, and if that removal fails the error says so.No CI filesystem rejects
FICLONEwithEPERM, so the regression testtest_reflink_rejected_with_eperm_falls_back_to_copycovers the retry decision with synthetic errors:PermissionDeniedfalls back, a failing retry still errors, and success andAlreadyExistspass through without a retry.test_rejected_reflink_fallback_does_not_overwrite_racing_destinationcreates a file at the destination between the rejected reflink and the retry, and checks that the file survives.test_failed_copy_cleanup_leaves_racing_destinationchecks that a failed copy leaves a file at the destination alone and leaves no temp file.test_discard_temp_reports_cleanup_failurechecks that a failed temp-file removal is reported.test_copy_to_new_file_copies_contents_and_modechecks the contents and mode. The full path was not run on an EPERM-rejecting filesystem.#4346 also edits this call site in
src/copy.rsand keeps the barereflink_copy::reflink_or_copy. Whichever lands second should route its call through the wrapper.Closes #4433 — automated triage