From 7d0a1efcd6087096671f3769ec2b850292465e9a Mon Sep 17 00:00:00 2001 From: Jiri Denemark Date: Tue, 24 Apr 2018 23:33:28 +0200 Subject: [PATCH] Introduce virConnectBaselineHypervisorCPU public API MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 virConnectBaselineCPU, which doesn't consider any hypervisor capabilities when computing the best CPU. Signed-off-by: Jiri Denemark Reviewed-by: Ján Tomko Reviewed-by: Collin Walling --- 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); int virNodeGetFreePages(virConnectPtr conn, diff --git a/src/driver-hypervisor.h b/src/driver-hypervisor.h index 4ba1f57710..aa99cbbb05 100644 --- a/src/driver-hypervisor.h +++ b/src/driver-hypervisor.h @@ -692,6 +692,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); typedef int (*virDrvConnectGetCPUModelNames)(virConnectPtr conn, @@ -1548,6 +1557,7 @@ struct _virHypervisorDriver { virDrvDomainSetBlockThreshold domainSetBlockThreshold; virDrvDomainSetLifecycleAction domainSetLifecycleAction; virDrvConnectCompareHypervisorCPU connectCompareHypervisorCPU; + virDrvConnectBaselineHypervisorCPU connectBaselineHypervisorCPU; }; diff --git a/src/libvirt-host.c b/src/libvirt-host.c index 1ee753e10f..3aaf558cac 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 virConnectBaselineHypervisorCPU() to get a CPU which can be provided + * by the 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, } +/** + * virConnectBaselineHypervisorCPU: + * + * @conn: pointer to the hypervisor connection + * @emulator: path to the emulator binary + * @arch: CPU 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 CPUs + * and can be provided by the specified hypervisor. For best results the + * host-model CPUs as advertised by virConnectGetDomainCapabilities() should 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 virConnectBaselineCPU() which doesn't consider any + * 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 error. + */ +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=%p, emulator=%s, arch=%s, machine=%s, " + "virttype=%s, xmlCPUs=%p, ncpus=%u, flags=0x%x", + conn, NULLSTR(emulator), NULLSTR(arch), NULLSTR(machine), + NULLSTR(virttype), xmlCPUs, ncpus, flags); + if (xmlCPUs) { + for (i = 0; i < ncpus; i++) + VIR_DEBUG("xmlCPUs[%zu]=%s", i, NULLSTR(xmlCPUs[i])); + } + + virResetLastError(); + + virCheckConnectReturn(conn, NULL); + virCheckNonNullArgGoto(xmlCPUs, error); + + if (conn->driver->connectBaselineHypervisorCPU) { + char *cpu; + + cpu = conn->driver->connectBaselineHypervisorCPU(conn, emulator, arch, + machine, virttype, + xmlCPUs, ncpus, flags); + 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 b6414fdc16..958601b1a5 100644 --- a/src/libvirt_public.syms +++ b/src/libvirt_public.syms @@ -789,6 +789,7 @@ LIBVIRT_4.4.0 { global: virDomainDetachDeviceAlias; virConnectCompareHypervisorCPU; + virConnectBaselineHypervisorCPU; } LIBVIRT_4.1.0; # .... define new API here using predicted next version number ....