renameat2(2) support was added in 61f761343f ("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; they are
skipped where the flag remains unsupported, i.e. on FUSE and on gVisor
kernels other than runsc. New tests cover mixed-type exchanges and
exchanges with ancestor directories.
Fixes #7895
Tests
The tests defined under this path are verifying functionality beyond what unit tests can cover, e.g. integration and end to end tests. Due to their nature, they may need extra setup in the test machine and extra configuration to run.
- syscalls: system call tests use a local runner, and do not require additional configuration in the machine.
- integration: defines integration tests that uses
docker runto test functionality. - image: basic end to end test for popular images. These require the same setup as integration tests.
- root: tests that require to be run as root. These require the same setup as integration tests.
- util: utilities library to support the tests.
For the above noted cases, the relevant runtime must be installed via runsc install before running. Just note that they require specific configuration to
work. This is handled automatically by the test scripts in the scripts
directory and they can be used to run tests locally on your machine. They are
also used to run these tests in kokoro.
Example:
To run image and integration tests, run:
make docker-tests
To run root tests, run:
make sudo TARGETS=test/root:root_test
There are a few other interesting variations for image and integration tests:
- overlay: sets writable overlay inside the sentry
- hostnet: configures host network passthrough, instead of netstack
- kvm: runsc the test using the KVM platform, instead of systrap
The test will build runsc, configure it with your local docker, restart
dockerd, and run tests. The location for runsc logs is printed to the output.