Support RENAME_EXCHANGE in tmpfs and overlayfs - #14416
Open
copybara-service[bot] wants to merge 1 commit into
Open
Support RENAME_EXCHANGE in tmpfs and overlayfs#14416copybara-service[bot] wants to merge 1 commit into
copybara-service[bot] wants to merge 1 commit into
Conversation
copybara-service
Bot
requested review from
EtiennePerot,
aaltinaydev,
carzh,
fvoznika,
gvisor-bot,
konstantin-s-bogom,
manninglucas,
milantracy,
nixprime,
nybidari,
parth-opensrc,
relkochta,
rexren-gif,
shailend-g,
trantoji,
xinzhong and
zkoopmans
as code owners
August 25, 2026 21:29
copybara-service
Bot
force-pushed
the
test/cl970791991
branch
2 times, most recently
from
August 25, 2026 22:33
8dd1910 to
6cf32f7
Compare
renameat2(2) support was added in 2c1c4a5 ("Implement renameat2."), but only for the gofer filesystem; tmpfs and overlayfs still return EINVAL for RENAME_EXCHANGE. Implement RENAME_EXCHANGE in tmpfs by swapping the two dentries between their parent directories. When the exchanged files differ in type, the parents' link counts (for "..") and the exchanged directory's reference on its parent are transferred. Implement RENAME_EXCHANGE in overlayfs by copying up the destination file (and its descendants, if it is a directory) in addition to the source, and then exchanging both files on the upper layer. Unlike a regular rename, no whiteout is created at the source location, since both locations remain occupied. Exchanged directories are marked opaque at their new locations to prevent merging with lower layer directories there. RENAME_EXCHANGE permits the two files to differ in type and does not require a directory being exchanged to be empty, but exchanging a file with an ancestor directory must fail with EINVAL; see Linux's fs/namei.c:__start_renaming(). The gofer filesystem previously required both files to have the same type; lift that restriction, and update parent link counts when files of different types are exchanged across directories. The RENAME_EXCHANGE syscall tests no longer accept EINVAL (except on FUSE, which does not support the flag), and new tests cover mixed-type exchanges and exchanges with ancestor directories. Fixes #7895 FUTURE_COPYBARA_INTEGRATE_REVIEW=#14221 from ayushr2:rename 26ca2a3 PiperOrigin-RevId: 970791991
copybara-service
Bot
force-pushed
the
test/cl970791991
branch
from
August 26, 2026 00:11
6cf32f7 to
634801b
Compare
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.
Support RENAME_EXCHANGE in tmpfs and overlayfs
renameat2(2) support was added in 2c1c4a5 ("Implement renameat2."), but only for the gofer filesystem; tmpfs and overlayfs still return EINVAL for RENAME_EXCHANGE.
Implement RENAME_EXCHANGE in tmpfs by swapping the two dentries between their parent directories. When the exchanged files differ in type, the parents' link counts (for "..") and the exchanged directory's reference on its parent are transferred.
Implement RENAME_EXCHANGE in overlayfs by copying up the destination file (and its descendants, if it is a directory) in addition to the source, and then exchanging both files on the upper layer. Unlike a regular rename, no whiteout is created at the source location, since both locations remain occupied. Exchanged directories are marked opaque at their new locations to prevent merging with lower layer directories there.
RENAME_EXCHANGE permits the two files to differ in type and does not require a directory being exchanged to be empty, but exchanging a file with an ancestor directory must fail with EINVAL; see Linux's fs/namei.c:__start_renaming(). The gofer filesystem previously required both files to have the same type; lift that restriction, and update parent link counts when files of different types are exchanged across directories.
The RENAME_EXCHANGE syscall tests no longer accept EINVAL (except on FUSE, which does not support the flag), and new tests cover mixed-type exchanges and exchanges with ancestor directories.
Fixes #7895
FUTURE_COPYBARA_INTEGRATE_REVIEW=#14221 from ayushr2:rename 26ca2a3