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 c5b13783f3..5d7fd6794f 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -11566,11 +11566,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;
@@ -11593,21 +11595,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