runtime-rs: enable dragonball hypervisor support initrd

enable the dragonball support initrd.

Fixes: #10023

Signed-off-by: Fupan Li <fupan.lfp@antgroup.com>
This commit is contained in:
Fupan Li 2024-07-17 14:28:52 +08:00
parent 4fbf9d67a5
commit e3f0d2a751
4 changed files with 55 additions and 39 deletions

View File

@ -122,14 +122,13 @@ impl ConfigPlugin for DragonballConfig {
"Guest kernel image for dragonball hypervisor is empty" "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!( 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() { if !db.boot_info.firmware.is_empty() {
return Err(eother!( return Err(eother!(
"Firmware for dragonball hypervisor should be empty" "Firmware for dragonball hypervisor should be empty"

View File

@ -16,6 +16,7 @@ path = "@DBPATH@"
ctlpath = "@DBCTLPATH@" ctlpath = "@DBCTLPATH@"
kernel = "@KERNELPATH_DB@" kernel = "@KERNELPATH_DB@"
image = "@IMAGEPATH@" image = "@IMAGEPATH@"
# initrd = "@INITRDPATH@"
# rootfs filesystem type: # rootfs filesystem type:
# - ext4 (default) # - ext4 (default)

View File

@ -31,6 +31,7 @@ use std::cmp::Ordering;
use std::{collections::HashSet, fs::create_dir_all}; use std::{collections::HashSet, fs::create_dir_all};
const DRAGONBALL_KERNEL: &str = "vmlinux"; const DRAGONBALL_KERNEL: &str = "vmlinux";
const DRAGONBALL_INITRD: &str = "initrd";
const DRAGONBALL_ROOT_FS: &str = "rootfs"; const DRAGONBALL_ROOT_FS: &str = "rootfs";
const BALLOON_DEVICE_ID: &str = "balloon0"; const BALLOON_DEVICE_ID: &str = "balloon0";
const MEM_DEVICE_ID: &str = "memmr0"; const MEM_DEVICE_ID: &str = "memmr0";
@ -121,15 +122,19 @@ impl DragonballInner {
self.set_vm_base_config().context("set vm base config")?; 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 // get kernel params
let mut kernel_params = KernelParams::new(self.config.debug_info.enable_debug); let mut kernel_params = KernelParams::new(self.config.debug_info.enable_debug);
kernel_params.append(&mut KernelParams::new_rootfs_kernel_params(
&rootfs_driver, if self.config.boot_info.initrd.is_empty() {
&self.config.boot_info.rootfs_type, // 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( kernel_params.append(&mut KernelParams::from_string(
&self.config.boot_info.kernel_params, &self.config.boot_info.kernel_params,
)); ));
@ -141,10 +146,7 @@ impl DragonballInner {
} }
info!(sl!(), "prepared kernel_params={:?}", kernel_params); info!(sl!(), "prepared kernel_params={:?}", kernel_params);
// set boot source
let kernel_path = self.config.boot_info.kernel.clone();
self.set_boot_source( self.set_boot_source(
&kernel_path,
&kernel_params &kernel_params
.to_string() .to_string()
.context("kernel params to string")?, .context("kernel params to string")?,
@ -259,16 +261,33 @@ impl DragonballInner {
Ok(abs_path) 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!( info!(
sl!(), 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 { let mut boot_cfg = BootSourceConfig {
kernel_path: self kernel_path: self
.get_resource(kernel_path, DRAGONBALL_KERNEL) .get_resource(kernel_path, DRAGONBALL_KERNEL)
.context("get resource")?, .context("get kernel resource")?,
initrd_path: initrd,
..Default::default() ..Default::default()
}; };

View File

@ -133,12 +133,14 @@ impl VirtSandbox {
resource_configs.push(virtio_fs_config); resource_configs.push(virtio_fs_config);
// prepare VM rootfs device config // prepare VM rootfs device config
let vm_rootfs = ResourceConfig::VmRootfs( if let Some(block_config) = self
self.prepare_rootfs_config() .prepare_rootfs_config()
.await .await
.context("failed to prepare rootfs device config")?, .context("failed to prepare rootfs device config")?
); {
resource_configs.push(vm_rootfs); let vm_rootfs = ResourceConfig::VmRootfs(block_config);
resource_configs.push(vm_rootfs);
}
Ok(resource_configs) Ok(resource_configs)
} }
@ -243,28 +245,23 @@ impl VirtSandbox {
Ok(()) Ok(())
} }
async fn prepare_rootfs_config(&self) -> Result<BlockConfig> { async fn prepare_rootfs_config(&self) -> Result<Option<BlockConfig>> {
let boot_info = self.hypervisor.hypervisor_config().await.boot_info; let boot_info = self.hypervisor.hypervisor_config().await.boot_info;
let image = { if !boot_info.initrd.is_empty() {
let initrd_path = boot_info.initrd.clone(); return Ok(None);
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"))
}
} }
.context("get image")?;
Ok(BlockConfig { if boot_info.image.is_empty() {
path_on_host: image, return Err(anyhow!("both of image and initrd isn't set"));
}
Ok(Some(BlockConfig {
path_on_host: boot_info.image.clone(),
is_readonly: true, is_readonly: true,
driver_option: boot_info.vm_rootfs_driver, driver_option: boot_info.vm_rootfs_driver,
..Default::default() ..Default::default()
}) }))
} }
async fn prepare_vm_socket_config(&self) -> Result<ResourceConfig> { async fn prepare_vm_socket_config(&self) -> Result<ResourceConfig> {