diff --git a/src/libs/kata-types/src/config/hypervisor/dragonball.rs b/src/libs/kata-types/src/config/hypervisor/dragonball.rs index 4057319459..35be68f523 100644 --- a/src/libs/kata-types/src/config/hypervisor/dragonball.rs +++ b/src/libs/kata-types/src/config/hypervisor/dragonball.rs @@ -122,14 +122,13 @@ impl ConfigPlugin for DragonballConfig { "Guest kernel image for dragonball hypervisor is empty" )); } - if db.boot_info.image.is_empty() { + + if db.boot_info.image.is_empty() && db.boot_info.initrd.is_empty() { return Err(eother!( - "Guest boot image for dragonball hypervisor is empty" + "Both of guest boot image and initrd for dragonball hypervisor is empty" )); } - if !db.boot_info.initrd.is_empty() { - return Err(eother!("Initrd for dragonball hypervisor should be empty")); - } + if !db.boot_info.firmware.is_empty() { return Err(eother!( "Firmware for dragonball hypervisor should be empty" diff --git a/src/runtime-rs/config/configuration-dragonball.toml.in b/src/runtime-rs/config/configuration-dragonball.toml.in index 6ed69e6e14..b2a226f202 100644 --- a/src/runtime-rs/config/configuration-dragonball.toml.in +++ b/src/runtime-rs/config/configuration-dragonball.toml.in @@ -16,6 +16,7 @@ path = "@DBPATH@" ctlpath = "@DBCTLPATH@" kernel = "@KERNELPATH_DB@" image = "@IMAGEPATH@" +# initrd = "@INITRDPATH@" # rootfs filesystem type: # - ext4 (default) diff --git a/src/runtime-rs/crates/hypervisor/src/dragonball/inner.rs b/src/runtime-rs/crates/hypervisor/src/dragonball/inner.rs index e0bd30e8e8..83f875e126 100644 --- a/src/runtime-rs/crates/hypervisor/src/dragonball/inner.rs +++ b/src/runtime-rs/crates/hypervisor/src/dragonball/inner.rs @@ -31,6 +31,7 @@ use std::cmp::Ordering; use std::{collections::HashSet, fs::create_dir_all}; const DRAGONBALL_KERNEL: &str = "vmlinux"; +const DRAGONBALL_INITRD: &str = "initrd"; const DRAGONBALL_ROOT_FS: &str = "rootfs"; const BALLOON_DEVICE_ID: &str = "balloon0"; const MEM_DEVICE_ID: &str = "memmr0"; @@ -121,15 +122,19 @@ impl DragonballInner { self.set_vm_base_config().context("set vm base config")?; - // get rootfs driver - let rootfs_driver = self.config.blockdev_info.block_device_driver.clone(); - // get kernel params let mut kernel_params = KernelParams::new(self.config.debug_info.enable_debug); - kernel_params.append(&mut KernelParams::new_rootfs_kernel_params( - &rootfs_driver, - &self.config.boot_info.rootfs_type, - )?); + + if self.config.boot_info.initrd.is_empty() { + // get rootfs driver + let rootfs_driver = self.config.blockdev_info.block_device_driver.clone(); + + kernel_params.append(&mut KernelParams::new_rootfs_kernel_params( + &rootfs_driver, + &self.config.boot_info.rootfs_type, + )?); + } + kernel_params.append(&mut KernelParams::from_string( &self.config.boot_info.kernel_params, )); @@ -141,10 +146,7 @@ impl DragonballInner { } info!(sl!(), "prepared kernel_params={:?}", kernel_params); - // set boot source - let kernel_path = self.config.boot_info.kernel.clone(); self.set_boot_source( - &kernel_path, &kernel_params .to_string() .context("kernel params to string")?, @@ -259,16 +261,33 @@ impl DragonballInner { Ok(abs_path) } - fn set_boot_source(&mut self, kernel_path: &str, kernel_params: &str) -> Result<()> { + fn set_boot_source(&mut self, kernel_params: &str) -> Result<()> { + // set boot source + let kernel_path = self.config.boot_info.kernel.as_str(); + let initrd_path = self.config.boot_info.initrd.as_str(); + info!( sl!(), - "kernel path {} kernel params {}", kernel_path, kernel_params + "kernel path {}, initrd path {}, kernel params {}", + kernel_path, + initrd_path, + kernel_params ); + let mut initrd = None; + + if !initrd_path.is_empty() { + initrd = Some( + self.get_resource(initrd_path, DRAGONBALL_INITRD) + .context("get initrd resource")?, + ); + } + let mut boot_cfg = BootSourceConfig { kernel_path: self .get_resource(kernel_path, DRAGONBALL_KERNEL) - .context("get resource")?, + .context("get kernel resource")?, + initrd_path: initrd, ..Default::default() }; diff --git a/src/runtime-rs/crates/runtimes/virt_container/src/sandbox.rs b/src/runtime-rs/crates/runtimes/virt_container/src/sandbox.rs index d731eb0152..686aa7ee1c 100644 --- a/src/runtime-rs/crates/runtimes/virt_container/src/sandbox.rs +++ b/src/runtime-rs/crates/runtimes/virt_container/src/sandbox.rs @@ -133,12 +133,14 @@ impl VirtSandbox { resource_configs.push(virtio_fs_config); // prepare VM rootfs device config - let vm_rootfs = ResourceConfig::VmRootfs( - self.prepare_rootfs_config() - .await - .context("failed to prepare rootfs device config")?, - ); - resource_configs.push(vm_rootfs); + if let Some(block_config) = self + .prepare_rootfs_config() + .await + .context("failed to prepare rootfs device config")? + { + let vm_rootfs = ResourceConfig::VmRootfs(block_config); + resource_configs.push(vm_rootfs); + } Ok(resource_configs) } @@ -243,28 +245,23 @@ impl VirtSandbox { Ok(()) } - async fn prepare_rootfs_config(&self) -> Result { + async fn prepare_rootfs_config(&self) -> Result> { let boot_info = self.hypervisor.hypervisor_config().await.boot_info; - let image = { - let initrd_path = boot_info.initrd.clone(); - let image_path = boot_info.image; - if !initrd_path.is_empty() { - Ok(initrd_path) - } else if !image_path.is_empty() { - Ok(image_path) - } else { - Err(anyhow!("failed to get image")) - } + if !boot_info.initrd.is_empty() { + return Ok(None); } - .context("get image")?; - Ok(BlockConfig { - path_on_host: image, + if boot_info.image.is_empty() { + return Err(anyhow!("both of image and initrd isn't set")); + } + + Ok(Some(BlockConfig { + path_on_host: boot_info.image.clone(), is_readonly: true, driver_option: boot_info.vm_rootfs_driver, ..Default::default() - }) + })) } async fn prepare_vm_socket_config(&self) -> Result {