mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-27 08:05:24 +00:00
conf: Introduce virCPUDefCopyModelFilter
The function filters all CPU features through a given callback while copying CPU model related parts of a CPU definition. Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
This commit is contained in:
parent
8e240afccb
commit
8fc6e7d824
@ -85,29 +85,46 @@ int ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2)
|
|||||||
virCPUDefCopyModel(virCPUDefPtr dst,
|
virCPUDefCopyModel(virCPUDefPtr dst,
|
||||||
const virCPUDef *src,
|
const virCPUDef *src,
|
||||||
bool resetPolicy)
|
bool resetPolicy)
|
||||||
|
{
|
||||||
|
return virCPUDefCopyModelFilter(dst, src, resetPolicy, NULL, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int
|
||||||
|
virCPUDefCopyModelFilter(virCPUDefPtr dst,
|
||||||
|
const virCPUDef *src,
|
||||||
|
bool resetPolicy,
|
||||||
|
virCPUDefFeatureFilter filter,
|
||||||
|
void *opaque)
|
||||||
{
|
{
|
||||||
size_t i;
|
size_t i;
|
||||||
|
size_t n;
|
||||||
|
|
||||||
if (VIR_STRDUP(dst->model, src->model) < 0 ||
|
if (VIR_STRDUP(dst->model, src->model) < 0 ||
|
||||||
VIR_STRDUP(dst->vendor, src->vendor) < 0 ||
|
VIR_STRDUP(dst->vendor, src->vendor) < 0 ||
|
||||||
VIR_STRDUP(dst->vendor_id, src->vendor_id) < 0 ||
|
VIR_STRDUP(dst->vendor_id, src->vendor_id) < 0 ||
|
||||||
VIR_ALLOC_N(dst->features, src->nfeatures) < 0)
|
VIR_ALLOC_N(dst->features, src->nfeatures) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
dst->nfeatures_max = dst->nfeatures = src->nfeatures;
|
dst->nfeatures_max = src->nfeatures;
|
||||||
|
dst->nfeatures = 0;
|
||||||
|
|
||||||
for (i = 0; i < dst->nfeatures; i++) {
|
for (i = 0; i < src->nfeatures; i++) {
|
||||||
|
if (filter && !filter(src->features[i].name, opaque))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
n = dst->nfeatures++;
|
||||||
if (dst->type != src->type && resetPolicy) {
|
if (dst->type != src->type && resetPolicy) {
|
||||||
if (dst->type == VIR_CPU_TYPE_HOST)
|
if (dst->type == VIR_CPU_TYPE_HOST)
|
||||||
dst->features[i].policy = -1;
|
dst->features[n].policy = -1;
|
||||||
else if (src->features[i].policy == -1)
|
else if (src->features[i].policy == -1)
|
||||||
dst->features[i].policy = VIR_CPU_FEATURE_REQUIRE;
|
dst->features[n].policy = VIR_CPU_FEATURE_REQUIRE;
|
||||||
else
|
else
|
||||||
dst->features[i].policy = src->features[i].policy;
|
dst->features[n].policy = src->features[i].policy;
|
||||||
} else {
|
} else {
|
||||||
dst->features[i].policy = src->features[i].policy;
|
dst->features[n].policy = src->features[i].policy;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (VIR_STRDUP(dst->features[i].name, src->features[i].name) < 0)
|
if (VIR_STRDUP(dst->features[n].name, src->features[i].name) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -123,6 +123,20 @@ virCPUDefCopyModel(virCPUDefPtr dst,
|
|||||||
const virCPUDef *src,
|
const virCPUDef *src,
|
||||||
bool resetPolicy);
|
bool resetPolicy);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Returns true if feature @name should copied, false otherwise.
|
||||||
|
*/
|
||||||
|
typedef bool (*virCPUDefFeatureFilter)(const char *name,
|
||||||
|
void *opaque);
|
||||||
|
|
||||||
|
int
|
||||||
|
virCPUDefCopyModelFilter(virCPUDefPtr dst,
|
||||||
|
const virCPUDef *src,
|
||||||
|
bool resetPolicy,
|
||||||
|
virCPUDefFeatureFilter filter,
|
||||||
|
void *opaque)
|
||||||
|
ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);
|
||||||
|
|
||||||
void
|
void
|
||||||
virCPUDefStealModel(virCPUDefPtr dst,
|
virCPUDefStealModel(virCPUDefPtr dst,
|
||||||
virCPUDefPtr src);
|
virCPUDefPtr src);
|
||||||
|
@ -66,6 +66,7 @@ virCapabilitiesSetNetPrefix;
|
|||||||
virCPUDefAddFeature;
|
virCPUDefAddFeature;
|
||||||
virCPUDefCopy;
|
virCPUDefCopy;
|
||||||
virCPUDefCopyModel;
|
virCPUDefCopyModel;
|
||||||
|
virCPUDefCopyModelFilter;
|
||||||
virCPUDefCopyWithoutModel;
|
virCPUDefCopyWithoutModel;
|
||||||
virCPUDefFormat;
|
virCPUDefFormat;
|
||||||
virCPUDefFormatBuf;
|
virCPUDefFormatBuf;
|
||||||
|
Loading…
Reference in New Issue
Block a user