[libvirt PATCH v2 04/10] virPCIDeviceAddressParseXML: Use virXMLProp*

Tim Wiederhake twiederh at redhat.com
Wed Apr 21 12:08:02 UTC 2021


Signed-off-by: Tim Wiederhake <twiederh at redhat.com>
Reviewed-by: Peter Krempa <pkrempa at redhat.com>
---
 src/conf/device_conf.c | 47 +++++++++++-------------------------------
 1 file changed, 12 insertions(+), 35 deletions(-)

diff --git a/src/conf/device_conf.c b/src/conf/device_conf.c
index 9abbd5ebb7..801552a9cf 100644
--- a/src/conf/device_conf.c
+++ b/src/conf/device_conf.c
@@ -200,52 +200,29 @@ virPCIDeviceAddressParseXML(xmlNodePtr node,
 {
     xmlNodePtr cur;
     xmlNodePtr zpci = NULL;
-    g_autofree char *domain   = virXMLPropString(node, "domain");
-    g_autofree char *bus      = virXMLPropString(node, "bus");
-    g_autofree char *slot     = virXMLPropString(node, "slot");
-    g_autofree char *function = virXMLPropString(node, "function");
-    g_autofree char *multi    = virXMLPropString(node, "multifunction");
 
     memset(addr, 0, sizeof(*addr));
 
-    if (domain &&
-        virStrToLong_uip(domain, NULL, 0, &addr->domain) < 0) {
-        virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
-                       _("Cannot parse <address> 'domain' attribute"));
+    if (virXMLPropUInt(node, "domain", 0, VIR_XML_PROP_NONE,
+                       &addr->domain) < 0)
         return -1;
-    }
 
-    if (bus &&
-        virStrToLong_uip(bus, NULL, 0, &addr->bus) < 0) {
-        virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
-                       _("Cannot parse <address> 'bus' attribute"));
+    if (virXMLPropUInt(node, "bus", 0, VIR_XML_PROP_NONE,
+                       &addr->bus) < 0)
         return -1;
-    }
 
-    if (slot &&
-        virStrToLong_uip(slot, NULL, 0, &addr->slot) < 0) {
-        virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
-                       _("Cannot parse <address> 'slot' attribute"));
+    if (virXMLPropUInt(node, "slot", 0, VIR_XML_PROP_NONE,
+                       &addr->slot) < 0)
         return -1;
-    }
 
-    if (function &&
-        virStrToLong_uip(function, NULL, 0, &addr->function) < 0) {
-        virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
-                       _("Cannot parse <address> 'function' attribute"));
+    if (virXMLPropUInt(node, "function", 0, VIR_XML_PROP_NONE,
+                       &addr->function) < 0)
+        return -1;
+
+    if (virXMLPropTristateSwitch(node, "multifunction", VIR_XML_PROP_NONE,
+                                 &addr->multi) < 0)
         return -1;
-    }
 
-    if (multi) {
-        int value;
-        if ((value = virTristateSwitchTypeFromString(multi)) <= 0) {
-            virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
-                           _("Unknown value '%s' for <address> 'multifunction' attribute"),
-                           multi);
-            return -1;
-        }
-        addr->multi = value;
-    }
     if (!virPCIDeviceAddressIsEmpty(addr) && !virPCIDeviceAddressIsValid(addr, true))
         return -1;
 
-- 
2.26.3




More information about the libvir-list mailing list