Allow QEMU to fall back

reviewable/pr1080/r1
Tamir Duberstein 3 months ago
parent 05623a0eb7
commit e3bfeb9dd6

@ -1,9 +1,8 @@
use std::{ use std::{
env::consts::{ARCH, OS},
ffi::OsString, ffi::OsString,
fmt::Write as _, fmt::Write as _,
fs::{copy, create_dir_all, OpenOptions}, fs::{copy, create_dir_all, OpenOptions},
io::{BufRead as _, BufReader, ErrorKind, Write as _}, io::{BufRead as _, BufReader, Write as _},
path::{Path, PathBuf}, path::{Path, PathBuf},
process::{Child, ChildStdin, Command, Output, Stdio}, process::{Child, ChildStdin, Command, Output, Stdio},
sync::{Arc, Mutex}, sync::{Arc, Mutex},
@ -358,28 +357,8 @@ pub fn run(opts: Options) -> Result<()> {
if let Some(cpu) = cpu { if let Some(cpu) = cpu {
qemu.args(["-cpu", cpu]); qemu.args(["-cpu", cpu]);
} }
if guest_arch == ARCH { for accel in ["kvm", "hvf", "tcg"] {
match OS { qemu.args(["-accel", accel]);
"linux" => {
const KVM: &str = "/dev/kvm";
match OpenOptions::new().read(true).write(true).open(KVM) {
Ok(_file) => {
qemu.args(["-accel", "kvm"]);
}
Err(error) => match error.kind() {
ErrorKind::NotFound | ErrorKind::PermissionDenied => {}
_kind => {
return Err(error)
.with_context(|| format!("failed to open {KVM}"));
}
},
}
}
"macos" => {
qemu.args(["-accel", "hvf"]);
}
os => bail!("unsupported OS: {os}"),
}
} }
let console = OsString::from(console); let console = OsString::from(console);
let mut kernel_args = std::iter::once(("console", &console)) let mut kernel_args = std::iter::once(("console", &console))

Loading…
Cancel
Save