Repository navigation
sender: support exact-size local FIFO transfers on Linux - #1150
Conversation
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.
|
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.
0205d26 to
6504328
Compare
- 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.
|
I think XNU should have different handling with poll also. |
|
@steadytao poll would introduce inconsistency and weird behavior with XNU due to how it handles EOF. I think I might fall back to |
|
@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.
steadytao
left a comment
There was a problem hiding this comment.
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.
|
Sorry for the delay just having some issues on the queue. Will be wrapping this up ASAP. |
Summary
Copy one local Linux FIFO into a regular file with
--stream-source --stream-size=SIZE. Require exactlySIZEbytes, 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.