Enable KVM only if available

This commit is contained in:
Roey Darwish Dror 2019-08-11 15:46:19 +03:00
parent 4e12052f5a
commit 34020614e1

View File

@ -421,12 +421,8 @@ fn chroot(command: ChrootCommand) -> Result<(), Error> {
fn qemu(command: QemuCommand) -> Result<(), Error> { fn qemu(command: QemuCommand) -> Result<(), Error> {
let qemu = Tool::find("qemu-system-x86_64")?; let qemu = Tool::find("qemu-system-x86_64")?;
let err = qemu let mut run = qemu.execute();
.execute() run.args(&[
.args(&[
"-enable-kvm",
"-cpu",
"host",
"-m", "-m",
"4G", "4G",
"-netdev", "-netdev",
@ -443,8 +439,14 @@ fn qemu(command: QemuCommand) -> Result<(), Error> {
"file={},if=virtio,format=raw", "file={},if=virtio,format=raw",
command.block_device.display() command.block_device.display()
)) ))
.args(command.args) .args(command.args);
.exec();
if PathBuf::from("/dev/kvm").exists() {
debug!("KVM is enabled");
run.args(&["-enable-kvm", "-cpu", "host"]);
}
let err = run.exec();
Err(err).context(ErrorKind::Qemu)? Err(err).context(ErrorKind::Qemu)?
} }