feat(krun): expand DiskBuilder with id, cache, direct_io, sync#51
Merged
feat(krun): expand DiskBuilder with id, cache, direct_io, sync#51
Conversation
Surface the per-disk knobs that libkrun's krun_add_disk3 C API already
supports but the Rust wrapper had hardcoded. This lets callers attach
extra disks as volumes (not just a rootfs) with stable identifiers and
per-disk safety/perf settings.
- Add CacheMode { Writeback, Unsafe } and SyncMode { None, Relaxed, Full }
enums with From impls to devices::virtio::{CacheType, block::SyncMode}.
- Add DiskBuilder::id() for caller-chosen block_ids, enabling guest
addressing via /dev/disk/by-id/virtio-<id> independent of attach order.
- Add DiskBuilder::cache(), direct_io(), sync() alongside the existing
path/format/read_only methods.
- Replace the naive format!("vd{}", (b'a' + i) as char) device-id
fallback, which rolled over into invalid characters past vdz, with a
bijective base-26 vd_suffix() helper matching block/genhd.c's
disk_name() scheme (vda..vdz, vdaa..vdzz, vdaaa...).
- Re-export CacheMode and SyncMode from the crate root.
Defaults (Writeback cache, direct_io=false, Full sync) preserve the
previous hardcoded behavior, so existing .disk(|d| d.path().format()
.read_only()) callers are unaffected.
When the caller passes a non-empty id via DiskBuilder::id() it now shows up in the guest as the virtio-blk serial (visible at /sys/block/<dev>/serial and, with udev, /dev/disk/by-id/virtio-<id>). Previously the id was stored as Block.id but disk_image_id was always generated from the host file's st_rdev + st_ino, so the configured id never reached the guest. Falls back to the rdev+inode default when id is empty, preserving existing behaviour for callers that do not set an id. Padding/truncation matches the existing default path: zero-padded to VIRTIO_BLK_ID_BYTES (20), with longer ids truncated.
4 tasks
appcypher
added a commit
that referenced
this pull request
Apr 26, 2026
Bump all msb_krun_* workspace crates and their internal path-dependency version refs from 0.1.10 to 0.1.11, and refresh both lockfiles. The libkrun C-API crate (1.17.3) and the rust_vm example are unchanged. Changes since 0.1.10: - feat(krun): expand DiskBuilder with id, cache, direct_io, sync (#51) - msb_krun_cpuid: fix compilation on Rust 1.93 by wrapping CPUID calls in unsafe blocks (#50)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
DiskBuilderwithid(),cache(),direct_io(), andsync()methods, surfacing per-disk knobs that libkrun'skrun_add_disk3C API already supports but the Rust wrapper had hardcoded.CacheMode { Writeback, Unsafe }andSyncMode { None, Relaxed, Full }enums (re-exported at the crate root) withFromimpls intodevices::virtio::{CacheType, block::SyncMode}.format!("vd{}", (b'a' + i) as char)rolled over into invalid characters (vd{,vd|, ...) past the 26th disk. Replaced with avd_suffix()helper implementing the kernel's bijective base-26disk_name()scheme (vda..vdz,vdaa..vdzz,vdaaa...)./dev/disk/by-id/virtio-<id>independent of attach order.Writebackcache,direct_io=false,Fullsync) preserve the previous hardcoded behavior, so existing.disk(|d| d.path().format().read_only())callers are unaffected.Test Plan
cargo build -p msb_krun(no features) passescargo build -p msb_krun --features blkpassescargo build -p msb_krun --features blk,netpassescargo test -p msb_krun --features blkpasses — 7 unit + 22 doctests (includes four new tests:vd_suffix_matches_kernel_scheme,disk_builder_preserves_insertion_order,disk_builder_auto_id_then_custom,disk_builder_per_disk_settings_dont_leak)cargo clippy -p msb_krun --features blk -- -D warningsclean