From 34020614e13600af04f88d0b674ca4f53f419332 Mon Sep 17 00:00:00 2001 From: Roey Darwish Dror Date: Sun, 11 Aug 2019 15:46:19 +0300 Subject: [PATCH] Enable KVM only if available --- src/main.rs | 50 ++++++++++++++++++++++++++------------------------ 1 file changed, 26 insertions(+), 24 deletions(-) diff --git a/src/main.rs b/src/main.rs index a5894a4..5130514 100644 --- a/src/main.rs +++ b/src/main.rs @@ -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)? }