Skip to content

Prototype for batching statx with io_uring - #1302

Open
erthalion wants to merge 1 commit into
mainfrom
feature/host-scanner-with-io-uring
Open

Prototype for batching statx with io_uring#1302
erthalion wants to merge 1 commit into
mainfrom
feature/host-scanner-with-io-uring

Conversation

@erthalion

@erthalion erthalion commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

Description

Prototype, statx buffer is not filled.

Checklist

  • Patch has a change log entry OR does not need one.
  • Investigated and inspected CI test results
  • Updated documentation accordingly

Automated testing

  • Added unit tests
  • Added integration tests
  • Added regression tests

If any of these don't apply, please comment below.

Testing Performed

TODO(replace-me)
Use this space to explain how you tested your PR, or, if you didn't test it, why you did not do so. (Valid reasons include "CI is sufficient" or "No testable changes")
In addition to reviewing your code, reviewers must also review your testing instructions, and make sure they are sufficient.

For more details, ref the Confluence page about this section.

Summary by CodeRabbit

  • Performance Improvements
    • Improved host filesystem scanning by classifying files and directories in batches for faster discovery.
    • Reduced per-path synchronous filesystem checks during scanning.
  • Bug Fixes
    • Improved handling and metrics for filesystem entries discovered during host scans.

@erthalion
erthalion requested review from a team and rhacs-bot as code owners July 28, 2026 14:32
@coderabbitai

coderabbitai Bot commented Jul 28, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yml

Review profile: CHILL

Plan: Pro Plus

Run ID: bff92c4e-2ce4-462d-b581-6d380faf0136

📥 Commits

Reviewing files that changed from the base of the PR and between abf869b and 49d058a.

⛔ Files ignored due to path filters (1)
  • Cargo.lock is excluded by !**/*.lock
📒 Files selected for processing (3)
  • Cargo.toml
  • fact/Cargo.toml
  • fact/src/host_scanner.rs
🚧 Files skipped from review as they are similar to previous changes (3)
  • Cargo.toml
  • fact/Cargo.toml
  • fact/src/host_scanner.rs

📝 Walkthrough

Walkthrough

The workspace adds io-uring, and host_scanner replaces synchronous path classification with batched statx requests. Completions classify entries as files or directories before updating scan results and metrics.

Changes

Host filesystem scanning

Layer / File(s) Summary
io-uring scanner setup
Cargo.toml, fact/Cargo.toml, fact/src/host_scanner.rs
The workspace and fact crate declare io-uring; the scanner adds buffers for target paths, C strings, and statx results.
Batched statx classification
fact/src/host_scanner.rs
scan_inner submits glob matches in batches, classifies completions using stx_mode, and updates matching entries and metrics.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant scan_inner
  participant IoUring
  participant update_entry
  scan_inner->>IoUring: Submit batched statx requests
  IoUring-->>scan_inner: Return statx completions
  scan_inner->>scan_inner: Classify files and directories
  scan_inner->>update_entry: Update matching scan entries
Loading

Possibly related PRs

  • stackrox/fact#1221: Modifies the host scanner entry-classification flow and update_entry/metrics handling.

Suggested reviewers: rhacs-bot

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The PR description keeps the required headings but leaves the description, checklist justifications, and testing details mostly incomplete. Add a fuller change summary, mark each checklist item as done or N/A with comments, and replace the TODO in Testing Performed with actual steps or rationale.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title is concise and accurately summarizes the main change: batching statx calls with io_uring.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/host-scanner-with-io-uring

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@codecov-commenter

codecov-commenter commented Jul 28, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 0% with 45 lines in your changes missing coverage. Please review.
✅ Project coverage is 35.59%. Comparing base (9800848) to head (49d058a).
⚠️ Report is 14 commits behind head on main.

Files with missing lines Patch % Lines
fact/src/host_scanner.rs 0.00% 45 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1302      +/-   ##
==========================================
+ Coverage   33.22%   35.59%   +2.37%     
==========================================
  Files          21       22       +1     
  Lines        2971     3214     +243     
  Branches     2971     3214     +243     
==========================================
+ Hits          987     1144     +157     
- Misses       1981     2067      +86     
  Partials        3        3              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@coderabbitai coderabbitai 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.

Actionable comments posted: 4

🧹 Nitpick comments (1)
fact/src/host_scanner.rs (1)

205-222: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Duplicate update_entry call across is_file/is_dir branches.

Both branches call self.update_entry(path.as_path()) with an identical .with_context(...), differing only in which metric label to increment. Consider merging to avoid the duplication.

Also note: once the pointer/mask bugs above are fixed, if stx_mode still doesn't match either S_IFREG or S_IFDIR (e.g., symlinks, sockets, devices), the entry is silently skipped with no metric increment or log — worth at least a debug log for visibility.

♻️ Proposed refactor
-                let is_dir = (statxbuf.stx_mode as u32 & libc::S_IFMT) == libc::S_IFDIR;
-                let is_file = (statxbuf.stx_mode as u32 & libc::S_IFMT) == libc::S_IFREG;
-
-                if is_file {
-                    self.metrics.scan_inc(ScanLabels::FileScanned);
-                    self.update_entry(path.as_path()).with_context(|| {
-                        format!("Failed to update entry for {}", path.display())
-                    })?;
-                } else if is_dir {
-                    self.metrics.scan_inc(ScanLabels::DirectoryScanned);
-                    self.update_entry(path.as_path()).with_context(|| {
-                        format!("Failed to update entry for {}", path.display())
-                    })?;
-                }
+                let file_type = statxbuf.stx_mode as u32 & libc::S_IFMT;
+                let label = match file_type {
+                    libc::S_IFREG => Some(ScanLabels::FileScanned),
+                    libc::S_IFDIR => Some(ScanLabels::DirectoryScanned),
+                    _ => None,
+                };
+
+                if let Some(label) = label {
+                    self.metrics.scan_inc(label);
+                    self.update_entry(path.as_path()).with_context(|| {
+                        format!("Failed to update entry for {}", path.display())
+                    })?;
+                } else {
+                    debug!("Unclassified statx mode {:`#o`} for {}", statxbuf.stx_mode, path.display());
+                }
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@fact/src/host_scanner.rs` around lines 205 - 222, Refactor the file and
directory handling in the batch loop around IoUringStatx so the metric label is
selected and incremented per type, then call self.update_entry(path.as_path())
with the shared context only once. Preserve skipping unsupported file types, but
add debug-level visibility for entries whose mode matches neither S_IFREG nor
S_IFDIR.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@fact/src/host_scanner.rs`:
- Around line 192-203: Update scan_inner to propagate the submission error from
ring.submission().push(op) through its existing anyhow::Result path instead of
panicking with expect. Replace the hardcoded user_data(0x99) when building each
op with a per-entry identifier so the completion debug log can distinguish
entries.
- Line 182: Update the statx mask in the host-scanning call to use bitwise OR
when combining requested flags, or only libc::STATX_TYPE since the result checks
stx_mode file-type bits. Remove the current libc::STATX_TYPE & libc::STATX_INO
expression and retain STATX_INO only if the returned inode is used later.
- Around line 163-188: Update the statx buffer ownership in the glob mapping
that constructs IoUringStatx so the address passed to opcode::Statx::new remains
stable through submission and completion. Allocate the statxbuf with stable heap
storage, such as a Box, and retain that ownership until the io_uring operation
completes; ensure moving the operation into the collected Vec cannot relocate
the kernel target.
- Line 161: Replace the bitwise-XOR expressions used for the IoUring ring size
and submission chunk size in the host scanner with the intended batch size of
128, using either a literal or an equivalent power-of-two expression.

---

Nitpick comments:
In `@fact/src/host_scanner.rs`:
- Around line 205-222: Refactor the file and directory handling in the batch
loop around IoUringStatx so the metric label is selected and incremented per
type, then call self.update_entry(path.as_path()) with the shared context only
once. Preserve skipping unsupported file types, but add debug-level visibility
for entries whose mode matches neither S_IFREG nor S_IFDIR.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yml

Review profile: CHILL

Plan: Pro Plus

Run ID: 65c6548e-2187-486b-ba5c-d819832c523b

📥 Commits

Reviewing files that changed from the base of the PR and between e1926f2 and abf869b.

⛔ Files ignored due to path filters (1)
  • Cargo.lock is excluded by !**/*.lock
