]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
qemu: Use qemuBuildChrChardevCommand for vhost-user-gpu backend chardev
authorPeter Krempa <pkrempa@redhat.com>
Fri, 5 Nov 2021 14:40:40 +0000 (15:40 +0100)
committerPeter Krempa <pkrempa@redhat.com>
Fri, 10 Dec 2021 15:37:42 +0000 (16:37 +0100)
Now that the API for qemuBuildChrChardevCommand is sane enough, we can
use it to centralize formatting of '-chardev' generally.

The 'virDomainVideoDef' doesn't use 'virDomainChrSourceDef' internally so
we create it for this occasion manually.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
src/qemu/qemu_command.c
tests/qemuxml2argvdata/vhost-user-gpu-secondary.x86_64-latest.args
tests/qemuxml2argvdata/virtio-options-video-ats.x86_64-latest.args
tests/qemuxml2argvdata/virtio-options-video-iommu.x86_64-latest.args
tests/qemuxml2argvdata/virtio-options-video-packed.x86_64-latest.args

index 3a5796fed8178e4bece639e5cac7d6fcaaa47c97..3ca7da9d5d5e28ef8069319bcdf83c5131866561 100644 (file)
@@ -4939,60 +4939,37 @@ qemuBuildDeviceVideoCmd(virCommand *cmd,
 }
 
 
-static char *
-qemuBuildVhostUserChardevStr(const char *alias,
-                             int *fd,
-                             virCommand *cmd)
-{
-    g_autofree char *chardev_alias = qemuDomainGetVhostUserChrAlias(alias);
-    char *chardev = NULL;
-
-    if (*fd == -1) {
-        virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
-                       _("Attempt to pass closed vhostuser FD"));
-        return NULL;
-    }
-
-    chardev = g_strdup_printf("socket,id=%s,fd=%d", chardev_alias, *fd);
-
-    virCommandPassFD(cmd, *fd, VIR_COMMAND_PASS_FD_CLOSE_PARENT);
-    *fd = -1;
-
-    return chardev;
-}
-
-
 static int
 qemuBuildVideoCommandLine(virCommand *cmd,
                           const virDomainDef *def,
-                          virQEMUCaps *qemuCaps)
+                          qemuDomainObjPrivate *priv)
 {
     size_t i;
 
     for (i = 0; i < def->nvideos; i++) {
-        g_autofree char *chardev = NULL;
         virDomainVideoDef *video = def->videos[i];
 
+        if (video->type == VIR_DOMAIN_VIDEO_TYPE_NONE)
+            continue;
+
         if (video->backend == VIR_DOMAIN_VIDEO_BACKEND_TYPE_VHOSTUSER) {
-            if (!(chardev = qemuBuildVhostUserChardevStr(video->info.alias,
-                                &QEMU_DOMAIN_VIDEO_PRIVATE(video)->vhost_user_fd,
-                                cmd)))
-                return -1;
+            qemuDomainVideoPrivate *videopriv = QEMU_DOMAIN_VIDEO_PRIVATE(video);
+            g_autoptr(virDomainChrSourceDef) chrsrc = virDomainChrSourceDefNew(priv->driver->xmlopt);
+            g_autofree char *chrAlias = qemuDomainGetVhostUserChrAlias(video->info.alias);
+            qemuDomainChrSourcePrivate *chrsrcpriv = QEMU_DOMAIN_CHR_SOURCE_PRIVATE(chrsrc);
 
-            virCommandAddArgList(cmd, "-chardev", chardev, NULL);
-        }
-    }
+            chrsrc->type = VIR_DOMAIN_CHR_TYPE_UNIX;
+            chrsrcpriv->fd = videopriv->vhost_user_fd;
+            videopriv->vhost_user_fd = -1;
 
-    for (i = 0; i < def->nvideos; i++) {
-        virDomainVideoDef *video = def->videos[i];
-
-        if (video->type == VIR_DOMAIN_VIDEO_TYPE_NONE)
-            continue;
+            if (qemuBuildChardevCommand(cmd, chrsrc, chrAlias, priv->qemuCaps) < 0)
+                return -1;
+        }
 
-        if (qemuCommandAddExtDevice(cmd, &def->videos[i]->info, qemuCaps) < 0)
+        if (qemuCommandAddExtDevice(cmd, &def->videos[i]->info, priv->qemuCaps) < 0)
             return -1;
 
-        if (qemuBuildDeviceVideoCmd(cmd, def, video, qemuCaps) < 0)
+        if (qemuBuildDeviceVideoCmd(cmd, def, video, priv->qemuCaps) < 0)
             return -1;
     }
 
