From nobody Thu Dec 18 00:23:46 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) client-ip=8.43.85.245; envelope-from=devel-bounces@lists.libvirt.org; helo=lists.libvirt.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=fail(p=reject dis=none) header.from=linux.ibm.com Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 1742448576351967.7816908711072; Wed, 19 Mar 2025 22:29:36 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 996) id AD15616DB; Thu, 20 Mar 2025 01:29:35 -0400 (EDT) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 60D7C168A; Thu, 20 Mar 2025 01:29:12 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 4E3AF166F; Thu, 20 Mar 2025 01:29:10 -0400 (EDT) Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by lists.libvirt.org (Postfix) with ESMTPS id 718A61534 for ; Thu, 20 Mar 2025 01:29:09 -0400 (EDT) Received: from pps.filterd (m0360083.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 52K3jwOI029694; Thu, 20 Mar 2025 05:29:08 GMT Received: from ppma13.dal12v.mail.ibm.com (dd.9e.1632.ip4.static.sl-reverse.com [50.22.158.221]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 45gbd9gcuy-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 20 Mar 2025 05:29:08 +0000 (GMT) Received: from pps.filterd (ppma13.dal12v.mail.ibm.com [127.0.0.1]) by ppma13.dal12v.mail.ibm.com (8.18.1.2/8.18.1.2) with ESMTP id 52K3QxOi023229; Thu, 20 Mar 2025 05:29:07 GMT Received: from smtprelay05.dal12v.mail.ibm.com ([172.16.1.7]) by ppma13.dal12v.mail.ibm.com (PPS) with ESMTPS id 45dp3kwwpc-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 20 Mar 2025 05:29:07 +0000 Received: from smtpav02.wdc07v.mail.ibm.com (smtpav02.wdc07v.mail.ibm.com [10.39.53.229]) by smtprelay05.dal12v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 52K5T65v1770116 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 20 Mar 2025 05:29:06 GMT Received: from smtpav02.wdc07v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 3B26B58067; Thu, 20 Mar 2025 05:29:06 +0000 (GMT) Received: from smtpav02.wdc07v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 80E7D5805E; Thu, 20 Mar 2025 05:29:05 +0000 (GMT) Received: from li-d664314c-3171-11b2-a85c-fa8047ef35bd.ibm.com.com (unknown [9.67.124.229]) by smtpav02.wdc07v.mail.ibm.com (Postfix) with ESMTP; Thu, 20 Mar 2025 05:29:05 +0000 (GMT) X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-1.5 required=5.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2,RCVD_IN_VALIDITY_RPBL_BLOCKED, RCVD_IN_VALIDITY_SAFE_BLOCKED,SPF_HELO_NONE autolearn=unavailable autolearn_force=no version=3.4.4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=cc :content-transfer-encoding:content-type:date:from:message-id :mime-version:subject:to; s=pp1; bh=zy5sESlauiVqOUGwM/B+wsd+53F4 Wo374xbHxK6d6HM=; b=b+ReMb5yZxgO2HGuPgrRgJfuNxQBH5WT0hNR6ph7U+Qn 0cRpBSvwj2HHlsD1SQftjwnZUE1+SFwI7sQ2gM2awKAqkAQJR9qR9l4wD1dZE309 qu1Kw1MFefeOekraT/x+cMh/dcq6qw0XS0jLtpOAXDt3ePytP0CuvHJ/xqr5+fwq 656ezO4lyR49+3eEtTW3+GfNJp+hjbkValWHEyfxhR5Fd9lzORqLrj9f1WxTxU7Q 86AHrr79fu6a01ihaXESpye5lD81GZiS/wwqsDqW8ICNmo04w2R5Eup1j+MZM4H1 MARC9yTjq5ieURvPh+y3mRV57Bi7xrh3TBV+J2zTqw== From: Collin Walling To: devel@lists.libvirt.org Subject: [PATCH v2] virsh: Introduce new hypervisor-cpu-models command Date: Thu, 20 Mar 2025 01:28:24 -0400 Message-ID: <20250320052827.213729-1-walling@linux.ibm.com> X-Mailer: git-send-email 2.47.1 MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: xiokbOPhphmDeoqcmiCUT_Dz6peix1sS X-Proofpoint-GUID: xiokbOPhphmDeoqcmiCUT_Dz6peix1sS X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1093,Hydra:6.0.680,FMLib:17.12.68.34 definitions=2025-03-20_01,2025-03-19_01,2024-11-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 bulkscore=0 priorityscore=1501 malwarescore=0 spamscore=0 impostorscore=0 mlxlogscore=999 lowpriorityscore=0 adultscore=0 suspectscore=0 clxscore=1015 mlxscore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2502280000 definitions=main-2503200032 Content-Transfer-Encoding: quoted-printable Message-ID-Hash: OOHDHCMIK7NOXA7IAMVVGDCM7B5AQN2M X-Message-ID-Hash: OOHDHCMIK7NOXA7IAMVVGDCM7B5AQN2M X-MailFrom: walling@linux.ibm.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-config-1; header-match-config-2; header-match-config-3; header-match-devel.lists.libvirt.org-0; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; suspicious-header CC: pkrempa@redhat.com, David Judkovics , Boris Fiuczynski , =?UTF-8?q?J=C3=A1n=20Tomko?= X-Mailman-Version: 3.2.2 Precedence: list List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1742448579298019000 Content-Type: text/plain; charset="utf-8" From: David Judkovics Add new virsh command 'hypervisor-cpu-models'. Command pulls from the existing domcapabilities XML and uses xpath to parse CPU model strings. By default, only models reported as usable by the hypervisor on the host system are printed. User may specify "--all" to also print models which are not supported on the host. Signed-off-by: David Judkovics Signed-off-by: Boris Fiuczynski Signed-off-by: Collin Walling Reviewed-by: J=C3=A1n Tomko --- Changelog: v2 - Corrected virsh.rst documentation - Removed unwanted_positional from emulator option - Adjusted xpath string based on feedback --- docs/manpages/virsh.rst | 25 ++++++++++++++ tools/virsh-host.c | 75 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 100 insertions(+) diff --git a/docs/manpages/virsh.rst b/docs/manpages/virsh.rst index baced15dec..612c567ff4 100644 --- a/docs/manpages/virsh.rst +++ b/docs/manpages/virsh.rst @@ -1034,6 +1034,31 @@ listed in the XML description. If *--migratable* is = specified, features that block migration will not be included in the resulting CPU. =20 =20 +hypervisor-cpu-models +--------------------- + +**Syntax:** + +:: + + hypervisor-cpu-models [--virttype virttype] [--emulator emulator] + [--arch arch] [--machine machine] [--all] + +Print the list of CPU models known by the hypervisor for the specified arc= hitecture. +It is not guaranteed that a listed CPU will run on the host. To determine = CPU +model compatibility with the host, see ``virsh hypervisor-cpu-baseline`` a= nd +``virsh hypervisor-cpu-compare``. + +The *virttype* option specifies the virtualization type (usable in the 'ty= pe' +attribute of the top level element from the domain XML). *emulato= r* +specifies the path to the emulator, *arch* specifies the CPU architecture,= and +*machine* specifies the machine type. + +By default, only the models that are claimed to be "usable" by the hypervi= sor +on the host are reported. The option *--all* will report every CPU model k= nown +to the hypervisor, including ones that are not supported on the hypervisor= (e.g. +newer generation models). + DOMAIN COMMANDS =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =20 diff --git a/tools/virsh-host.c b/tools/virsh-host.c index 9e8f542c96..f4e34fb146 100644 --- a/tools/virsh-host.c +++ b/tools/virsh-host.c @@ -1766,6 +1766,75 @@ cmdHypervisorCPUBaseline(vshControl *ctl, } =20 =20 +/* + * "hypervisor-cpu-models" command + */ +static const vshCmdInfo info_hypervisor_cpu_models =3D { + .help =3D N_("Hypervisor reported CPU models"), + .desc =3D N_("Get the CPU models reported by the hypervisor."), +}; + +static const vshCmdOptDef opts_hypervisor_cpu_models[] =3D { + {.name =3D "virttype", + .type =3D VSH_OT_STRING, + .completer =3D virshDomainVirtTypeCompleter, + .help =3D N_("virtualization type (/domain/@type)"), + }, + {.name =3D "emulator", + .type =3D VSH_OT_STRING, + .help =3D N_("path to emulator binary (/domain/devices/emulator)"), + }, + {.name =3D "arch", + .type =3D VSH_OT_STRING, + .completer =3D virshArchCompleter, + .help =3D N_("CPU architecture (/domain/os/type/@arch)"), + }, + {.name =3D "machine", + .type =3D VSH_OT_STRING, + .help =3D N_("machine type (/domain/os/type/@machine)"), + }, + {.name =3D "all", + .type =3D VSH_OT_BOOL, + .help =3D N_("include all CPU models known to the hypervisor for the = architecture") + }, + {.name =3D NULL} +}; + +static bool +cmdHypervisorCPUModelNames(vshControl *ctl, + const vshCmd *cmd) +{ + g_autofree char *caps_xml =3D NULL; + const char *virttype =3D NULL; + const char *emulator =3D NULL; + const char *arch =3D NULL; + const char *machine =3D NULL; + const char *xpath =3D NULL; + virshControl *priv =3D ctl->privData; + + if (vshCommandOptString(ctl, cmd, "virttype", &virttype) < 0 || + vshCommandOptString(ctl, cmd, "emulator", &emulator) < 0 || + vshCommandOptString(ctl, cmd, "arch", &arch) < 0 || + vshCommandOptString(ctl, cmd, "machine", &machine) < 0) + return false; + + if (vshCommandOptBool(cmd, "all")) + xpath =3D "//cpu//model[@usable]/text()"; + else + xpath =3D "//cpu//model[@usable=3D'yes']/text()"; + + caps_xml =3D virConnectGetDomainCapabilities(priv->conn, emulator, arc= h, + machine, virttype, 0); + + if (!caps_xml) { + vshError(ctl, "%s", _("failed to get hypervisor CPU model names")); + return false; + } + + return virshDumpXML(ctl, caps_xml, "domcapabilities", xpath, false); +} + + const vshCmdDef hostAndHypervisorCmds[] =3D { {.name =3D "allocpages", .handler =3D cmdAllocpages, @@ -1833,6 +1902,12 @@ const vshCmdDef hostAndHypervisorCmds[] =3D { .info =3D &info_hypervisor_cpu_compare, .flags =3D 0 }, + {.name =3D "hypervisor-cpu-models", + .handler =3D cmdHypervisorCPUModelNames, + .opts =3D opts_hypervisor_cpu_models, + .info =3D &info_hypervisor_cpu_models, + .flags =3D 0 + }, {.name =3D "maxvcpus", .handler =3D cmdMaxvcpus, .opts =3D opts_maxvcpus, --=20 2.47.1