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> { 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(&[ "-m",
"-enable-kvm", "4G",
"-cpu", "-netdev",
"host", "user,id=user.0",
"-m", "-device",
"4G", "virtio-net-pci,netdev=user.0",
"-netdev", "-device",
"user,id=user.0", "qemu-xhci,id=xhci",
"-device", "-device",
"virtio-net-pci,netdev=user.0", "usb-tablet,bus=xhci.0",
"-device", "-drive",
"qemu-xhci,id=xhci", ])
"-device", .arg(format!(
"usb-tablet,bus=xhci.0", "file={},if=virtio,format=raw",
"-drive", command.block_device.display()
]) ))
.arg(format!( .args(command.args);
"file={},if=virtio,format=raw",
command.block_device.display() if PathBuf::from("/dev/kvm").exists() {
)) debug!("KVM is enabled");
.args(command.args) run.args(&["-enable-kvm", "-cpu", "host"]);
.exec(); }
let err = run.exec();
Err(err).context(ErrorKind::Qemu)? Err(err).context(ErrorKind::Qemu)?
} }