Signed-off-by: Kristina Hanicova <khanicov(a)redhat.com>
---
src/conf/domain_conf.c | 25 +++++++++----------------
1 file changed, 9 insertions(+), 16 deletions(-)
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 0748c93567..8d53b30917 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -12145,11 +12145,13 @@ virDomainChrDefParseXML(virDomainXMLOption *xmlopt,
xmlNodePtr node,
unsigned int flags)
{
- xmlNodePtr cur;
+ xmlNodePtr target;
const char *nodeName;
virDomainChrDef *def;
- bool seenTarget = false;
g_autofree char *type = NULL;
+ VIR_XPATH_NODE_AUTORESTORE(ctxt)
+
+ ctxt->node = node;
if (!(def = virDomainChrDefNew(xmlopt)))
return NULL;
@@ -12172,21 +12174,12 @@ virDomainChrDefParseXML(virDomainXMLOption *xmlopt,
goto error;
}
- cur = node->children;
- while (cur != NULL) {
- if (cur->type == XML_ELEMENT_NODE) {
- if (virXMLNodeNameEqual(cur, "target")) {
- seenTarget = true;
- if (virDomainChrDefParseTargetXML(def, cur, ctxt, flags) < 0)
- goto error;
- }
- }
- cur = cur->next;
- }
-
- if (!seenTarget &&
- ((def->targetType = virDomainChrDefaultTargetType(def->deviceType)) <
0))
+ if ((target = virXPathNode("./target", ctxt))) {
+ if (virDomainChrDefParseTargetXML(def, target, ctxt, flags) < 0)
+ goto error;
+ } else if ((def->targetType = virDomainChrDefaultTargetType(def->deviceType))
< 0) {
goto error;
+ }
if (virDomainChrSourceDefParseXML(def->source, node, flags, def,
ctxt) < 0)
--
2.30.2