[PATCH 03/10] conf: use virXMLPropString for virDomainVirtioOptionsParseXML

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



XPath is good for random search of elements, not for accessing
attributes of one node.

Signed-off-by: Pavel Hrdina <phrdina@xxxxxxxxxx>
---
 src/conf/domain_conf.c | 49 ++++++++++++++++++++++++++++---------------------
 1 file changed, 28 insertions(+), 21 deletions(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 281dc68f0e..ec4fbf36b3 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -1114,7 +1114,7 @@ virDomainXMLOptionGetNamespace(virDomainXMLOptionPtr xmlopt)
 }
 
 static int
-virDomainVirtioOptionsParseXML(xmlXPathContextPtr ctxt,
+virDomainVirtioOptionsParseXML(xmlNodePtr driver,
                                virDomainVirtioOptionsPtr *virtio)
 {
     char *str = NULL;
@@ -1122,12 +1122,15 @@ virDomainVirtioOptionsParseXML(xmlXPathContextPtr ctxt,
     int val;
     virDomainVirtioOptionsPtr res;
 
+    if (*virtio || !driver)
+        return 0;
+
     if (VIR_ALLOC(*virtio) < 0)
         return -1;
 
     res = *virtio;
 
-    if ((str = virXPathString("string(./driver/@iommu)", ctxt))) {
+    if ((str = virXMLPropString(driver, "iommu"))) {
         if ((val = virTristateSwitchTypeFromString(str)) <= 0) {
             virReportError(VIR_ERR_XML_ERROR, "%s",
                            _("invalid iommu value"));
@@ -1137,7 +1140,7 @@ virDomainVirtioOptionsParseXML(xmlXPathContextPtr ctxt,
     }
     VIR_FREE(str);
 
-    if ((str = virXPathString("string(./driver/@ats)", ctxt))) {
+    if ((str = virXMLPropString(driver, "ats"))) {
         if ((val = virTristateSwitchTypeFromString(str)) <= 0) {
             virReportError(VIR_ERR_XML_ERROR, "%s",
                            _("invalid ats value"));
@@ -8406,6 +8409,9 @@ virDomainDiskDefParseXML(virDomainXMLOptionPtr xmlopt,
             }
         } else if (!def->src->driverName &&
                    virXMLNodeNameEqual(cur, "driver")) {
+            if (virDomainVirtioOptionsParseXML(cur, &def->virtio) < 0)
+                goto error;
+
             if (virDomainDiskDefDriverParseXML(def, cur) < 0)
                 goto error;
         } else if (!def->mirror &&
@@ -8491,9 +8497,6 @@ virDomainDiskDefParseXML(virDomainXMLOptionPtr xmlopt,
         }
     }
 
-    if (virDomainVirtioOptionsParseXML(ctxt, &def->virtio) < 0)
-        goto error;
-
     /* Disk volume types will have authentication information handled in
      * virStorageTranslateDiskSourcePool
      */
@@ -9078,6 +9081,9 @@ virDomainControllerDefParseXML(xmlNodePtr node,
                 max_sectors = virXMLPropString(cur, "max_sectors");
                 ioeventfd = virXMLPropString(cur, "ioeventfd");
                 iothread = virXMLPropString(cur, "iothread");
+
+                if (virDomainVirtioOptionsParseXML(cur, &def->virtio) < 0)
+                    goto error;
             } else if (virXMLNodeNameEqual(cur, "model")) {
                 if (processedModel) {
                     virReportError(VIR_ERR_XML_ERROR, "%s",
@@ -9105,9 +9111,6 @@ virDomainControllerDefParseXML(xmlNodePtr node,
         cur = cur->next;
     }
 
-    if (virDomainVirtioOptionsParseXML(ctxt, &def->virtio) < 0)
-        goto error;
-
     /* node is parsed differently from target attributes because
      * someone thought it should be a subelement instead...
      */
@@ -9483,6 +9486,9 @@ virDomainFSDefParseXML(xmlNodePtr node,
                     wrpolicy = virXMLPropString(cur, "wrpolicy");
                 if (!format)
                     format = virXMLPropString(cur, "format");
+
+                if (virDomainVirtioOptionsParseXML(cur, &def->virtio) < 0)
+                    goto error;
             }
         }
         cur = cur->next;
@@ -9544,9 +9550,6 @@ virDomainFSDefParseXML(xmlNodePtr node,
             goto error;
     }
 
-    if (virDomainVirtioOptionsParseXML(ctxt, &def->virtio) < 0)
-        goto error;
-
     def->src->path = source;
     source = NULL;
     def->dst = target;
@@ -9986,6 +9989,9 @@ virDomainNetDefParseXML(virDomainXMLOptionPtr xmlopt,
                 queues = virXMLPropString(cur, "queues");
                 rx_queue_size = virXMLPropString(cur, "rx_queue_size");
                 tx_queue_size = virXMLPropString(cur, "tx_queue_size");
+
+                if (virDomainVirtioOptionsParseXML(cur, &def->virtio) < 0)
+                    goto error;
             } else if (virXMLNodeNameEqual(cur, "filterref")) {
                 if (filter) {
                     virReportError(VIR_ERR_XML_ERROR, "%s",
@@ -10563,9 +10569,6 @@ virDomainNetDefParseXML(virDomainXMLOptionPtr xmlopt,
             goto error;
     }
 
-    if (virDomainVirtioOptionsParseXML(ctxt, &def->virtio) < 0)
-        goto error;
-
  cleanup:
     ctxt->node = oldnode;
     VIR_FREE(macaddr);
@@ -11689,7 +11692,8 @@ virDomainInputDefParseXML(const virDomainDef *dom,
         goto error;
     }
 
-    if (virDomainVirtioOptionsParseXML(ctxt, &def->virtio) < 0)
+    if (virDomainVirtioOptionsParseXML(virXPathNode("./driver", ctxt),
+                                       &def->virtio) < 0)
         goto error;
 
  cleanup:
@@ -13028,7 +13032,8 @@ virDomainRNGDefParseXML(virDomainXMLOptionPtr xmlopt,
     if (virDomainDeviceInfoParseXML(node, NULL, &def->info, flags) < 0)
         goto error;
 
-    if (virDomainVirtioOptionsParseXML(ctxt, &def->virtio) < 0)
+    if (virDomainVirtioOptionsParseXML(virXPathNode("./driver", ctxt),
+                                       &def->virtio) < 0)
         goto error;
 
  cleanup:
@@ -13096,7 +13101,8 @@ virDomainMemballoonDefParseXML(xmlNodePtr node,
     else if (virDomainDeviceInfoParseXML(node, NULL, &def->info, flags) < 0)
         goto error;
 
-    if (virDomainVirtioOptionsParseXML(ctxt, &def->virtio) < 0)
+    if (virDomainVirtioOptionsParseXML(virXPathNode("./driver", ctxt),
+                                       &def->virtio) < 0)
         goto error;
 
  cleanup:
@@ -13681,6 +13687,10 @@ virDomainVideoDefParseXML(xmlNodePtr node,
 
                 def->accel = virDomainVideoAccelDefParseXML(cur);
             }
+            if (virXMLNodeNameEqual(cur, "driver")) {
+                if (virDomainVirtioOptionsParseXML(cur, &def->virtio) < 0)
+                    goto error;
+            }
         }
         cur = cur->next;
     }
@@ -13759,9 +13769,6 @@ virDomainVideoDefParseXML(xmlNodePtr node,
     if (virDomainDeviceInfoParseXML(node, NULL, &def->info, flags) < 0)
         goto error;
 
-    if (virDomainVirtioOptionsParseXML(ctxt, &def->virtio) < 0)
-        goto error;
-
     def->driver = virDomainVideoDriverDefParseXML(node);
 
  cleanup:
-- 
2.13.5

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list



[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]
  Powered by Linux