]> xenbits.xensource.com Git - libvirt.git/commitdiff
conf: Convert virNetworkPortDefParseXML() to virXMLProp*()
authorMichal Privoznik <mprivozn@redhat.com>
Fri, 21 Jan 2022 09:19:34 +0000 (10:19 +0100)
committerMichal Privoznik <mprivozn@redhat.com>
Fri, 21 Jan 2022 15:42:14 +0000 (16:42 +0100)
After previous cleanups, the virNetworkPortDefParseXML() function
uses a mixture of virXMLProp*() and the old virXMLPropString() +
virXXXTypeFromString() patterns. Rework it so that virXMLProp*()
is used.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
src/conf/virnetworkportdef.c
src/conf/virnetworkportdef.h

index 1d7543608597fcb010dd3cc8167088ac75dc0b49..fcd9e55a557b2292f054ee917ef4b57a0c5fa165 100644 (file)
@@ -92,7 +92,6 @@ virNetworkPortDefParseXML(xmlXPathContextPtr ctxt)
     g_autofree char *mac = NULL;
     g_autofree char *macmgr = NULL;
     g_autofree char *mode = NULL;
-    g_autofree char *plugtype = NULL;
     g_autofree char *driver = NULL;
 
     def = g_new0(virNetworkPortDef, 1);
@@ -176,13 +175,12 @@ virNetworkPortDefParseXML(xmlXPathContextPtr ctxt)
         return NULL;
 
     plugNode = virXPathNode("./plug", ctxt);
-    plugtype = virXPathString("string(./plug/@type)", ctxt);
 
-    if (plugtype &&
-        (def->plugtype = virNetworkPortPlugTypeFromString(plugtype)) < 0) {
-        virReportError(VIR_ERR_XML_ERROR,
-                       _("Invalid network port plug type '%s'"), plugtype);
-    }
+    if (virXMLPropEnum(plugNode, "type",
+                       virNetworkPortPlugTypeFromString,
+                       VIR_XML_PROP_NONE,
+                       &def->plugtype) < 0)
+        return NULL;
 
     switch (def->plugtype) {
     case VIR_NETWORK_PORT_PLUG_TYPE_NONE:
@@ -190,12 +188,12 @@ virNetworkPortDefParseXML(xmlXPathContextPtr ctxt)
 
     case VIR_NETWORK_PORT_PLUG_TYPE_NETWORK:
     case VIR_NETWORK_PORT_PLUG_TYPE_BRIDGE:
-        if (!(def->plug.bridge.brname = virXPathString("string(./plug/@bridge)", ctxt))) {
+        if (!(def->plug.bridge.brname = virXMLPropString(plugNode, "bridge"))) {
             virReportError(VIR_ERR_XML_ERROR, "%s",
                            _("Missing network port bridge name"));
             return NULL;
         }
-        macmgr = virXPathString("string(./plug/@macTableManager)", ctxt);
+        macmgr = virXMLPropString(plugNode, "macTableManager");
         if (macmgr &&
             (def->plug.bridge.macTableManager =
              virNetworkBridgeMACTableManagerTypeFromString(macmgr)) <= 0) {
@@ -207,12 +205,12 @@ virNetworkPortDefParseXML(xmlXPathContextPtr ctxt)
         break;
 
     case VIR_NETWORK_PORT_PLUG_TYPE_DIRECT:
-        if (!(def->plug.direct.linkdev = virXPathString("string(./plug/@dev)", ctxt))) {
+        if (!(def->plug.direct.linkdev = virXMLPropString(plugNode, "dev"))) {
             virReportError(VIR_ERR_XML_ERROR, "%s",
                            _("Missing network port link device name"));
             return NULL;
         }
-        mode = virXPathString("string(./plug/@mode)", ctxt);
+        mode = virXMLPropString(plugNode, "mode");
         if (mode &&
             (def->plug.direct.mode =
              virNetDevMacVLanModeTypeFromString(mode)) < 0) {
index c6474c4ad8b11474c69a11460db65cd5a7ab3905..ee13f8a0846b0b23ac33ad5db3e26ffe1c546d06 100644 (file)
@@ -58,7 +58,7 @@ struct _virNetworkPortDef {
     virTristateBool trustGuestRxFilters;
     virTristateBool isolatedPort;
 
-    int plugtype; /* virNetworkPortPlugType */
+    virNetworkPortPlugType plugtype;
     union {
         struct {
             char *brname;