mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-08-28 11:31:16 +00:00
cpu: Introduce virCPUCopyMigratable
This new internal API makes a copy of virCPUDef while removing all features which would block migration. It uses cpu_map.xml as a database of such features, which should only be used as a fallback when we cannot get the data from a hypervisor. The main goal of this API is to decouple this filtering from virCPUUpdate so that the hypervisor driver can filter the features according to the hypervisor. Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
This commit is contained in:
parent
f0ad8e7ee0
commit
05e91c79f1
@ -1130,3 +1130,34 @@ virCPUExpandFeatures(virArch arch,
|
|||||||
VIR_DEBUG("nfeatures=%zu", cpu->nfeatures);
|
VIR_DEBUG("nfeatures=%zu", cpu->nfeatures);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* virCPUCopyMigratable:
|
||||||
|
*
|
||||||
|
* @arch: CPU architecture
|
||||||
|
* @cpu: CPU definition to be copied
|
||||||
|
*
|
||||||
|
* Makes a copy of @cpu with all features which would block migration removed.
|
||||||
|
* If this doesn't make sense for a given architecture, the function returns a
|
||||||
|
* plain copy of @cpu (i.e., a copy with no features removed).
|
||||||
|
*
|
||||||
|
* Returns the copy of the CPU or NULL on error.
|
||||||
|
*/
|
||||||
|
virCPUDefPtr
|
||||||
|
virCPUCopyMigratable(virArch arch,
|
||||||
|
virCPUDefPtr cpu)
|
||||||
|
{
|
||||||
|
struct cpuArchDriver *driver;
|
||||||
|
|
||||||
|
VIR_DEBUG("arch=%s, cpu=%p, model=%s",
|
||||||
|
virArchToString(arch), cpu, NULLSTR(cpu->model));
|
||||||
|
|
||||||
|
if (!(driver = cpuGetSubDriver(arch)))
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
if (driver->copyMigratable)
|
||||||
|
return driver->copyMigratable(cpu);
|
||||||
|
else
|
||||||
|
return virCPUDefCopy(cpu);
|
||||||
|
}
|
||||||
|
@ -118,6 +118,9 @@ typedef int
|
|||||||
typedef int
|
typedef int
|
||||||
(*virCPUArchExpandFeatures)(virCPUDefPtr cpu);
|
(*virCPUArchExpandFeatures)(virCPUDefPtr cpu);
|
||||||
|
|
||||||
|
typedef virCPUDefPtr
|
||||||
|
(*virCPUArchCopyMigratable)(virCPUDefPtr cpu);
|
||||||
|
|
||||||
struct cpuArchDriver {
|
struct cpuArchDriver {
|
||||||
const char *name;
|
const char *name;
|
||||||
const virArch *arch;
|
const virArch *arch;
|
||||||
@ -138,6 +141,7 @@ struct cpuArchDriver {
|
|||||||
virCPUArchTranslate translate;
|
virCPUArchTranslate translate;
|
||||||
virCPUArchConvertLegacy convertLegacy;
|
virCPUArchConvertLegacy convertLegacy;
|
||||||
virCPUArchExpandFeatures expandFeatures;
|
virCPUArchExpandFeatures expandFeatures;
|
||||||
|
virCPUArchCopyMigratable copyMigratable;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@ -254,6 +258,10 @@ int
|
|||||||
virCPUExpandFeatures(virArch arch,
|
virCPUExpandFeatures(virArch arch,
|
||||||
virCPUDefPtr cpu);
|
virCPUDefPtr cpu);
|
||||||
|
|
||||||
|
virCPUDefPtr
|
||||||
|
virCPUCopyMigratable(virArch arch,
|
||||||
|
virCPUDefPtr cpu);
|
||||||
|
|
||||||
/* virCPUDataFormat and virCPUDataParse are implemented for unit tests only and
|
/* virCPUDataFormat and virCPUDataParse are implemented for unit tests only and
|
||||||
* have no real-life usage
|
* have no real-life usage
|
||||||
*/
|
*/
|
||||||
|
@ -2903,6 +2903,30 @@ virCPUx86ExpandFeatures(virCPUDefPtr cpu)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static virCPUDefPtr
|
||||||
|
virCPUx86CopyMigratable(virCPUDefPtr cpu)
|
||||||
|
{
|
||||||
|
virCPUDefPtr copy;
|
||||||
|
virCPUx86MapPtr map;
|
||||||
|
|
||||||
|
if (!(map = virCPUx86GetMap()))
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
if (!(copy = virCPUDefCopyWithoutModel(cpu)))
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
if (virCPUDefCopyModelFilter(copy, cpu, false,
|
||||||
|
x86FeatureIsMigratable, map) < 0)
|
||||||
|
goto error;
|
||||||
|
|
||||||
|
return copy;
|
||||||
|
|
||||||
|
error:
|
||||||
|
virCPUDefFree(copy);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
int
|
int
|
||||||
virCPUx86DataAddCPUID(virCPUDataPtr cpuData,
|
virCPUx86DataAddCPUID(virCPUDataPtr cpuData,
|
||||||
const virCPUx86CPUID *cpuid)
|
const virCPUx86CPUID *cpuid)
|
||||||
@ -2978,4 +3002,5 @@ struct cpuArchDriver cpuDriverX86 = {
|
|||||||
.getModels = virCPUx86GetModels,
|
.getModels = virCPUx86GetModels,
|
||||||
.translate = virCPUx86Translate,
|
.translate = virCPUx86Translate,
|
||||||
.expandFeatures = virCPUx86ExpandFeatures,
|
.expandFeatures = virCPUx86ExpandFeatures,
|
||||||
|
.copyMigratable = virCPUx86CopyMigratable,
|
||||||
};
|
};
|
||||||
|
@ -1017,6 +1017,7 @@ virCPUCheckFeature;
|
|||||||
virCPUCompare;
|
virCPUCompare;
|
||||||
virCPUCompareXML;
|
virCPUCompareXML;
|
||||||
virCPUConvertLegacy;
|
virCPUConvertLegacy;
|
||||||
|
virCPUCopyMigratable;
|
||||||
virCPUDataCheckFeature;
|
virCPUDataCheckFeature;
|
||||||
virCPUDataFormat;
|
virCPUDataFormat;
|
||||||
virCPUDataFree;
|
virCPUDataFree;
|
||||||
|
Loading…
Reference in New Issue
Block a user