提交 b71946af 编写于 作者: P Pavel Hrdina

conf: use virXMLPropString and virXMLNodeContentString for vcpu parsing

XPath is good for random search of elements, not for accessing
attributes of one node.
Signed-off-by: NPavel Hrdina <phrdina@redhat.com>
上级 49991b74
...@@ -16914,37 +16914,37 @@ virDomainVcpuParse(virDomainDefPtr def, ...@@ -16914,37 +16914,37 @@ virDomainVcpuParse(virDomainDefPtr def,
{ {
int n; int n;
xmlNodePtr *nodes = NULL; xmlNodePtr *nodes = NULL;
xmlNodePtr vcpuNode;
size_t i; size_t i;
char *tmp = NULL; char *tmp = NULL;
unsigned int maxvcpus; unsigned int maxvcpus;
unsigned int vcpus; unsigned int vcpus;
int ret = -1; int ret = -1;
if ((n = virXPathUInt("string(./vcpu[1])", ctxt, &maxvcpus)) < 0) { vcpus = maxvcpus = 1;
if (n == -2) {
if ((vcpuNode = virXPathNode("./vcpu[1]", ctxt))) {
if ((tmp = virXMLNodeContentString(vcpuNode))) {
if (virStrToLong_ui(tmp, NULL, 10, &maxvcpus) < 0) {
virReportError(VIR_ERR_XML_ERROR, "%s", virReportError(VIR_ERR_XML_ERROR, "%s",
_("maximum vcpus count must be an integer")); _("maximum vcpus count must be an integer"));
goto cleanup; goto cleanup;
} }
VIR_FREE(tmp);
maxvcpus = 1;
} }
if (virDomainDefSetVcpusMax(def, maxvcpus, xmlopt) < 0) if ((tmp = virXMLPropString(vcpuNode, "current"))) {
goto cleanup; if (virStrToLong_ui(tmp, NULL, 10, &vcpus) < 0) {
if ((n = virXPathUInt("string(./vcpu[1]/@current)", ctxt, &vcpus)) < 0) {
if (n == -2) {
virReportError(VIR_ERR_XML_ERROR, "%s", virReportError(VIR_ERR_XML_ERROR, "%s",
_("current vcpus count must be an integer")); _("current vcpus count must be an integer"));
goto cleanup; goto cleanup;
} }
VIR_FREE(tmp);
} else {
vcpus = maxvcpus; vcpus = maxvcpus;
} }
tmp = virXMLPropString(vcpuNode, "placement");
tmp = virXPathString("string(./vcpu[1]/@placement)", ctxt);
if (tmp) { if (tmp) {
if ((def->placement_mode = if ((def->placement_mode =
virDomainCpuPlacementModeTypeFromString(tmp)) < 0) { virDomainCpuPlacementModeTypeFromString(tmp)) < 0) {
...@@ -16959,7 +16959,7 @@ virDomainVcpuParse(virDomainDefPtr def, ...@@ -16959,7 +16959,7 @@ virDomainVcpuParse(virDomainDefPtr def,
} }
if (def->placement_mode != VIR_DOMAIN_CPU_PLACEMENT_MODE_AUTO) { if (def->placement_mode != VIR_DOMAIN_CPU_PLACEMENT_MODE_AUTO) {
tmp = virXPathString("string(./vcpu[1]/@cpuset)", ctxt); tmp = virXMLPropString(vcpuNode, "cpuset");
if (tmp) { if (tmp) {
if (virBitmapParse(tmp, &def->cpumask, VIR_DOMAIN_CPUMASK_LEN) < 0) if (virBitmapParse(tmp, &def->cpumask, VIR_DOMAIN_CPUMASK_LEN) < 0)
goto cleanup; goto cleanup;
...@@ -16973,6 +16973,10 @@ virDomainVcpuParse(virDomainDefPtr def, ...@@ -16973,6 +16973,10 @@ virDomainVcpuParse(virDomainDefPtr def,
VIR_FREE(tmp); VIR_FREE(tmp);
} }
} }
}
if (virDomainDefSetVcpusMax(def, maxvcpus, xmlopt) < 0)
goto cleanup;
if ((n = virXPathNodeSet("./vcpus/vcpu", ctxt, &nodes)) < 0) if ((n = virXPathNodeSet("./vcpus/vcpu", ctxt, &nodes)) < 0)
goto cleanup; goto cleanup;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册