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
|
|
|
*
|
|
|
|
* Authors:
|
|
|
|
* Jiri Denemark <jdenemar@redhat.com>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#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"
|
2009-12-18 13:44:55 +00:00
|
|
|
|
|
|
|
#define VIR_FROM_THIS VIR_FROM_CPU
|
|
|
|
|
2011-05-27 09:47:30 +00:00
|
|
|
VIR_ENUM_IMPL(virCPU, VIR_CPU_TYPE_LAST,
|
|
|
|
"host", "guest", "auto")
|
|
|
|
|
2011-08-18 10:14:36 +00:00
|
|
|
VIR_ENUM_IMPL(virCPUMode, VIR_CPU_MODE_LAST,
|
|
|
|
"custom",
|
|
|
|
"host-model",
|
|
|
|
"host-passthrough")
|
|
|
|
|
2009-12-18 13:44:55 +00:00
|
|
|
VIR_ENUM_IMPL(virCPUMatch, VIR_CPU_MATCH_LAST,
|
|
|
|
"minimum",
|
|
|
|
"exact",
|
|
|
|
"strict")
|
|
|
|
|
2011-12-21 13:27:16 +00:00
|
|
|
VIR_ENUM_IMPL(virCPUFallback, VIR_CPU_FALLBACK_LAST,
|
|
|
|
"allow",
|
|
|
|
"forbid")
|
|
|
|
|
2009-12-18 13:44:55 +00:00
|
|
|
VIR_ENUM_IMPL(virCPUFeaturePolicy, VIR_CPU_FEATURE_LAST,
|
|
|
|
"force",
|
|
|
|
"require",
|
|
|
|
"optional",
|
|
|
|
"disable",
|
|
|
|
"forbid")
|
|
|
|
|
2011-12-19 14:41:16 +00:00
|
|
|
void ATTRIBUTE_NONNULL(1)
|
|
|
|
virCPUDefFreeModel(virCPUDefPtr def)
|
|
|
|
{
|
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-12-19 14:41:16 +00:00
|
|
|
|
|
|
|
VIR_FREE(def->model);
|
|
|
|
VIR_FREE(def->vendor);
|
2012-06-28 10:21:17 +00:00
|
|
|
VIR_FREE(def->vendor_id);
|
2011-12-19 14:41:16 +00:00
|
|
|
|
|
|
|
for (i = 0; i < def->nfeatures; i++)
|
|
|
|
VIR_FREE(def->features[i].name);
|
|
|
|
VIR_FREE(def->features);
|
|
|
|
}
|
|
|
|
|
2009-12-18 13:44:55 +00:00
|
|
|
void
|
|
|
|
virCPUDefFree(virCPUDefPtr def)
|
|
|
|
{
|
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;
|
2009-12-18 13:44:55 +00:00
|
|
|
|
|
|
|
if (!def)
|
|
|
|
return;
|
|
|
|
|
2011-12-19 14:41:16 +00:00
|
|
|
virCPUDefFreeModel(def);
|
2009-12-18 13:44:55 +00:00
|
|
|
|
2015-02-11 13:06:20 +00:00
|
|
|
for (i = 0; i < def->ncells; i++)
|
2012-09-14 07:47:02 +00:00
|
|
|
virBitmapFree(def->cells[i].cpumask);
|
2011-11-11 12:51:45 +00:00
|
|
|
VIR_FREE(def->cells);
|
2012-12-17 10:48:37 +00:00
|
|
|
VIR_FREE(def->vendor_id);
|
2011-11-11 12:51:45 +00:00
|
|
|
|
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)
|
|
|
|
{
|
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-12-19 14:41:16 +00:00
|
|
|
|
2013-05-03 12:40:46 +00:00
|
|
|
if (VIR_STRDUP(dst->model, src->model) < 0 ||
|
|
|
|
VIR_STRDUP(dst->vendor, src->vendor) < 0 ||
|
|
|
|
VIR_STRDUP(dst->vendor_id, src->vendor_id) < 0 ||
|
|
|
|
VIR_ALLOC_N(dst->features, src->nfeatures) < 0)
|
2013-07-04 10:02:00 +00:00
|
|
|
return -1;
|
2011-12-19 14:41:16 +00:00
|
|
|
dst->nfeatures_max = dst->nfeatures = src->nfeatures;
|
|
|
|
|
|
|
|
for (i = 0; i < dst->nfeatures; i++) {
|
|
|
|
if (dst->type != src->type && resetPolicy) {
|
|
|
|
if (dst->type == VIR_CPU_TYPE_HOST)
|
|
|
|
dst->features[i].policy = -1;
|
|
|
|
else if (src->features[i].policy == -1)
|
|
|
|
dst->features[i].policy = VIR_CPU_FEATURE_REQUIRE;
|
|
|
|
else
|
|
|
|
dst->features[i].policy = src->features[i].policy;
|
|
|
|
} else {
|
|
|
|
dst->features[i].policy = src->features[i].policy;
|
|
|
|
}
|
|
|
|
|
2013-05-03 12:40:46 +00:00
|
|
|
if (VIR_STRDUP(dst->features[i].name, src->features[i].name) < 0)
|
|
|
|
return -1;
|
2011-12-19 14:41:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-03-23 08:34:04 +00:00
|
|
|
virCPUDefPtr
|
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
|
|
|
virCPUDefCopy(const virCPUDef *cpu)
|
2010-03-23 08:34:04 +00:00
|
|
|
{
|
|
|
|
virCPUDefPtr copy;
|
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;
|
2010-03-23 08:34:04 +00:00
|
|
|
|
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;
|
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
|
|
|
|
|
|
|
if (virCPUDefCopyModel(copy, cpu, false) < 0)
|
|
|
|
goto error;
|
2011-12-19 11:38:11 +00:00
|
|
|
|
|
|
|
if (cpu->ncells) {
|
|
|
|
if (VIR_ALLOC_N(copy->cells, cpu->ncells) < 0)
|
2013-07-04 10:02:00 +00:00
|
|
|
goto error;
|
2011-12-19 11:38:11 +00:00
|
|
|
|
|
|
|
for (i = 0; i < cpu->ncells; i++) {
|
|
|
|
copy->cells[i].mem = cpu->cells[i].mem;
|
|
|
|
|
2012-09-14 07:47:02 +00:00
|
|
|
copy->cells[i].cpumask = virBitmapNewCopy(cpu->cells[i].cpumask);
|
|
|
|
|
|
|
|
if (!copy->cells[i].cpumask)
|
2013-07-04 10:02:00 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2009-12-18 13:44:55 +00:00
|
|
|
virCPUDefPtr
|
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
|
|
|
virCPUDefParseXML(xmlNodePtr node,
|
2009-12-18 13:44:55 +00:00
|
|
|
xmlXPathContextPtr ctxt,
|
2014-04-28 00:15:21 +00:00
|
|
|
virCPUType mode)
|
2009-12-18 13:44:55 +00:00
|
|
|
{
|
|
|
|
virCPUDefPtr def;
|
|
|
|
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;
|
2009-12-18 13:44:55 +00:00
|
|
|
|
2010-03-31 23:02:57 +00:00
|
|
|
if (!xmlStrEqual(node->name, BAD_CAST "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"));
|
2010-03-31 23:02:57 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2013-07-04 10:02:00 +00:00
|
|
|
if (VIR_ALLOC(def) < 0)
|
2009-12-18 13:44:55 +00:00
|
|
|
return NULL;
|
|
|
|
|
2010-01-12 14:25:36 +00:00
|
|
|
if (mode == 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'"));
|
2010-07-12 14:08:00 +00:00
|
|
|
goto error;
|
|
|
|
}
|
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 {
|
2009-12-18 13:44:55 +00:00
|
|
|
def->type = mode;
|
2011-08-18 10:14:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if ((cpuMode = virXMLPropString(node, "mode"))) {
|
|
|
|
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"));
|
2011-08-18 10:14:36 +00:00
|
|
|
goto error;
|
|
|
|
} 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);
|
2011-08-18 10:14:36 +00:00
|
|
|
goto error;
|
|
|
|
}
|
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) {
|
2010-01-12 14:25:36 +00:00
|
|
|
char *match = virXMLPropString(node, "match");
|
|
|
|
|
|
|
|
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"));
|
2010-01-12 14:25:36 +00:00
|
|
|
goto error;
|
|
|
|
}
|
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"));
|
2009-12-18 13:44:55 +00:00
|
|
|
goto error;
|
|
|
|
}
|
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);
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
VIR_FREE(arch);
|
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"));
|
2009-12-18 13:44:55 +00:00
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
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"));
|
|
|
|
goto error;
|
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);
|
|
|
|
goto error;
|
|
|
|
}
|
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"));
|
2012-06-28 10:21:17 +00:00
|
|
|
goto error;
|
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"));
|
2010-07-02 15:51:59 +00:00
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
2010-02-04 21:52:34 +00:00
|
|
|
if (virXPathNode("./topology[1]", ctxt)) {
|
2009-12-18 13:44:55 +00:00
|
|
|
int ret;
|
|
|
|
unsigned long ul;
|
|
|
|
|
2010-02-04 21:52:34 +00:00
|
|
|
ret = virXPathULong("string(./topology[1]/@sockets)",
|
2009-12-18 13:44:55 +00:00
|
|
|
ctxt, &ul);
|
|
|
|
if (ret < 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"));
|
2009-12-18 13:44:55 +00:00
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
def->sockets = (unsigned int) ul;
|
|
|
|
|
2010-02-04 21:52:34 +00:00
|
|
|
ret = virXPathULong("string(./topology[1]/@cores)",
|
2009-12-18 13:44:55 +00:00
|
|
|
ctxt, &ul);
|
|
|
|
if (ret < 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"));
|
2009-12-18 13:44:55 +00:00
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
def->cores = (unsigned int) ul;
|
|
|
|
|
2010-02-04 21:52:34 +00:00
|
|
|
ret = virXPathULong("string(./topology[1]/@threads)",
|
2009-12-18 13:44:55 +00:00
|
|
|
ctxt, &ul);
|
|
|
|
if (ret < 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"));
|
2009-12-18 13:44:55 +00:00
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
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"));
|
2009-12-18 13:44:55 +00:00
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-07-15 13:40:40 +00:00
|
|
|
if ((n = virXPathNodeSet("./feature", ctxt, &nodes)) < 0)
|
2009-12-18 13:44:55 +00:00
|
|
|
goto error;
|
|
|
|
|
|
|
|
if (n > 0) {
|
2015-01-05 16:03:58 +00:00
|
|
|
if (!def->model && def->mode != VIR_CPU_MODE_HOST_MODEL &&
|
|
|
|
def->mode != VIR_CPU_MODE_HOST_PASSTHROUGH) {
|
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"));
|
2010-01-12 14:25:36 +00:00
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
2010-08-17 21:41:51 +00:00
|
|
|
if (VIR_RESIZE_N(def->features, def->nfeatures_max,
|
|
|
|
def->nfeatures, n) < 0)
|
2013-07-04 10:02:00 +00:00
|
|
|
goto error;
|
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"));
|
2009-12-18 13:44:55 +00:00
|
|
|
goto error;
|
|
|
|
}
|
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"));
|
2009-12-18 13:44:55 +00:00
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
def->features[i].name = name;
|
|
|
|
def->features[i].policy = policy;
|
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
return def;
|
|
|
|
|
2014-03-25 06:48:31 +00:00
|
|
|
error:
|
2009-12-18 13:44:55 +00:00
|
|
|
virCPUDefFree(def);
|
|
|
|
def = NULL;
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
char *
|
2011-08-18 10:14:36 +00:00
|
|
|
virCPUDefFormat(virCPUDefPtr def,
|
2015-01-06 11:54:32 +00:00
|
|
|
bool updateCPU)
|
2009-12-18 13:44:55 +00:00
|
|
|
{
|
|
|
|
virBuffer buf = VIR_BUFFER_INITIALIZER;
|
|
|
|
|
2015-01-06 11:54:32 +00:00
|
|
|
if (virCPUDefFormatBufFull(&buf, def, updateCPU) < 0)
|
2009-12-18 13:44:55 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
2014-06-27 08:40:15 +00:00
|
|
|
if (virBufferCheckError(&buf) < 0)
|
|
|
|
goto cleanup;
|
2009-12-18 13:44:55 +00:00
|
|
|
|
|
|
|
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,
|
2015-01-06 11:54:32 +00:00
|
|
|
bool updateCPU)
|
2011-09-21 23:42:07 +00:00
|
|
|
{
|
|
|
|
if (!def)
|
|
|
|
return 0;
|
|
|
|
|
2011-08-18 10:14:36 +00:00
|
|
|
virBufferAddLit(buf, "<cpu");
|
|
|
|
if (def->type == VIR_CPU_TYPE_GUEST) {
|
|
|
|
const char *tmp;
|
|
|
|
|
|
|
|
if (def->mode != VIR_CPU_MODE_CUSTOM || def->model) {
|
|
|
|
if (!(tmp = virCPUModeTypeToString(def->mode))) {
|
2012-07-18 10:50:44 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("Unexpected CPU mode %d"), def->mode);
|
2011-08-18 10:14:36 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
virBufferAsprintf(buf, " mode='%s'", tmp);
|
2011-09-21 23:42:07 +00:00
|
|
|
}
|
|
|
|
|
2011-08-18 10:14:36 +00:00
|
|
|
if (def->model &&
|
|
|
|
(def->mode == VIR_CPU_MODE_CUSTOM ||
|
2015-01-06 11:54:32 +00:00
|
|
|
updateCPU)) {
|
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);
|
2011-08-18 10:14:36 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
virBufferAsprintf(buf, " match='%s'", tmp);
|
|
|
|
}
|
2011-09-21 23:42:07 +00:00
|
|
|
}
|
2011-08-18 10:14:36 +00:00
|
|
|
virBufferAddLit(buf, ">\n");
|
2014-03-06 14:58:56 +00:00
|
|
|
virBufferAdjustIndent(buf, 2);
|
2011-09-21 23:42:07 +00:00
|
|
|
|
|
|
|
if (def->arch)
|
2014-03-06 14:58:56 +00:00
|
|
|
virBufferAsprintf(buf, "<arch>%s</arch>\n",
|
2012-12-11 12:58:54 +00:00
|
|
|
virArchToString(def->arch));
|
2015-01-06 11:54:32 +00:00
|
|
|
if (virCPUDefFormatBuf(buf, def, updateCPU) < 0)
|
2011-09-21 23:42:07 +00:00
|
|
|
return -1;
|
|
|
|
|
2015-02-11 13:26:19 +00:00
|
|
|
if (virDomainNumaDefCPUFormat(buf, def) < 0)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
virBufferAdjustIndent(buf, -2);
|
2011-09-21 23:42:07 +00:00
|
|
|
virBufferAddLit(buf, "</cpu>\n");
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-12-18 13:44:55 +00:00
|
|
|
int
|
2010-02-10 12:22:36 +00:00
|
|
|
virCPUDefFormatBuf(virBufferPtr buf,
|
2011-08-18 10:14:36 +00:00
|
|
|
virCPUDefPtr def,
|
2015-01-06 11:54:32 +00:00
|
|
|
bool updateCPU)
|
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 ||
|
2014-11-04 17:22:44 +00:00
|
|
|
def->mode == VIR_CPU_MODE_HOST_MODEL ||
|
2015-01-06 11:54:32 +00:00
|
|
|
updateCPU);
|
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)));
|
|
|
|
|
2013-07-15 15:38:55 +00:00
|
|
|
if (!def->model &&
|
|
|
|
def->mode != VIR_CPU_MODE_HOST_MODEL &&
|
2015-01-05 16:03:58 +00:00
|
|
|
def->mode != VIR_CPU_MODE_HOST_PASSTHROUGH &&
|
2013-07-15 15:38:55 +00:00
|
|
|
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)
|
|
|
|
virBufferAsprintf(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) {
|
|
|
|
virBufferAsprintf(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)
|
2011-09-21 23:42:07 +00:00
|
|
|
virBufferAsprintf(buf, "<vendor>%s</vendor>\n", def->vendor);
|
2010-07-02 15:51:59 +00:00
|
|
|
|
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");
|
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
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;
|
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;
|
|
|
|
|
2013-05-21 07:21:17 +00:00
|
|
|
for (i = 0; i < def->nfeatures; i++) {
|
2009-12-18 13:44:55 +00:00
|
|
|
if (STREQ(name, def->features[i].name)) {
|
2013-07-15 12:36:09 +00:00
|
|
|
if (update) {
|
|
|
|
def->features[i].policy = policy;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-07-18 10:50:44 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
2014-09-23 01:45:21 +00:00
|
|
|
_("CPU feature '%s' specified more than once"),
|
2013-07-15 09:12:18 +00:00
|
|
|
name);
|
2013-07-15 12:36:09 +00:00
|
|
|
|
2009-12-18 13:44:55 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2013-05-03 12:40:46 +00:00
|
|
|
if (VIR_STRDUP(def->features[def->nfeatures].name, name) < 0)
|
|
|
|
return -1;
|
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);
|
|
|
|
}
|
|
|
|
|
2011-05-27 09:47:30 +00:00
|
|
|
bool
|
|
|
|
virCPUDefIsEqual(virCPUDefPtr src,
|
|
|
|
virCPUDefPtr dst)
|
|
|
|
{
|
|
|
|
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;
|
|
|
|
|
|
|
|
if ((src && !dst) || (!src && dst)) {
|
2012-07-18 10:50:44 +00:00
|
|
|
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
|
|
|
|
_("Target CPU does not match source"));
|
2011-05-27 09:47:30 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (src->type != dst->type) {
|
2012-07-18 10:50:44 +00:00
|
|
|
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
|
|
|
|
_("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) {
|
2012-07-18 10:50:44 +00:00
|
|
|
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
|
|
|
|
_("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;
|
|
|
|
}
|
|
|
|
|
2012-12-11 12:58:54 +00:00
|
|
|
if (src->arch != dst->arch) {
|
2012-07-18 10:50:44 +00:00
|
|
|
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
|
|
|
|
_("Target CPU arch %s does not match source %s"),
|
2012-12-11 12:58:54 +00:00
|
|
|
virArchToString(dst->arch),
|
|
|
|
virArchToString(src->arch));
|
2011-05-27 09:47:30 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (STRNEQ_NULLABLE(src->model, dst->model)) {
|
2012-07-18 10:50:44 +00:00
|
|
|
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
|
|
|
|
_("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)) {
|
2012-07-18 10:50:44 +00:00
|
|
|
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
|
|
|
|
_("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)) {
|
2012-07-18 10:50:44 +00:00
|
|
|
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
|
2013-11-07 03:31:32 +00:00
|
|
|
_("Target CPU vendor id %s does not match source %s"),
|
2012-07-18 10:50:44 +00:00
|
|
|
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) {
|
2012-07-18 10:50:44 +00:00
|
|
|
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
|
|
|
|
_("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) {
|
2012-07-18 10:50:44 +00:00
|
|
|
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
|
|
|
|
_("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) {
|
2012-07-18 10:50:44 +00:00
|
|
|
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
|
|
|
|
_("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) {
|
2012-07-18 10:50:44 +00:00
|
|
|
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
|
|
|
|
_("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)) {
|
2012-07-18 10:50:44 +00:00
|
|
|
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
|
|
|
|
_("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) {
|
2012-07-18 10:50:44 +00:00
|
|
|
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
|
|
|
|
_("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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
identical = true;
|
|
|
|
|
2014-03-25 06:48:31 +00:00
|
|
|
cleanup:
|
2011-05-27 09:47:30 +00:00
|
|
|
return identical;
|
|
|
|
}
|