]> xenbits.xensource.com Git - people/liuw/libxenctrl-split/libvirt.git/commitdiff
interface: clean up virInterfaceDefParseXML
authorLaine Stump <laine@laine.org>
Thu, 19 Jun 2014 09:51:38 +0000 (12:51 +0300)
committerLaine Stump <laine@laine.org>
Fri, 20 Jun 2014 08:49:06 +0000 (11:49 +0300)
the switch cases for the 4 different interface types had repetitive
code which has now been pulled out as common. While touching those
lines, some extra usage of "!= NULL" etc has been eliminated to make
things more compact and inline with current coding practices.

NB: parentIfType == VIR_INTERFACE_TYPE_LAST means that this is a
toplevel interface (not a subordinate of a bridge or bond). Only
toplevel interfaces can have a start mode, mtu, or IP address element.

src/conf/interface_conf.c

index c1a089ab68dec79328c051d0d67bfbb68fa57459..883053f92390cf20aed8be42aef86165fc7d7298 100644 (file)
@@ -724,6 +724,19 @@ virInterfaceDefParseXML(xmlXPathContextPtr ctxt, int parentIfType)
     }
     def->type = type;
 
+    if (virInterfaceDefParseName(def, ctxt) < 0)
+       goto error;
+
+    if (parentIfType == VIR_INTERFACE_TYPE_LAST) {
+        /* only recognize these in toplevel bond interfaces */
+        if (virInterfaceDefParseStartMode(def, ctxt) < 0)
+            goto error;
+        if (virInterfaceDefParseMtu(def, ctxt) < 0)
+            goto error;
+        if (virInterfaceDefParseIfAdressing(def, ctxt) < 0)
+            goto error;
+    }
+
     if (type != VIR_INTERFACE_TYPE_BRIDGE) {
         /* link status makes no sense for a bridge */
         lnk = virXPathNode("./link", ctxt);
@@ -732,38 +745,14 @@ virInterfaceDefParseXML(xmlXPathContextPtr ctxt, int parentIfType)
     }
 
     switch (type) {
-        case VIR_INTERFACE_TYPE_ETHERNET: {
-            if (virInterfaceDefParseName(def, ctxt) < 0)
-                goto error;
-            tmp = virXPathString("string(./mac/@address)", ctxt);
-            if (tmp != NULL)
+        case VIR_INTERFACE_TYPE_ETHERNET:
+            if ((tmp = virXPathString("string(./mac/@address)", ctxt)))
                 def->mac = tmp;
-
-            if (parentIfType == VIR_INTERFACE_TYPE_LAST) {
-                /* only recognize these in toplevel bond interfaces */
-                if (virInterfaceDefParseStartMode(def, ctxt) < 0)
-                    goto error;
-                if (virInterfaceDefParseMtu(def, ctxt) < 0)
-                    goto error;
-                if (virInterfaceDefParseIfAdressing(def, ctxt) < 0)
-                    goto error;
-            }
             break;
-        }
         case VIR_INTERFACE_TYPE_BRIDGE: {
             xmlNodePtr bridge;
 
-            if (virInterfaceDefParseName(def, ctxt) < 0)
-                goto error;
-            if (virInterfaceDefParseStartMode(def, ctxt) < 0)
-                goto error;
-            if (virInterfaceDefParseMtu(def, ctxt) < 0)
-                goto error;
-            if (virInterfaceDefParseIfAdressing(def, ctxt) < 0)
-                goto error;
-
-            bridge = virXPathNode("./bridge[1]", ctxt);
-            if (bridge == NULL) {
+            if (!(bridge = virXPathNode("./bridge[1]", ctxt))) {
                 virReportError(VIR_ERR_XML_ERROR,
                                "%s", _("bridge interface misses the bridge element"));
                 goto error;
@@ -776,20 +765,7 @@ virInterfaceDefParseXML(xmlXPathContextPtr ctxt, int parentIfType)
         case VIR_INTERFACE_TYPE_BOND: {
             xmlNodePtr bond;
 
-            if (virInterfaceDefParseName(def, ctxt) < 0)
-                goto error;
-            if (parentIfType == VIR_INTERFACE_TYPE_LAST) {
-                /* only recognize these in toplevel bond interfaces */
-                if (virInterfaceDefParseStartMode(def, ctxt) < 0)
-                    goto error;
-                if (virInterfaceDefParseMtu(def, ctxt) < 0)
-                    goto error;
-                if (virInterfaceDefParseIfAdressing(def, ctxt) < 0)
-                    goto error;
-            }
-
-            bond = virXPathNode("./bond[1]", ctxt);
-            if (bond == NULL) {
+            if (!(bond = virXPathNode("./bond[1]", ctxt))) {
                 virReportError(VIR_ERR_XML_ERROR,
                                "%s", _("bond interface misses the bond element"));
                 goto error;
@@ -802,15 +778,7 @@ virInterfaceDefParseXML(xmlXPathContextPtr ctxt, int parentIfType)
         case VIR_INTERFACE_TYPE_VLAN: {
             xmlNodePtr vlan;
 
-            tmp = virXPathString("string(./@name)", ctxt);
-            if (tmp != NULL)
-                def->name = tmp;
-            if (virInterfaceDefParseStartMode(def, ctxt) < 0)
-                goto error;
-            if (virInterfaceDefParseIfAdressing(def, ctxt) < 0)
-                goto error;
-            vlan = virXPathNode("./vlan[1]", ctxt);
-            if (vlan == NULL) {
+            if (!(vlan = virXPathNode("./vlan[1]", ctxt))) {
                 virReportError(VIR_ERR_XML_ERROR,
                                "%s", _("vlan interface misses the vlan element"));
                 goto error;