Repository navigation
fix(engine): key --write-devices on the local-copy destination - #7796
Merged
Merged
Conversation
The local-copy executor had no `--write-devices` predicate at all. It reached
upstream's answer only because its DEFAULT write strategy stages into a temp
file and renames over whatever stands at the destination; every strategy that
opens the final name instead - `--inplace`, `--append`, and the `--inplace`
that `--write-devices` itself implies (options.c:2555) - streamed the payload
THROUGH a device node the operator had not authorised writing through.
Upstream decides this once, keyed on the DESTINATION:
generator.c:2148-2153
if (statret == 0 && !(stype == FT_REG || (write_devices && stype == FT_DEVICE))) {
if (delete_item(fname, sx.st.st_mode, del_opts | DEL_FOR_FILE) != 0)
goto cleanup;
statret = -1;
stat_errno = ENOENT;
}
The source is a REGULAR file in both arms - `--write-devices` streams a regular
file's contents into an existing device - so nothing in the entry being sent
identifies the case. That is the same keying the receiver pipeline uses
(crates/transfer/.../candidates.rs, PR #7583), and the reason a predicate
derived from the flist can only ever be wrong.
This adds the DEVICE arm of that condition to the local path as one decision
site next to the directory arm that already lives there. It is
`delete_item()`'s NON-directory branch, which differs from the directory branch
in two ways that both matter: the node is backed up rather than unlinked under
`--backup`, and the backup prefers an outright RENAME
(delete.c:230 `make_backup(fbuf, True)`) instead of the hard-link tier the
generator's own `make_backup(fname, False)` uses - a hard link would leave the
device standing at the destination and the transfer would write through it
after all. The `statret = -1` reset is carried too, so the entry itemizes as a
creation rather than as an update against a node that is no longer there.
`--write-devices` reaches the engine as a flag of its own rather than only as
the `--inplace` it implies: `--inplace` alone never authorises writing through
a device node, so the two cannot share one boolean.
Measured against rsync 3.5.0 (protocol 32) as root on Linux (aarch64, a tmpfs
mounted `dev`, the destination a loop device over a 64 KiB backing file so the
bytes that reach the device are readable afterwards), 52 local cells:
| cell | rsync 3.5.0 | oc before |
|----------------------------------|------------------------|------------------------|
| `--inplace`, device dest | 0, dest REGULAR | 0, device written through |
| `--append`, device dest | 0, dest REGULAR | 0, device written through |
| `--inplace --sparse`, device | 0, dest REGULAR | 23, ftruncate EINVAL |
| `--inplace --no-whole-file` | 0, dest REGULAR | 0, device written through |
| `--inplace -r`, device in tree | 0, dest REGULAR | 0, device kept |
| `--inplace`, CHAR device dest | 0, dest REGULAR | 0, device kept |
| `--append`, CHAR device dest | 0, dest REGULAR | 0, device kept |
| `--backup --inplace`, device | 0, dest REGULAR, `~` the node | 0, device kept |
| `-i`, device dest | `>f+++++++++` | `>f.sT......` |
| `--stats`, device dest | `created files: 1` | `created files: 0` |
All ten now agree. The cells that already agreed are kept as negative
controls and still agree: `--write-devices` keeps and writes the node (plain,
`-a`, `--checksum`, `--update`, `--whole-file`, `--no-whole-file`, recursive),
`--ignore-existing` leaves it standing (generator.c:1780 is tested ahead of the
removal), `--dry-run` leaves it standing while still reporting a creation,
`--existing` still replaces it, a regular destination is untouched, and a device
SOURCE is unaffected in every combination of `-D` / `--copy-devices` /
`--write-devices`.
Three device cells still diverge and are NOT addressed here, each owned
elsewhere:
- `--write-devices --sparse`: upstream exits 11 `write failed on %s` from
`sparse_end()` (receiver.c:639-644, whose own ftruncate is deliberately not
IS_DEVICE-gated); oc exits 23 from the equivalent truncate. The divergence
is the exit-code and message mapping of a failing sparse end, not the
predicate.
- `--write-devices --preallocate`: upstream never attempts the reservation,
because receiver.c:476's `(!inplace_sizing || total_size > size_r)` sees the
device's real size (generator.c:2226 `get_device_size`); oc has no
device-size probe, attempts `fallocate` and exits 23, where upstream would
only have warned (receiver.c:480 `rsyserr(FWARNING, ...)`).
- `--write-devices --backup`: upstream's backup of the kept device is a
regular file holding the pre-image; oc hard-links the node.
Two further findings from the same sweep, both outside this change:
- `--inplace` over a FIFO destination HANGS indefinitely (upstream exits 0
having replaced it). Same missing make-way decision, different disjunct:
only the FT_DEVICE half is ported here.
- `--write-devices` into a device the caller does not own exits 23 with
`failed to apply dest_mode` where upstream exits 0, because upstream skips
the `chmod` when the permission bits already match and `dest_mode()`'s
`exists` arm has already made them match.
Verified on the pinned toolchain (1.88.0): `tools/ci/check_rustfmt_all.py`
clean, `clippy -p engine -p core -p bin --all-targets --no-deps -D warnings`
clean, `nextest -p engine --all-features` 5125 passed, `-p core` 2851 passed,
`-p transfer` 2938 passed.
Mutation-proved by reverting each half and rebuilding for Linux, run as root:
| mutation | tests that failed |
|-----------------------------------------|-------------------|
| predicate always false (pre-fix shape) | inplace_..._replaces, append_..._replaces, ..._itemizes_as_a_creation, ..._is_backed_up_not_unlinked, plus the `write_devices=false` unit cell |
| predicate ignores `--write-devices` | write_devices_keeps_a_device_destination, write_devices_never_makes_way_at_a_shared_device, plus the `write_devices=true` unit cell |
| `--ignore-existing` ordering guard dropped | ignore_existing_leaves_a_device_destination_alone |
| `statret = -1` reset dropped | a_replaced_device_destination_itemizes_as_a_creation |
Most of those cells need `mknod(2)`, so they self-gate and say so out loud on
an unprivileged host; the two that run everywhere - the predicate unit cells and
the `/dev/null` cell - kill both predicate mutations on their own. The
`/dev/null` cell deliberately runs ONLY where device nodes cannot be created:
where they can, a mutated tree unlinks the host's `/dev/null` for real.
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.
Local copy had no
--write-devicespredicate at all, so a device node standing atthe destination was never cleared: without the flag oc wrote through the device
where upstream replaces it with a regular file.
The filed premise is refuted
This was filed as "structurally absent, but accidentally correct 3/3". Measured
against real
rsync 3.5.0binaries, 10 of 52 local cells diverge — and one ofthem is not a divergence but a failure.
--inplace, block-dev dest--append, block-dev dest--inplace --sparse, block dev--inplace --no-whole-file--inplace -r, device in tree--inplace, CHAR dev dest--append, CHAR dev dest--backup --inplace, devdst~= the node-i, dev dest>f+++++++++>f.sT......>f+++++++++--stats, dev destcreated files: 1created files: 01"Written through" is the substantive one: without
--write-devicesthe operatordid not ask to write to the device, and oc did anyway.
Upstream, read first
write_devicesis consulted at exactly six sites in 3.5.0. Two were already ported(
options.c:2555inplace = 1via #7260;options.c:3150server args). Themake-way decision is
generator.c:2148:The new predicate is that line's
write_devices && stype == FT_DEVICEhalf andnothing more;
IS_DEVICEisrsync.h:1394(S_ISCHR || S_ISBLK), so char andblock both count. The
statret = -1reset at:2151is what makes the itemize rowread as a creation rather than a change — that is why the
-iand--statsrowsabove move together with the filesystem outcome.
Disposal follows
delete.c:227-238: under--backupthe node is renamed(
make_backup(fbuf, True)), not hard-linked. A hard link would leave the devicenode standing at the destination, which is the whole thing being fixed.
Consistent with #7583: no
file->mode→S_IFBLKrewrite anywhere. The decision iskeyed on the destination at every upstream site.
How it was measured
Not by reading. Upstream 3.5.0 and
oc-rsyncwere both cross-built foraarch64-linux-muslwithzig ccand run as root in a Linux VM, on a tmpfsmount, with the destination a loop device over a 64 KiB backing file — so the bytes
that reach the device are readable back and "written through" is an observation, not
an inference.
Negative controls that agreed before and still agree:
--write-deviceskeeps andwrites the node across plain/
-a/--checksum/--update/--whole-file/--no-whole-file/recursive/empty-source;--ignore-existingand--dry-runleaveit standing;
--existingreplaces it; regular destinations untouched; a devicesource is unaffected across
-D,--copy-devicesand--write-devices;--write-devices --partial-dirstill exits 1 with upstream's text.Mutations
false(the pre-fix shape)--write-devices--ignore-existingordering guard droppedignore_existing_leaves_a_device_destination_alonestatret = -1reset droppeda_replaced_device_destination_itemizes_as_a_creationBoth predicate mutations are killed unprivileged on macOS too, by the unit cells
plus the
/dev/nullcell — so ordinary CI is not blind to this, despite theoracle needing root.
Residuals — measured, not fixed, each needs its own decision
--inplaceover a FIFO destination hangs indefinitely (upstream: exit 0, nodereplaced). Same missing make-way decision, different disjunct; only the
FT_DEVICEhalf is in scope here. This is the most serious of the five.--write-devices --sparse: oc exits 23failed to truncate; upstream exits 11write failed on %sfromsparse_end(), whose own ftruncate is deliberatelynot
IS_DEVICE-gated. Exit-code mapping, not the predicate.--write-devices --preallocate: oc 23, upstream 0 —receiver.c:476's(!inplace_sizing || total_size > size_r)uses the device's real size fromgenerator.c:2226 get_device_size(), which local copy has no analogue of; and afailing
do_fallocateis onlyFWARNINGupstream.--write-devicesinto a device the caller does not own: oc 23failed to apply dest_mode, upstream 0 — it skips thechmodwhen the bits already match. Aregular-file control shows the mode value itself is correct.
--write-devices --backup: upstream's backup of the kept device is a regular fileholding the pre-image; oc hard-links the node.
Gates (pinned 1.88.0)
check_rustfmt_all.pyclean;clippy -p engine -p core -p bin --all-targets --no-deps -D warningsclean;nextest -p engine --all-features5125 passed,-p core2851,-p transfer2938; the device/obstacle/backup subset 66 passed.7/7 of the new tests green as root, and 7/7 unprivileged on macOS.
Not run: interop, the upstream testsuite legs, Windows, musl. The Linux binary used
for the oracle was built without the
aclfeature (nolibaclin the zig sysroot),so no cell exercised ACLs. No expect-manifest is touched.