From nobody Tue Jan 21 04:14:26 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 1736937368920579.4953662337945; Wed, 15 Jan 2025 02:36:08 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 996) id 47D81161A; Wed, 15 Jan 2025 05:36:08 -0500 (EST) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 939771918; Wed, 15 Jan 2025 05:34:25 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 996) id DBE3115B9; Wed, 15 Jan 2025 05:34:16 -0500 (EST) 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 11A04162C for ; Wed, 15 Jan 2025 05:34:15 -0500 (EST) 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 50F3rhe0019115 for ; Wed, 15 Jan 2025 10:34:15 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 4465gbshkw-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Wed, 15 Jan 2025 10:34:14 +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 50F9X4dm004526 for ; Wed, 15 Jan 2025 10:34:14 GMT Received: from smtprelay02.fra02v.mail.ibm.com ([9.218.2.226]) by ppma12.dal12v.mail.ibm.com (PPS) with ESMTPS id 4442ysr0sm-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Wed, 15 Jan 2025 10:34:13 +0000 Received: from smtpav02.fra02v.mail.ibm.com (smtpav02.fra02v.mail.ibm.com [10.20.54.101]) by smtprelay02.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 50FAYAaf34800100 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 15 Jan 2025 10:34:10 GMT Received: from smtpav02.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 132272004B; Wed, 15 Jan 2025 10:34:10 +0000 (GMT) Received: from smtpav02.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id F0C852004F; Wed, 15 Jan 2025 10:34:09 +0000 (GMT) Received: from fiuczyvm.. (unknown [9.152.222.247]) by smtpav02.fra02v.mail.ibm.com (Postfix) with ESMTP; Wed, 15 Jan 2025 10:34:09 +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=-3.0 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:date:from:in-reply-to:message-id :mime-version:references:subject:to; s=pp1; bh=JiILvBNXG6PJtHYPe h9Ec26M5lwgfWG1lL7c92e820E=; b=n2+dmVy0rGQ1M99pjVX71eQZs5OiKToN7 /3pEofUvbM2Fu85ujlhyvID/Tf5ptgjSagzvK+7R+Gy1cniVIFotOB2SCGKgHmHO c3sVrVZKZoNmJsMPZ6y2+9yyIQf9sGa1T6x4XiJkJfFFP1unj9dszCr00rOfLsdQ HKqL1LeujMuoAfH5qXOluRVQfYEFIYkQ1I4LMZeuNDNPYNEkY6+e2CKC7gFqNDlZ dyH7i4dePY7/6osKGRIYme+nzioNRmNjakkezxUjpITe/lz1PwVclisQUUI5KDAx 38669PtwFNsVnNH5r0DBbSNq27NYIZFaL7zS8zejlZx3WgMfcy7HQ== From: Boris Fiuczynski To: devel@lists.libvirt.org Subject: [PATCH 1/4] libvirt: Introduce virConnectGetHypervisorCPUModelNames public API Date: Wed, 15 Jan 2025 11:34:06 +0100 Message-ID: <20250115103409.31064-2-fiuczy@linux.ibm.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250115103409.31064-1-fiuczy@linux.ibm.com> References: <20250115103409.31064-1-fiuczy@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: Y3PU3_kpV4gLmEzwPj-olTnhMcJfUgVF X-Proofpoint-ORIG-GUID: Y3PU3_kpV4gLmEzwPj-olTnhMcJfUgVF X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1057,Hydra:6.0.680,FMLib:17.12.68.34 definitions=2025-01-15_04,2025-01-15_02,2024-11-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1015 spamscore=0 adultscore=0 mlxlogscore=852 phishscore=0 priorityscore=1501 suspectscore=0 bulkscore=0 malwarescore=0 impostorscore=0 lowpriorityscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2411120000 definitions=main-2501150079 Content-Transfer-Encoding: quoted-printable Message-ID-Hash: 5LHVPWJMGHRC4TVRANLX6UV7FPWCBHTK X-Message-ID-Hash: 5LHVPWJMGHRC4TVRANLX6UV7FPWCBHTK X-MailFrom: fiuczy@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: djudkovi@linux.ibm.com, walling@linux.ibm.com 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: 1736937370325019000 Content-Type: text/plain; charset="utf-8" From: David Judkovics The new API collects a list of CPU model names supported by the specified hypervisor. This is a more useful version of virConnectGetCPUNames, which does not consider any hypervisor capabilities when querying model names. Signed-off-by: David Judkovics Signed-off-by: Collin Walling Reviewed-by: Boris Fiuczynski Signed-off-by: Boris Fiuczynski --- include/libvirt/libvirt-host.h | 7 ++++ src/driver-hypervisor.h | 10 ++++++ src/libvirt-host.c | 65 ++++++++++++++++++++++++++++++++++ src/libvirt_public.syms | 5 +++ 4 files changed, 87 insertions(+) diff --git a/include/libvirt/libvirt-host.h b/include/libvirt/libvirt-host.h index 3112f2b676..67f57cdd16 100644 --- a/include/libvirt/libvirt-host.h +++ b/include/libvirt/libvirt-host.h @@ -961,6 +961,13 @@ int virConnectGetCPUModelNames(virConnectPtr conn, const char *arch, char ***models, unsigned int flags); +int virConnectGetHypervisorCPUModelNames(virConnectPtr conn, + const char *emulator, + const char *arch, + const char *machine, + const char *virttype, + char ***models, + unsigned int flags); =20 /** * virConnectBaselineCPUFlags: diff --git a/src/driver-hypervisor.h b/src/driver-hypervisor.h index 4ce8da078d..ed42e3553d 100644 --- a/src/driver-hypervisor.h +++ b/src/driver-hypervisor.h @@ -1453,6 +1453,15 @@ typedef int unsigned int type, unsigned int flags); =20 +typedef int +(*virDrvConnectGetHypervisorCPUModelNames)(virConnectPtr conn, + const char *emulator, + const char *arch, + const char *machine, + const char *virttype, + char ***models, + unsigned int flags); + typedef struct _virHypervisorDriver virHypervisorDriver; =20 /** @@ -1726,4 +1735,5 @@ struct _virHypervisorDriver { virDrvDomainStartDirtyRateCalc domainStartDirtyRateCalc; virDrvDomainFDAssociate domainFDAssociate; virDrvDomainGraphicsReload domainGraphicsReload; + virDrvConnectGetHypervisorCPUModelNames connectGetHypervisorCPUModelNa= mes; }; diff --git a/src/libvirt-host.c b/src/libvirt-host.c index b3a6421a7f..ba845a7126 100644 --- a/src/libvirt-host.c +++ b/src/libvirt-host.c @@ -1222,6 +1222,71 @@ virConnectGetCPUModelNames(virConnectPtr conn, const= char *arch, char ***models, } =20 =20 +/** + * virConnectGetHypervisorCPUModelNames: + * + * @conn: pointer to the hypervisor connection + * @emulator: path to the emulator binary + * @arch: CPU architecture + * @machine: machine type + * @virttype: virtualization type + * @models: Pointer to a variable to store the NULL-terminated array of the + * CPU models supported by the hypervisor. Each element + * and the array itself must be freed by the caller with free. Pa= ss + * NULL if only the list length is needed. + * @flags: extra flags; not used yet, so callers should always pass 0. + * + * Get the list of CPU models recognized by the hypervisor for a specific + * architecture. Note that even if the hypervisor reports a particular CPU + * model, hardware limitations may impose restrictions on which CPU models + * may be supported on the host (e.g. on s390 the hypervisor may report + * model gen15a, but this model will not run on an older machine such as z= 14). + * + * Returns -1 on error, number of elements in @models on success. + * + * Since: 11.1.0 + */ +int +virConnectGetHypervisorCPUModelNames(virConnectPtr conn, + const char *emulator, + const char *arch, + const char *machine, + const char *virttype, + char ***models, + unsigned int flags) +{ + + VIR_DEBUG("conn=3D%p, emulator=3D%s, arch=3D%s, " + "machine=3D%s, virttype=3D%s,flags=3D0x%x", + conn, NULLSTR(emulator), NULLSTR(arch), + NULLSTR(machine), NULLSTR(virttype), flags); + + virResetLastError(); + virCheckConnectReturn(conn, -1); + + if (conn->driver->connectGetHypervisorCPUModelNames) { + int nmodels; + nmodels =3D conn->driver->connectGetHypervisorCPUModelNames(conn, + emulator, + arch, + machine, + virttype, + models, + flags); + if (nmodels < 0) { + goto error; + } + + return nmodels; + } + virReportUnsupportedError(); + + error: + virDispatchError(conn); + return -1; +} + + /** * virConnectBaselineCPU: * diff --git a/src/libvirt_public.syms b/src/libvirt_public.syms index 7a3492d9d7..88f33427cc 100644 --- a/src/libvirt_public.syms +++ b/src/libvirt_public.syms @@ -948,4 +948,9 @@ LIBVIRT_10.2.0 { virDomainGraphicsReload; } LIBVIRT_10.1.0; =20 +LIBVIRT_11.1.0 { + global: + virConnectGetHypervisorCPUModelNames; +} LIBVIRT_10.2.0; + # .... define new API here using predicted next version number .... --=20 2.47.0 From nobody Tue Jan 21 04:14:26 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 1736937312034587.9016262870942; Wed, 15 Jan 2025 02:35:12 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 996) id 5EC051942; Wed, 15 Jan 2025 05:35:11 -0500 (EST) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 0DE8F18FE; Wed, 15 Jan 2025 05:34:20 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 996) id 4E1551639; Wed, 15 Jan 2025 05:34:16 -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 9BAA415FE for ; Wed, 15 Jan 2025 05:34:15 -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 50F2QcHd014295 for ; Wed, 15 Jan 2025 10:34:15 GMT Received: from ppma21.wdc07v.mail.ibm.com (5b.69.3da9.ip4.static.sl-reverse.com [169.61.105.91]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 445sd64gu0-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Wed, 15 Jan 2025 10:34:14 +0000 (GMT) Received: from pps.filterd (ppma21.wdc07v.mail.ibm.com [127.0.0.1]) by ppma21.wdc07v.mail.ibm.com (8.18.1.2/8.18.1.2) with ESMTP id 50F6KZNi007396 for ; Wed, 15 Jan 2025 10:34:14 GMT Received: from smtprelay02.fra02v.mail.ibm.com ([9.218.2.226]) by ppma21.wdc07v.mail.ibm.com (PPS) with ESMTPS id 4443yn7tk2-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Wed, 15 Jan 2025 10:34:14 +0000 Received: from smtpav02.fra02v.mail.ibm.com (smtpav02.fra02v.mail.ibm.com [10.20.54.101]) by smtprelay02.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 50FAYAsV36700564 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 15 Jan 2025 10:34:10 GMT Received: from smtpav02.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 387782004E; Wed, 15 Jan 2025 10:34:10 +0000 (GMT) Received: from smtpav02.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 18DA22005A; Wed, 15 Jan 2025 10:34:10 +0000 (GMT) Received: from fiuczyvm.. (unknown [9.152.222.247]) by smtpav02.fra02v.mail.ibm.com (Postfix) with ESMTP; Wed, 15 Jan 2025 10:34:10 +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=-3.0 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:date:from:in-reply-to:message-id :mime-version:references:subject:to; s=pp1; bh=172CM7O2XgUDCjF7j SXLtR1vpA/WfMeX1nFPf/UzCCo=; b=dgLazcFivo/YxxZKa8Vh9q+qQshVyv2cO QSbUCVnzYFpBEO3fl3b7gDdho91VpcqgqFL49nxX8TwaVaNQXj0U327UHquqv4+x JeRrvQ+u+MAo/Fvi0TZ10aAyeRYZedVZTJxJXJ6UQH4ealMJk3iY9U7WxXnSwBJ+ Cktbrl8nplY2TtvgyN/yEvaTC/ZJCLIJGT8Ker4h9CEVVObcLTR2ko33Wc7z2qZ1 tMN9QEKI2LxeLyIVP2V3YwxdUb3TK/iJLMekLfX7GExkWmu+EBowJCq1NPDV13YG 70TgPsJ9OS6ZV9Pl/miC6d+ahIlnA+fyjN//2eXuM/A3i/7GSeCnQ== From: Boris Fiuczynski To: devel@lists.libvirt.org Subject: [PATCH 2/4] remote: Implement virConnectGetHypervisorCPUModelNames Date: Wed, 15 Jan 2025 11:34:07 +0100 Message-ID: <20250115103409.31064-3-fiuczy@linux.ibm.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250115103409.31064-1-fiuczy@linux.ibm.com> References: <20250115103409.31064-1-fiuczy@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: I49y-6eE3fd6lW9YOrsgt-jpQq8YCxgm X-Proofpoint-ORIG-GUID: I49y-6eE3fd6lW9YOrsgt-jpQq8YCxgm X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1057,Hydra:6.0.680,FMLib:17.12.68.34 definitions=2025-01-15_04,2025-01-15_02,2024-11-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxscore=0 adultscore=0 clxscore=1015 phishscore=0 spamscore=0 suspectscore=0 priorityscore=1501 mlxlogscore=429 bulkscore=0 lowpriorityscore=0 malwarescore=0 impostorscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2411120000 definitions=main-2501150079 Content-Transfer-Encoding: quoted-printable Message-ID-Hash: QUFDF6BV5A5E5PKULPDYFCIMTB2TGGYB X-Message-ID-Hash: QUFDF6BV5A5E5PKULPDYFCIMTB2TGGYB X-MailFrom: fiuczy@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: djudkovi@linux.ibm.com, walling@linux.ibm.com 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: 1736937313878019000 Content-Type: text/plain; charset="utf-8" From: David Judkovics Adding access to virConnectGetHypervisorCPUModelNames running on a remote machine. Signed-off-by: David Judkovics Reviewed-by: Boris Fiuczynski Signed-off-by: Boris Fiuczynski --- src/remote/remote_daemon_dispatch.c | 62 +++++++++++++++++++++++++++++ src/remote/remote_driver.c | 52 ++++++++++++++++++++++++ src/remote/remote_protocol.x | 26 +++++++++++- src/remote_protocol-structs | 16 ++++++++ 4 files changed, 155 insertions(+), 1 deletion(-) diff --git a/src/remote/remote_daemon_dispatch.c b/src/remote/remote_daemon= _dispatch.c index e812f5c3e9..2d3db1c74e 100644 --- a/src/remote/remote_daemon_dispatch.c +++ b/src/remote/remote_daemon_dispatch.c @@ -5924,6 +5924,68 @@ remoteDispatchConnectGetCPUModelNames(virNetServer *= server G_GNUC_UNUSED, } =20 =20 +static int +remoteDispatchConnectGetHypervisorCPUModelNames(virNetServer *server G_GNU= C_UNUSED, + virNetServerClient *client, + virNetMessage *msg G_GNUC_= UNUSED, + struct virNetMessageError = *rerr, + remote_connect_get_hypervi= sor_cpu_model_names_args *args, + remote_connect_get_hypervi= sor_cpu_model_names_ret *ret) +{ + int len, rv =3D -1; + char *emulator; + char *arch; + char *machine; + char *virttype; + + g_auto(GStrv) models =3D NULL; + virConnectPtr conn =3D remoteGetHypervisorConn(client); + + if (!conn) + goto cleanup; + + emulator =3D args->emulator ? *args->emulator : NULL; + arch =3D args->arch ? *args->arch : NULL; + machine =3D args->machine ? *args->machine : NULL; + virttype =3D args->virttype ? *args->virttype : NULL; + + len =3D virConnectGetHypervisorCPUModelNames(conn, + emulator, + arch, + machine, + virttype, + args->need_results ? &model= s : NULL, + args->flags); + + if (len < 0) + goto cleanup; + + if (len > REMOTE_CONNECT_HYPERVISOR_CPU_MODELS_MAX) { + virReportError(VIR_ERR_RPC, + _("Too many CPU models '%1$d' for limit '%2$d'"), + len, REMOTE_CONNECT_HYPERVISOR_CPU_MODELS_MAX); + goto cleanup; + } + + if (len && models) { + ret->models.models_val =3D g_steal_pointer(&models); + ret->models.models_len =3D len; + } else { + ret->models.models_val =3D NULL; + ret->models.models_len =3D 0; + } + + ret->ret =3D len; + + rv =3D 0; + + cleanup: + if (rv < 0) + virNetMessageSaveError(rerr); + return rv; +} + + static int remoteDispatchDomainCreateXMLWithFiles(virNetServer *server G_GNUC_UNUSED, virNetServerClient *client, diff --git a/src/remote/remote_driver.c b/src/remote/remote_driver.c index 307f9ca945..f5e2c88723 100644 --- a/src/remote/remote_driver.c +++ b/src/remote/remote_driver.c @@ -5865,6 +5865,57 @@ remoteConnectGetCPUModelNames(virConnectPtr conn, } =20 =20 +static int +remoteConnectGetHypervisorCPUModelNames(virConnectPtr conn, + const char *emulator, + const char *arch, + const char *machine, + const char *virttype, + char ***models, + unsigned int flags) +{ + size_t i; + g_auto(GStrv) retmodels =3D NULL; + remote_connect_get_hypervisor_cpu_model_names_args args =3D {0}; + g_auto(remote_connect_get_hypervisor_cpu_model_names_ret) ret =3D {0}; + struct private_data *priv =3D conn->privateData; + VIR_LOCK_GUARD lock =3D remoteDriverLock(priv); + + args.emulator =3D emulator ? (char **)&emulator : NULL; + args.arch =3D arch ? (char **)&arch : NULL; + args.machine =3D machine ? (char **)&machine : NULL; + args.virttype =3D virttype ? (char **)&virttype : NULL; + args.need_results =3D !!models; + args.flags =3D flags; + + if (call(conn, priv, 0, REMOTE_PROC_CONNECT_GET_HYPERVISOR_CPU_MODEL_N= AMES, + (xdrproc_t) xdr_remote_connect_get_hypervisor_cpu_model_names= _args, + (char *) &args, + (xdrproc_t) xdr_remote_connect_get_hypervisor_cpu_model_names= _ret, + (char *) &ret) < 0) + return -1; + + /* Check the length of the returned list carefully. */ + if (ret.models.models_len > REMOTE_CONNECT_HYPERVISOR_CPU_MODELS_MAX) { + virReportError(VIR_ERR_RPC, + _("Too many model names '%1$d' for limit '%2$d'"), + ret.models.models_len, + REMOTE_CONNECT_HYPERVISOR_CPU_MODELS_MAX); + return -1; + } + + if (models) { + retmodels =3D g_new0(char *, ret.models.models_len + 1); + for (i =3D 0; i < ret.models.models_len; i++) { + retmodels[i] =3D g_steal_pointer(&ret.models.models_val[i]); + } + *models =3D g_steal_pointer(&retmodels); + } + + return ret.ret; +} + + static int remoteDomainOpenGraphics(virDomainPtr dom, unsigned int idx, @@ -7815,6 +7866,7 @@ static virHypervisorDriver hypervisor_driver =3D { .domainSetLifecycleAction =3D remoteDomainSetLifecycleAction, /* 3.9.0= */ .connectCompareHypervisorCPU =3D remoteConnectCompareHypervisorCPU, /*= 4.4.0 */ .connectBaselineHypervisorCPU =3D remoteConnectBaselineHypervisorCPU, = /* 4.4.0 */ + .connectGetHypervisorCPUModelNames =3D remoteConnectGetHypervisorCPUMo= delNames, /* 11.1.0 */ .nodeGetSEVInfo =3D remoteNodeGetSEVInfo, /* 4.5.0 */ .domainGetLaunchSecurityInfo =3D remoteDomainGetLaunchSecurityInfo, /*= 4.5.0 */ .domainCheckpointCreateXML =3D remoteDomainCheckpointCreateXML, /* 5.6= .0 */ diff --git a/src/remote/remote_protocol.x b/src/remote/remote_protocol.x index 41c045ff78..3daf991e2d 100644 --- a/src/remote/remote_protocol.x +++ b/src/remote/remote_protocol.x @@ -239,6 +239,9 @@ const REMOTE_DOMAIN_JOB_STATS_MAX =3D 64; /* Upper limit on number of CPU models */ const REMOTE_CONNECT_CPU_MODELS_MAX =3D 8192; =20 +/* Upper limit on number Hypervisor CPU models */ +const REMOTE_CONNECT_HYPERVISOR_CPU_MODELS_MAX =3D 256; + /* Upper limit on number of mountpoints to frozen */ const REMOTE_DOMAIN_FSFREEZE_MOUNTPOINTS_MAX =3D 256; =20 @@ -3679,6 +3682,20 @@ struct remote_connect_baseline_hypervisor_cpu_ret { remote_nonnull_string cpu; }; =20 +struct remote_connect_get_hypervisor_cpu_model_names_args { + remote_string emulator; + remote_string arch; + remote_string machine; + remote_string virttype; + int need_results; + unsigned int flags; +}; + +struct remote_connect_get_hypervisor_cpu_model_names_ret { + remote_nonnull_string models; + int ret; +}; + struct remote_node_get_sev_info_args { int nparams; unsigned int flags; @@ -7048,5 +7065,12 @@ enum remote_procedure { * @generate: both * @acl: domain:write */ - REMOTE_PROC_DOMAIN_GRAPHICS_RELOAD =3D 448 + REMOTE_PROC_DOMAIN_GRAPHICS_RELOAD =3D 448, + + /** + * @generate: none + * @priority: high + * @acl: connect:write + */ + REMOTE_PROC_CONNECT_GET_HYPERVISOR_CPU_MODEL_NAMES =3D 449 }; diff --git a/src/remote_protocol-structs b/src/remote_protocol-structs index 4d3dc2d249..6d354ab6cc 100644 --- a/src/remote_protocol-structs +++ b/src/remote_protocol-structs @@ -3031,6 +3031,21 @@ struct remote_connect_baseline_hypervisor_cpu_args { struct remote_connect_baseline_hypervisor_cpu_ret { remote_nonnull_string cpu; }; +struct remote_connect_get_hypervisor_cpu_model_names_args { + remote_string emulator; + remote_string arch; + remote_string machine; + remote_string virttype; + int need_results; + u_int flags; +}; +struct remote_connect_get_hypervisor_cpu_model_names_ret { + struct { + u_int models_len; + remote_nonnull_string * models_val; + } models; + int ret; +}; struct remote_node_get_sev_info_args { int nparams; u_int flags; @@ -3755,4 +3770,5 @@ enum remote_procedure { REMOTE_PROC_NETWORK_EVENT_CALLBACK_METADATA_CHANGE =3D 446, REMOTE_PROC_NODE_DEVICE_UPDATE =3D 447, REMOTE_PROC_DOMAIN_GRAPHICS_RELOAD =3D 448, + REMOTE_PROC_CONNECT_GET_HYPERVISOR_CPU_MODEL_NAMES =3D 449, }; --=20 2.47.0 From nobody Tue Jan 21 04:14:26 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 1736937396232107.37547514028756; Wed, 15 Jan 2025 02:36:36 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 996) id 95332190F; Wed, 15 Jan 2025 05:36:35 -0500 (EST) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id BDF8219AF; Wed, 15 Jan 2025 05:34:27 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 996) id DE13D15F8; Wed, 15 Jan 2025 05:34:16 -0500 (EST) 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 0DDB2161A for ; Wed, 15 Jan 2025 05:34:15 -0500 (EST) Received: from pps.filterd (m0356517.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 50F3r0LD019701 for ; Wed, 15 Jan 2025 10:34:15 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 4465gjshxw-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Wed, 15 Jan 2025 10:34:14 +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 50F9fIYr004554 for ; Wed, 15 Jan 2025 10:34:14 GMT Received: from smtprelay02.fra02v.mail.ibm.com ([9.218.2.226]) by ppma12.dal12v.mail.ibm.com (PPS) with ESMTPS id 4442ysr0sn-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Wed, 15 Jan 2025 10:34:14 +0000 Received: from smtpav02.fra02v.mail.ibm.com (smtpav02.fra02v.mail.ibm.com [10.20.54.101]) by smtprelay02.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 50FAYAN136700566 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 15 Jan 2025 10:34:10 GMT Received: from smtpav02.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 56F872005A; Wed, 15 Jan 2025 10:34:10 +0000 (GMT) Received: from smtpav02.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 3E31E2004F; Wed, 15 Jan 2025 10:34:10 +0000 (GMT) Received: from fiuczyvm.. (unknown [9.152.222.247]) by smtpav02.fra02v.mail.ibm.com (Postfix) with ESMTP; Wed, 15 Jan 2025 10:34:10 +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=-3.0 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:date:from:in-reply-to:message-id :mime-version:references:subject:to; s=pp1; bh=CwpSHw+A+toSQSIcv Y+yR6AQmG4EvH88IZmVWdc9xzE=; b=qV49L4WrTo1f0SaSAtdmoRkRI0NStjCgk KimdLiJhzGLrVK/7P1xURO3oKi1DrViAqV2jtt/UnR78380YoK/nGTU5f/c5pbgJ BCV2vl6ZkGP55wbmgOafoqWEMRsdia2A0tKzXLJkCJ+pYNoZW37fBKKQtwKxdwGM nnlvexSiZ5ra7+MX+e2gwffHX2pCji0nV4YJ3jXlXseArZRt9aqgGGeamzIZF64T pBKo9z8gzxgaIs1BpWLyyjwYSeh6Q0d4PoLRlcey9lo/oiWamYida4IYa2QqBCGi Lbr5iCcDE260n/RJ4zf1qj0sTgaAy7vaBx5KY2VGg3bI2tJ6l58tg== From: Boris Fiuczynski To: devel@lists.libvirt.org Subject: [PATCH 3/4] qemu_driver: Implement qemuConnectGetHypervisorCPUModelNames Date: Wed, 15 Jan 2025 11:34:08 +0100 Message-ID: <20250115103409.31064-4-fiuczy@linux.ibm.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250115103409.31064-1-fiuczy@linux.ibm.com> References: <20250115103409.31064-1-fiuczy@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: ESvubww5RWFx7sYpYWLNocYRsj6rauug X-Proofpoint-GUID: ESvubww5RWFx7sYpYWLNocYRsj6rauug X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1057,Hydra:6.0.680,FMLib:17.12.68.34 definitions=2025-01-15_04,2025-01-15_02,2024-11-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 bulkscore=0 phishscore=0 clxscore=1015 suspectscore=0 lowpriorityscore=0 malwarescore=0 spamscore=0 priorityscore=1501 mlxlogscore=369 impostorscore=0 adultscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2411120000 definitions=main-2501150079 Content-Transfer-Encoding: quoted-printable Message-ID-Hash: KAFT75FFZUZCIXLMP6GZZKPGH7RLE4JX X-Message-ID-Hash: KAFT75FFZUZCIXLMP6GZZKPGH7RLE4JX X-MailFrom: fiuczy@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: djudkovi@linux.ibm.com, walling@linux.ibm.com 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: 1736937398300019000 Content-Type: text/plain; charset="utf-8" From: David Judkovics This function is utilized by the new virsh hypervisor-cpu-models command. The CPU models are read directly from the QEMU capabilities file, which contains a list of all models queried from the hypervisor. Signed-off-by: David Judkovics Signed-off-by: Collin Walling Reviewed-by: Boris Fiuczynski Signed-off-by: Boris Fiuczynski --- src/qemu/qemu_driver.c | 59 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index d2eddbd9ae..1a795cebd0 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -11948,6 +11948,64 @@ qemuConnectBaselineHypervisorCPU(virConnectPtr con= n, } =20 =20 +static int +qemuConnectGetHypervisorCPUModelNames(virConnectPtr conn, + const char *emulator, + const char *archStr, + const char *machine, + const char *virttypeStr, + char ***models, + unsigned int flags) +{ + virQEMUDriver *driver =3D conn->privateData; + g_autoptr(virQEMUCaps) qemuCaps =3D NULL; + virArch arch; + virDomainVirtType virttype; + g_autoptr(virDomainCaps) domCaps =3D NULL; + size_t i =3D 0; + + virDomainCapsCPUModel *customModels =3D NULL; + int customNumModels; + + virCheckFlags(0, -1); + + if (virConnectGetHypervisorCPUModelNamesEnsureACL(conn) < 0) + return -1; + + qemuCaps =3D virQEMUCapsCacheLookupDefault(driver->qemuCapsCache, + emulator, + archStr, + virttypeStr, + machine, + &arch, + &virttype, + &machine); + if (!qemuCaps) + return -1; + + if (!(domCaps =3D virQEMUDriverGetDomainCapabilities(driver, + qemuCaps, + machine, + arch, + virttype))) + return -1; + + customModels =3D domCaps->cpu.custom->models; + customNumModels =3D domCaps->cpu.custom->nmodels; + + if (models) { + *models =3D g_new0(char *, customNumModels); + for (i =3D 0; i < customNumModels; i++) { + (*models)[i] =3D g_strdup(customModels[i].name); + VIR_DEBUG("adding models[%zu] =3D name[%s]", + i, customModels[i].name); + } + } + + return customNumModels; +} + + static int qemuDomainGetJobInfoMigrationStats(virDomainObj *vm, virDomainJobData *jobData) @@ -20289,6 +20347,7 @@ static virHypervisorDriver qemuHypervisorDriver =3D= { .domainSetLifecycleAction =3D qemuDomainSetLifecycleAction, /* 3.9.0 */ .connectCompareHypervisorCPU =3D qemuConnectCompareHypervisorCPU, /* 4= .4.0 */ .connectBaselineHypervisorCPU =3D qemuConnectBaselineHypervisorCPU, /*= 4.4.0 */ + .connectGetHypervisorCPUModelNames =3D qemuConnectGetHypervisorCPUMode= lNames, /* 11.1.0 */ .nodeGetSEVInfo =3D qemuNodeGetSEVInfo, /* 4.5.0 */ .domainGetLaunchSecurityInfo =3D qemuDomainGetLaunchSecurityInfo, /* 4= .5.0 */ .domainCheckpointCreateXML =3D qemuDomainCheckpointCreateXML, /* 5.6.0= */ --=20 2.47.0 From nobody Tue Jan 21 04:14:26 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 1736937340309398.50228972730315; Wed, 15 Jan 2025 02:35:40 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 996) id A21F8190F; Wed, 15 Jan 2025 05:35:39 -0500 (EST) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 6DAE31996; Wed, 15 Jan 2025 05:34:23 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 996) id 976BC15FE; Wed, 15 Jan 2025 05:34:16 -0500 (EST) 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 EF28915F8 for ; Wed, 15 Jan 2025 05:34:15 -0500 (EST) Received: from pps.filterd (m0353729.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 50ENwKxh014643 for ; Wed, 15 Jan 2025 10:34:15 GMT Received: from ppma11.dal12v.mail.ibm.com (db.9e.1632.ip4.static.sl-reverse.com [50.22.158.219]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 44622ht7cf-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Wed, 15 Jan 2025 10:34:14 +0000 (GMT) Received: from pps.filterd (ppma11.dal12v.mail.ibm.com [127.0.0.1]) by ppma11.dal12v.mail.ibm.com (8.18.1.2/8.18.1.2) with ESMTP id 50F86bI5016499 for ; Wed, 15 Jan 2025 10:34:13 GMT Received: from smtprelay02.fra02v.mail.ibm.com ([9.218.2.226]) by ppma11.dal12v.mail.ibm.com (PPS) with ESMTPS id 4445p1qfpb-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Wed, 15 Jan 2025 10:34:13 +0000 Received: from smtpav02.fra02v.mail.ibm.com (smtpav02.fra02v.mail.ibm.com [10.20.54.101]) by smtprelay02.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 50FAYAMC38011298 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 15 Jan 2025 10:34:10 GMT Received: from smtpav02.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 72F0C20043; Wed, 15 Jan 2025 10:34:10 +0000 (GMT) Received: from smtpav02.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 5C7AA20063; Wed, 15 Jan 2025 10:34:10 +0000 (GMT) Received: from fiuczyvm.. (unknown [9.152.222.247]) by smtpav02.fra02v.mail.ibm.com (Postfix) with ESMTP; Wed, 15 Jan 2025 10:34:10 +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=-3.0 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:date:from:in-reply-to:message-id :mime-version:references:subject:to; s=pp1; bh=gkepbmcoKOg1VYowq c784N4XCtbhSk5jsSVQED1wz1g=; b=NbnHAomub+e3NiuwjpC4L4h+SiWlhWWQ0 RPFTeLYAgUaj60ws6Ni0pircBwQHSYs2xA+mJ4993k8vYQQ88sVPkAkc4yFtkLT7 5DM+51jtszITC/JB281fPDJVSJZ3iv1lUQeo9PrjF7tMgb5DhNRo94pH8DuhrtH8 aP84lGw3vXPpI2TwizScpibIS1JuxiItdx6ZTg9J4Z4jVrZc/636TjaPMm+Hlhsv S/MuzRMTuNWMQ23konvWa0dmnwcNM6dAuWopQIBlPu/LF5S2rbsYrjtd4UMKFzeQ PXlsTZovOWw7VsxgrGwJEYPEmo0Cz3AdeVVSMbEMU0KNnn5tyV6cw== From: Boris Fiuczynski To: devel@lists.libvirt.org Subject: [PATCH 4/4] virsh: Introduce new hypervisor-cpu-models command Date: Wed, 15 Jan 2025 11:34:09 +0100 Message-ID: <20250115103409.31064-5-fiuczy@linux.ibm.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250115103409.31064-1-fiuczy@linux.ibm.com> References: <20250115103409.31064-1-fiuczy@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: JNuEliRWxPpmUlnjfpjndKTcuHkylrHy X-Proofpoint-ORIG-GUID: JNuEliRWxPpmUlnjfpjndKTcuHkylrHy X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1057,Hydra:6.0.680,FMLib:17.12.68.34 definitions=2025-01-15_04,2025-01-15_02,2024-11-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 clxscore=1015 impostorscore=0 bulkscore=0 lowpriorityscore=0 phishscore=0 suspectscore=0 priorityscore=1501 mlxlogscore=817 malwarescore=0 adultscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2411120000 definitions=main-2501150079 Content-Transfer-Encoding: quoted-printable Message-ID-Hash: CJKC6ZXZQR7HSG3LEOE5OIOLH7UVKZRX X-Message-ID-Hash: CJKC6ZXZQR7HSG3LEOE5OIOLH7UVKZRX X-MailFrom: fiuczy@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: djudkovi@linux.ibm.com, walling@linux.ibm.com 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: 1736937342008019000 Content-Type: text/plain; charset="utf-8" From: David Judkovics Add new virsh 'host' group command 'hypervisor-cpu-models' to virsh. Signed-off-by: David Judkovics Reviewed-by: Boris Fiuczynski Signed-off-by: Boris Fiuczynski --- docs/manpages/virsh.rst | 20 +++++++++++ tools/virsh-host.c | 74 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 94 insertions(+) diff --git a/docs/manpages/virsh.rst b/docs/manpages/virsh.rst index e801037c04..0f165944eb 100644 --- a/docs/manpages/virsh.rst +++ b/docs/manpages/virsh.rst @@ -1023,6 +1023,26 @@ 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] + +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. + + 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 f4e7324f42..7d52f22baa 100644 --- a/tools/virsh-host.c +++ b/tools/virsh-host.c @@ -1758,6 +1758,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, + .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 NULL} +}; + +static bool +cmdHypervisorCPUModelNames(vshControl *ctl, + const vshCmd *cmd) +{ + const char *virttype =3D NULL; + char **models =3D NULL; + const char *emulator =3D NULL; + const char *arch =3D NULL; + const char *machine =3D NULL; + virshControl *priv =3D ctl->privData; + size_t i; + int nmodels; + + 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; + + nmodels =3D virConnectGetHypervisorCPUModelNames(priv->conn, emulator,= arch, + machine, virttype, &mod= els, 0); + + if (nmodels < 0) { + vshError(ctl, "%s", _("failed to get Hypervisor CPU model names")); + return false; + } + + for (i =3D 0; i < nmodels; i++) { + vshPrint(ctl, "%s\n", models[i]); + VIR_FREE(models[i]); + } + + VIR_FREE(models); + + return true; +} + + const vshCmdDef hostAndHypervisorCmds[] =3D { {.name =3D "allocpages", .handler =3D cmdAllocpages, @@ -1825,6 +1893,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.0