Skip to content

feat(receiver): stage a --partial-dir resume in place - #7599

Merged
oferchen merged 4 commits into
masterfrom
feat/one-inplace-partial-dir-staging
Sep 2, 2026
Merged

oferchen merged 4 commits into
masterfrom
feat/one-inplace-partial-dir-staging

Conversation

@oferchen

@oferchen oferchen commented Sep 1, 2026 •

Copy link
Copy Markdown
Owner

What

Mirrors upstream's one_inplace in the local-copy receiver: when a --partial-dir entry for a file already exists as a regular file, the reconstruction is written into that entry and the entry is renamed onto the destination on commit.

rsync-3.5.0/receiver.c:1195-1196:

if (inplace || one_inplace)  {
        fnametmp = one_inplace ? partialptr : fname;

The in-place target under one_inplace is partialptr - the file inside the partial dir - never the live destination. receiver.c:1137-1138 gates it (inplace_partial && fnamecmp_type == FNAMECMP_PARTIAL_DIR && fd1 != -1), receiver.c:1204-1224 opens it through the three-arm chain with one_inplace threaded into every arm, and receiver.c:1288-1299 renames it onto the destination and then removes the emptied partial dir - without unlinking the entry, because finish_transfer() already renamed it away.

Before this, oc reconstructed into a temp beside the destination and deleted the partial entry afterwards, so pdir/<name> was never opened at all.

Measured end to end on aarch64 Linux - an ordinary --partial-dir transfer, nothing refusing anything, 90000-byte stale partial replaced by a 40960-byte source:

openat(<mod>, "pdir", O_RDONLY|O_NOFOLLOW|O_CLOEXEC|O_PATH|O_DIRECTORY) = 5
openat(5, "victim", O_WRONLY|O_CREAT|O_TRUNC|O_NOFOLLOW|O_CLOEXEC, 0600) = 3
renameat(<pdir>, "victim", <mod>, "victim")                             = 0
unlinkat(AT_FDCWD, "<mod>/pdir", AT_REMOVEDIR)                          = 0

rc=0, destination byte-identical to the source, no unlink of the entry.

OperatorWalk gets its first production call site

fast_io::InplaceResolution::OperatorWalk and the three-arm open_inplace_output chain were already ported and correct, but OperatorWalk was constructed at zero production sites - all 10 occurrences repo-wide were in fast_io's own unit tests. DestinationWriteGuard::new_one_inplace is its first. No parallel resolver was written.

The ownership walk now issues its syscalls through libc

fast_io::owner_walk used rustix, whose linux_raw backend issues the syscall instruction directly and bypasses libc. Upstream's walk is plain C against libc (syscall.c:469), so an interposition layer an operator has in place - fakeroot, an audit or sandbox preload - sees upstream's resolution and did not see oc's. Measured, driving --exclude-from through the walk:

syscall strace LD_PRELOAD openat shim
openat(3, "cfg", …O_PATH|O_DIRECTORY) seen not seen
openat(4, "excl", …) seen not seen

The walk now routes onto fast_io's own libc-backed *at primitives (at_syscalls::openat / fstatat_nofollow / readlinkat), which the crate already owns and audits. Same syscalls, same flags (O_LARGEFILE is re-added explicitly on Linux because rustix added it), same checks - the resolver logic is untouched. This is the same class as the am_root/fakeroot divergence: a raw syscall answers a different question than upstream's libc call in an interposed process.

The doc comment that argued the opposite

resolve_use_inplace's comment argued the wire receiver's exclusion on data-integrity grounds - that taking the in-place path for a --partial-dir resume "would write the reconstruction directly to the live destination and leave a full-size but incomplete file there on interrupt". That read upstream's in-place target as fname; it is partialptr, so the hazard it described was a property of oc's implementation, not of upstream's design. The comment now states the real reason - this receiver has no partial-dir output mode to write into - and records that the suppression is unreachable today anyway, because --inplace and --partial-dir are rejected together during config validation. The parity test's comment is corrected to match, and a stale cleanup.c:105-115 citation is retargeted to the handle_partial_dir() call at cleanup.c:169-170.

Testsuite

tools/ci/upstream-3.5.0-expect.{nonroot,root}.txt: partial-protected-regular-retry-linux fail → pass, measured on both legs.

The cell builds an LD_PRELOAD shim that synthesises the EACCES an fs.protected_regular kernel raises on the O_CREAT open of the partial entry, swaps the partial dir for a foreign-owned symlink inside that window, and checks the retry keeps the ownership walk.

Two independent causes, each proven by reverting it alone and rebuilding - the cell reddens with the original receiver did not open the existing partial file with O_CREAT:

mutation cell
one_inplace_partial_file forced to None (staging reverted, walk kept) FAIL
walk_openat reverted to rustix::fs::openat (walk backend reverted, staging kept) FAIL
neither PASS

Upstream 3.5.0 itself passes the cell on the same host; that was the control run.

Full 3.5.0 suite against the manifests on that host: nonroot 254 pass / 5 fail / 86 skip, root 281 / 7 / 57. Expected-result mismatches: simd-checksum skips on aarch64 in both legs (no x86 SIMD), and the root leg's batch-file-symlink failed once during a run with the host at 98% disk and three other builds active - it passes 3/3 in isolation there.

Non-vacuity companions

New engine tests: an ordinary --partial-dir transfer stays byte-correct with and without a delta pass and clears the partial dir; the committed destination wears the inode the partial entry had (a rename, not a fresh temp - this one fails on the old behaviour); a symlink at the partial leaf is refused as a staging target (link_stat + S_ISREG, generator.c:2173-2179) and its target is untouched; and select_write_strategy returns InplacePartialDir only when the gate is on.

Known remaining gap

The local --partial-dir leaf is now a one_inplace staging target but is still not a delta basis: upstream's generator also sets fnamecmp = partialptr (generator.c:2270-2273) and lets a final ftruncate size the result, whereas this executor still picks its basis from the destination or a --fuzzy candidate only. Because nothing reads the entry back, it is opened O_TRUNC where upstream does not - stated in full at the call site so the compensating half is visible. The wire receiver has neither half; resolve_use_inplace's comment now says so.

One deliberate departure from upstream's precedence

--append keeps its own strategy even when a partial-dir entry exists, where upstream's ternary would pick partialptr. Upstream's append seek (receiver.c:372-373) takes its offset from sx.st, which the generator has already replaced with partial_st (generator.c:2271) - the partial file's length. This executor derives append_offset from the destination's length, which is not the file one_inplace writes into, so honouring it there would seek to the wrong offset in the wrong file. --append and --partial-dir are rejected together through the CLI anyway. Stated at the selector, with a unit test.

@oferchen
oferchen force-pushed the feat/one-inplace-partial-dir-staging branch 3 times, most recently from 27aab00 to 6b3c998 Compare September 1, 2026 11:53
Mirror upstream's `one_inplace`: when a `--partial-dir` entry for a file
already exists as a regular file, the local-copy executor now writes the
reconstruction straight into that entry and renames it onto the
destination on commit, instead of building a separate temp beside the
destination and deleting the partial entry afterwards.

receiver.c:1195-1196 is the shape being mirrored:

    if (inplace || one_inplace)  {
            fnametmp = one_inplace ? partialptr : fname;

The in-place target is `partialptr`, the file inside the partial dir -
never the live destination. The entry is opened through fast_io's
three-arm chain (`O_WRONLY|O_CREAT`, the Linux `protected_regular` retry
without `O_CREAT`, then the read-only-destination arm) with
`InplaceResolution::OperatorWalk`, which is upstream's `one_inplace`
argument to `secure_recv_open()` at every arm: the partial dir is an
operator-supplied path, so each component is walked and a foreign-owned
symlink is refused. `OperatorWalk` had been implemented and left with no
production construction site; this is its first one.

Measured end to end on aarch64 Linux, an ordinary `--partial-dir`
transfer with nothing refusing anything:

    openat(<mod>, "pdir", O_PATH|O_DIRECTORY|O_NOFOLLOW)      = 5
    openat(5, "victim", O_WRONLY|O_CREAT|O_TRUNC|O_NOFOLLOW, 0600)
    renameat(<pdir>, "victim", <mod>, "victim")               = 0
    unlinkat(AT_FDCWD, "<mod>/pdir", AT_REMOVEDIR)            = 0

rc 0, destination byte-identical to the source, no unlink of the entry
(upstream skips it under `one_inplace`, receiver.c:1291).

The ownership walk now issues its `openat`/`fstatat`/`readlinkat` through
fast_io's own libc-backed `*at` primitives rather than rustix, whose
`linux_raw` backend issues the syscall instruction directly. Upstream's
walk is plain C against libc (syscall.c:469), so an interposition layer
an operator has in place sees upstream's resolution; it did not see oc's.
Measured, driving `--exclude-from` through the walk: both component opens
appear under strace and neither appears to an LD_PRELOAD `openat` shim.
`O_LARGEFILE` is added explicitly on Linux because rustix added it, so
the emitted flag word is unchanged.

`resolve_use_inplace`'s comment argued the wire receiver's exclusion on
data-integrity grounds - that taking the in-place path would leave a
full-size incomplete file at the live destination. That reasoning read
upstream's in-place target as `fname`; it is `partialptr`. The comment
now states the real reason: this receiver has no partial-dir output mode
to write into, and the suppression is unreachable anyway because
`--inplace` and `--partial-dir` are rejected together.

Flips `partial-protected-regular-retry-linux` to pass in both 3.5.0
expect manifests. Upstream 3.5.0 passes the cell; oc failed at its
positive control. Two independent causes, each proven by reverting it
alone and watching the cell redden with the original message:

  - the missing staging (no O_CREAT open of the partial entry at all);
  - the rustix backend (the walk's opens invisible to the cell's shim,
    which is how it models `fs.protected_regular`).

Full 3.5.0 suite against the manifests on that host: nonroot 254 pass /
5 fail / 86 skip, root 281/7/57. The only mismatch attributable to the
run rather than the host is none - `simd-checksum` skips on aarch64 in
both legs, and the root leg's `batch-file-symlink` passes 3/3 in
isolation (that run had the host at 98% disk).

Known remaining gap, unchanged: the local `--partial-dir` leaf is now a
staging target but still not a delta basis (generator.c:2270-2273), so
the entry is opened `O_TRUNC` where upstream relies on a final
`ftruncate`. Stated at the call site.

Append keeps precedence over the new strategy even though upstream's
ternary would not: this executor derives `append_offset` from the
destination's length, while upstream's comes from `sx.st` after the
generator replaced it with `partial_st` (generator.c:2271) - the partial
file's length. Honouring it here would seek to the wrong offset in the
wrong file. Stated at the selector, with a unit test.
@oferchen
oferchen force-pushed the feat/one-inplace-partial-dir-staging branch from 6b3c998 to 3a491ff Compare September 1, 2026 11:59
@github-actions github-actions Bot added the enhancement New feature or request label Sep 1, 2026
clippy fires useless_conversion on u32::from(mode.bits()) because
rustix's RawMode is already u32 on Linux. The conversion is not
redundant on macOS, where mode_t is u16, so taking clippy's
suggestion breaks that build.

Neither spelling is clean on both targets - .. as u32 trips
unnecessary_cast on Linux for the same reason - so the widening
is kept and the lint allowed at the one site, matching the
unused_mut allow the same function already carries for its
cfg-conditional O_LARGEFILE.
…est sites

`fmt + clippy` failed with four instances of

    error[E0061]: this function takes 8 arguments but 7 arguments were supplied

`select_write_strategy` gained `one_inplace_partial_dir` as its seventh
parameter in this branch. Two call sites in the test module were updated;
the four inside `#[cfg(target_os = "linux")]` blocks were not, so a macOS
build cannot see them and every Linux cell fails to compile the lib test.

All four assert O_TMPFILE/anonymous strategy selection, which is
orthogonal to the one_inplace staging gate, so they pass `false` — the
same value the shared `strategy()` helper already passes.

Verified by compiling the Linux-gated blocks on macOS: the four cfgs were
temporarily made unconditional, `cargo check -p engine --tests` reported
zero errors, and reverting one call site to seven arguments reproduced
E0061 exactly. The cfgs are restored to `target_os = "linux"`.
@oferchen
oferchen merged commit d3104fc into master Sep 2, 2026
72 checks passed
@oferchen
oferchen deleted the feat/one-inplace-partial-dir-staging branch September 2, 2026 08:00
oferchen added a commit that referenced this pull request Sep 2, 2026
…e tree (#7626)

An accuracy audit of every performance, coverage and security claim in
README.md and SECURITY.md against a workflow file, a committed manifest, a
test or a measured number. Most of the 3.5.0 alignment already checked out;
what follows is what did not.

Stale testsuite outcomes. Both files carried 254/6 and 282/7 for the two
full-corpus legs, "7 of 345 tests currently diverge", and "32 across all
four". The committed manifests say 257/3 and 286/3, with 3 distinct
divergences on the pipe legs and 29 across all four; #7596, #7598 and #7599
each fixed a divergence and flipped its manifest rows without refreshing the
prose. Re-derived with the awk one-liner both files already publish.

An unmeasured measurement. Both files said "a measured run of 100,000
sessions consumed a single bgid" as the evidence that the u16 bgid namespace
cannot be exhausted. No such run exists in the tree, and it could not: per
docs/audits/bgid-lifecycle.md section 5, BufferRing and BgidAllocator are
constructed only inside fast_io and its tests, so an accepted connection
consumes no bgid at all. The conclusion holds; the evidence for it is now the
structural fact rather than an invented number.

A benchmark shape no published release carries. The Performance section
described the dual-baseline, peak-RSS, corpus-rate, spread-carrying report as
what is "attached to every GitHub release", and the image alt text named both
baselines. The linked image is served from the latest release, v0.6.4, whose
benchmark_results.json has one baseline (3.4.4), a 148 MB corpus, and only
mean/min/max per series. The paragraph now describes the harness and says
plainly which releases predate it.

MAX_WIRE_DEL_STAT. SECURITY cited crates/protocol/src/flist/delete_stats.rs,
which does not exist, and claimed a cap "well below the upstream lowered
ceiling". The reader is crates/protocol/src/stats/delete.rs and its cap is
1 << 28 - exactly upstream's rsync.h:187 value, unchanged in 3.4.4 and 3.5.0 -
and it rejects rather than clamps. Parity is the right answer; "well below"
was not.

Landlock framing. README presented the daemon's Landlock layer as "cargo
feature landlock", which reads as opt-in. crates/daemon pins fast_io with
that feature under cfg(target_os = "linux"), so it is on in every Linux build
including the released binaries. SECURITY's ABI enumeration stopped at v3
while the helper requests AccessFs::from_all(ABI::V5).

Benchmark report: publish the sample size. stats() records `runs` with the
stated intent that "a reader can tell a three-run cell from a six-run one",
but the report left it in the JSON. A reset cell is timed 3 times with the
warm-up discarded, so its median rests on 2 samples, and it rendered
identically to a 6-run cell's median over 5. One `Runs` column per row states
it - compare() hands every series in a row the same count - and the footnote
now names which population the median and the spread each describe.

benchmark_chart.py's no-baselines fallback said "3.4.4" while
benchmark_report.py's said "3.5.0"; two renderers of one file would have
named different upstream releases for the same run.

Verified and left alone: the 33-CVE count, the five new options and three new
daemon directives, the 13 Aug 2026 date, PROTOCOL_VERSION 32 /
SUBPROTOCOL_VERSION 0 and byte-identical errcode.h (checked against the
pinned 3.5.0 source); the 345/155 corpus sizes and the two tcp manifest rows;
the interop version lists against run_interop.sh; the 26 fuzz targets against
fuzz/Cargo.toml, name for name; the empty known-failures roster already
described as historical; daemon-seccomp absent from the default set and from
the release build; and every 3.4.4 mention that is deliberately about 3.4.4.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant