Skip to content

flist: order local LTFS reads by partition and block - #1001

Open
hugo-hur wants to merge 27 commits into
RsyncProject:masterfrom
hugo-hur:ltfs-aware
Open

hugo-hur wants to merge 27 commits into
RsyncProject:masterfrom
hugo-hur:ltfs-aware

Conversation

@hugo-hur

Copy link
Copy Markdown
Contributor

Motivation

I'm running several LTFS formatted LTO tapes for incremental backups. Backupping to tape has been working fine with rsync (using the --whole-file and -t options) but reading from the tape is basically impossible due to the reasons stated below.

Summary

Adds a --ltfs option that makes rsync read an LTFS-tape source in physical
block order
instead of name order, so a restore streams the tape forward in a
single pass instead of seeking back and forth ("shoe-shining").

On an LTFS volume, each file's metadata — name, size, mtime, and the block where
its data begins — lives in the volume index and is cheap to read. File content,
however, requires physically positioning the tape. rsync's normal name-sorted
traversal bears no relation to physical layout, so an unordered restore can take
many times longer than one forward pass.

What it does

  • The sender reads each file's starting block from the ltfs.startblock
    virtual xattr (also honoring a user.ltfs.startblock alias) and transmits it
    as a new optional 64-bit file-list extra.
  • The generator drives the transfer in ascending start-block order. Entries
    with no start block (directories, symlinks) sort first, which front-loads
    creation of the destination directory tree before the bulk data read.

Behavior & safeguards

--ltfs is opinionated about the things that would silently defeat it:

  • Implies --whole-file — a delta transfer would re-read the source off
    tape anyway.
  • Forces --no-inc-recursive — the complete file list is needed before a
    read order can be chosen.
  • Refuses --checksum — it would read every byte of every file off the tape
    just to decide what to transfer.
  • Implies --times (just like --archive) — the whole benefit is that the index
    serves size+mtime for free so unchanged files are skipped without reading
    content; that only holds across runs if mtimes are preserved. A later
    --no-times overrides it but emits a warning.

Compatibility / requirements

  • Reading the start block needs xattr support, so the feature is gated on
    SUPPORT_XATTRS: the file-list extra is only registered when xattrs are
    available, and a build without them refuses --ltfs (like --crtimes)
    rather than silently no-op'ing.
  • Over ssh, both ends must have this functionality (sender reads the start block, generator
    orders the reads); --ltfs is forwarded to the server side.
  • Only the read (restore) direction is affected.

Testing

  • New testsuite/ltfs_test.py exercises ordering on an ordinary filesystem via
    the user.ltfs.startblock alias: round-trip integrity, physical-block read
    order across subdirectories (directories handled first), the implied -t /
    --no-times warning, and that --checksum is refused. It skips cleanly when
    the build lacks xattr support or the platform/filesystem can't set a user.*
    xattr (e.g. Windows, where os.setxattr is absent).
  • Full suite green; builds warning-free both with and without
    --disable-xattr-support.
  • Validated against a real LTFS volume: --ltfs read three files
    whose start blocks ran opposite to name order in correct forward order
    (verified via strace on the drive), all MD5s matched the tape, and a second
    -t pass skipped every file from index metadata alone — zero content reads.

Not in scope (possible follow-ups)

  • Add partition check to sorting for special cases where small files are persisted in the LTFS index partition instead of data partition.

Comment thread rsync.1.md Resolved
Comment thread ltfs.c Resolved
@hugo-hur
hugo-hur force-pushed the ltfs-aware branch 2 times, most recently from 33f4f3e to a60b11c Compare June 13, 2026 15:16
@hugo-hur

Copy link
Copy Markdown
Contributor Author

Rebased on top of changes on the master branch

@hugo-hur
hugo-hur force-pushed the ltfs-aware branch 2 times, most recently from 235954f to 67ad361 Compare June 13, 2026 15:56
@mosesn292-hue

Copy link
Copy Markdown

hugo-hur:ltfs-aware

@hugo-hur
hugo-hur marked this pull request as draft June 13, 2026 16:34
@hugo-hur

Copy link
Copy Markdown
Contributor Author

Changed to draft for now as I found out some problems with testing I have to look at and test other things too locally (mainly compatibilities between rsync versions).

@hugo-hur

hugo-hur commented Jun 13, 2026 •

Copy link
Copy Markdown
Contributor Author

Now tests pass on Debian and Cygwin, should pass also elsewhere (famous last words). The --disable-ltfs flag also tested working for the configure. Added more test cases that are automatically skipped if built without support for this new feature.

