Skip to content

Extract the blktrace capture core into a standalone blktrace-rs crate - #152

Merged
imlk0 merged 10 commits into
masterfrom
blktrace
Oct 15, 2026
Merged

imlk0 merged 10 commits into
masterfrom
blktrace

Conversation

@imlk0

@imlk0 imlk0 commented Oct 15, 2026

Copy link
Copy Markdown
Collaborator

What

Moves the block-layer trace capture core out of cryptpilot-core into a new
workspace member, blktrace-rs, shaped as an independent library ready for
crates.io. cryptpilot-core keeps the mkfs analysis/replay logic and consumes
the crate with its new async feature.

Why

The capture core (kernel ioctls, debugfs relay channel readers, blk_io_trace
record parsing) has value beyond this project and has no maintained Rust
equivalent on crates.io. Extracting it now also drops build-time bindgen and
several dependencies from cryptpilot-core.

The crate

  • Sync core: per-CPU reader threads, a collector thread, AtomicBool cancel,
    Drop-based STOP/TEARDOWN on every exit path (a start failure now unwinds
    through Drop, which the old tokio code did not guarantee).
  • async feature (default off): monitor_async/shutdown_async wrap the
    core in tokio::task::spawn_blocking, so async callers never stall their
    executor. Without the feature the crate has zero tokio dependency.
  • Errors are a thiserror type with source chains; no anyhow in the public
    surface.
  • UAPI types come from bindgen at build time (README documents the
    libclang + kernel header requirement); ioctls stay crate-private.
  • Tests: unit tests for record parsing and event classification, plus live
    loop-device capture tests (sync and async) with panic-safe cleanup.

cryptpilot-core changes

  • Deletes fs/block/blktrace/ and the bindgen section of build.rs
    (ttrpc section untouched).
  • mkfs.rs switches to monitor_async/shutdown_async; drop_page_cache
    becomes an explicit call where it used to hide inside monitor(), keeping
    the same position in the sequence. The event analysis loop is unchanged.
  • Drops now-unused dependencies: mnt, num_cpus, bindgen, tokio-util.

Publishing

cargo package passes; the packaged manifest is verified clean (nix pulls
only ioctl + mount). Publishing to crates.io is a separate manual step.

Rust-Go sync: not applicable, no blktrace counterpart in verity-go.

imlk0 added 10 commits October 15, 2026 11:46
New workspace member holding the block-layer trace capture core before it moves out of cryptpilot-core.

Assisted-by: Claude:glm-5.3
Signed-off-by: Kun Lai <laikun@linux.alibaba.com>
Assisted-by: Claude:glm-5.3
Signed-off-by: Kun Lai <laikun@linux.alibaba.com>
Assisted-by: Claude:glm-5.3
Signed-off-by: Kun Lai <laikun@linux.alibaba.com>
Assisted-by: Claude:glm-5.3
Signed-off-by: Kun Lai <laikun@linux.alibaba.com>
Replaces the tokio task per CPU with plain reader threads and a collector thread; the blocking core this crate publishes.

Assisted-by: Claude:glm-5.3
Signed-off-by: Kun Lai <laikun@linux.alibaba.com>
Assisted-by: Claude:glm-5.3
Signed-off-by: Kun Lai <laikun@linux.alibaba.com>
Assisted-by: Claude:glm-5.3
Signed-off-by: Kun Lai <laikun@linux.alibaba.com>
The trace capture core now lives in the blktrace-rs workspace member. drop_page_cache becomes an explicit call where it used to hide inside monitor(), so the mkfs read path still forces real I/O.

Assisted-by: Claude:glm-5.3
Signed-off-by: Kun Lai <laikun@linux.alibaba.com>
Assisted-by: Claude:glm-5.3
Signed-off-by: Kun Lai <laikun@linux.alibaba.com>
blktrace-rs ran bindgen unconditionally, so on non-Linux hosts the
first error was "Unable to generate bindings" from the missing
linux/blktrace_api.h header. build.rs now returns early when the
target OS is not Linux, letting lib.rs's compile_error! deliver the
clean "Linux only" message instead.

cryptpilot-core's out_dir binding and its env/PathBuf imports were
used only under the provider-kbs feature, so a plain default-features
build emitted an unused-variable warning. Move both inside the cfg
block.

blktrace-rs declared nix via the workspace, which serialized the
workspace's "feature" and "time" features into the packaged
manifest and duplicated ioctl. Declare nix locally with exactly the
features the crate uses, ioctl and mount, the same way tokio is
already declared locally.

Also drop unused dependencies: tokio-util in cryptpilot-core (its
only user was the in-tree blktrace module, now replaced by
blktrace-rs) and the "time" dev-feature of blktrace-rs's tokio.

Assisted-by: Claude:glm-5.3
Signed-off-by: Kun Lai <laikun@linux.alibaba.com>
@ostest-bot

Copy link
Copy Markdown

@imlk0 ,您好,您的请求已接收,请耐心等待结果。

@ostest-bot

Copy link
Copy Markdown

@imlk0 ,您好,未检测到有镜像需要构建,如需重新检测请评论 /start 。

@imlk0
imlk0 merged commit 864df4c into master Oct 15, 2026
84 of 85 checks passed
@imlk0
imlk0 deleted the blktrace branch October 15, 2026 08:31
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