On 29/01/2020 21:23, Philippe Mathieu-Daudé wrote:
Instead of parsing the process help output, use the
binary_get_accels() helper which queries the list of
accelerators over a QMP socket.
Signed-off-by: Philippe Mathieu-Daudé <phi...@redhat.com>
Reviewed-by: Liam Merwick <liam.merw...@oracle.com>
---
python/qemu/accel.py | 26 ++++----------------------
1 file changed, 4 insertions(+), 22 deletions(-)
diff --git a/python/qemu/accel.py b/python/qemu/accel.py
index 0b38ddf0ab..cde51ae159 100644
--- a/python/qemu/accel.py
+++ b/python/qemu/accel.py
@@ -16,7 +16,8 @@ accelerators.
import logging
import os
-import subprocess
+
+from .binutils import binary_get_accels
LOG = logging.getLogger(__name__)
@@ -27,25 +28,6 @@ ADDITIONAL_ARCHES = {
"aarch64" : "armhf"
}
-def list_accel(qemu_bin):
- """
- List accelerators enabled in the QEMU binary.
-
- @param qemu_bin (str): path to the QEMU binary.
- @raise Exception: if failed to run `qemu -accel help`
- @return a list of accelerator names.
- """
- if not qemu_bin:
- return []
- try:
- out = subprocess.check_output([qemu_bin, '-accel', 'help'],
- universal_newlines=True)
- except:
- LOG.debug("Failed to get the list of accelerators in %s", qemu_bin)
- raise
- # Skip the first line which is the header.
- return [acc.strip() for acc in out.splitlines()[1:]]
-
def kvm_available(target_arch=None, qemu_bin=None):
"""
Check if KVM is available using the following heuristic:
@@ -64,7 +46,7 @@ def kvm_available(target_arch=None, qemu_bin=None):
if target_arch != host_arch:
if target_arch != ADDITIONAL_ARCHES.get(host_arch):
return False
- if qemu_bin and "kvm" not in list_accel(qemu_bin):
+ if qemu_bin and "kvm" not in binary_get_accels(qemu_bin):
return False
return True
@@ -74,4 +56,4 @@ def tcg_available(qemu_bin):
@param qemu_bin (str): path to the QEMU binary
"""
- return 'tcg' in list_accel(qemu_bin)
+ return 'tcg' in binary_get_accels(qemu_bin)