[libvirt PATCH v2 25/51] domain_conf: Use virXMLPropTristateXXX in virDomainNetDefParseXML

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

 



Signed-off-by: Tim Wiederhake <twiederh@xxxxxxxxxx>
---
 src/conf/domain_conf.c | 177 +++++++++++------------------------------
 1 file changed, 48 insertions(+), 129 deletions(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index fef0b7235a..329f42d6dd 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -10720,7 +10720,6 @@ virDomainNetDefParseXML(virDomainXMLOptionPtr xmlopt,
     g_autofree char *queues = NULL;
     g_autofree char *rx_queue_size = NULL;
     g_autofree char *tx_queue_size = NULL;
-    g_autofree char *str = NULL;
     g_autofree char *filter = NULL;
     g_autofree char *internal = NULL;
     g_autofree char *mode = NULL;
@@ -10730,7 +10729,6 @@ virDomainNetDefParseXML(virDomainXMLOptionPtr xmlopt,
     g_autofree char *vhostuser_mode = NULL;
     g_autofree char *vhostuser_path = NULL;
     g_autofree char *vhostuser_type = NULL;
-    g_autofree char *trustGuestRxFilters = NULL;
     g_autofree char *vhost_path = NULL;
     const char *prefix = xmlopt ? xmlopt->config.netPrefix : NULL;
 
@@ -10750,15 +10748,9 @@ virDomainNetDefParseXML(virDomainXMLOptionPtr xmlopt,
         def->type = VIR_DOMAIN_NET_TYPE_USER;
     }
 
-    trustGuestRxFilters = virXMLPropString(node, "trustGuestRxFilters");
-    if (trustGuestRxFilters &&
-        ((def->trustGuestRxFilters
-          = virTristateBoolTypeFromString(trustGuestRxFilters)) <= 0)) {
-        virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
-                       _("unknown trustGuestRxFilters value '%s'"),
-                       trustGuestRxFilters);
+    if (virXMLPropTristateBool(node, "trustGuestRxFilters", false,
+                               &def->trustGuestRxFilters) < 0)
         goto error;
-    }
 
     cur = node->children;
     while (cur != NULL) {
@@ -11328,128 +11320,55 @@ virDomainNetDefParseXML(virDomainXMLOptionPtr xmlopt,
         }
 
         if ((tmpNode = virXPathNode("./driver/host", ctxt))) {
-            if ((str = virXMLPropString(tmpNode, "csum"))) {
-                if ((val = virTristateSwitchTypeFromString(str)) <= 0) {
-                    virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
-                                   _("unknown host csum mode '%s'"),
-                                   str);
-                    goto error;
-                }
-                def->driver.virtio.host.csum = val;
-            }
-            VIR_FREE(str);
-            if ((str = virXMLPropString(tmpNode, "gso"))) {
-                if ((val = virTristateSwitchTypeFromString(str)) <= 0) {
-                    virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
-                                   _("unknown host gso mode '%s'"),
-                                   str);
-                    goto error;
-                }
-                def->driver.virtio.host.gso = val;
-            }
-            VIR_FREE(str);
-            if ((str = virXMLPropString(tmpNode, "tso4"))) {
-                if ((val = virTristateSwitchTypeFromString(str)) <= 0) {
-                    virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
-                                   _("unknown host tso4 mode '%s'"),
-                                   str);
-                    goto error;
-                }
-                def->driver.virtio.host.tso4 = val;
-            }
-            VIR_FREE(str);
-            if ((str = virXMLPropString(tmpNode, "tso6"))) {
-                if ((val = virTristateSwitchTypeFromString(str)) <= 0) {
-                    virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
-                                   _("unknown host tso6 mode '%s'"),
-                                   str);
-                    goto error;
-                }
-                def->driver.virtio.host.tso6 = val;
-            }
-            VIR_FREE(str);
-            if ((str = virXMLPropString(tmpNode, "ecn"))) {
-                if ((val = virTristateSwitchTypeFromString(str)) <= 0) {
-                    virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
-                                   _("unknown host ecn mode '%s'"),
-                                   str);
-                    goto error;
-                }
-                def->driver.virtio.host.ecn = val;
-            }
-            VIR_FREE(str);
-            if ((str = virXMLPropString(tmpNode, "ufo"))) {
-                if ((val = virTristateSwitchTypeFromString(str)) <= 0) {
-                    virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
-                                   _("unknown host ufo mode '%s'"),
-                                   str);
-                    goto error;
-                }
-                def->driver.virtio.host.ufo = val;
-            }
-            VIR_FREE(str);
-            if ((str = virXMLPropString(tmpNode, "mrg_rxbuf"))) {
-                if ((val = virTristateSwitchTypeFromString(str)) <= 0) {
-                    virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
-                                   _("unknown host mrg_rxbuf mode '%s'"),
-                                   str);
-                    goto error;
-                }
-                def->driver.virtio.host.mrg_rxbuf = val;
-            }
-            VIR_FREE(str);
+            if (virXMLPropTristateSwitch(tmpNode, "csum", false,
+                                         &def->driver.virtio.host.csum) < 0)
+                goto error;
+
+            if (virXMLPropTristateSwitch(tmpNode, "gso", false,
+                                         &def->driver.virtio.host.gso) < 0)
+                goto error;
+
+            if (virXMLPropTristateSwitch(tmpNode, "tso4", false,
+                                         &def->driver.virtio.host.tso4) < 0)
+                goto error;
+
+            if (virXMLPropTristateSwitch(tmpNode, "tso6", false,
+                                         &def->driver.virtio.host.tso6) < 0)
+                goto error;
+
+            if (virXMLPropTristateSwitch(tmpNode, "ecn", false,
+                                         &def->driver.virtio.host.ecn) < 0)
+                goto error;
+
+            if (virXMLPropTristateSwitch(tmpNode, "ufo", false,
+                                         &def->driver.virtio.host.ufo) < 0)
+                goto error;
+
+            if (virXMLPropTristateSwitch(tmpNode, "mrg_rxbuf", false,
+                                         &def->driver.virtio.host.mrg_rxbuf) < 0)
+                goto error;
         }
 
         if ((tmpNode = virXPathNode("./driver/guest", ctxt))) {
-            if ((str = virXMLPropString(tmpNode, "csum"))) {
-                if ((val = virTristateSwitchTypeFromString(str)) <= 0) {
-                    virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
-                                   _("unknown guest csum mode '%s'"),
-                                   str);
-                    goto error;
-                }
-                def->driver.virtio.guest.csum = val;
-            }
-            VIR_FREE(str);
-            if ((str = virXMLPropString(tmpNode, "tso4"))) {
-                if ((val = virTristateSwitchTypeFromString(str)) <= 0) {
-                    virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
-                                   _("unknown guest tso4 mode '%s'"),
-                                   str);
-                    goto error;
-                }
-                def->driver.virtio.guest.tso4 = val;
-            }
-            VIR_FREE(str);
-            if ((str = virXMLPropString(tmpNode, "tso6"))) {
-                if ((val = virTristateSwitchTypeFromString(str)) <= 0) {
-                    virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
-                                   _("unknown guest tso6 mode '%s'"),
-                                   str);
-                    goto error;
-                }
-                def->driver.virtio.guest.tso6 = val;
-            }
-            VIR_FREE(str);
-            if ((str = virXMLPropString(tmpNode, "ecn"))) {
-                if ((val = virTristateSwitchTypeFromString(str)) <= 0) {
-                    virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
-                                   _("unknown guest ecn mode '%s'"),
-                                   str);
-                    goto error;
-                }
-                def->driver.virtio.guest.ecn = val;
-            }
-            VIR_FREE(str);
-            if ((str = virXMLPropString(tmpNode, "ufo"))) {
-                if ((val = virTristateSwitchTypeFromString(str)) <= 0) {
-                    virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
-                                   _("unknown guest ufo mode '%s'"),
-                                   str);
-                    goto error;
-                }
-                def->driver.virtio.guest.ufo = val;
-            }
+            if (virXMLPropTristateSwitch(tmpNode, "csum", false,
+                                         &def->driver.virtio.guest.csum) < 0)
+                goto error;
+
+            if (virXMLPropTristateSwitch(tmpNode, "tso4", false,
+                                         &def->driver.virtio.guest.tso4) < 0)
+                goto error;
+
+            if (virXMLPropTristateSwitch(tmpNode, "tso6", false,
+                                         &def->driver.virtio.guest.tso6) < 0)
+                goto error;
+
+            if (virXMLPropTristateSwitch(tmpNode, "ecn", false,
+                                         &def->driver.virtio.guest.ecn) < 0)
+                goto error;
+
+            if (virXMLPropTristateSwitch(tmpNode, "ufo", false,
+                                         &def->driver.virtio.guest.ufo) < 0)
+                goto error;
         }
         def->backend.vhost = g_steal_pointer(&vhost_path);
     }
-- 
2.26.2




[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