From nobody Wed Mar 12 13:16:28 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 1741288249654799.0856268534076; Thu, 6 Mar 2025 11:10:49 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 996) id BA96419E6; Thu, 6 Mar 2025 14:10:48 -0500 (EST) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id E5B2119B3; Thu, 6 Mar 2025 14:10:21 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 996) id 7D88DCBA; Thu, 6 Mar 2025 14:10:18 -0500 (EST) Received: from mx0b-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) (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 B679F199C for ; Thu, 6 Mar 2025 14:10:17 -0500 (EST) Received: from pps.filterd (m0353725.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 526H5agG028432 for ; Thu, 6 Mar 2025 19:10:17 GMT Received: from ppma12.dal12v.mail.ibm.com (dc.9e.1632.ip4.static.sl-reverse.com [50.22.158.220]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 456wu05uh5-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Thu, 06 Mar 2025 19:10:17 +0000 (GMT) Received: from pps.filterd (ppma12.dal12v.mail.ibm.com [127.0.0.1]) by ppma12.dal12v.mail.ibm.com (8.18.1.2/8.18.1.2) with ESMTP id 526HZ3GQ032243 for ; Thu, 6 Mar 2025 19:10:16 GMT Received: from smtprelay02.wdc07v.mail.ibm.com ([172.16.1.69]) by ppma12.dal12v.mail.ibm.com (PPS) with ESMTPS id 454cjtar7h-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Thu, 06 Mar 2025 19:10:16 +0000 Received: from smtpav04.wdc07v.mail.ibm.com (smtpav04.wdc07v.mail.ibm.com [10.39.53.231]) by smtprelay02.wdc07v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 526JAFLM28705326 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Thu, 6 Mar 2025 19:10:15 GMT Received: from smtpav04.wdc07v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id AB75D58045 for ; Thu, 6 Mar 2025 19:10:15 +0000 (GMT) Received: from smtpav04.wdc07v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 6DD9F58050 for ; Thu, 6 Mar 2025 19:10:15 +0000 (GMT) Received: from li-d664314c-3171-11b2-a85c-fa8047ef35bd.pok.ibm.com (unknown [9.12.68.85]) by smtpav04.wdc07v.mail.ibm.com (Postfix) with ESMTP for ; Thu, 6 Mar 2025 19:10:15 +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= content-transfer-encoding:date:from:message-id:mime-version :subject:to; s=pp1; bh=j7wX74qnkxmBWeuknDLry0Rq+TQSGMHlnzfF1Tw4f RU=; b=LgYftWSEgBlK6ZU6H3pBnV1VMunsr+ps29YxdD/9eDslCTQamvSNzEQpf zWOMwelqO6nvmp834zZ9LHrOMUC0Exe3ige7WiZ1M+i/GcRKP8Y/ifyMDSqerrME uoZrUKQIMrqpa1KVt/UBHuVGBWZwfb87nO6NQfKE+vcgFGfgKJBvwsICtuJnKcM8 VcwhHr3Dee2CtV78X1zIqz2iwesiN0Wj71qHus2JtXcVI64ToJekcV1M2Er3dasM sqVAhPBAyqOJ29TOBYnhatRRra+4Ljyr60y4K0vAkZFApOZkZ7O3x+Vvr3RRNbG3 3RvT0RRR0gYkcKiPnckwgpnnRpJ6Q== From: Collin Walling To: devel@lists.libvirt.org Subject: [PATCH] virsh: Introduce new hypervisor-cpu-models command Date: Thu, 6 Mar 2025 14:07:27 -0500 Message-ID: <20250306190727.21182-1-walling@linux.ibm.com> X-Mailer: git-send-email 2.47.1 MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: MaIXVhCzJK1WMmVLasQqQbziL62XeZRC X-Proofpoint-ORIG-GUID: MaIXVhCzJK1WMmVLasQqQbziL62XeZRC 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-06_06,2025-03-06_04,2024-11-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 impostorscore=0 suspectscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 bulkscore=0 adultscore=0 spamscore=0 mlxlogscore=999 phishscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2502100000 definitions=main-2503060144 Content-Transfer-Encoding: quoted-printable Message-ID-Hash: CTILZMCFNICRXV3IBCEHRHTDLUFIBWVC X-Message-ID-Hash: CTILZMCFNICRXV3IBCEHRHTDLUFIBWVC 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 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: 1741288251186019000 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 --- This is a continuation of a previous series found here: https://lists.libvirt.org/archives/list/devel@lists.libvirt.org/message/I4Y= KUBDJDMLFJ6767ZPP2NP6Y4COEMBW/ --- docs/manpages/virsh.rst | 24 +++++++++++++ tools/virsh-host.c | 74 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 98 insertions(+) diff --git a/docs/manpages/virsh.rst b/docs/manpages/virsh.rst index baced15dec..48b667736d 100644 --- a/docs/manpages/virsh.rst +++ b/docs/manpages/virsh.rst @@ -1034,6 +1034,30 @@ 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] [emulator] [arch] [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..2884067bbb 100644 --- a/tools/virsh-host.c +++ b/tools/virsh-host.c @@ -1766,6 +1766,74 @@ 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, + .unwanted_positional =3D true, + .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_all =3D "//cpu//model[@usable]/text()"; + const char *xpath_usable =3D "//cpu//model[@usable=3D'yes']/text()"; + 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; + + 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", + vshCommandOptBool(cmd, "all") ? xpath_all : xpath_= usable, + false); +} + + const vshCmdDef hostAndHypervisorCmds[] =3D { {.name =3D "allocpages", .handler =3D cmdAllocpages, @@ -1833,6 +1901,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