qemuProcessPrepareHostBackendChardevFileHelper: Always use FD passing

Code paths which don't wish to use FD passing are supposed to not call
the function which sets up the chardev for FD passing.

This is ensured by calling it only in the host prepare step.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
Peter Krempa 2022-02-07 17:12:31 +01:00
parent 0f0d6af1b2
commit 9aab7acfe0
7 changed files with 17 additions and 26 deletions

View File

@ -6730,18 +6730,9 @@ qemuProcessPrepareHostBackendChardevFileHelper(const char *path,
int *fd, int *fd,
virLogManager *logManager, virLogManager *logManager,
virSecurityManager *secManager, virSecurityManager *secManager,
virQEMUCaps *qemuCaps,
virQEMUDriverConfig *cfg, virQEMUDriverConfig *cfg,
const virDomainDef *def) const virDomainDef *def)
{ {
/* Technically, to pass an FD via /dev/fdset we don't need
* any capability check because X_QEMU_CAPS_ADD_FD is already
* assumed. But keeping the old style is still handy when
* building a standalone command line (e.g. for tests). */
if (!logManager &&
!virQEMUCapsGet(qemuCaps, QEMU_CAPS_CHARDEV_FD_PASS_COMMANDLINE))
return 0;
if (logManager) { if (logManager) {
int flags = 0; int flags = 0;
@ -6839,7 +6830,6 @@ qemuProcessPrepareHostBackendChardevOne(virDomainDeviceDef *dev,
&charpriv->fd, &charpriv->fd,
data->logManager, data->logManager,
data->secManager, data->secManager,
data->qemuCaps,
data->cfg, data->cfg,
data->def) < 0) data->def) < 0)
return -1; return -1;
@ -6880,7 +6870,6 @@ qemuProcessPrepareHostBackendChardevOne(virDomainDeviceDef *dev,
&charpriv->logfd, &charpriv->logfd,
data->logManager, data->logManager,
data->secManager, data->secManager,
data->qemuCaps,
data->cfg, data->cfg,
data->def) < 0) data->def) < 0)
return -1; return -1;

View File

@ -29,6 +29,7 @@ QEMU_AUDIO_DRV=none \
-device i82801b11-bridge,id=pci.1,bus=pcie.0,addr=0x1 \ -device i82801b11-bridge,id=pci.1,bus=pcie.0,addr=0x1 \
-device pci-bridge,chassis_nr=2,id=pci.2,bus=pci.1,addr=0x0 \ -device pci-bridge,chassis_nr=2,id=pci.2,bus=pci.1,addr=0x0 \
-device pcie-root-port,port=16,chassis=3,id=pci.3,bus=pcie.0,addr=0x2 \ -device pcie-root-port,port=16,chassis=3,id=pci.3,bus=pcie.0,addr=0x2 \
-chardev pty,id=charserial0,logfile=/tmp/log,logappend=on \ -add-fd set=0,fd=1751 \
-chardev pty,id=charserial0,logfile=/dev/fdset/0,logappend=on \
-device pci-serial,chardev=charserial0,id=serial0,bus=pci.2,addr=0x1 \ -device pci-serial,chardev=charserial0,id=serial0,bus=pci.2,addr=0x1 \
-msg timestamp=on -msg timestamp=on

View File

@ -33,7 +33,8 @@ QEMU_AUDIO_DRV=spice \
-device ccid-card-emulated,backend=certificates,cert1=cert1,,foo,cert2=cert2,cert3=cert3,db=/etc/pki/nssdb,,foo,id=smartcard0,bus=ccid0.0 \ -device ccid-card-emulated,backend=certificates,cert1=cert1,,foo,cert2=cert2,cert3=cert3,db=/etc/pki/nssdb,,foo,id=smartcard0,bus=ccid0.0 \
-chardev tty,id=charserial0,path=/dev/ttyS2,,foo \ -chardev tty,id=charserial0,path=/dev/ttyS2,,foo \
-device isa-serial,chardev=charserial0,id=serial0,index=1 \ -device isa-serial,chardev=charserial0,id=serial0,index=1 \
-chardev file,id=charserial1,path=/tmp/serial.log,,foo,append=on \ -add-fd set=0,fd=1750 \
-chardev file,id=charserial1,path=/dev/fdset/0,append=on \
-device isa-serial,chardev=charserial1,id=serial1,index=0 \ -device isa-serial,chardev=charserial1,id=serial1,index=0 \
-chardev pipe,id=charchannel0,path=/tmp/guestfwd,,foo \ -chardev pipe,id=charchannel0,path=/tmp/guestfwd,,foo \
-netdev user,guestfwd=tcp:10.0.2.1:4600-chardev:charchannel0,id=channel0 \ -netdev user,guestfwd=tcp:10.0.2.1:4600-chardev:charchannel0,id=channel0 \

