Skip to content

fix(batch): carry hardlinks through --write-batch and --read-batch - #7596

Merged
oferchen merged 1 commit into
masterfrom
fix/batch-hardlink-roundtrip
Sep 1, 2026
Merged

oferchen merged 1 commit into
masterfrom
fix/batch-hardlink-roundtrip

Conversation

@oferchen

@oferchen oferchen commented Sep 1, 2026 •

Copy link
Copy Markdown
Owner

Upstream testsuite cell batch-only-remove-source-regression fails on both
pipe legs (nonroot and root) with the retained batch did not reproduce the source hard link. Upstream rsync 3.5.0 passes it. Content was already
byte-correct; only the -H hardlink data was lost, and only on the batch path
(a plain -aH local transfer links correctly).

Two coupled defects

A cross matrix of writer x replayer, -aH --only-write-batch then
-aH --read-batch, on a source directory holding two names for one inode
(aarch64 Linux, upstream 3.5.0 built from the pinned tarball):

write replay before after
upstream upstream LINKED LINKED
upstream oc-rsync NOTLINKED, follower content stale LINKED
oc-rsync upstream NOTLINKED LINKED
oc-rsync oc-rsync NOTLINKED LINKED

Both directions failed, so both ends were wrong and fixing one would have left
the cell red.

