[RFCv2 19/46] conf: Extract error-checking code from virNetworkDNSDefParseXML

Shi Lei shi_lei at massclouds.com
Fri Sep 4 03:35:11 UTC 2020


Signed-off-by: Shi Lei <shi_lei at massclouds.com>
---
 src/conf/network_conf.c | 34 ++++++++++++++++++++++++++++------
 1 file changed, 28 insertions(+), 6 deletions(-)

diff --git a/src/conf/network_conf.c b/src/conf/network_conf.c
index 437c2c6..910d23f 100644
--- a/src/conf/network_conf.c
+++ b/src/conf/network_conf.c
@@ -882,6 +882,31 @@ virNetworkDNSForwarderParseXMLHook(xmlNodePtr node G_GNUC_UNUSED,
 }
 
 
+static int
+virNetworkDNSDefParseXMLHook(xmlNodePtr node G_GNUC_UNUSED,
+                             virNetworkDNSDefPtr def,
+                             const char *networkName,
+                             void *parent G_GNUC_UNUSED,
+                             void *opaque G_GNUC_UNUSED,
+                             const char *enable G_GNUC_UNUSED,
+                             const char *forwardPlainNames G_GNUC_UNUSED,
+                             int ntxts,
+                             int nhosts,
+                             int nsrvs,
+                             int nfwds)
+{
+    if (def->enable == VIR_TRISTATE_BOOL_NO &&
+        (nfwds || nhosts || nsrvs || ntxts)) {
+        virReportError(VIR_ERR_XML_ERROR,
+                       _("Extra data in disabled network '%s'"),
+                       networkName);
+        return -1;
+    }
+
+    return 0;
+}
+
+
 static int
 virNetworkDNSDefParseXML(const char *networkName,
                          xmlNodePtr node,
@@ -1007,13 +1032,10 @@ virNetworkDNSDefParseXML(const char *networkName,
         }
     }
 
-    if (def->enable == VIR_TRISTATE_BOOL_NO &&
-        (nfwds || nhosts || nsrvs || ntxts)) {
-        virReportError(VIR_ERR_XML_ERROR,
-                       _("Extra data in disabled network '%s'"),
-                       networkName);
+    if (virNetworkDNSDefParseXMLHook(node, def, networkName, def, NULL,
+                                     enable, forwardPlainNames,
+                                     ntxts, nhosts, nsrvs, nfwds) < 0)
         return -1;
-    }
 
     return 0;
 }
-- 
2.25.1





More information about the libvir-list mailing list