View File

@ -29,7 +29,8 @@ QEMU_AUDIO_DRV=none \
-usb \ -usb \
-drive file=/dev/HostVG/QEMUGuest1,format=raw,if=none,id=drive-ide0-0-0 \ -drive file=/dev/HostVG/QEMUGuest1,format=raw,if=none,id=drive-ide0-0-0 \
-device ide-hd,bus=ide.0,unit=0,drive=drive-ide0-0-0,id=ide0-0-0,bootindex=1 \ -device ide-hd,bus=ide.0,unit=0,drive=drive-ide0-0-0,id=ide0-0-0,bootindex=1 \
-chardev file,id=charserial0,path=/tmp/serial.log,append=on \ -add-fd set=0,fd=1750 \
-chardev file,id=charserial0,path=/dev/fdset/0,append=on \
-device isa-serial,chardev=charserial0,id=serial0,index=0 \ -device isa-serial,chardev=charserial0,id=serial0,index=0 \
-device virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x2 \ -device virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x2 \
-msg timestamp=on -msg timestamp=on

View File

@ -29,6 +29,8 @@ QEMU_AUDIO_DRV=none \
-usb \ -usb \
-drive file=/dev/HostVG/QEMUGuest1,format=raw,if=none,id=drive-ide0-0-0 \ -drive file=/dev/HostVG/QEMUGuest1,format=raw,if=none,id=drive-ide0-0-0 \
-device ide-hd,bus=ide.0,unit=0,drive=drive-ide0-0-0,id=ide0-0-0,bootindex=1 \ -device ide-hd,bus=ide.0,unit=0,drive=drive-ide0-0-0,id=ide0-0-0,bootindex=1 \
-chardev file,id=charserial0,path=/tmp/serial.log,logfile=/var/lib/libvirt/qemu/demo-serial.log,logappend=off \ -add-fd set=0,fd=1750 \
-add-fd set=1,fd=1751 \
-chardev file,id=charserial0,path=/dev/fdset/0,append=on,logfile=/dev/fdset/1,logappend=on \
-device isa-serial,chardev=charserial0,id=serial0,index=0 \ -device isa-serial,chardev=charserial0,id=serial0,index=0 \
-msg timestamp=on -msg timestamp=on

View File

@ -31,7 +31,8 @@ QEMU_AUDIO_DRV=none \
-device ide-hd,bus=ide.0,unit=0,drive=drive-ide0-0-0,id=ide0-0-0,bootindex=1 \ -device ide-hd,bus=ide.0,unit=0,drive=drive-ide0-0-0,id=ide0-0-0,bootindex=1 \
-chardev pty,id=charserial0 \ -chardev pty,id=charserial0 \
-device isa-serial,chardev=charserial0,id=serial0,index=0 \ -device isa-serial,chardev=charserial0,id=serial0,index=0 \
-chardev file,id=charserial1,path=/tmp/serial.log \ -add-fd set=0,fd=1750 \
-chardev file,id=charserial1,path=/dev/fdset/0,append=on \
-device isa-serial,chardev=charserial1,id=serial1,index=1 \ -device isa-serial,chardev=charserial1,id=serial1,index=1 \
-device virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x2 \ -device virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x2 \
-msg timestamp=on -msg timestamp=on

View File

@ -416,11 +416,9 @@ testPrepareHostBackendChardevOne(virDomainDeviceDef *dev,
break; break;
case VIR_DOMAIN_CHR_TYPE_FILE: case VIR_DOMAIN_CHR_TYPE_FILE:
if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_CHARDEV_FD_PASS_COMMANDLINE)) { if (fcntl(1750, F_GETFD) != -1)
if (fcntl(1750, F_GETFD) != -1) abort();
abort(); charpriv->fd = 1750;
charpriv->fd = 1750;
}
break; break;
case VIR_DOMAIN_CHR_TYPE_UNIX: case VIR_DOMAIN_CHR_TYPE_UNIX:
@ -440,11 +438,9 @@ testPrepareHostBackendChardevOne(virDomainDeviceDef *dev,
} }
if (chardev->logfile) { if (chardev->logfile) {
if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_CHARDEV_FD_PASS_COMMANDLINE)) { if (fcntl(1751, F_GETFD) != -1)
if (fcntl(1751, F_GETFD) != -1) abort();
abort(); charpriv->logfd = 1751;
charpriv->logfd = 1751;
}
} }
return 0; return 0;