From af9bc47f1dbdb77f5e0d55df1cea2520ea38efa8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabiano=20Fid=C3=AAncio?= Date: Thu, 9 Apr 2026 22:28:07 +0200 Subject: [PATCH] kata-deploy: Set block_device_driver to virtio-blk for EROFS MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The EROFS multi-layer rootfs implementation in runtime-rs only supports virtio-blk block devices, but the default QEMU block_device_driver is virtio-scsi. When kata-deploy configures a Rust shim with the erofs snapshotter, generate a drop-in config file that overrides the block device driver to virtio-blk. Signed-off-by: Fabiano Fidêncio --- .../binary/src/artifacts/install.rs | 62 +++++++++++++++++++ 1 file changed, 62 insertions(+) diff --git a/tools/packaging/kata-deploy/binary/src/artifacts/install.rs b/tools/packaging/kata-deploy/binary/src/artifacts/install.rs index 701339e9b1..7167caf01a 100644 --- a/tools/packaging/kata-deploy/binary/src/artifacts/install.rs +++ b/tools/packaging/kata-deploy/binary/src/artifacts/install.rs @@ -71,6 +71,30 @@ fn get_hypervisor_name(shim: &str) -> Result<&str> { } } +/// Return the correct virtio-blk driver name for the current architecture. +/// +/// runtime-rs only accepts the fully-qualified variants (`virtio-blk-pci`, +/// `virtio-blk-ccw`, …); plain `"virtio-blk"` is rejected at config load time. +fn erofs_virtio_blk_driver() -> &'static str { + match std::env::consts::ARCH { + "s390x" => "virtio-blk-ccw", + _ => "virtio-blk-pci", + } +} + +/// Look up the snapshotter assigned to a shim from the mapping string. +/// The mapping format is "shim1:snapshotter1,shim2:snapshotter2". +fn get_snapshotter_for_shim<'a>(mapping: &'a str, shim: &str) -> Option<&'a str> { + mapping.split(',').find_map(|entry| { + let parts: Vec<&str> = entry.split(':').collect(); + if parts.len() == 2 && parts[0].trim() == shim { + Some(parts[1].trim()) + } else { + None + } + }) +} + pub async fn install_artifacts(config: &Config, container_runtime: &str) -> Result<()> { info!("copying kata artifacts onto host"); @@ -618,6 +642,22 @@ async fn configure_shim_config(config: &Config, shim: &str, container_runtime: & configure_experimental_force_guest_pull(&kata_config_file).await?; } + if utils::is_rust_shim(shim) { + if let Some(ref mapping) = config.snapshotter_handler_mapping_for_arch { + if get_snapshotter_for_shim(mapping, shim) == Some("erofs") { + let hypervisor_name = get_hypervisor_name(shim)?; + let blk_driver = erofs_virtio_blk_driver(); + let content = format!( + "# EROFS snapshotter requires a virtio-blk block device driver\n\ + # Generated by kata-deploy\n\n\ + [hypervisor.{hypervisor_name}]\n\ + block_device_driver = \"{blk_driver}\"\n" + ); + write_drop_in_file(&config_d_dir, "25-erofs-block-driver.toml", &content)?; + } + } + } + Ok(()) } @@ -1095,6 +1135,28 @@ mod tests { ); } + #[rstest] + #[case( + "qemu-coco-dev-runtime-rs:erofs", + "qemu-coco-dev-runtime-rs", + Some("erofs") + )] + #[case( + "qemu:nydus,qemu-coco-dev-runtime-rs:erofs", + "qemu-coco-dev-runtime-rs", + Some("erofs") + )] + #[case("qemu:nydus,qemu-coco-dev-runtime-rs:erofs", "qemu", Some("nydus"))] + #[case("qemu:nydus", "qemu-coco-dev-runtime-rs", None)] + #[case("", "qemu-coco-dev-runtime-rs", None)] + fn test_get_snapshotter_for_shim( + #[case] mapping: &str, + #[case] shim: &str, + #[case] expected: Option<&str>, + ) { + assert_eq!(get_snapshotter_for_shim(mapping, shim), expected); + } + #[test] fn test_copy_artifacts_overwrites_existing_files() { use std::fs;