[elbe-devel] [PATCH v2 3/3] initvm: Prevent trying old kvm interpreter names

Bastian Germann bage at linutronix.de
Thu Jun 30 12:58:52 CEST 2022


buster and later Debian versions just have a kvm symlink to qemu-system.
libvirt takes care of setting the right arguments so that KVM is enabled
with the default template. The qemu arguments are only kept for the initvm
creation.

There was an inconsistency in that amd64 had the full path to interpreter
and all other systems had only the executable name.
Make up for that by finding the path later via shutil.which().

The Debian package qemu-kvm, which used to have the kvm wrapper executable
is a virtual package. Virtual packages should only be used in Depends as
alternatives, so depend on the real package.

Signed-off-by: Bastian Germann <bage at linutronix.de>
---
 debian/control                     |  2 +-
 debian/python3-elbe-common.install |  1 -
 elbepack/init/libvirt.xml.mako     |  3 +-
 elbepack/kvm.py                    | 56 ------------------------------
 elbepack/xmldefaults.py            |  6 ++--
 5 files changed, 5 insertions(+), 63 deletions(-)
 delete mode 100644 elbepack/kvm.py

diff --git a/debian/control b/debian/control
index 8ecbed5dc1..bbeb4eb97e 100644
--- a/debian/control
+++ b/debian/control
@@ -87,7 +87,7 @@ Depends: ${misc:Depends},
   python3-elbe-bin (= ${binary:Version}),
   python3-elbe-control (= ${binary:Version}),
   qemu-utils,
-  qemu-kvm,
+  qemu-system-x86,
   p7zip-full,
   make,
   lsb-release
diff --git a/debian/python3-elbe-common.install b/debian/python3-elbe-common.install
index dd67340eea..dbaff34200 100644
--- a/debian/python3-elbe-common.install
+++ b/debian/python3-elbe-common.install
@@ -26,7 +26,6 @@
 ./usr/lib/python3.*/*-packages/elbepack/hdimg.py
 ./usr/lib/python3.*/*-packages/elbepack/initvmaction.py
 ./usr/lib/python3.*/*-packages/elbepack/isooptions.py
-./usr/lib/python3.*/*-packages/elbepack/kvm.py
 ./usr/lib/python3.*/*-packages/elbepack/licencexml.py
 ./usr/lib/python3.*/*-packages/elbepack/log.py
 ./usr/lib/python3.*/*-packages/elbepack/packers.py
diff --git a/elbepack/init/libvirt.xml.mako b/elbepack/init/libvirt.xml.mako
index 285b875548..559aa11417 100644
--- a/elbepack/init/libvirt.xml.mako
+++ b/elbepack/init/libvirt.xml.mako
@@ -13,6 +13,7 @@
 import uuid
 import multiprocessing
 import os
+import shutil
 from elbepack.filesystem import size_to_int
 
 # Generate UUID
@@ -26,7 +27,7 @@ memory = size_to_int(prj.text('mem', default=defs, key='mem')) // 1024
 imagetype = prj.text('img', default=defs, key='img')
 img = os.path.join(opt.directory, 'initvm.img')
 
-emulator = prj.text('interpreter', default=defs, key='interpreter')
+emulator = shutil.which(prj.text('interpreter', default=defs, key='interpreter'))
 nicmac = prj.text('buildimage/NIC/MAC', default=defs, key='nicmac')
 forward = ''
 for f in prj.node("portforwarding"):
diff --git a/elbepack/kvm.py b/elbepack/kvm.py
deleted file mode 100644
index 7889288fa4..0000000000
--- a/elbepack/kvm.py
+++ /dev/null
@@ -1,56 +0,0 @@
-# ELBE - Debian Based Embedded Rootfilesystem Builder
-# Copyright (c) 2016 Torben Hohn <torben.hohn at linutronix.de>
-# Copyright (c) 2017 Kurt Kanzenbach <kurt at linutronix.de>
-# Copyright (c) 2017 Manuel Traut <manut at linutronix.de>
-#
-# SPDX-License-Identifier: GPL-3.0-or-later
-
-import os
-
-from elbepack.shellhelper import command_out
-
-kvm_exe_list = [
-    '/usr/bin/kvm',
-    '/usr/bin/qemu-kvm',
-    '/usr/libexec/qemu-kvm',
-    '/usr/bin/qemu-system-x86_64'
-]
-
-cached_kvm_infos = None
-
-def find_kvm_exe():
-
-    # pylint: disable=global-statement
-    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')
-            for line in stdout.splitlines():
-                if "version" in line:
-                    version = line.split()[3].split('(')[0].strip()
-
-            if fname == "/usr/bin/qemu-system-x86_64":
-                args.append("-enable-kvm")
-
-            cached_kvm_infos = {
-                "exec_name": fname,
-                "version": version,
-                "args":args
-            }
-
-            return cached_kvm_infos
-
-    return {
-        "exec_name": "kvm_executable_not_found",
-        "version": version,
-        "args": args
-    }
diff --git a/elbepack/xmldefaults.py b/elbepack/xmldefaults.py
index 7e4420d4ea..edbfa10d89 100644
--- a/elbepack/xmldefaults.py
+++ b/elbepack/xmldefaults.py
@@ -8,8 +8,6 @@
 
 import random
 
-from elbepack.kvm import find_kvm_exe
-
 armel_defaults = {
     "arch": "armel",
     "interpreter": "qemu-system-arm",
@@ -133,8 +131,8 @@ ppc64el_defaults = {
 
 amd64_defaults = {
     "arch": "amd64",
-    "interpreter": find_kvm_exe()["exec_name"],
-    "interpreter-args": find_kvm_exe()["args"],
+    "interpreter": "qemu-system-x86_64",
+    "interpreter-args": ["-enable-kvm"],
     "console": "ttyS0,115200n1",
     "machine": "pc",
     "nicmodel": "virtio",
-- 
2.30.2



More information about the elbe-devel mailing list