render / rpms / libvirt

Forked from rpms/libvirt 9 months ago
Clone
0a7476
From 92f60bbc60e5ff60069f6d775d23f228eb3b5c78 Mon Sep 17 00:00:00 2001
0a7476
Message-Id: <92f60bbc60e5ff60069f6d775d23f228eb3b5c78@dist-git>
0a7476
From: Erik Skultety <eskultet@redhat.com>
0a7476
Date: Tue, 9 Apr 2019 08:34:27 +0200
0a7476
Subject: [PATCH] qemu: process: spice: Pick the first available DRM render
0a7476
 node
0a7476
MIME-Version: 1.0
0a7476
Content-Type: text/plain; charset=UTF-8
0a7476
Content-Transfer-Encoding: 8bit
0a7476
0a7476
Up until now, we formatted 'rendernode=' onto QEMU cmdline only if the
0a7476
user specified it in the XML, otherwise we let QEMU do it for us. This
0a7476
causes permission issues because by default the /dev/dri/renderDX
0a7476
permissions are as follows:
0a7476
0a7476
crw-rw----. 1 root video
0a7476
0a7476
There's literally no reason why it shouldn't be libvirt picking the DRM
0a7476
render node instead of QEMU, that way (and because we're using
0a7476
namespaces by default), we can safely relabel the device within the
0a7476
namespace.
0a7476
0a7476
Signed-off-by: Erik Skultety <eskultet@redhat.com>
0a7476
Reviewed-by: Ján Tomko <jtomko@redhat.com>
0a7476
(cherry picked from commit 27cc9f6ac187924456b658683e490f6d318ebe08)
0a7476
0a7476
https://bugzilla.redhat.com/show_bug.cgi?id=1628892
0a7476
Signed-off-by: Erik Skultety <eskultet@redhat.com>
0a7476
0a7476
 Conflicts:
0a7476
	tests/qemuxml2argvmock.c
0a7476
            Missing context because v4.6.0-309-gd06a8ebe8f and
0a7476
            v4.6.0-311-g3411fd4db4 were not backported
0a7476
Message-Id: <be2bca27f2b84bfebbe62a699d78bd91e59e96bd.1554791287.git.eskultet@redhat.com>
0a7476
0a7476
Reviewed-by: Jiri Denemark <jdenemar@redhat.com>
0a7476
---
0a7476
 src/qemu/qemu_process.c                       | 24 +++++++++++++-
0a7476
 src/util/virutil.h                            |  2 +-
0a7476
 ...pice-gl-auto-rendernode.x86_64-latest.args | 31 +++++++++++++++++++
0a7476
 .../graphics-spice-gl-auto-rendernode.xml     | 24 ++++++++++++++
0a7476
 tests/qemuxml2argvmock.c                      |  9 ++++++
0a7476
 tests/qemuxml2argvtest.c                      |  1 +
0a7476
 6 files changed, 89 insertions(+), 2 deletions(-)
0a7476
 create mode 100644 tests/qemuxml2argvdata/graphics-spice-gl-auto-rendernode.x86_64-latest.args
0a7476
 create mode 100644 tests/qemuxml2argvdata/graphics-spice-gl-auto-rendernode.xml
0a7476
0a7476
diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
0a7476
index a44f371346..465dabd8e3 100644
0a7476
--- a/src/qemu/qemu_process.c
0a7476
+++ b/src/qemu/qemu_process.c
0a7476
@@ -4751,9 +4751,28 @@ qemuProcessGraphicsSetupListen(virQEMUDriverPtr driver,
0a7476
 }
0a7476
 
0a7476
 
0a7476
+static int
0a7476
+qemuProcessGraphicsSetupRenderNode(virDomainGraphicsDefPtr graphics,
0a7476
+                                   virQEMUCapsPtr qemuCaps)
0a7476
+{
0a7476
+    if (!virDomainGraphicsNeedsAutoRenderNode(graphics))
0a7476
+        return 0;
0a7476
+
0a7476
+    /* Don't bother picking a DRM node if QEMU doesn't support it. */
0a7476
+    if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_SPICE_RENDERNODE))
0a7476
+        return 0;
0a7476
+
0a7476
+    if (!(graphics->data.spice.rendernode = virHostGetDRMRenderNode()))
0a7476
+        return -1;
0a7476
+
0a7476
+    return 0;
0a7476
+}
0a7476
+
0a7476
+
0a7476
 static int
