1
0
mirror of https://gitlab.com/libvirt/libvirt.git synced 2025-03-07 17:28:15 +00:00

virDomainVcpuParse: Use virXMLProp*

Signed-off-by: Tim Wiederhake <twiederh@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
Tim Wiederhake 2021-05-04 16:02:33 +02:00 committed by Michal Privoznik
parent 8e0efc8f72
commit 232c01ec4f

View File

@ -18044,32 +18044,16 @@ virDomainVcpuParse(virDomainDef *def,
} }
VIR_FREE(tmp); VIR_FREE(tmp);
if ((tmp = virXMLPropString(vcpuNode, "current"))) { vcpus = maxvcpus;
if (virStrToLong_ui(tmp, NULL, 10, &vcpus) < 0) {
virReportError(VIR_ERR_XML_ERROR, "%s",
_("current vcpus count must be an integer"));
return -1;
}
VIR_FREE(tmp);
} else {
vcpus = maxvcpus;
}
tmp = virXMLPropString(vcpuNode, "placement"); if (virXMLPropUInt(vcpuNode, "current", 10, VIR_XML_PROP_NONE, &vcpus) < 0)
if (tmp) { return -1;
int placement_mode;
if ((placement_mode = def->placement_mode = VIR_DOMAIN_CPU_PLACEMENT_MODE_STATIC;
virDomainCpuPlacementModeTypeFromString(tmp)) < 0) { if (virXMLPropEnum(vcpuNode, "placement",
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, virDomainCpuPlacementModeTypeFromString,
_("Unsupported CPU placement mode '%s'"), VIR_XML_PROP_NONE, &def->placement_mode) < 0)
tmp); return -1;
return -1;
}
def->placement_mode = placement_mode;
VIR_FREE(tmp);
} else {
def->placement_mode = VIR_DOMAIN_CPU_PLACEMENT_MODE_STATIC;
}
if (def->placement_mode != VIR_DOMAIN_CPU_PLACEMENT_MODE_AUTO) { if (def->placement_mode != VIR_DOMAIN_CPU_PLACEMENT_MODE_AUTO) {
tmp = virXMLPropString(vcpuNode, "cpuset"); tmp = virXMLPropString(vcpuNode, "cpuset");
@ -18100,18 +18084,11 @@ virDomainVcpuParse(virDomainDef *def,
for (i = 0; i < n; i++) { for (i = 0; i < n; i++) {
virDomainVcpuDef *vcpu; virDomainVcpuDef *vcpu;
int state; virTristateBool state;
unsigned int id; unsigned int id;
unsigned int order;
if (!(tmp = virXMLPropString(nodes[i], "id")) || if (virXMLPropUInt(nodes[i], "id", 10, VIR_XML_PROP_REQUIRED, &id) < 0)
virStrToLong_uip(tmp, NULL, 10, &id) < 0) {
virReportError(VIR_ERR_XML_ERROR, "%s",
_("missing or invalid vcpu id"));
return -1; return -1;
}
VIR_FREE(tmp);
if (id >= def->maxvcpus) { if (id >= def->maxvcpus) {
virReportError(VIR_ERR_XML_ERROR, virReportError(VIR_ERR_XML_ERROR,
@ -18122,41 +18099,20 @@ virDomainVcpuParse(virDomainDef *def,
vcpu = virDomainDefGetVcpu(def, id); vcpu = virDomainDefGetVcpu(def, id);
if (!(tmp = virXMLPropString(nodes[i], "enabled"))) { if (virXMLPropTristateBool(nodes[i], "enabled",
virReportError(VIR_ERR_XML_ERROR, "%s", VIR_XML_PROP_REQUIRED, &state) < 0)
_("missing vcpu enabled state"));
return -1; return -1;
}
if ((state = virTristateBoolTypeFromString(tmp)) < 0) {
virReportError(VIR_ERR_XML_ERROR,
_("invalid vcpu 'enabled' value '%s'"), tmp);
return -1;
}
VIR_FREE(tmp);
vcpu->online = state == VIR_TRISTATE_BOOL_YES; vcpu->online = state == VIR_TRISTATE_BOOL_YES;
if ((tmp = virXMLPropString(nodes[i], "hotpluggable"))) { if (virXMLPropTristateBool(nodes[i], "hotpluggable",
int hotpluggable; VIR_XML_PROP_NONE,
if ((hotpluggable = virTristateBoolTypeFromString(tmp)) < 0) { &vcpu->hotpluggable) < 0)
virReportError(VIR_ERR_XML_ERROR, return -1;
_("invalid vcpu 'hotpluggable' value '%s'"), tmp);
return -1;
}
vcpu->hotpluggable = hotpluggable;
VIR_FREE(tmp);
}
if ((tmp = virXMLPropString(nodes[i], "order"))) { if (virXMLPropUInt(nodes[i], "order", 10, VIR_XML_PROP_NONE,
if (virStrToLong_uip(tmp, NULL, 10, &order) < 0) { &vcpu->order) < 0)
virReportError(VIR_ERR_XML_ERROR, "%s", return -1;
_("invalid vcpu order"));
return -1;
}
vcpu->order = order;
VIR_FREE(tmp);
}
} }
} else { } else {
if (virDomainDefSetVcpus(def, vcpus) < 0) if (virDomainDefSetVcpus(def, vcpus) < 0)