Sign Up
Log In
Log In
or
Sign Up
Places
All Projects
Status Monitor
Collapse sidebar
SUSE:SLE-12-SP1:Update
libvirt.10484
ea51e6a0-cpu_x86-Compare-CPU-candidates-in-a-se...
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
File ea51e6a0-cpu_x86-Compare-CPU-candidates-in-a-separate-functio.patch of Package libvirt.10484
From ea51e6a04550422d92aa9421f6dc61436f8302fc Mon Sep 17 00:00:00 2001 From: Jiri Denemark <jdenemar@redhat.com> Date: Thu, 12 May 2016 14:50:17 +0200 Subject: [PATCH] cpu_x86: Compare CPU candidates in a separate function Splitting the comparison into a separate function makes the code cleaner and easier to update in the future. Signed-off-by: Jiri Denemark <jdenemar@redhat.com> --- src/cpu/cpu_x86.c | 65 ++++++++++++++++++++++++++++++++++++------------------- 1 file changed, 43 insertions(+), 22 deletions(-) Index: libvirt-1.2.18.4/src/cpu/cpu_x86.c =================================================================== --- libvirt-1.2.18.4.orig/src/cpu/cpu_x86.c +++ libvirt-1.2.18.4/src/cpu/cpu_x86.c @@ -1538,6 +1538,43 @@ x86GuestData(virCPUDefPtr host, } +/* + * Checks whether cpuCandidate is a better fit for the CPU data than the + * currently selected one from cpuCurrent. + * + * Returns 0 if cpuCurrent is better, + * 1 if cpuCandidate is better, + * 2 if cpuCandidate is the best one (search should stop now). + */ +static int +x86DecodeUseCandidate(virCPUDefPtr cpuCurrent, + virCPUDefPtr cpuCandidate, + const char *preferred, + bool checkPolicy) +{ + if (checkPolicy) { + size_t i; + for (i = 0; i < cpuCandidate->nfeatures; i++) { + if (cpuCandidate->features[i].policy == VIR_CPU_FEATURE_DISABLE) + return 0; + cpuCandidate->features[i].policy = -1; + } + } + + if (preferred && + STREQ(cpuCandidate->model, preferred)) + return 2; + + if (!cpuCurrent) + return 1; + + if (cpuCurrent->nfeatures > cpuCandidate->nfeatures) + return 1; + + return 0; +} + + static int x86Decode(virCPUDefPtr cpu, const virCPUx86Data *data, @@ -1555,6 +1592,7 @@ x86Decode(virCPUDefPtr cpu, virCPUx86Data *features = NULL; const virCPUx86Data *cpuData = NULL; size_t i; + int rc; virCheckFlags(VIR_CONNECT_BASELINE_CPU_EXPAND_FEATURES | VIR_CONNECT_BASELINE_CPU_MIGRATABLE, -1); @@ -1585,6 +1623,7 @@ x86Decode(virCPUDefPtr cpu, if (!(cpuCandidate = x86DataToCPU(data, candidate, map))) goto out; + cpuCandidate->type = cpu->type; if (candidate->vendor && cpuCandidate->vendor && STRNEQ(candidate->vendor->name, cpuCandidate->vendor)) { @@ -1595,31 +1634,13 @@ x86Decode(virCPUDefPtr cpu, goto next; } - if (cpu->type == VIR_CPU_TYPE_HOST) { - cpuCandidate->type = VIR_CPU_TYPE_HOST; - for (i = 0; i < cpuCandidate->nfeatures; i++) { - switch (cpuCandidate->features[i].policy) { - case VIR_CPU_FEATURE_DISABLE: - virCPUDefFree(cpuCandidate); - goto next; - default: - cpuCandidate->features[i].policy = -1; - } - } - } - - if (preferred && STREQ(cpuCandidate->model, preferred)) { - virCPUDefFree(cpuModel); - cpuModel = cpuCandidate; - cpuData = candidate->data; - break; - } - - if (cpuModel == NULL - || cpuModel->nfeatures > cpuCandidate->nfeatures) { + if ((rc = x86DecodeUseCandidate(cpuModel, cpuCandidate, preferred, + cpu->type == VIR_CPU_TYPE_HOST))) { virCPUDefFree(cpuModel); cpuModel = cpuCandidate; cpuData = candidate->data; + if (rc == 2) + break; } else { virCPUDefFree(cpuCandidate); }
Locations
Projects
Search
Status Monitor
Help
OpenBuildService.org
Documentation
API Documentation
Code of Conduct
Contact
Support
@OBShq
Terms
openSUSE Build Service is sponsored by
The Open Build Service is an
openSUSE project
.
Sign Up
Log In
Places
Places
All Projects
Status Monitor