Skip to content

The micro-VM for AI agents — light enough to embed on your laptop, elastic enough to power an agentic cloud.

perf(runtime): fast-path guest rootfs and skip empty volume resolution (#3164)

lfld287c699d6f8b241
diff --git a/docs/concepts/storage.md b/docs/concepts/storage.md
index f6c02d0fb..9335e2550 100644
--- a/docs/concepts/storage.md
+++ b/docs/concepts/storage.md
@@ -21,6 +21,11 @@ Image Layers Rootfs Builder Box Rootfs
- DNS configuration injection
- Copy-on-write snapshot creation
+The minimal guest rootfs is cached separately from the container rootfs. BoxLite checks
+artifact metadata (size, modification time, and inode, plus device and change time) to
+reuse an unchanged guest rootfs without rereading and validating the binaries or
+rebuilding the ext4 image. A cache miss triggers full artifact validation and a rebuild.
+
### ext4 image disk cache
On a cache miss, concurrent requests in the same process for the same image
@@ -30,6 +35,9 @@ for other image digests or reserve sizes do not wait for that build.
## Volume management
+When neither volumes nor mount specs are configured, BoxLite skips volume resolution,
+including volume lookups and user mount setup.
+
**Supported volume types:**
| Type | Description | Use Case |
diff --git a/scripts/build/build-runtime.sh b/scripts/build/build-runtime.sh
index 612ade9c0..9926a7726 100755
--- a/scripts/build/build-runtime.sh
+++ b/scripts/build/build-runtime.sh
@@ -163,7 +163,7 @@ build_guest() {
# Build the guest e2fsprogs tools (mke2fs, resize2fs).
#
-# These are required by GuestArtifacts::get() on the default boot path, so they
+# These are required by minimal guest rootfs initialization on the default boot path, so they
# must always be produced here rather than treated as optional — a runtime
# missing them builds fine but fails on the first Box start.
diff --git a/src/boxlite/src/litebox/init/tasks/guest_rootfs.rs b/src/boxlite/src/litebox/init/tasks/guest_rootfs.rs
index 18681e6f9..54de437d3 100644
--- a/src/boxlite/src/litebox/init/tasks/guest_rootfs.rs
+++ b/src/boxlite/src/litebox/init/tasks/guest_rootfs.rs
@@ -10,7 +10,6 @@ use crate::rootfs::guest::{GuestRootfs, GuestRootfsManager};
use crate::runtime::constants::images;
use crate::runtime::layout::BoxFilesystemLayout;
use crate::runtime::rt_impl::SharedRuntimeImpl;
-use crate::vmm::guest_artifacts::GuestArtifacts;
use async_trait::async_trait;
use boxlite_shared::errors::{BoxliteError, BoxliteResult};
@@ -58,11 +57,15 @@ async fn run_guest_rootfs(
.get_or_try_init(|| async {
tracing::info!("Initializing minimal guest rootfs (first time only)");
- let artifacts = GuestArtifacts::get()?;
- let guest_rootfs = runtime
- .guest_rootfs_mgr
- .get_or_create_minimal(artifacts)
- .await?;
+ let runtime = runtime.clone();
+ let span = tracing::Span::current();
+ let guest_rootfs = tokio::task::spawn_blocking(move || {
+ span.in_scope(|| runtime.guest_rootfs_mgr.get_or_create_minimal())
+ })
+ .await
+ .map_err(|e| {
+ BoxliteError::Storage(format!("minimal rootfs init task failed: {e}"))
+ })??;
tracing::info!("Minimal guest rootfs ready: {:?}", guest_rootfs.strategy);
diff --git a/src/boxlite/src/litebox/init/tasks/vmm_spawn.rs b/src/boxlite/src/litebox/init/tasks/vmm_spawn.rs
index 5f1dc7174..af0c61631 100644
--- a/src/boxlite/src/litebox/init/tasks/vmm_spawn.rs
+++ b/src/boxlite/src/litebox/init/tasks/vmm_spawn.rs
@@ -156,25 +156,8 @@ async fn build_config(
let transport = BoxTransport::unix(layout.socket_path());
let ready_transport = BoxTransport::unix(layout.ready_socket_path());
- let local_volume_store = runtime.local_volume_store.clone();
- let volume_options = options.clone();
- // Declared sources are checked before the resolver runs: it would mount a
- // file where a declared directory used to be, or fail without naming the
- // target. Both read the host filesystem, and the resolution takes
- // filesystem locks, so keep them off Tokio's async worker threads.
- let (declared, user_volumes) = tokio::task::spawn_blocking(move || {
- if let Some(declared) = &declared {
- declared.check_sources()?;
- }
- resolve_user_volumes(
- &volume_options.volumes,
- &volume_options.mounts,
- &local_volume_store,
- )
- .map(|volumes| (declared, volumes))
- })
- .await
- .map_err(|error| BoxliteError::Internal(format!("volume resolution task failed: {error}")))??;
+ let (declared, user_volumes) =
+ prepare_volumes(declared, options, &runtime.local_volume_store).await?;
// Prepare container directories (image/, rw/, rootfs/)
let container_layout = layout.shared_layout().container(container_id.as_str());
@@ -339,6 +322,49 @@ async fn build_config(
))
}
+fn needs_volume_preparation(declared: Option<&crate::db::Mounts>, options: &BoxOptions) -> bool {
+ let has_declared_checks = declared.is_some_and(|mounts| !mounts.declarations.is_empty());
+ let has_user_volumes = !options.volumes.is_empty() || !options.mounts.is_empty();
+ has_declared_checks || has_user_volumes
+}
+
+async fn prepare_volumes(
+ declared: Option<crate::db::Mounts>,
+ options: &BoxOptions,
+ local_volume_store: &crate::volumes::LocalVolumeStore,
+) -> BoxliteResult<(
+ Option<crate::db::Mounts>,
+ Vec<crate::litebox::init::types::ResolvedVolume>,
+)> {
+ if !needs_volume_preparation(declared.as_ref(), options) {
+ return Ok((declared, Vec::new()));
+ }
+
+ let local_volume_store = local_volume_store.clone();
+ let volume_options = options.clone();
+ // Declared sources are checked before the resolver runs: it would mount a
+ // file where a declared directory used to be, or fail without naming the
+ // target. Both read the host filesystem, and the resolution takes
+ // filesystem locks, so keep them off Tokio's async worker threads.
+ tokio::task::spawn_blocking(move || {
+ if let Some(declared) = &declared {
+ declared.check_sources()?;
+ }
+ let volumes = if volume_options.volumes.is_empty() && volume_options.mounts.is_empty() {
+ Vec::new()
+ } else {
+ resolve_user_volumes(
+ &volume_options.volumes,
+ &volume_options.mounts,
+ &local_volume_store,
+ )?
+ };
+ Ok::<_, BoxliteError>((declared, volumes))
+ })
+ .await
+ .map_err(|error| BoxliteError::Internal(format!("volume resolution task failed: {error}")))?
+}
+
/// Configure guest rootfs with device path from volume manager.
fn configure_guest_rootfs(
mut guest_rootfs: GuestRootfs,
@@ -584,4 +610,132 @@ mod tests {
"guest rootfs must attach read-only (is_disk_read_only)"
);
}
+
+ #[tokio::test]
+ async fn volume_preparation_fast_path_respects_declared_and_options() {
+ use crate::db::{BoxStore, Database};
+ use crate::litebox::BoxManager;
+ use crate::litebox::config::{BoxConfig, ContainerRuntimeConfig};
+ use crate::litebox::state::BoxState;
+ use crate::runtime::id::BoxIDMint;
+ use crate::runtime::options::{MountSpec, RootfsSpec};
+ use crate::runtime::types::ContainerID;
+ use crate::volumes::LocalVolumeStore;
+ use chrono::Utc;
+
+ let dir = tempfile::tempdir_in("/tmp").unwrap();
+ let db_path = dir.path().join("boxlite.db");
+ let store = BoxStore::new(Database::open(&db_path).unwrap());
+ let volume_store = LocalVolumeStore::new(
+ dir.path().join("volumes"),
+ BoxManager::new(BoxStore::new(Database::open(&db_path).unwrap())),
+ )
+ .unwrap();
+
+ let empty_options = BoxOptions::default();
+
+ // 1. None + empty options -> fast path returns (None, vec![]).
+ let (declared_out, volumes_out) = prepare_volumes(None, &empty_options, &volume_store)
+ .await
+ .unwrap();
+ assert!(declared_out.is_none());
+ assert!(volumes_out.is_empty());
+
+ // 2. Some(empty_declared) + empty options -> fast path preserves declared.
+ let empty_id = BoxIDMint::mint();
+ let empty_config = BoxConfig {
+ id: empty_id.clone(),
+ name: None,
+ created_at: Utc::now(),
+ container: ContainerRuntimeConfig {
+ id: ContainerID::new(),
+ },
+ options: BoxOptions {
+ rootfs: RootfsSpec::Image("alpine:latest".into()),
+ ..Default::default()
+ },
+ engine_kind: VmmKind::Native,
+ box_home: dir.path().join(empty_id.as_str()),
+ };
+ store.save(&empty_config, &BoxState::new()).unwrap();
+ let empty_declared = store.mounts(empty_id.as_str()).unwrap();
+ let (declared_out, volumes_out) =
+ prepare_volumes(Some(empty_declared), &empty_options, &volume_store)
+ .await
+ .unwrap();
+ assert!(
+ declared_out
+ .as_ref()
+ .is_some_and(|mounts| mounts.declarations.is_empty()),
+ "fast path must return empty Mounts unchanged"
+ );
+ assert!(volumes_out.is_empty());
+
+ // 3. Some(empty_declared) + non-empty options -> resolves user volumes.
+ let mount_src = dir.path().join("mount-src");
+ std::fs::create_dir(&mount_src).unwrap();
+ let with_mount = BoxOptions {
+ mounts: vec![MountSpec::bind_mount(
+ mount_src.to_string_lossy().as_ref(),
+ "/work",
+ )],
+ ..Default::default()
+ };
+ let empty_declared = store.mounts(empty_id.as_str()).unwrap();
+ let (declared_out, volumes_out) =
+ prepare_volumes(Some(empty_declared), &with_mount, &volume_store)
+ .await
+ .unwrap();
+ assert!(declared_out.is_some());
+ assert_eq!(volumes_out.len(), 1);
+ assert_eq!(volumes_out[0].guest_path, "/work");
+
+ // 4. Some(non_empty_declared) + empty options -> still runs check_sources().
+ let source_dir = dir.path().join("declared-src");
+ std::fs::create_dir(&source_dir).unwrap();
+ let declared_id = BoxIDMint::mint();
+ let declared_config = BoxConfig {
+ id: declared_id.clone(),
+ name: None,
+ created_at: Utc::now(),
+ container: ContainerRuntimeConfig {
+ id: ContainerID::new(),
+ },
+ options: BoxOptions {
+ rootfs: RootfsSpec::Image("alpine:latest".into()),
+ mounts: vec![MountSpec::bind_mount(
+ source_dir.to_string_lossy().as_ref(),
+ "/work",
+ )],
+ ..Default::default()
+ },
+ engine_kind: VmmKind::Native,
+ box_home: dir.path().join(declared_id.as_str()),
+ };
+ store.save(&declared_config, &BoxState::new()).unwrap();
+
+ // Removing the declared source directory after loading `Mounts` must fail via check_sources().
+ let non_empty_declared = store.mounts(declared_id.as_str()).unwrap();
+ std::fs::remove_dir(&source_dir).unwrap();
+ let err = prepare_volumes(Some(non_empty_declared), &empty_options, &volume_store)
+ .await
+ .unwrap_err();
+ assert!(
+ matches!(err, BoxliteError::InvalidState(_)),
+ "expected InvalidState when declared source is missing, got {err:?}"
+ );
+
+ // Replacing the declared source directory with a file after loading `Mounts` must also fail.
+ std::fs::create_dir(&source_dir).unwrap();
+ let non_empty_declared = store.mounts(declared_id.as_str()).unwrap();
+ std::fs::remove_dir(&source_dir).unwrap();
+ std::fs::write(&source_dir, b"not-a-dir").unwrap();
+ let err = prepare_volumes(Some(non_empty_declared), &empty_options, &volume_store)
+ .await
+ .unwrap_err();
+ assert!(
+ matches!(err, BoxliteError::InvalidState(_)),
+ "expected InvalidState when declared source is a file, got {err:?}"
+ );
+ }
}
diff --git a/src/boxlite/src/rootfs/guest.rs b/src/boxlite/src/rootfs/guest.rs
index ac3814634..bd11136b1 100644
--- a/src/boxlite/src/rootfs/guest.rs
+++ b/src/boxlite/src/rootfs/guest.rs
@@ -1,6 +1,7 @@
//! Guest rootfs types and metadata.
use std::fs;
+use std::os::unix::fs::MetadataExt;
use std::path::{Path, PathBuf};
use boxlite_shared::errors::{BoxliteError, BoxliteResult};
@@ -13,7 +14,8 @@ use crate::images::{ImageDiskManager, ImageObject};
#[cfg(test)]
use crate::runtime::id::BaseDiskID;
use crate::runtime::id::BaseDiskIDMint;
-use crate::vmm::guest_artifacts::GuestArtifacts;
+use crate::util::find_binary;
+use crate::vmm::guest_artifacts::{GuestArtifacts, HOST_GUEST_MKE2FS, HOST_GUEST_RESIZE2FS};
use crate::vmm::guest_binary::GuestBinary;
/// A fully resolved and ready-to-use guest rootfs.
@@ -329,31 +331,39 @@ impl GuestRootfsManager {
/// Get or create the minimal guest rootfs from the standalone artifacts.
///
/// The minimal rootfs is just `boxlite-guest` plus the static
- /// `mke2fs`/`resize2fs`; it is built straight into an ext4 (no OCI image,
- /// nothing injected afterward) and cached content-addressed in `bases/`
- /// under the combined artifact hash, tracked and GC'd like the Debian rootfs.
- pub async fn get_or_create_minimal(
- &self,
- artifacts: &GuestArtifacts,
- ) -> BoxliteResult<GuestRootfs> {
- let key = Self::minimal_version_key(artifacts);
+ /// `mke2fs`/`resize2fs`. Check their metadata before opening the binaries;
+ /// only a miss needs to validate and copy the artifacts into a new ext4.
+ /// This is called on a blocking thread under the runtime's async OnceCell.
+ pub fn get_or_create_minimal(&self) -> BoxliteResult<GuestRootfs> {
+ self.get_or_create_minimal_at(&Self::minimal_artifact_paths()?)
+ }
+ fn get_or_create_minimal_at(&self, paths: &[PathBuf; 3]) -> BoxliteResult<GuestRootfs> {
+ let key = Self::minimal_version_key(paths)?;
if let Some(disk) = self.find(&key) {
tracing::debug!(version_key = %key, "get_or_create_minimal: cache hit");
return Self::disk_to_guest_rootfs(disk, Vec::new());
}
tracing::info!(version_key = %key, "get_or_create_minimal: cache miss — building");
- let disk = self.build_minimal_and_install(artifacts, &key).await?;
+ let [guest, mke2fs, resize2fs] = paths;
+ let guest = GuestBinary::resolve_at(guest.clone())?;
+ let artifacts = GuestArtifacts::resolve_at(&guest, mke2fs.clone(), resize2fs.clone())?;
+ tracing::debug!(
+ artifact_id = artifacts.id(),
+ "Validated minimal rootfs artifacts"
+ );
+ let disk = self.build_minimal_and_install(&artifacts, paths, &key)?;
Self::disk_to_guest_rootfs(disk, Vec::new())
}
/// Stage the artifacts into a tree, build an ext4, and install it through
/// the shared cache (`install`), so the minimal rootfs is tracked and GC'd
/// like the Debian rootfs.
- async fn build_minimal_and_install(
+ fn build_minimal_and_install(
&self,
artifacts: &GuestArtifacts,
+ paths: &[PathBuf; 3],
key: &str,
) -> BoxliteResult<Disk> {
let temp = tempfile::tempdir_in(&self.temp_dir).map_err(|e| {
@@ -366,17 +376,14 @@ impl GuestRootfsManager {
let tree_root = temp.path().join("rootfs");
stage_tree(&tree_root, artifacts)?;
+ // Don't publish a disk under a key for files replaced during staging.
+ if Self::minimal_version_key(paths)? != key {
+ return Err(BoxliteError::Storage(
+ "Guest artifacts changed while staging the minimal rootfs; retry startup".into(),
+ ));
+ }
let staged_path = temp.path().join("minimal-rootfs.ext4");
-
- // mke2fs runs as a subprocess plus disk I/O; keep it off the async path.
- let tree_for_build = tree_root.clone();
- let staged_for_build = staged_path.clone();
- let disk = tokio::task::spawn_blocking(move || {
- create_ext4_from_dir(&tree_for_build, &staged_for_build, 0)
- })
- .await
- .map_err(|e| BoxliteError::Storage(format!("minimal rootfs build task failed: {e}")))??;
-
+ let disk = create_ext4_from_dir(&tree_root, &staged_path, 0)?;
self.install(key, disk)
}
@@ -556,7 +563,7 @@ impl GuestRootfsManager {
/// Garbage-collect stale guest rootfs entries.
///
- /// Keeps the current minimal rootfs (keyed by the combined artifact id) and
+ /// Keeps the current minimal rootfs (keyed by artifact metadata) and
/// any base an existing box overlay still backs onto. Deletes everything else
/// — including OCI Debian rootfs bases, which the boot path no longer produces.
///
@@ -567,7 +574,7 @@ impl GuestRootfsManager {
// Propagate resolution failure: a transient error must not turn the
// current key into `None`, which would make gc_inner delete every cached
// rootfs as non-current.
- let current_minimal_key = GuestArtifacts::get()?.id().to_string();
+ let current_minimal_key = Self::minimal_version_key(&Self::minimal_artifact_paths()?)?;
let result = self.gc_inner(boxes_dir, Some(&current_minimal_key));
@@ -671,9 +678,41 @@ impl GuestRootfsManager {
format!("{}-{}", d, g)
}
- /// Version key for the minimal rootfs: the combined artifact content id.
- fn minimal_version_key(artifacts: &GuestArtifacts) -> String {
- artifacts.id().to_string()
+ fn minimal_artifact_paths() -> BoxliteResult<[PathBuf; 3]> {
+ Ok([
+ find_binary("boxlite-guest")?,
+ find_binary(HOST_GUEST_MKE2FS)?,
+ find_binary(HOST_GUEST_RESIZE2FS)?,
+ ])
+ }
+
+ /// Size and nanosecond timestamps catch in-place writes (even when mtime
+ /// is restored); device/inode also catch atomic replacement. Version the
+ /// key separately from the legacy content hashes in the same table.
+ fn minimal_version_key(paths: &[PathBuf; 3]) -> BoxliteResult<String> {
+ use sha2::{Digest, Sha256};
+
+ let mut hash = Sha256::new();
+ for path in paths {
+ let metadata = fs::metadata(path).map_err(|e| {
+ BoxliteError::Storage(format!(
+ "Cannot stat guest artifact {}: {e}",
+ path.display()
+ ))
+ })?;
+ for field in [metadata.dev(), metadata.ino(), metadata.len()] {
+ hash.update(field.to_le_bytes());
+ }
+ for field in [
+ metadata.mtime(),
+ metadata.mtime_nsec(),
+ metadata.ctime(),
+ metadata.ctime_nsec(),
+ ] {
+ hash.update(field.to_le_bytes());
+ }
+ }
+ Ok(format!("minimal-meta-v1-{}", hex::encode(hash.finalize())))
}
}
@@ -1199,8 +1238,8 @@ mod tests {
/// The full build must land the artifacts inside a real ext4 image, tracked
/// in the bases/ cache. Skipped without the host e2fsprogs binaries.
- #[tokio::test]
- async fn get_or_create_minimal_builds_ext4_with_artifacts() {
+ #[test]
+ fn get_or_create_minimal_builds_ext4_with_artifacts() {
use crate::util::find_binary;
if find_binary("mke2fs").is_err() || find_binary("debugfs").is_err() {
@@ -1210,11 +1249,17 @@ mod tests {
let dir = tempfile::tempdir().unwrap();
let artifacts = fake_artifacts(&dir);
+ let paths = [
+ artifacts.guest_path(),
+ artifacts.mke2fs().path(),
+ artifacts.resize2fs().path(),
+ ]
+ .map(Path::to_path_buf);
let temp_dir = dir.path().join("tmp");
std::fs::create_dir_all(&temp_dir).unwrap();
let mgr = make_mgr(dir.path().join("bases"), temp_dir);
- let rootfs = mgr.get_or_create_minimal(&artifacts).await.unwrap();
+ let rootfs = mgr.get_or_create_minimal_at(&paths).unwrap();
let Strategy::Disk { disk_path, .. } = rootfs.strategy else {
panic!("minimal rootfs must be disk-based");
};
@@ -1240,7 +1285,7 @@ mod tests {
}
// Second call is a cache hit — same path, no rebuild.
- let rootfs2 = mgr.get_or_create_minimal(&artifacts).await.unwrap();
+ let rootfs2 = mgr.get_or_create_minimal_at(&paths).unwrap();
let Strategy::Disk {
disk_path: disk_path2,
..
@@ -1250,4 +1295,41 @@ mod tests {
};
assert_eq!(disk_path, disk_path2);
}
+
+ #[test]
+ fn minimal_version_key_is_stable_and_changes_on_artifact_modification() {
+ let dir = tempfile::tempdir().unwrap();
+ let paths = [
+ dir.path().join("boxlite-guest"),
+ dir.path().join("guest-mke2fs"),
+ dir.path().join("guest-resize2fs"),
+ ];
+ for (i, path) in paths.iter().enumerate() {
+ std::fs::write(path, format!("artifact-{i}")).unwrap();
+ }
+
+ let initial = GuestRootfsManager::minimal_version_key(&paths).unwrap();
+ assert!(initial.starts_with("minimal-meta-v1-"));
+ assert_eq!(
+ initial,
+ GuestRootfsManager::minimal_version_key(&paths).unwrap(),
+ "unchanged artifacts must produce the same version key"
+ );
+
+ let mut prev = initial;
+ for (i, path) in paths.iter().enumerate() {
+ let staged = dir.path().join(format!("replacement-{i}"));
+ std::fs::write(&staged, format!("updated-artifact-{i}-v2")).unwrap();
+ std::fs::rename(&staged, path).unwrap();
+
+ let next = GuestRootfsManager::minimal_version_key(&paths).unwrap();
+ assert_ne!(
+ next,
+ prev,
+ "replacing artifact {} must invalidate minimal_version_key",
+ path.display()
+ );
+ prev = next;
+ }
+ }
}
diff --git a/src/boxlite/src/vmm/guest_artifacts.rs b/src/boxlite/src/vmm/guest_artifacts.rs
index 27425b041..582b3d663 100644
--- a/src/boxlite/src/vmm/guest_artifacts.rs
+++ b/src/boxlite/src/vmm/guest_artifacts.rs
@@ -6,29 +6,26 @@
//! `guest-resize2fs`) so they never shadow the *host* `mke2fs` bundled by
//! `e2fsprogs-sys` (resolved by `disk/ext4.rs` to build images).
//!
-//! [`GuestArtifacts`] is the single place all three are resolved, and the one
-//! value that binds the three host paths to their identity. The combined
-//! content identity (`id()`) keys the minimal-rootfs cache, so a rebuild of any
-//! one artifact moves the key — the same "path and identity from the same value"
-//! contract [`GuestBinary`] documents.
+//! [`GuestArtifacts`] binds and validates the three host paths together with
+//! their combined content identity (`id()`), used on a minimal-rootfs cache
+//! miss for validation, staging, and logging — the same "path and identity
+//! from the same value" contract [`GuestBinary`] documents.
use std::path::{Path, PathBuf};
-use std::sync::OnceLock;
use boxlite_shared::errors::{BoxliteError, BoxliteResult};
use sha2::{Digest, Sha256};
use super::guest_binary::GuestBinary;
use super::guest_check::validate_guest_bytes;
-use crate::util::find_binary;
/// Hex characters of the content digest used as the identity.
const ID_LEN: usize = 12;
/// Host-side name the guest `mke2fs` is embedded under.
-const HOST_GUEST_MKE2FS: &str = "guest-mke2fs";
+pub(crate) const HOST_GUEST_MKE2FS: &str = "guest-mke2fs";
/// Host-side name the guest `resize2fs` is embedded under.
-const HOST_GUEST_RESIZE2FS: &str = "guest-resize2fs";
+pub(crate) const HOST_GUEST_RESIZE2FS: &str = "guest-resize2fs";
/// A resolved guest tool, identified by its host path.
pub struct GuestTool {
@@ -51,22 +48,6 @@ pub struct GuestArtifacts {
}
impl GuestArtifacts {
- /// Resolve the guest artifacts once per process.
- ///
- /// Only success is memoised, mirroring [`GuestBinary::get`]: a failure here
- /// (e.g. the guest tools were not built) must not be cached as a rendered
- /// string that hides the actionable error. Callers run this in a background
- /// best-effort task, so a retry on a later boot costs nothing that matters.
- pub fn get() -> BoxliteResult<&'static Self> {
- static INSTANCE: OnceLock<GuestArtifacts> = OnceLock::new();
-
- if let Some(artifacts) = INSTANCE.get() {
- return Ok(artifacts);
- }
- let resolved = Self::resolve()?;
- Ok(INSTANCE.get_or_init(|| resolved))
- }
-
/// Host path to the `boxlite-guest` binary.
pub fn guest_path(&self) -> &Path {
&self.guest_path
@@ -82,23 +63,12 @@ impl GuestArtifacts {
&self.resize2fs
}
- /// Combined content identity, for cache keys and log fields.
+ /// Combined content identity, for miss-path validation and log fields.
pub fn id(&self) -> &str {
&self.combined_id
}
- fn resolve() -> BoxliteResult<Self> {
- let guest = GuestBinary::get()?;
- let mke2fs = find_binary(HOST_GUEST_MKE2FS)?;
- let resize2fs = find_binary(HOST_GUEST_RESIZE2FS)?;
- Self::resolve_at(guest, mke2fs, resize2fs)
- }
-
/// Resolve and identify the artifacts from explicit paths.
- ///
- /// Split from [`Self::resolve`] so the read-hash-identify step can be
- /// exercised against known files without touching `BOXLITE_RUNTIME_DIR` or
- /// the process-wide cache.
pub(crate) fn resolve_at(
guest: &GuestBinary,
mke2fs: PathBuf,
diff --git a/src/boxlite/tests/native_vmm.rs b/src/boxlite/tests/native_vmm.rs
index b4e99e9d5..a7d68495a 100644
--- a/src/boxlite/tests/native_vmm.rs
+++ b/src/boxlite/tests/native_vmm.rs
@@ -241,7 +241,7 @@ async fn resize_with_lost_shim_reply(
async fn online_resize_allows_other_execs_to_exit() {
const ORIGINAL_TOOL: &str = "BOXLITE_TEST_ORIGINAL_RESIZE2FS";
let Some(original) = std::env::var_os(ORIGINAL_TOOL) else {
- // GuestArtifacts caches its resolution per process. Override only this VM's tool.
+ // Override BOXLITE_RUNTIME_DIR in a child process so only this test VM's tool resolution sees it.
let tool = boxlite::util::find_binary("guest-resize2fs").unwrap();
let shim = boxlite::util::find_binary("boxlite-shim").unwrap();
let probe = std::env::var_os("VMM_GUEST_PROBE").expect("set VMM_GUEST_PROBE");