On a Wednesday in 2022, Peter Krempa wrote:
Rewrite the parts which already pass FDs via fdset or directly to use
the new infrastructure.
Apart from simpler code this also adds the appropriate names to the fds
in the fdsets which will allow us to properly remove the fdsets won
hot-unplug of chardevs, which we didn't do for now and resulted in
leaking the FDs.
Signed-off-by: Peter Krempa <pkrempa(a)redhat.com>
---
src/qemu/qemu_command.c | 74 ++++---------------
src/qemu/qemu_domain.c | 11 +--
src/qemu/qemu_domain.h | 8 +-
src/qemu/qemu_process.c | 42 +++++++++--
.../qemuxml2argvdata/aarch64-pci-serial.args | 4 +-
.../name-escape.x86_64-2.11.0.args | 4 +-
.../name-escape.x86_64-latest.args | 4 +-
.../qemuxml2argvdata/serial-file-chardev.args | 4 +-
.../serial-file-chardev.x86_64-latest.args | 4 +-
tests/qemuxml2argvdata/serial-file-log.args | 6 +-
.../serial-file-log.x86_64-latest.args | 6 +-
.../qemuxml2argvdata/serial-many-chardev.args | 4 +-
.../serial-many-chardev.x86_64-latest.args | 4 +-
tests/qemuxml2argvtest.c | 56 ++++++++------
14 files changed, 108 insertions(+), 123 deletions(-)
[..]
case VIR_DOMAIN_CHR_TYPE_UNIX:
if (chardev->data.nix.listen &&
virQEMUCapsGet(data->priv->qemuCaps,
QEMU_CAPS_CHARDEV_FD_PASS_COMMANDLINE)) {
+ VIR_AUTOCLOSE sourcefd = -1;
if (qemuSecuritySetSocketLabel(data->priv->driver->securityManager,
data->def) < 0)
return -1;
- charpriv->fd = qemuOpenChrChardevUNIXSocket(chardev);
+ sourcefd = qemuOpenChrChardevUNIXSocket(chardev);
- if
(qemuSecurityClearSocketLabel(data->priv->driver->securityManager, data->def)
< 0) {
- VIR_FORCE_CLOSE(charpriv->fd);
+ if
(qemuSecurityClearSocketLabel(data->priv->driver->securityManager, data->def)
< 0 ||
+ sourcefd < 0)
return -1;
- }
- if (charpriv->fd < 0)
+ /* UNIX socket use direct FD passing */
*sockets
+ charpriv->sourcefd = qemuFDPassNew(devalias,
data->priv, false);
+
+ if (qemuFDPassAddFD(charpriv->sourcefd, &sourcefd,
"-source") < 0)
return -1;
}
break;
Reviewed-by: Ján Tomko <jtomko(a)redhat.com>
Jano