Skip to content

sender: support exact-size local FIFO transfers on Linux - #1150

Merged
steadytao merged 7 commits into
RsyncProject:masterfrom
seks99x:feat/stream-source
Dec 4, 2026
Merged

steadytao merged 7 commits into
RsyncProject:masterfrom
seks99x:feat/stream-source

Conversation

@seks99x

@seks99x seks99x commented Nov 6, 2026 •

Copy link
Copy Markdown
Member

Summary

Copy one local Linux FIFO into a regular file with --stream-source --stream-size=SIZE. Require exactly SIZE bytes, EOF and successful verification before replacing the destination. Short input, excess input and timeouts leave the existing file unchanged. Remote and in-place transfers are not supported.

Enable rsync to read directly from a local named pipe (FIFO) or unseekable
stream and perform full rolling-checksum delta transfers against an existing
destination basis file without staging to temporary storage or changing the
wire protocol.

Key changes:
- Add --stream-source, --stream-max-size=SIZE, --stream-timeout=SECONDS,
  and --stream-pipe-sz=SIZE CLI options to options.c, usage.c, and rsync.1.md.
- Disguise the local FIFO source as S_IFREG with st_size = stream_max_size
  in make_file() (flist.c) so the receiver/generator negotiates normal
  basis checksums (s->sums) without protocol modifications.
- Implement sequential stream windowing in map_file() and map_ptr()
  (fileio.c): disallow backward seeks (read_start != map->p_fd_offset),
  multiplex reads with select() to enforce stream_timeout, clamp
  map->file_size dynamically on early EOF (n == 0), and optionally resize
  the kernel pipe ring buffer via F_SETPIPE_SZ on Linux.
- Update match_sums() and hash_search() (match.c) to pre-read stream
  data when s->count == 0 (missing/empty basis file) and safely clamp the
  sliding window and tail flush upon early EOF.
- Verify true EOF in send_files() (sender.c) via a non-blocking read probe
  when a stream reaches stream_max_size, aborting with IOERR_GENERAL on
  overflow, and reconcile F_LENGTH(file) and stats.total_size to the actual
  bytes read before progress and transfer logging.
- Ensure receive_data() (receiver.c) calls do_ftruncate(fd, offset) in
  --inplace mode when an early-EOF stream ends shorter than the basis file.
- Block incompatible options (-r, -a, -d, -c, --append, --files-from,
  --remove-source-files, batch mode) and file-size-dependent options
  (--size-only, --max-size, --min-size, --fuzzy, --preallocate),
  while enforcing ignore_times = 1 and clearing update_only, preserve_links,
  preserve_specials, and preserve_devices.
- Add Python test suites (stream-source_test.py and stream-early-eof_test.py)
  covering delta matching, --inplace truncation, early EOF, exact ceiling,
  ceiling overflow, idle timeout, and option validation.
@seks99x

seks99x commented Nov 6, 2026

Copy link
Copy Markdown
Member Author

I think XNU/NetBSD would require extra/different pipe handling for EOF. Will look into that.

…ld warning

On macOS (XNU) and NetBSD, named FIFOs clear their EOF socket state (SBS_CANTRCVMORE) after a 0-byte read() is consumed so the FIFO can be reused by future writers. If map_ptr() is called again before the caller clamps its length to the shrunk buf->file_size, a subsequent select() on the FIFO sees zero writers and no EOF flag, blocking until stream_timeout expires.

Track stream EOF via eof_reached in fileio.c (reset in map_file()) so map_ptr() and send_files() never invoke select() or read() on the stream descriptor once a 0-byte read() has been observed. Also guard buf before dereferencing buf->file_size in match_sums() to silence a Clang scan-build null-dereference warning.
@seks99x
seks99x force-pushed the feat/stream-source branch from 0205d26 to 6504328 Compare November 6, 2026 22:45
Comment thread fileio.c Resolved
Comment thread sender.c Resolved
Comment thread options.c Resolved
Comment thread testsuite/stream-source_test.py Resolved
@steadytao steadytao changed the title Add --stream-source support for single-pass FIFO/pipe delta transfers options: add --stream-source FIFO transfers Nov 8, 2026
- Verify EOF or excess stream bytes in match_sums() before finalising the
  transfer checksum so streams exceeding --stream-max-size fail with
  RERR_FILEIO (exit code 11) without truncating or overwriting existing
  destination files, and stalled streams at the size boundary honour
  --stream-timeout via poll().
- Track --stream-timeout explicitly with OPT_STREAM_TIMEOUT instead of a
  -1 sentinel so negative values disable the timeout consistently with 0,
  matching the documented behaviour.
- Reject multiple source arguments in start_client() before opening any
  FIFO when --stream-source is active.
- Update rsync.1.md to document pre-finalisation abort behaviour on
  oversized streams and the single-source requirement.
- Expand stream-source_test.py to cover exact-ceiling transfers, oversized
  stream aborts preserving destination files, paused/stalled stream
  timeouts, and writerless multi-FIFO rejection in both argument orders.
@seks99x

seks99x commented Nov 10, 2026

Copy link
Copy Markdown
Member Author

I think XNU should have different handling with poll also.

@seks99x

seks99x commented Nov 10, 2026

Copy link
Copy Markdown
Member Author

@steadytao poll would introduce inconsistency and weird behavior with XNU due to how it handles EOF. I think I might fall back to select only in macOS and make bounds check for the fd number.

@seks99x

seks99x commented Nov 10, 2026

Copy link
Copy Markdown
Member Author

@steadytao Also, XNU supports expanding FD_SETSIZE (Linux do not) at compile time via _DARWIN_UNLIMITED_SELECT, I'll bump FD_SETSIZE in fileio.c alongside the select() fallback and bounds check so high file descriptors still work cleanly on macOS without dynamic allocations or complex handling.

- Fall back to select() under __APPLE__ in wait_stream_fd() because XNU's
  poll() fails to wake on FIFO EOF when the pipe buffer is empty, causing
  0-byte and exact-ceiling --stream-source transfers to time out on macOS.
- Enable _DARWIN_UNLIMITED_SELECT and expand FD_SETSIZE to 65536 before
  including headers in fileio.c alongside an explicit bounds check so
  high inherited file descriptors remain supported.
@seks99x seks99x added this to the 4.0.0 milestone Nov 16, 2026
@seks99x seks99x added the Enhancement New capability or intentional behaviour change label Nov 16, 2026

@steadytao steadytao left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs rebasing + testsuite consolidation. Please port the stream tests to the current harness and cover local copies, remote-shell and daemon pushes, interoperability with an older receiver and both normal and --inplace writes.

Also. The PR description still says an oversized stream is truncated successfully. Please update it to say that exceeding --stream-max-size fails the transfer.

Comment thread flist.c Resolved
Comment thread sender.c Resolved
@seks99x

seks99x commented Nov 21, 2026

Copy link
Copy Markdown
Member Author

Sorry for the delay just having some issues on the queue. Will be wrapping this up ASAP.

@steadytao steadytao changed the title options: add --stream-source FIFO transfers sender: support exact-size local FIFO transfers on Linux Nov 26, 2026
@steadytao steadytao added the Portability Affects behaviour on a supported operating system, architecture or toolchain label Nov 26, 2026
steadytao
steadytao previously approved these changes Dec 4, 2026
@steadytao
steadytao merged commit 60b2ccf into RsyncProject:master Dec 4, 2026
41 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Enhancement New capability or intentional behaviour change Portability Affects behaviour on a supported operating system, architecture or toolchain

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants