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>
|
|
|
|
|
2020-10-07 08:54:55 +00:00
|
|
|
#include "configmake.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"
|
2020-10-07 08:54:55 +00:00
|
|
|
#include "virfile.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
|
|
|
"exact",
|
2019-11-12 14:26:23 +00:00
|
|
|
"minimum",
|
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
|
|
|
|
|
|
|
|
2019-11-29 11:00:26 +00:00
|
|
|
virCPUDefPtr virCPUDefNew(void)
|
|
|
|
{
|
|
|
|
virCPUDefPtr cpu = g_new0(virCPUDef, 1);
|
|
|
|
cpu->refs = 1;
|
|
|
|
return cpu;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2019-11-29 11:00:26 +00:00
|
|
|
void
|
|
|
|
virCPUDefRef(virCPUDefPtr def)
|
|
|
|
{
|
|
|
|
g_atomic_int_inc(&def->refs);
|
|
|
|
}
|
|
|
|
|
2009-12-18 13:44:55 +00:00
|
|
|
void
|
|
|
|
virCPUDefFree(virCPUDefPtr def)
|
|
|
|
{
|
|
|
|
if (!def)
|
|
|
|
return;
|
|
|
|
|
2019-11-29 11:00:26 +00:00
|
|
|
if (g_atomic_int_dec_and_test(&def->refs)) {
|
|
|
|
virCPUDefFreeModel(def);
|
|
|
|
VIR_FREE(def->cache);
|
|
|
|
VIR_FREE(def->tsc);
|
|
|
|
VIR_FREE(def);
|
|
|
|
}
|
2009-12-18 13:44:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
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
|
|
|
|
2020-10-07 19:15:39 +00:00
|
|
|
dst->features = g_new0(virCPUFeatureDef, src->nfeatures);
|
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
|
|
|
{
|
2020-05-22 19:56:16 +00:00
|
|
|
g_autoptr(virCPUDef) copy = NULL;
|
2010-03-23 08:34:04 +00:00
|
|
|
|
2019-11-29 11:00:26 +00:00
|
|
|
if (!cpu)
|
2010-03-23 08:34:04 +00:00
|
|
|
return NULL;
|
|
|
|
|
2019-11-29 11:00:26 +00:00
|
|
|
copy = virCPUDefNew();
|
2010-03-23 08:34:04 +00:00
|
|
|
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;
|
2019-12-16 11:16:51 +00:00
|
|
|
copy->dies = cpu->dies;
|
2010-03-23 08:34:04 +00:00
|
|
|
copy->cores = cpu->cores;
|
|
|
|
copy->threads = cpu->threads;
|
2012-12-11 12:58:54 +00:00
|
|
|
copy->arch = cpu->arch;
|
2020-06-02 10:29:57 +00:00
|
|
|
copy->migratable = cpu->migratable;
|
2011-12-19 14:41:16 +00:00
|
|
|
|
2017-04-24 13:40:07 +00:00
|
|
|
if (cpu->cache) {
|
2020-10-07 19:15:39 +00:00
|
|
|
copy->cache = g_new0(virCPUCacheDef, 1);
|
2017-04-24 13:40:07 +00:00
|
|
|
*copy->cache = *cpu->cache;
|
|
|
|
}
|
|
|
|
|
2019-05-30 19:47:49 +00:00
|
|
|
if (cpu->tsc) {
|
2020-10-07 19:15:39 +00:00
|
|
|
copy->tsc = g_new0(virHostCPUTscInfo, 1);
|
2019-05-30 19:47:49 +00:00
|
|
|
*copy->tsc = *cpu->tsc;
|
|
|
|
}
|
|
|
|
|
2020-05-22 19:56:16 +00:00
|
|
|
return g_steal_pointer(©);
|
2016-06-17 07:44:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
virCPUDefPtr
|
|
|
|
virCPUDefCopy(const virCPUDef *cpu)
|
|
|
|
{
|
2020-05-22 19:56:16 +00:00
|
|
|
g_autoptr(virCPUDef) copy = NULL;
|
2016-06-17 07:44:43 +00:00
|
|
|
|
|
|
|
if (!(copy = virCPUDefCopyWithoutModel(cpu)))
|
|
|
|
return NULL;
|
|
|
|
|
2011-12-19 14:41:16 +00:00
|
|
|
if (virCPUDefCopyModel(copy, cpu, false) < 0)
|
2020-05-22 19:56:16 +00:00
|
|
|
return NULL;
|
2010-03-23 08:34:04 +00:00
|
|
|
|
2020-05-22 19:56:16 +00:00
|
|
|
return g_steal_pointer(©);
|
2010-03-23 08:34:04 +00:00
|
|
|
}
|
|
|
|
|
2016-06-17 07:44:43 +00:00
|
|
|
|
2019-09-19 20:25:04 +00:00
|
|
|
int
|
|
|
|
virCPUDefParseXMLString(const char *xml,
|
|
|
|
virCPUType type,
|
2020-10-07 08:54:55 +00:00
|
|
|
virCPUDefPtr *cpu,
|
|
|
|
bool validateXML)
|
2019-09-19 20:25:04 +00:00
|
|
|
{
|
|
|
|
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;
|
|
|
|
|
2020-10-07 08:54:55 +00:00
|
|
|
if (virCPUDefParseXML(ctxt, NULL, type, cpu, validateXML) < 0)
|
2019-09-19 20:25:04 +00:00
|
|
|
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,
|
2020-10-07 08:54:55 +00:00
|
|
|
virCPUDefPtr *cpu,
|
|
|
|
bool validateXML)
|
2009-12-18 13:44:55 +00:00
|
|
|
{
|
2020-05-29 12:41:26 +00:00
|
|
|
g_autoptr(virCPUDef) def = NULL;
|
|
|
|
g_autofree xmlNodePtr *nodes = NULL;
|
2020-07-28 19:47:48 +00:00
|
|
|
VIR_XPATH_NODE_AUTORESTORE(ctxt)
|
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;
|
2020-05-29 12:41:26 +00:00
|
|
|
g_autofree char *cpuMode = NULL;
|
|
|
|
g_autofree char *fallback = NULL;
|
|
|
|
g_autofree char *vendor_id = NULL;
|
|
|
|
g_autofree char *tscScaling = NULL;
|
2020-06-02 10:29:57 +00:00
|
|
|
g_autofree char *migratable = NULL;
|
2020-06-16 12:07:09 +00:00
|
|
|
g_autofree virHostCPUTscInfoPtr tsc = NULL;
|
2009-12-18 13:44:55 +00:00
|
|
|
|
2017-05-23 07:29:36 +00:00
|
|
|
*cpu = NULL;
|
|
|
|
|
2020-05-29 12:41:26 +00:00
|
|
|
if (xpath && !(ctxt->node = virXPathNode(xpath, ctxt)))
|
|
|
|
return 0;
|
2017-05-23 07:29:36 +00:00
|
|
|
|
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"));
|
2020-05-29 12:41:26 +00:00
|
|
|
return -1;
|
2010-03-31 23:02:57 +00:00
|
|
|
}
|
|
|
|
|
2020-10-07 08:54:55 +00:00
|
|
|
if (validateXML) {
|
|
|
|
g_autofree char *schemafile = NULL;
|
|
|
|
|
|
|
|
if (!(schemafile = virFileFindResource("cpu.rng",
|
|
|
|
abs_top_srcdir "/docs/schemas",
|
|
|
|
PKGDATADIR "/schemas")))
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
if (virXMLValidateNodeAgainstSchema(schemafile, ctxt->doc,
|
|
|
|
ctxt->node) < 0)
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2019-11-29 11:00:26 +00:00
|
|
|
def = virCPUDefNew();
|
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'"));
|
2020-05-29 12:41:26 +00:00
|
|
|
return -1;
|
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) {
|
2012-07-18 10:50:44 +00:00
|
|
|
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
|
|
|
|
_("Attribute mode is only allowed for guest CPU"));
|
2020-05-29 12:41:26 +00:00
|
|
|
return -1;
|
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);
|
2020-05-29 12:41:26 +00:00
|
|
|
return -1;
|
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
|
|
|
|
2020-06-02 10:29:57 +00:00
|
|
|
if ((migratable = virXMLPropString(ctxt->node, "migratable"))) {
|
|
|
|
int val;
|
|
|
|
|
|
|
|
if (def->mode != VIR_CPU_MODE_HOST_PASSTHROUGH) {
|
|
|
|
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
|
|
|
|
_("Attribute migratable is only allowed for "
|
|
|
|
"host-passthrough CPU"));
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((val = virTristateSwitchTypeFromString(migratable)) < 0) {
|
|
|
|
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
|
|
|
|
_("Invalid value in migratable attribute: '%s'"),
|
|
|
|
migratable);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
def->migratable = val;
|
|
|
|
}
|
|
|
|
|
2009-12-18 13:44:55 +00:00
|
|
|
if (def->type == VIR_CPU_TYPE_GUEST) {
|
2020-05-29 12:41:26 +00:00
|
|
|
g_autofree char *match = virXMLPropString(ctxt->node, "match");
|
|
|
|
g_autofree char *check = NULL;
|
2010-01-12 14:25:36 +00:00
|
|
|
|
2019-11-12 14:26:23 +00:00
|
|
|
if (match) {
|
2010-01-12 14:25:36 +00:00
|
|
|
def->match = virCPUMatchTypeFromString(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"));
|
2020-05-29 12:41:26 +00:00
|
|
|
return -1;
|
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);
|
|
|
|
if (value < 0) {
|
|
|
|
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
|
|
|
|
_("Invalid check attribute for CPU "
|
|
|
|
"specification"));
|
2020-05-29 12:41:26 +00:00
|
|
|
return -1;
|
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) {
|
2020-05-29 12:41:26 +00:00
|
|
|
g_autofree char *arch = virXPathString("string(./arch[1])", ctxt);
|
2012-12-11 12:58:54 +00:00
|
|
|
if (!arch) {
|
2013-07-15 09:12:18 +00:00
|
|
|
virReportError(VIR_ERR_XML_ERROR, "%s",
|
|
|
|
_("Missing CPU architecture"));
|
2020-05-29 12:41:26 +00:00
|
|
|
return -1;
|
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);
|
2020-05-29 12:41:26 +00:00
|
|
|
return -1;
|
2012-12-11 12:58:54 +00:00
|
|
|
}
|
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"));
|
2020-05-29 12:41:26 +00:00
|
|
|
return -1;
|
2017-12-12 15:23:40 +00:00
|
|
|
}
|
2019-05-30 19:47:49 +00:00
|
|
|
|
|
|
|
if (virXPathBoolean("boolean(./counter[@name='tsc'])", ctxt) > 0) {
|
2020-05-29 12:41:26 +00:00
|
|
|
tsc = g_new0(virHostCPUTscInfo, 1);
|
2019-05-30 19:47:49 +00:00
|
|
|
|
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"));
|
2020-05-29 12:41:26 +00:00
|
|
|
return -1;
|
2019-05-30 19:47:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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"));
|
2020-05-29 12:41:26 +00:00
|
|
|
return -1;
|
2019-05-30 19:47:49 +00:00
|
|
|
}
|
|
|
|
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"));
|
2020-05-29 12:41:26 +00:00
|
|
|
return -1;
|
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"));
|
2020-05-29 12:41:26 +00:00
|
|
|
return -1;
|
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);
|
2020-05-29 12:41:26 +00:00
|
|
|
return -1;
|
2012-12-17 08:05:59 +00:00
|
|
|
}
|
2012-12-17 10:49:33 +00:00
|
|
|
|
2020-01-24 20:30:04 +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"));
|
2020-05-29 12:41:26 +00:00
|
|
|
return -1;
|
2011-12-21 13:27:16 +00:00
|
|
|
}
|
2012-12-17 10:49:33 +00:00
|
|
|
|
2020-05-29 12:41:26 +00:00
|
|
|
def->vendor_id = g_steal_pointer(&vendor_id);
|
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"));
|
2020-05-29 12:41:26 +00:00
|
|
|
return -1;
|
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"));
|
2020-05-29 12:41:26 +00:00
|
|
|
return -1;
|
2009-12-18 13:44:55 +00:00
|
|
|
}
|
|
|
|
def->sockets = (unsigned int) ul;
|
|
|
|
|
2019-12-16 11:16:51 +00:00
|
|
|
if (virXPathNode("./topology[1]/@dies", ctxt)) {
|
|
|
|
if (virXPathULong("string(./topology[1]/@dies)", ctxt, &ul) < 0) {
|
|
|
|
virReportError(VIR_ERR_XML_ERROR, "%s",
|
|
|
|
_("Malformed 'dies' attribute in CPU topology"));
|
2020-05-29 12:41:26 +00:00
|
|
|
return -1;
|
2019-12-16 11:16:51 +00:00
|
|
|
}
|
|
|
|
def->dies = (unsigned int) ul;
|
|
|
|
} else {
|
|
|
|
def->dies = 1;
|
|
|
|
}
|
|
|
|
|
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"));
|
2020-05-29 12:41:26 +00:00
|
|
|
return -1;
|
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"));
|
2020-05-29 12:41:26 +00:00
|
|
|
return -1;
|
2009-12-18 13:44:55 +00:00
|
|
|
}
|
|
|
|
def->threads = (unsigned int) ul;
|
|
|
|
|
2019-12-16 11:16:51 +00:00
|
|
|
if (!def->sockets || !def->cores || !def->threads || !def->dies) {
|
2013-07-15 09:12:18 +00:00
|
|
|
virReportError(VIR_ERR_XML_ERROR, "%s",
|
|
|
|
_("Invalid CPU topology"));
|
2020-05-29 12:41:26 +00:00
|
|
|
return -1;
|
2009-12-18 13:44:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-07-15 13:40:40 +00:00
|
|
|
if ((n = virXPathNodeSet("./feature", ctxt, &nodes)) < 0)
|
2020-05-29 12:41:26 +00:00
|
|
|
return -1;
|
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"));
|
2020-05-29 12:41:26 +00:00
|
|
|
return -1;
|
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)
|
2020-05-29 12:41:26 +00:00
|
|
|
return -1;
|
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++) {
|
2020-05-29 12:41:26 +00:00
|
|
|
g_autofree char *name = NULL;
|
2009-12-18 13:44:55 +00:00
|
|
|
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) {
|
2020-05-29 12:41:26 +00:00
|
|
|
g_autofree char *strpolicy = NULL;
|
2009-12-18 13:44:55 +00:00
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
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"));
|
2020-05-29 12:41:26 +00:00
|
|
|
return -1;
|
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) {
|
2013-07-15 09:12:18 +00:00
|
|
|
virReportError(VIR_ERR_XML_ERROR, "%s",
|
|
|
|
_("Invalid CPU feature name"));
|
2020-05-29 12:41:26 +00:00
|
|
|
return -1;
|
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);
|
2020-05-29 12:41:26 +00:00
|
|
|
return -1;
|
2009-12-18 13:44:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-29 12:41:26 +00:00
|
|
|
def->features[i].name = g_steal_pointer(&name);
|
2009-12-18 13:44:55 +00:00
|
|
|
def->features[i].policy = policy;
|
|
|
|
}
|
|
|
|
|
2017-04-24 13:40:07 +00:00
|
|
|
if (virXPathInt("count(./cache)", ctxt, &n) < 0) {
|
2020-05-29 12:41:26 +00:00
|
|
|
return -1;
|
2017-04-24 13:40:07 +00:00
|
|
|
} else if (n > 1) {
|
|
|
|
virReportError(VIR_ERR_XML_ERROR, "%s",
|
|
|
|
_("at most one CPU cache element may be specified"));
|
2020-05-29 12:41:26 +00:00
|
|
|
return -1;
|
2017-04-24 13:40:07 +00:00
|
|
|
} else if (n == 1) {
|
|
|
|
int level = -1;
|
2020-05-29 12:41:26 +00:00
|
|
|
g_autofree char *strmode = NULL;
|
2017-04-24 13:40:07 +00:00
|
|
|
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]"));
|
2020-05-29 12:41:26 +00:00
|
|
|
return -1;
|
2017-04-24 13:40:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!(strmode = virXPathString("string(./cache[1]/@mode)", ctxt)) ||
|
|
|
|
(mode = virCPUCacheModeTypeFromString(strmode)) < 0) {
|
|
|
|
virReportError(VIR_ERR_XML_ERROR, "%s",
|
|
|
|
_("missing or invalid CPU cache mode"));
|
2020-05-29 12:41:26 +00:00
|
|
|
return -1;
|
2017-04-24 13:40:07 +00:00
|
|
|
}
|
|
|
|
|
2020-05-29 12:41:26 +00:00
|
|
|
def->cache = g_new0(virCPUCacheDef, 1);
|
2017-04-24 13:40:07 +00:00
|
|
|
def->cache->level = level;
|
|
|
|
def->cache->mode = mode;
|
|
|
|
}
|
|
|
|
|
2019-10-16 11:43:01 +00:00
|
|
|
*cpu = g_steal_pointer(&def);
|
2020-05-29 12:41:26 +00:00
|
|
|
return 0;
|
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
|
|
|
{
|
2020-07-03 02:19:01 +00:00
|
|
|
g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
|
2009-12-18 13:44:55 +00:00
|
|
|
|
2017-06-30 13:47:23 +00:00
|
|
|
if (virCPUDefFormatBufFull(&buf, def, numa) < 0)
|
2020-07-03 03:19:26 +00:00
|
|
|
return NULL;
|
2009-12-18 13:44:55 +00:00
|
|
|
|
|
|
|
return virBufferContentAndReset(&buf);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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
|
|
|
{
|
2020-07-03 02:19:01 +00:00
|
|
|
g_auto(virBuffer) attributeBuf = VIR_BUFFER_INITIALIZER;
|
|
|
|
g_auto(virBuffer) childrenBuf = VIR_BUFFER_INIT_CHILD(buf);
|
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);
|
2020-07-03 03:19:26 +00:00
|
|
|
return -1;
|
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);
|
2020-07-03 03:19:26 +00:00
|
|
|
return -1;
|
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));
|
|
|
|
}
|
2020-06-02 10:29:57 +00:00
|
|
|
|
|
|
|
if (def->mode == VIR_CPU_MODE_HOST_PASSTHROUGH && def->migratable) {
|
|
|
|
virBufferAsprintf(&attributeBuf, " migratable='%s'",
|
|
|
|
virTristateSwitchTypeToString(def->migratable));
|
|
|
|
}
|
2011-09-21 23:42:07 +00:00
|
|
|
}
|
|
|
|
|
2015-04-10 13:09:59 +00:00
|
|
|
/* Format children */
|
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)
|
2020-07-03 03:19:26 +00:00
|
|
|
return -1;
|
2011-09-21 23:42:07 +00:00
|
|
|
|
2020-05-28 14:52:22 +00:00
|
|
|
if (virDomainNumaDefFormatXML(&childrenBuf, numa) < 0)
|
2020-07-03 03:19:26 +00:00
|
|
|
return -1;
|
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
|
|
|
|
2020-07-03 03:19:26 +00:00
|
|
|
return 0;
|
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;
|
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
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2020-02-19 12:48:39 +00:00
|
|
|
if (formatModel && (def->model || def->vendor_id)) {
|
2011-12-21 13:27:16 +00:00
|
|
|
virBufferAddLit(buf, "<model");
|
2019-11-12 14:54:12 +00:00
|
|
|
|
2020-02-19 12:48:39 +00:00
|
|
|
if (def->type == VIR_CPU_TYPE_GUEST && def->model) {
|
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);
|
|
|
|
}
|
2019-11-12 14:54:12 +00:00
|
|
|
|
2020-02-19 12:48:39 +00:00
|
|
|
if (def->type == VIR_CPU_TYPE_GUEST)
|
|
|
|
virBufferEscapeString(buf, " vendor_id='%s'", def->vendor_id);
|
|
|
|
|
|
|
|
if (def->model)
|
|
|
|
virBufferEscapeString(buf, ">%s</model>\n", def->model);
|
|
|
|
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");
|
|
|
|
}
|
|
|
|
|
2019-12-16 11:16:51 +00:00
|
|
|
if (def->sockets && def->dies && 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);
|
2019-12-16 11:16:51 +00:00
|
|
|
virBufferAsprintf(buf, " dies='%u'", def->dies);
|
2011-04-30 16:34:49 +00:00
|
|
|
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
|
|
|
{
|
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"));
|
2020-01-06 21:57:26 +00:00
|
|
|
return false;
|
2011-05-27 09:47:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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));
|
2020-01-06 21:57:26 +00:00
|
|
|
return false;
|
2011-05-27 09:47:30 +00:00
|
|
|
}
|
|
|
|
|
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));
|
2020-01-06 21:57:26 +00:00
|
|
|
return false;
|
2011-08-18 10:14:36 +00:00
|
|
|
}
|
|
|
|
|
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));
|
2020-01-06 21:57:26 +00:00
|
|
|
return false;
|
2019-04-24 09:51:18 +00:00
|
|
|
}
|
|
|
|
|
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));
|
2020-01-06 21:57:26 +00:00
|
|
|
return false;
|
2011-05-27 09:47:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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));
|
2020-01-06 21:57:26 +00:00
|
|
|
return false;
|
2011-05-27 09:47:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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));
|
2020-01-06 21:57:26 +00:00
|
|
|
return false;
|
2011-05-27 09:47:30 +00:00
|
|
|
}
|
|
|
|
|
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));
|
2020-01-06 21:57:26 +00:00
|
|
|
return false;
|
2012-06-28 10:21:17 +00:00
|
|
|
}
|
|
|
|
|
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);
|
2020-01-06 21:57:26 +00:00
|
|
|
return false;
|
2011-05-27 09:47:30 +00:00
|
|
|
}
|
|
|
|
|
2019-12-16 11:16:51 +00:00
|
|
|
if (src->dies != dst->dies) {
|
|
|
|
MISMATCH(_("Target CPU dies %d does not match source %d"),
|
|
|
|
dst->dies, src->dies);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-05-27 09:47:30 +00:00
|
|
|
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);
|
2020-01-06 21:57:26 +00:00
|
|
|
return false;
|
2011-05-27 09:47:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
2020-01-06 21:57:26 +00:00
|
|
|
return false;
|
2011-05-27 09:47:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
2020-01-06 21:57:26 +00:00
|
|
|
return false;
|
2011-05-27 09:47:30 +00:00
|
|
|
}
|
|
|
|
|
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);
|
2020-01-06 21:57:26 +00:00
|
|
|
return false;
|
2011-05-27 09:47:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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));
|
2020-01-06 21:57:26 +00:00
|
|
|
return false;
|
2011-05-27 09:47:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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"));
|
2020-01-06 21:57:26 +00:00
|
|
|
return false;
|
2017-05-09 14:03:19 +00:00
|
|
|
}
|
|
|
|
|
2017-05-31 14:42:42 +00:00
|
|
|
#undef MISMATCH
|
|
|
|
|
2020-01-06 21:57:26 +00:00
|
|
|
return true;
|
2011-05-27 09:47:30 +00:00
|
|
|
}
|
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;
|
|
|
|
}
|
|
|
|
|
2020-10-07 19:15:39 +00:00
|
|
|
cpus = g_new0(virCPUDefPtr, ncpus + 1);
|
2017-09-13 13:23:43 +00:00
|
|
|
|
|
|
|
for (i = 0; i < ncpus; i++) {
|
|
|
|
if (!(doc = virXMLParseStringCtxt(xmlCPUs[i], _("(CPU_definition)"), &ctxt)))
|
|
|
|
goto error;
|
|
|
|
|
2020-10-07 08:54:55 +00:00
|
|
|
if (virCPUDefParseXML(ctxt, NULL, cpuType, &cpus[i], false) < 0)
|
2017-09-13 13:23:43 +00:00
|
|
|
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);
|
|
|
|
}
|