From: Marc-André Lureau <marcandre.lureau@xxxxxxxxxx> By default, libvirt will start a private bus and tell QEMU to connect to it. Instead, a D-Bus "address" to connect to can be specified, or the p2p mode enabled. D-Bus display works best with GL & a rendernode, which can be specified with <gl> child element. Signed-off-by: Marc-André Lureau <marcandre.lureau@xxxxxxxxxx> --- src/qemu/qemu_command.c | 41 ++++++++++++++++++- src/qemu/qemu_driver.c | 4 ++ src/qemu/qemu_process.c | 36 +++++++++++++++- .../graphics-dbus-address.args | 30 ++++++++++++++ tests/qemuxml2argvdata/graphics-dbus-p2p.args | 30 ++++++++++++++ tests/qemuxml2argvdata/graphics-dbus.args | 30 ++++++++++++++ tests/qemuxml2argvtest.c | 7 ++++ 7 files changed, 174 insertions(+), 4 deletions(-) create mode 100644 tests/qemuxml2argvdata/graphics-dbus-address.args create mode 100644 tests/qemuxml2argvdata/graphics-dbus-p2p.args create mode 100644 tests/qemuxml2argvdata/graphics-dbus.args diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index 8a32cb79f922..12197cfdb7b2 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -8578,6 +8578,36 @@ qemuBuildGraphicsEGLHeadlessCommandLine(virQEMUDriverConfig *cfg G_GNUC_UNUSED, } +static int +qemuBuildGraphicsDBusCommandLine(virCommand *cmd, + virDomainGraphicsDef *graphics) +{ + g_auto(virBuffer) opt = VIR_BUFFER_INITIALIZER; + + virBufferAddLit(&opt, "dbus"); + + if (graphics->data.dbus.p2p) { + virBufferAddLit(&opt, ",p2p=on"); + } else { + virBufferAddLit(&opt, ",addr="); + virQEMUBuildBufferEscapeComma(&opt, graphics->data.dbus.address); + } + if (graphics->data.dbus.gl != VIR_TRISTATE_BOOL_ABSENT) + virBufferAsprintf(&opt, ",gl=%s", + virTristateSwitchTypeToString(graphics->data.dbus.gl)); + if (graphics->data.dbus.rendernode) { + virBufferAddLit(&opt, ",rendernode="); + virQEMUBuildBufferEscapeComma(&opt, + graphics->data.dbus.rendernode); + } + + virCommandAddArg(cmd, "-display"); + virCommandAddArgBuffer(cmd, &opt); + + return 0; +} + + static int qemuBuildGraphicsCommandLine(virQEMUDriverConfig *cfg, virCommand *cmd, @@ -8613,7 +8643,11 @@ qemuBuildGraphicsCommandLine(virQEMUDriverConfig *cfg, graphics) < 0) return -1; + break; case VIR_DOMAIN_GRAPHICS_TYPE_DBUS: + if (qemuBuildGraphicsDBusCommandLine(cmd, graphics) < 0) + return -1; + break; case VIR_DOMAIN_GRAPHICS_TYPE_RDP: case VIR_DOMAIN_GRAPHICS_TYPE_DESKTOP: @@ -10210,6 +10244,7 @@ qemuBuildCommandLineValidate(virQEMUDriver *driver, int vnc = 0; int spice = 0; int egl_headless = 0; + int dbus = 0; if (!driver->privileged) { /* If we have no cgroups then we can have no tunings that @@ -10255,6 +10290,8 @@ qemuBuildCommandLineValidate(virQEMUDriver *driver, ++egl_headless; break; case VIR_DOMAIN_GRAPHICS_TYPE_DBUS: + ++dbus; + break; case VIR_DOMAIN_GRAPHICS_TYPE_RDP: case VIR_DOMAIN_GRAPHICS_TYPE_DESKTOP: case VIR_DOMAIN_GRAPHICS_TYPE_LAST: @@ -10262,10 +10299,10 @@ qemuBuildCommandLineValidate(virQEMUDriver *driver, } } - if (sdl > 1 || vnc > 1 || spice > 1 || egl_headless > 1) { + if (sdl > 1 || vnc > 1 || spice > 1 || egl_headless > 1 || dbus > 1) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", _("only 1 graphics device of each type " - "(sdl, vnc, spice, headless) is supported")); + "(sdl, vnc, spice, headless, dbus) is supported")); return -1; } diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 1a73d4392c64..5f186a22beee 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -15681,6 +15681,8 @@ qemuDomainOpenGraphics(virDomainPtr dom, protocol = "spice"; break; case VIR_DOMAIN_GRAPHICS_TYPE_DBUS: + protocol = "@dbus-display"; + break; case VIR_DOMAIN_GRAPHICS_TYPE_SDL: case VIR_DOMAIN_GRAPHICS_TYPE_RDP: case VIR_DOMAIN_GRAPHICS_TYPE_DESKTOP: @@ -15750,6 +15752,8 @@ qemuDomainOpenGraphicsFD(virDomainPtr dom, protocol = "spice"; break; case VIR_DOMAIN_GRAPHICS_TYPE_DBUS: + protocol = "@dbus-display"; + break; case VIR_DOMAIN_GRAPHICS_TYPE_SDL: case VIR_DOMAIN_GRAPHICS_TYPE_RDP: case VIR_DOMAIN_GRAPHICS_TYPE_DESKTOP: diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index fd04849f025f..0bfb17e09790 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -4874,6 +4874,22 @@ qemuProcessGraphicsSetupNetworkAddress(virDomainGraphicsListenDef *glisten, } +static int +qemuProcessGraphicsSetupDBus(virQEMUDriver *driver, + virDomainGraphicsDef *graphics, + virDomainObj *vm) +{ + if (graphics->type != VIR_DOMAIN_GRAPHICS_TYPE_DBUS) + return 0; + + if (!graphics->data.dbus.p2p && !graphics->data.dbus.address) { + graphics->data.dbus.address = qemuDBusGetAddress(driver, vm); + } + + return 0; +} + + static int qemuProcessGraphicsSetupListen(virQEMUDriver *driver, virDomainGraphicsDef *graphics, @@ -4965,16 +4981,29 @@ qemuProcessGraphicsSetupRenderNode(virDomainGraphicsDef *graphics, return 0; /* Don't bother picking a DRM node if QEMU doesn't support it. */ - if (graphics->type == VIR_DOMAIN_GRAPHICS_TYPE_SPICE) { + switch (graphics->type) { + case VIR_DOMAIN_GRAPHICS_TYPE_SPICE: if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_SPICE_RENDERNODE)) return 0; rendernode = &graphics->data.spice.rendernode; - } else { + break; + case VIR_DOMAIN_GRAPHICS_TYPE_EGL_HEADLESS: if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_EGL_HEADLESS_RENDERNODE)) return 0; rendernode = &graphics->data.egl_headless.rendernode; + break; + case VIR_DOMAIN_GRAPHICS_TYPE_DBUS: + rendernode = &graphics->data.dbus.rendernode; + break; + case VIR_DOMAIN_GRAPHICS_TYPE_SDL: + case VIR_DOMAIN_GRAPHICS_TYPE_VNC: + case VIR_DOMAIN_GRAPHICS_TYPE_RDP: + case VIR_DOMAIN_GRAPHICS_TYPE_DESKTOP: + case VIR_DOMAIN_GRAPHICS_TYPE_LAST: + virReportEnumRangeError(virDomainGraphicsType, graphics->type); + break; } if (!(*rendernode = virHostGetDRMRenderNode())) @@ -5002,6 +5031,9 @@ qemuProcessSetupGraphics(virQEMUDriver *driver, if (qemuProcessGraphicsSetupListen(driver, graphics, vm) < 0) return -1; + + if (qemuProcessGraphicsSetupDBus(driver, graphics, vm) < 0) + return -1; } if (allocate) { diff --git a/tests/qemuxml2argvdata/graphics-dbus-address.args b/tests/qemuxml2argvdata/graphics-dbus-address.args new file mode 100644 index 000000000000..5332728a6175 --- /dev/null +++ b/tests/qemuxml2argvdata/graphics-dbus-address.args @@ -0,0 +1,30 @@ +LC_ALL=C \ +PATH=/bin \ +HOME=/tmp/lib/domain--1-QEMUGuest1 \ +USER=test \ +LOGNAME=test \ +XDG_DATA_HOME=/tmp/lib/domain--1-QEMUGuest1/.local/share \ +XDG_CACHE_HOME=/tmp/lib/domain--1-QEMUGuest1/.cache \ +XDG_CONFIG_HOME=/tmp/lib/domain--1-QEMUGuest1/.config \ +/usr/bin/qemu-system-i386 \ +-name guest=QEMUGuest1,debug-threads=on \ +-S \ +-object secret,id=masterKey0,format=raw,file=/tmp/lib/domain--1-QEMUGuest1/master-key.aes \ +-machine pc,usb=off,dump-guest-core=off \ +-accel tcg \ +-m 214 \ +-realtime mlock=off \ +-smp 1,sockets=1,cores=1,threads=1 \ +-uuid c7a5fdbd-edaf-9455-926a-d65c16db1809 \ +-no-user-config \ +-nodefaults \ +-chardev socket,id=charmonitor,path=/tmp/lib/domain--1-QEMUGuest1/monitor.sock,server=on,wait=off \ +-mon chardev=charmonitor,id=monitor,mode=control \ +-rtc base=utc \ +-no-shutdown \ +-no-acpi \ +-boot strict=on \ +-usb \ +-display dbus,addr=unix:path=/tmp/foo,gl=on,rendernode=/dev/dri/foo \ +-device cirrus-vga,id=video0,bus=pci.0,addr=0x2 \ +-msg timestamp=on diff --git a/tests/qemuxml2argvdata/graphics-dbus-p2p.args b/tests/qemuxml2argvdata/graphics-dbus-p2p.args new file mode 100644 index 000000000000..e90a0eeeea4d --- /dev/null +++ b/tests/qemuxml2argvdata/graphics-dbus-p2p.args @@ -0,0 +1,30 @@ +LC_ALL=C \ +PATH=/bin \ +HOME=/tmp/lib/domain--1-QEMUGuest1 \ +USER=test \ +LOGNAME=test \ +XDG_DATA_HOME=/tmp/lib/domain--1-QEMUGuest1/.local/share \ +XDG_CACHE_HOME=/tmp/lib/domain--1-QEMUGuest1/.cache \ +XDG_CONFIG_HOME=/tmp/lib/domain--1-QEMUGuest1/.config \ +/usr/bin/qemu-system-i386 \ +-name guest=QEMUGuest1,debug-threads=on \ +-S \ +-object secret,id=masterKey0,format=raw,file=/tmp/lib/domain--1-QEMUGuest1/master-key.aes \ +-machine pc,usb=off,dump-guest-core=off \ +-accel tcg \ +-m 214 \ +-realtime mlock=off \ +-smp 1,sockets=1,cores=1,threads=1 \ +-uuid c7a5fdbd-edaf-9455-926a-d65c16db1809 \ +-no-user-config \ +-nodefaults \ +-chardev socket,id=charmonitor,path=/tmp/lib/domain--1-QEMUGuest1/monitor.sock,server=on,wait=off \ +-mon chardev=charmonitor,id=monitor,mode=control \ +-rtc base=utc \ +-no-shutdown \ +-no-acpi \ +-boot strict=on \ +-usb \ +-display dbus,p2p=on \ +-device cirrus-vga,id=video0,bus=pci.0,addr=0x2 \ +-msg timestamp=on diff --git a/tests/qemuxml2argvdata/graphics-dbus.args b/tests/qemuxml2argvdata/graphics-dbus.args new file mode 100644 index 000000000000..80ab9ed7b477 --- /dev/null +++ b/tests/qemuxml2argvdata/graphics-dbus.args @@ -0,0 +1,30 @@ +LC_ALL=C \ +PATH=/bin \ +HOME=/tmp/lib/domain--1-QEMUGuest1 \ +USER=test \ +LOGNAME=test \ +XDG_DATA_HOME=/tmp/lib/domain--1-QEMUGuest1/.local/share \ +XDG_CACHE_HOME=/tmp/lib/domain--1-QEMUGuest1/.cache \ +XDG_CONFIG_HOME=/tmp/lib/domain--1-QEMUGuest1/.config \ +/usr/bin/qemu-system-i386 \ +-name guest=QEMUGuest1,debug-threads=on \ +-S \ +-object secret,id=masterKey0,format=raw,file=/tmp/lib/domain--1-QEMUGuest1/master-key.aes \ +-machine pc,usb=off,dump-guest-core=off \ +-accel tcg \ +-m 214 \ +-realtime mlock=off \ +-smp 1,sockets=1,cores=1,threads=1 \ +-uuid c7a5fdbd-edaf-9455-926a-d65c16db1809 \ +-no-user-config \ +-nodefaults \ +-chardev socket,id=charmonitor,path=/tmp/lib/domain--1-QEMUGuest1/monitor.sock,server=on,wait=off \ +-mon chardev=charmonitor,id=monitor,mode=control \ +-rtc base=utc \ +-no-shutdown \ +-no-acpi \ +-boot strict=on \ +-usb \ +-display dbus,addr=unix:path=/bad-test-used-env-xdg-runtime-dir/libvirt/qemu/run/dbus/-1-QEMUGuest1-dbus.sock \ +-device cirrus-vga,id=video0,bus=pci.0,addr=0x2 \ +-msg timestamp=on diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c index 6c67b36d5c8e..68f1ac9fdbb7 100644 --- a/tests/qemuxml2argvtest.c +++ b/tests/qemuxml2argvtest.c @@ -1602,6 +1602,13 @@ mymain(void) DO_TEST_CAPS_LATEST_PARSE_ERROR("graphics-spice-invalid-egl-headless"); DO_TEST_CAPS_LATEST("graphics-spice-gl-auto-rendernode"); + DO_TEST("graphics-dbus", + QEMU_CAPS_DEVICE_CIRRUS_VGA, QEMU_CAPS_DISPLAY_DBUS); + DO_TEST("graphics-dbus-address", + QEMU_CAPS_DEVICE_CIRRUS_VGA, QEMU_CAPS_DISPLAY_DBUS); + DO_TEST("graphics-dbus-p2p", + QEMU_CAPS_DEVICE_CIRRUS_VGA, QEMU_CAPS_DISPLAY_DBUS); + DO_TEST_NOCAPS("input-usbmouse"); DO_TEST_NOCAPS("input-usbtablet"); DO_TEST_NOCAPS("misc-acpi"); -- 2.34.1.8.g35151cf07204