render / rpms / libvirt

Forked from rpms/libvirt 9 months ago
Clone
Blob Blame History Raw
From 413eb4cbdddfd7ecc3fd12320a59033c76f878cc Mon Sep 17 00:00:00 2001
Message-Id: <413eb4cbdddfd7ecc3fd12320a59033c76f878cc@dist-git>
From: Peter Krempa <pkrempa@redhat.com>
Date: Thu, 23 Nov 2017 19:02:15 +0100
Subject: [PATCH] qemu: domain: Move hostdev validation into separate function

(cherry picked from commit a6936ec0987f6b014516e4d51b44c9c9de57a6cb)

https://bugzilla.redhat.com/show_bug.cgi?id=1511480
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
---
 src/qemu/qemu_domain.c | 30 ++++++++++++++++++++----------
 1 file changed, 20 insertions(+), 10 deletions(-)

diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index 30a602a1e9..13b96368c1 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -3649,6 +3649,23 @@ qemuDomainDeviceDefValidateNetwork(const virDomainNetDef *net)
 }
 
 
+static int
+qemuDomainDeviceDefValidateHostdev(const virDomainHostdevDef *hostdev,
+                                   const virDomainDef *def)
+{
+    /* forbid capabilities mode hostdev in this kind of hypervisor */
+    if (hostdev->mode == VIR_DOMAIN_HOSTDEV_MODE_CAPABILITIES) {
+        virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+                       _("hostdev mode 'capabilities' is not "
+                         "supported in %s"),
+                       virDomainVirtTypeToString(def->virtType));
+        return -1;
+    }
+
+    return 0;
+}
+
+
 static int
 qemuDomainDeviceDefValidate(const virDomainDeviceDef *dev,
                             const virDomainDef *def,
@@ -3674,16 +3691,9 @@ qemuDomainDeviceDefValidate(const virDomainDeviceDef *dev,
     } else if (dev->type == VIR_DOMAIN_DEVICE_WATCHDOG) {
         if (qemuDomainWatchdogDefValidate(dev->data.watchdog, def) < 0)
             goto cleanup;
-    }
-
-    /* forbid capabilities mode hostdev in this kind of hypervisor */
-    if (dev->type == VIR_DOMAIN_DEVICE_HOSTDEV &&
-        dev->data.hostdev->mode == VIR_DOMAIN_HOSTDEV_MODE_CAPABILITIES) {
-        virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
-                       _("hostdev mode 'capabilities' is not "
-                         "supported in %s"),
-                       virDomainVirtTypeToString(def->virtType));
-        goto cleanup;
+    } else if (dev->type == VIR_DOMAIN_DEVICE_HOSTDEV) {
+        if (qemuDomainDeviceDefValidateHostdev(dev->data.hostdev, def) < 0)
+            goto cleanup;
     }
 
     if (dev->type == VIR_DOMAIN_DEVICE_VIDEO) {
-- 
2.15.0