2009-12-18 13:44:55 +00:00
|
|
|
/*
|
2013-07-15 09:12:18 +00:00
|
|
|
* cpu_conf.c: CPU XML handling
|
2009-12-18 13:44:55 +00:00
|
|
|
*
|
2015-01-05 16:03:58 +00:00
|
|
|
* Copyright (C) 2009-2015 Red Hat, Inc.
|
2009-12-18 13:44:55 +00:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
2012-09-20 22:30:55 +00:00
|
|
|
* License along with this library. If not, see
|
2012-07-21 10:06:23 +00:00
|
|
|
* <http://www.gnu.org/licenses/>.
|
2009-12-18 13:44:55 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
2012-12-13 18:21:53 +00:00
|
|
|
#include "virerror.h"
|
2012-12-12 18:06:53 +00:00
|
|
|
#include "viralloc.h"
|
2012-12-04 12:04:07 +00:00
|
|
|
#include "virbuffer.h"
|
2009-12-18 13:44:55 +00:00
|
|
|
#include "cpu_conf.h"
|
2011-11-11 12:51:45 +00:00
|
|
|
#include "domain_conf.h"
|
2013-04-03 10:36:23 +00:00
|
|
|
#include "virstring.h"
|
2017-09-13 13:23:43 +00:00
|
|
|
#include "virlog.h"
|
2009-12-18 13:44:55 +00:00
|
|
|
|
|
|
|
#define VIR_FROM_THIS VIR_FROM_CPU
|
|
|
|
|
2017-09-13 13:23:43 +00:00
|
|
|
VIR_LOG_INIT("conf.cpu_conf");
|
|
|
|
|
2019-03-16 18:20:32 +00:00
|
|
|
VIR_ENUM_IMPL(virCPU,
|
|
|
|
VIR_CPU_TYPE_LAST,
|
2019-01-20 16:30:15 +00:00
|
|
|
"host", "guest", "auto",
|
|
|
|
);
|
2011-05-27 09:47:30 +00:00
|
|
|
|
2019-03-16 18:20:32 +00:00
|
|
|
VIR_ENUM_IMPL(virCPUMode,
|
|
|
|
VIR_CPU_MODE_LAST,
|
2011-08-18 10:14:36 +00:00
|
|
|
"custom",
|
|
|
|
"host-model",
|
2019-01-20 16:30:15 +00:00
|
|
|
"host-passthrough",
|
|
|
|
);
|
2011-08-18 10:14:36 +00:00
|
|
|
|
2019-03-16 18:20:32 +00:00
|
|
|
VIR_ENUM_IMPL(virCPUMatch,
|
|
|
|
VIR_CPU_MATCH_LAST,
|
2009-12-18 13:44:55 +00:00
|
|
|
"minimum",
|
|
|
|
"exact",
|
2019-01-20 16:30:15 +00:00
|
|
|
"strict",
|
|
|
|
);
|
2009-12-18 13:44:55 +00:00
|
|
|
|
2019-03-16 18:20:32 +00:00
|
|
|
VIR_ENUM_IMPL(virCPUCheck,
|
|
|
|
VIR_CPU_CHECK_LAST,
|
2017-03-01 14:18:22 +00:00
|
|
|
"default",
|
|
|
|
"none",
|
|
|
|
"partial",
|
2019-01-20 16:30:15 +00:00
|
|
|
"full",
|
|
|
|
);
|
2017-03-01 14:18:22 +00:00
|
|
|
|
2019-03-16 18:20:32 +00:00
|
|
|
VIR_ENUM_IMPL(virCPUFallback,
|
|
|
|
VIR_CPU_FALLBACK_LAST,
|
2011-12-21 13:27:16 +00:00
|
|
|
"allow",
|
2019-01-20 16:30:15 +00:00
|
|
|
"forbid",
|
|
|
|
);
|
2011-12-21 13:27:16 +00:00
|
|
|
|
2019-03-16 18:20:32 +00:00
|
|
|
VIR_ENUM_IMPL(virCPUFeaturePolicy,
|
|
|
|
VIR_CPU_FEATURE_LAST,
|
2009-12-18 13:44:55 +00:00
|
|
|
"force",
|
|
|
|
"require",
|
|
|
|
"optional",
|
|
|
|
"disable",
|
2019-01-20 16:30:15 +00:00
|
|
|
"forbid",
|
|
|
|
);
|
2009-12-18 13:44:55 +00:00
|
|
|
|
2019-03-16 18:20:32 +00:00
|
|
|
VIR_ENUM_IMPL(virCPUCacheMode,
|
|
|
|
VIR_CPU_CACHE_MODE_LAST,
|
2017-04-24 13:40:07 +00:00
|
|
|
"emulate",
|
|
|
|
"passthrough",
|
2019-01-20 16:30:15 +00:00
|
|
|
"disable",
|
|
|
|
);
|
2017-04-24 13:40:07 +00:00
|
|
|
|
|
|
|
|
2017-03-16 11:21:58 +00:00
|
|
|
void
|
|
|
|
virCPUDefFreeFeatures(virCPUDefPtr def)
|
|
|
|
{
|
|
|
|
size_t i;
|
|
|
|
|
|
|
|
for (i = 0; i < def->nfeatures; i++)
|
|
|
|
VIR_FREE(def->features[i].name);
|
|
|
|
VIR_FREE(def->features);
|
|
|
|
|
|
|
|
def->nfeatures = def->nfeatures_max = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-12-19 14:41:16 +00:00
|
|
|
void ATTRIBUTE_NONNULL(1)
|
|
|
|
virCPUDefFreeModel(virCPUDefPtr def)
|
|
|
|
{
|
|
|
|
VIR_FREE(def->model);
|
|
|
|
VIR_FREE(def->vendor);
|
2012-06-28 10:21:17 +00:00
|
|
|
VIR_FREE(def->vendor_id);
|
2017-03-16 11:21:58 +00:00
|
|
|
virCPUDefFreeFeatures(def);
|
2011-12-19 14:41:16 +00:00
|
|
|
}
|
|
|
|
|
2009-12-18 13:44:55 +00:00
|
|
|
void
|
|
|
|
virCPUDefFree(virCPUDefPtr def)
|
|
|
|
{
|
|
|
|
if (!def)
|
|
|
|
return;
|
|
|
|
|
2011-12-19 14:41:16 +00:00
|
|
|
virCPUDefFreeModel(def);
|
2017-04-24 13:40:07 +00:00
|
|
|
VIR_FREE(def->cache);
|
2019-05-30 19:47:49 +00:00
|
|
|
VIR_FREE(def->tsc);
|
2009-12-18 13:44:55 +00:00
|
|
|
VIR_FREE(def);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-12-19 14:41:16 +00:00
|
|
|
int ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2)
|
|
|
|
virCPUDefCopyModel(virCPUDefPtr dst,
|
maint: avoid 'const fooPtr' in cpu files
'const fooPtr' is the same as 'foo * const' (the pointer won't
change, but it's contents can). But in general, if an interface
is trying to be const-correct, it should be using 'const foo *'
(the pointer is to data that can't be changed).
Fix up offenders in src/cpu.
* src/cpu/cpu.h (cpuArchDecode, cpuArchEncode, cpuArchUpdate)
(cpuArchHasFeature, cpuDecode, cpuEncode, cpuUpdate)
(cpuHasFeature): Use intended type.
* src/conf/cpu_conf.h (virCPUDefCopyModel, virCPUDefCopy):
Likewise.
(virCPUDefParseXML): Drop const.
* src/cpu/cpu.c (cpuDecode, cpuEncode, cpuUpdate, cpuHasFeature):
Fix fallout.
* src/cpu/cpu_x86.c (x86ModelFromCPU, x86ModelSubtractCPU)
(x86DecodeCPUData, x86EncodePolicy, x86Encode, x86UpdateCustom)
(x86UpdateHostModel, x86Update, x86HasFeature): Likewise.
* src/cpu/cpu_s390.c (s390Decode): Likewise.
* src/cpu/cpu_arm.c (ArmDecode): Likewise.
* src/cpu/cpu_powerpc.c (ppcModelFromCPU, ppcCompute, ppcDecode)
(ppcUpdate): Likewise.
* src/conf/cpu_conf.c (virCPUDefCopyModel, virCPUDefCopy)
(virCPUDefParseXML): Likewise.
Signed-off-by: Eric Blake <eblake@redhat.com>
2013-10-05 20:01:02 +00:00
|
|
|
const virCPUDef *src,
|
2011-12-19 14:41:16 +00:00
|
|
|
bool resetPolicy)
|
2016-06-28 08:44:20 +00:00
|
|
|
{
|
|
|
|
return virCPUDefCopyModelFilter(dst, src, resetPolicy, NULL, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
virCPUDefCopyModelFilter(virCPUDefPtr dst,
|
|
|
|
const virCPUDef *src,
|
|
|
|
bool resetPolicy,
|
|
|
|
virCPUDefFeatureFilter filter,
|
|
|
|
void *opaque)
|
2011-12-19 14:41:16 +00:00
|
|
|
{
|
Convert 'int i' to 'size_t i' in src/conf/ files
Convert the type of loop iterators named 'i', 'j', k',
'ii', 'jj', 'kk', to be 'size_t' instead of 'int' or
'unsigned int', also santizing 'ii', 'jj', 'kk' to use
the normal 'i', 'j', 'k' naming
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2013-07-08 14:09:33 +00:00
|
|
|
size_t i;
|
2016-06-28 08:44:20 +00:00
|
|
|
size_t n;
|
2011-12-19 14:41:16 +00:00
|
|
|
|
2019-10-20 11:49:46 +00:00
|
|
|
if (VIR_ALLOC_N(dst->features, src->nfeatures) < 0)
|
2013-07-04 10:02:00 +00:00
|
|
|
return -1;
|
2019-10-20 11:49:46 +00:00
|
|
|
|
|
|
|
dst->model = g_strdup(src->model);
|
|
|
|
dst->vendor = g_strdup(src->vendor);
|
|
|
|
dst->vendor_id = g_strdup(src->vendor_id);
|
2017-12-12 15:23:40 +00:00
|
|
|
dst->microcodeVersion = src->microcodeVersion;
|
2016-06-28 08:44:20 +00:00
|
|
|
dst->nfeatures_max = src->nfeatures;
|
|
|
|
dst->nfeatures = 0;
|
|
|
|
|
|
|
|
for (i = 0; i < src->nfeatures; i++) {
|
2019-11-07 15:25:47 +00:00
|
|
|
if (filter && !filter(src->features[i].name, src->features[i].policy, opaque))
|
2016-06-28 08:44:20 +00:00
|
|
|
continue;
|
2011-12-19 14:41:16 +00:00
|
|
|
|
2016-06-28 08:44:20 +00:00
|
|
|
n = dst->nfeatures++;
|
2011-12-19 14:41:16 +00:00
|
|
|
if (dst->type != src->type && resetPolicy) {
|
|
|
|
if (dst->type == VIR_CPU_TYPE_HOST)
|
2016-06-28 08:44:20 +00:00
|
|
|
dst->features[n].policy = -1;
|
2011-12-19 14:41:16 +00:00
|
|
|
else if (src->features[i].policy == -1)
|
2016-06-28 08:44:20 +00:00
|
|
|
dst->features[n].policy = VIR_CPU_FEATURE_REQUIRE;
|
2011-12-19 14:41:16 +00:00
|
|
|
else
|
2016-06-28 08:44:20 +00:00
|
|
|
dst->features[n].policy = src->features[i].policy;
|
2011-12-19 14:41:16 +00:00
|
|
|
} else {
|
2016-06-28 08:44:20 +00:00
|
|
|
dst->features[n].policy = src->features[i].policy;
|
2011-12-19 14:41:16 +00:00
|
|
|
}
|
|
|
|
|
2019-10-20 11:49:46 +00:00
|
|
|
dst->features[n].name = g_strdup(src->features[i].name);
|
2011-12-19 14:41:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-06-17 07:44:43 +00:00
|
|
|
|
2016-11-10 09:26:03 +00:00
|
|
|
/**
|
|
|
|
* virCPUDefStealModel:
|
|
|
|
*
|
|
|
|
* Move CPU model related parts virCPUDef from @src to @dst. If @keepVendor
|
|
|
|
* is true, the function keeps the original vendor/vendor_id in @dst rather
|
|
|
|
* than overwriting it with the values from @src.
|
|
|
|
*/
|
2016-06-23 10:54:19 +00:00
|
|
|
void
|
|
|
|
virCPUDefStealModel(virCPUDefPtr dst,
|
2016-11-10 09:26:03 +00:00
|
|
|
virCPUDefPtr src,
|
|
|
|
bool keepVendor)
|
2016-06-23 10:54:19 +00:00
|
|
|
{
|
2016-11-16 07:55:30 +00:00
|
|
|
char *vendor = NULL;
|
|
|
|
char *vendor_id = NULL;
|
2016-11-10 09:26:03 +00:00
|
|
|
|
|
|
|
if (keepVendor) {
|
2019-10-16 11:43:01 +00:00
|
|
|
vendor = g_steal_pointer(&dst->vendor);
|
|
|
|
vendor_id = g_steal_pointer(&dst->vendor_id);
|
2016-11-10 09:26:03 +00:00
|
|
|
}
|
|
|
|
|
2016-06-23 10:54:19 +00:00
|
|
|
virCPUDefFreeModel(dst);
|
|
|
|
|
2019-10-16 11:43:01 +00:00
|
|
|
dst->model = g_steal_pointer(&src->model);
|
|
|
|
dst->features = g_steal_pointer(&src->features);
|
2017-12-12 15:23:40 +00:00
|
|
|
dst->microcodeVersion = src->microcodeVersion;
|
2016-06-23 10:54:19 +00:00
|
|
|
dst->nfeatures_max = src->nfeatures_max;
|
|
|
|
src->nfeatures_max = 0;
|
|
|
|
dst->nfeatures = src->nfeatures;
|
|
|
|
src->nfeatures = 0;
|
2016-11-10 09:26:03 +00:00
|
|
|
|
|
|
|
if (keepVendor) {
|
|
|
|
dst->vendor = vendor;
|
|
|
|
dst->vendor_id = vendor_id;
|
|
|
|
} else {
|
2019-10-16 11:43:01 +00:00
|
|
|
dst->vendor = g_steal_pointer(&src->vendor);
|
|
|
|
dst->vendor_id = g_steal_pointer(&src->vendor_id);
|
2016-11-10 09:26:03 +00:00
|
|
|
}
|
2016-06-23 10:54:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-03-23 08:34:04 +00:00
|
|
|
virCPUDefPtr
|
2016-06-17 07:44:43 +00:00
|
|
|
virCPUDefCopyWithoutModel(const virCPUDef *cpu)
|
2010-03-23 08:34:04 +00:00
|
|
|
{
|
|
|
|
virCPUDefPtr copy;
|
|
|
|
|
2013-07-04 10:02:00 +00:00
|
|
|
if (!cpu || VIR_ALLOC(copy) < 0)
|
2010-03-23 08:34:04 +00:00
|
|
|
return NULL;
|
|
|
|
|
|
|
|
copy->type = cpu->type;
|
2011-08-18 10:14:36 +00:00
|
|
|
copy->mode = cpu->mode;
|
2010-03-23 08:34:04 +00:00
|
|
|
copy->match = cpu->match;
|
2017-03-01 14:18:22 +00:00
|
|
|
copy->check = cpu->check;
|
2011-12-21 13:27:16 +00:00
|
|
|
copy->fallback = cpu->fallback;
|
2010-03-23 08:34:04 +00:00
|
|
|
copy->sockets = cpu->sockets;
|
|
|
|
copy->cores = cpu->cores;
|
|
|
|
copy->threads = cpu->threads;
|
2012-12-11 12:58:54 +00:00
|
|
|
copy->arch = cpu->arch;
|
2011-12-19 14:41:16 +00:00
|
|
|
|
2017-04-24 13:40:07 +00:00
|
|
|
if (cpu->cache) {
|
|
|
|
if (VIR_ALLOC(copy->cache) < 0)
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
*copy->cache = *cpu->cache;
|
|
|
|
}
|
|
|
|
|
2019-05-30 19:47:49 +00:00
|
|
|
if (cpu->tsc) {
|
|
|
|
if (VIR_ALLOC(copy->tsc) < 0)
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
*copy->tsc = *cpu->tsc;
|
|
|
|
}
|
|
|
|
|
2016-06-17 07:44:43 +00:00
|
|
|
return copy;
|
2017-04-24 13:40:07 +00:00
|
|
|
|
|
|
|
error:
|
|
|
|
virCPUDefFree(copy);
|
|
|
|
return NULL;
|
2016-06-17 07:44:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
virCPUDefPtr
|
|
|
|
virCPUDefCopy(const virCPUDef *cpu)
|
|
|
|
{
|
|
|
|
virCPUDefPtr copy;
|
|
|
|
|
|
|
|
if (!(copy = virCPUDefCopyWithoutModel(cpu)))
|
|
|
|
return NULL;
|
|
|
|
|
2011-12-19 14:41:16 +00:00
|
|
|
if (virCPUDefCopyModel(copy, cpu, false) < 0)
|
|
|
|
goto error;
|
2011-12-19 11:38:11 +00:00
|
|
|
|
2010-03-23 08:34:04 +00:00
|
|
|
return copy;
|
|
|
|
|
2014-03-25 06:48:31 +00:00
|
|
|
error:
|
2010-03-23 08:34:04 +00:00
|
|
|
virCPUDefFree(copy);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2016-06-17 07:44:43 +00:00
|
|
|
|
2019-09-19 20:25:04 +00:00
|
|
|
int
|
|
|
|
virCPUDefParseXMLString(const char *xml,
|
|
|
|
virCPUType type,
|
|
|
|
virCPUDefPtr *cpu)
|
|
|
|
{
|
|
|
|
xmlDocPtr doc = NULL;
|
|
|
|
xmlXPathContextPtr ctxt = NULL;
|
|
|
|
int ret = -1;
|
|
|
|
|
|
|
|
if (!xml) {
|
|
|
|
virReportError(VIR_ERR_INVALID_ARG, "%s", _("missing CPU definition"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!(doc = virXMLParseStringCtxt(xml, _("(CPU_definition)"), &ctxt)))
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (virCPUDefParseXML(ctxt, NULL, type, cpu) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
ret = 0;
|
|
|
|
|
|
|
|
cleanup:
|
|
|
|
xmlFreeDoc(doc);
|
|
|
|
xmlXPathFreeContext(ctxt);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-05-23 07:29:36 +00:00
|
|
|
/*
|
|
|
|
* Parses CPU definition XML from a node pointed to by @xpath. If @xpath is
|
|
|
|
* NULL, the current node of @ctxt is used (i.e., it is a shortcut to ".").
|
|
|
|
*
|
|
|
|
* Missing <cpu> element in the XML document is not considered an error unless
|
|
|
|
* @xpath is NULL in which case the function expects it was provided with a
|
|
|
|
* valid <cpu> element already. In other words, the function returns success
|
|
|
|
* and sets @cpu to NULL if @xpath is not NULL and the node pointed to by
|
|
|
|
* @xpath is not found.
|
|
|
|
*
|
|
|
|
* Returns 0 on success, -1 on error.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
virCPUDefParseXML(xmlXPathContextPtr ctxt,
|
|
|
|
const char *xpath,
|
|
|
|
virCPUType type,
|
|
|
|
virCPUDefPtr *cpu)
|
2009-12-18 13:44:55 +00:00
|
|
|
{
|
2017-05-23 07:29:36 +00:00
|
|
|
virCPUDefPtr def = NULL;
|
2009-12-18 13:44:55 +00:00
|
|
|
xmlNodePtr *nodes = NULL;
|
2014-11-10 11:52:58 +00:00
|
|
|
xmlNodePtr oldnode = ctxt->node;
|
2009-12-18 13:44:55 +00:00
|
|
|
int n;
|
Convert 'int i' to 'size_t i' in src/conf/ files
Convert the type of loop iterators named 'i', 'j', k',
'ii', 'jj', 'kk', to be 'size_t' instead of 'int' or
'unsigned int', also santizing 'ii', 'jj', 'kk' to use
the normal 'i', 'j', 'k' naming
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2013-07-08 14:09:33 +00:00
|
|
|
size_t i;
|
2011-08-18 10:14:36 +00:00
|
|
|
char *cpuMode;
|
2012-12-17 10:49:33 +00:00
|
|
|
char *fallback = NULL;
|
|
|
|
char *vendor_id = NULL;
|
2019-05-30 19:47:49 +00:00
|
|
|
char *tscScaling = NULL;
|
|
|
|
virHostCPUTscInfoPtr tsc = NULL;
|
2017-05-23 07:29:36 +00:00
|
|
|
int ret = -1;
|
2009-12-18 13:44:55 +00:00
|
|
|
|
2017-05-23 07:29:36 +00:00
|
|
|
*cpu = NULL;
|
|
|
|
|
|
|
|
if (xpath && !(ctxt->node = virXPathNode(xpath, ctxt))) {
|
|
|
|
ret = 0;
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2017-08-14 12:31:52 +00:00
|
|
|
if (!virXMLNodeNameEqual(ctxt->node, "cpu")) {
|
2013-07-15 09:12:18 +00:00
|
|
|
virReportError(VIR_ERR_XML_ERROR, "%s",
|
2012-07-18 10:50:44 +00:00
|
|
|
_("XML does not contain expected 'cpu' element"));
|
2017-05-23 07:29:36 +00:00
|
|
|
goto cleanup;
|
2010-03-31 23:02:57 +00:00
|
|
|
}
|
|
|
|
|
2013-07-04 10:02:00 +00:00
|
|
|
if (VIR_ALLOC(def) < 0)
|
2017-05-23 07:29:36 +00:00
|
|
|
goto cleanup;
|
2009-12-18 13:44:55 +00:00
|
|
|
|
2017-04-24 13:38:41 +00:00
|
|
|
if (type == VIR_CPU_TYPE_AUTO) {
|
2010-07-12 14:08:00 +00:00
|
|
|
if (virXPathBoolean("boolean(./arch)", ctxt)) {
|
|
|
|
if (virXPathBoolean("boolean(./@match)", ctxt)) {
|
2012-07-18 10:50:44 +00:00
|
|
|
virReportError(VIR_ERR_XML_ERROR, "%s",
|
2014-09-22 15:41:42 +00:00
|
|
|
_("'arch' element cannot be used inside 'cpu'"
|
2012-07-18 10:50:44 +00:00
|
|
|
" element with 'match' attribute'"));
|
2017-05-23 07:29:36 +00:00
|
|
|
goto cleanup;
|
2010-07-12 14:08:00 +00:00
|
|
|
}
|
2010-01-12 14:25:36 +00:00
|
|
|
def->type = VIR_CPU_TYPE_HOST;
|
2011-08-18 10:14:36 +00:00
|
|
|
} else {
|
2010-01-12 14:25:36 +00:00
|
|
|
def->type = VIR_CPU_TYPE_GUEST;
|
2011-08-18 10:14:36 +00:00
|
|
|
}
|
|
|
|
} else {
|
2017-04-24 13:38:41 +00:00
|
|
|
def->type = type;
|
2011-08-18 10:14:36 +00:00
|
|
|
}
|
|
|
|
|
2017-05-23 07:29:36 +00:00
|
|
|
if ((cpuMode = virXMLPropString(ctxt->node, "mode"))) {
|
2011-08-18 10:14:36 +00:00
|
|
|
if (def->type == VIR_CPU_TYPE_HOST) {
|
|
|
|
VIR_FREE(cpuMode);
|
2012-07-18 10:50:44 +00:00
|
|
|
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
|
|
|
|
_("Attribute mode is only allowed for guest CPU"));
|
2017-05-23 07:29:36 +00:00
|
|
|
goto cleanup;
|
2011-08-18 10:14:36 +00:00
|
|
|
} else {
|
|
|
|
def->mode = virCPUModeTypeFromString(cpuMode);
|
|
|
|
|
|
|
|
if (def->mode < 0) {
|
2014-01-10 16:41:33 +00:00
|
|
|
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
|
2012-07-18 10:50:44 +00:00
|
|
|
_("Invalid mode attribute '%s'"),
|
|
|
|
cpuMode);
|
2012-06-13 17:21:29 +00:00
|
|
|
VIR_FREE(cpuMode);
|
2017-05-23 07:29:36 +00:00
|
|
|
goto cleanup;
|
2011-08-18 10:14:36 +00:00
|
|
|
}
|
2012-06-13 17:21:29 +00:00
|
|
|
VIR_FREE(cpuMode);
|
2011-08-18 10:14:36 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (def->type == VIR_CPU_TYPE_HOST)
|
|
|
|
def->mode = -1;
|
|
|
|
else
|
|
|
|
def->mode = VIR_CPU_MODE_CUSTOM;
|
|
|
|
}
|
2009-12-18 13:44:55 +00:00
|
|
|
|
|
|
|
if (def->type == VIR_CPU_TYPE_GUEST) {
|
2017-05-23 07:29:36 +00:00
|
|
|
char *match = virXMLPropString(ctxt->node, "match");
|
2017-03-01 14:18:22 +00:00
|
|
|
char *check;
|
2010-01-12 14:25:36 +00:00
|
|
|
|
|
|
|
if (!match) {
|
2010-09-22 11:47:48 +00:00
|
|
|
if (virXPathBoolean("boolean(./model)", ctxt))
|
|
|
|
def->match = VIR_CPU_MATCH_EXACT;
|
|
|
|
else
|
|
|
|
def->match = -1;
|
2010-01-12 14:25:36 +00:00
|
|
|
} else {
|
|
|
|
def->match = virCPUMatchTypeFromString(match);
|
|
|
|
VIR_FREE(match);
|
|
|
|
|
|
|
|
if (def->match < 0) {
|
2014-01-10 16:41:33 +00:00
|
|
|
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
|
2012-12-17 11:04:14 +00:00
|
|
|
_("Invalid match attribute for CPU "
|
|
|
|
"specification"));
|
2017-05-23 07:29:36 +00:00
|
|
|
goto cleanup;
|
2010-01-12 14:25:36 +00:00
|
|
|
}
|
2009-12-18 13:44:55 +00:00
|
|
|
}
|
2017-03-01 14:18:22 +00:00
|
|
|
|
2017-05-23 07:29:36 +00:00
|
|
|
if ((check = virXMLPropString(ctxt->node, "check"))) {
|
2017-03-01 14:18:22 +00:00
|
|
|
int value = virCPUCheckTypeFromString(check);
|
|
|
|
VIR_FREE(check);
|
|
|
|
|
|
|
|
if (value < 0) {
|
|
|
|
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
|
|
|
|
_("Invalid check attribute for CPU "
|
|
|
|
"specification"));
|
2017-05-23 07:29:36 +00:00
|
|
|
goto cleanup;
|
2017-03-01 14:18:22 +00:00
|
|
|
}
|
|
|
|
def->check = value;
|
|
|
|
}
|
2009-12-18 13:44:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (def->type == VIR_CPU_TYPE_HOST) {
|
2012-12-11 12:58:54 +00:00
|
|
|
char *arch = virXPathString("string(./arch[1])", ctxt);
|
|
|
|
if (!arch) {
|
2013-07-15 09:12:18 +00:00
|
|
|
virReportError(VIR_ERR_XML_ERROR, "%s",
|
|
|
|
_("Missing CPU architecture"));
|
2017-05-23 07:29:36 +00:00
|
|
|
goto cleanup;
|
2009-12-18 13:44:55 +00:00
|
|
|
}
|
2012-12-11 12:58:54 +00:00
|
|
|
if ((def->arch = virArchFromString(arch)) == VIR_ARCH_NONE) {
|
2014-01-10 16:41:33 +00:00
|
|
|
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
|
2012-12-11 12:58:54 +00:00
|
|
|
_("Unknown architecture %s"), arch);
|
|
|
|
VIR_FREE(arch);
|
2017-05-23 07:29:36 +00:00
|
|
|
goto cleanup;
|
2012-12-11 12:58:54 +00:00
|
|
|
}
|
|
|
|
VIR_FREE(arch);
|
2017-12-12 15:23:40 +00:00
|
|
|
|
|
|
|
if (virXPathBoolean("boolean(./microcode[1]/@version)", ctxt) > 0 &&
|
|
|
|
virXPathUInt("string(./microcode[1]/@version)", ctxt,
|
|
|
|
&def->microcodeVersion) < 0) {
|
|
|
|
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
|
|
|
|
_("invalid microcode version"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
2019-05-30 19:47:49 +00:00
|
|
|
|
|
|
|
if (virXPathBoolean("boolean(./counter[@name='tsc'])", ctxt) > 0) {
|
|
|
|
if (VIR_ALLOC(tsc) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
2019-06-06 07:29:38 +00:00
|
|
|
if (virXPathULongLong("string(./counter[@name='tsc']/@frequency)",
|
|
|
|
ctxt, &tsc->frequency) < 0) {
|
2019-05-30 19:47:49 +00:00
|
|
|
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
|
|
|
|
_("Invalid TSC frequency"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
tscScaling = virXPathString("string(./counter[@name='tsc']/@scaling)",
|
|
|
|
ctxt);
|
|
|
|
if (tscScaling) {
|
|
|
|
int scaling = virTristateBoolTypeFromString(tscScaling);
|
|
|
|
if (scaling < 0) {
|
|
|
|
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
|
|
|
|
_("Invalid TSC scaling attribute"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
tsc->scaling = scaling;
|
|
|
|
}
|
|
|
|
|
2019-10-16 11:43:01 +00:00
|
|
|
def->tsc = g_steal_pointer(&tsc);
|
2019-05-30 19:47:49 +00:00
|
|
|
}
|
2009-12-18 13:44:55 +00:00
|
|
|
}
|
|
|
|
|
2010-02-04 21:52:34 +00:00
|
|
|
if (!(def->model = virXPathString("string(./model[1])", ctxt)) &&
|
2010-01-12 14:25:36 +00:00
|
|
|
def->type == VIR_CPU_TYPE_HOST) {
|
2013-07-15 09:12:18 +00:00
|
|
|
virReportError(VIR_ERR_XML_ERROR, "%s",
|
|
|
|
_("Missing CPU model name"));
|
2017-05-23 07:29:36 +00:00
|
|
|
goto cleanup;
|
2009-12-18 13:44:55 +00:00
|
|
|
}
|
|
|
|
|
2011-08-18 10:14:36 +00:00
|
|
|
if (def->type == VIR_CPU_TYPE_GUEST &&
|
2012-06-28 10:21:17 +00:00
|
|
|
def->mode != VIR_CPU_MODE_HOST_PASSTHROUGH) {
|
|
|
|
|
2012-12-17 10:49:33 +00:00
|
|
|
if ((fallback = virXPathString("string(./model[1]/@fallback)", ctxt))) {
|
|
|
|
if ((def->fallback = virCPUFallbackTypeFromString(fallback)) < 0) {
|
2014-01-10 16:41:33 +00:00
|
|
|
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
|
2012-12-17 10:49:33 +00:00
|
|
|
_("Invalid fallback attribute"));
|
2017-05-23 07:29:36 +00:00
|
|
|
goto cleanup;
|
2012-06-28 10:21:17 +00:00
|
|
|
}
|
2012-12-17 08:05:59 +00:00
|
|
|
}
|
2012-06-28 10:21:17 +00:00
|
|
|
|
2012-12-17 10:49:33 +00:00
|
|
|
if ((vendor_id = virXPathString("string(./model[1]/@vendor_id)",
|
|
|
|
ctxt))) {
|
|
|
|
if (strlen(vendor_id) != VIR_CPU_VENDOR_ID_LENGTH) {
|
2012-12-17 08:05:59 +00:00
|
|
|
virReportError(VIR_ERR_XML_ERROR,
|
2012-12-17 10:49:33 +00:00
|
|
|
_("vendor_id must be exactly %d characters long"),
|
2012-12-17 08:05:59 +00:00
|
|
|
VIR_CPU_VENDOR_ID_LENGTH);
|
2017-05-23 07:29:36 +00:00
|
|
|
goto cleanup;
|
2012-12-17 08:05:59 +00:00
|
|
|
}
|
2012-12-17 10:49:33 +00:00
|
|
|
|
2012-12-17 08:05:59 +00:00
|
|
|
/* ensure that the string can be passed to qemu*/
|
2012-12-17 10:49:33 +00:00
|
|
|
if (strchr(vendor_id, ',')) {
|
2012-12-17 08:05:59 +00:00
|
|
|
virReportError(VIR_ERR_XML_ERROR, "%s",
|
|
|
|
_("vendor id is invalid"));
|
2017-05-23 07:29:36 +00:00
|
|
|
goto cleanup;
|
2011-12-21 13:27:16 +00:00
|
|
|
}
|
2012-12-17 10:49:33 +00:00
|
|
|
|
2012-12-17 08:05:59 +00:00
|
|
|
def->vendor_id = vendor_id;
|
2012-12-17 10:49:33 +00:00
|
|
|
vendor_id = NULL;
|
2011-12-21 13:27:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-07-02 15:51:59 +00:00
|
|
|
def->vendor = virXPathString("string(./vendor[1])", ctxt);
|
|
|
|
if (def->vendor && !def->model) {
|
2013-07-15 09:12:18 +00:00
|
|
|
virReportError(VIR_ERR_XML_ERROR, "%s",
|
|
|
|
_("CPU vendor specified without CPU model"));
|
2017-05-23 07:29:36 +00:00
|
|
|
goto cleanup;
|
2010-07-02 15:51:59 +00:00
|
|
|
}
|
|
|
|
|
2010-02-04 21:52:34 +00:00
|
|
|
if (virXPathNode("./topology[1]", ctxt)) {
|
2009-12-18 13:44:55 +00:00
|
|
|
unsigned long ul;
|
|
|
|
|
2017-05-23 07:29:36 +00:00
|
|
|
if (virXPathULong("string(./topology[1]/@sockets)", ctxt, &ul) < 0) {
|
2013-07-15 09:12:18 +00:00
|
|
|
virReportError(VIR_ERR_XML_ERROR, "%s",
|
2012-12-17 11:04:14 +00:00
|
|
|
_("Missing 'sockets' attribute in CPU topology"));
|
2017-05-23 07:29:36 +00:00
|
|
|
goto cleanup;
|
2009-12-18 13:44:55 +00:00
|
|
|
}
|
|
|
|
def->sockets = (unsigned int) ul;
|
|
|
|
|
2017-05-23 07:29:36 +00:00
|
|
|
if (virXPathULong("string(./topology[1]/@cores)", ctxt, &ul) < 0) {
|
2013-07-15 09:12:18 +00:00
|
|
|
virReportError(VIR_ERR_XML_ERROR, "%s",
|
2012-12-17 11:04:14 +00:00
|
|
|
_("Missing 'cores' attribute in CPU topology"));
|
2017-05-23 07:29:36 +00:00
|
|
|
goto cleanup;
|
2009-12-18 13:44:55 +00:00
|
|
|
}
|
|
|
|
def->cores = (unsigned int) ul;
|
|
|
|
|
2017-05-23 07:29:36 +00:00
|
|
|
if (virXPathULong("string(./topology[1]/@threads)", ctxt, &ul) < 0) {
|
2013-07-15 09:12:18 +00:00
|
|
|
virReportError(VIR_ERR_XML_ERROR, "%s",
|
2012-12-17 11:04:14 +00:00
|
|
|
_("Missing 'threads' attribute in CPU topology"));
|
2017-05-23 07:29:36 +00:00
|
|
|
goto cleanup;
|
2009-12-18 13:44:55 +00:00
|
|
|
}
|
|
|
|
def->threads = (unsigned int) ul;
|
|
|
|
|
|
|
|
if (!def->sockets || !def->cores || !def->threads) {
|
2013-07-15 09:12:18 +00:00
|
|
|
virReportError(VIR_ERR_XML_ERROR, "%s",
|
|
|
|
_("Invalid CPU topology"));
|
2017-05-23 07:29:36 +00:00
|
|
|
goto cleanup;
|
2009-12-18 13:44:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-07-15 13:40:40 +00:00
|
|
|
if ((n = virXPathNodeSet("./feature", ctxt, &nodes)) < 0)
|
2017-05-23 07:29:36 +00:00
|
|
|
goto cleanup;
|
2009-12-18 13:44:55 +00:00
|
|
|
|
|
|
|
if (n > 0) {
|
2015-06-22 08:27:05 +00:00
|
|
|
if (!def->model && def->mode == VIR_CPU_MODE_CUSTOM) {
|
2013-07-15 09:12:18 +00:00
|
|
|
virReportError(VIR_ERR_XML_ERROR, "%s",
|
2012-12-17 11:04:14 +00:00
|
|
|
_("Non-empty feature list specified without "
|
|
|
|
"CPU model"));
|
2017-05-23 07:29:36 +00:00
|
|
|
goto cleanup;
|
2010-01-12 14:25:36 +00:00
|
|
|
}
|
|
|
|
|
2010-08-17 21:41:51 +00:00
|
|
|
if (VIR_RESIZE_N(def->features, def->nfeatures_max,
|
|
|
|
def->nfeatures, n) < 0)
|
2017-05-23 07:29:36 +00:00
|
|
|
goto cleanup;
|
2013-07-15 13:40:40 +00:00
|
|
|
|
2009-12-18 13:44:55 +00:00
|
|
|
def->nfeatures = n;
|
|
|
|
}
|
|
|
|
|
2013-05-21 07:21:17 +00:00
|
|
|
for (i = 0; i < n; i++) {
|
2009-12-18 13:44:55 +00:00
|
|
|
char *name;
|
|
|
|
int policy; /* enum virDomainCPUFeaturePolicy */
|
Convert 'int i' to 'size_t i' in src/conf/ files
Convert the type of loop iterators named 'i', 'j', k',
'ii', 'jj', 'kk', to be 'size_t' instead of 'int' or
'unsigned int', also santizing 'ii', 'jj', 'kk' to use
the normal 'i', 'j', 'k' naming
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2013-07-08 14:09:33 +00:00
|
|
|
size_t j;
|
2009-12-18 13:44:55 +00:00
|
|
|
|
|
|
|
if (def->type == VIR_CPU_TYPE_GUEST) {
|
|
|
|
char *strpolicy;
|
|
|
|
|
|
|
|
strpolicy = virXMLPropString(nodes[i], "policy");
|
2010-09-22 11:47:48 +00:00
|
|
|
if (strpolicy == NULL)
|
|
|
|
policy = VIR_CPU_FEATURE_REQUIRE;
|
|
|
|
else
|
|
|
|
policy = virCPUFeaturePolicyTypeFromString(strpolicy);
|
2009-12-18 13:44:55 +00:00
|
|
|
VIR_FREE(strpolicy);
|
|
|
|
|
|
|
|
if (policy < 0) {
|
2014-01-10 16:41:33 +00:00
|
|
|
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
|
2013-07-15 09:12:18 +00:00
|
|
|
_("Invalid CPU feature policy"));
|
2017-05-23 07:29:36 +00:00
|
|
|
goto cleanup;
|
2009-12-18 13:44:55 +00:00
|
|
|
}
|
2011-08-18 10:14:36 +00:00
|
|
|
} else {
|
2009-12-18 13:44:55 +00:00
|
|
|
policy = -1;
|
2011-08-18 10:14:36 +00:00
|
|
|
}
|
2009-12-18 13:44:55 +00:00
|
|
|
|
|
|
|
if (!(name = virXMLPropString(nodes[i], "name")) || *name == 0) {
|
|
|
|
VIR_FREE(name);
|
2013-07-15 09:12:18 +00:00
|
|
|
virReportError(VIR_ERR_XML_ERROR, "%s",
|
|
|
|
_("Invalid CPU feature name"));
|
2017-05-23 07:29:36 +00:00
|
|
|
goto cleanup;
|
2009-12-18 13:44:55 +00:00
|
|
|
}
|
|
|
|
|
2013-05-21 07:21:17 +00:00
|
|
|
for (j = 0; j < i; j++) {
|
2009-12-18 13:44:55 +00:00
|
|
|
if (STREQ(name, def->features[j].name)) {
|
2013-07-15 09:12:18 +00:00
|
|
|
virReportError(VIR_ERR_XML_ERROR,
|
2014-09-23 01:45:21 +00:00
|
|
|
_("CPU feature '%s' specified more than once"),
|
2012-07-18 10:50:44 +00:00
|
|
|
name);
|
2009-12-18 13:44:55 +00:00
|
|
|
VIR_FREE(name);
|
2017-05-23 07:29:36 +00:00
|
|
|
goto cleanup;
|
2009-12-18 13:44:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
def->features[i].name = name;
|
|
|
|
def->features[i].policy = policy;
|
|
|
|
}
|
|
|
|
|
2017-04-24 13:40:07 +00:00
|
|
|
if (virXPathInt("count(./cache)", ctxt, &n) < 0) {
|
|
|
|
goto cleanup;
|
|
|
|
} else if (n > 1) {
|
|
|
|
virReportError(VIR_ERR_XML_ERROR, "%s",
|
|
|
|
_("at most one CPU cache element may be specified"));
|
|
|
|
goto cleanup;
|
|
|
|
} else if (n == 1) {
|
|
|
|
int level = -1;
|
|
|
|
char *strmode;
|
|
|
|
int mode;
|
|
|
|
|
|
|
|
if (virXPathBoolean("boolean(./cache[1]/@level)", ctxt) == 1 &&
|
|
|
|
(virXPathInt("string(./cache[1]/@level)", ctxt, &level) < 0 ||
|
|
|
|
level < 1 || level > 3)) {
|
|
|
|
virReportError(VIR_ERR_XML_ERROR, "%s",
|
|
|
|
_("invalid CPU cache level, must be in range [1,3]"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!(strmode = virXPathString("string(./cache[1]/@mode)", ctxt)) ||
|
|
|
|
(mode = virCPUCacheModeTypeFromString(strmode)) < 0) {
|
|
|
|
VIR_FREE(strmode);
|
|
|
|
virReportError(VIR_ERR_XML_ERROR, "%s",
|
|
|
|
_("missing or invalid CPU cache mode"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
VIR_FREE(strmode);
|
|
|
|
|
|
|
|
if (VIR_ALLOC(def->cache) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
def->cache->level = level;
|
|
|
|
def->cache->mode = mode;
|
|
|
|
}
|
|
|
|
|
2019-10-16 11:43:01 +00:00
|
|
|
*cpu = g_steal_pointer(&def);
|
2017-05-23 07:29:36 +00:00
|
|
|
ret = 0;
|
|
|
|
|
2014-03-25 06:48:31 +00:00
|
|
|
cleanup:
|
2014-11-10 11:52:58 +00:00
|
|
|
ctxt->node = oldnode;
|
2012-12-17 10:49:33 +00:00
|
|
|
VIR_FREE(fallback);
|
|
|
|
VIR_FREE(vendor_id);
|
2009-12-18 13:44:55 +00:00
|
|
|
VIR_FREE(nodes);
|
2019-05-30 19:47:49 +00:00
|
|
|
VIR_FREE(tscScaling);
|
|
|
|
VIR_FREE(tsc);
|
2009-12-18 13:44:55 +00:00
|
|
|
virCPUDefFree(def);
|
2017-05-23 07:29:36 +00:00
|
|
|
return ret;
|
2009-12-18 13:44:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
char *
|
2011-08-18 10:14:36 +00:00
|
|
|
virCPUDefFormat(virCPUDefPtr def,
|
2017-06-30 13:47:23 +00:00
|
|
|
virDomainNumaPtr numa)
|
2009-12-18 13:44:55 +00:00
|
|
|
{
|
|
|
|
virBuffer buf = VIR_BUFFER_INITIALIZER;
|
|
|
|
|
2017-06-30 13:47:23 +00:00
|
|
|
if (virCPUDefFormatBufFull(&buf, def, numa) < 0)
|
2009-12-18 13:44:55 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
return virBufferContentAndReset(&buf);
|
|
|
|
|
2014-03-25 06:48:31 +00:00
|
|
|
cleanup:
|
2010-01-30 16:27:05 +00:00
|
|
|
virBufferFreeAndReset(&buf);
|
2009-12-18 13:44:55 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-09-21 23:42:07 +00:00
|
|
|
int
|
|
|
|
virCPUDefFormatBufFull(virBufferPtr buf,
|
2011-08-18 10:14:36 +00:00
|
|
|
virCPUDefPtr def,
|
2017-06-30 13:47:23 +00:00
|
|
|
virDomainNumaPtr numa)
|
2011-09-21 23:42:07 +00:00
|
|
|
{
|
2015-02-18 17:06:44 +00:00
|
|
|
int ret = -1;
|
2015-04-10 13:09:59 +00:00
|
|
|
virBuffer attributeBuf = VIR_BUFFER_INITIALIZER;
|
2015-02-18 17:04:16 +00:00
|
|
|
virBuffer childrenBuf = VIR_BUFFER_INITIALIZER;
|
2015-02-18 17:06:44 +00:00
|
|
|
|
2011-09-21 23:42:07 +00:00
|
|
|
if (!def)
|
|
|
|
return 0;
|
|
|
|
|
2017-06-30 14:05:28 +00:00
|
|
|
/* Format attributes for guest CPUs unless they only specify
|
|
|
|
* topology or cache. */
|
|
|
|
if (def->type == VIR_CPU_TYPE_GUEST &&
|
|
|
|
(def->mode != VIR_CPU_MODE_CUSTOM || def->model)) {
|
2011-08-18 10:14:36 +00:00
|
|
|
const char *tmp;
|
|
|
|
|
2017-06-30 14:05:28 +00:00
|
|
|
if (!(tmp = virCPUModeTypeToString(def->mode))) {
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("Unexpected CPU mode %d"), def->mode);
|
|
|
|
goto cleanup;
|
2011-09-21 23:42:07 +00:00
|
|
|
}
|
2017-06-30 14:05:28 +00:00
|
|
|
virBufferAsprintf(&attributeBuf, " mode='%s'", tmp);
|
2011-09-21 23:42:07 +00:00
|
|
|
|
2017-06-30 14:05:28 +00:00
|
|
|
if (def->mode == VIR_CPU_MODE_CUSTOM) {
|
2011-08-18 10:14:36 +00:00
|
|
|
if (!(tmp = virCPUMatchTypeToString(def->match))) {
|
2012-07-18 10:50:44 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("Unexpected CPU match policy %d"),
|
|
|
|
def->match);
|
2015-02-18 17:06:44 +00:00
|
|
|
goto cleanup;
|
2011-08-18 10:14:36 +00:00
|
|
|
}
|
2015-04-10 13:09:59 +00:00
|
|
|
virBufferAsprintf(&attributeBuf, " match='%s'", tmp);
|
2011-08-18 10:14:36 +00:00
|
|
|
}
|
2017-03-01 14:18:22 +00:00
|
|
|
|
|
|
|
if (def->check) {
|
|
|
|
virBufferAsprintf(&attributeBuf, " check='%s'",
|
|
|
|
virCPUCheckTypeToString(def->check));
|
|
|
|
}
|
2011-09-21 23:42:07 +00:00
|
|
|
}
|
|
|
|
|
2015-04-10 13:09:59 +00:00
|
|
|
/* Format children */
|
2017-08-24 12:54:56 +00:00
|
|
|
virBufferSetChildIndent(&childrenBuf, buf);
|
2013-07-24 08:15:38 +00:00
|
|
|
if (def->type == VIR_CPU_TYPE_HOST && def->arch)
|
2015-02-18 17:04:16 +00:00
|
|
|
virBufferAsprintf(&childrenBuf, "<arch>%s</arch>\n",
|
2012-12-11 12:58:54 +00:00
|
|
|
virArchToString(def->arch));
|
2017-06-30 13:47:23 +00:00
|
|
|
if (virCPUDefFormatBuf(&childrenBuf, def) < 0)
|
2015-02-18 17:06:44 +00:00
|
|
|
goto cleanup;
|
2011-09-21 23:42:07 +00:00
|
|
|
|
2017-09-08 14:47:14 +00:00
|
|
|
if (virDomainNumaDefCPUFormatXML(&childrenBuf, numa) < 0)
|
2015-02-18 17:06:44 +00:00
|
|
|
goto cleanup;
|
2015-02-11 13:26:19 +00:00
|
|
|
|
2015-04-10 13:09:59 +00:00
|
|
|
/* Put it all together */
|
|
|
|
if (virBufferUse(&attributeBuf) || virBufferUse(&childrenBuf)) {
|
|
|
|
virBufferAddLit(buf, "<cpu");
|
|
|
|
|
|
|
|
if (virBufferUse(&attributeBuf))
|
|
|
|
virBufferAddBuffer(buf, &attributeBuf);
|
|
|
|
|
|
|
|
if (virBufferUse(&childrenBuf)) {
|
|
|
|
virBufferAddLit(buf, ">\n");
|
|
|
|
virBufferAddBuffer(buf, &childrenBuf);
|
|
|
|
virBufferAddLit(buf, "</cpu>\n");
|
|
|
|
} else {
|
|
|
|
virBufferAddLit(buf, "/>\n");
|
|
|
|
}
|
2015-02-18 17:04:16 +00:00
|
|
|
}
|
2011-09-21 23:42:07 +00:00
|
|
|
|
2015-02-18 17:06:44 +00:00
|
|
|
ret = 0;
|
|
|
|
cleanup:
|
2015-04-10 13:09:59 +00:00
|
|
|
virBufferFreeAndReset(&attributeBuf);
|
2015-02-18 17:04:16 +00:00
|
|
|
virBufferFreeAndReset(&childrenBuf);
|
2015-02-18 17:06:44 +00:00
|
|
|
return ret;
|
2011-09-21 23:42:07 +00:00
|
|
|
}
|
|
|
|
|
2009-12-18 13:44:55 +00:00
|
|
|
int
|
2010-02-10 12:22:36 +00:00
|
|
|
virCPUDefFormatBuf(virBufferPtr buf,
|
2017-06-30 13:47:23 +00:00
|
|
|
virCPUDefPtr def)
|
2009-12-18 13:44:55 +00:00
|
|
|
{
|
Convert 'int i' to 'size_t i' in src/conf/ files
Convert the type of loop iterators named 'i', 'j', k',
'ii', 'jj', 'kk', to be 'size_t' instead of 'int' or
'unsigned int', also santizing 'ii', 'jj', 'kk' to use
the normal 'i', 'j', 'k' naming
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2013-07-08 14:09:33 +00:00
|
|
|
size_t i;
|
2011-08-18 10:14:36 +00:00
|
|
|
bool formatModel;
|
|
|
|
bool formatFallback;
|
2009-12-18 13:44:55 +00:00
|
|
|
|
|
|
|
if (!def)
|
|
|
|
return 0;
|
|
|
|
|
2011-08-18 10:14:36 +00:00
|
|
|
formatModel = (def->mode == VIR_CPU_MODE_CUSTOM ||
|
2017-06-30 13:47:23 +00:00
|
|
|
def->mode == VIR_CPU_MODE_HOST_MODEL);
|
2011-08-18 10:14:36 +00:00
|
|
|
formatFallback = (def->type == VIR_CPU_TYPE_GUEST &&
|
|
|
|
(def->mode == VIR_CPU_MODE_HOST_MODEL ||
|
|
|
|
(def->mode == VIR_CPU_MODE_CUSTOM && def->model)));
|
|
|
|
|
2015-06-22 08:27:05 +00:00
|
|
|
if (!def->model && def->mode == VIR_CPU_MODE_CUSTOM && def->nfeatures) {
|
2013-07-15 09:12:18 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("Non-empty feature list specified without CPU model"));
|
2009-12-18 13:44:55 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2011-08-18 10:14:36 +00:00
|
|
|
if ((formatModel && def->model) || formatFallback) {
|
2011-12-21 13:27:16 +00:00
|
|
|
virBufferAddLit(buf, "<model");
|
2011-08-18 10:14:36 +00:00
|
|
|
if (formatFallback) {
|
2011-12-21 13:27:16 +00:00
|
|
|
const char *fallback;
|
|
|
|
|
|
|
|
fallback = virCPUFallbackTypeToString(def->fallback);
|
|
|
|
if (!fallback) {
|
2012-07-18 10:50:44 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("Unexpected CPU fallback value: %d"),
|
|
|
|
def->fallback);
|
2011-12-21 13:27:16 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
virBufferAsprintf(buf, " fallback='%s'", fallback);
|
2012-06-28 10:21:17 +00:00
|
|
|
if (def->vendor_id)
|
2015-05-05 14:52:46 +00:00
|
|
|
virBufferEscapeString(buf, " vendor_id='%s'", def->vendor_id);
|
2011-12-21 13:27:16 +00:00
|
|
|
}
|
2011-08-18 10:14:36 +00:00
|
|
|
if (formatModel && def->model) {
|
2015-05-05 14:52:46 +00:00
|
|
|
virBufferEscapeString(buf, ">%s</model>\n", def->model);
|
2011-08-18 10:14:36 +00:00
|
|
|
} else {
|
|
|
|
virBufferAddLit(buf, "/>\n");
|
|
|
|
}
|
2011-12-21 13:27:16 +00:00
|
|
|
}
|
2009-12-18 13:44:55 +00:00
|
|
|
|
2011-08-18 10:14:36 +00:00
|
|
|
if (formatModel && def->vendor)
|
2015-05-05 14:52:46 +00:00
|
|
|
virBufferEscapeString(buf, "<vendor>%s</vendor>\n", def->vendor);
|
2010-07-02 15:51:59 +00:00
|
|
|
|
2017-12-12 15:23:40 +00:00
|
|
|
if (def->type == VIR_CPU_TYPE_HOST && def->microcodeVersion)
|
|
|
|
virBufferAsprintf(buf, "<microcode version='%u'/>\n",
|
|
|
|
def->microcodeVersion);
|
|
|
|
|
2019-05-30 19:47:49 +00:00
|
|
|
if (def->type == VIR_CPU_TYPE_HOST && def->tsc) {
|
|
|
|
virBufferAddLit(buf, "<counter name='tsc'");
|
|
|
|
virBufferAsprintf(buf, " frequency='%llu'", def->tsc->frequency);
|
|
|
|
if (def->tsc->scaling) {
|
|
|
|
virBufferAsprintf(buf, " scaling='%s'",
|
|
|
|
virTristateBoolTypeToString(def->tsc->scaling));
|
|
|
|
}
|
|
|
|
virBufferAddLit(buf, "/>\n");
|
|
|
|
}
|
|
|
|
|
2009-12-18 13:44:55 +00:00
|
|
|
if (def->sockets && def->cores && def->threads) {
|
2011-09-21 23:42:07 +00:00
|
|
|
virBufferAddLit(buf, "<topology");
|
2011-04-30 16:34:49 +00:00
|
|
|
virBufferAsprintf(buf, " sockets='%u'", def->sockets);
|
|
|
|
virBufferAsprintf(buf, " cores='%u'", def->cores);
|
|
|
|
virBufferAsprintf(buf, " threads='%u'", def->threads);
|
2009-12-18 13:44:55 +00:00
|
|
|
virBufferAddLit(buf, "/>\n");
|
|
|
|
}
|
|
|
|
|
2017-04-24 13:40:07 +00:00
|
|
|
if (def->cache) {
|
|
|
|
virBufferAddLit(buf, "<cache ");
|
|
|
|
if (def->cache->level != -1)
|
|
|
|
virBufferAsprintf(buf, "level='%d' ", def->cache->level);
|
|
|
|
virBufferAsprintf(buf, "mode='%s'",
|
|
|
|
virCPUCacheModeTypeToString(def->cache->mode));
|
|
|
|
virBufferAddLit(buf, "/>\n");
|
|
|
|
}
|
|
|
|
|
2015-01-15 11:49:13 +00:00
|
|
|
for (i = 0; i < def->nfeatures; i++) {
|
|
|
|
virCPUFeatureDefPtr feature = def->features + i;
|
2009-12-18 13:44:55 +00:00
|
|
|
|
2015-01-15 11:49:13 +00:00
|
|
|
if (!feature->name) {
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("Missing CPU feature name"));
|
|
|
|
return -1;
|
|
|
|
}
|
2011-08-18 10:14:36 +00:00
|
|
|
|
2015-01-15 11:49:13 +00:00
|
|
|
if (def->type == VIR_CPU_TYPE_GUEST) {
|
|
|
|
const char *policy;
|
2013-07-15 15:38:55 +00:00
|
|
|
|
2015-01-15 11:49:13 +00:00
|
|
|
policy = virCPUFeaturePolicyTypeToString(feature->policy);
|
|
|
|
if (!policy) {
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("Unexpected CPU feature policy %d"),
|
|
|
|
feature->policy);
|
|
|
|
return -1;
|
2011-08-18 10:14:36 +00:00
|
|
|
}
|
2015-01-15 11:49:13 +00:00
|
|
|
virBufferAsprintf(buf, "<feature policy='%s' name='%s'/>\n",
|
|
|
|
policy, feature->name);
|
|
|
|
} else {
|
|
|
|
virBufferAsprintf(buf, "<feature name='%s'/>\n",
|
|
|
|
feature->name);
|
2009-12-18 13:44:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-07-15 12:36:09 +00:00
|
|
|
static int
|
|
|
|
virCPUDefUpdateFeatureInternal(virCPUDefPtr def,
|
|
|
|
const char *name,
|
|
|
|
int policy,
|
|
|
|
bool update)
|
2009-12-18 13:44:55 +00:00
|
|
|
{
|
2017-10-09 14:20:43 +00:00
|
|
|
virCPUFeatureDefPtr feat;
|
2009-12-18 13:44:55 +00:00
|
|
|
|
2013-07-15 12:36:09 +00:00
|
|
|
if (def->type == VIR_CPU_TYPE_HOST)
|
|
|
|
policy = -1;
|
|
|
|
|
2017-10-09 14:20:43 +00:00
|
|
|
if ((feat = virCPUDefFindFeature(def, name))) {
|
|
|
|
if (update) {
|
|
|
|
feat->policy = policy;
|
|
|
|
return 0;
|
|
|
|
}
|
2013-07-15 12:36:09 +00:00
|
|
|
|
2017-10-09 14:20:43 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("CPU feature '%s' specified more than once"),
|
|
|
|
name);
|
2013-07-15 12:36:09 +00:00
|
|
|
|
2017-10-09 14:20:43 +00:00
|
|
|
return -1;
|
2009-12-18 13:44:55 +00:00
|
|
|
}
|
|
|
|
|
2010-08-17 21:41:51 +00:00
|
|
|
if (VIR_RESIZE_N(def->features, def->nfeatures_max,
|
|
|
|
def->nfeatures, 1) < 0)
|
2013-07-04 10:02:00 +00:00
|
|
|
return -1;
|
2009-12-18 13:44:55 +00:00
|
|
|
|
2019-10-20 11:49:46 +00:00
|
|
|
def->features[def->nfeatures].name = g_strdup(name);
|
2009-12-18 13:44:55 +00:00
|
|
|
|
|
|
|
def->features[def->nfeatures].policy = policy;
|
|
|
|
def->nfeatures++;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2011-05-27 09:47:30 +00:00
|
|
|
|
2013-07-15 12:36:09 +00:00
|
|
|
int
|
|
|
|
virCPUDefUpdateFeature(virCPUDefPtr def,
|
|
|
|
const char *name,
|
|
|
|
int policy)
|
|
|
|
{
|
|
|
|
return virCPUDefUpdateFeatureInternal(def, name, policy, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
virCPUDefAddFeature(virCPUDefPtr def,
|
|
|
|
const char *name,
|
|
|
|
int policy)
|
|
|
|
{
|
|
|
|
return virCPUDefUpdateFeatureInternal(def, name, policy, false);
|
|
|
|
}
|
|
|
|
|
2017-10-09 14:20:43 +00:00
|
|
|
|
|
|
|
virCPUFeatureDefPtr
|
|
|
|
virCPUDefFindFeature(virCPUDefPtr def,
|
|
|
|
const char *name)
|
|
|
|
{
|
|
|
|
size_t i;
|
|
|
|
|
|
|
|
for (i = 0; i < def->nfeatures; i++) {
|
|
|
|
if (STREQ(name, def->features[i].name))
|
|
|
|
return def->features + i;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-06-07 12:07:10 +00:00
|
|
|
int
|
|
|
|
virCPUDefFilterFeatures(virCPUDefPtr cpu,
|
|
|
|
virCPUDefFeatureFilter filter,
|
|
|
|
void *opaque)
|
|
|
|
{
|
|
|
|
size_t i = 0;
|
|
|
|
|
|
|
|
while (i < cpu->nfeatures) {
|
2019-11-07 15:25:47 +00:00
|
|
|
if (filter(cpu->features[i].name, cpu->features[i].policy, opaque)) {
|
2019-06-07 12:07:10 +00:00
|
|
|
i++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
VIR_FREE(cpu->features[i].name);
|
|
|
|
if (VIR_DELETE_ELEMENT_INPLACE(cpu->features, i, cpu->nfeatures) < 0)
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-06-19 17:01:30 +00:00
|
|
|
/**
|
|
|
|
* virCPUDefCheckFeatures:
|
|
|
|
*
|
|
|
|
* Check CPU features for which @filter reports true and store them in a NULL
|
|
|
|
* terminated list returned via @features.
|
|
|
|
*
|
|
|
|
* Returns the number of features matching @filter or -1 on error.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
virCPUDefCheckFeatures(virCPUDefPtr cpu,
|
|
|
|
virCPUDefFeatureFilter filter,
|
|
|
|
void *opaque,
|
|
|
|
char ***features)
|
|
|
|
{
|
|
|
|
VIR_AUTOSTRINGLIST list = NULL;
|
|
|
|
size_t n = 0;
|
|
|
|
size_t i;
|
|
|
|
|
|
|
|
*features = NULL;
|
|
|
|
|
|
|
|
for (i = 0; i < cpu->nfeatures; i++) {
|
2019-11-07 15:25:47 +00:00
|
|
|
if (filter(cpu->features[i].name, cpu->features[i].policy, opaque)) {
|
2019-06-19 17:01:30 +00:00
|
|
|
if (virStringListAdd(&list, cpu->features[i].name) < 0)
|
|
|
|
return -1;
|
|
|
|
n++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-16 11:43:01 +00:00
|
|
|
*features = g_steal_pointer(&list);
|
2019-06-19 17:01:30 +00:00
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-05-27 09:47:30 +00:00
|
|
|
bool
|
|
|
|
virCPUDefIsEqual(virCPUDefPtr src,
|
2017-05-31 14:42:42 +00:00
|
|
|
virCPUDefPtr dst,
|
|
|
|
bool reportError)
|
2011-05-27 09:47:30 +00:00
|
|
|
{
|
|
|
|
bool identical = false;
|
Convert 'int i' to 'size_t i' in src/conf/ files
Convert the type of loop iterators named 'i', 'j', k',
'ii', 'jj', 'kk', to be 'size_t' instead of 'int' or
'unsigned int', also santizing 'ii', 'jj', 'kk' to use
the normal 'i', 'j', 'k' naming
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2013-07-08 14:09:33 +00:00
|
|
|
size_t i;
|
2011-05-27 09:47:30 +00:00
|
|
|
|
|
|
|
if (!src && !dst)
|
|
|
|
return true;
|
|
|
|
|
2017-11-03 12:09:47 +00:00
|
|
|
#define MISMATCH(fmt, ...) \
|
|
|
|
if (reportError) \
|
2017-05-31 14:42:42 +00:00
|
|
|
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, fmt, __VA_ARGS__)
|
|
|
|
|
2011-05-27 09:47:30 +00:00
|
|
|
if ((src && !dst) || (!src && dst)) {
|
2017-05-31 14:42:42 +00:00
|
|
|
MISMATCH("%s", _("Target CPU does not match source"));
|
2011-05-27 09:47:30 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (src->type != dst->type) {
|
2017-05-31 14:42:42 +00:00
|
|
|
MISMATCH(_("Target CPU type %s does not match source %s"),
|
|
|
|
virCPUTypeToString(dst->type),
|
|
|
|
virCPUTypeToString(src->type));
|
2011-05-27 09:47:30 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2011-08-18 10:14:36 +00:00
|
|
|
if (src->mode != dst->mode) {
|
2017-05-31 14:42:42 +00:00
|
|
|
MISMATCH(_("Target CPU mode %s does not match source %s"),
|
|
|
|
virCPUModeTypeToString(dst->mode),
|
|
|
|
virCPUModeTypeToString(src->mode));
|
2011-08-18 10:14:36 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2019-04-24 09:51:18 +00:00
|
|
|
if (src->check != dst->check) {
|
|
|
|
MISMATCH(_("Target CPU check %s does not match source %s"),
|
|
|
|
virCPUCheckTypeToString(dst->check),
|
|
|
|
virCPUCheckTypeToString(src->check));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2012-12-11 12:58:54 +00:00
|
|
|
if (src->arch != dst->arch) {
|
2017-05-31 14:42:42 +00:00
|
|
|
MISMATCH(_("Target CPU arch %s does not match source %s"),
|
|
|
|
virArchToString(dst->arch),
|
|
|
|
virArchToString(src->arch));
|
2011-05-27 09:47:30 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (STRNEQ_NULLABLE(src->model, dst->model)) {
|
2017-05-31 14:42:42 +00:00
|
|
|
MISMATCH(_("Target CPU model %s does not match source %s"),
|
|
|
|
NULLSTR(dst->model), NULLSTR(src->model));
|
2011-05-27 09:47:30 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (STRNEQ_NULLABLE(src->vendor, dst->vendor)) {
|
2017-05-31 14:42:42 +00:00
|
|
|
MISMATCH(_("Target CPU vendor %s does not match source %s"),
|
|
|
|
NULLSTR(dst->vendor), NULLSTR(src->vendor));
|
2011-05-27 09:47:30 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2012-06-28 10:21:17 +00:00
|
|
|
if (STRNEQ_NULLABLE(src->vendor_id, dst->vendor_id)) {
|
2017-05-31 14:42:42 +00:00
|
|
|
MISMATCH(_("Target CPU vendor id %s does not match source %s"),
|
|
|
|
NULLSTR(dst->vendor_id), NULLSTR(src->vendor_id));
|
2012-06-28 10:21:17 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2011-05-27 09:47:30 +00:00
|
|
|
if (src->sockets != dst->sockets) {
|
2017-05-31 14:42:42 +00:00
|
|
|
MISMATCH(_("Target CPU sockets %d does not match source %d"),
|
|
|
|
dst->sockets, src->sockets);
|
2011-05-27 09:47:30 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (src->cores != dst->cores) {
|
2017-05-31 14:42:42 +00:00
|
|
|
MISMATCH(_("Target CPU cores %d does not match source %d"),
|
|
|
|
dst->cores, src->cores);
|
2011-05-27 09:47:30 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (src->threads != dst->threads) {
|
2017-05-31 14:42:42 +00:00
|
|
|
MISMATCH(_("Target CPU threads %d does not match source %d"),
|
|
|
|
dst->threads, src->threads);
|
2011-05-27 09:47:30 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (src->nfeatures != dst->nfeatures) {
|
2017-05-31 14:42:42 +00:00
|
|
|
MISMATCH(_("Target CPU feature count %zu does not match source %zu"),
|
|
|
|
dst->nfeatures, src->nfeatures);
|
2011-05-27 09:47:30 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2013-05-21 07:21:17 +00:00
|
|
|
for (i = 0; i < src->nfeatures; i++) {
|
2011-05-27 09:47:30 +00:00
|
|
|
if (STRNEQ(src->features[i].name, dst->features[i].name)) {
|
2017-05-31 14:42:42 +00:00
|
|
|
MISMATCH(_("Target CPU feature %s does not match source %s"),
|
|
|
|
dst->features[i].name, src->features[i].name);
|
2011-05-27 09:47:30 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (src->features[i].policy != dst->features[i].policy) {
|
2017-05-31 14:42:42 +00:00
|
|
|
MISMATCH(_("Target CPU feature policy %s does not match source %s"),
|
|
|
|
virCPUFeaturePolicyTypeToString(dst->features[i].policy),
|
|
|
|
virCPUFeaturePolicyTypeToString(src->features[i].policy));
|
2011-05-27 09:47:30 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-09 14:03:19 +00:00
|
|
|
if ((src->cache && !dst->cache) ||
|
|
|
|
(!src->cache && dst->cache) ||
|
|
|
|
(src->cache && dst->cache &&
|
|
|
|
(src->cache->level != dst->cache->level ||
|
|
|
|
src->cache->mode != dst->cache->mode))) {
|
2017-05-31 14:42:42 +00:00
|
|
|
MISMATCH("%s", _("Target CPU cache does not match source"));
|
2017-05-09 14:03:19 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2017-05-31 14:42:42 +00:00
|
|
|
#undef MISMATCH
|
|
|
|
|
2011-05-27 09:47:30 +00:00
|
|
|
identical = true;
|
|
|
|
|
2014-03-25 06:48:31 +00:00
|
|
|
cleanup:
|
2011-05-27 09:47:30 +00:00
|
|
|
return identical;
|
|
|
|
}
|
2017-09-13 13:23:43 +00:00
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Parses a list of CPU XMLs into a NULL-terminated list of CPU defs.
|
|
|
|
*/
|
|
|
|
virCPUDefPtr *
|
|
|
|
virCPUDefListParse(const char **xmlCPUs,
|
|
|
|
unsigned int ncpus,
|
|
|
|
virCPUType cpuType)
|
|
|
|
{
|
|
|
|
xmlDocPtr doc = NULL;
|
|
|
|
xmlXPathContextPtr ctxt = NULL;
|
|
|
|
virCPUDefPtr *cpus = NULL;
|
|
|
|
size_t i;
|
|
|
|
|
|
|
|
VIR_DEBUG("xmlCPUs=%p, ncpus=%u", xmlCPUs, ncpus);
|
|
|
|
|
|
|
|
if (xmlCPUs) {
|
|
|
|
for (i = 0; i < ncpus; i++)
|
|
|
|
VIR_DEBUG("xmlCPUs[%zu]=%s", i, NULLSTR(xmlCPUs[i]));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!xmlCPUs && ncpus != 0) {
|
|
|
|
virReportError(VIR_ERR_INVALID_ARG, "%s",
|
|
|
|
_("nonzero ncpus doesn't match with NULL xmlCPUs"));
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ncpus == 0) {
|
|
|
|
virReportError(VIR_ERR_INVALID_ARG, "%s", _("no CPUs given"));
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (VIR_ALLOC_N(cpus, ncpus + 1))
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
for (i = 0; i < ncpus; i++) {
|
|
|
|
if (!(doc = virXMLParseStringCtxt(xmlCPUs[i], _("(CPU_definition)"), &ctxt)))
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
if (virCPUDefParseXML(ctxt, NULL, cpuType, &cpus[i]) < 0)
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
xmlXPathFreeContext(ctxt);
|
|
|
|
xmlFreeDoc(doc);
|
|
|
|
ctxt = NULL;
|
|
|
|
doc = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return cpus;
|
|
|
|
|
|
|
|
error:
|
|
|
|
virCPUDefListFree(cpus);
|
|
|
|
xmlXPathFreeContext(ctxt);
|
|
|
|
xmlFreeDoc(doc);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Frees NULL-terminated list of CPUs created by virCPUDefListParse.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
virCPUDefListFree(virCPUDefPtr *cpus)
|
|
|
|
{
|
|
|
|
virCPUDefPtr *cpu;
|
|
|
|
|
|
|
|
if (!cpus)
|
|
|
|
return;
|
|
|
|
|
|
|
|
for (cpu = cpus; *cpu != NULL; cpu++)
|
|
|
|
virCPUDefFree(*cpu);
|
|
|
|
|
|
|
|
VIR_FREE(cpus);
|
|
|
|
}
|