📒 Files selected for processing (3)
  • Cargo.toml
  • fact/Cargo.toml
  • fact/src/host_scanner.rs

Comment thread fact/src/host_scanner.rs Outdated
Comment thread fact/src/host_scanner.rs
Comment thread fact/src/host_scanner.rs Outdated
Comment thread fact/src/host_scanner.rs
Comment on lines +192 to +203
unsafe {
ring.submission()
.push(op)
.expect("submission queue is full");
}
}

ring.submit_and_wait(batch.len())?;

for cqe in ring.completion() {
debug!("IoUring CQE {:?}, {:?}", cqe.user_data(), cqe.result());
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🩺 Stability & Availability | 🟠 Major | 💤 Low value

Prefer propagating submission errors instead of panicking.

scan_inner already returns anyhow::Result<()>; using .expect("submission queue is full") inside the loop will abort the scan task rather than letting the caller recover/log via the existing ? error path.

Separately, every op is built with the same hardcoded user_data(0x99) (line 184), so the debug!("IoUring CQE {:?}, {:?}", ...) log can't distinguish which entry a given completion belongs to; consider tagging with a per-entry index for useful debugging.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@fact/src/host_scanner.rs` around lines 192 - 203, Update scan_inner to
propagate the submission error from ring.submission().push(op) through its
existing anyhow::Result path instead of panicking with expect. Replace the
hardcoded user_data(0x99) when building each op with a per-entry identifier so
the completion debug log can distinguish entries.

@erthalion
erthalion force-pushed the feature/host-scanner-with-io-uring branch from abf869b to 93b4b2f Compare July 28, 2026 14:49
@erthalion
erthalion force-pushed the feature/host-scanner-with-io-uring branch from 93b4b2f to 49d058a Compare July 28, 2026 15:39
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.

2 participants