[PATCH 11/15] qemu: move qemuDomainDeviceDefValidateGraphics() to qemu_validate.c

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

 



Signed-off-by: Daniel Henrique Barboza <danielhb413@xxxxxxxxx>
---
 src/qemu/qemu_domain.c   | 177 +--------------------------------------
 src/qemu/qemu_validate.c | 175 ++++++++++++++++++++++++++++++++++++++
 src/qemu/qemu_validate.h |   5 ++
 3 files changed, 181 insertions(+), 176 deletions(-)

diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index 522edb8274..ca9e642632 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -5521,181 +5521,6 @@ qemuDomainDeviceDefValidateTPM(virDomainTPMDef *tpm,
 }
 
 
-static int
-qemuDomainDeviceDefValidateSPICEGraphics(const virDomainGraphicsDef *graphics,
-                                         virQEMUDriverPtr driver,
-                                         virQEMUCapsPtr qemuCaps)
-{
-    g_autoptr(virQEMUDriverConfig) cfg = virQEMUDriverGetConfig(driver);
-    virDomainGraphicsListenDefPtr glisten = NULL;
-    int tlsPort = graphics->data.spice.tlsPort;
-
-    if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_SPICE)) {
-        virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
-                       _("spice graphics are not supported with this QEMU"));
-        return -1;
-    }
-
-    glisten = virDomainGraphicsGetListen((virDomainGraphicsDefPtr)graphics, 0);
-    if (!glisten) {
-        virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
-                       _("missing listen element"));
-        return -1;
-    }
-
-    switch (glisten->type) {
-    case VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_SOCKET:
-        if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_SPICE_UNIX)) {
-            virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
-                           _("unix socket for spice graphics are not supported "
-                             "with this QEMU"));
-            return -1;
-        }
-        break;
-
-    case VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_ADDRESS:
-    case VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_NETWORK:
-        if (tlsPort > 0 && !cfg->spiceTLS) {
-            virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
-                           _("spice TLS port set in XML configuration, "
-                             "but TLS is disabled in qemu.conf"));
-            return -1;
-        }
-        break;
-
-    case VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_NONE:
-        break;
-    case VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_LAST:
-        break;
-    }
-
-    if (graphics->data.spice.filetransfer == VIR_TRISTATE_BOOL_NO &&
-        !virQEMUCapsGet(qemuCaps, QEMU_CAPS_SPICE_FILE_XFER_DISABLE)) {
-            virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
-                           _("This QEMU can't disable file transfers through spice"));
-            return -1;
-    }
-
-    if (graphics->data.spice.gl == VIR_TRISTATE_BOOL_YES) {
-        if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_SPICE_GL)) {
-            virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
-                           _("This QEMU doesn't support spice OpenGL"));
-            return -1;
-        }
-
-        if (graphics->data.spice.rendernode &&
-            !virQEMUCapsGet(qemuCaps, QEMU_CAPS_SPICE_RENDERNODE)) {
-            virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
-                           _("This QEMU doesn't support spice OpenGL rendernode"));
-            return -1;
-        }
-    }
-
-    return 0;
-}
-
-
-static int
-qemuDomainDeviceDefValidateGraphics(const virDomainGraphicsDef *graphics,
-                                    const virDomainDef *def,
-                                    virQEMUDriverPtr driver,
-                                    virQEMUCapsPtr qemuCaps)
-{
-    bool have_egl_headless = false;
-    size_t i;
-
-    for (i = 0; i < def->ngraphics; i++) {
-        if (def->graphics[i]->type == VIR_DOMAIN_GRAPHICS_TYPE_EGL_HEADLESS) {
-            have_egl_headless = true;
-            break;
-        }
-    }
-
-    /* Only VNC and SPICE can be paired with egl-headless, the other types
-     * either don't make sense to pair with egl-headless or aren't even
-     * supported by QEMU.
-     */
-    if (have_egl_headless) {
-        if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_EGL_HEADLESS)) {
-            virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
-                           _("egl-headless display is not supported with this "
-                             "QEMU binary"));
-            return -1;
-        }
-
-        if (graphics->type != VIR_DOMAIN_GRAPHICS_TYPE_EGL_HEADLESS &&
-            graphics->type != VIR_DOMAIN_GRAPHICS_TYPE_VNC &&
-            graphics->type != VIR_DOMAIN_GRAPHICS_TYPE_SPICE) {
-            virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
-                           _("graphics type 'egl-headless' is only supported "
-                             "with one of: 'vnc', 'spice' graphics types"));
-            return -1;
-        }
-
-        /* '-spice gl=on' and '-display egl-headless' are mutually
-         * exclusive
-         */
-        if (graphics->type == VIR_DOMAIN_GRAPHICS_TYPE_SPICE &&
-            graphics->data.spice.gl == VIR_TRISTATE_BOOL_YES) {
-            virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
-                           _("multiple OpenGL displays are not supported "
-                             "by QEMU"));
-            return -1;
-        }
-    }
-
-    switch (graphics->type) {
-    case VIR_DOMAIN_GRAPHICS_TYPE_SDL:
-        if (graphics->data.sdl.gl != VIR_TRISTATE_BOOL_ABSENT) {
-            if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_SDL_GL)) {
-                virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
-                               _("OpenGL for SDL is not supported with this QEMU "
-                                 "binary"));
-                return -1;
-            }
-        }
-        break;
-
-    case VIR_DOMAIN_GRAPHICS_TYPE_VNC:
-        if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_VNC)) {
-            virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
-                           _("vnc graphics are not supported with this QEMU"));
-            return -1;
-        }
-        break;
-
-    case VIR_DOMAIN_GRAPHICS_TYPE_SPICE:
-        if (qemuDomainDeviceDefValidateSPICEGraphics(graphics, driver,
-                                                     qemuCaps) < 0)
-            return -1;
-
-        break;
-
-    case VIR_DOMAIN_GRAPHICS_TYPE_EGL_HEADLESS:
-        if (graphics->data.egl_headless.rendernode &&
-            !virQEMUCapsGet(qemuCaps, QEMU_CAPS_EGL_HEADLESS_RENDERNODE)) {
-            virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
-                           _("This QEMU doesn't support OpenGL rendernode "
-                             "with egl-headless graphics type"));
-            return -1;
-        }
-
-        break;
-    case VIR_DOMAIN_GRAPHICS_TYPE_RDP:
-    case VIR_DOMAIN_GRAPHICS_TYPE_DESKTOP:
-        virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
-                       _("unsupported graphics type '%s'"),
-                       virDomainGraphicsTypeToString(graphics->type));
-        return -1;
-    case VIR_DOMAIN_GRAPHICS_TYPE_LAST:
-    default:
-        return -1;
-    }
-
-    return 0;
-}
-
-
 static int
 qemuDomainDeviceDefValidateInput(const virDomainInputDef *input,
                                  const virDomainDef *def,
@@ -6098,7 +5923,7 @@ qemuDomainDeviceDefValidate(const virDomainDeviceDef *dev,
         break;
 
     case VIR_DOMAIN_DEVICE_GRAPHICS:
-        ret = qemuDomainDeviceDefValidateGraphics(dev->data.graphics, def,
+        ret = qemuValidateDomainDeviceDefGraphics(dev->data.graphics, def,
                                                   driver, qemuCaps);
         break;
 
diff --git a/src/qemu/qemu_validate.c b/src/qemu/qemu_validate.c
index f8228f3491..5438431e93 100644
--- a/src/qemu/qemu_validate.c
+++ b/src/qemu/qemu_validate.c
@@ -2718,3 +2718,178 @@ qemuValidateDomainDeviceDefController(const virDomainControllerDef *controller,
 
     return ret;
 }
+
+
+static int
+qemuValidateDomainDeviceDefSPICEGraphics(const virDomainGraphicsDef *graphics,
+                                         virQEMUDriverPtr driver,
+                                         virQEMUCapsPtr qemuCaps)
+{
+    g_autoptr(virQEMUDriverConfig) cfg = virQEMUDriverGetConfig(driver);
+    virDomainGraphicsListenDefPtr glisten = NULL;
+    int tlsPort = graphics->data.spice.tlsPort;
+
+    if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_SPICE)) {
+        virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+                       _("spice graphics are not supported with this QEMU"));
+        return -1;
+    }
+
+    glisten = virDomainGraphicsGetListen((virDomainGraphicsDefPtr)graphics, 0);
+    if (!glisten) {
+        virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+                       _("missing listen element"));
+        return -1;
+    }
+
+    switch (glisten->type) {
+    case VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_SOCKET:
+        if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_SPICE_UNIX)) {
+            virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+                           _("unix socket for spice graphics are not supported "
+                             "with this QEMU"));
+            return -1;
+        }
+        break;
+
+    case VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_ADDRESS:
+    case VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_NETWORK:
+        if (tlsPort > 0 && !cfg->spiceTLS) {
+            virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+                           _("spice TLS port set in XML configuration, "
+                             "but TLS is disabled in qemu.conf"));
+            return -1;
+        }
+        break;
+
+    case VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_NONE:
+        break;
+    case VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_LAST:
+        break;
+    }
+
+    if (graphics->data.spice.filetransfer == VIR_TRISTATE_BOOL_NO &&
+        !virQEMUCapsGet(qemuCaps, QEMU_CAPS_SPICE_FILE_XFER_DISABLE)) {
+            virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+                           _("This QEMU can't disable file transfers through spice"));
+            return -1;
+    }
+
+    if (graphics->data.spice.gl == VIR_TRISTATE_BOOL_YES) {
+        if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_SPICE_GL)) {
+            virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+                           _("This QEMU doesn't support spice OpenGL"));
+            return -1;
+        }
+
+        if (graphics->data.spice.rendernode &&
+            !virQEMUCapsGet(qemuCaps, QEMU_CAPS_SPICE_RENDERNODE)) {
+            virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+                           _("This QEMU doesn't support spice OpenGL rendernode"));
+            return -1;
+        }
+    }
+
+    return 0;
+}
+
+
+int
+qemuValidateDomainDeviceDefGraphics(const virDomainGraphicsDef *graphics,
+                                    const virDomainDef *def,
+                                    virQEMUDriverPtr driver,
+                                    virQEMUCapsPtr qemuCaps)
+{
+    bool have_egl_headless = false;
+    size_t i;
+
+    for (i = 0; i < def->ngraphics; i++) {
+        if (def->graphics[i]->type == VIR_DOMAIN_GRAPHICS_TYPE_EGL_HEADLESS) {
+            have_egl_headless = true;
+            break;
+        }
+    }
+
+    /* Only VNC and SPICE can be paired with egl-headless, the other types
+     * either don't make sense to pair with egl-headless or aren't even
+     * supported by QEMU.
+     */
+    if (have_egl_headless) {
+        if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_EGL_HEADLESS)) {
+            virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+                           _("egl-headless display is not supported with this "
+                             "QEMU binary"));
+            return -1;
+        }
+
+        if (graphics->type != VIR_DOMAIN_GRAPHICS_TYPE_EGL_HEADLESS &&
+            graphics->type != VIR_DOMAIN_GRAPHICS_TYPE_VNC &&
+            graphics->type != VIR_DOMAIN_GRAPHICS_TYPE_SPICE) {
+            virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+                           _("graphics type 'egl-headless' is only supported "
+                             "with one of: 'vnc', 'spice' graphics types"));
+            return -1;
+        }
+
+        /* '-spice gl=on' and '-display egl-headless' are mutually
+         * exclusive
+         */
+        if (graphics->type == VIR_DOMAIN_GRAPHICS_TYPE_SPICE &&
+            graphics->data.spice.gl == VIR_TRISTATE_BOOL_YES) {
+            virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+                           _("multiple OpenGL displays are not supported "
+                             "by QEMU"));
+            return -1;
+        }
+    }
+
+    switch (graphics->type) {
+    case VIR_DOMAIN_GRAPHICS_TYPE_SDL:
+        if (graphics->data.sdl.gl != VIR_TRISTATE_BOOL_ABSENT) {
+            if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_SDL_GL)) {
+                virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+                               _("OpenGL for SDL is not supported with this QEMU "
+                                 "binary"));
+                return -1;
+            }
+        }
+        break;
+
+    case VIR_DOMAIN_GRAPHICS_TYPE_VNC:
+        if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_VNC)) {
+            virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+                           _("vnc graphics are not supported with this QEMU"));
+            return -1;
+        }
+        break;
+
+    case VIR_DOMAIN_GRAPHICS_TYPE_SPICE:
+        if (qemuValidateDomainDeviceDefSPICEGraphics(graphics, driver,
+                                                     qemuCaps) < 0)
+            return -1;
+
+        break;
+
+    case VIR_DOMAIN_GRAPHICS_TYPE_EGL_HEADLESS:
+        if (graphics->data.egl_headless.rendernode &&
+            !virQEMUCapsGet(qemuCaps, QEMU_CAPS_EGL_HEADLESS_RENDERNODE)) {
+            virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+                           _("This QEMU doesn't support OpenGL rendernode "
+                             "with egl-headless graphics type"));
+            return -1;
+        }
+
+        break;
+    case VIR_DOMAIN_GRAPHICS_TYPE_RDP:
+    case VIR_DOMAIN_GRAPHICS_TYPE_DESKTOP:
+        virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+                       _("unsupported graphics type '%s'"),
+                       virDomainGraphicsTypeToString(graphics->type));
+        return -1;
+    case VIR_DOMAIN_GRAPHICS_TYPE_LAST:
+    default:
+        return -1;
+    }
+
+    return 0;
+}
diff --git a/src/qemu/qemu_validate.h b/src/qemu/qemu_validate.h
index 85efa9354f..3b34cd55a2 100644
--- a/src/qemu/qemu_validate.h
+++ b/src/qemu/qemu_validate.h
@@ -24,6 +24,7 @@
 
 #include "domain_conf.h"
 #include "qemu_capabilities.h"
+#include "qemu_conf.h"
 
 int qemuValidateDomainDef(const virDomainDef *def, void *opaque);
 int qemuValidateDomainDeviceDefDisk(const virDomainDiskDef *disk,
@@ -51,3 +52,7 @@ int qemuValidateDomainDeviceDefVideo(const virDomainVideoDef *video,
 int qemuValidateDomainDeviceDefController(const virDomainControllerDef *controller,
                                           const virDomainDef *def,
                                           virQEMUCapsPtr qemuCaps);
+int qemuValidateDomainDeviceDefGraphics(const virDomainGraphicsDef *graphics,
+                                        const virDomainDef *def,
+                                        virQEMUDriverPtr driver,
+                                        virQEMUCapsPtr qemuCaps);
-- 
2.25.1






[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