qemu: Adapt to new way of specifying PC speaker

Historically, the way to set PC speaker for a guest was to pass:

  -soundhw pcspk

but as of QEMU commit v5.1.0-rc0~28^2~3 this is deprecated and we
should use:

  -machine pcspk-audiodev=$id

instead. The old way was then removed in commit v7.1.0-rc0~99^2~3.

Now, ideally we would have a capability selecting whether we talk
to a QEMU that understands the new way or not. But it's not that
simple - the machine attribute is just an alias to the .audiodev=
attribute of 'isa-pcspk' object and both are created in
pc_machine_initfn() function, i.e. not then the PC_MACHINE() class
is initialized, but when it's instantiated. IOW, it's not possible
for us to query whether we're dealing with older or newer QEMU.

But given that the newer version is supported since v5.1.0 and the
minimal version we require is v4.2.0 (i.e. there are two releases
which don't understand the newer cmd line) and how frequently this
feature is (un-)used (the issue was reported after ~1 year since it
stopped working), I believe we can live without any capability and
just use the newer cmd line unconditionally.

Resolves: https://gitlab.com/libvirt/libvirt/-/issues/490
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Kristina Hanicova <khanicov@redhat.com>
This commit is contained in:
Michal Privoznik 2023-06-16 13:05:48 +02:00
parent f9641d2c37
commit ecbce92371
3 changed files with 38 additions and 25 deletions

View File

@ -4478,31 +4478,30 @@ qemuBuildSoundCommandLine(virCommand *cmd,
for (i = 0; i < def->nsounds; i++) {
virDomainSoundDef *sound = def->sounds[i];
/* Sadly pcspk device doesn't use -device syntax. Fortunately
* we don't need to set any PCI address on it, so we don't
* mind too much */
if (sound->model == VIR_DOMAIN_SOUND_MODEL_PCSPK) {
virCommandAddArgList(cmd, "-soundhw", "pcspk", NULL);
} else {
if (qemuCommandAddExtDevice(cmd, &sound->info, def, qemuCaps) < 0)
return -1;
/* Sadly pcspk device doesn't use -device syntax. And it
* was handled already in qemuBuildMachineCommandLine().
*/
if (sound->model == VIR_DOMAIN_SOUND_MODEL_PCSPK)
continue;
if (qemuBuildSoundDevCmd(cmd, def, sound, qemuCaps) < 0)
return -1;
if (qemuCommandAddExtDevice(cmd, &sound->info, def, qemuCaps) < 0)
return -1;
if (virDomainSoundModelSupportsCodecs(sound)) {
for (j = 0; j < sound->ncodecs; j++) {
if (qemuBuildSoundCodecCmd(cmd, def, sound, sound->codecs[j],
qemuCaps) < 0)
return -1;
}
if (qemuBuildSoundDevCmd(cmd, def, sound, qemuCaps) < 0)
return -1;
if (j == 0) {
virDomainSoundCodecDef codec = { VIR_DOMAIN_SOUND_CODEC_TYPE_DUPLEX, 0 };
if (virDomainSoundModelSupportsCodecs(sound)) {
for (j = 0; j < sound->ncodecs; j++) {
if (qemuBuildSoundCodecCmd(cmd, def, sound, sound->codecs[j],
qemuCaps) < 0)
return -1;
}
if (qemuBuildSoundCodecCmd(cmd, def, sound, &codec, qemuCaps) < 0)
return -1;
}
if (j == 0) {
virDomainSoundCodecDef codec = { VIR_DOMAIN_SOUND_CODEC_TYPE_DUPLEX, 0 };
if (qemuBuildSoundCodecCmd(cmd, def, sound, &codec, qemuCaps) < 0)
return -1;
}
}
}
@ -7030,6 +7029,22 @@ qemuBuildMachineCommandLine(virCommand *cmd,
}
}
/* PC speaker is a bit different than the rest of sound cards
* which are handled in qemuBuildSoundCommandLine(). */
for (i = 0; i < def->nsounds; i++) {
const virDomainSoundDef *sound = def->sounds[i];
g_autofree char *audioid = NULL;
if (sound->model != VIR_DOMAIN_SOUND_MODEL_PCSPK)
continue;
if (!(audioid = qemuGetAudioIDString(def, sound->audioId)))
return -1;
virBufferAsprintf(&buf, ",pcspk-audiodev=%s", audioid);
break;
}
qemuBuildMachineACPI(&buf, def, qemuCaps);
virCommandAddArgBuffer(cmd, &buf);

View File

@ -10,7 +10,7 @@ XDG_CONFIG_HOME=/var/lib/libvirt/qemu/domain--1-QEMUGuest1/.config \
-name guest=QEMUGuest1,debug-threads=on \
-S \
-object secret,id=masterKey0,format=raw,file=/var/lib/libvirt/qemu/domain--1-QEMUGuest1/master-key.aes \
-machine pc-i440fx-4.2,usb=off,dump-guest-core=off \
-machine pc-i440fx-4.2,usb=off,dump-guest-core=off,pcspk-audiodev=audio1 \
-accel tcg \
-cpu qemu64 \
-m size=219136k \
@ -28,7 +28,6 @@ XDG_CONFIG_HOME=/var/lib/libvirt/qemu/domain--1-QEMUGuest1/.config \
-boot strict=on \
-device piix3-usb-uhci,id=usb,bus=pci.0,addr=0x1.0x2 \
-audiodev '{"id":"audio1","driver":"none"}' \
-soundhw pcspk \
-device ES1370,id=sound1,audiodev=audio1,bus=pci.0,addr=0x2 \
-device sb16,id=sound2,audiodev=audio1 \
-device AC97,id=sound3,audiodev=audio1,bus=pci.0,addr=0x3 \

View File

@ -10,7 +10,7 @@ XDG_CONFIG_HOME=/var/lib/libvirt/qemu/domain--1-QEMUGuest1/.config \
-name guest=QEMUGuest1,debug-threads=on \
-S \
-object '{"qom-type":"secret","id":"masterKey0","format":"raw","file":"/var/lib/libvirt/qemu/domain--1-QEMUGuest1/master-key.aes"}' \
-machine pc,usb=off,dump-guest-core=off,memory-backend=pc.ram,acpi=off \
-machine pc,usb=off,dump-guest-core=off,memory-backend=pc.ram,pcspk-audiodev=audio1,acpi=off \
-accel tcg \
-cpu qemu64 \
-m size=219136k \
@ -28,7 +28,6 @@ XDG_CONFIG_HOME=/var/lib/libvirt/qemu/domain--1-QEMUGuest1/.config \
-boot strict=on \
-device '{"driver":"piix3-usb-uhci","id":"usb","bus":"pci.0","addr":"0x1.0x2"}' \
-audiodev '{"id":"audio1","driver":"none"}' \
-soundhw pcspk \
-device '{"driver":"ES1370","id":"sound1","audiodev":"audio1","bus":"pci.0","addr":"0x2"}' \
-device '{"driver":"sb16","id":"sound2","audiodev":"audio1"}' \
-device '{"driver":"AC97","id":"sound3","audiodev":"audio1","bus":"pci.0","addr":"0x3"}' \