[PATCH 08/15] qemu: move qemuDomainDeviceDefValidateVideo() to qemu_validate.c

Daniel Henrique Barboza danielhb413 at gmail.com
Thu Mar 26 21:31:18 UTC 2020


Signed-off-by: Daniel Henrique Barboza <danielhb413 at gmail.com>
---
 src/qemu/qemu_domain.c   | 98 +---------------------------------------
 src/qemu/qemu_validate.c | 96 +++++++++++++++++++++++++++++++++++++++
 src/qemu/qemu_validate.h |  2 +
 3 files changed, 99 insertions(+), 97 deletions(-)

diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index 25b889b2d6..6fa2326edc 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -5245,102 +5245,6 @@ qemuDomainValidateActualNetDef(const virDomainNetDef *net,
 }
 
 
-static int
-qemuDomainDeviceDefValidateVideo(const virDomainVideoDef *video,
-                                 virQEMUCapsPtr qemuCaps)
-{
-    /* there's no properties to validate for NONE video devices */
-    if (video->type == VIR_DOMAIN_VIDEO_TYPE_NONE)
-        return 0;
-
-    if (!video->primary &&
-        video->type != VIR_DOMAIN_VIDEO_TYPE_QXL &&
-        video->type != VIR_DOMAIN_VIDEO_TYPE_VIRTIO) {
-        virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
-                       _("video type '%s' is only valid as primary "
-                         "video device"),
-                       virDomainVideoTypeToString(video->type));
-        return -1;
-    }
-
-    if (video->accel && video->accel->accel2d == VIR_TRISTATE_SWITCH_ON) {
-        virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
-                       _("qemu does not support the accel2d setting"));
-        return -1;
-    }
-
-    if (video->type == VIR_DOMAIN_VIDEO_TYPE_QXL) {
-        if (video->vram > (UINT_MAX / 1024)) {
-            virReportError(VIR_ERR_OVERFLOW,
-                           _("value for 'vram' must be less than '%u'"),
-                           UINT_MAX / 1024);
-            return -1;
-        }
-        if (video->ram > (UINT_MAX / 1024)) {
-            virReportError(VIR_ERR_OVERFLOW,
-                           _("value for 'ram' must be less than '%u'"),
-                           UINT_MAX / 1024);
-            return -1;
-        }
-        if (video->vgamem) {
-            if (video->vgamem < 1024) {
-                virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
-                               _("value for 'vgamem' must be at least 1 MiB "
-                                 "(1024 KiB)"));
-                return -1;
-            }
-
-            if (video->vgamem != VIR_ROUND_UP_POWER_OF_TWO(video->vgamem)) {
-                virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
-                               _("value for 'vgamem' must be power of two"));
-                return -1;
-            }
-        }
-    }
-
-    if (video->type != VIR_DOMAIN_VIDEO_TYPE_VGA &&
-        video->type != VIR_DOMAIN_VIDEO_TYPE_QXL &&
-        video->type != VIR_DOMAIN_VIDEO_TYPE_VIRTIO &&
-        video->type != VIR_DOMAIN_VIDEO_TYPE_BOCHS) {
-        if (video->res) {
-            virReportError(VIR_ERR_XML_ERROR, "%s",
-                           _("model resolution is not supported"));
-            return -1;
-        }
-    }
-
-    if (video->type == VIR_DOMAIN_VIDEO_TYPE_VGA ||
-        video->type == VIR_DOMAIN_VIDEO_TYPE_VMVGA) {
-        if (video->vram && video->vram < 1024) {
-            virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
-                           "%s", _("value for 'vram' must be at least "
-                                   "1 MiB (1024 KiB)"));
-            return -1;
-        }
-    }
-
-    if (video->backend == VIR_DOMAIN_VIDEO_BACKEND_TYPE_VHOSTUSER) {
-        if (video->type == VIR_DOMAIN_VIDEO_TYPE_VIRTIO &&
-            !virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE_VHOST_USER_GPU)) {
-            virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
-                           _("this QEMU does not support 'vhost-user' video device"));
-            return -1;
-        }
-    } else if (video->accel) {
-        if (video->accel->accel3d == VIR_TRISTATE_SWITCH_ON &&
-            (video->type != VIR_DOMAIN_VIDEO_TYPE_VIRTIO ||
-             !virQEMUCapsGet(qemuCaps, QEMU_CAPS_VIRTIO_GPU_VIRGL))) {
-            virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
-                           _("%s 3d acceleration is not supported"),
-                           virDomainVideoTypeToString(video->type));
-            return -1;
-        }
-    }
-
-    return 0;
-}
-
-
 int
 qemuDomainValidateStorageSource(virStorageSourcePtr src,
                                 virQEMUCapsPtr qemuCaps)
