404507
From 413eb4cbdddfd7ecc3fd12320a59033c76f878cc Mon Sep 17 00:00:00 2001
404507
Message-Id: <413eb4cbdddfd7ecc3fd12320a59033c76f878cc@dist-git>
404507
From: Peter Krempa <pkrempa@redhat.com>
404507
Date: Thu, 23 Nov 2017 19:02:15 +0100
404507
Subject: [PATCH] qemu: domain: Move hostdev validation into separate function
404507
404507
(cherry picked from commit a6936ec0987f6b014516e4d51b44c9c9de57a6cb)
404507
404507
https://bugzilla.redhat.com/show_bug.cgi?id=1511480
404507
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
404507
---
404507
 src/qemu/qemu_domain.c | 30 ++++++++++++++++++++----------
404507
 1 file changed, 20 insertions(+), 10 deletions(-)
404507
404507
diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
404507
index 30a602a1e9..13b96368c1 100644
404507
--- a/src/qemu/qemu_domain.c
404507
+++ b/src/qemu/qemu_domain.c
404507
@@ -3649,6 +3649,23 @@ qemuDomainDeviceDefValidateNetwork(const virDomainNetDef *net)
404507
 }
404507
 
404507
 
404507
+static int
404507
+qemuDomainDeviceDefValidateHostdev(const virDomainHostdevDef *hostdev,
404507
+                                   const virDomainDef *def)
404507
+{
404507
+    /* forbid capabilities mode hostdev in this kind of hypervisor */
404507
+    if (hostdev->mode == VIR_DOMAIN_HOSTDEV_MODE_CAPABILITIES) {
404507
+        virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
404507
+                       _("hostdev mode 'capabilities' is not "
404507
+                         "supported in %s"),
404507
+                       virDomainVirtTypeToString(def->virtType));
404507
+        return -1;
404507
+    }
404507
+
404507
+    return 0;
404507
+}
404507
+
404507
+
404507
 static int
404507
 qemuDomainDeviceDefValidate(const virDomainDeviceDef *dev,
404507
                             const virDomainDef *def,
404507
@@ -3674,16 +3691,9 @@ qemuDomainDeviceDefValidate(const virDomainDeviceDef *dev,
404507
     } else if (dev->type == VIR_DOMAIN_DEVICE_WATCHDOG) {
404507
         if (qemuDomainWatchdogDefValidate(dev->data.watchdog, def) < 0)
404507
             goto cleanup;
404507
-    }
404507
-
404507
-    /* forbid capabilities mode hostdev in this kind of hypervisor */
404507
-    if (dev->type == VIR_DOMAIN_DEVICE_HOSTDEV &&
404507
-        dev->data.hostdev->mode == VIR_DOMAIN_HOSTDEV_MODE_CAPABILITIES) {
404507
-        virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
404507
-                       _("hostdev mode 'capabilities' is not "
404507
-                         "supported in %s"),
404507
-                       virDomainVirtTypeToString(def->virtType));
404507
-        goto cleanup;
404507
+    } else if (dev->type == VIR_DOMAIN_DEVICE_HOSTDEV) {
404507
+        if (qemuDomainDeviceDefValidateHostdev(dev->data.hostdev, def) < 0)
404507
+            goto cleanup;
404507
     }
404507
 
404507
     if (dev->type == VIR_DOMAIN_DEVICE_VIDEO) {
404507
-- 
404507
2.15.0
404507