diff mbox series

[v2,13/16] qemu: start/stop the vhost-user-gpu external device

Message ID 4d239a3b4ce0dbd10672fee6c78121dfbf4a5b76.1566576129.git.crobinso@redhat.com
State New
Headers show
Series Add vhost-user-gpu support | expand

Commit Message

Cole Robinson Aug. 23, 2019, 4:21 p.m. UTC
From: Marc-André Lureau <marcandre.lureau@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@redhat.com>
Signed-off-by: Cole Robinson <crobinso@redhat.com>
---
 src/qemu/qemu_extdevice.c | 46 +++++++++++++++++++++++++++++++++++----
 1 file changed, 42 insertions(+), 4 deletions(-)
diff mbox series

Patch

diff --git a/src/qemu/qemu_extdevice.c b/src/qemu/qemu_extdevice.c
index 5c55aba006..3dbcec3546 100644
--- a/src/qemu/qemu_extdevice.c
+++ b/src/qemu/qemu_extdevice.c
@@ -161,10 +161,21 @@  qemuExtDevicesStart(virQEMUDriverPtr driver,
                     bool incomingMigration)
 {
     int ret = 0;
+    size_t i;
 
     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, incomingMigration);
 
@@ -176,9 +187,18 @@  void
 qemuExtDevicesStop(virQEMUDriverPtr driver,
                    virDomainObjPtr vm)
 {
+    size_t 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 +207,14 @@  qemuExtDevicesStop(virQEMUDriverPtr driver,
 bool
 qemuExtDevicesHasDevice(virDomainDefPtr def)
 {
+    size_t 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 +227,20 @@  qemuExtDevicesSetupCgroup(virQEMUDriverPtr driver,
                           virDomainDefPtr def,
                           virCgroupPtr cgroup)
 {
-    int ret = 0;
+    size_t 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;
 }