[PATCH v2 02/11] qemu: domain: Despaghetify qemuDomainDeviceDefValidate

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

 



Move network device validation into a separate function.
---
 src/qemu/qemu_domain.c | 158 ++++++++++++++++++++++++++-----------------------
 1 file changed, 84 insertions(+), 74 deletions(-)

diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index cc7596bad1..3755a23907 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -3589,101 +3589,111 @@ qemuDomainWatchdogDefValidate(const virDomainWatchdogDef *dev,


 static int
-qemuDomainDeviceDefValidate(const virDomainDeviceDef *dev,
-                            const virDomainDef *def,
-                            void *opaque ATTRIBUTE_UNUSED)
+qemuDomainDeviceDefValidateNetwork(const virDomainNetDef *net)
 {
-    int ret = -1;
+    bool hasIPv4 = false;
+    bool hasIPv6 = false;
     size_t i;

-    if (dev->type == VIR_DOMAIN_DEVICE_NET) {
-        const virDomainNetDef *net = dev->data.net;
-        bool hasIPv4 = false, hasIPv6 = false;
+    if (net->type == VIR_DOMAIN_NET_TYPE_USER) {
+        if (net->guestIP.nroutes) {
+            virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+                           _("Invalid attempt to set network interface "
+                             "guest-side IP route, not supported by QEMU"));
+            return -1;
+        }

-        if (net->type == VIR_DOMAIN_NET_TYPE_USER) {
-            if (net->guestIP.nroutes) {
+        for (i = 0; i < net->guestIP.nips; i++) {
+            const virNetDevIPAddr *ip = net->guestIP.ips[i];
+
+            if (VIR_SOCKET_ADDR_VALID(&net->guestIP.ips[i]->peer)) {
                 virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
-                               _("Invalid attempt to set network interface "
-                                 "guest-side IP route, not supported by QEMU"));
-                goto cleanup;
+                               _("Invalid attempt to set peer IP for guest"));
+                return -1;
             }

-            for (i = 0; i < net->guestIP.nips; i++) {
-                const virNetDevIPAddr *ip = net->guestIP.ips[i];
-
-                if (VIR_SOCKET_ADDR_VALID(&net->guestIP.ips[i]->peer)) {
+            if (VIR_SOCKET_ADDR_IS_FAMILY(&ip->address, AF_INET)) {
+                if (hasIPv4) {
                     virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
-                                   _("Invalid attempt to set peer IP for guest"));
-                    goto cleanup;
+                                   _("Only one IPv4 address per "
+                                     "interface is allowed"));
+                    return -1;
                 }
+                hasIPv4 = true;

-                if (VIR_SOCKET_ADDR_IS_FAMILY(&ip->address, AF_INET)) {
-                    if (hasIPv4) {
-                        virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
-                                       _("Only one IPv4 address per "
-                                         "interface is allowed"));
-                        goto cleanup;
-                    }
-                    hasIPv4 = true;
-
-                    if (ip->prefix > 27) {
-                        virReportError(VIR_ERR_XML_ERROR, "%s",
-                                       _("prefix too long"));
-                        goto cleanup;
-                    }
+                if (ip->prefix > 27) {
+                    virReportError(VIR_ERR_XML_ERROR, "%s",
+                                   _("prefix too long"));
+                    return -1;
                 }
+            }

-                if (VIR_SOCKET_ADDR_IS_FAMILY(&ip->address, AF_INET6)) {
-                    if (hasIPv6) {
-                        virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
-                                       _("Only one IPv6 address per "
-                                         "interface is allowed"));
-                        goto cleanup;
-                    }
-                    hasIPv6 = true;
+            if (VIR_SOCKET_ADDR_IS_FAMILY(&ip->address, AF_INET6)) {
+                if (hasIPv6) {
+                    virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+                                   _("Only one IPv6 address per "
+                                     "interface is allowed"));
+                    return -1;
+                }
+                hasIPv6 = true;

-                    if (ip->prefix > 120) {
-                        virReportError(VIR_ERR_XML_ERROR, "%s",
-                                       _("prefix too long"));
-                        goto cleanup;
-                    }
+                if (ip->prefix > 120) {
+                    virReportError(VIR_ERR_XML_ERROR, "%s",
+                                   _("prefix too long"));
+                    return -1;
                 }
             }
-        } else if (net->guestIP.nroutes || net->guestIP.nips) {
-            virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
-                           _("Invalid attempt to set network interface "
-                             "guest-side IP route and/or address info, "
-                             "not supported by QEMU"));
-            goto cleanup;
         }
+    } else if (net->guestIP.nroutes || net->guestIP.nips) {
+        virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+                       _("Invalid attempt to set network interface "
+                         "guest-side IP route and/or address info, "
+                         "not supported by QEMU"));
+        return -1;
+    }

-        if (STREQ_NULLABLE(net->model, "virtio")) {
-            if (net->driver.virtio.rx_queue_size & (net->driver.virtio.rx_queue_size - 1)) {
-                virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
-                               _("rx_queue_size has to be a power of two"));
-                goto cleanup;
-            }
-            if (net->driver.virtio.tx_queue_size & (net->driver.virtio.tx_queue_size - 1)) {
-                virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
-                               _("tx_queue_size has to be a power of two"));
-                goto cleanup;
-            }
+    if (STREQ_NULLABLE(net->model, "virtio")) {
+        if (net->driver.virtio.rx_queue_size & (net->driver.virtio.rx_queue_size - 1)) {
+            virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+                           _("rx_queue_size has to be a power of two"));
+            return -1;
         }
-
-        if (net->mtu &&
-            !qemuDomainNetSupportsMTU(net->type)) {
-            virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
-                           _("setting MTU on interface type %s is not supported yet"),
-                           virDomainNetTypeToString(net->type));
-            goto cleanup;
+        if (net->driver.virtio.tx_queue_size & (net->driver.virtio.tx_queue_size - 1)) {
+            virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+                           _("tx_queue_size has to be a power of two"));
+            return -1;
         }
+    }

-        if (net->coalesce && !qemuDomainNetSupportsCoalesce(net->type)) {
-            virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
-                           _("coalesce settings on interface type %s are not supported"),
-                           virDomainNetTypeToString(net->type));
+    if (net->mtu &&
+        !qemuDomainNetSupportsMTU(net->type)) {
+        virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+                       _("setting MTU on interface type %s is not supported yet"),
+                       virDomainNetTypeToString(net->type));
+        return -1;
+    }
+
+    if (net->coalesce && !qemuDomainNetSupportsCoalesce(net->type)) {
+        virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+                       _("coalesce settings on interface type %s are not supported"),
+                       virDomainNetTypeToString(net->type));
+        return -1;
+    }
+
+    return 0;
+}
+
+
+static int
+qemuDomainDeviceDefValidate(const virDomainDeviceDef *dev,
+                            const virDomainDef *def,
+                            void *opaque ATTRIBUTE_UNUSED)
+{
+    int ret = -1;
+
+    if (dev->type == VIR_DOMAIN_DEVICE_NET) {
+        if (qemuDomainDeviceDefValidateNetwork(dev->data.net) < 0)
             goto cleanup;
-        }
     } else if (dev->type == VIR_DOMAIN_DEVICE_CHR) {
         if (qemuDomainChrDefValidate(dev->data.chr, def) < 0)
             goto cleanup;
-- 
2.14.3

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list



[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