提交 8fc6e7d8 编写于 作者: J Jiri Denemark

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: NJiri Denemark <jdenemar@redhat.com>
上级 8e240afc
......@@ -85,29 +85,46 @@ int ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2)
virCPUDefCopyModel(virCPUDefPtr dst,
const virCPUDef *src,
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 n;
if (VIR_STRDUP(dst->model, src->model) < 0 ||
VIR_STRDUP(dst->vendor, src->vendor) < 0 ||
VIR_STRDUP(dst->vendor_id, src->vendor_id) < 0 ||
VIR_ALLOC_N(dst->features, src->nfeatures) < 0)
return -1;
dst->nfeatures_max = dst->nfeatures = src->nfeatures;
dst->nfeatures_max = src->nfeatures;
dst->nfeatures = 0;
for (i = 0; i < src->nfeatures; i++) {
if (filter && !filter(src->features[i].name, opaque))
continue;
for (i = 0; i < dst->nfeatures; i++) {
n = dst->nfeatures++;
if (dst->type != src->type && resetPolicy) {
if (dst->type == VIR_CPU_TYPE_HOST)
dst->features[i].policy = -1;
dst->features[n].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
dst->features[i].policy = src->features[i].policy;
dst->features[n].policy = src->features[i].policy;
} 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;
}
......
......@@ -123,6 +123,20 @@ virCPUDefCopyModel(virCPUDefPtr dst,
const virCPUDef *src,
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
virCPUDefStealModel(virCPUDefPtr dst,
virCPUDefPtr src);
......
......@@ -66,6 +66,7 @@ virCapabilitiesSetNetPrefix;
virCPUDefAddFeature;
virCPUDefCopy;
virCPUDefCopyModel;
virCPUDefCopyModelFilter;
virCPUDefCopyWithoutModel;
virCPUDefFormat;
virCPUDefFormatBuf;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册