Let OSDK allow specifying additional boot drive options

This commit is contained in:
Zhang Junyang
2024-06-05 14:34:08 +00:00
committed by Tate, Hongliang Tian
parent 37e23a16a3
commit 74e4623e70
4 changed files with 48 additions and 4 deletions

View File

@ -219,17 +219,30 @@ impl Bundle {
BootMethod::GrubRescueIso => {
let vm_image = self.manifest.vm_image.as_ref().unwrap();
assert!(matches!(vm_image.typ(), AsterVmImageType::GrubIso(_)));
let bootdev_opts = action
.qemu
.bootdev_append_options
.as_deref()
.unwrap_or(",index=2,media=cdrom");
qemu_cmd.arg("-drive").arg(format!(
"file={},index=2,media=cdrom",
self.path.join(vm_image.path()).to_string_lossy()
"file={},format=raw{}",
self.path.join(vm_image.path()).to_string_lossy(),
bootdev_opts,
));
}
BootMethod::GrubQcow2 => {
let vm_image = self.manifest.vm_image.as_ref().unwrap();
assert!(matches!(vm_image.typ(), AsterVmImageType::Qcow2(_)));
// FIXME: this doesn't work for regular QEMU, but may work for TDX.
let bootdev_opts = action
.qemu
.bootdev_append_options
.as_deref()
.unwrap_or(",if=virtio");
qemu_cmd.arg("-drive").arg(format!(
"file={},index=0,media=disk,format=qcow2",
self.path.join(vm_image.path()).to_string_lossy()
"file={},format=qcow2{}",
self.path.join(vm_image.path()).to_string_lossy(),
bootdev_opts,
));
}
};

View File

@ -309,6 +309,13 @@ pub struct CommonArgs {
global = true
)]
pub boot_method: Option<BootMethod>,
#[arg(
long = "bootdev-append-options",
help = "Additional QEMU `-drive` options for the boot device",
value_name = "OPTIONS",
global = true
)]
pub bootdev_append_options: Option<String>,
#[arg(
long = "display-grub-menu",
help = "Display the GRUB menu if booting with GRUB",

View File

@ -72,6 +72,9 @@ fn apply_args_before_finalize(action_scheme: &mut ActionScheme, args: &CommonArg
if let Some(path) = &args.qemu_exe {
qemu.path = Some(path.clone());
}
if let Some(bootdev_options) = &args.bootdev_append_options {
qemu.bootdev_append_options = Some(bootdev_options.clone());
}
}
}

View File

@ -16,6 +16,20 @@ pub struct QemuScheme {
/// The additional arguments for running QEMU, in the form of raw
/// command line arguments.
pub args: Option<String>,
/// The additional qemu argument after the `-drive` option for the
/// boot device, in the form of raw command line arguments, comma
/// included. For example, `",if=virtio,media=disk,index=2"`.
/// The `format` and the `file` options are not allowed to set.
///
/// This option only works with [`super::BootMethod::GrubQcow2`] and
/// [`super::BootMethod::GrubRescueIso`].
///
/// This option exist because different firmwares may need
/// different interface types for the boot drive.
///
/// See <https://www.qemu.org/docs/master/system/invocation.html>
/// for details about `-drive` option.
pub bootdev_append_options: Option<String>,
/// The path of qemu
pub path: Option<PathBuf>,
}
@ -23,6 +37,11 @@ pub struct QemuScheme {
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct Qemu {
pub args: String,
/// This finalized config has a unorthodox `Option` because
/// we cannot provide a default value for it. The default
/// value is determined by the final running routine
/// [`crate::bundle::Bundle::run`].
pub bootdev_append_options: Option<String>,
pub path: PathBuf,
}
@ -30,6 +49,7 @@ impl Default for Qemu {
fn default() -> Self {
Qemu {
args: String::new(),
bootdev_append_options: None,
path: PathBuf::from(get_default_arch().system_qemu()),
}
}
@ -63,6 +83,7 @@ impl QemuScheme {
pub fn finalize(self, arch: Arch) -> Qemu {
Qemu {
args: self.args.unwrap_or_default(),
bootdev_append_options: self.bootdev_append_options,
path: self.path.unwrap_or(PathBuf::from(arch.system_qemu())),
}
}