mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-23 21:34:54 +03:00
qemu: add -display dbus support
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@redhat.com> Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
parent
5c1e203a80
commit
bde66322e8
@ -8556,6 +8556,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,
|
||||
@ -8591,7 +8621,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:
|
||||
@ -10147,6 +10181,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
|
||||
@ -10192,6 +10227,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:
|
||||
@ -10199,10 +10236,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;
|
||||
}
|
||||
|
||||
|
@ -15718,6 +15718,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:
|
||||
@ -15787,6 +15789,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:
|
||||
|
@ -4906,6 +4906,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,
|
||||
@ -4997,16 +5013,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()))
|
||||
@ -5034,6 +5063,9 @@ qemuProcessSetupGraphics(virQEMUDriver *driver,
|
||||
|
||||
if (qemuProcessGraphicsSetupListen(driver, graphics, vm) < 0)
|
||||
return -1;
|
||||
|
||||
if (qemuProcessGraphicsSetupDBus(driver, graphics, vm) < 0)
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (allocate) {
|
||||
|
30
tests/qemuxml2argvdata/graphics-dbus-address.args
Normal file
30
tests/qemuxml2argvdata/graphics-dbus-address.args
Normal file
@ -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 \
|
||||
-overcommit mem-lock=off \
|
||||
-smp 1,sockets=1,cores=1,threads=1 \
|
||||
-uuid c7a5fdbd-edaf-9455-926a-d65c16db1809 \
|
||||
-no-user-config \
|
||||
-nodefaults \
|
||||
-chardev socket,id=charmonitor,fd=1729,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
|
30
tests/qemuxml2argvdata/graphics-dbus-p2p.args
Normal file
30
tests/qemuxml2argvdata/graphics-dbus-p2p.args
Normal file
@ -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 \
|
||||
-overcommit mem-lock=off \
|
||||
-smp 1,sockets=1,cores=1,threads=1 \
|
||||
-uuid c7a5fdbd-edaf-9455-926a-d65c16db1809 \
|
||||
-no-user-config \
|
||||
-nodefaults \
|
||||
-chardev socket,id=charmonitor,fd=1729,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
|
30
tests/qemuxml2argvdata/graphics-dbus.args
Normal file
30
tests/qemuxml2argvdata/graphics-dbus.args
Normal file
@ -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 \
|
||||
-overcommit mem-lock=off \
|
||||
-smp 1,sockets=1,cores=1,threads=1 \
|
||||
-uuid c7a5fdbd-edaf-9455-926a-d65c16db1809 \
|
||||
-no-user-config \
|
||||
-nodefaults \
|
||||
-chardev socket,id=charmonitor,fd=1729,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
|
@ -1531,6 +1531,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");
|
||||
|
Loading…
Reference in New Issue
Block a user