79 lines
3.1 KiB
Diff
79 lines
3.1 KiB
Diff
From 4761842ceae0c8ac766b04c8e7bfbb7396e802c4 Mon Sep 17 00:00:00 2001
|
|
From: yezengruan <yezengruan@huawei.com>
|
|
Date: Fri, 3 Feb 2023 14:26:34 +0800
|
|
Subject: [PATCH] support parameter -accel
|
|
|
|
The libvirt v7.10.0 (commit id d20ebdda28) changed `-machine accel=XXX`
|
|
to `-accel=XXX`, let's add `-accel` parameter support for compatibility
|
|
with libvirt.
|
|
|
|
Signed-off-by: yezengruan <yezengruan@huawei.com>
|
|
---
|
|
machine_manager/src/cmdline.rs | 8 ++++++++
|
|
machine_manager/src/config/machine_config.rs | 16 ++++++++++++++++
|
|
2 files changed, 24 insertions(+)
|
|
|
|
diff --git a/machine_manager/src/cmdline.rs b/machine_manager/src/cmdline.rs
|
|
index 7e61a40b..8c5eb26b 100644
|
|
--- a/machine_manager/src/cmdline.rs
|
|
+++ b/machine_manager/src/cmdline.rs
|
|
@@ -91,6 +91,13 @@ pub fn create_args_parser<'a>() -> ArgParser<'a> {
|
|
.help("selects emulated machine and set properties")
|
|
.takes_value(true),
|
|
)
|
|
+ .arg(
|
|
+ Arg::with_name("accel")
|
|
+ .long("accel")
|
|
+ .value_name("[accel]")
|
|
+ .help("select accelerator, only 'kvm' is supported now.")
|
|
+ .takes_value(true),
|
|
+ )
|
|
.arg(
|
|
Arg::with_name("smp")
|
|
.long("smp")
|
|
@@ -406,6 +413,7 @@ pub fn create_vmconfig(args: &ArgMatches) -> Result<VmConfig> {
|
|
// Parse cmdline args which need to set in VmConfig
|
|
add_args_to_config!((args.value_of("name")), vm_cfg, add_name);
|
|
add_args_to_config!((args.value_of("machine")), vm_cfg, add_machine);
|
|
+ add_args_to_config!((args.value_of("accel")), vm_cfg, add_accel);
|
|
add_args_to_config!((args.value_of("memory")), vm_cfg, add_memory);
|
|
add_args_to_config!((args.value_of("mem-path")), vm_cfg, add_mem_path);
|
|
add_args_to_config!((args.value_of("smp")), vm_cfg, add_cpu);
|
|
diff --git a/machine_manager/src/config/machine_config.rs b/machine_manager/src/config/machine_config.rs
|
|
index 33755519..d9280b22 100644
|
|
--- a/machine_manager/src/config/machine_config.rs
|
|
+++ b/machine_manager/src/config/machine_config.rs
|
|
@@ -193,6 +193,7 @@ impl VmConfig {
|
|
}
|
|
|
|
if let Some(accel) = cmd_parser.get_value::<String>("accel")? {
|
|
+ // Libvirt checks the parameter types of 'kvm', 'kvm:tcg' and 'tcg'.
|
|
if accel.ne("kvm:tcg") && accel.ne("tcg") && accel.ne("kvm") {
|
|
bail!("Only \'kvm\', \'kvm:tcg\' and \'tcg\' are supported for \'accel\' of \'machine\'");
|
|
}
|
|
@@ -224,6 +225,21 @@ impl VmConfig {
|
|
Ok(())
|
|
}
|
|
|
|
+ /// Add '-accel' accelerator config to `VmConfig`.
|
|
+ pub fn add_accel(&mut self, accel_config: &str) -> Result<()> {
|
|
+ let mut cmd_parser = CmdParser::new("accel");
|
|
+ cmd_parser.push("");
|
|
+ cmd_parser.parse(accel_config)?;
|
|
+
|
|
+ if let Some(accel) = cmd_parser.get_value::<String>("")? {
|
|
+ if accel.ne("kvm") {
|
|
+ bail!("Only \'kvm\' is supported for \'accel\'");
|
|
+ }
|
|
+ }
|
|
+
|
|
+ Ok(())
|
|
+ }
|
|
+
|
|
/// Add '-m' memory config to `VmConfig`.
|
|
pub fn add_memory(&mut self, mem_config: &str) -> Result<()> {
|
|
let mut cmd_parser = CmdParser::new("m");
|
|
--
|
|
2.27.0
|
|
|