From 11219f42da3b15bd76b9215fda9d23d5435a1d3b Mon Sep 17 00:00:00 2001 Message-Id: <11219f42da3b15bd76b9215fda9d23d5435a1d3b@dist-git> From: Erik Skultety Date: Thu, 19 Jul 2018 15:03:58 +0200 Subject: [PATCH] qemu: Introduce a new graphics display type 'headless' MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Since 2.10 QEMU supports a new display type egl-headless which uses the drm nodes for OpenGL rendering copying back the rendered bits back to QEMU into a dma-buf which can be accessed by standard "display" apps like VNC or SPICE. Although this display type can be used on its own, for any practical use case it makes sense to pair it with either VNC or SPICE display. The clear benefit of this display is that VNC gains OpenGL support, which it natively doesn't have, and SPICE gains remote OpenGL support (native OpenGL support only works locally through a UNIX socket, i.e. listen type=socket/none). Reviewed-by: Ján Tomko Signed-off-by: Erik Skultety (cherry picked from commit d8266ebe1615c4b043db6b8d486465722cdd0ef8) https://bugzilla.redhat.com/show_bug.cgi?id=1475770 Signed-off-by: Erik Skultety Reviewed-by: Ján Tomko --- docs/formatdomain.html.in | 33 +++++++++- docs/schemas/domaincommon.rng | 3 + src/conf/domain_conf.c | 6 +- src/conf/domain_conf.h | 1 + src/libxl/libxl_conf.c | 1 + src/qemu/qemu_command.c | 14 ++++- src/qemu/qemu_domain.c | 60 ++++++++++++++++++- src/qemu/qemu_driver.c | 2 + src/qemu/qemu_hotplug.c | 1 + src/qemu/qemu_process.c | 4 ++ src/vmx/vmx.c | 1 + tests/domaincapsschemadata/full.xml | 1 + .../graphics-egl-headless.args | 26 ++++++++ .../graphics-egl-headless.xml | 31 ++++++++++ .../graphics-sdl-egl-headless.xml | 35 +++++++++++ .../graphics-spice-egl-headless.args | 31 ++++++++++ .../graphics-spice-egl-headless.xml | 36 +++++++++++ .../graphics-spice-invalid-egl-headless.xml | 37 ++++++++++++ .../graphics-vnc-egl-headless.args | 28 +++++++++ .../graphics-vnc-egl-headless.xml | 37 ++++++++++++ tests/qemuxml2argvtest.c | 17 ++++++ .../graphics-spice-egl-headless.xml | 44 ++++++++++++++ .../graphics-vnc-egl-headless.xml | 42 +++++++++++++ tests/qemuxml2xmltest.c | 2 + 24 files changed, 488 insertions(+), 5 deletions(-) create mode 100644 tests/qemuxml2argvdata/graphics-egl-headless.args create mode 100644 tests/qemuxml2argvdata/graphics-egl-headless.xml create mode 100644 tests/qemuxml2argvdata/graphics-sdl-egl-headless.xml create mode 100644 tests/qemuxml2argvdata/graphics-spice-egl-headless.args create mode 100644 tests/qemuxml2argvdata/graphics-spice-egl-headless.xml create mode 100644 tests/qemuxml2argvdata/graphics-spice-invalid-egl-headless.xml create mode 100644 tests/qemuxml2argvdata/graphics-vnc-egl-headless.args create mode 100644 tests/qemuxml2argvdata/graphics-vnc-egl-headless.xml create mode 100644 tests/qemuxml2xmloutdata/graphics-spice-egl-headless.xml create mode 100644 tests/qemuxml2xmloutdata/graphics-vnc-egl-headless.xml diff --git a/docs/formatdomain.html.in b/docs/formatdomain.html.in index a3afe137bf..9dd22554ad 100644 --- a/docs/formatdomain.html.in +++ b/docs/formatdomain.html.in @@ -6299,7 +6299,8 @@ qemu-kvm -net nic,model=? /dev/null

The graphics element has a mandatory type attribute which takes the value sdl, vnc, - spice, rdp or desktop: + spice, rdp, desktop or + egl-headless:

sdl
@@ -6358,6 +6359,11 @@ qemu-kvm -net nic,model=? /dev/null auto-allocation and autoport having no effect due to security reasons) Since 1.0.6.

+

+ Although VNC doesn't support OpenGL natively, it can be paired + with graphics type egl-headless (see below) which + will instruct QEMU to open and use drm nodes for OpenGL rendering. +

