mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-03 11:35:19 +00:00
qemu: Use qemuBuildChrChardevCommand for vhost-user-gpu backend chardev
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>
This commit is contained in:
parent
1164f234e3
commit
9a89ec8997
@ -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->backend == VIR_DOMAIN_VIDEO_BACKEND_TYPE_VHOSTUSER) {
|
||||
if (!(chardev = qemuBuildVhostUserChardevStr(video->info.alias,
|
||||
&QEMU_DOMAIN_VIDEO_PRIVATE(video)->vhost_user_fd,
|
||||
cmd)))
|
||||
return -1;
|
||||
|
||||
virCommandAddArgList(cmd, "-chardev", chardev, NULL);
|
||||
}
|
||||
}
|
||||
|
||||
for (i = 0; i < def->nvideos; i++) {
|
||||
virDomainVideoDef *video = def->videos[i];
|
||||
|
||||
if (video->type == VIR_DOMAIN_VIDEO_TYPE_NONE)
|
||||
continue;
|
||||
|
||||
if (qemuCommandAddExtDevice(cmd, &def->videos[i]->info, qemuCaps) < 0)
|
||||
if (video->backend == VIR_DOMAIN_VIDEO_BACKEND_TYPE_VHOSTUSER) {
|
||||
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);
|
||||
|
||||
chrsrc->type = VIR_DOMAIN_CHR_TYPE_UNIX;
|
||||
chrsrcpriv->fd = videopriv->vhost_user_fd;
|
||||
videopriv->vhost_user_fd = -1;
|
||||
|
||||
if (qemuBuildChardevCommand(cmd, chrsrc, chrAlias, priv->qemuCaps) < 0)
|
||||
return -1;
|
||||
}
|
||||
|
||||
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)
|
||||
|
@ -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 \
|
||||
|
@ -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 \
|
||||
|
@ -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 \
|
||||
|
@ -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 \
|
||||
|
Loading…
Reference in New Issue
Block a user