Unix socket chardevs with FD passing need to use the direct mode so we need to convert it to use qemuFDPassDirect. Signed-off-by: Peter Krempa <pkrempa@xxxxxxxxxx> --- src/qemu/qemu_command.c | 15 +++++++++------ src/qemu/qemu_domain.c | 1 + src/qemu/qemu_domain.h | 1 + src/qemu/qemu_hotplug.c | 5 +++-- src/qemu/qemu_monitor_json.c | 4 ++-- src/qemu/qemu_process.c | 5 ++--- tests/testutilsqemu.c | 26 +++++++++++--------------- 7 files changed, 29 insertions(+), 28 deletions(-) diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index 90a4b98e1e..828c7c38f5 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -1396,8 +1396,8 @@ qemuBuildChardevStr(const virDomainChrSourceDef *dev, case VIR_DOMAIN_CHR_TYPE_UNIX: virBufferAsprintf(&buf, "socket,id=%s", charAlias); - if (chrSourcePriv->sourcefd) { - virBufferAsprintf(&buf, ",fd=%s", qemuFDPassGetPath(chrSourcePriv->sourcefd)); + if (chrSourcePriv->directfd) { + virBufferAsprintf(&buf, ",fd=%s", qemuFDPassDirectGetPath(chrSourcePriv->directfd)); } else { virBufferAddLit(&buf, ",path="); virQEMUBuildBufferEscapeComma(&buf, dev->data.nix.path); @@ -1513,9 +1513,13 @@ qemuBuildChardevCommand(virCommand *cmd, break; case VIR_DOMAIN_CHR_TYPE_FILE: - case VIR_DOMAIN_CHR_TYPE_UNIX: if (qemuFDPassTransferCommand(chrSourcePriv->sourcefd, cmd) < 0) return -1; + + break; + + case VIR_DOMAIN_CHR_TYPE_UNIX: + qemuFDPassDirectTransferCommand(chrSourcePriv->directfd, cmd); break; case VIR_DOMAIN_CHR_TYPE_NULL: @@ -4943,12 +4947,11 @@ qemuBuildVideoCommandLine(virCommand *cmd, qemuDomainVideoPrivate *videopriv = QEMU_DOMAIN_VIDEO_PRIVATE(video); g_autoptr(virDomainChrSourceDef) chrsrc = virDomainChrSourceDefNew(priv->driver->xmlopt); g_autofree char *chrAlias = qemuDomainGetVhostUserChrAlias(video->info.alias); + g_autofree char *name = g_strdup_printf("%s-vhost-user", video->info.alias); qemuDomainChrSourcePrivate *chrsrcpriv = QEMU_DOMAIN_CHR_SOURCE_PRIVATE(chrsrc); chrsrc->type = VIR_DOMAIN_CHR_TYPE_UNIX; - chrsrcpriv->sourcefd = qemuFDPassNewDirect(video->info.alias, priv); - - qemuFDPassAddFD(chrsrcpriv->sourcefd, &videopriv->vhost_user_fd, "-vhost-user"); + chrsrcpriv->directfd = qemuFDPassDirectNew(name, &videopriv->vhost_user_fd); if (qemuBuildChardevCommand(cmd, chrsrc, chrAlias, priv->qemuCaps) < 0) return -1; diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index c957b5296a..29a09bb7f7 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -916,6 +916,7 @@ qemuDomainChrSourcePrivateClearFDPass(qemuDomainChrSourcePrivate *priv) g_clear_pointer(&priv->sourcefd, qemuFDPassFree); g_clear_pointer(&priv->logfd, qemuFDPassFree); + g_clear_pointer(&priv->directfd, qemuFDPassDirectFree); } diff --git a/src/qemu/qemu_domain.h b/src/qemu/qemu_domain.h index 1547dec668..547d85b5f9 100644 --- a/src/qemu/qemu_domain.h +++ b/src/qemu/qemu_domain.h @@ -350,6 +350,7 @@ struct _qemuDomainChrSourcePrivate { qemuFDPass *sourcefd; qemuFDPass *logfd; + qemuFDPassDirect *directfd; bool wait; /* wait for incoming connections on chardev */ char *tlsCertPath; /* path to certificates if TLS is requested */ diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c index 3504cd21ff..15ffcdc6ce 100644 --- a/src/qemu/qemu_hotplug.c +++ b/src/qemu/qemu_hotplug.c @@ -2133,11 +2133,12 @@ qemuDomainAttachChrDevice(virQEMUDriver *driver, if (qemuProcessPrepareHostBackendChardevHotplug(vm, dev) < 0) goto cleanup; - if (charpriv->sourcefd || charpriv->logfd) { + if (charpriv->sourcefd || charpriv->logfd || charpriv->directfd) { qemuDomainObjEnterMonitor(driver, vm); if (qemuFDPassTransferMonitor(charpriv->sourcefd, priv->mon) < 0 || - qemuFDPassTransferMonitor(charpriv->logfd, priv->mon) < 0) + qemuFDPassTransferMonitor(charpriv->logfd, priv->mon) < 0 || + qemuFDPassDirectTransferMonitor(charpriv->directfd, priv->mon) < 0) goto exit_monitor; qemuDomainObjExitMonitor(vm); diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c index a092bf420f..523a4326da 100644 --- a/src/qemu/qemu_monitor_json.c +++ b/src/qemu/qemu_monitor_json.c @@ -6724,8 +6724,8 @@ qemuMonitorJSONAttachCharDevGetProps(const char *chrID, waitval = VIR_TRISTATE_BOOL_NO; } - if (chrSourcePriv->sourcefd) { - if (!(addr = qemuMonitorJSONBuildFDSocketAddress(qemuFDPassGetPath(chrSourcePriv->sourcefd)))) + if (chrSourcePriv->directfd) { + if (!(addr = qemuMonitorJSONBuildFDSocketAddress(qemuFDPassDirectGetPath(chrSourcePriv->directfd)))) return NULL; } else { if (!(addr = qemuMonitorJSONBuildUnixSocketAddress(chr->data.nix.path))) diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index 07e467d01e..e83d1fff27 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -6876,6 +6876,7 @@ qemuProcessPrepareHostBackendChardevOne(virDomainDeviceDef *dev, case VIR_DOMAIN_CHR_TYPE_UNIX: if (chardev->data.nix.listen) { + g_autofree char *name = g_strdup_printf("%s-source", devalias); VIR_AUTOCLOSE sourcefd = -1; if (qemuSecuritySetSocketLabel(data->priv->driver->securityManager, data->def) < 0) @@ -6887,9 +6888,7 @@ qemuProcessPrepareHostBackendChardevOne(virDomainDeviceDef *dev, sourcefd < 0) return -1; - charpriv->sourcefd = qemuFDPassNewDirect(devalias, data->priv); - - qemuFDPassAddFD(charpriv->sourcefd, &sourcefd, "-source"); + charpriv->directfd = qemuFDPassDirectNew(name, &sourcefd); } break; diff --git a/tests/testutilsqemu.c b/tests/testutilsqemu.c index 89fdf1d6fe..7ae88c9b8d 100644 --- a/tests/testutilsqemu.c +++ b/tests/testutilsqemu.c @@ -1019,7 +1019,6 @@ testQemuPrepareHostBackendChardevOne(virDomainDeviceDef *dev, qemuDomainChrSourcePrivate *charpriv = QEMU_DOMAIN_CHR_SOURCE_PRIVATE(chardev); int fakesourcefd = -1; const char *devalias = NULL; - bool usefdset = true; if (vm) priv = vm->privateData; @@ -1061,13 +1060,22 @@ testQemuPrepareHostBackendChardevOne(virDomainDeviceDef *dev, case VIR_DOMAIN_CHR_TYPE_FILE: fakesourcefd = 1750; + + if (fcntl(fakesourcefd, F_GETFD) != -1) + abort(); + + charpriv->sourcefd = qemuFDPassNew(devalias, priv); + qemuFDPassAddFD(charpriv->sourcefd, &fakesourcefd, "-source"); break; case VIR_DOMAIN_CHR_TYPE_UNIX: - if (chardev->data.nix.listen) + if (chardev->data.nix.listen) { + g_autofree char *name = g_strdup_printf("%s-source", devalias); fakesourcefd = 1729; - usefdset = false; + charpriv->directfd = qemuFDPassDirectNew(name, &fakesourcefd); + } + break; case VIR_DOMAIN_CHR_TYPE_NMDM: @@ -1075,18 +1083,6 @@ testQemuPrepareHostBackendChardevOne(virDomainDeviceDef *dev, break; } - if (fakesourcefd != -1) { - if (fcntl(fakesourcefd, F_GETFD) != -1) - abort(); - - if (usefdset) - charpriv->sourcefd = qemuFDPassNew(devalias, priv); - else - charpriv->sourcefd = qemuFDPassNewDirect(devalias, priv); - - qemuFDPassAddFD(charpriv->sourcefd, &fakesourcefd, "-source"); - } - if (chardev->logfile) { int fd = 1751; -- 2.35.3