@hugo-hur
hugo-hur marked this pull request as ready for review June 13, 2026 21:21
@hugo-hur

hugo-hur commented Jun 13, 2026 •

Copy link
Copy Markdown
Contributor Author

Also worth noting that currently Cygwin configure flags xattrs as linux style available. I'm not sure if that works as expected...

@hugo-hur

Copy link
Copy Markdown
Contributor Author

Rebased to master once more. Also added another pr #1007 for sha256 support for OpenSSL builds for possibly helping on the future --checksum functionalities.

@hugo-hur
hugo-hur requested review from tridge and varesa June 16, 2026 21:12
@hugo-hur
hugo-hur force-pushed the ltfs-aware branch 2 times, most recently from 8313559 to 195e436 Compare August 12, 2026 19:58
Introduce the machinery for tape-aware transfers without yet changing the
read order.  On an LTFS volume each file's metadata -- including the block
where its data begins -- lives in the volume index and is cheap to read,
while reading content requires physically positioning the tape.

Add a new ltfs.c module that reads a file's starting block from the
ltfs.startblock virtual xattr (also honoring a user.ltfs.startblock alias so
the feature can be exercised on an ordinary filesystem).  The sender records
that block into a new optional 64-bit file-list extra and transmits it, so
the generator -- which on a local copy is chdir'd into the destination and
cannot read the source xattrs itself -- receives each file's physical
position.

Wire up the --ltfs option: it allocates the extra, implies --whole-file (a
delta transfer would re-read the source off tape anyway), forces
--no-inc-recursive (the full list is needed before a read order can be
chosen), and refuses --checksum (which would read the whole tape just to
decide what to transfer).  The option is propagated to the server side so
both ends agree on the file-list extra layout.

Reading the start block requires xattr support, so the whole feature is
gated on SUPPORT_XATTRS: the file-list extra is only registered when xattrs
are available, and a build without them refuses --ltfs (like --crtimes and
friends) rather than silently accepting an inert option.
With the start block of every file now available on the generator side,
order the data-read phase by ascending block instead of by name when --ltfs
is in effect.  The drive then makes a single forward streaming pass rather
than seeking back and forth ("shoe-shining"), which on a real tape can cut a
restore from hours to one pass.

Entries with no start block (directories, symlinks, anything not on tape)
sort first in their original order, which conveniently front-loads creation
of the destination directory tree before the bulk data read begins.  A NULL
ordering (ltfs off, no metadata negotiated, or an empty range) falls back to
the natural low..high sweep.
Add the option summary line and a full description covering what LTFS
ordering does, the options it implies (--whole-file, --no-inc-recursive) and
refuses (--checksum), that the fast index metadata still drives the normal
size+mtime quick check, and that only the read (restore) direction is
optimized.
Exercise --ltfs on an ordinary filesystem via the user.ltfs.startblock alias,
assigning blocks that run opposite to name order.  The test verifies
round-trip integrity, that the itemized output (rsync's observable processing
order) comes out in physical block order across subdirectories with
directories handled first, and that --ltfs --checksum is refused.  Skips
cleanly when the build lacks xattr support or the scratch filesystem rejects
a user.* xattr.
--ltfs's value is that an LTFS source serves size and mtime from the tape
index for free, letting rsync's quick check skip unchanged files without
reading their content off the tape. That only works if the destination keeps
the source mtimes: without -t, every run sees a time mismatch and re-reads
the whole tape, defeating the purpose.

Process --ltfs in the option loop (via OPT_LTFS) and set preserve_mtimes
there, the same way --archive implies -t, so a later --no-times can still
override it in option order. When it is overridden, warn that unchanged
files can no longer be skipped, rather than silently doing the slow thing.

Found while testing against a real LTO-5 LTFS volume: a bare -r --ltfs left
current mtimes on the destination, so the next run wanted to re-read every
file.
Note in the manpage that --ltfs enables mtime preservation (like --archive)
so the index quick-check can skip unchanged files across runs, and that a
later --no-times overrides it with a warning.
Verify that --ltfs preserves source mtimes without an explicit -t (so an
immediate re-run finds nothing to transfer) and that an explicit --no-times
still runs but emits a warning.
Add SUPPORT_LTFS to rsync.h, defined whenever SUPPORT_XATTRS is present,
as a named compile-time capability for the feature.

