Skip to content

feat: wire --write-batch into SSH and daemon transfer paths - #3026

Merged
oferchen merged 15 commits into
masterfrom
feature/batch-remote-tee
Mar 27, 2026
Merged

oferchen merged 15 commits into
masterfrom
feature/batch-remote-tee

Conversation

@oferchen

Copy link
Copy Markdown
Owner

Summary

  • Wire --write-batch recording into SSH transfer path via multiplex-level taps (post-demux for reads, pre-mux for writes), matching upstream rsync's write_batch_monitor_in/write_batch_monitor_out in io.c
  • Wire --write-batch recording into daemon (rsync://) transfer path for both pull and push operations
  • Extract shared batch support (BatchContext, BatchWriteAdapter, build_batch_recording) into batch_support.rs to keep SSH and daemon paths DRY
  • Refactor ServerReader from enum to struct+inner for pending batch recorder propagation across Plain->Multiplex transitions
  • Add BatchRecording struct in transfer crate with on_setup_complete callback for deferred header writing after protocol negotiation
  • Delete dead tee.rs module (replaced by multiplex-level recording)

Design

Uses the Adapter Pattern (BatchWriteAdapter) to bridge BatchWriter::write_data() to std::io::Write, and a callback hook (on_setup_complete) to defer batch header writing until negotiated protocol values are available after setup_protocol().

Test plan

  • CI passes (fmt+clippy, nextest, all platforms)
  • Verify --write-batch produces valid batch files over SSH transfers
  • Verify --write-batch produces valid batch files over daemon transfers
  • Verify --read-batch can replay files written by --write-batch

@github-actions github-actions Bot added the enhancement New feature or request label Mar 27, 2026
@oferchen
oferchen force-pushed the feature/batch-remote-tee branch from 5c01347 to c133664 Compare March 27, 2026 17:52
…ecording

Record demuxed protocol bytes at the multiplex layer instead of raw I/O,
matching upstream rsync's write_batch_monitor_in/out taps in io.c.

- Add BatchRecording struct in transfer crate with on_setup_complete
  callback for deferred header writing after protocol negotiation
- Refactor ServerReader from enum to struct+inner for pending recorder
  propagation across Plain->Multiplex transitions
- Add batch_recorder field to MultiplexReader (post-demux) and
  MultiplexWriter (pre-mux) for correct protocol data capture
- Replace TeeReader/TeeWriter approach with BatchWriteAdapter bridging
  BatchWriter::write_data() to std::io::Write trait
- Delete dead tee.rs module
… batch support

Extract BatchContext, build_batch_context, build_batch_recording, and
BatchWriteAdapter from ssh_transfer.rs into a shared batch_support module.
Wire the batch recording through run_daemon_transfer -> run_pull_transfer
/ run_push_transfer -> run_server_with_handshake, enabling --write-batch
for rsync:// daemon connections.
Verify that batch recording correctly captures pre-mux data on the
writer side and post-demux data on the reader side. Includes roundtrip
test confirming both sides capture identical protocol bytes.
Add a fast path in execute_transfer() that attempts clonefile() before
falling back to the normal read/write copy pipeline. On APFS, this
creates an instant copy-on-write clone with zero I/O overhead.

Conditions: new file, whole-file mode, no inplace/partial/sparse/
compress/bandwidth-limiter/delay-updates/temp-dir/copy-dest-override.
On failure (cross-device, non-APFS), falls through to normal copy.

Also adds has_bandwidth_limiter() accessor to CopyContext.
Only caller is the APFS clonefile path which is macOS-only.
@oferchen
oferchen force-pushed the feature/batch-remote-tee branch 3 times, most recently from a27ee56 to 2e9d10f Compare March 27, 2026 18:56
@oferchen
oferchen force-pushed the feature/batch-remote-tee branch from 2e9d10f to 1e1e242 Compare March 27, 2026 19:10
Increase test payload from 256KB to 4MB so intermediate progress
updates are emitted even on fast systems. Remove timing-dependent
\r assertion - carriage returns depend on transfer speed.
The test created a new destination file (no pre-existing file) with source
mode 0o511. With typical umask 0o022, the resulting mode 0o511 & ~0o022 =
0o511 was unchanged, making the assert_ne!(mode & 0o666, 0o511 & 0o666)
always fail since both sides equal 0o400.

Fix: pre-create destination with known different permissions (0o620) and
use --ignore-times to force transfer. This matches the engine-level test
pattern and reliably verifies that --executability only toggles execute
bits while preserving the destination's non-execute bits.
@oferchen
oferchen force-pushed the feature/batch-remote-tee branch 4 times, most recently from 47f5007 to ccbda6e Compare March 27, 2026 20:11
clonefile() preserves source metadata verbatim. When metadata preservation
is disabled (--no-perms, --no-times), finalize_guard_and_metadata skips
corrections assuming open()-created defaults. This left cloned files with
source permissions and mtime instead of umask/current-time defaults.

Add normalize_cloned_metadata() to bridge the gap: after a successful
clonefile, reset permissions to source_mode & ~umask and mtime to current
time when the respective preservation flags are off. This makes the
clonefile path transparent - finalize_guard_and_metadata produces identical
results regardless of whether clonefile or read/write copy was used.

Also fix flaky tests that depended on specific umask/mtime behavior:
- executability test: use pre-existing destination with known permissions
- no_perms test: use 0o777 source mode so umask always makes a difference
- no_times test: use SystemTime::now() comparison instead of exact equality
@oferchen
oferchen force-pushed the feature/batch-remote-tee branch from ccbda6e to e791a16 Compare March 27, 2026 20:21
clonefile() preserves source permissions verbatim, so a source with
mode 0o444 produces a read-only destination. The previous approach
of opening the file with write access to call set_modified() fails
with PermissionDenied on such files.

Switch to rustix::fs::utimensat() with UTIME_NOW, which operates on
the path via syscall and does not require write access to the file.
This matches the ownership-based permission model of utimensat(2).
clonefile() copies all xattrs from the source verbatim. When xattr
filter rules are configured to exclude specific attributes, the
clonefile fast path bypasses the selective xattr copy logic in
finalize_guard_and_metadata. Fall back to the standard read/write
path so that xattr filtering is applied correctly.
normalize_cloned_metadata used source_mode & 0o7777 which preserves
setuid/setgid/sticky bits. When open() creates files, special bits
are never set - only standard permission bits are applied with umask.
Mask to 0o777 to match open() semantics and also skip clonefile when
xattr filter rules are active since clonefile copies all xattrs
verbatim, preventing selective filtering.
Refactor clonefile conditions into a single clonefile_eligible block
that centralizes all safety checks. Add xattr_ok guard that requires
xattrs_enabled when the xattr feature is active - clonefile copies
all xattrs verbatim, so it must be skipped when xattrs should not
appear on the destination (xattrs disabled) or when selective xattr
filtering is needed (xattr filter rules active).
@oferchen
oferchen merged commit 333a1a5 into master Mar 27, 2026
55 of 56 checks passed
@oferchen
oferchen deleted the feature/batch-remote-tee branch March 28, 2026 06:20
oferchen added a commit that referenced this pull request May 1, 2026
* feat: wire --write-batch into SSH transfer path via multiplex-level recording

Record demuxed protocol bytes at the multiplex layer instead of raw I/O,
matching upstream rsync's write_batch_monitor_in/out taps in io.c.

- Add BatchRecording struct in transfer crate with on_setup_complete
  callback for deferred header writing after protocol negotiation
- Refactor ServerReader from enum to struct+inner for pending recorder
  propagation across Plain->Multiplex transitions
- Add batch_recorder field to MultiplexReader (post-demux) and
  MultiplexWriter (pre-mux) for correct protocol data capture
- Replace TeeReader/TeeWriter approach with BatchWriteAdapter bridging
  BatchWriter::write_data() to std::io::Write trait
- Delete dead tee.rs module

* feat: wire --write-batch into daemon transfer path and extract shared batch support

Extract BatchContext, build_batch_context, build_batch_recording, and
BatchWriteAdapter from ssh_transfer.rs into a shared batch_support module.
Wire the batch recording through run_daemon_transfer -> run_pull_transfer
/ run_push_transfer -> run_server_with_handshake, enabling --write-batch
for rsync:// daemon connections.

* test: add batch recorder tests for multiplex writer and reader

Verify that batch recording correctly captures pre-mux data on the
writer side and post-demux data on the reader side. Includes roundtrip
test confirming both sides capture identical protocol bytes.

* feat: wire macOS clonefile into transfer hot path

Add a fast path in execute_transfer() that attempts clonefile() before
falling back to the normal read/write copy pipeline. On APFS, this
creates an instant copy-on-write clone with zero I/O overhead.

Conditions: new file, whole-file mode, no inplace/partial/sparse/
compress/bandwidth-limiter/delay-updates/temp-dir/copy-dest-override.
On failure (cross-device, non-APFS), falls through to normal copy.

Also adds has_bandwidth_limiter() accessor to CopyContext.

* fix: gate has_bandwidth_limiter behind cfg(target_os = "macos")

Only caller is the APFS clonefile path which is macOS-only.

* fix: correct MultiplexWriter import path in reader tests

* fix: eliminate flaky progress test on fast macOS CI runners

Increase test payload from 256KB to 4MB so intermediate progress
updates are emitted even on fast systems. Remove timing-dependent
\r assertion - carriage returns depend on transfer speed.

* fix: correct flaky executability test that depended on umask behavior

The test created a new destination file (no pre-existing file) with source
mode 0o511. With typical umask 0o022, the resulting mode 0o511 & ~0o022 =
0o511 was unchanged, making the assert_ne!(mode & 0o666, 0o511 & 0o666)
always fail since both sides equal 0o400.

Fix: pre-create destination with known different permissions (0o620) and
use --ignore-times to force transfer. This matches the engine-level test
pattern and reliably verifies that --executability only toggles execute
bits while preserving the destination's non-execute bits.

* style: fix rustfmt formatting in executability test

* fix: normalize cloned metadata for seamless clonefile integration

clonefile() preserves source metadata verbatim. When metadata preservation
is disabled (--no-perms, --no-times), finalize_guard_and_metadata skips
corrections assuming open()-created defaults. This left cloned files with
source permissions and mtime instead of umask/current-time defaults.

Add normalize_cloned_metadata() to bridge the gap: after a successful
clonefile, reset permissions to source_mode & ~umask and mtime to current
time when the respective preservation flags are off. This makes the
clonefile path transparent - finalize_guard_and_metadata produces identical
results regardless of whether clonefile or read/write copy was used.

Also fix flaky tests that depended on specific umask/mtime behavior:
- executability test: use pre-existing destination with known permissions
- no_perms test: use 0o777 source mode so umask always makes a difference
- no_times test: use SystemTime::now() comparison instead of exact equality

* fix: use utimensat for mtime reset on read-only cloned files

clonefile() preserves source permissions verbatim, so a source with
mode 0o444 produces a read-only destination. The previous approach
of opening the file with write access to call set_modified() fails
with PermissionDenied on such files.

Switch to rustix::fs::utimensat() with UTIME_NOW, which operates on
the path via syscall and does not require write access to the file.
This matches the ownership-based permission model of utimensat(2).

* style: fix rustfmt formatting in utimensat call

* fix: skip clonefile when xattr filter rules are active

clonefile() copies all xattrs from the source verbatim. When xattr
filter rules are configured to exclude specific attributes, the
clonefile fast path bypasses the selective xattr copy logic in
finalize_guard_and_metadata. Fall back to the standard read/write
path so that xattr filtering is applied correctly.

* fix: strip special bits in clonefile metadata normalization

normalize_cloned_metadata used source_mode & 0o7777 which preserves
setuid/setgid/sticky bits. When open() creates files, special bits
are never set - only standard permission bits are applied with umask.
Mask to 0o777 to match open() semantics and also skip clonefile when
xattr filter rules are active since clonefile copies all xattrs
verbatim, preventing selective filtering.

* fix: centralize clonefile eligibility with xattr guard

Refactor clonefile conditions into a single clonefile_eligible block
that centralizes all safety checks. Add xattr_ok guard that requires
xattrs_enabled when the xattr feature is active - clonefile copies
all xattrs verbatim, so it must be skipped when xattrs should not
appear on the destination (xattrs disabled) or when selective xattr
filtering is needed (xattr filter rules active).
oferchen added a commit that referenced this pull request May 5, 2026
* feat: wire --write-batch into SSH transfer path via multiplex-level recording

Record demuxed protocol bytes at the multiplex layer instead of raw I/O,
matching upstream rsync's write_batch_monitor_in/out taps in io.c.

- Add BatchRecording struct in transfer crate with on_setup_complete
  callback for deferred header writing after protocol negotiation
- Refactor ServerReader from enum to struct+inner for pending recorder
  propagation across Plain->Multiplex transitions
- Add batch_recorder field to MultiplexReader (post-demux) and
  MultiplexWriter (pre-mux) for correct protocol data capture
- Replace TeeReader/TeeWriter approach with BatchWriteAdapter bridging
  BatchWriter::write_data() to std::io::Write trait
- Delete dead tee.rs module

* feat: wire --write-batch into daemon transfer path and extract shared batch support

Extract BatchContext, build_batch_context, build_batch_recording, and
BatchWriteAdapter from ssh_transfer.rs into a shared batch_support module.
Wire the batch recording through run_daemon_transfer -> run_pull_transfer
/ run_push_transfer -> run_server_with_handshake, enabling --write-batch
for rsync:// daemon connections.

* test: add batch recorder tests for multiplex writer and reader

Verify that batch recording correctly captures pre-mux data on the
writer side and post-demux data on the reader side. Includes roundtrip
test confirming both sides capture identical protocol bytes.

* feat: wire macOS clonefile into transfer hot path

Add a fast path in execute_transfer() that attempts clonefile() before
falling back to the normal read/write copy pipeline. On APFS, this
creates an instant copy-on-write clone with zero I/O overhead.

Conditions: new file, whole-file mode, no inplace/partial/sparse/
compress/bandwidth-limiter/delay-updates/temp-dir/copy-dest-override.
On failure (cross-device, non-APFS), falls through to normal copy.

Also adds has_bandwidth_limiter() accessor to CopyContext.

* fix: gate has_bandwidth_limiter behind cfg(target_os = "macos")

Only caller is the APFS clonefile path which is macOS-only.

* fix: correct MultiplexWriter import path in reader tests

* fix: eliminate flaky progress test on fast macOS CI runners

Increase test payload from 256KB to 4MB so intermediate progress
updates are emitted even on fast systems. Remove timing-dependent
\r assertion - carriage returns depend on transfer speed.

* fix: correct flaky executability test that depended on umask behavior

The test created a new destination file (no pre-existing file) with source
mode 0o511. With typical umask 0o022, the resulting mode 0o511 & ~0o022 =
0o511 was unchanged, making the assert_ne!(mode & 0o666, 0o511 & 0o666)
always fail since both sides equal 0o400.

Fix: pre-create destination with known different permissions (0o620) and
use --ignore-times to force transfer. This matches the engine-level test
pattern and reliably verifies that --executability only toggles execute
bits while preserving the destination's non-execute bits.

* style: fix rustfmt formatting in executability test

* fix: normalize cloned metadata for seamless clonefile integration

clonefile() preserves source metadata verbatim. When metadata preservation
is disabled (--no-perms, --no-times), finalize_guard_and_metadata skips
corrections assuming open()-created defaults. This left cloned files with
source permissions and mtime instead of umask/current-time defaults.

Add normalize_cloned_metadata() to bridge the gap: after a successful
clonefile, reset permissions to source_mode & ~umask and mtime to current
time when the respective preservation flags are off. This makes the
clonefile path transparent - finalize_guard_and_metadata produces identical
results regardless of whether clonefile or read/write copy was used.

Also fix flaky tests that depended on specific umask/mtime behavior:
- executability test: use pre-existing destination with known permissions
- no_perms test: use 0o777 source mode so umask always makes a difference
- no_times test: use SystemTime::now() comparison instead of exact equality

* fix: use utimensat for mtime reset on read-only cloned files

clonefile() preserves source permissions verbatim, so a source with
mode 0o444 produces a read-only destination. The previous approach
of opening the file with write access to call set_modified() fails
with PermissionDenied on such files.

Switch to rustix::fs::utimensat() with UTIME_NOW, which operates on
the path via syscall and does not require write access to the file.
This matches the ownership-based permission model of utimensat(2).

* style: fix rustfmt formatting in utimensat call

* fix: skip clonefile when xattr filter rules are active

clonefile() copies all xattrs from the source verbatim. When xattr
filter rules are configured to exclude specific attributes, the
clonefile fast path bypasses the selective xattr copy logic in
finalize_guard_and_metadata. Fall back to the standard read/write
path so that xattr filtering is applied correctly.

* fix: strip special bits in clonefile metadata normalization

normalize_cloned_metadata used source_mode & 0o7777 which preserves
setuid/setgid/sticky bits. When open() creates files, special bits
are never set - only standard permission bits are applied with umask.
Mask to 0o777 to match open() semantics and also skip clonefile when
xattr filter rules are active since clonefile copies all xattrs
verbatim, preventing selective filtering.

* fix: centralize clonefile eligibility with xattr guard

Refactor clonefile conditions into a single clonefile_eligible block
that centralizes all safety checks. Add xattr_ok guard that requires
xattrs_enabled when the xattr feature is active - clonefile copies
all xattrs verbatim, so it must be skipped when xattrs should not
appear on the destination (xattrs disabled) or when selective xattr
filtering is needed (xattr filter rules active).
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