Writer. build_protocol_file_entry() never set any hardlink identity on
the flist entry it built, so the encoded batch flist carried neither
XMIT_HLINKED nor a group index, and the payload was written once per cluster
member (the batch was 1878 bytes where upstream's was 1005 for the same tree).

Replay. batch::replay decoded the hardlink fields an upstream-written
batch does carry - FileListReader already resolves the abbreviated follower
entry - but nothing ever acted on them, so a cluster came back as unrelated
copies and the follower kept its pre-replay bytes.

The format, from upstream

Mirrored rather than invented; the citations are to the pinned 3.5.0 tree.

  • flist.c:1628-1635 make_file(): an entry is a cluster candidate when
    !S_ISDIR(st.st_mode) && st.st_nlink > 1 (protocol >= 28).
  • flist.c:599-625 send_file_entry(): idev_find(dev, ino) returns -1 for a
    first sighting, which records first_ndx + ndx and sets XMIT_HLINK_FIRST;
    every repeat becomes a follower. XMIT_HLINKED is set either way.
  • flist.c:668-672: a follower writes write_varint(first_hlink_ndx) right
    after the name and then goto the_end - no length, mtime, mode or ownership
    follows.
  • flist.c:741-753: below protocol 30 there is no index; the cluster is named
    by a trailing (dev, ino) pair instead.
  • flist.c:1335-1341 recv_file_entry(): F_HL_GNUM is stamped while the
    entry is still in wire order - the leader records its own index, a follower
    the one it was sent.
  • hlink.c:113-194 match_gnums(): clusters by that tag over the sorted
    list and marks the sorted-first member FLAG_HLINK_FIRST; generator.c
    routes every other member through hlink.c:300 hard_link_check(), which
    returns 1 (skip), so the payload is requested exactly once per cluster.
  • hlink.c:496-565 finish_hard_link(): the member that completes becomes the
    link source - "FIRST combined with DONE means we were the first to get done".

No divergence from that format. The one place this implementation has a choice
upstream does not is which member the replay treats as the link source: the
replay uses the member the batch actually fed rather than assuming the
sorted-first, which is the same rule finish_hard_link() applies and keeps a
batch written by either implementation replayable.

The fix

Writer (crates/engine): capture_batch_file_entry() groups candidates by
(st_dev, st_ino) in traversal order, stamping the first sighting with the
u32::MAX sentinel FileListWriter reads as XMIT_HLINK_FIRST and every
repeat with the leader's index (or the (dev, ino) pair below protocol 30).
flush_batch_delta_to_batch() then drops the duplicated payloads through the
traversal-to-sorted mapping it already builds, leaving one per cluster - the
sorted-first, as match_gnums() makes upstream do.

Replay (crates/batch): group tags are stamped in wire order before the sort
(and per segment under INC_RECURSE, where the tags live in that segment's NDX
space), the delta phase records which entries it wrote, and a pass after it
links each cluster to the member the batch fed. A member that already shares
the source's inode is left alone, matching hlink.c:224-256 maybe_hard_link().

Evidence

  • The cell passes on both legs with the fixed binary: nonroot PASS, and under
    sudo PASS.
  • Full 3.5.0 pipe suite, non-root: 254 passed, 5 failed, 86 skipped. All five
    failures (basis-xname-traversal, filter-merge-content-echo,
    partial-protected-regular-retry-linux, rrsync-backup-dir-inband-pivot,
    rrsync-merge-file-confine) are already recorded fail in the manifest, so
    nothing regressed.
  • Six sibling batch cells still pass (batch-mode, write-batch-quoting,
    write-batch-filter-injection, operator-path-write-batch,
    scanner-batch-flag-mismatch, hardlinks); batch-file-symlink still skips
    as non-root.
  • Mutation proof, writer half reverted (assign_batch_hlink_group forced to
    find no cluster): the two writer rows redden and only those -
    oc->upstream and oc->oc NOTLINKED, upstream->oc still LINKED - and the
    cell fails at the retained batch did not reproduce the source hard link,
    the original message.
  • Mutation proof, replay half reverted (link_hardlink_clusters disabled): the
    two replay rows redden and only those - upstream->oc and oc->oc
    NOTLINKED with stale follower content, oc->upstream still LINKED - and the
    cell fails at the retained batch did not install hard-linked payloads.
  • New regression test
    crates/engine/tests/only_write_batch_hard_links.rs covers a three-member
    cluster whose sorted-first member is not the one the walk reaches first, plus
    a same-content file that was never linked. Both mutations above kill it.

Manifests

batch-only-remove-source-regression flipped fail -> pass in
tools/ci/upstream-3.5.0-expect.nonroot.txt and .root.txt, in the same
commit as the fix.

A batch recorded by the local copy path described every hardlink cluster
member as an independent file: build_protocol_file_entry() never set the
hardlink identity, so the flist carried neither XMIT_HLINKED nor a group
index and the payload was repeated once per member. Replay had the
matching hole - it decoded the hardlink fields upstream sends but never
acted on them, so a cluster came back as unrelated copies.

Both ends are needed: a batch written by oc-rsync and replayed by
upstream rsync 3.5.0 lost the links because the writer said nothing, and
one written by upstream and replayed by oc-rsync lost them because the
reader ignored what it was told.

Writer: capture_batch_file_entry() now groups non-directories with
st_nlink > 1 by (st_dev, st_ino) in traversal order, marking the first
sighting XMIT_HLINK_FIRST and every repeat a follower carrying the
leader's index (flist.c:599-625, flist.c:668-672, flist.c:741-753 for the
pre-30 dev/ino form). flush_batch_delta_to_batch() then drops the
duplicated payloads, leaving one per cluster as hlink.c:113-194
match_gnums() and generator.c's hard_link_check() skip make upstream do.

Replay: gnums are stamped in wire order before the sort, matching
flist.c:1335-1341, and a pass after the delta phase links each cluster to
the member the batch actually fed - hlink.c:496-565 finish_hard_link()
picks the same file for the same reason.

Flips batch-only-remove-source-regression to ok in the 3.5.0 expect
manifests.
@oferchen
oferchen force-pushed the fix/batch-hardlink-roundtrip branch from e50f9b8 to ce74ca5 Compare September 1, 2026 10:05
@github-actions github-actions Bot added the bug Something isn't working label Sep 1, 2026
@oferchen
oferchen merged commit 079dd8e into master Sep 1, 2026
70 of 71 checks passed
@oferchen
oferchen deleted the fix/batch-hardlink-roundtrip branch September 1, 2026 17:11
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

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant