Skip to content

Add file list timing metrics to stats reporting - #930

Merged
oferchen merged 1 commit into
masterfrom
implement-missing-components-for-oc-rsync
Oct 23, 2025
Merged

oferchen merged 1 commit into
masterfrom
implement-missing-components-for-oc-rsync

Conversation

@oferchen

@oferchen oferchen commented Oct 23, 2025 •

Copy link
Copy Markdown
Owner

Summary

  • track file-list size and generation timing inside LocalCopySummary
  • expose the new metrics through ClientSummary and surface them in oc-rsync --stats
  • extend the stats output test suite to cover the additional fields

Testing

  • cargo test

@oferchen
oferchen merged commit 4dc3f95 into master Oct 23, 2025
@oferchen
oferchen deleted the implement-missing-components-for-oc-rsync branch October 23, 2025 00:08

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines 2048 to +2057
self.total_elapsed = self.total_elapsed.saturating_add(elapsed);
}

fn record_file_list_generation(&mut self, elapsed: Duration) {
self.file_list_generation = self.file_list_generation.saturating_add(elapsed);
}

fn record_file_list_transfer(&mut self, elapsed: Duration) {
self.file_list_transfer = self.file_list_transfer.saturating_add(elapsed);
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Populate file list metrics before displaying stats

The CLI now prints File list size, File list generation time, and File list transfer time via ClientSummary, but LocalCopySummary only defines the fields and accessors here and there are no call sites that ever assign to file_list_size or invoke record_file_list_transfer. A repository-wide search shows these values remain at their Default of zero, so the new stats lines will always render 0 bytes and 0.000 seconds regardless of actual work. Consider computing the file list size and transfer timing when building/sending the list, or gate the output until the metrics are populated.

Useful? React with 👍 / 👎.

oferchen added a commit that referenced this pull request Aug 21, 2026
`basis_link_stat()` has three arms, and only the first belongs to a
non-daemon receiver:

  1. `!am_daemon && am_root >= 0 && !symlink_optout_allowed()` resolves the
     basis parent through the ownership walk (generator.c:978).
  2. `am_daemon && !am_chrooted && path[0] == '/'` walks it with module-root
     confinement (generator.c:993).
  3. everything else takes a plain `link_stat()` (generator.c:1010).

The ownership walk was being applied unconditionally, so a daemon receiver
took arm 1 where upstream takes arm 3. That is not just stricter than
upstream, it is inoperative: the walk opens every component starting at `/`,
and a daemon worker is confined - chroot, or a Landlock ruleset rooted at the
module - precisely so the module's ancestors are not openable. The first
`openat("/")` returns EACCES, the basis looks absent, and every file is
re-transferred. Upstream's own note on arm 2 covers this exact shape: a
relative basis such as `--link-dest=../01` is a dest-relative sibling whose
`../` `sanitize_path` has already clamped to the module root, so it "must
keep the plain link_stat below (#915/#930)".

Arm selection is spelled as a `BasisTrust` value rather than a bare bool so
neither arm can be picked by accident at a call site. Arm 2 (an absolute
basis under module-root confinement) is not implemented here; on that path
the receiver keeps the path-based stat it has always used, so this is no
weaker than before in any configuration.

Measured on Linux against the upstream 3.5.0 testsuite cell
`link-dest-relative-basis`, which exercises `--link-dest`, `--copy-dest` and
`--compare-dest` over a daemon push: it is `pass` in both pipe manifests, and
the unconditional walk turned it red.
oferchen added a commit that referenced this pull request Aug 21, 2026
* fix(receiver): stat alt-dest basis via the ownership walk

The receiver resolved a `--compare-dest` / `--copy-dest` / `--link-dest`
basis entry with a plain path stat, which walks every component of a
peer-supplied entry name at call time. Upstream reaches the same entry
through `owner_walk_parent()` plus `link_stat_at()` (generator.c:979-990),
so a symlink component owned by neither root nor our euid is refused with
ELOOP instead of followed.

Route the basis stat onto `fast_io::owner_walk`, the same primitive the
sibling operator-path families already use for --temp-dir and --backup-dir.
Only the parent is walked: the leaf is `fstatat(AT_SYMLINK_NOFOLLOW)`'d and
never opened, because upstream must report a symlink at the basis name AS a
symlink for its `!S_ISREG` filter to drop it, and because opening would
demand read permission the --link-dest hard-link path does not need. The
`fs::Metadata` handed downstream comes from a second path stat that is
accepted only when it names the same (dev, ino) the confined stat saw, so a
parent flipped between the two calls is refused.

Measured against real rsync 3.5.0: a self-owned symlinked parent is
traversed by both implementations, and that half is now pinned. The
refusing half needs a foreign-owned symlink and therefore root to
construct; it stays pinned at the predicate, by owner_walk's
`refuses_an_owner_that_is_neither_root_nor_the_euid`.

* test(fast_io): pin AtMetadata against std::fs::Metadata on one file

The alt-dest basis lookup stats a file two ways - `fstatat` through the
confined dirfd and `symlink_metadata` by path - and accepts the second only
when it names the same `(dev, ino)` as the first. That cross-check silently
degrades into "basis absent" on any target where the two stat APIs disagree,
and the comparison is not a tautology: `fstatat_nofollow` calls
`libc::fstatat`, while `std` on Linux goes through `statx` and rebuilds
`st_dev` from the returned major/minor pair.

Pin the agreement directly so the platform where it stops holding fails
loudly and by name instead of surfacing as a mis-attributed transfer.

* fix(receiver): keep the plain basis stat on a daemon receiver

`basis_link_stat()` has three arms, and only the first belongs to a
non-daemon receiver:

  1. `!am_daemon && am_root >= 0 && !symlink_optout_allowed()` resolves the
     basis parent through the ownership walk (generator.c:978).
  2. `am_daemon && !am_chrooted && path[0] == '/'` walks it with module-root
     confinement (generator.c:993).
  3. everything else takes a plain `link_stat()` (generator.c:1010).

The ownership walk was being applied unconditionally, so a daemon receiver
took arm 1 where upstream takes arm 3. That is not just stricter than
upstream, it is inoperative: the walk opens every component starting at `/`,
and a daemon worker is confined - chroot, or a Landlock ruleset rooted at the
module - precisely so the module's ancestors are not openable. The first
`openat("/")` returns EACCES, the basis looks absent, and every file is
re-transferred. Upstream's own note on arm 2 covers this exact shape: a
relative basis such as `--link-dest=../01` is a dest-relative sibling whose
`../` `sanitize_path` has already clamped to the module root, so it "must
keep the plain link_stat below (#915/#930)".

Arm selection is spelled as a `BasisTrust` value rather than a bare bool so
neither arm can be picked by accident at a call site. Arm 2 (an absolute
basis under module-root confinement) is not implemented here; on that path
the receiver keeps the path-based stat it has always used, so this is no
weaker than before in any configuration.

Measured on Linux against the upstream 3.5.0 testsuite cell
`link-dest-relative-basis`, which exercises `--link-dest`, `--copy-dest` and
`--compare-dest` over a daemon push: it is `pass` in both pipe manifests, and
the unconditional walk turned it red.
oferchen added a commit that referenced this pull request Aug 24, 2026
* fix(receiver): stat alt-dest basis via the ownership walk

The receiver resolved a `--compare-dest` / `--copy-dest` / `--link-dest`
basis entry with a plain path stat, which walks every component of a
peer-supplied entry name at call time. Upstream reaches the same entry
through `owner_walk_parent()` plus `link_stat_at()` (generator.c:979-990),
so a symlink component owned by neither root nor our euid is refused with
ELOOP instead of followed.

Route the basis stat onto `fast_io::owner_walk`, the same primitive the
sibling operator-path families already use for --temp-dir and --backup-dir.
Only the parent is walked: the leaf is `fstatat(AT_SYMLINK_NOFOLLOW)`'d and
never opened, because upstream must report a symlink at the basis name AS a
symlink for its `!S_ISREG` filter to drop it, and because opening would
demand read permission the --link-dest hard-link path does not need. The
`fs::Metadata` handed downstream comes from a second path stat that is
accepted only when it names the same (dev, ino) the confined stat saw, so a
parent flipped between the two calls is refused.

Measured against real rsync 3.5.0: a self-owned symlinked parent is
traversed by both implementations, and that half is now pinned. The
refusing half needs a foreign-owned symlink and therefore root to
construct; it stays pinned at the predicate, by owner_walk's
`refuses_an_owner_that_is_neither_root_nor_the_euid`.

* test(fast_io): pin AtMetadata against std::fs::Metadata on one file

The alt-dest basis lookup stats a file two ways - `fstatat` through the
confined dirfd and `symlink_metadata` by path - and accepts the second only
when it names the same `(dev, ino)` as the first. That cross-check silently
degrades into "basis absent" on any target where the two stat APIs disagree,
and the comparison is not a tautology: `fstatat_nofollow` calls
`libc::fstatat`, while `std` on Linux goes through `statx` and rebuilds
`st_dev` from the returned major/minor pair.

Pin the agreement directly so the platform where it stops holding fails
loudly and by name instead of surfacing as a mis-attributed transfer.

* fix(receiver): keep the plain basis stat on a daemon receiver

`basis_link_stat()` has three arms, and only the first belongs to a
non-daemon receiver:

  1. `!am_daemon && am_root >= 0 && !symlink_optout_allowed()` resolves the
     basis parent through the ownership walk (generator.c:978).
  2. `am_daemon && !am_chrooted && path[0] == '/'` walks it with module-root
     confinement (generator.c:993).
  3. everything else takes a plain `link_stat()` (generator.c:1010).

The ownership walk was being applied unconditionally, so a daemon receiver
took arm 1 where upstream takes arm 3. That is not just stricter than
upstream, it is inoperative: the walk opens every component starting at `/`,
and a daemon worker is confined - chroot, or a Landlock ruleset rooted at the
module - precisely so the module's ancestors are not openable. The first
`openat("/")` returns EACCES, the basis looks absent, and every file is
re-transferred. Upstream's own note on arm 2 covers this exact shape: a
relative basis such as `--link-dest=../01` is a dest-relative sibling whose
`../` `sanitize_path` has already clamped to the module root, so it "must
keep the plain link_stat below (#915/#930)".

Arm selection is spelled as a `BasisTrust` value rather than a bare bool so
neither arm can be picked by accident at a call site. Arm 2 (an absolute
basis under module-root confinement) is not implemented here; on that path
the receiver keeps the path-based stat it has always used, so this is no
weaker than before in any configuration.

Measured on Linux against the upstream 3.5.0 testsuite cell
`link-dest-relative-basis`, which exercises `--link-dest`, `--copy-dest` and
`--compare-dest` over a daemon push: it is `pass` in both pipe manifests, and
the unconditional walk turned it red.
oferchen added a commit that referenced this pull request Sep 7, 2026
…le root (#7725)

* fix(receiver): confine a daemon's absolute alt-dest basis to the module root

Upstream's `basis_link_stat()` has four arms. oc modelled two of them, and
the missing one is the arm that exists for a daemon:

  generator.c:979  arm 1  !am_daemon                -> ownership walk
  generator.c:1004 arm 2  am_daemon && !am_chrooted
                          && path[0] == '/'         -> ownership walk with
                                                       operator_path_resolve = 1
  generator.c:1046 arm 3  am_daemon && am_chrooted
                          && relative               -> secure_relative_open
  generator.c:1064 arm 4                            -> plain link_stat

`BasisTrust` was a two-valued enum keyed on one bool, so every daemon
receiver fell straight to arm 4. The ownership rule alone cannot stand in
for arm 2: a module tree belongs to the daemon uid, so an in-module symlink
whose target lands outside the module is trusted-OWNED and is followed.
Only the module-root judgement on the resolved leaf refuses it.

That is a read oracle. The daemon roots a peer's `--compare-dest=/evil`
under the module (`clamp_basis_to_module`, upstream `sanitize_path`), so
the basis path is `<module>/evil/tgtfile` and the escaping component is a
PARENT. `fs::symlink_metadata` declines to follow a symlink at the LEAF
only; the kernel resolves every parent, and the stat lands outside.

Changes:

- `BasisTrust` becomes the two session facts upstream branches on
  (`am_daemon`, `am_chrooted`); `BasisTrust::arm_for` applies the per-path
  `path[0] == '/'` term and yields a `BasisArm`. A RELATIVE basis keeps the
  plain stat on both implementations - upstream's own comment at
  generator.c:997-1001 spells out why, and confining it would re-open the
  `link-dest-relative-basis` regression (#915/#930).
- `fast_io::operator_symlink_metadata_confined` is the arm-2 resolver:
  the same walk, with `PathKind::Confined` so the resolved leaf is judged
  against the session root. Both spellings share one body.
- `fast_io::confinement` publishes `am_chrooted` alongside the opt-out it
  already published. A chroot changes the process root, so it belongs in
  process state; a module's `insecure links` directive does not, and stays
  on the connection.
- The predicate reads `am_daemon` as `served_module_root().is_some()`, not
  `is_daemon_connection`. The latter is set on BOTH ends of an `rsync://`
  transfer, so it was applying a daemon's confinement to an `rsync://`
  CLIENT's own local destination, which upstream leaves on arm 1.

The symlink opt-out is deliberately not restated at the predicate. Upstream
tests it per arm but reads the same global the walk reads, and `ona_open()`
short-circuits to a legacy symlink-following open before any root is
consulted (syscall.c:300-302); `fast_io::owner_walk` mirrors that, so under
an opt-out every walking arm already degenerates to arm 4's resolution.

Still absent, and named rather than papered over: upstream's arm 3, and
`try_dests_non` (generator.c:1226/1253) which reaches `basis_link_stat`
upstream but a plain `symlink_metadata` here.

* fix(transfer): gate the basis-arm selector to Unix, matching its only consumer

`BasisArm` and `BasisTrust::arm_for` were declared unconditionally while
their sole production consumer is the `cfg(unix)` `basis_stat`, so on Windows
both are dead and `-D warnings` makes that fatal. Two of the three arms name
the ownership walk, which the `cfg(not(unix))` `basis_stat` already documents
as having no Windows analogue - it takes the plain stat for every
`BasisTrust` and never asks which arm applies. Selecting an arm is therefore
not a question that can be posed off Unix, so the gate states a platform
truth rather than silencing a lint.

`BasisTrust` itself stays ungated: both `basis_stat` arms take it, which is
why only the other two were reported. The test module follows `arm_for`'s
gate because every case asserts an `arm_for` answer.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant