/*
* cpu_conf.h: CPU XML handling
*
- * Copyright (C) 2009 Red Hat, Inc.
+ * Copyright (C) 2009, 2010 Red Hat, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
{
virCPUDefPtr def;
xmlNodePtr *nodes = NULL;
- char *match;
int n;
unsigned int i;
return NULL;
}
- match = virXMLPropString(node, "match");
-
- if (mode == VIR_CPU_TYPE_AUTO)
- def->type = (match == NULL) ? VIR_CPU_TYPE_HOST : VIR_CPU_TYPE_GUEST;
- else
+ if (mode == VIR_CPU_TYPE_AUTO) {
+ if (virXPathBoolean(conn, "boolean(./arch)", ctxt))
+ def->type = VIR_CPU_TYPE_HOST;
+ else
+ def->type = VIR_CPU_TYPE_GUEST;
+ } else
def->type = mode;
if (def->type == VIR_CPU_TYPE_GUEST) {
- if ((def->match = virCPUMatchTypeFromString(match)) < 0) {
- virCPUReportError(conn, VIR_ERR_INTERNAL_ERROR,
- "%s", _("Invalid match attribute for CPU specification"));
- goto error;
+ char *match = virXMLPropString(node, "match");
+
+ if (!match) {
+ if (virXPathBoolean(conn, "boolean(./model)", ctxt)) {
+ virCPUReportError(conn, VIR_ERR_INTERNAL_ERROR,
+ "%s", _("Missing match attribute for CPU specification"));
+ goto error;
+ }
+ def->match = -1;
+ } else {
+ def->match = virCPUMatchTypeFromString(match);
+ VIR_FREE(match);
+
+ if (def->match < 0) {
+ virCPUReportError(conn, VIR_ERR_INTERNAL_ERROR,
+ "%s", _("Invalid match attribute for CPU specification"));
+ goto error;
+ }
}
}
}
}
- if (!(def->model = virXPathString(conn, "string(./model[1])", ctxt))) {
+ if (!(def->model = virXPathString(conn, "string(./model[1])", ctxt)) &&
+ def->type == VIR_CPU_TYPE_HOST) {
virCPUReportError(conn, VIR_ERR_INTERNAL_ERROR,
"%s", _("Missing CPU model name"));
goto error;
goto error;
if (n > 0) {
+ if (!def->model) {
+ virCPUReportError(conn, VIR_ERR_INTERNAL_ERROR,
+ "%s", _("Non-empty feature list specified without CPU model"));
+ goto error;
+ }
+
if (VIR_ALLOC_N(def->features, n) < 0)
goto no_memory;
def->nfeatures = n;
}
cleanup:
- VIR_FREE(match);
VIR_FREE(nodes);
return def;
if (indent == NULL)
indent = "";
- if (!def->model) {
+ if (!def->model && def->nfeatures) {
virCPUReportError(conn, VIR_ERR_INTERNAL_ERROR,
- "%s", _("Missing CPU model"));
+ "%s", _("Non-empty feature list specified without CPU model"));
return -1;
}
if (!(flags & VIR_CPU_FORMAT_EMBEDED)) {
- if (def->type == VIR_CPU_TYPE_GUEST) {
+ if (def->type == VIR_CPU_TYPE_GUEST && def->model) {
const char *match;
if (!(match = virCPUMatchTypeToString(def->match))) {
virCPUReportError(conn, VIR_ERR_INTERNAL_ERROR,
virBufferVSprintf(buf, "%s <arch>%s</arch>\n", indent, def->arch);
}
- virBufferVSprintf(buf, "%s <model>%s</model>\n", indent, def->model);
+ if (def->model)
+ virBufferVSprintf(buf, "%s <model>%s</model>\n", indent, def->model);
if (def->sockets && def->cores && def->threads) {
virBufferVSprintf(buf, "%s <topology", indent);