From nobody Wed May 14 02:46:51 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1526459998102694.2807009636552; Wed, 16 May 2018 01:39:58 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id A77C230C34AD; Wed, 16 May 2018 08:39:56 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 69F6817B4C; Wed, 16 May 2018 08:39:56 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 0A7E64A467; Wed, 16 May 2018 08:39:56 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w4G8djJS018346 for ; Wed, 16 May 2018 04:39:45 -0400 Received: by smtp.corp.redhat.com (Postfix) id 171A72166BAE; Wed, 16 May 2018 08:39:45 +0000 (UTC) Received: from virval.usersys.redhat.com (unknown [10.43.2.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id CCEE52166BAD for ; Wed, 16 May 2018 08:39:44 +0000 (UTC) Received: by virval.usersys.redhat.com (Postfix, from userid 500) id B2839102EE2; Wed, 16 May 2018 10:39:42 +0200 (CEST) From: Jiri Denemark To: libvir-list@redhat.com Date: Wed, 16 May 2018 10:39:27 +0200 Message-Id: <7e35a993aa0af18a2226801a48a78538d9c672da.1526459534.git.jdenemar@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 08/22] Introduce virConnectCompareHypervisorCPU public API X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.48]); Wed, 16 May 2018 08:39:57 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" This new API compares the given CPU description with the CPU the specified hypervisor is able to provide on the host. It is a more useful version of virConnectCompareCPU, which compares the CPU definition with the host CPU without considering any specific hypervisor and its abilities. Signed-off-by: Jiri Denemark Reviewed-by: Collin Walling Reviewed-by: J=EF=BF=BDn Tomko --- include/libvirt/libvirt-host.h | 7 ++++ src/driver-hypervisor.h | 10 +++++ src/libvirt-host.c | 72 +++++++++++++++++++++++++++++++++- src/libvirt_public.syms | 5 +++ 4 files changed, 93 insertions(+), 1 deletion(-) diff --git a/include/libvirt/libvirt-host.h b/include/libvirt/libvirt-host.h index 07b5d15943..e2054baebc 100644 --- a/include/libvirt/libvirt-host.h +++ b/include/libvirt/libvirt-host.h @@ -640,6 +640,13 @@ typedef enum { int virConnectCompareCPU(virConnectPtr conn, const char *xmlDesc, unsigned int flags); +int virConnectCompareHypervisorCPU(virConnectPtr conn, + const char *emulator, + const char *arch, + const char *machine, + const char *virttype, + const char *xmlCPU, + unsigned int flags); =20 int virConnectGetCPUModelNames(virConnectPtr conn, const char *arch, diff --git a/src/driver-hypervisor.h b/src/driver-hypervisor.h index e71a72a441..d64de2d54c 100644 --- a/src/driver-hypervisor.h +++ b/src/driver-hypervisor.h @@ -673,6 +673,15 @@ typedef int const char *cpu, unsigned int flags); =20 +typedef int +(*virDrvConnectCompareHypervisorCPU)(virConnectPtr conn, + const char *emulator, + const char *arch, + const char *machine, + const char *virttype, + const char *xmlCPU, + unsigned int flags); + typedef char * (*virDrvConnectBaselineCPU)(virConnectPtr conn, const char **xmlCPUs, @@ -1532,6 +1541,7 @@ struct _virHypervisorDriver { virDrvDomainSetVcpu domainSetVcpu; virDrvDomainSetBlockThreshold domainSetBlockThreshold; virDrvDomainSetLifecycleAction domainSetLifecycleAction; + virDrvConnectCompareHypervisorCPU connectCompareHypervisorCPU; }; =20 =20 diff --git a/src/libvirt-host.c b/src/libvirt-host.c index ed689b9ec2..17cf183499 100644 --- a/src/libvirt-host.c +++ b/src/libvirt-host.c @@ -954,7 +954,11 @@ virConnectIsSecure(virConnectPtr conn) * @xmlDesc: XML describing the CPU to compare with host CPU * @flags: bitwise-OR of virConnectCompareCPUFlags * - * Compares the given CPU description with the host CPU + * Compares the given CPU description with the host CPU. + * + * See vitConnectCompareHypervisorCPU() if you want to consider hypervisor + * abilities and compare the CPU to the CPU which a hypervisor is able to + * provide on the host. * * Returns comparison result according to enum virCPUCompareResult. If * VIR_CONNECT_COMPARE_CPU_FAIL_INCOMPATIBLE is used and @xmlDesc CPU is @@ -992,6 +996,72 @@ virConnectCompareCPU(virConnectPtr conn, } =20 =20 +/** + * virConnectCompareHypervisorCPU: + * @conn: pointer to the hypervisor connection + * @emulator: path to the emulator binary + * @arch: domain architecture + * @machine: machine type + * @virttype: virtualization type + * @xmlCPU: XML describing the CPU to be compared + * @flags: bitwise-OR of virConnectCompareCPUFlags + * + * Compares the given CPU description with the CPU the specified hyperviso= r is + * able to provide on the host. Any of @emulator, @arch, @machine, and + * @virttype parameters may be NULL; libvirt will choose sensible defaults + * tailored to the host and its current configuration. + * + * This is different from virConnectCompareCPU() which compares the CPU + * definition with the host CPU without considering any specific hyperviso= r and + * its abilities. + * + * Returns comparison result according to enum virCPUCompareResult. If + * VIR_CONNECT_COMPARE_CPU_FAIL_INCOMPATIBLE is used and @xmlCPU is + * incompatible with the CPU the specified hypervisor is able to provide o= n the + * host, this function will return VIR_CPU_COMPARE_ERROR (instead of + * VIR_CPU_COMPARE_INCOMPATIBLE) and the error will use the + * VIR_ERR_CPU_INCOMPATIBLE code with a message providing more details abo= ut + * the incompatibility. + */ +int +virConnectCompareHypervisorCPU(virConnectPtr conn, + const char *emulator, + const char *arch, + const char *machine, + const char *virttype, + const char *xmlCPU, + unsigned int flags) +{ + VIR_DEBUG("conn=3D%p, emulator=3D%s, arch=3D%s, machine=3D%s, " + "virttype=3D%s, xmlCPU=3D%s, flags=3D0x%x", + conn, NULLSTR(emulator), NULLSTR(arch), NULLSTR(machine), + NULLSTR(virttype), NULLSTR(xmlCPU), flags); + + virResetLastError(); + + virCheckConnectReturn(conn, VIR_CPU_COMPARE_ERROR); + virCheckNonNullArgGoto(xmlCPU, error); + + if (conn->driver->connectCompareHypervisorCPU) { + int ret; + + ret =3D conn->driver->connectCompareHypervisorCPU(conn, emulator, = arch, + machine, virttype, + xmlCPU, flags); + if (ret =3D=3D VIR_CPU_COMPARE_ERROR) + goto error; + + return ret; + } + + virReportUnsupportedError(); + + error: + virDispatchError(conn); + return VIR_CPU_COMPARE_ERROR; +} + + /** * virConnectGetCPUModelNames: * diff --git a/src/libvirt_public.syms b/src/libvirt_public.syms index 95df3a0dbc..97597d7708 100644 --- a/src/libvirt_public.syms +++ b/src/libvirt_public.syms @@ -785,4 +785,9 @@ LIBVIRT_4.1.0 { virStoragePoolLookupByTargetPath; } LIBVIRT_3.9.0; =20 +LIBVIRT_4.4.0 { + global: + virConnectCompareHypervisorCPU; +} LIBVIRT_4.1.0; + # .... define new API here using predicted next version number .... --=20 2.17.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list