mirror of
https://github.com/kata-containers/kata-containers.git
synced 2026-04-10 14:02:59 +00:00
kata-deploy: Set block_device_driver to virtio-blk for EROFS
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 <ffidencio@nvidia.com>
This commit is contained in:
committed by
Alex Lyn
parent
f65cfe302a
commit
af9bc47f1d
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user