@@ -10646,7 +10623,7 @@ qemuBuildCommandLine(virQEMUDriver *driver,
     if (qemuBuildGraphicsCommandLine(cfg, cmd, def, qemuCaps) < 0)
         return NULL;
 
-    if (qemuBuildVideoCommandLine(cmd, def, qemuCaps) < 0)
+    if (qemuBuildVideoCommandLine(cmd, def, priv) < 0)
         return NULL;
 
     if (qemuBuildSoundCommandLine(cmd, def, qemuCaps) < 0)
index 7f0db5fbceed68149d74fce54fed4246ee5a6314..43ae421715b243364db33682fdabca3383b96ab3 100644 (file)
@@ -34,8 +34,8 @@ XDG_CONFIG_HOME=/tmp/lib/domain--1-QEMUGuest1/.config \
 -device '{"driver":"ide-hd","bus":"ide.0","unit":0,"drive":"libvirt-1-format","id":"ide0-0-0","bootindex":1}' \
 -audiodev '{"id":"audio1","driver":"none"}' \
 -chardev socket,id=chr-vu-video0,fd=1729 \
--chardev socket,id=chr-vu-video1,fd=1729 \
 -device '{"driver":"vhost-user-vga","id":"video0","max_outputs":1,"chardev":"chr-vu-video0","bus":"pci.0","addr":"0x2"}' \
+-chardev socket,id=chr-vu-video1,fd=1729 \
 -device '{"driver":"vhost-user-gpu-pci","id":"video1","max_outputs":1,"chardev":"chr-vu-video1","bus":"pci.0","addr":"0x4"}' \
 -device '{"driver":"virtio-balloon-pci","id":"balloon0","bus":"pci.0","addr":"0x3"}' \
 -sandbox on,obsolete=deny,elevateprivileges=deny,spawn=deny,resourcecontrol=deny \
index 4ec8d006e7a4f25496a70b196cde985186d3cfc5..c0b5ad781aca09c1285c1e92674b09e6895d1a70 100644 (file)
@@ -30,8 +30,8 @@ XDG_CONFIG_HOME=/tmp/lib/domain--1-QEMUGuest1/.config \
 -device '{"driver":"piix3-usb-uhci","id":"usb","bus":"pci.0","addr":"0x1.0x2"}' \
 -audiodev '{"id":"audio1","driver":"none"}' \
 -chardev socket,id=chr-vu-video0,fd=1729 \
--chardev socket,id=chr-vu-video1,fd=1729 \
 -device '{"driver":"vhost-user-vga","id":"video0","max_outputs":1,"chardev":"chr-vu-video0","bus":"pci.0","addr":"0x2"}' \
+-chardev socket,id=chr-vu-video1,fd=1729 \
 -device '{"driver":"vhost-user-gpu-pci","ats":false,"id":"video1","max_outputs":1,"chardev":"chr-vu-video1","bus":"pci.0","addr":"0x3"}' \
 -device '{"driver":"virtio-balloon-pci","id":"balloon0","bus":"pci.0","addr":"0x4"}' \
 -sandbox on,obsolete=deny,elevateprivileges=deny,spawn=deny,resourcecontrol=deny \
index d90b5c674fe26f4311017fa43af454ce21904734..48c7bcf7f61a74ab21697e686d255daffc159cf4 100644 (file)
@@ -30,8 +30,8 @@ XDG_CONFIG_HOME=/tmp/lib/domain--1-QEMUGuest1/.config \
 -device '{"driver":"piix3-usb-uhci","id":"usb","bus":"pci.0","addr":"0x1.0x2"}' \
 -audiodev '{"id":"audio1","driver":"none"}' \
 -chardev socket,id=chr-vu-video0,fd=1729 \
--chardev socket,id=chr-vu-video1,fd=1729 \
 -device '{"driver":"vhost-user-vga","id":"video0","max_outputs":1,"chardev":"chr-vu-video0","bus":"pci.0","addr":"0x2"}' \
+-chardev socket,id=chr-vu-video1,fd=1729 \
 -device '{"driver":"vhost-user-gpu-pci","iommu_platform":false,"id":"video1","max_outputs":1,"chardev":"chr-vu-video1","bus":"pci.0","addr":"0x3"}' \
 -device '{"driver":"virtio-balloon-pci","id":"balloon0","bus":"pci.0","addr":"0x4"}' \
 -sandbox on,obsolete=deny,elevateprivileges=deny,spawn=deny,resourcecontrol=deny \
index 532285eb85c6ac7ca2b617ffe67cd368ca567538..f1b96b92d744efcb6230f48626d285e4db00d6d9 100644 (file)
@@ -30,8 +30,8 @@ XDG_CONFIG_HOME=/tmp/lib/domain--1-QEMUGuest1/.config \
 -device '{"driver":"piix3-usb-uhci","id":"usb","bus":"pci.0","addr":"0x1.0x2"}' \
 -audiodev '{"id":"audio1","driver":"none"}' \
 -chardev socket,id=chr-vu-video0,fd=1729 \
--chardev socket,id=chr-vu-video1,fd=1729 \
 -device '{"driver":"vhost-user-vga","id":"video0","max_outputs":1,"chardev":"chr-vu-video0","bus":"pci.0","addr":"0x2"}' \
+-chardev socket,id=chr-vu-video1,fd=1729 \
 -device '{"driver":"vhost-user-gpu-pci","packed":false,"id":"video1","max_outputs":1,"chardev":"chr-vu-video1","bus":"pci.0","addr":"0x3"}' \
 -device '{"driver":"virtio-balloon-pci","id":"balloon0","bus":"pci.0","addr":"0x4"}' \
 -sandbox on,obsolete=deny,elevateprivileges=deny,spawn=deny,resourcecontrol=deny \