[elbe-devel] [PATCH 1/1] Fix libvirt emulator qemu-kvm for x86_64

Olivier Dion dion at linutronix.de
Mon Feb 3 02:23:43 CET 2020


libvirt is looking for file "/usr/bin/qemu-system-x86_64 -enable-kvm".
See the following traceback:

----------------------------------------------------------------------
Traceback (most recent call last):
File "./elbe", line 55, in <module>
cmdmod.run_command(sys.argv[2:])
File "/home/olivier/linutronix/elbe/elbepack/commands/initvm.py", \
line 98, in run_command
action.execute(directory, opt, args[1:])
File "/home/olivier/linutronix/elbe/elbepack/initvmaction.py", \
line 560, in execute
self.conn.defineXML(xml)
File "/usr/lib/python3.8/site-packages/libvirt.py", line 3941, \
in defineXML
if ret is None:raise libvirtError('virDomainDefineXML() failed', \
conn=self)
libvirt.libvirtError: Cannot check QEMU binary \
/usr/bin/qemu-system-x86_64 -enable-kvm: No such file or directory
----------------------------------------------------------------------

In order to pass arguments to the emulator, 'find_kvm_exe()' returns a
dict with the informations about the qemu executable.  These
informations are then used in the 'libvirt.xml.mako' template to
generate the proper XML node.

Signed-off-by: Olivier Dion <dion at linutronix.de>
---
 elbepack/init/libvirt.xml.mako |  5 +++++
 elbepack/kvm.py                | 26 +++++++++++++++++++++++---
 elbepack/xmldefaults.py        |  5 +++--
 3 files changed, 31 insertions(+), 5 deletions(-)

diff --git a/elbepack/init/libvirt.xml.mako b/elbepack/init/libvirt.xml.mako
index cafa385fe..801590058 100644
--- a/elbepack/init/libvirt.xml.mako
+++ b/elbepack/init/libvirt.xml.mako
@@ -91,6 +91,11 @@ xmlns:qemu='http://libvirt.org/schemas/domain/qemu/1.0'>
     </channel>
   </devices>
   <qemu:commandline>
+% if defs["interpreter-args"] is not None:
+% for arg in defs["interpreter-args"]:
+    <qemu:arg value='${arg}' />
+% endfor
+% endif
     <qemu:arg value='-netdev' />
     <qemu:arg value='user,id=user.0${forward}' />
     <qemu:arg value='-device' />
diff --git a/elbepack/kvm.py b/elbepack/kvm.py
index 8ea0e6dd0..65fd43f03 100644
--- a/elbepack/kvm.py
+++ b/elbepack/kvm.py
@@ -16,10 +16,20 @@ kvm_exe_list = [
     '/usr/bin/qemu-system-x86_64'
 ]
 
+cached_kvm_infos = None
 
 def find_kvm_exe():
+
+    global cached_kvm_infos
+
+    if cached_kvm_infos:
+        return cached_kvm_infos
+
     version = "0.0.0"
+    args = []
+
     for fname in kvm_exe_list:
+
         if os.path.isfile(fname) and os.access(fname, os.X_OK):
             # determine kvm version
             _, stdout = command_out(fname + ' --version')
@@ -28,8 +38,18 @@ def find_kvm_exe():
                     version = line.split()[3].split('(')[0].strip()
 
             if fname == "/usr/bin/qemu-system-x86_64":
-                fname += " -enable-kvm"
+                args.append("-enable-kvm")
+
+            cached_kvm_infos = {
+                "exec_name": fname,
+                "version": version,
+                "args":args
+            }
 
-            return fname, version
+            return cached_kvm_infos
 
-    return 'kvm_executable_not_found'
+    return {
+        "exec_name": "kvm_executable_not_found",
+        "version": version,
+        "args": args
+    }
diff --git a/elbepack/xmldefaults.py b/elbepack/xmldefaults.py
index 1979b67df..3ca7102a4 100644
--- a/elbepack/xmldefaults.py
+++ b/elbepack/xmldefaults.py
@@ -146,8 +146,9 @@ ppc64el_defaults = {
 
 amd64_defaults = {
     "arch": "amd64",
-    "interpreter": find_kvm_exe()[0],
-    "interpreterversion": find_kvm_exe()[1],
+    "interpreter": find_kvm_exe()["exec_name"],
+    "interpreterversion": find_kvm_exe()["version"],
+    "interpreter-args": find_kvm_exe()["args"],
     "console": "ttyS0,115200n1",
     "machine": "pc",
     "nicmodel": "virtio",
-- 
2.25.0




More information about the elbe-devel mailing list