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 <pkre...@redhat.com>
---
 src/qemu/qemu_command.c                       | 57 ++++++-------------
 ...host-user-gpu-secondary.x86_64-latest.args |  2 +-
 ...irtio-options-video-ats.x86_64-latest.args |  2 +-
 ...tio-options-video-iommu.x86_64-latest.args |  2 +-
 ...io-options-video-packed.x86_64-latest.args |  2 +-
 5 files changed, 21 insertions(+), 44 deletions(-)

diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index 3a5796fed8..3ca7da9d5d 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -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)
diff --git a/tests/qemuxml2argvdata/vhost-user-gpu-secondary.x86_64-latest.args 
b/tests/qemuxml2argvdata/vhost-user-gpu-secondary.x86_64-latest.args
index 7f0db5fbce..43ae421715 100644
--- a/tests/qemuxml2argvdata/vhost-user-gpu-secondary.x86_64-latest.args
+++ b/tests/qemuxml2argvdata/vhost-user-gpu-secondary.x86_64-latest.args
@@ -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 \
diff --git a/tests/qemuxml2argvdata/virtio-options-video-ats.x86_64-latest.args 
b/tests/qemuxml2argvdata/virtio-options-video-ats.x86_64-latest.args
index 4ec8d006e7..c0b5ad781a 100644
--- a/tests/qemuxml2argvdata/virtio-options-video-ats.x86_64-latest.args
+++ b/tests/qemuxml2argvdata/virtio-options-video-ats.x86_64-latest.args
@@ -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 \
diff --git 
a/tests/qemuxml2argvdata/virtio-options-video-iommu.x86_64-latest.args 
b/tests/qemuxml2argvdata/virtio-options-video-iommu.x86_64-latest.args
index d90b5c674f..48c7bcf7f6 100644
--- a/tests/qemuxml2argvdata/virtio-options-video-iommu.x86_64-latest.args
+++ b/tests/qemuxml2argvdata/virtio-options-video-iommu.x86_64-latest.args
@@ -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 \
diff --git 
a/tests/qemuxml2argvdata/virtio-options-video-packed.x86_64-latest.args 
b/tests/qemuxml2argvdata/virtio-options-video-packed.x86_64-latest.args
index 532285eb85..f1b96b92d7 100644
--- a/tests/qemuxml2argvdata/virtio-options-video-packed.x86_64-latest.args
+++ b/tests/qemuxml2argvdata/virtio-options-video-packed.x86_64-latest.args
@@ -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 \
-- 
2.31.1

Reply via email to