mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-03-20 07:59:00 +00:00
qemu: move qemuDomainDeviceDefValidateGraphics() to qemu_validate.c
Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com> Reviewed-by: Ján Tomko <jtomko@redhat.com> Signed-off-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
parent
4d3d025ecb
commit
3b4e054c3d
@ -5530,181 +5530,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,
|
||||
@ -6107,7 +5932,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;
|
||||
|
||||
|
@ -2719,3 +2719,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;
|
||||
}
|
||||
|
@ -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);
|
||||
|
Loading…
x
Reference in New Issue
Block a user