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,30 +421,32 @@ fn chroot(command: ChrootCommand) -> Result<(), Error> {
fn qemu(command: QemuCommand) -> Result<(), Error> {
let qemu = Tool::find("qemu-system-x86_64")?;
let err = qemu
.execute()
.args(&[
"-enable-kvm",
"-cpu",
"host",
"-m",
"4G",
"-netdev",
"user,id=user.0",
"-device",
"virtio-net-pci,netdev=user.0",
"-device",
"qemu-xhci,id=xhci",
"-device",
"usb-tablet,bus=xhci.0",
"-drive",
])
.arg(format!(
"file={},if=virtio,format=raw",
command.block_device.display()
))
.args(command.args)
.exec();
let mut run = qemu.execute();
run.args(&[
"-m",
"4G",
"-netdev",
"user,id=user.0",
"-device",
"virtio-net-pci,netdev=user.0",
"-device",
"qemu-xhci,id=xhci",
"-device",
"usb-tablet,bus=xhci.0",
"-drive",
])
.arg(format!(
"file={},if=virtio,format=raw",
command.block_device.display()
))
.args(command.args);
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)?
}