[libvirt] [PATCH 16/19] qemu: start/stop the vhost-user-gpu external device

marcandre.lureau at redhat.com marcandre.lureau at redhat.com
Wed Jun 5 10:31:14 UTC 2019


From: Marc-André Lureau <marcandre.lureau at redhat.com>

Each vhost-user-gpu needs its own helper gpu process.
Start/stop them, and apply the emulator cgroup controller.

Signed-off-by: Marc-André Lureau <marcandre.lureau at redhat.com>
---
 src/qemu/qemu_extdevice.c | 49 +++++++++++++++++++++++++++++++++++----
 1 file changed, 44 insertions(+), 5 deletions(-)

diff --git a/src/qemu/qemu_extdevice.c b/src/qemu/qemu_extdevice.c
index 977743d240..7e78e10cdd 100644
--- a/src/qemu/qemu_extdevice.c
+++ b/src/qemu/qemu_extdevice.c
@@ -24,6 +24,7 @@
 #include "qemu_vhost_user_gpu.h"
 #include "qemu_domain.h"
 #include "qemu_tpm.h"
+#include "qemu_vhost_user_gpu.h"
 
 #include "viralloc.h"
 #include "virlog.h"
@@ -160,11 +161,21 @@ qemuExtDevicesStart(virQEMUDriverPtr driver,
                     virDomainObjPtr vm,
                     qemuDomainLogContextPtr logCtxt)
 {
-    int ret = 0;
+    int i, ret = 0;
 
     if (qemuExtDevicesInitPaths(driver, vm->def) < 0)
         return -1;
 
+    for (i = 0; i < vm->def->nvideos; i++) {
+        virDomainVideoDefPtr video = vm->def->videos[i];
+
+        if (video->type == VIR_DOMAIN_VIDEO_TYPE_VIRTIO && video->vhostuser) {
+            ret = qemuExtVhostUserGPUStart(driver, vm, video, logCtxt);
+            if (ret < 0)
+                return ret;
+        }
+    }
+
     if (vm->def->tpm)
         ret = qemuExtTPMStart(driver, vm, logCtxt);
 
@@ -176,9 +187,19 @@ void
 qemuExtDevicesStop(virQEMUDriverPtr driver,
                    virDomainObjPtr vm)
 {
+    int i;
+
     if (qemuExtDevicesInitPaths(driver, vm->def) < 0)
         return;
 
+    for (i = 0; i < vm->def->nvideos; i++) {
+        virDomainVideoDefPtr video = vm->def->videos[i];
+
+        if (video->type == VIR_DOMAIN_VIDEO_TYPE_VIRTIO && video->vhostuser) {
+            qemuExtVhostUserGPUStop(driver, vm, video);
+        }
+    }
+
     if (vm->def->tpm)
         qemuExtTPMStop(driver, vm);
 }
@@ -187,6 +208,14 @@ qemuExtDevicesStop(virQEMUDriverPtr driver,
 bool
 qemuExtDevicesHasDevice(virDomainDefPtr def)
 {
+    int i;
+
+    for (i = 0; i < def->nvideos; i++) {
+        if (def->videos[i]->type == VIR_DOMAIN_VIDEO_TYPE_VIRTIO &&
+            def->videos[i]->vhostuser)
+            return true;
+    }
+
     if (def->tpm && def->tpm->type == VIR_DOMAIN_TPM_TYPE_EMULATOR)
         return true;
 
@@ -199,10 +228,20 @@ qemuExtDevicesSetupCgroup(virQEMUDriverPtr driver,
                           virDomainDefPtr def,
                           virCgroupPtr cgroup)
 {
-    int ret = 0;
+    int i;
 
-    if (def->tpm)
-        ret = qemuExtTPMSetupCgroup(driver, def, cgroup);
+    for (i = 0; i < def->nvideos; i++) {
+        virDomainVideoDefPtr video = def->videos[i];
 
-    return ret;
+        if (video->type == VIR_DOMAIN_VIDEO_TYPE_VIRTIO &&
+            video->vhostuser &&
+            qemuExtVhostUserGPUSetupCgroup(driver, def, video, cgroup) < 0)
+            return -1;
+    }
+
+    if (def->tpm &&
+        qemuExtTPMSetupCgroup(driver, def, cgroup) < 0)
+        return -1;
+
+    return 0;
 }
-- 
2.22.0.rc2.384.g1a9a72ea1d




More information about the libvir-list mailing list