spice Since 0.8.6
@@ -6463,6 +6469,12 @@ qemu-kvm -net nic,model=? /dev/null You can enable or disable OpenGL support explicitly with the gl element, by setting the enable property. (QEMU only, since 1.3.3). + Note that this only works locally, since this requires usage of + UNIX sockets, i.e. using listen types 'socket' or + 'none'. For accelerated OpenGL with remote support, consider + pairing this element with type egl-headless + (see below). However, this will deliver weaker performance + compared to native Spice OpenGL support.

By default, QEMU will pick the first available GPU DRM render node. @@ -6498,6 +6510,25 @@ qemu-kvm -net nic,model=? /dev/null fullscreen.

+
egl-headlessSince 4.6.0
+
+

+ This display type provides support for an OpenGL accelerated + display accessible both locally and remotely (for comparison, + Spice's native OpenGL support only works locally using UNIX + sockets at the moment, but has better performance). Since this + display type doesn't provide any window or graphical console like + the other types, for practical reasons it should be paired with + either vnc or spice graphics types. + This display type is only supported by QEMU domains + (needs QEMU 2.10 or newer) and doesn't + accept any attributes. +

+
+<graphics type='spice' autoport='yes'/>
+<graphics type='egl-headless'/>
+            
+
diff --git a/docs/schemas/domaincommon.rng b/docs/schemas/domaincommon.rng index f24a56392a..157726752c 100644 --- a/docs/schemas/domaincommon.rng +++ b/docs/schemas/domaincommon.rng @@ -3366,6 +3366,9 @@ + + egl-headless + diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index db8e17dac4..fa4dfafcff 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -615,7 +615,8 @@ VIR_ENUM_IMPL(virDomainGraphics, VIR_DOMAIN_GRAPHICS_TYPE_LAST, "vnc", "rdp", "desktop", - "spice") + "spice", + "egl-headless") VIR_ENUM_IMPL(virDomainGraphicsListen, VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_LAST, "none", @@ -1426,6 +1427,7 @@ void virDomainGraphicsDefFree(virDomainGraphicsDefPtr def) virDomainGraphicsAuthDefClear(&def->data.spice.auth); break; + case VIR_DOMAIN_GRAPHICS_TYPE_EGL_HEADLESS: case VIR_DOMAIN_GRAPHICS_TYPE_LAST: break; } @@ -14172,6 +14174,7 @@ virDomainGraphicsDefParseXML(xmlNodePtr node, if (virDomainGraphicsDefParseXMLSpice(def, node, ctxt, flags) < 0) goto error; break; + case VIR_DOMAIN_GRAPHICS_TYPE_EGL_HEADLESS: case VIR_DOMAIN_GRAPHICS_TYPE_LAST: break; } @@ -26404,6 +26407,7 @@ virDomainGraphicsDefFormat(virBufferPtr buf, virDomainGraphicsAuthDefFormatAttr(buf, &def->data.spice.auth, flags); break; + case VIR_DOMAIN_GRAPHICS_TYPE_EGL_HEADLESS: case VIR_DOMAIN_GRAPHICS_TYPE_LAST: break; } diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index 0f10e242fd..26f75b15d0 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -1473,6 +1473,7 @@ typedef enum { VIR_DOMAIN_GRAPHICS_TYPE_RDP, VIR_DOMAIN_GRAPHICS_TYPE_DESKTOP, VIR_DOMAIN_GRAPHICS_TYPE_SPICE, + VIR_DOMAIN_GRAPHICS_TYPE_EGL_HEADLESS, VIR_DOMAIN_GRAPHICS_TYPE_LAST } virDomainGraphicsType; diff --git a/src/libxl/libxl_conf.c b/src/libxl/libxl_conf.c index 452a77f3b8..cda4eb9d31 100644 --- a/src/libxl/libxl_conf.c +++ b/src/libxl/libxl_conf.c @@ -1441,6 +1441,7 @@ libxlMakeVfb(virPortAllocatorRangePtr graphicsports, case VIR_DOMAIN_GRAPHICS_TYPE_RDP: case VIR_DOMAIN_GRAPHICS_TYPE_DESKTOP: case VIR_DOMAIN_GRAPHICS_TYPE_SPICE: + case VIR_DOMAIN_GRAPHICS_TYPE_EGL_HEADLESS: case VIR_DOMAIN_GRAPHICS_TYPE_LAST: break; } diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index fed4f8faf9..8915040c6a 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -8212,6 +8212,7 @@ qemuBuildGraphicsSPICECommandLine(virQEMUDriverConfigPtr cfg, return -1; } + static int qemuBuildGraphicsCommandLine(virQEMUDriverConfigPtr cfg, virCommandPtr cmd, @@ -8241,6 +8242,11 @@ qemuBuildGraphicsCommandLine(virQEMUDriverConfigPtr cfg, qemuCaps, graphics) < 0) return -1; + break; + case VIR_DOMAIN_GRAPHICS_TYPE_EGL_HEADLESS: + virCommandAddArg(cmd, "-display"); + virCommandAddArg(cmd, "egl-headless"); + break; case VIR_DOMAIN_GRAPHICS_TYPE_RDP: case VIR_DOMAIN_GRAPHICS_TYPE_DESKTOP: @@ -10068,6 +10074,7 @@ qemuBuildCommandLineValidate(virQEMUDriverPtr driver, int sdl = 0; int vnc = 0; int spice = 0; + int egl_headless = 0; if (!virQEMUDriverIsPrivileged(driver)) { /* If we have no cgroups then we can have no tunings that @@ -10109,6 +10116,9 @@ qemuBuildCommandLineValidate(virQEMUDriverPtr driver, case VIR_DOMAIN_GRAPHICS_TYPE_SPICE: ++spice; break; + case VIR_DOMAIN_GRAPHICS_TYPE_EGL_HEADLESS: + ++egl_headless; + break; case VIR_DOMAIN_GRAPHICS_TYPE_RDP: case VIR_DOMAIN_GRAPHICS_TYPE_DESKTOP: case VIR_DOMAIN_GRAPHICS_TYPE_LAST: @@ -10116,10 +10126,10 @@ qemuBuildCommandLineValidate(virQEMUDriverPtr driver, } } - if (sdl > 1 || vnc > 1 || spice > 1) { + if (sdl > 1 || vnc > 1 || spice > 1 || egl_headless > 1) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", _("only 1 graphics device of each type " - "(sdl, vnc, spice) is supported")); + "(sdl, vnc, spice, headless) is supported")); return -1; } diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index a42a6df91b..9498594857 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -5502,6 +5502,60 @@ qemuDomainDeviceDefValidateTPM(virDomainTPMDef *tpm, } +static int +qemuDomainDeviceDefValidateGraphics(const virDomainGraphicsDef *graphics, + const virDomainDef *def, + virQEMUCapsPtr qemuCaps) +{ + bool have_egl_headless = false; + size_t i; + + for (i = 0; i < def->ngraphics; i++) { + graphics = def->graphics[i]; + + if (graphics->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; + } + } + + return 0; +} + + static int qemuDomainDeviceDefValidate(const virDomainDeviceDef *dev, const virDomainDef *def, @@ -5569,11 +5623,15 @@ qemuDomainDeviceDefValidate(const virDomainDeviceDef *dev, ret = qemuDomainDeviceDefValidateTPM(dev->data.tpm, def); break; + case VIR_DOMAIN_DEVICE_GRAPHICS: + ret = qemuDomainDeviceDefValidateGraphics(dev->data.graphics, def, + qemuCaps); + break; + case VIR_DOMAIN_DEVICE_LEASE: case VIR_DOMAIN_DEVICE_FS: case VIR_DOMAIN_DEVICE_INPUT: case VIR_DOMAIN_DEVICE_SOUND: - case VIR_DOMAIN_DEVICE_GRAPHICS: case VIR_DOMAIN_DEVICE_HUB: case VIR_DOMAIN_DEVICE_MEMBALLOON: case VIR_DOMAIN_DEVICE_NVRAM: diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 7094c80498..62deae4b98 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -18116,6 +18116,7 @@ qemuDomainOpenGraphics(virDomainPtr dom, case VIR_DOMAIN_GRAPHICS_TYPE_SDL: case VIR_DOMAIN_GRAPHICS_TYPE_RDP: case VIR_DOMAIN_GRAPHICS_TYPE_DESKTOP: + case VIR_DOMAIN_GRAPHICS_TYPE_EGL_HEADLESS: virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("Can only open VNC or SPICE graphics backends, not %s"), virDomainGraphicsTypeToString(vm->def->graphics[idx]->type)); @@ -18184,6 +18185,7 @@ qemuDomainOpenGraphicsFD(virDomainPtr dom, case VIR_DOMAIN_GRAPHICS_TYPE_SDL: case VIR_DOMAIN_GRAPHICS_TYPE_RDP: case VIR_DOMAIN_GRAPHICS_TYPE_DESKTOP: + case VIR_DOMAIN_GRAPHICS_TYPE_EGL_HEADLESS: virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("Can only open VNC or SPICE graphics backends, not %s"), virDomainGraphicsTypeToString(vm->def->graphics[idx]->type)); diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c index 91a751a2fe..053ddb14ec 100644 --- a/src/qemu/qemu_hotplug.c +++ b/src/qemu/qemu_hotplug.c @@ -3699,6 +3699,7 @@ qemuDomainChangeGraphics(virQEMUDriverPtr driver, case VIR_DOMAIN_GRAPHICS_TYPE_SDL: case VIR_DOMAIN_GRAPHICS_TYPE_RDP: case VIR_DOMAIN_GRAPHICS_TYPE_DESKTOP: + case VIR_DOMAIN_GRAPHICS_TYPE_EGL_HEADLESS: virReportError(VIR_ERR_INTERNAL_ERROR, _("unable to change config on '%s' graphics type"), type); break; diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index c903a8e5c8..a4b1f97df5 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -4467,6 +4467,7 @@ qemuProcessGraphicsReservePorts(virDomainGraphicsDefPtr graphics, case VIR_DOMAIN_GRAPHICS_TYPE_SDL: case VIR_DOMAIN_GRAPHICS_TYPE_RDP: case VIR_DOMAIN_GRAPHICS_TYPE_DESKTOP: + case VIR_DOMAIN_GRAPHICS_TYPE_EGL_HEADLESS: case VIR_DOMAIN_GRAPHICS_TYPE_LAST: break; } @@ -4505,6 +4506,7 @@ qemuProcessGraphicsAllocatePorts(virQEMUDriverPtr driver, case VIR_DOMAIN_GRAPHICS_TYPE_SDL: case VIR_DOMAIN_GRAPHICS_TYPE_RDP: case VIR_DOMAIN_GRAPHICS_TYPE_DESKTOP: + case VIR_DOMAIN_GRAPHICS_TYPE_EGL_HEADLESS: case VIR_DOMAIN_GRAPHICS_TYPE_LAST: break; } @@ -4657,6 +4659,7 @@ qemuProcessGraphicsSetupListen(virQEMUDriverPtr driver, case VIR_DOMAIN_GRAPHICS_TYPE_SDL: case VIR_DOMAIN_GRAPHICS_TYPE_RDP: case VIR_DOMAIN_GRAPHICS_TYPE_DESKTOP: + case VIR_DOMAIN_GRAPHICS_TYPE_EGL_HEADLESS: case VIR_DOMAIN_GRAPHICS_TYPE_LAST: break; } @@ -4944,6 +4947,7 @@ qemuProcessStartValidateGraphics(virDomainObjPtr vm) case VIR_DOMAIN_GRAPHICS_TYPE_SDL: case VIR_DOMAIN_GRAPHICS_TYPE_RDP: case VIR_DOMAIN_GRAPHICS_TYPE_DESKTOP: + case VIR_DOMAIN_GRAPHICS_TYPE_EGL_HEADLESS: case VIR_DOMAIN_GRAPHICS_TYPE_LAST: break; } diff --git a/src/vmx/vmx.c b/src/vmx/vmx.c index fe24b060d7..937bf0c96b 100644 --- a/src/vmx/vmx.c +++ b/src/vmx/vmx.c @@ -3282,6 +3282,7 @@ virVMXFormatConfig(virVMXContext *ctx, virDomainXMLOptionPtr xmlopt, virDomainDe case VIR_DOMAIN_GRAPHICS_TYPE_RDP: case VIR_DOMAIN_GRAPHICS_TYPE_DESKTOP: case VIR_DOMAIN_GRAPHICS_TYPE_SPICE: + case VIR_DOMAIN_GRAPHICS_TYPE_EGL_HEADLESS: virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("Unsupported graphics type '%s'"), virDomainGraphicsTypeToString(def->graphics[i]->type)); diff --git a/tests/domaincapsschemadata/full.xml b/tests/domaincapsschemadata/full.xml index d3faf38da0..154c4a6fe9 100644 --- a/tests/domaincapsschemadata/full.xml +++ b/tests/domaincapsschemadata/full.xml @@ -59,6 +59,7 @@ rdp desktop spice + egl-headless