Skip to content

source: separate reading libxenstat from filling its gaps - #11

Merged
olivierlambert merged 2 commits into
mainfrom
refactor/xenstat-enrich
Oct 2, 2026
Merged

olivierlambert merged 2 commits into
mainfrom
refactor/xenstat-enrich

Conversation

@olivierlambert

Copy link
Copy Markdown
Owner

Item 2 of the cleanup plan. Stacked on #10 (base refactor/lib-loading); behavior-preserving.

Changes

XenstatSource::sample used to copy a node out of libxenstat and patch what the library lacks in one pass. Now:

  • read_node() (xenstat.rs): the FFI copy into a Snapshot, as the library reports it. All the unsafe code that touches libxenstat's structures is here.
  • gaps::fill() (new src/source/gaps.rs): plain Rust over the Snapshot for pCPU idle time, VIFs, steal time and tapdisk3 latency. Returns where each came from (Gaps), which sample copies into DataStatus exactly as before.
  • The host collectors (libxenctrl, /proc/net/dev, tapdisk3 stats files) sit behind a small Collectors trait; HostCollectors is the real one, holding the libxenctrl handles that used to be fields of XenstatSource. Each collector is still only called when the snapshot needs it.
  • Vbd3Index::into_map() replaces is_empty()/read().

sample is now: read node → fill gaps → xenstore storage → xapi names.

Testing

  • New tests with fake collectors: every Avail value for each class, VIFs rebuilt per guest in id order (dom0 and guests that have VIFs untouched), steal per domain, tapdisk3 latency from stats files, and that no collector is called when the library is complete. cargo test 78 passed; clippy -D warnings and fmt clean.
  • Demo smoke tests pass.
  • The real-host path is covered by unit tests only. The demo doesn't use libxenstat; on a non-Xen machine the binary loads it and stops at xenstat_init() as before. Please run it on an XCP-ng host (stock and patched libxenstat if possible) and compare the i panel / --batch "sources" with 0.4.0.

🤖 Generated with Claude Code

olivierlambert and others added 2 commits October 2, 2026 14:33
XenstatSource::sample copied a node out of libxenstat and patched what
the library lacks in one go. Now:

- read_node(): the FFI copy into a Snapshot, the only place libxenstat's
  structures are touched (all the unsafe code);
- gaps::fill(): plain Rust over the Snapshot for pCPU idle time, VIFs,
  steal time and tapdisk3 latency, returning where each came from. The
  host collectors (libxenctrl, /proc/net/dev, tapdisk3 stats files) sit
  behind a small Collectors trait; HostCollectors is the real one.

DataStatus is set from the result exactly as before, and each collector
is still only called when the snapshot needs it. Vbd3Index hands over
its map (into_map) instead of is_empty()/read().

New tests with fake collectors cover every status value and that
nothing is read when the library is complete.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@olivierlambert
olivierlambert changed the base branch from refactor/lib-loading to main October 2, 2026 15:37
@olivierlambert
olivierlambert merged commit b4cd54a into main Oct 2, 2026
5 checks passed
@olivierlambert
olivierlambert deleted the refactor/xenstat-enrich branch October 2, 2026 15:39
@olivierlambert olivierlambert mentioned this pull request Oct 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant