From nobody Mon Feb 9 09:43:19 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1623161586; cv=none; d=zohomail.com; s=zohoarc; b=Xa/uEDf4aa8dntJcR4Bh5aEAR2zoyDapg3F2nduWLbOuwvdWxo4iCpgRs7G7fvSpHmn891lUq5IFtMdRMyxW/oC+07PNr3U7s6Nq9jSOWWgk+UtyyXlRbgp5MIRyrzzbLJxyo19DQG4IXpGYeXYziwhITllhYu/zLzo5kEdn5/o= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1623161586; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=jAIQtbHhBm5hiDXzC73PJ8AlCHtrIQkxvk6NGwK2V8w=; b=CSxesQazyLZhgf90Xz+BITFfasp6M3QF4HpzVB64lyQe+3OHjoD1e0QXCMmOCXypdhEE2Piw2NbJ1YgvfGLRCfxZQne5vxOVPvdeMOS4pVxGnxFngW+k0VHPdLd00CyNYCUtOty1JH3oVSkwOKt/qVC5KO2v3XprlsrZkhJm4WM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1623161586930545.3769788380932; Tue, 8 Jun 2021 07:13:06 -0700 (PDT) Received: from localhost ([::1]:34352 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lqcTa-00070G-6f for importer@patchew.org; Tue, 08 Jun 2021 10:13:06 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:53618) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lqcQX-0002xo-At for qemu-devel@nongnu.org; Tue, 08 Jun 2021 10:09:57 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:58552) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lqcQU-0001yy-MU for qemu-devel@nongnu.org; Tue, 08 Jun 2021 10:09:57 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-87-kqBIXk8WM7eThd4_sBZEbg-1; Tue, 08 Jun 2021 10:09:53 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id AA897800D62; Tue, 8 Jun 2021 14:09:51 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-112-153.phx2.redhat.com [10.3.112.153]) by smtp.corp.redhat.com (Postfix) with ESMTPS id D8B6F5D9DE; Tue, 8 Jun 2021 14:09:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1623161394; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=jAIQtbHhBm5hiDXzC73PJ8AlCHtrIQkxvk6NGwK2V8w=; b=CKOkk4rzCALqrQrmUqLZJ5zjitpC92pxzLgqYO2FTzmHu5t+4s+UPKcR0cKM8W9zGufIw+ hkQdeIyNg6+Xdsl3jJAlckL+HGEAWpXWcULsW8f1bgONcmueK9OfSMD9xzhtLGOruCmhQT alCzSREaziIQwWxayYlOC2zNZWQiRXI= X-MC-Unique: kqBIXk8WM7eThd4_sBZEbg-1 From: Cleber Rosa To: qemu-devel@nongnu.org Subject: [PATCH 2/4] Python QEMU utils: introduce a generic feature list Date: Tue, 8 Jun 2021 10:09:36 -0400 Message-Id: <20210608140938.863580-3-crosa@redhat.com> In-Reply-To: <20210608140938.863580-1-crosa@redhat.com> References: <20210608140938.863580-1-crosa@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=crosa@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=216.205.24.124; envelope-from=crosa@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -29 X-Spam_score: -3.0 X-Spam_bar: --- X-Spam_report: (-3.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.197, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Fam Zheng , Thomas Huth , Eduardo Habkost , qemu-block@nongnu.org, Erik Skultety , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Cleber Rosa , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Wainer dos Santos Moschetta , Andrea Bolognani , Willian Rampazzo , John Snow , Willian Rampazzo , Stefan Hajnoczi , Max Reitz , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Beraldo Leal Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Which can be used to check for any "feature" that is available as a QEMU command line option, and that will return its list of available options. This is a generalization of the list_accel() utility function, which is itself re-implemented in terms of the more generic feature. Signed-off-by: Cleber Rosa Acked-by: John Snow Reviewed-by: Willian Rampazzo --- python/qemu/utils/__init__.py | 2 ++ python/qemu/utils/accel.py | 15 ++---------- python/qemu/utils/feature.py | 44 +++++++++++++++++++++++++++++++++++ 3 files changed, 48 insertions(+), 13 deletions(-) create mode 100644 python/qemu/utils/feature.py diff --git a/python/qemu/utils/__init__.py b/python/qemu/utils/__init__.py index 7f1a5138c4..1d0789eaa2 100644 --- a/python/qemu/utils/__init__.py +++ b/python/qemu/utils/__init__.py @@ -20,12 +20,14 @@ =20 # pylint: disable=3Dimport-error from .accel import kvm_available, list_accel, tcg_available +from .feature import list_feature =20 =20 __all__ =3D ( 'get_info_usernet_hostfwd_port', 'kvm_available', 'list_accel', + 'list_feature', 'tcg_available', ) =20 diff --git a/python/qemu/utils/accel.py b/python/qemu/utils/accel.py index 297933df2a..b5bb80c6d3 100644 --- a/python/qemu/utils/accel.py +++ b/python/qemu/utils/accel.py @@ -14,13 +14,11 @@ # the COPYING file in the top-level directory. # =20 -import logging import os -import subprocess from typing import List, Optional =20 +from qemu.utils.feature import list_feature =20 -LOG =3D logging.getLogger(__name__) =20 # Mapping host architecture to any additional architectures it can # support which often includes its 32 bit cousin. @@ -39,16 +37,7 @@ def list_accel(qemu_bin: str) -> List[str]: @raise Exception: if failed to run `qemu -accel help` @return a list of accelerator names. """ - if not qemu_bin: - return [] - try: - out =3D subprocess.check_output([qemu_bin, '-accel', 'help'], - universal_newlines=3DTrue) - 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:]] + return list_feature(qemu_bin, 'accel') =20 =20 def kvm_available(target_arch: Optional[str] =3D None, diff --git a/python/qemu/utils/feature.py b/python/qemu/utils/feature.py new file mode 100644 index 0000000000..b4a5f929ab --- /dev/null +++ b/python/qemu/utils/feature.py @@ -0,0 +1,44 @@ +""" +QEMU feature module: + +This module provides a utility for discovering the availability of +generic features. +""" +# Copyright (C) 2022 Red Hat Inc. +# +# Authors: +# Cleber Rosa +# +# This work is licensed under the terms of the GNU GPL, version 2. See +# the COPYING file in the top-level directory. +# + +import logging +import subprocess +from typing import List + + +LOG =3D logging.getLogger(__name__) + + +def list_feature(qemu_bin: str, feature: str) -> List[str]: + """ + List available options the QEMU binary for a given feature type. + + By calling a "qemu $feature -help" and parsing its output. + + @param qemu_bin (str): path to the QEMU binary. + @param feature (str): feature name, matching the command line option. + @raise Exception: if failed to run `qemu -feature help` + @return a list of available options for the given feature. + """ + if not qemu_bin: + return [] + try: + out =3D subprocess.check_output([qemu_bin, '-%s' % feature, 'help'= ], + universal_newlines=3DTrue) + except: + LOG.debug("Failed to get the list of %s(s) in %s", feature, qemu_b= in) + raise + # Skip the first line which is the header. + return [item.split(' ', 1)[0] for item in out.splitlines()[1:]] --=20 2.25.4