[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[libvirt] [RFC v2 14/16] qemu: build vhost-user-backend for vhost-user-gpu



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

Pass the vhost-user socket to a chardev, and associate a
vhost-user-backend with it for each vhost-user-gpu.

Signed-off-by: Marc-André Lureau <marcandre lureau redhat com>
---
 src/qemu/qemu_command.c | 50 +++++++++++++++++++++++++++++++++++++++++
 1 file changed, 50 insertions(+)

diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index 2f3bd2a98e..5d08ea7d50 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -4577,6 +4577,38 @@ qemuBuildVgaVideoCommand(virCommandPtr cmd,
 }
 
 
+static char *
+qemuBuildVhostUserBackendStr(virDomainVideoDefPtr video,
+                             virCommandPtr cmd,
+                             char **chardev)
+{
+    virBuffer buf = VIR_BUFFER_INITIALIZER;
+
+    if (virAsprintf(chardev, "socket,id=chr-vu-%s,fd=%d",
+                    video->info.alias, video->info.vhost_user_fd) < 0)
+        goto error;
+
+    virCommandPassFD(cmd, video->info.vhost_user_fd,
+                     VIR_COMMAND_PASS_FD_CLOSE_PARENT);
+
+    video->info.vhost_user_fd = -1;
+
+    virBufferAsprintf(&buf, "vhost-user-backend,id=vu-%s,chardev=chr-vu-%s",
+                      video->info.alias, video->info.alias);
+
+    if (virBufferCheckError(&buf) < 0)
+        goto error;
+
+    return virBufferContentAndReset(&buf);
+
+error:
+    VIR_FREE(*chardev);
+    virBufferFreeAndReset(&buf);
+    return NULL;
+
+}
+
+
 static int
 qemuBuildVideoCommandLine(virCommandPtr cmd,
                           const virDomainDef *def,
@@ -4584,6 +4616,24 @@ qemuBuildVideoCommandLine(virCommandPtr cmd,
 {
     size_t i;
 
+    for (i = 0; i < def->nvideos; i++) {
+        char *optstr;
+        char *chardev = NULL;
+        virDomainVideoDefPtr video = def->videos[i];
+
+        if (video->type == VIR_DOMAIN_VIDEO_TYPE_VHOST_USER) {
+
+            if (!(optstr = qemuBuildVhostUserBackendStr(video, cmd, &chardev)))
+                return -1;
+
+            virCommandAddArgList(cmd, "-chardev", chardev, NULL);
+            virCommandAddArgList(cmd, "-object", optstr, NULL);
+
+            VIR_FREE(optstr);
+            VIR_FREE(chardev);
+        }
+    }
+
     for (i = 0; i < def->nvideos; i++) {
         char *str = NULL;
         virDomainVideoDefPtr video = def->videos[i];
-- 
2.19.0.rc0.48.gb9dfa238d5


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]