Remove the parse_one_refuse_match() call that hard-refused --ltfs on
non-xattr builds.  Instead, move startblock_ndx allocation out of its
#ifdef SUPPORT_XATTRS guard so both sides of a connection always agree on
the file-list layout when ltfs_mode is on.  A server-side runtime check
(#ifndef SUPPORT_LTFS) aborts with "--ltfs is not supported on this
server" if the server lacks the capability.

This lets a client without extended attribute support accept --ltfs and
forward it to a remote server that does have SUPPORT_LTFS, while ensuring
a non-capable server fails loudly rather than silently.
The test exercises local-to-local copy ordering only; it does not test
remote flag forwarding. Rename testsuite/ltfs_test.py to
testsuite/ltfs-local_test.py, add a clarifying comment at the top of
the script, and update the RSYNC_EXPECT_SKIPPED list in both the macOS
and Cygwin CI workflows to match the new test base name.
Two bugs prevented --ltfs from being rejected by a server that lacks
SUPPORT_LTFS:

  1. The abort guard in parse_arguments() checked only am_server, which is
     0 in daemon mode (it is set only when --server appears in argv, i.e.
     remote-shell invocation).  Daemon mode sets am_daemon instead, so the
     condition now reads  am_server || am_daemon.

  2. The test binary rsync_noltfs was compiled with -USUPPORT_XATTRS to
     suppress SUPPORT_LTFS, but config.h (which has no include guard and
     is re-included by rsync.h) redefines SUPPORT_XATTRS regardless of
     -U flags.  The fix uses a positive compile-time hook:
     -DLTFS_SERVER_REJECT_TEST activates the abort block via
     #if !defined(SUPPORT_LTFS) || defined(LTFS_SERVER_REJECT_TEST)
     so the rejection path is always compiled into the test binary
     regardless of config.h.

Makefile.in gains the rsync_noltfs build rules (options.c recompiled with
the test hook; all other .o files shared with the normal rsync binary).
The ltfs-server-reject test drives this: it starts rsync_noltfs as the
daemon via RSYNC_CONNECT_PROG and verifies that the client gets a clear
"--ltfs is not supported on this server" error.
ltfs-daemon_test.py exercises the full client-server path over a
RSYNC_CONNECT_PROG pipe (no TCP socket, no real LTFS volume needed):

  1. Round-trip integrity: files with user.ltfs.startblock xattrs pushed
     to a daemon module and received successfully with --ltfs.

  2. Physical ordering: files with startblocks assigned in reverse name
     order; the -i output from the generator (daemon side) must list them
     in ascending startblock order, confirming that ltfs_build_order()
     runs correctly across the daemon pipe.

The test skips on platforms where os.setxattr is unavailable (Cygwin,
macOS without the xattr shim), so ltfs-daemon is added to
RSYNC_EXPECT_SKIPPED in both CI workflows.
…mon, verifying both a push and a pull complete correctly with no errors
CHECK_PROGS unconditionally included rsync_noltfs, so it was built even
on MinGW where LTFS is disabled.  shutil.which() then found it and the
ltfs-server-reject / ltfs-client-compat tests ran instead of skipping.

Gate the binary and its intermediate object on the same condition that
gates SUPPORT_LTFS in configure.ac: xattr support present and --ltfs not
explicitly disabled.
…ng regenerating configure files after make distclean
referencing the autogen.sh script in Makefile.in
The test transferred with -r but compared tls listings that include
mtimes.  Without -t the destination mtimes are set to the transfer time
rather than copied from the source, so the listings only matched when
the whole test happened to run inside a single wall-clock second.  It
failed intermittently otherwise (~25% of parallel runs here).  The
other ltfs tests pass --ltfs, which implies -t, so this was the only
one affected.  Preserve times on all four transfers instead.

Also move DAEMON_PORT off 12897, which daemon-path-root-read_test.py
already uses, to the unused 12900.
@steadytao

Copy link
Copy Markdown
Member

Should likely require the complete xattr value to be a valid non-negative decimal and reject ERANGE or trailing characters. As written, 123junk and an overflowing value can be accepted as physical positions and silently produce incorrect tape order.

@steadytao steadytao changed the title Initial LTFS order awarness functionality flist: order local LTFS reads by partition and block Nov 26, 2026
@steadytao steadytao added Enhancement New capability or intentional behaviour change Portability Affects behaviour on a supported operating system, architecture or toolchain labels Nov 26, 2026
@steadytao steadytao added this to the 4.0.0 milestone Nov 26, 2026
@RsyncProject RsyncProject deleted a comment from mosesn292-hue Nov 26, 2026
@steadytao

Copy link
Copy Markdown
Member

@hugo-hur Any chance I could get you to test this on LTFS? It now handles a flat local restore from one volume. A comparison with plain rsync -rt using the same files and a fresh destination would help verify the read order and whether it actually reduces seeks.

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.

5 participants