From nobody Wed May 14 20:48:14 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 1526460025027784.6913982425364; Wed, 16 May 2018 01:40:25 -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 1A588A703B; Wed, 16 May 2018 08:40:23 +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 B8A3E2B476; Wed, 16 May 2018 08:40:22 +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 3C4093D385; Wed, 16 May 2018 08:40:22 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w4G8dkct018384 for ; Wed, 16 May 2018 04:39:46 -0400 Received: by smtp.corp.redhat.com (Postfix) id 3C9DE2024CBE; Wed, 16 May 2018 08:39:46 +0000 (UTC) Received: from virval.usersys.redhat.com (unknown [10.43.2.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id F23DF2024CBB for ; Wed, 16 May 2018 08:39:45 +0000 (UTC) Received: by virval.usersys.redhat.com (Postfix, from userid 500) id C887B102EE9; Wed, 16 May 2018 10:39:42 +0200 (CEST) From: Jiri Denemark To: libvir-list@redhat.com Date: Wed, 16 May 2018 10:39:31 +0200 Message-Id: <5c6cef8a6d570656113531fefbc1d9458a3193e4.1526459534.git.jdenemar@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 12/22] Introduce virConnectBaselineHypervisorCPU 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.30]); Wed, 16 May 2018 08:40:24 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" The new API computes the most feature-rich CPU which is compatible with all given CPUs and can be provided by the specified hypervisor. It is a more useful version of vitConnectBaselineCPU, which doesn't consider any hypervisor capabilities when computing the best CPU. Signed-off-by: Jiri Denemark Reviewed-by: Collin Walling Reviewed-by: J=EF=BF=BDn Tomko --- include/libvirt/libvirt-host.h | 8 ++++ src/driver-hypervisor.h | 10 +++++ src/libvirt-host.c | 81 ++++++++++++++++++++++++++++++++++ src/libvirt_public.syms | 1 + 4 files changed, 100 insertions(+) diff --git a/include/libvirt/libvirt-host.h b/include/libvirt/libvirt-host.h index e2054baebc..84f4858169 100644 --- a/include/libvirt/libvirt-host.h +++ b/include/libvirt/libvirt-host.h @@ -667,6 +667,14 @@ char *virConnectBaselineCPU(virConnectPtr conn, const char **xmlCPUs, unsigned int ncpus, unsigned int flags); +char *virConnectBaselineHypervisorCPU(virConnectPtr conn, + const char *emulator, + const char *arch, + const char *machine, + const char *virttype, + const char **xmlCPUs, + unsigned int ncpus, + unsigned int flags); =20 =20 int virNodeGetFreePages(virConnectPtr conn, diff --git a/src/driver-hypervisor.h b/src/driver-hypervisor.h index d64de2d54c..9ce0d7e5de 100644 --- a/src/driver-hypervisor.h +++ b/src/driver-hypervisor.h @@ -687,6 +687,15 @@ typedef char * const char **xmlCPUs, unsigned int ncpus, unsigned int flags); +typedef char * +(*virDrvConnectBaselineHypervisorCPU)(virConnectPtr conn, + const char *emulator, + const char *arch, + const char *machine, + const char *virttype, + const char **xmlCPUs, + unsigned int ncpus, + unsigned int flags); =20 typedef int (*virDrvConnectGetCPUModelNames)(virConnectPtr conn, @@ -1542,6 +1551,7 @@ struct _virHypervisorDriver { virDrvDomainSetBlockThreshold domainSetBlockThreshold; virDrvDomainSetLifecycleAction domainSetLifecycleAction; virDrvConnectCompareHypervisorCPU connectCompareHypervisorCPU; + virDrvConnectBaselineHypervisorCPU connectBaselineHypervisorCPU; }; =20 =20 diff --git a/src/libvirt-host.c b/src/libvirt-host.c index 17cf183499..cdbbe35e5a 100644 --- a/src/libvirt-host.c +++ b/src/libvirt-host.c @@ -1127,6 +1127,9 @@ virConnectGetCPUModelNames(virConnectPtr conn, const = char *arch, char ***models, * Computes the most feature-rich CPU which is compatible with all given * host CPUs. * + * See vitConnectBaselineHypervisorCPU() to get a CPU which can be provided + * by a specific hypervisor. + * * If @flags includes VIR_CONNECT_BASELINE_CPU_EXPAND_FEATURES then libvirt * will explicitly list all CPU features that are part of the host CPU, * without this flag features that are part of the CPU model will not be @@ -1174,6 +1177,84 @@ virConnectBaselineCPU(virConnectPtr conn, } =20 =20 +/** + * virConnectBaselineHypervisorCPU: + * + * @conn: pointer to the hypervisor connection + * @emulator: path to the emulator binary + * @arch: domain architecture + * @machine: machine type + * @virttype: virtualization type + * @xmlCPUs: array of XML descriptions of CPUs + * @ncpus: number of CPUs in xmlCPUs + * @flags: bitwise-OR of virConnectBaselineCPUFlags + * + * Computes the most feature-rich CPU which is compatible with all given C= PUs + * and can be provided by the specified hypervisor. For best results the + * host-model CPUs as advertised by virConnectGetDomainCapabilities() shou= ld be + * passed in @xmlCPUs. 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 vitConnectBaselineCPU() which doesn't consider a= ny + * hypervisor abilities when computing the best CPU. + * + * If @flags includes VIR_CONNECT_BASELINE_CPU_EXPAND_FEATURES then libvirt + * will explicitly list all CPU features that are part of the computed CPU, + * without this flag features that are part of the CPU model will not be + * listed. + * + * If @flags includes VIR_CONNECT_BASELINE_CPU_MIGRATABLE, the resulting + * CPU will not include features that block migration. + * + * Returns XML description of the computed CPU (caller frees) or NULL on e= rror. + */ +char * +virConnectBaselineHypervisorCPU(virConnectPtr conn, + const char *emulator, + const char *arch, + const char *machine, + const char *virttype, + const char **xmlCPUs, + unsigned int ncpus, + unsigned int flags) +{ + size_t i; + + VIR_DEBUG("conn=3D%p, emulator=3D%s, arch=3D%s, machine=3D%s, " + "virttype=3D%s, xmlCPUs=3D%p, ncpus=3D%u, flags=3D0x%x", + conn, NULLSTR(emulator), NULLSTR(arch), NULLSTR(machine), + NULLSTR(virttype), xmlCPUs, ncpus, flags); + if (xmlCPUs) { + for (i =3D 0; i < ncpus; i++) + VIR_DEBUG("xmlCPUs[%zu]=3D%s", i, NULLSTR(xmlCPUs[i])); + } + + virResetLastError(); + + virCheckConnectReturn(conn, NULL); + virCheckNonNullArgGoto(xmlCPUs, error); + + if (conn->driver->connectBaselineHypervisorCPU) { + char *cpu; + + cpu =3D conn->driver->connectBaselineHypervisorCPU(conn, emulator,= arch, + machine, virttype, + xmlCPUs, ncpus, f= lags); + if (!cpu) + goto error; + + return cpu; + } + + virReportUnsupportedError(); + + error: + virDispatchError(conn); + return NULL; +} + + /** * virConnectSetKeepAlive: * @conn: pointer to a hypervisor connection diff --git a/src/libvirt_public.syms b/src/libvirt_public.syms index 97597d7708..05ab077fb4 100644 --- a/src/libvirt_public.syms +++ b/src/libvirt_public.syms @@ -788,6 +788,7 @@ LIBVIRT_4.1.0 { LIBVIRT_4.4.0 { global: virConnectCompareHypervisorCPU; + virConnectBaselineHypervisorCPU; } LIBVIRT_4.1.0; =20 # .... 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