@@ -7073,7 +6977,7 @@ qemuDomainDeviceDefValidate(const virDomainDeviceDef *dev,
         break;
 
     case VIR_DOMAIN_DEVICE_VIDEO:
-        ret = qemuDomainDeviceDefValidateVideo(dev->data.video, qemuCaps);
+        ret = qemuValidateDomainDeviceDefVideo(dev->data.video, qemuCaps);
         break;
 
     case VIR_DOMAIN_DEVICE_DISK:
diff --git a/src/qemu/qemu_validate.c b/src/qemu/qemu_validate.c
index 62ecca3c84..0caec1fce3 100644
--- a/src/qemu/qemu_validate.c
+++ b/src/qemu/qemu_validate.c
@@ -1719,3 +1719,99 @@ qemuValidateDomainDeviceDefHostdev(const virDomainHostdevDef *hostdev,
 
     return 0;
 }
+
+
+int
+qemuValidateDomainDeviceDefVideo(const virDomainVideoDef *video,
+                                 virQEMUCapsPtr qemuCaps)
+{
+    /* there's no properties to validate for NONE video devices */
+    if (video->type == VIR_DOMAIN_VIDEO_TYPE_NONE)
+        return 0;
+
+    if (!video->primary &&
+        video->type != VIR_DOMAIN_VIDEO_TYPE_QXL &&
+        video->type != VIR_DOMAIN_VIDEO_TYPE_VIRTIO) {
+        virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+                       _("video type '%s' is only valid as primary "
+                         "video device"),
+                       virDomainVideoTypeToString(video->type));
+        return -1;
+    }
+
+    if (video->accel && video->accel->accel2d == VIR_TRISTATE_SWITCH_ON) {
+        virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+                       _("qemu does not support the accel2d setting"));
+        return -1;
+    }
+
+    if (video->type == VIR_DOMAIN_VIDEO_TYPE_QXL) {
+        if (video->vram > (UINT_MAX / 1024)) {
+            virReportError(VIR_ERR_OVERFLOW,
+                           _("value for 'vram' must be less than '%u'"),
+                           UINT_MAX / 1024);
+            return -1;
+        }
+        if (video->ram > (UINT_MAX / 1024)) {
+            virReportError(VIR_ERR_OVERFLOW,
+                           _("value for 'ram' must be less than '%u'"),
+                           UINT_MAX / 1024);
+            return -1;
+        }
+        if (video->vgamem) {
+            if (video->vgamem < 1024) {
+                virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+                               _("value for 'vgamem' must be at least 1 MiB "
+                                 "(1024 KiB)"));
+                return -1;
+            }
+
+            if (video->vgamem != VIR_ROUND_UP_POWER_OF_TWO(video->vgamem)) {
+                virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+                               _("value for 'vgamem' must be power of two"));
+                return -1;
+            }
+        }
+    }
+
+    if (video->type != VIR_DOMAIN_VIDEO_TYPE_VGA &&
+        video->type != VIR_DOMAIN_VIDEO_TYPE_QXL &&
+        video->type != VIR_DOMAIN_VIDEO_TYPE_VIRTIO &&
+        video->type != VIR_DOMAIN_VIDEO_TYPE_BOCHS) {
+        if (video->res) {
+            virReportError(VIR_ERR_XML_ERROR, "%s",
+                           _("model resolution is not supported"));
+            return -1;
+        }
+    }
+
+    if (video->type == VIR_DOMAIN_VIDEO_TYPE_VGA ||
+        video->type == VIR_DOMAIN_VIDEO_TYPE_VMVGA) {
+        if (video->vram && video->vram < 1024) {
+            virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+                           "%s", _("value for 'vram' must be at least "
+                                   "1 MiB (1024 KiB)"));
+            return -1;
+        }
+    }
+
+    if (video->backend == VIR_DOMAIN_VIDEO_BACKEND_TYPE_VHOSTUSER) {
+        if (video->type == VIR_DOMAIN_VIDEO_TYPE_VIRTIO &&
+            !virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE_VHOST_USER_GPU)) {
+            virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+                           _("this QEMU does not support 'vhost-user' video device"));
+            return -1;
+        }
+    } else if (video->accel) {
+        if (video->accel->accel3d == VIR_TRISTATE_SWITCH_ON &&
+            (video->type != VIR_DOMAIN_VIDEO_TYPE_VIRTIO ||
+             !virQEMUCapsGet(qemuCaps, QEMU_CAPS_VIRTIO_GPU_VIRGL))) {
+            virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+                           _("%s 3d acceleration is not supported"),
+                           virDomainVideoTypeToString(video->type));
+            return -1;
+        }
+    }
+
+    return 0;
+}
diff --git a/src/qemu/qemu_validate.h b/src/qemu/qemu_validate.h
index ca1449c27f..387c6ce556 100644
--- a/src/qemu/qemu_validate.h
+++ b/src/qemu/qemu_validate.h
@@ -44,3 +44,5 @@ int qemuValidateDomainWatchdogDef(const virDomainWatchdogDef *dev,
 int qemuValidateDomainDeviceDefHostdev(const virDomainHostdevDef *hostdev,
                                        const virDomainDef *def,
                                        virQEMUCapsPtr qemuCaps);
+int qemuValidateDomainDeviceDefVideo(const virDomainVideoDef *video,
+                                     virQEMUCapsPtr qemuCaps);
-- 
2.25.1





More information about the libvir-list mailing list