0a7476
 qemuProcessSetupGraphics(virQEMUDriverPtr driver,
0a7476
                          virDomainObjPtr vm,
0a7476
+                         virQEMUCapsPtr qemuCaps,
0a7476
                          unsigned int flags)
0a7476
 {
0a7476
     virDomainGraphicsDefPtr graphics;
0a7476
@@ -4764,6 +4783,9 @@ qemuProcessSetupGraphics(virQEMUDriverPtr driver,
0a7476
     for (i = 0; i < vm->def->ngraphics; i++) {
0a7476
         graphics = vm->def->graphics[i];
0a7476
 
0a7476
+        if (qemuProcessGraphicsSetupRenderNode(graphics, qemuCaps) < 0)
0a7476
+            goto cleanup;
0a7476
+
0a7476
         if (qemuProcessGraphicsSetupListen(driver, graphics, vm) < 0)
0a7476
             goto cleanup;
0a7476
     }
0a7476
@@ -5924,7 +5946,7 @@ qemuProcessPrepareDomain(virQEMUDriverPtr driver,
0a7476
         goto cleanup;
0a7476
 
0a7476
     VIR_DEBUG("Setting graphics devices");
0a7476
-    if (qemuProcessSetupGraphics(driver, vm, flags) < 0)
0a7476
+    if (qemuProcessSetupGraphics(driver, vm, priv->qemuCaps, flags) < 0)
0a7476
         goto cleanup;
0a7476
 
0a7476
     VIR_DEBUG("Create domain masterKey");
0a7476
diff --git a/src/util/virutil.h b/src/util/virutil.h
0a7476
index 284c713be4..abbbb7101e 100644
0a7476
--- a/src/util/virutil.h
0a7476
+++ b/src/util/virutil.h
0a7476
@@ -218,7 +218,7 @@ unsigned long long virMemoryMaxValue(bool ulong) ATTRIBUTE_NOINLINE;
0a7476
 
0a7476
 bool virHostHasIOMMU(void);
0a7476
 
0a7476
-char *virHostGetDRMRenderNode(void);
0a7476
+char *virHostGetDRMRenderNode(void) ATTRIBUTE_NOINLINE;
0a7476
 
0a7476
 /**
0a7476
  * VIR_ASSIGN_IS_OVERFLOW:
0a7476
diff --git a/tests/qemuxml2argvdata/graphics-spice-gl-auto-rendernode.x86_64-latest.args b/tests/qemuxml2argvdata/graphics-spice-gl-auto-rendernode.x86_64-latest.args
0a7476
new file mode 100644
0a7476
index 0000000000..ee92e1fa5a
0a7476
--- /dev/null
0a7476
+++ b/tests/qemuxml2argvdata/graphics-spice-gl-auto-rendernode.x86_64-latest.args
0a7476
@@ -0,0 +1,31 @@
0a7476
+LC_ALL=C \
0a7476
+PATH=/bin \
0a7476
+HOME=/home/test \
0a7476
+USER=test \
0a7476
+LOGNAME=test \
0a7476
+QEMU_AUDIO_DRV=spice \
0a7476
+/usr/bin/qemu-system-i686 \
0a7476
+-name guest=QEMUGuest1,debug-threads=on \
0a7476
+-S \
0a7476
+-object secret,id=masterKey0,format=raw,\
0a7476
+file=/tmp/lib/domain--1-QEMUGuest1/master-key.aes \
0a7476
+-machine pc,accel=tcg,usb=off,dump-guest-core=off \
0a7476
+-m 214 \
0a7476
+-realtime mlock=off \
0a7476
+-smp 1,sockets=1,cores=1,threads=1 \
0a7476
+-uuid c7a5fdbd-edaf-9455-926a-d65c16db1809 \
0a7476
+-no-user-config \
0a7476
+-nodefaults \
0a7476
+-chardev socket,id=charmonitor,fd=1729,server,nowait \
0a7476
+-mon chardev=charmonitor,id=monitor,mode=control \
0a7476
+-rtc base=utc \
0a7476
+-no-shutdown \
0a7476
+-no-acpi \
0a7476
+-boot strict=on \
0a7476
+-device piix3-usb-uhci,id=usb,bus=pci.0,addr=0x1.0x2 \
0a7476
+-spice port=0,gl=on,rendernode=/dev/dri/foo,seamless-migration=on \
0a7476
+-device cirrus-vga,id=video0,bus=pci.0,addr=0x2 \
0a7476
+-device virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x3 \
0a7476
+-sandbox on,obsolete=deny,elevateprivileges=deny,spawn=deny,\
0a7476
+resourcecontrol=deny \
0a7476
+-msg timestamp=on
0a7476
diff --git a/tests/qemuxml2argvdata/graphics-spice-gl-auto-rendernode.xml b/tests/qemuxml2argvdata/graphics-spice-gl-auto-rendernode.xml
0a7476
new file mode 100644
0a7476
index 0000000000..b48e7bc94e
0a7476
--- /dev/null
0a7476
+++ b/tests/qemuxml2argvdata/graphics-spice-gl-auto-rendernode.xml
0a7476
@@ -0,0 +1,24 @@
0a7476
+<domain type='qemu'>
0a7476
+  <name>QEMUGuest1</name>
0a7476
+  <uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid>
0a7476
+  <memory unit='KiB'>219136</memory>
0a7476
+  <currentMemory unit='KiB'>219136</currentMemory>
0a7476
+  <vcpu placement='static'>1</vcpu>
0a7476
+  <os>
0a7476
+    <type arch='i686' machine='pc'>hvm</type>
0a7476
+    <boot dev='hd'/>
0a7476
+  </os>
0a7476
+  <clock offset='utc'/>
0a7476
+  <on_poweroff>destroy</on_poweroff>
0a7476
+  <on_reboot>restart</on_reboot>
0a7476
+  <on_crash>destroy</on_crash>
0a7476
+  <devices>
0a7476
+    <emulator>/usr/bin/qemu-system-i686</emulator>
0a7476
+    <input type='mouse' bus='ps2'/>
0a7476
+    <input type='keyboard' bus='ps2'/>
0a7476
+    <graphics type='spice' autoport='no'>
0a7476
+      <gl enable='yes'/>
0a7476
+    </graphics>
0a7476
+    <memballoon model='virtio'/>
0a7476
+  </devices>
0a7476
+</domain>
0a7476
diff --git a/tests/qemuxml2argvmock.c b/tests/qemuxml2argvmock.c
0a7476
index 4df92cf396..d826793d28 100644
0a7476
--- a/tests/qemuxml2argvmock.c
0a7476
+++ b/tests/qemuxml2argvmock.c
0a7476
@@ -184,6 +184,15 @@ virNetDevRunEthernetScript(const char *ifname ATTRIBUTE_UNUSED,
0a7476
     return 0;
0a7476
 }
0a7476
 
0a7476
+char *
0a7476
+virHostGetDRMRenderNode(void)
0a7476
+{
0a7476
+    char *dst = NULL;
0a7476
+
0a7476
+    ignore_value(VIR_STRDUP(dst, "/dev/dri/foo"));
0a7476
+    return dst;
0a7476
+}
0a7476
+
0a7476
 void
0a7476
 virCommandPassFD(virCommandPtr cmd ATTRIBUTE_UNUSED,
0a7476
                  int fd ATTRIBUTE_UNUSED,
0a7476
diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c
0a7476
index 693e768d66..f76856dc5f 100644
0a7476
--- a/tests/qemuxml2argvtest.c
0a7476
+++ b/tests/qemuxml2argvtest.c
0a7476
@@ -1279,6 +1279,7 @@ mymain(void)
0a7476
                     QEMU_CAPS_SPICE,
0a7476
                     QEMU_CAPS_EGL_HEADLESS,
0a7476
                     QEMU_CAPS_DEVICE_QXL);
0a7476
+    DO_TEST_CAPS_LATEST("graphics-spice-gl-auto-rendernode");
0a7476
 
0a7476
     DO_TEST("input-usbmouse", NONE);
0a7476
     DO_TEST("input-usbtablet", NONE);
0a7476
-- 
0a7476
2.21.0
0a7476